| 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 | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 145 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 146 | * @phba: Pointer to HBA context object. |
| 147 | * @iocbq: Pointer to driver iocb object. |
| 148 | * |
| 149 | * This function is called with hbalock held to release driver |
| 150 | * iocb object to the iocb pool. The iotag in the iocb object |
| 151 | * does not change for each use of the iocb object. This function |
| 152 | * clears all other fields of the iocb object when it is freed. |
| 153 | **/ |
| 154 | static void |
| 155 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 156 | { |
| 157 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 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 | iocbq->sli4_xritag = NO_XRI; |
| 164 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 165 | } |
| 166 | |
| 167 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 168 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 169 | * @phba: Pointer to HBA context object. |
| 170 | * @iocbq: Pointer to driver iocb object. |
| 171 | * |
| 172 | * This function is called with hbalock held to release driver |
| 173 | * iocb object to the iocb pool. The iotag in the iocb object |
| 174 | * does not change for each use of the iocb object. This function |
| 175 | * clears all other fields of the iocb object when it is freed. |
| 176 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 177 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 178 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 179 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 180 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 181 | } |
| 182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 184 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 185 | * @phba: Pointer to HBA context object. |
| 186 | * @iocbq: Pointer to driver iocb object. |
| 187 | * |
| 188 | * This function is called with no lock held to release the iocb to |
| 189 | * iocb pool. |
| 190 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 191 | void |
| 192 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 193 | { |
| 194 | unsigned long iflags; |
| 195 | |
| 196 | /* |
| 197 | * Clean all volatile data fields, preserve iotag and node struct. |
| 198 | */ |
| 199 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 200 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 201 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 202 | } |
| 203 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 204 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 205 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 206 | * @phba: Pointer to HBA context object. |
| 207 | * @iocblist: List of IOCBs. |
| 208 | * @ulpstatus: ULP status in IOCB command field. |
| 209 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 210 | * |
| 211 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 212 | * on the list by invoking the complete callback function associated with the |
| 213 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 214 | * fields. |
| 215 | **/ |
| 216 | void |
| 217 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 218 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 219 | { |
| 220 | struct lpfc_iocbq *piocb; |
| 221 | |
| 222 | while (!list_empty(iocblist)) { |
| 223 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 224 | |
| 225 | if (!piocb->iocb_cmpl) |
| 226 | lpfc_sli_release_iocbq(phba, piocb); |
| 227 | else { |
| 228 | piocb->iocb.ulpStatus = ulpstatus; |
| 229 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 230 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 231 | } |
| 232 | } |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 237 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 238 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 239 | * |
| 240 | * This function is called by ring event handler function to get the iocb type. |
| 241 | * This function translates the iocb command to an iocb command type used to |
| 242 | * decide the final disposition of each completed IOCB. |
| 243 | * The function returns |
| 244 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 245 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 246 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 247 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 248 | * |
| 249 | * The caller is not required to hold any lock. |
| 250 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | static lpfc_iocb_type |
| 252 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 253 | { |
| 254 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 255 | |
| 256 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 257 | return 0; |
| 258 | |
| 259 | switch (iocb_cmnd) { |
| 260 | case CMD_XMIT_SEQUENCE_CR: |
| 261 | case CMD_XMIT_SEQUENCE_CX: |
| 262 | case CMD_XMIT_BCAST_CN: |
| 263 | case CMD_XMIT_BCAST_CX: |
| 264 | case CMD_ELS_REQUEST_CR: |
| 265 | case CMD_ELS_REQUEST_CX: |
| 266 | case CMD_CREATE_XRI_CR: |
| 267 | case CMD_CREATE_XRI_CX: |
| 268 | case CMD_GET_RPI_CN: |
| 269 | case CMD_XMIT_ELS_RSP_CX: |
| 270 | case CMD_GET_RPI_CR: |
| 271 | case CMD_FCP_IWRITE_CR: |
| 272 | case CMD_FCP_IWRITE_CX: |
| 273 | case CMD_FCP_IREAD_CR: |
| 274 | case CMD_FCP_IREAD_CX: |
| 275 | case CMD_FCP_ICMND_CR: |
| 276 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 277 | case CMD_FCP_TSEND_CX: |
| 278 | case CMD_FCP_TRSP_CX: |
| 279 | case CMD_FCP_TRECEIVE_CX: |
| 280 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 281 | case CMD_ADAPTER_MSG: |
| 282 | case CMD_ADAPTER_DUMP: |
| 283 | case CMD_XMIT_SEQUENCE64_CR: |
| 284 | case CMD_XMIT_SEQUENCE64_CX: |
| 285 | case CMD_XMIT_BCAST64_CN: |
| 286 | case CMD_XMIT_BCAST64_CX: |
| 287 | case CMD_ELS_REQUEST64_CR: |
| 288 | case CMD_ELS_REQUEST64_CX: |
| 289 | case CMD_FCP_IWRITE64_CR: |
| 290 | case CMD_FCP_IWRITE64_CX: |
| 291 | case CMD_FCP_IREAD64_CR: |
| 292 | case CMD_FCP_IREAD64_CX: |
| 293 | case CMD_FCP_ICMND64_CR: |
| 294 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 295 | case CMD_FCP_TSEND64_CX: |
| 296 | case CMD_FCP_TRSP64_CX: |
| 297 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 298 | case CMD_GEN_REQUEST64_CR: |
| 299 | case CMD_GEN_REQUEST64_CX: |
| 300 | case CMD_XMIT_ELS_RSP64_CX: |
| 301 | type = LPFC_SOL_IOCB; |
| 302 | break; |
| 303 | case CMD_ABORT_XRI_CN: |
| 304 | case CMD_ABORT_XRI_CX: |
| 305 | case CMD_CLOSE_XRI_CN: |
| 306 | case CMD_CLOSE_XRI_CX: |
| 307 | case CMD_XRI_ABORTED_CX: |
| 308 | case CMD_ABORT_MXRI64_CN: |
| 309 | type = LPFC_ABORT_IOCB; |
| 310 | break; |
| 311 | case CMD_RCV_SEQUENCE_CX: |
| 312 | case CMD_RCV_ELS_REQ_CX: |
| 313 | case CMD_RCV_SEQUENCE64_CX: |
| 314 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 315 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 316 | case CMD_IOCB_RCV_SEQ64_CX: |
| 317 | case CMD_IOCB_RCV_ELS64_CX: |
| 318 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 319 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | type = LPFC_UNSOL_IOCB; |
| 321 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 322 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 323 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 324 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 325 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 326 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 327 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 328 | case CMD_IOCB_RET_HBQE64_CN: |
| 329 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 330 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 331 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 332 | case CMD_IOCB_LOGENTRY_CN: |
| 333 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 334 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 335 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 336 | type = LPFC_UNKNOWN_IOCB; |
| 337 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 338 | default: |
| 339 | type = LPFC_UNKNOWN_IOCB; |
| 340 | break; |
| 341 | } |
| 342 | |
| 343 | return type; |
| 344 | } |
| 345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 347 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 348 | * @phba: Pointer to HBA context object. |
| 349 | * |
| 350 | * This function is called from SLI initialization code |
| 351 | * to configure every ring of the HBA's SLI interface. The |
| 352 | * caller is not required to hold any lock. This function issues |
| 353 | * a config_ring mailbox command for each ring. |
| 354 | * This function returns zero if successful else returns a negative |
| 355 | * error code. |
| 356 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 357 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 358 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 359 | { |
| 360 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 361 | LPFC_MBOXQ_t *pmb; |
| 362 | MAILBOX_t *pmbox; |
| 363 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 364 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 365 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 366 | if (!pmb) |
| 367 | return -ENOMEM; |
| 368 | pmbox = &pmb->mb; |
| 369 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 371 | lpfc_config_ring(phba, i, pmb); |
| 372 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 373 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 375 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 376 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 377 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 378 | rc, pmbox->mbxCommand, |
| 379 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 380 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 381 | ret = -ENXIO; |
| 382 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 385 | mempool_free(pmb, phba->mbox_mem_pool); |
| 386 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | } |
| 388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 390 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 391 | * @phba: Pointer to HBA context object. |
| 392 | * @pring: Pointer to driver SLI ring object. |
| 393 | * @piocb: Pointer to the driver iocb object. |
| 394 | * |
| 395 | * This function is called with hbalock held. The function adds the |
| 396 | * new iocb to txcmplq of the given ring. This function always returns |
| 397 | * 0. If this function is called for ELS ring, this function checks if |
| 398 | * there is a vport associated with the ELS command. This function also |
| 399 | * starts els_tmofunc timer if this is an ELS command. |
| 400 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 401 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 402 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 403 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 406 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 407 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 408 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 409 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 410 | if (!piocb->vport) |
| 411 | BUG(); |
| 412 | else |
| 413 | mod_timer(&piocb->vport->els_tmofunc, |
| 414 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 415 | } |
| 416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 418 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 419 | } |
| 420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 422 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 423 | * @phba: Pointer to HBA context object. |
| 424 | * @pring: Pointer to driver SLI ring object. |
| 425 | * |
| 426 | * This function is called with hbalock held to get next |
| 427 | * iocb in txq of the given ring. If there is any iocb in |
| 428 | * the txq, the function returns first iocb in the list after |
| 429 | * removing the iocb from the list, else it returns NULL. |
| 430 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 432 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | struct lpfc_iocbq *cmd_iocb; |
| 435 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 436 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 437 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | } |
| 441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 443 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 444 | * @phba: Pointer to HBA context object. |
| 445 | * @pring: Pointer to driver SLI ring object. |
| 446 | * |
| 447 | * This function is called with hbalock held and the caller must post the |
| 448 | * iocb without releasing the lock. If the caller releases the lock, |
| 449 | * iocb slot returned by the function is not guaranteed to be available. |
| 450 | * The function returns pointer to the next available iocb slot if there |
| 451 | * is available slot in the ring, else it returns NULL. |
| 452 | * If the get index of the ring is ahead of the put index, the function |
| 453 | * will post an error attention event to the worker thread to take the |
| 454 | * HBA to offline state. |
| 455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | static IOCB_t * |
| 457 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 458 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 459 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 462 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 463 | pring->next_cmdidx = 0; |
| 464 | |
| 465 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 466 | |
| 467 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 468 | |
| 469 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 470 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 471 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 472 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 473 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | pring->local_getidx, max_cmd_idx); |
| 475 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 476 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 477 | /* |
| 478 | * All error attention handlers are posted to |
| 479 | * worker thread |
| 480 | */ |
| 481 | phba->work_ha |= HA_ERATT; |
| 482 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 483 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 484 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 485 | |
| 486 | return NULL; |
| 487 | } |
| 488 | |
| 489 | if (pring->local_getidx == pring->next_cmdidx) |
| 490 | return NULL; |
| 491 | } |
| 492 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 493 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 494 | } |
| 495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 497 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 498 | * @phba: Pointer to HBA context object. |
| 499 | * @iocbq: Pointer to driver iocb object. |
| 500 | * |
| 501 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 502 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 503 | * array and assigns a new iotag. |
| 504 | * The function returns the allocated iotag if successful, else returns zero. |
| 505 | * Zero is not a valid iotag. |
| 506 | * The caller is not required to hold any lock. |
| 507 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 508 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 509 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | struct lpfc_iocbq **new_arr; |
| 512 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 513 | size_t new_len; |
| 514 | struct lpfc_sli *psli = &phba->sli; |
| 515 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 517 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 518 | iotag = psli->last_iotag; |
| 519 | if(++iotag < psli->iocbq_lookup_len) { |
| 520 | psli->last_iotag = iotag; |
| 521 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 522 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 523 | iocbq->iotag = iotag; |
| 524 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 525 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 526 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 527 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 528 | spin_unlock_irq(&phba->hbalock); |
| 529 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 530 | GFP_KERNEL); |
| 531 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 533 | old_arr = psli->iocbq_lookup; |
| 534 | if (new_len <= psli->iocbq_lookup_len) { |
| 535 | /* highly unprobable case */ |
| 536 | kfree(new_arr); |
| 537 | iotag = psli->last_iotag; |
| 538 | if(++iotag < psli->iocbq_lookup_len) { |
| 539 | psli->last_iotag = iotag; |
| 540 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 541 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 542 | iocbq->iotag = iotag; |
| 543 | return iotag; |
| 544 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 545 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | if (psli->iocbq_lookup) |
| 549 | memcpy(new_arr, old_arr, |
| 550 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 551 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 552 | psli->iocbq_lookup = new_arr; |
| 553 | psli->iocbq_lookup_len = new_len; |
| 554 | psli->last_iotag = iotag; |
| 555 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 556 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 557 | iocbq->iotag = iotag; |
| 558 | kfree(old_arr); |
| 559 | return iotag; |
| 560 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 561 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 562 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 564 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 565 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 566 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 567 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 568 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | } |
| 570 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 571 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 572 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 573 | * @phba: Pointer to HBA context object. |
| 574 | * @pring: Pointer to driver SLI ring object. |
| 575 | * @iocb: Pointer to iocb slot in the ring. |
| 576 | * @nextiocb: Pointer to driver iocb object which need to be |
| 577 | * posted to firmware. |
| 578 | * |
| 579 | * This function is called with hbalock held to post a new iocb to |
| 580 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 581 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 582 | * a completion call back for this iocb else the function will free the |
| 583 | * iocb object. |
| 584 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 585 | static void |
| 586 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 587 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 588 | { |
| 589 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 590 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 592 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 594 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 595 | if (pring->ringno == LPFC_ELS_RING) { |
| 596 | lpfc_debugfs_slow_ring_trc(phba, |
| 597 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 598 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 599 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 600 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 601 | } |
| 602 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | /* |
| 604 | * Issue iocb command to adapter |
| 605 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 606 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | wmb(); |
| 608 | pring->stats.iocb_cmd++; |
| 609 | |
| 610 | /* |
| 611 | * If there is no completion routine to call, we can release the |
| 612 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 613 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 614 | */ |
| 615 | if (nextiocb->iocb_cmpl) |
| 616 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 617 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 618 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | |
| 620 | /* |
| 621 | * Let the HBA know what IOCB slot will be the next one the |
| 622 | * driver will put a command into. |
| 623 | */ |
| 624 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 625 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | } |
| 627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 629 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 630 | * @phba: Pointer to HBA context object. |
| 631 | * @pring: Pointer to driver SLI ring object. |
| 632 | * |
| 633 | * The caller is not required to hold any lock for calling this function. |
| 634 | * This function updates the chip attention bits for the ring to inform firmware |
| 635 | * that there are pending work to be done for this ring and requests an |
| 636 | * interrupt when there is space available in the ring. This function is |
| 637 | * called when the driver is unable to post more iocbs to the ring due |
| 638 | * to unavailability of space in the ring. |
| 639 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 640 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 641 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | { |
| 643 | int ringno = pring->ringno; |
| 644 | |
| 645 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 646 | |
| 647 | wmb(); |
| 648 | |
| 649 | /* |
| 650 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 651 | * The HBA will tell us when an IOCB entry is available. |
| 652 | */ |
| 653 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 654 | readl(phba->CAregaddr); /* flush */ |
| 655 | |
| 656 | pring->stats.iocb_cmd_full++; |
| 657 | } |
| 658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 659 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 660 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 661 | * @phba: Pointer to HBA context object. |
| 662 | * @pring: Pointer to driver SLI ring object. |
| 663 | * |
| 664 | * This function updates the chip attention register bit for the |
| 665 | * given ring to inform HBA that there is more work to be done |
| 666 | * in this ring. The caller is not required to hold any lock. |
| 667 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 669 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 670 | { |
| 671 | int ringno = pring->ringno; |
| 672 | |
| 673 | /* |
| 674 | * Tell the HBA that there is work to do in this ring. |
| 675 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 676 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 677 | wmb(); |
| 678 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 679 | readl(phba->CAregaddr); /* flush */ |
| 680 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 681 | } |
| 682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 684 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 685 | * @phba: Pointer to HBA context object. |
| 686 | * @pring: Pointer to driver SLI ring object. |
| 687 | * |
| 688 | * This function is called with hbalock held to post pending iocbs |
| 689 | * in the txq to the firmware. This function is called when driver |
| 690 | * detects space available in the ring. |
| 691 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 692 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 693 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | { |
| 695 | IOCB_t *iocb; |
| 696 | struct lpfc_iocbq *nextiocb; |
| 697 | |
| 698 | /* |
| 699 | * Check to see if: |
| 700 | * (a) there is anything on the txq to send |
| 701 | * (b) link is up |
| 702 | * (c) link attention events can be processed (fcp ring only) |
| 703 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 704 | */ |
| 705 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 706 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 707 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 708 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | |
| 710 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 711 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 712 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 713 | |
| 714 | if (iocb) |
| 715 | lpfc_sli_update_ring(phba, pring); |
| 716 | else |
| 717 | lpfc_sli_update_full_ring(phba, pring); |
| 718 | } |
| 719 | |
| 720 | return; |
| 721 | } |
| 722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 724 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 725 | * @phba: Pointer to HBA context object. |
| 726 | * @hbqno: HBQ number. |
| 727 | * |
| 728 | * This function is called with hbalock held to get the next |
| 729 | * available slot for the given HBQ. If there is free slot |
| 730 | * available for the HBQ it will return pointer to the next available |
| 731 | * HBQ entry else it will return NULL. |
| 732 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 733 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 734 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 735 | { |
| 736 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 737 | |
| 738 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 739 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 740 | hbqp->next_hbqPutIdx = 0; |
| 741 | |
| 742 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 743 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 744 | uint32_t getidx = le32_to_cpu(raw_index); |
| 745 | |
| 746 | hbqp->local_hbqGetIdx = getidx; |
| 747 | |
| 748 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 749 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 750 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 751 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 752 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 753 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 754 | hbqp->entry_count); |
| 755 | |
| 756 | phba->link_state = LPFC_HBA_ERROR; |
| 757 | return NULL; |
| 758 | } |
| 759 | |
| 760 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 761 | return NULL; |
| 762 | } |
| 763 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 764 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 765 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 766 | } |
| 767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 769 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 770 | * @phba: Pointer to HBA context object. |
| 771 | * |
| 772 | * This function is called with no lock held to free all the |
| 773 | * hbq buffers while uninitializing the SLI interface. It also |
| 774 | * frees the HBQ buffers returned by the firmware but not yet |
| 775 | * processed by the upper layers. |
| 776 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 777 | void |
| 778 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 779 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 780 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 781 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 782 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 783 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 784 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 785 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 786 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 787 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 788 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 789 | for (i = 0; i < hbq_count; ++i) { |
| 790 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 791 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 792 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 793 | list_del(&hbq_buf->dbuf.list); |
| 794 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 795 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 796 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 797 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 798 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 799 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 800 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 801 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 802 | list_del(&hbq_buf->dbuf.list); |
| 803 | if (hbq_buf->tag == -1) { |
| 804 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 805 | (phba, hbq_buf); |
| 806 | } else { |
| 807 | hbqno = hbq_buf->tag >> 16; |
| 808 | if (hbqno >= LPFC_MAX_HBQS) |
| 809 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 810 | (phba, hbq_buf); |
| 811 | else |
| 812 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 813 | hbq_buf); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | /* Mark the HBQs not in use */ |
| 818 | phba->hbq_in_use = 0; |
| 819 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 820 | } |
| 821 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 822 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 823 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 824 | * @phba: Pointer to HBA context object. |
| 825 | * @hbqno: HBQ number. |
| 826 | * @hbq_buf: Pointer to HBQ buffer. |
| 827 | * |
| 828 | * This function is called with the hbalock held to post a |
| 829 | * hbq buffer to the firmware. If the function finds an empty |
| 830 | * slot in the HBQ, it will post the buffer. The function will return |
| 831 | * pointer to the hbq entry if it successfully post the buffer |
| 832 | * else it will return NULL. |
| 833 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 834 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 835 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 837 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 838 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 843 | * @phba: Pointer to HBA context object. |
| 844 | * @hbqno: HBQ number. |
| 845 | * @hbq_buf: Pointer to HBQ buffer. |
| 846 | * |
| 847 | * This function is called with the hbalock held to post a hbq buffer to the |
| 848 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 849 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 850 | * it successfully post the buffer else it will return an error. |
| 851 | **/ |
| 852 | static int |
| 853 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 854 | struct hbq_dmabuf *hbq_buf) |
| 855 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 856 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 857 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 858 | |
| 859 | /* Get next HBQ entry slot to use */ |
| 860 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 861 | if (hbqe) { |
| 862 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 863 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 864 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 865 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 866 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 867 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 868 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 869 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 870 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 871 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 872 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 873 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 874 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 875 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 876 | return 0; |
| 877 | } else |
| 878 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 879 | } |
| 880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 881 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 882 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 883 | .rn = 1, |
| 884 | .entry_count = 200, |
| 885 | .mask_count = 0, |
| 886 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 887 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 888 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 889 | .init_count = 40, |
| 890 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 891 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 893 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 894 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 895 | .rn = 1, |
| 896 | .entry_count = 200, |
| 897 | .mask_count = 0, |
| 898 | .profile = 0, |
| 899 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 900 | .buffer_count = 0, |
| 901 | .init_count = 0, |
| 902 | .add_count = 5, |
| 903 | }; |
| 904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 905 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 906 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 907 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 908 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 909 | }; |
| 910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 912 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 913 | * @phba: Pointer to HBA context object. |
| 914 | * @hbqno: HBQ number. |
| 915 | * @count: Number of HBQ buffers to be posted. |
| 916 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 917 | * This function is called with no lock held to post more hbq buffers to the |
| 918 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 919 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 920 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 921 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 922 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 923 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 924 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 925 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 926 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 927 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 928 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 929 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 930 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 931 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 932 | lpfc_hbq_defs[hbqno]->entry_count) |
| 933 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 934 | phba->hbqs[hbqno].buffer_count; |
| 935 | if (!count) |
| 936 | return 0; |
| 937 | /* Allocate HBQ entries */ |
| 938 | for (i = 0; i < count; i++) { |
| 939 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 940 | if (!hbq_buffer) |
| 941 | break; |
| 942 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 943 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 944 | /* Check whether HBQ is still in use */ |
| 945 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 946 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 947 | goto err; |
| 948 | while (!list_empty(&hbq_buf_list)) { |
| 949 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 950 | dbuf.list); |
| 951 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 952 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 953 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 954 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 955 | posted++; |
| 956 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 957 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 958 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 959 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 960 | return posted; |
| 961 | err: |
| 962 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 963 | while (!list_empty(&hbq_buf_list)) { |
| 964 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 965 | dbuf.list); |
| 966 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 967 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 969 | } |
| 970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 972 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 973 | * @phba: Pointer to HBA context object. |
| 974 | * @qno: HBQ number. |
| 975 | * |
| 976 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 977 | * is called with no lock held. The function returns the number of HBQ entries |
| 978 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 979 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 980 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 981 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 982 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 983 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 984 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 985 | } |
| 986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 987 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 988 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 989 | * @phba: Pointer to HBA context object. |
| 990 | * @qno: HBQ queue number. |
| 991 | * |
| 992 | * This function is called from SLI initialization code path with |
| 993 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 994 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 995 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 996 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 997 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 998 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1000 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1001 | } |
| 1002 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1003 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1004 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1005 | * @phba: Pointer to HBA context object. |
| 1006 | * @hbqno: HBQ number. |
| 1007 | * |
| 1008 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1009 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1010 | **/ |
| 1011 | static struct hbq_dmabuf * |
| 1012 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1013 | { |
| 1014 | struct lpfc_dmabuf *d_buf; |
| 1015 | |
| 1016 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1017 | if (!d_buf) |
| 1018 | return NULL; |
| 1019 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1020 | } |
| 1021 | |
| 1022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1023 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1024 | * @phba: Pointer to HBA context object. |
| 1025 | * @tag: Tag of the hbq buffer. |
| 1026 | * |
| 1027 | * This function is called with hbalock held. This function searches |
| 1028 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1029 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1030 | * it returns NULL. |
| 1031 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1032 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1033 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1034 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1035 | struct lpfc_dmabuf *d_buf; |
| 1036 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1037 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1038 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1039 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1040 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1041 | return NULL; |
| 1042 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1043 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1044 | 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] | 1045 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1046 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1047 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1048 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1049 | } |
| 1050 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1051 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1053 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1054 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1055 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1056 | } |
| 1057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1059 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1060 | * @phba: Pointer to HBA context object. |
| 1061 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1062 | * |
| 1063 | * This function is called with hbalock. This function gives back |
| 1064 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1065 | * post the buffer, it will free the buffer. |
| 1066 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1067 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1068 | 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] | 1069 | { |
| 1070 | uint32_t hbqno; |
| 1071 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1072 | if (hbq_buffer) { |
| 1073 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1074 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1075 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1080 | * 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] | 1081 | * @mbxCommand: mailbox command code. |
| 1082 | * |
| 1083 | * This function is called by the mailbox event handler function to verify |
| 1084 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1085 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1086 | * and the mailbox event handler will take the HBA offline. |
| 1087 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | static int |
| 1089 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1090 | { |
| 1091 | uint8_t ret; |
| 1092 | |
| 1093 | switch (mbxCommand) { |
| 1094 | case MBX_LOAD_SM: |
| 1095 | case MBX_READ_NV: |
| 1096 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1097 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | case MBX_RUN_BIU_DIAG: |
| 1099 | case MBX_INIT_LINK: |
| 1100 | case MBX_DOWN_LINK: |
| 1101 | case MBX_CONFIG_LINK: |
| 1102 | case MBX_CONFIG_RING: |
| 1103 | case MBX_RESET_RING: |
| 1104 | case MBX_READ_CONFIG: |
| 1105 | case MBX_READ_RCONFIG: |
| 1106 | case MBX_READ_SPARM: |
| 1107 | case MBX_READ_STATUS: |
| 1108 | case MBX_READ_RPI: |
| 1109 | case MBX_READ_XRI: |
| 1110 | case MBX_READ_REV: |
| 1111 | case MBX_READ_LNK_STAT: |
| 1112 | case MBX_REG_LOGIN: |
| 1113 | case MBX_UNREG_LOGIN: |
| 1114 | case MBX_READ_LA: |
| 1115 | case MBX_CLEAR_LA: |
| 1116 | case MBX_DUMP_MEMORY: |
| 1117 | case MBX_DUMP_CONTEXT: |
| 1118 | case MBX_RUN_DIAGS: |
| 1119 | case MBX_RESTART: |
| 1120 | case MBX_UPDATE_CFG: |
| 1121 | case MBX_DOWN_LOAD: |
| 1122 | case MBX_DEL_LD_ENTRY: |
| 1123 | case MBX_RUN_PROGRAM: |
| 1124 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1125 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1127 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1129 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1130 | case MBX_LOAD_AREA: |
| 1131 | case MBX_RUN_BIU_DIAG64: |
| 1132 | case MBX_CONFIG_PORT: |
| 1133 | case MBX_READ_SPARM64: |
| 1134 | case MBX_READ_RPI64: |
| 1135 | case MBX_REG_LOGIN64: |
| 1136 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1137 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1138 | case MBX_SET_DEBUG: |
| 1139 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1140 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1141 | case MBX_REG_VPI: |
| 1142 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1143 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1144 | case MBX_PORT_CAPABILITIES: |
| 1145 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | ret = mbxCommand; |
| 1147 | break; |
| 1148 | default: |
| 1149 | ret = MBX_SHUTDOWN; |
| 1150 | break; |
| 1151 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1152 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1153 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1154 | |
| 1155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1156 | * 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] | 1157 | * @phba: Pointer to HBA context object. |
| 1158 | * @pmboxq: Pointer to mailbox command. |
| 1159 | * |
| 1160 | * This is completion handler function for mailbox commands issued from |
| 1161 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1162 | * mailbox event handler function with no lock held. This function |
| 1163 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1164 | * of the mailbox. |
| 1165 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1167 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | { |
| 1169 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1170 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | |
| 1172 | /* |
| 1173 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1174 | * continued running. |
| 1175 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1176 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1178 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1179 | if (pdone_q) |
| 1180 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1181 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | return; |
| 1183 | } |
| 1184 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1185 | |
| 1186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1187 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | * @phba: Pointer to HBA context object. |
| 1189 | * @pmb: Pointer to mailbox object. |
| 1190 | * |
| 1191 | * This function is the default mailbox completion handler. It |
| 1192 | * frees the memory resources associated with the completed mailbox |
| 1193 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1194 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1195 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1197 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1198 | { |
| 1199 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1200 | uint16_t rpi; |
| 1201 | int rc; |
| 1202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1203 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | if (mp) { |
| 1206 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1207 | kfree(mp); |
| 1208 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1209 | |
| 1210 | /* |
| 1211 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1212 | * is in re-discovery driver need to cleanup the RPI. |
| 1213 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1214 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1215 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1216 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1217 | |
| 1218 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1219 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1220 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1221 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1222 | if (rc != MBX_NOT_FINISHED) |
| 1223 | return; |
| 1224 | } |
| 1225 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | return; |
| 1228 | } |
| 1229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1231 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1232 | * @phba: Pointer to HBA context object. |
| 1233 | * |
| 1234 | * This function is called with no lock held. This function processes all |
| 1235 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1236 | * service routine processes mailbox completion interrupt and adds completed |
| 1237 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1238 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1239 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1240 | * function returns the mailbox commands to the upper layer by calling the |
| 1241 | * completion handler function of each mailbox. |
| 1242 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1244 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1246 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1247 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1248 | int rc; |
| 1249 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1250 | |
| 1251 | phba->sli.slistat.mbox_event++; |
| 1252 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1253 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1254 | spin_lock_irq(&phba->hbalock); |
| 1255 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1256 | spin_unlock_irq(&phba->hbalock); |
| 1257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1259 | do { |
| 1260 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1261 | if (pmb == NULL) |
| 1262 | break; |
| 1263 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1266 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1267 | if (pmb->vport) { |
| 1268 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1269 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1270 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1271 | (uint32_t)pmbox->mbxCommand, |
| 1272 | pmbox->un.varWords[0], |
| 1273 | pmbox->un.varWords[1]); |
| 1274 | } |
| 1275 | else { |
| 1276 | lpfc_debugfs_disc_trc(phba->pport, |
| 1277 | LPFC_DISC_TRC_MBOX, |
| 1278 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1279 | (uint32_t)pmbox->mbxCommand, |
| 1280 | pmbox->un.varWords[0], |
| 1281 | pmbox->un.varWords[1]); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | /* |
| 1286 | * It is a fatal error if unknown mbox command completion. |
| 1287 | */ |
| 1288 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1289 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1291 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1292 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1294 | pmb->vport ? pmb->vport->vpi : 0, |
| 1295 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | phba->work_hs = HS_FFER3; |
| 1298 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1299 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | } |
| 1301 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | if (pmbox->mbxStatus) { |
| 1303 | phba->sli.slistat.mbox_stat_err++; |
| 1304 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1305 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1306 | lpfc_printf_log(phba, KERN_INFO, |
| 1307 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1308 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1309 | "error - RETRYing Data: x%x " |
| 1310 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1311 | pmb->vport ? pmb->vport->vpi :0, |
| 1312 | pmbox->mbxCommand, |
| 1313 | pmbox->mbxStatus, |
| 1314 | pmbox->un.varWords[0], |
| 1315 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | pmbox->mbxStatus = 0; |
| 1317 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1318 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1319 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1320 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1322 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1323 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1328 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1329 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | "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] | 1331 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | pmbox->mbxCommand, |
| 1333 | pmb->mbox_cmpl, |
| 1334 | *((uint32_t *) pmbox), |
| 1335 | pmbox->un.varWords[0], |
| 1336 | pmbox->un.varWords[1], |
| 1337 | pmbox->un.varWords[2], |
| 1338 | pmbox->un.varWords[3], |
| 1339 | pmbox->un.varWords[4], |
| 1340 | pmbox->un.varWords[5], |
| 1341 | pmbox->un.varWords[6], |
| 1342 | pmbox->un.varWords[7]); |
| 1343 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1344 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1346 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1347 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1351 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1352 | * @phba: Pointer to HBA context object. |
| 1353 | * @pring: Pointer to driver SLI ring object. |
| 1354 | * @tag: buffer tag. |
| 1355 | * |
| 1356 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1357 | * is set in the tag the buffer is posted for a particular exchange, |
| 1358 | * the function will return the buffer without replacing the buffer. |
| 1359 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1360 | * returns the buffer and also posts another buffer to the firmware. |
| 1361 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1362 | static struct lpfc_dmabuf * |
| 1363 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1364 | struct lpfc_sli_ring *pring, |
| 1365 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1366 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1367 | struct hbq_dmabuf *hbq_entry; |
| 1368 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1369 | if (tag & QUE_BUFTAG_BIT) |
| 1370 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1371 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 1372 | if (!hbq_entry) |
| 1373 | return NULL; |
| 1374 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1375 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1376 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1377 | /** |
| 1378 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 1379 | * @phba: Pointer to HBA context object. |
| 1380 | * @pring: Pointer to driver SLI ring object. |
| 1381 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 1382 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 1383 | * @fch_type: the type for the first frame of the sequence. |
| 1384 | * |
| 1385 | * This function is called with no lock held. This function uses the r_ctl and |
| 1386 | * type of the received sequence to find the correct callback function to call |
| 1387 | * to process the sequence. |
| 1388 | **/ |
| 1389 | static int |
| 1390 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1391 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 1392 | uint32_t fch_type) |
| 1393 | { |
| 1394 | int i; |
| 1395 | |
| 1396 | /* unSolicited Responses */ |
| 1397 | if (pring->prt[0].profile) { |
| 1398 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1399 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1400 | saveq); |
| 1401 | return 1; |
| 1402 | } |
| 1403 | /* We must search, based on rctl / type |
| 1404 | for the right routine */ |
| 1405 | for (i = 0; i < pring->num_mask; i++) { |
| 1406 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 1407 | (pring->prt[i].type == fch_type)) { |
| 1408 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1409 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1410 | (phba, pring, saveq); |
| 1411 | return 1; |
| 1412 | } |
| 1413 | } |
| 1414 | return 0; |
| 1415 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1416 | |
| 1417 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1418 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1419 | * @phba: Pointer to HBA context object. |
| 1420 | * @pring: Pointer to driver SLI ring object. |
| 1421 | * @saveq: Pointer to the unsolicited iocb. |
| 1422 | * |
| 1423 | * This function is called with no lock held by the ring event handler |
| 1424 | * when there is an unsolicited iocb posted to the response ring by the |
| 1425 | * firmware. This function gets the buffer associated with the iocbs |
| 1426 | * and calls the event handler for the ring. This function handles both |
| 1427 | * qring buffers and hbq buffers. |
| 1428 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1429 | * upper layer functions will free the iocb objects. |
| 1430 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | static int |
| 1432 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1433 | struct lpfc_iocbq *saveq) |
| 1434 | { |
| 1435 | IOCB_t * irsp; |
| 1436 | WORD5 * w5p; |
| 1437 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1438 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1439 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1440 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | |
| 1442 | match = 0; |
| 1443 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1444 | |
| 1445 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1446 | if (pring->lpfc_sli_rcv_async_status) |
| 1447 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1448 | else |
| 1449 | lpfc_printf_log(phba, |
| 1450 | KERN_WARNING, |
| 1451 | LOG_SLI, |
| 1452 | "0316 Ring %d handler: unexpected " |
| 1453 | "ASYNC_STATUS iocb received evt_code " |
| 1454 | "0x%x\n", |
| 1455 | pring->ringno, |
| 1456 | irsp->un.asyncstat.evt_code); |
| 1457 | return 1; |
| 1458 | } |
| 1459 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1460 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1461 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1462 | if (irsp->ulpBdeCount > 0) { |
| 1463 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1464 | irsp->un.ulpWord[3]); |
| 1465 | lpfc_in_buf_free(phba, dmzbuf); |
| 1466 | } |
| 1467 | |
| 1468 | if (irsp->ulpBdeCount > 1) { |
| 1469 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1470 | irsp->unsli3.sli3Words[3]); |
| 1471 | lpfc_in_buf_free(phba, dmzbuf); |
| 1472 | } |
| 1473 | |
| 1474 | if (irsp->ulpBdeCount > 2) { |
| 1475 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1476 | irsp->unsli3.sli3Words[7]); |
| 1477 | lpfc_in_buf_free(phba, dmzbuf); |
| 1478 | } |
| 1479 | |
| 1480 | return 1; |
| 1481 | } |
| 1482 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1483 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1484 | if (irsp->ulpBdeCount != 0) { |
| 1485 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1486 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1487 | if (!saveq->context2) |
| 1488 | lpfc_printf_log(phba, |
| 1489 | KERN_ERR, |
| 1490 | LOG_SLI, |
| 1491 | "0341 Ring %d Cannot find buffer for " |
| 1492 | "an unsolicited iocb. tag 0x%x\n", |
| 1493 | pring->ringno, |
| 1494 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1495 | } |
| 1496 | if (irsp->ulpBdeCount == 2) { |
| 1497 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1498 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1499 | if (!saveq->context3) |
| 1500 | lpfc_printf_log(phba, |
| 1501 | KERN_ERR, |
| 1502 | LOG_SLI, |
| 1503 | "0342 Ring %d Cannot find buffer for an" |
| 1504 | " unsolicited iocb. tag 0x%x\n", |
| 1505 | pring->ringno, |
| 1506 | irsp->unsli3.sli3Words[7]); |
| 1507 | } |
| 1508 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1509 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1510 | if (irsp->ulpBdeCount != 0) { |
| 1511 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1512 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1513 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1514 | lpfc_printf_log(phba, |
| 1515 | KERN_ERR, |
| 1516 | LOG_SLI, |
| 1517 | "0343 Ring %d Cannot find " |
| 1518 | "buffer for an unsolicited iocb" |
| 1519 | ". tag 0x%x\n", pring->ringno, |
| 1520 | irsp->un.ulpWord[3]); |
| 1521 | } |
| 1522 | if (irsp->ulpBdeCount == 2) { |
| 1523 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1524 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1525 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1526 | lpfc_printf_log(phba, |
| 1527 | KERN_ERR, |
| 1528 | LOG_SLI, |
| 1529 | "0344 Ring %d Cannot find " |
| 1530 | "buffer for an unsolicited " |
| 1531 | "iocb. tag 0x%x\n", |
| 1532 | pring->ringno, |
| 1533 | irsp->unsli3.sli3Words[7]); |
| 1534 | } |
| 1535 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1536 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1537 | if (irsp->ulpBdeCount != 0 && |
| 1538 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1539 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1540 | int found = 0; |
| 1541 | |
| 1542 | /* search continue save q for same XRI */ |
| 1543 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1544 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1545 | list_add_tail(&saveq->list, &iocbq->list); |
| 1546 | found = 1; |
| 1547 | break; |
| 1548 | } |
| 1549 | } |
| 1550 | if (!found) |
| 1551 | list_add_tail(&saveq->clist, |
| 1552 | &pring->iocb_continue_saveq); |
| 1553 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1554 | list_del_init(&iocbq->clist); |
| 1555 | saveq = iocbq; |
| 1556 | irsp = &(saveq->iocb); |
| 1557 | } else |
| 1558 | return 0; |
| 1559 | } |
| 1560 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1561 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1562 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1563 | Rctl = FC_ELS_REQ; |
| 1564 | Type = FC_ELS_DATA; |
| 1565 | } else { |
| 1566 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1567 | Rctl = w5p->hcsw.Rctl; |
| 1568 | Type = w5p->hcsw.Type; |
| 1569 | |
| 1570 | /* Firmware Workaround */ |
| 1571 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1572 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1573 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1574 | Rctl = FC_ELS_REQ; |
| 1575 | Type = FC_ELS_DATA; |
| 1576 | w5p->hcsw.Rctl = Rctl; |
| 1577 | w5p->hcsw.Type = Type; |
| 1578 | } |
| 1579 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1580 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1581 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1582 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1583 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1584 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1585 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1586 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1590 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1591 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1592 | * @phba: Pointer to HBA context object. |
| 1593 | * @pring: Pointer to driver SLI ring object. |
| 1594 | * @prspiocb: Pointer to response iocb object. |
| 1595 | * |
| 1596 | * This function looks up the iocb_lookup table to get the command iocb |
| 1597 | * corresponding to the given response iocb using the iotag of the |
| 1598 | * response iocb. This function is called with the hbalock held. |
| 1599 | * This function returns the command iocb object if it finds the command |
| 1600 | * iocb else returns NULL. |
| 1601 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1603 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1604 | struct lpfc_sli_ring *pring, |
| 1605 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1606 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1608 | uint16_t iotag; |
| 1609 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1610 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1612 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1613 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1614 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1615 | pring->txcmplq_cnt--; |
| 1616 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1620 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1621 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1622 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1623 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | return NULL; |
| 1625 | } |
| 1626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1627 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 1628 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 1629 | * @phba: Pointer to HBA context object. |
| 1630 | * @pring: Pointer to driver SLI ring object. |
| 1631 | * @iotag: IOCB tag. |
| 1632 | * |
| 1633 | * This function looks up the iocb_lookup table to get the command iocb |
| 1634 | * corresponding to the given iotag. This function is called with the |
| 1635 | * hbalock held. |
| 1636 | * This function returns the command iocb object if it finds the command |
| 1637 | * iocb else returns NULL. |
| 1638 | **/ |
| 1639 | static struct lpfc_iocbq * |
| 1640 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 1641 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 1642 | { |
| 1643 | struct lpfc_iocbq *cmd_iocb; |
| 1644 | |
| 1645 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1646 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
| 1647 | list_del_init(&cmd_iocb->list); |
| 1648 | pring->txcmplq_cnt--; |
| 1649 | return cmd_iocb; |
| 1650 | } |
| 1651 | |
| 1652 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 1653 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 1654 | iotag, phba->sli.last_iotag); |
| 1655 | return NULL; |
| 1656 | } |
| 1657 | |
| 1658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1659 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1660 | * @phba: Pointer to HBA context object. |
| 1661 | * @pring: Pointer to driver SLI ring object. |
| 1662 | * @saveq: Pointer to the response iocb to be processed. |
| 1663 | * |
| 1664 | * This function is called by the ring event handler for non-fcp |
| 1665 | * rings when there is a new response iocb in the response ring. |
| 1666 | * The caller is not required to hold any locks. This function |
| 1667 | * gets the command iocb associated with the response iocb and |
| 1668 | * calls the completion handler for the command iocb. If there |
| 1669 | * is no completion handler, the function will free the resources |
| 1670 | * associated with command iocb. If the response iocb is for |
| 1671 | * an already aborted command iocb, the status of the completion |
| 1672 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1673 | * This function always returns 1. |
| 1674 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | struct lpfc_iocbq *saveq) |
| 1678 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1679 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1680 | int rc = 1; |
| 1681 | unsigned long iflag; |
| 1682 | |
| 1683 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1684 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1685 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1687 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | if (cmdiocbp) { |
| 1689 | if (cmdiocbp->iocb_cmpl) { |
| 1690 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1691 | * If an ELS command failed send an event to mgmt |
| 1692 | * application. |
| 1693 | */ |
| 1694 | if (saveq->iocb.ulpStatus && |
| 1695 | (pring->ringno == LPFC_ELS_RING) && |
| 1696 | (cmdiocbp->iocb.ulpCommand == |
| 1697 | CMD_ELS_REQUEST64_CR)) |
| 1698 | lpfc_send_els_failure_event(phba, |
| 1699 | cmdiocbp, saveq); |
| 1700 | |
| 1701 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | * Post all ELS completions to the worker thread. |
| 1703 | * All other are passed to the completion callback. |
| 1704 | */ |
| 1705 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1706 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1707 | cmdiocbp->iocb_flag &= |
| 1708 | ~LPFC_DRIVER_ABORTED; |
| 1709 | saveq->iocb.ulpStatus = |
| 1710 | IOSTAT_LOCAL_REJECT; |
| 1711 | saveq->iocb.un.ulpWord[4] = |
| 1712 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1713 | |
| 1714 | /* Firmware could still be in progress |
| 1715 | * of DMAing payload, so don't free data |
| 1716 | * buffer till after a hbeat. |
| 1717 | */ |
| 1718 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1719 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1720 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1722 | } else |
| 1723 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1724 | } else { |
| 1725 | /* |
| 1726 | * Unknown initiating command based on the response iotag. |
| 1727 | * This could be the case on the ELS ring because of |
| 1728 | * lpfc_els_abort(). |
| 1729 | */ |
| 1730 | if (pring->ringno != LPFC_ELS_RING) { |
| 1731 | /* |
| 1732 | * Ring <ringno> handler: unexpected completion IoTag |
| 1733 | * <IoTag> |
| 1734 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1735 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1736 | "0322 Ring %d handler: " |
| 1737 | "unexpected completion IoTag x%x " |
| 1738 | "Data: x%x x%x x%x x%x\n", |
| 1739 | pring->ringno, |
| 1740 | saveq->iocb.ulpIoTag, |
| 1741 | saveq->iocb.ulpStatus, |
| 1742 | saveq->iocb.un.ulpWord[4], |
| 1743 | saveq->iocb.ulpCommand, |
| 1744 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | } |
| 1746 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | return rc; |
| 1749 | } |
| 1750 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1751 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1752 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1753 | * @phba: Pointer to HBA context object. |
| 1754 | * @pring: Pointer to driver SLI ring object. |
| 1755 | * |
| 1756 | * This function is called from the iocb ring event handlers when |
| 1757 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1758 | * an error attention condition to the worker thread and the worker |
| 1759 | * thread will transition the HBA to offline state. |
| 1760 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1761 | static void |
| 1762 | 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] | 1763 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1764 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1765 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1766 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1767 | * rsp ring <portRspMax> |
| 1768 | */ |
| 1769 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1770 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1771 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1772 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1773 | pring->numRiocb); |
| 1774 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1775 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1776 | |
| 1777 | /* |
| 1778 | * All error attention handlers are posted to |
| 1779 | * worker thread |
| 1780 | */ |
| 1781 | phba->work_ha |= HA_ERATT; |
| 1782 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1783 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1784 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1785 | |
| 1786 | return; |
| 1787 | } |
| 1788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1790 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1791 | * @ptr: Pointer to address of HBA context object. |
| 1792 | * |
| 1793 | * This function is invoked by the Error Attention polling timer when the |
| 1794 | * timer times out. It will check the SLI Error Attention register for |
| 1795 | * possible attention events. If so, it will post an Error Attention event |
| 1796 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1797 | * Error Attention polling timer for the next poll. |
| 1798 | **/ |
| 1799 | void lpfc_poll_eratt(unsigned long ptr) |
| 1800 | { |
| 1801 | struct lpfc_hba *phba; |
| 1802 | uint32_t eratt = 0; |
| 1803 | |
| 1804 | phba = (struct lpfc_hba *)ptr; |
| 1805 | |
| 1806 | /* Check chip HA register for error event */ |
| 1807 | eratt = lpfc_sli_check_eratt(phba); |
| 1808 | |
| 1809 | if (eratt) |
| 1810 | /* Tell the worker thread there is work to do */ |
| 1811 | lpfc_worker_wake_up(phba); |
| 1812 | else |
| 1813 | /* Restart the timer for next eratt poll */ |
| 1814 | mod_timer(&phba->eratt_poll, jiffies + |
| 1815 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1816 | return; |
| 1817 | } |
| 1818 | |
| 1819 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1820 | * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1821 | * @phba: Pointer to HBA context object. |
| 1822 | * |
| 1823 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1824 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1825 | * is enabled. |
| 1826 | * |
| 1827 | * The caller does not hold any lock. |
| 1828 | * The function processes each response iocb in the response ring until it |
| 1829 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1830 | * LE bit set. The function will call the completion handler of the command iocb |
| 1831 | * if the response iocb indicates a completion for a command iocb or it is |
| 1832 | * an abort completion. |
| 1833 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1834 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1835 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | struct lpfc_sli *psli = &phba->sli; |
| 1837 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1838 | IOCB_t *irsp = NULL; |
| 1839 | IOCB_t *entry = NULL; |
| 1840 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1841 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1842 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1843 | uint32_t status; |
| 1844 | uint32_t portRspPut, portRspMax; |
| 1845 | int type; |
| 1846 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1847 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1848 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1849 | |
| 1850 | pring->stats.iocb_event++; |
| 1851 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1852 | /* |
| 1853 | * The next available response entry should never exceed the maximum |
| 1854 | * entries. If it does, treat it as an adapter hardware error. |
| 1855 | */ |
| 1856 | portRspMax = pring->numRiocb; |
| 1857 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1858 | if (unlikely(portRspPut >= portRspMax)) { |
| 1859 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1860 | return; |
| 1861 | } |
| 1862 | |
| 1863 | rmb(); |
| 1864 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1865 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1866 | if (++pring->rspidx >= portRspMax) |
| 1867 | pring->rspidx = 0; |
| 1868 | |
| 1869 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1870 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1871 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1872 | irsp = &rspiocbq.iocb; |
| 1873 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1874 | pring->stats.iocb_rsp++; |
| 1875 | rsp_cmpl++; |
| 1876 | |
| 1877 | if (unlikely(irsp->ulpStatus)) { |
| 1878 | /* Rsp ring <ringno> error: IOCB */ |
| 1879 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1880 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1881 | "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] | 1882 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1883 | irsp->un.ulpWord[0], |
| 1884 | irsp->un.ulpWord[1], |
| 1885 | irsp->un.ulpWord[2], |
| 1886 | irsp->un.ulpWord[3], |
| 1887 | irsp->un.ulpWord[4], |
| 1888 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1889 | *(uint32_t *)&irsp->un1, |
| 1890 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | switch (type) { |
| 1894 | case LPFC_ABORT_IOCB: |
| 1895 | case LPFC_SOL_IOCB: |
| 1896 | /* |
| 1897 | * Idle exchange closed via ABTS from port. No iocb |
| 1898 | * resources need to be recovered. |
| 1899 | */ |
| 1900 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1901 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1902 | "0314 IOCB cmd 0x%x " |
| 1903 | "processed. Skipping " |
| 1904 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1905 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1906 | break; |
| 1907 | } |
| 1908 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1910 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1911 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1912 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1913 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1914 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1915 | &rspiocbq); |
| 1916 | } |
| 1917 | break; |
| 1918 | default: |
| 1919 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1920 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1921 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1922 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1923 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1924 | dev_warn(&((phba->pcidev)->dev), |
| 1925 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1926 | phba->brd_no, adaptermsg); |
| 1927 | } else { |
| 1928 | /* Unknown IOCB command */ |
| 1929 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1930 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1931 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1932 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1933 | irsp->ulpStatus, |
| 1934 | irsp->ulpIoTag, |
| 1935 | irsp->ulpContext); |
| 1936 | } |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | /* |
| 1941 | * The response IOCB has been processed. Update the ring |
| 1942 | * pointer in SLIM. If the port response put pointer has not |
| 1943 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1944 | * response put pointer. |
| 1945 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1946 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1947 | |
| 1948 | if (pring->rspidx == portRspPut) |
| 1949 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1950 | } |
| 1951 | |
| 1952 | ha_copy = readl(phba->HAregaddr); |
| 1953 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1954 | |
| 1955 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1957 | pring->stats.iocb_rsp_full++; |
| 1958 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1959 | writel(status, phba->CAregaddr); |
| 1960 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1962 | } |
| 1963 | if ((ha_copy & HA_R0CE_RSP) && |
| 1964 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1966 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1967 | pring->stats.iocb_cmd_empty++; |
| 1968 | |
| 1969 | /* Force update of the local copy of cmdGetInx */ |
| 1970 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1971 | lpfc_sli_resume_iocb(phba, pring); |
| 1972 | |
| 1973 | if ((pring->lpfc_sli_cmd_available)) |
| 1974 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | return; |
| 1980 | } |
| 1981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1983 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1984 | * @phba: Pointer to HBA context object. |
| 1985 | * @pring: Pointer to driver SLI ring object. |
| 1986 | * @mask: Host attention register mask for this ring. |
| 1987 | * |
| 1988 | * This function is called from the interrupt context when there is a ring |
| 1989 | * event for the fcp ring. The caller does not hold any lock. |
| 1990 | * The function processes each response iocb in the response ring until it |
| 1991 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1992 | * LE bit set. The function will call the completion handler of the command iocb |
| 1993 | * if the response iocb indicates a completion for a command iocb or it is |
| 1994 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1995 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1997 | * to check it explicitly. This function always returns 1. |
| 1998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2000 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2001 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2003 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2005 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2007 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | uint32_t status; |
| 2009 | uint32_t portRspPut, portRspMax; |
| 2010 | int rc = 1; |
| 2011 | lpfc_iocb_type type; |
| 2012 | unsigned long iflag; |
| 2013 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2015 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | pring->stats.iocb_event++; |
| 2017 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | /* |
| 2019 | * The next available response entry should never exceed the maximum |
| 2020 | * entries. If it does, treat it as an adapter hardware error. |
| 2021 | */ |
| 2022 | portRspMax = pring->numRiocb; |
| 2023 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2024 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2025 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2026 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | return 1; |
| 2028 | } |
| 2029 | |
| 2030 | rmb(); |
| 2031 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2032 | /* |
| 2033 | * Fetch an entry off the ring and copy it into a local data |
| 2034 | * structure. The copy involves a byte-swap since the |
| 2035 | * network byte order and pci byte orders are different. |
| 2036 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2037 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2038 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2039 | |
| 2040 | if (++pring->rspidx >= portRspMax) |
| 2041 | pring->rspidx = 0; |
| 2042 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2043 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2044 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2046 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2047 | irsp = &rspiocbq.iocb; |
| 2048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2050 | pring->stats.iocb_rsp++; |
| 2051 | rsp_cmpl++; |
| 2052 | |
| 2053 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | /* |
| 2055 | * If resource errors reported from HBA, reduce |
| 2056 | * queuedepths of the SCSI device. |
| 2057 | */ |
| 2058 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2059 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2060 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2061 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2062 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2063 | } |
| 2064 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | /* Rsp ring <ringno> error: IOCB */ |
| 2066 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2067 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2068 | "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] | 2069 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2070 | irsp->un.ulpWord[0], |
| 2071 | irsp->un.ulpWord[1], |
| 2072 | irsp->un.ulpWord[2], |
| 2073 | irsp->un.ulpWord[3], |
| 2074 | irsp->un.ulpWord[4], |
| 2075 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2076 | *(uint32_t *)&irsp->un1, |
| 2077 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | switch (type) { |
| 2081 | case LPFC_ABORT_IOCB: |
| 2082 | case LPFC_SOL_IOCB: |
| 2083 | /* |
| 2084 | * Idle exchange closed via ABTS from port. No iocb |
| 2085 | * resources need to be recovered. |
| 2086 | */ |
| 2087 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2088 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2089 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2090 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2091 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2092 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | break; |
| 2094 | } |
| 2095 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2096 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2097 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2099 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2100 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2101 | &rspiocbq); |
| 2102 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2103 | spin_unlock_irqrestore(&phba->hbalock, |
| 2104 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2105 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2106 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2108 | iflag); |
| 2109 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | } |
| 2111 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2112 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2113 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2114 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2115 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2116 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | default: |
| 2118 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2119 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2120 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2121 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2122 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2123 | dev_warn(&((phba->pcidev)->dev), |
| 2124 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | phba->brd_no, adaptermsg); |
| 2126 | } else { |
| 2127 | /* Unknown IOCB command */ |
| 2128 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2129 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2130 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2131 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2132 | irsp->ulpStatus, |
| 2133 | irsp->ulpIoTag, |
| 2134 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | } |
| 2136 | break; |
| 2137 | } |
| 2138 | |
| 2139 | /* |
| 2140 | * The response IOCB has been processed. Update the ring |
| 2141 | * pointer in SLIM. If the port response put pointer has not |
| 2142 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2143 | * response put pointer. |
| 2144 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2145 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | |
| 2147 | if (pring->rspidx == portRspPut) |
| 2148 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2149 | } |
| 2150 | |
| 2151 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2152 | pring->stats.iocb_rsp_full++; |
| 2153 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2154 | writel(status, phba->CAregaddr); |
| 2155 | readl(phba->CAregaddr); |
| 2156 | } |
| 2157 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2158 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2159 | pring->stats.iocb_cmd_empty++; |
| 2160 | |
| 2161 | /* Force update of the local copy of cmdGetInx */ |
| 2162 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2163 | lpfc_sli_resume_iocb(phba, pring); |
| 2164 | |
| 2165 | if ((pring->lpfc_sli_cmd_available)) |
| 2166 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2167 | |
| 2168 | } |
| 2169 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | return rc; |
| 2172 | } |
| 2173 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2174 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2175 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 2176 | * @phba: Pointer to HBA context object. |
| 2177 | * @pring: Pointer to driver SLI ring object. |
| 2178 | * @rspiocbp: Pointer to driver response IOCB object. |
| 2179 | * |
| 2180 | * This function is called from the worker thread when there is a slow-path |
| 2181 | * response IOCB to process. This function chains all the response iocbs until |
| 2182 | * seeing the iocb with the LE bit set. The function will call |
| 2183 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 2184 | * completion of a command iocb. The function will call the |
| 2185 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 2186 | * The function frees the resources or calls the completion handler if this |
| 2187 | * iocb is an abort completion. The function returns NULL when the response |
| 2188 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 2189 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 2190 | * response iocb passed in. |
| 2191 | **/ |
| 2192 | static struct lpfc_iocbq * |
| 2193 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2194 | struct lpfc_iocbq *rspiocbp) |
| 2195 | { |
| 2196 | struct lpfc_iocbq *saveq; |
| 2197 | struct lpfc_iocbq *cmdiocbp; |
| 2198 | struct lpfc_iocbq *next_iocb; |
| 2199 | IOCB_t *irsp = NULL; |
| 2200 | uint32_t free_saveq; |
| 2201 | uint8_t iocb_cmd_type; |
| 2202 | lpfc_iocb_type type; |
| 2203 | unsigned long iflag; |
| 2204 | int rc; |
| 2205 | |
| 2206 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2207 | /* First add the response iocb to the countinueq list */ |
| 2208 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 2209 | pring->iocb_continueq_cnt++; |
| 2210 | |
| 2211 | /* Now, determine whetehr the list is completed for processing */ |
| 2212 | irsp = &rspiocbp->iocb; |
| 2213 | if (irsp->ulpLe) { |
| 2214 | /* |
| 2215 | * By default, the driver expects to free all resources |
| 2216 | * associated with this iocb completion. |
| 2217 | */ |
| 2218 | free_saveq = 1; |
| 2219 | saveq = list_get_first(&pring->iocb_continueq, |
| 2220 | struct lpfc_iocbq, list); |
| 2221 | irsp = &(saveq->iocb); |
| 2222 | list_del_init(&pring->iocb_continueq); |
| 2223 | pring->iocb_continueq_cnt = 0; |
| 2224 | |
| 2225 | pring->stats.iocb_rsp++; |
| 2226 | |
| 2227 | /* |
| 2228 | * If resource errors reported from HBA, reduce |
| 2229 | * queuedepths of the SCSI device. |
| 2230 | */ |
| 2231 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2232 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2233 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2234 | phba->lpfc_rampdown_queue_depth(phba); |
| 2235 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2236 | } |
| 2237 | |
| 2238 | if (irsp->ulpStatus) { |
| 2239 | /* Rsp ring <ringno> error: IOCB */ |
| 2240 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 2241 | "0328 Rsp Ring %d error: " |
| 2242 | "IOCB Data: " |
| 2243 | "x%x x%x x%x x%x " |
| 2244 | "x%x x%x x%x x%x " |
| 2245 | "x%x x%x x%x x%x " |
| 2246 | "x%x x%x x%x x%x\n", |
| 2247 | pring->ringno, |
| 2248 | irsp->un.ulpWord[0], |
| 2249 | irsp->un.ulpWord[1], |
| 2250 | irsp->un.ulpWord[2], |
| 2251 | irsp->un.ulpWord[3], |
| 2252 | irsp->un.ulpWord[4], |
| 2253 | irsp->un.ulpWord[5], |
| 2254 | *(((uint32_t *) irsp) + 6), |
| 2255 | *(((uint32_t *) irsp) + 7), |
| 2256 | *(((uint32_t *) irsp) + 8), |
| 2257 | *(((uint32_t *) irsp) + 9), |
| 2258 | *(((uint32_t *) irsp) + 10), |
| 2259 | *(((uint32_t *) irsp) + 11), |
| 2260 | *(((uint32_t *) irsp) + 12), |
| 2261 | *(((uint32_t *) irsp) + 13), |
| 2262 | *(((uint32_t *) irsp) + 14), |
| 2263 | *(((uint32_t *) irsp) + 15)); |
| 2264 | } |
| 2265 | |
| 2266 | /* |
| 2267 | * Fetch the IOCB command type and call the correct completion |
| 2268 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 2269 | * get freed back to the lpfc_iocb_list by the discovery |
| 2270 | * kernel thread. |
| 2271 | */ |
| 2272 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2273 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2274 | switch (type) { |
| 2275 | case LPFC_SOL_IOCB: |
| 2276 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2277 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 2278 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2279 | break; |
| 2280 | |
| 2281 | case LPFC_UNSOL_IOCB: |
| 2282 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2283 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 2284 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2285 | if (!rc) |
| 2286 | free_saveq = 0; |
| 2287 | break; |
| 2288 | |
| 2289 | case LPFC_ABORT_IOCB: |
| 2290 | cmdiocbp = NULL; |
| 2291 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 2292 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 2293 | saveq); |
| 2294 | if (cmdiocbp) { |
| 2295 | /* Call the specified completion routine */ |
| 2296 | if (cmdiocbp->iocb_cmpl) { |
| 2297 | spin_unlock_irqrestore(&phba->hbalock, |
| 2298 | iflag); |
| 2299 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 2300 | saveq); |
| 2301 | spin_lock_irqsave(&phba->hbalock, |
| 2302 | iflag); |
| 2303 | } else |
| 2304 | __lpfc_sli_release_iocbq(phba, |
| 2305 | cmdiocbp); |
| 2306 | } |
| 2307 | break; |
| 2308 | |
| 2309 | case LPFC_UNKNOWN_IOCB: |
| 2310 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2311 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2312 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2313 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 2314 | MAX_MSG_DATA); |
| 2315 | dev_warn(&((phba->pcidev)->dev), |
| 2316 | "lpfc%d: %s\n", |
| 2317 | phba->brd_no, adaptermsg); |
| 2318 | } else { |
| 2319 | /* Unknown IOCB command */ |
| 2320 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2321 | "0335 Unknown IOCB " |
| 2322 | "command Data: x%x " |
| 2323 | "x%x x%x x%x\n", |
| 2324 | irsp->ulpCommand, |
| 2325 | irsp->ulpStatus, |
| 2326 | irsp->ulpIoTag, |
| 2327 | irsp->ulpContext); |
| 2328 | } |
| 2329 | break; |
| 2330 | } |
| 2331 | |
| 2332 | if (free_saveq) { |
| 2333 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2334 | &saveq->list, list) { |
| 2335 | list_del(&rspiocbp->list); |
| 2336 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 2337 | } |
| 2338 | __lpfc_sli_release_iocbq(phba, saveq); |
| 2339 | } |
| 2340 | rspiocbp = NULL; |
| 2341 | } |
| 2342 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2343 | return rspiocbp; |
| 2344 | } |
| 2345 | |
| 2346 | /** |
| 2347 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2348 | * @phba: Pointer to HBA context object. |
| 2349 | * @pring: Pointer to driver SLI ring object. |
| 2350 | * @mask: Host attention register mask for this ring. |
| 2351 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2352 | * This routine wraps the actual slow_ring event process routine from the |
| 2353 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2354 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2355 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2357 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2359 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 2364 | * @phba: Pointer to HBA context object. |
| 2365 | * @pring: Pointer to driver SLI ring object. |
| 2366 | * @mask: Host attention register mask for this ring. |
| 2367 | * |
| 2368 | * This function is called from the worker thread when there is a ring event |
| 2369 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 2370 | * remove each response iocb in the response ring and calls the handle |
| 2371 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 2372 | **/ |
| 2373 | static void |
| 2374 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 2375 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 2376 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2377 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | IOCB_t *entry; |
| 2379 | IOCB_t *irsp = NULL; |
| 2380 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2383 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2385 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2386 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | pring->stats.iocb_event++; |
| 2388 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | /* |
| 2390 | * The next available response entry should never exceed the maximum |
| 2391 | * entries. If it does, treat it as an adapter hardware error. |
| 2392 | */ |
| 2393 | portRspMax = pring->numRiocb; |
| 2394 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2395 | if (portRspPut >= portRspMax) { |
| 2396 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2397 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | * rsp ring <portRspMax> |
| 2399 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2400 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2401 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2402 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2403 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | phba->link_state = LPFC_HBA_ERROR; |
| 2406 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | |
| 2408 | phba->work_hs = HS_FFER3; |
| 2409 | lpfc_handle_eratt(phba); |
| 2410 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2411 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | while (pring->rspidx != portRspPut) { |
| 2416 | /* |
| 2417 | * Build a completion list and call the appropriate handler. |
| 2418 | * The process is to get the next available response iocb, get |
| 2419 | * a free iocb from the list, copy the response data into the |
| 2420 | * free iocb, insert to the continuation list, and update the |
| 2421 | * next response index to slim. This process makes response |
| 2422 | * iocb's in the ring available to DMA as fast as possible but |
| 2423 | * pays a penalty for a copy operation. Since the iocb is |
| 2424 | * only 32 bytes, this penalty is considered small relative to |
| 2425 | * the PCI reads for register values and a slim write. When |
| 2426 | * the ulpLe field is set, the entire Command has been |
| 2427 | * received. |
| 2428 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2429 | entry = lpfc_resp_iocb(phba, pring); |
| 2430 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2431 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2432 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | if (rspiocbp == NULL) { |
| 2434 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2435 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | break; |
| 2437 | } |
| 2438 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2439 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2440 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | irsp = &rspiocbp->iocb; |
| 2442 | |
| 2443 | if (++pring->rspidx >= portRspMax) |
| 2444 | pring->rspidx = 0; |
| 2445 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2446 | if (pring->ringno == LPFC_ELS_RING) { |
| 2447 | lpfc_debugfs_slow_ring_trc(phba, |
| 2448 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2449 | *(((uint32_t *) irsp) + 4), |
| 2450 | *(((uint32_t *) irsp) + 6), |
| 2451 | *(((uint32_t *) irsp) + 7)); |
| 2452 | } |
| 2453 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2454 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2456 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2457 | /* Handle the response IOCB */ |
| 2458 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 2459 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | |
| 2461 | /* |
| 2462 | * If the port response put pointer has not been updated, sync |
| 2463 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2464 | * response put pointer. |
| 2465 | */ |
| 2466 | if (pring->rspidx == portRspPut) { |
| 2467 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2468 | } |
| 2469 | } /* while (pring->rspidx != portRspPut) */ |
| 2470 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2471 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | /* At least one response entry has been freed */ |
| 2473 | pring->stats.iocb_rsp_full++; |
| 2474 | /* SET RxRE_RSP in Chip Att register */ |
| 2475 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2476 | writel(status, phba->CAregaddr); |
| 2477 | readl(phba->CAregaddr); /* flush */ |
| 2478 | } |
| 2479 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2480 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2481 | pring->stats.iocb_cmd_empty++; |
| 2482 | |
| 2483 | /* Force update of the local copy of cmdGetInx */ |
| 2484 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2485 | lpfc_sli_resume_iocb(phba, pring); |
| 2486 | |
| 2487 | if ((pring->lpfc_sli_cmd_available)) |
| 2488 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2489 | |
| 2490 | } |
| 2491 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2492 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2493 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2494 | } |
| 2495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2497 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2498 | * @phba: Pointer to HBA context object. |
| 2499 | * @pring: Pointer to driver SLI ring object. |
| 2500 | * |
| 2501 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2502 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2503 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2504 | * the return of this function. The caller is not required to hold any locks. |
| 2505 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2506 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2508 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2509 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2510 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | if (pring->ringno == LPFC_ELS_RING) { |
| 2513 | lpfc_fabric_abort_hba(phba); |
| 2514 | } |
| 2515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | /* Error everything on txq and txcmplq |
| 2517 | * First do the txq. |
| 2518 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2519 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2520 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | |
| 2523 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2524 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2525 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2526 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2527 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2528 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2529 | /* Cancel all the IOCBs from the completions list */ |
| 2530 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 2531 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | } |
| 2533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2535 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2536 | * @phba: Pointer to HBA context object. |
| 2537 | * |
| 2538 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2539 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2540 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2541 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2542 | * slot has been permanently disabled. |
| 2543 | **/ |
| 2544 | void |
| 2545 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2546 | { |
| 2547 | LIST_HEAD(txq); |
| 2548 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2549 | struct lpfc_sli *psli = &phba->sli; |
| 2550 | struct lpfc_sli_ring *pring; |
| 2551 | |
| 2552 | /* Currently, only one fcp ring */ |
| 2553 | pring = &psli->ring[psli->fcp_ring]; |
| 2554 | |
| 2555 | spin_lock_irq(&phba->hbalock); |
| 2556 | /* Retrieve everything on txq */ |
| 2557 | list_splice_init(&pring->txq, &txq); |
| 2558 | pring->txq_cnt = 0; |
| 2559 | |
| 2560 | /* Retrieve everything on the txcmplq */ |
| 2561 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2562 | pring->txcmplq_cnt = 0; |
| 2563 | spin_unlock_irq(&phba->hbalock); |
| 2564 | |
| 2565 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2566 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 2567 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2568 | |
| 2569 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2570 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 2571 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2575 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2576 | * @phba: Pointer to HBA context object. |
| 2577 | * @mask: Bit mask to be checked. |
| 2578 | * |
| 2579 | * This function reads the host status register and compares |
| 2580 | * with the provided bit mask to check if HBA completed |
| 2581 | * the restart. This function will wait in a loop for the |
| 2582 | * HBA to complete restart. If the HBA does not restart within |
| 2583 | * 15 iterations, the function will reset the HBA again. The |
| 2584 | * function returns 1 when HBA fail to restart otherwise returns |
| 2585 | * zero. |
| 2586 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2587 | static int |
| 2588 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2590 | uint32_t status; |
| 2591 | int i = 0; |
| 2592 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2594 | /* Read the HBA Host Status Register */ |
| 2595 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2597 | /* |
| 2598 | * Check status register every 100ms for 5 retries, then every |
| 2599 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2600 | * every 2.5 sec for 4. |
| 2601 | * Break our of the loop if errors occurred during init. |
| 2602 | */ |
| 2603 | while (((status & mask) != mask) && |
| 2604 | !(status & HS_FFERM) && |
| 2605 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2607 | if (i <= 5) |
| 2608 | msleep(10); |
| 2609 | else if (i <= 10) |
| 2610 | msleep(500); |
| 2611 | else |
| 2612 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2614 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2615 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2616 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2617 | lpfc_sli_brdrestart(phba); |
| 2618 | } |
| 2619 | /* Read the HBA Host Status Register */ |
| 2620 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2623 | /* Check to see if any errors occurred during init */ |
| 2624 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2625 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2626 | retval = 1; |
| 2627 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2629 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | } |
| 2631 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2632 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2635 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2636 | * @phba: Pointer to HBA context object. |
| 2637 | * |
| 2638 | * This function is called before resetting an HBA. This |
| 2639 | * function requests HBA to quiesce DMAs before a reset. |
| 2640 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2641 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2642 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2643 | uint32_t __iomem *resp_buf; |
| 2644 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2645 | volatile uint32_t mbox; |
| 2646 | uint32_t hc_copy; |
| 2647 | int i; |
| 2648 | uint8_t hdrtype; |
| 2649 | |
| 2650 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2651 | if (hdrtype != 0x80 || |
| 2652 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2653 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2654 | return; |
| 2655 | |
| 2656 | /* |
| 2657 | * Tell the other part of the chip to suspend temporarily all |
| 2658 | * its DMA activity. |
| 2659 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2660 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2661 | |
| 2662 | /* Disable the error attention */ |
| 2663 | hc_copy = readl(phba->HCregaddr); |
| 2664 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2665 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2667 | |
| 2668 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2669 | /* Clear Chip error bit */ |
| 2670 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | mbox = 0; |
| 2675 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2676 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2677 | |
| 2678 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2679 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2680 | writel(mbox, mbox_buf); |
| 2681 | |
| 2682 | for (i = 0; |
| 2683 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2684 | mdelay(1); |
| 2685 | |
| 2686 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2687 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2688 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2689 | goto restore_hc; |
| 2690 | else |
| 2691 | goto clear_errat; |
| 2692 | } |
| 2693 | |
| 2694 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2695 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2696 | mdelay(1); |
| 2697 | |
| 2698 | clear_errat: |
| 2699 | |
| 2700 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2701 | mdelay(1); |
| 2702 | |
| 2703 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2704 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2705 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2709 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2710 | writel(hc_copy, phba->HCregaddr); |
| 2711 | readl(phba->HCregaddr); /* flush */ |
| 2712 | } |
| 2713 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2714 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2715 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2716 | * @phba: Pointer to HBA context object. |
| 2717 | * |
| 2718 | * This function issues a kill_board mailbox command and waits for |
| 2719 | * the error attention interrupt. This function is called for stopping |
| 2720 | * the firmware processing. The caller is not required to hold any |
| 2721 | * locks. This function calls lpfc_hba_down_post function to free |
| 2722 | * any pending commands after the kill. The function will return 1 when it |
| 2723 | * fails to kill the board else will return 0. |
| 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_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2728 | struct lpfc_sli *psli; |
| 2729 | LPFC_MBOXQ_t *pmb; |
| 2730 | uint32_t status; |
| 2731 | uint32_t ha_copy; |
| 2732 | int retval; |
| 2733 | int i = 0; |
| 2734 | |
| 2735 | psli = &phba->sli; |
| 2736 | |
| 2737 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2738 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2739 | "0329 Kill HBA Data: x%x x%x\n", |
| 2740 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2741 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2742 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2743 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2744 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2745 | |
| 2746 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2747 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2748 | status = readl(phba->HCregaddr); |
| 2749 | status &= ~HC_ERINT_ENA; |
| 2750 | writel(status, phba->HCregaddr); |
| 2751 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2752 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2753 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2754 | |
| 2755 | lpfc_kill_board(phba, pmb); |
| 2756 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2757 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2758 | |
| 2759 | if (retval != MBX_SUCCESS) { |
| 2760 | if (retval != MBX_BUSY) |
| 2761 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | spin_lock_irq(&phba->hbalock); |
| 2763 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2764 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2765 | return 1; |
| 2766 | } |
| 2767 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2768 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2769 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2770 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2771 | |
| 2772 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2773 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2774 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2775 | * board is now undefined. |
| 2776 | */ |
| 2777 | ha_copy = readl(phba->HAregaddr); |
| 2778 | |
| 2779 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2780 | mdelay(100); |
| 2781 | ha_copy = readl(phba->HAregaddr); |
| 2782 | } |
| 2783 | |
| 2784 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2785 | if (ha_copy & HA_ERATT) { |
| 2786 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2787 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2788 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2789 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2790 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2791 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2792 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2793 | |
| 2794 | psli->mbox_active = NULL; |
| 2795 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2796 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2797 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2798 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2799 | } |
| 2800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2801 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2802 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2803 | * @phba: Pointer to HBA context object. |
| 2804 | * |
| 2805 | * This function resets the HBA by writing HC_INITFF to the control |
| 2806 | * register. After the HBA resets, this function resets all the iocb ring |
| 2807 | * indices. This function disables PCI layer parity checking during |
| 2808 | * the reset. |
| 2809 | * This function returns 0 always. |
| 2810 | * The caller is not required to hold any locks. |
| 2811 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2812 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2813 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2814 | { |
| 2815 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2817 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2820 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2822 | /* Reset HBA */ |
| 2823 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2824 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2825 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | |
| 2827 | /* perform board reset */ |
| 2828 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2829 | phba->pport->fc_myDID = 0; |
| 2830 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2832 | /* Turn off parity checking and serr during the physical reset */ |
| 2833 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2834 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2835 | (cfg_value & |
| 2836 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2837 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 2838 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 2839 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2840 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2841 | writel(HC_INITFF, phba->HCregaddr); |
| 2842 | mdelay(1); |
| 2843 | readl(phba->HCregaddr); /* flush */ |
| 2844 | writel(0, phba->HCregaddr); |
| 2845 | readl(phba->HCregaddr); /* flush */ |
| 2846 | |
| 2847 | /* Restore PCI cmd register */ |
| 2848 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | |
| 2850 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2851 | for (i = 0; i < psli->num_rings; i++) { |
| 2852 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | pring->flag = 0; |
| 2854 | pring->rspidx = 0; |
| 2855 | pring->next_cmdidx = 0; |
| 2856 | pring->local_getidx = 0; |
| 2857 | pring->cmdidx = 0; |
| 2858 | pring->missbufcnt = 0; |
| 2859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2861 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2862 | return 0; |
| 2863 | } |
| 2864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2866 | * lpfc_sli_brdrestart - Restart the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2867 | * @phba: Pointer to HBA context object. |
| 2868 | * |
| 2869 | * This function is called in the SLI initialization code path to |
| 2870 | * restart the HBA. The caller is not required to hold any lock. |
| 2871 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2872 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2873 | * function to free any pending commands. The function enables |
| 2874 | * POST only during the first initialization. The function returns zero. |
| 2875 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2876 | * command before the return of this function. |
| 2877 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2878 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2880 | { |
| 2881 | MAILBOX_t *mb; |
| 2882 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2883 | volatile uint32_t word0; |
| 2884 | void __iomem *to_slim; |
| 2885 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2887 | |
| 2888 | psli = &phba->sli; |
| 2889 | |
| 2890 | /* Restart HBA */ |
| 2891 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2892 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2893 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2894 | |
| 2895 | word0 = 0; |
| 2896 | mb = (MAILBOX_t *) &word0; |
| 2897 | mb->mbxCommand = MBX_RESTART; |
| 2898 | mb->mbxHc = 1; |
| 2899 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2900 | lpfc_reset_barrier(phba); |
| 2901 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2902 | to_slim = phba->MBslimaddr; |
| 2903 | writel(*(uint32_t *) mb, to_slim); |
| 2904 | readl(to_slim); /* flush */ |
| 2905 | |
| 2906 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2907 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2908 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2909 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2910 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2911 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2912 | writel(*(uint32_t *) mb, to_slim); |
| 2913 | readl(to_slim); /* flush */ |
| 2914 | |
| 2915 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2916 | phba->pport->stopped = 0; |
| 2917 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2918 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2919 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2920 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2921 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2922 | psli->stats_start = get_seconds(); |
| 2923 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2924 | /* Give the INITFF and Post time to settle. */ |
| 2925 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2927 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2928 | |
| 2929 | return 0; |
| 2930 | } |
| 2931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2932 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2933 | * 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] | 2934 | * @phba: Pointer to HBA context object. |
| 2935 | * |
| 2936 | * This function is called after a HBA restart to wait for successful |
| 2937 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2938 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2939 | * iteration, the function will restart the HBA again. The function returns |
| 2940 | * zero if HBA successfully restarted else returns negative error code. |
| 2941 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | static int |
| 2943 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2944 | { |
| 2945 | uint32_t status, i = 0; |
| 2946 | |
| 2947 | /* Read the HBA Host Status Register */ |
| 2948 | status = readl(phba->HSregaddr); |
| 2949 | |
| 2950 | /* Check status register to see what current state is */ |
| 2951 | i = 0; |
| 2952 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2953 | |
| 2954 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2955 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2956 | * 4. |
| 2957 | */ |
| 2958 | if (i++ >= 20) { |
| 2959 | /* Adapter failed to init, timeout, status reg |
| 2960 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2962 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2963 | "timeout, status reg x%x, " |
| 2964 | "FW Data: A8 x%x AC x%x\n", status, |
| 2965 | readl(phba->MBslimaddr + 0xa8), |
| 2966 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2967 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | return -ETIMEDOUT; |
| 2969 | } |
| 2970 | |
| 2971 | /* Check to see if any errors occurred during init */ |
| 2972 | if (status & HS_FFERM) { |
| 2973 | /* ERROR: During chipset initialization */ |
| 2974 | /* Adapter failed to init, chipset, status reg |
| 2975 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2976 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2977 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2978 | "chipset, status reg x%x, " |
| 2979 | "FW Data: A8 x%x AC x%x\n", status, |
| 2980 | readl(phba->MBslimaddr + 0xa8), |
| 2981 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2982 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | return -EIO; |
| 2984 | } |
| 2985 | |
| 2986 | if (i <= 5) { |
| 2987 | msleep(10); |
| 2988 | } else if (i <= 10) { |
| 2989 | msleep(500); |
| 2990 | } else { |
| 2991 | msleep(2500); |
| 2992 | } |
| 2993 | |
| 2994 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2995 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2996 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2997 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | } |
| 2999 | /* Read the HBA Host Status Register */ |
| 3000 | status = readl(phba->HSregaddr); |
| 3001 | } |
| 3002 | |
| 3003 | /* Check to see if any errors occurred during init */ |
| 3004 | if (status & HS_FFERM) { |
| 3005 | /* ERROR: During chipset initialization */ |
| 3006 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3007 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3008 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3009 | "status reg x%x, " |
| 3010 | "FW Data: A8 x%x AC x%x\n", status, |
| 3011 | readl(phba->MBslimaddr + 0xa8), |
| 3012 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | return -EIO; |
| 3015 | } |
| 3016 | |
| 3017 | /* Clear all interrupt enable conditions */ |
| 3018 | writel(0, phba->HCregaddr); |
| 3019 | readl(phba->HCregaddr); /* flush */ |
| 3020 | |
| 3021 | /* setup host attn register */ |
| 3022 | writel(0xffffffff, phba->HAregaddr); |
| 3023 | readl(phba->HAregaddr); /* flush */ |
| 3024 | return 0; |
| 3025 | } |
| 3026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3028 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3029 | * |
| 3030 | * This function calculates and returns the number of HBQs required to be |
| 3031 | * configured. |
| 3032 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3033 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3034 | lpfc_sli_hbq_count(void) |
| 3035 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3036 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3037 | } |
| 3038 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3039 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3040 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3041 | * |
| 3042 | * This function adds the number of hbq entries in every HBQ to get |
| 3043 | * the total number of hbq entries required for the HBA and returns |
| 3044 | * the total count. |
| 3045 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3046 | static int |
| 3047 | lpfc_sli_hbq_entry_count(void) |
| 3048 | { |
| 3049 | int hbq_count = lpfc_sli_hbq_count(); |
| 3050 | int count = 0; |
| 3051 | int i; |
| 3052 | |
| 3053 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3054 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3055 | return count; |
| 3056 | } |
| 3057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3059 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3060 | * |
| 3061 | * This function calculates amount of memory required for all hbq entries |
| 3062 | * to be configured and returns the total memory required. |
| 3063 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3064 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3065 | lpfc_sli_hbq_size(void) |
| 3066 | { |
| 3067 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 3068 | } |
| 3069 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3070 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3071 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3072 | * @phba: Pointer to HBA context object. |
| 3073 | * |
| 3074 | * This function is called during the SLI initialization to configure |
| 3075 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 3076 | * required to hold any locks. This function will return zero if successful |
| 3077 | * else it will return negative error code. |
| 3078 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3079 | static int |
| 3080 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 3081 | { |
| 3082 | int hbq_count = lpfc_sli_hbq_count(); |
| 3083 | LPFC_MBOXQ_t *pmb; |
| 3084 | MAILBOX_t *pmbox; |
| 3085 | uint32_t hbqno; |
| 3086 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3087 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3088 | /* Get a Mailbox buffer to setup mailbox |
| 3089 | * commands for HBA initialization |
| 3090 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3091 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3092 | |
| 3093 | if (!pmb) |
| 3094 | return -ENOMEM; |
| 3095 | |
| 3096 | pmbox = &pmb->mb; |
| 3097 | |
| 3098 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 3099 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3100 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3101 | |
| 3102 | hbq_entry_index = 0; |
| 3103 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 3104 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 3105 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 3106 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 3107 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3108 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3109 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 3110 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3111 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 3112 | |
| 3113 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 3114 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 3115 | mbxStatus <status>, ring <num> */ |
| 3116 | |
| 3117 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3118 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3119 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3120 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3121 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3122 | pmbox->mbxStatus, hbqno); |
| 3123 | |
| 3124 | phba->link_state = LPFC_HBA_ERROR; |
| 3125 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3126 | return ENXIO; |
| 3127 | } |
| 3128 | } |
| 3129 | phba->hbq_count = hbq_count; |
| 3130 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3131 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3133 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3134 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 3135 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3136 | return 0; |
| 3137 | } |
| 3138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3140 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3141 | * @phba: Pointer to HBA context object. |
| 3142 | * @sli_mode: sli mode - 2/3 |
| 3143 | * |
| 3144 | * This function is called by the sli intialization code path |
| 3145 | * to issue config_port mailbox command. This function restarts the |
| 3146 | * HBA firmware and issues a config_port mailbox command to configure |
| 3147 | * the SLI interface in the sli mode specified by sli_mode |
| 3148 | * variable. The caller is not required to hold any locks. |
| 3149 | * The function returns 0 if successful, else returns negative error |
| 3150 | * code. |
| 3151 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3152 | int |
| 3153 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | { |
| 3155 | LPFC_MBOXQ_t *pmb; |
| 3156 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3157 | |
| 3158 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3159 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3161 | return -ENOMEM; |
| 3162 | } |
| 3163 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3164 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3166 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3167 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3168 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3169 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3170 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | rc = lpfc_sli_chipset_init(phba); |
| 3172 | if (rc) |
| 3173 | break; |
| 3174 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3175 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3176 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3178 | resetcount++; |
| 3179 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3180 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3181 | * value of 0 means the call was successful. Any other |
| 3182 | * nonzero value is a failure, but if ERESTART is returned, |
| 3183 | * the driver may reset the HBA and try again. |
| 3184 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | rc = lpfc_config_port_prep(phba); |
| 3186 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3187 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3189 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3191 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | lpfc_config_port(phba, pmb); |
| 3193 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3194 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3195 | LPFC_SLI3_HBQ_ENABLED | |
| 3196 | LPFC_SLI3_CRP_ENABLED | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3197 | LPFC_SLI3_INB_ENABLED | |
| 3198 | LPFC_SLI3_BG_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3199 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3201 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3202 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3203 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3204 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | spin_unlock_irq(&phba->hbalock); |
| 3207 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3208 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3209 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3210 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3211 | if (!done) { |
| 3212 | rc = -EINVAL; |
| 3213 | goto do_prep_failed; |
| 3214 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3215 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3216 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3217 | rc = -ENXIO; |
| 3218 | goto do_prep_failed; |
| 3219 | } |
| 3220 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3221 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3222 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3223 | } else |
| 3224 | phba->max_vpi = 0; |
| 3225 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3226 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3227 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3228 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3229 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3230 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3231 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3232 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3233 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3234 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3235 | phba->inb_last_counter = |
| 3236 | phba->mbox->us.s3_inb_pgp.counter; |
| 3237 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3238 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3239 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3240 | phba->inb_ha_copy = NULL; |
| 3241 | phba->inb_counter = NULL; |
| 3242 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3243 | |
| 3244 | if (phba->cfg_enable_bg) { |
| 3245 | if (pmb->mb.un.varCfgPort.gbg) |
| 3246 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 3247 | else |
| 3248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3249 | "0443 Adapter did not grant " |
| 3250 | "BlockGuard\n"); |
| 3251 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3252 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3253 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3254 | phba->port_gp = phba->mbox->us.s2.port; |
| 3255 | phba->inb_ha_copy = NULL; |
| 3256 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3257 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3258 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3259 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3260 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3261 | return rc; |
| 3262 | } |
| 3263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3264 | |
| 3265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3266 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3267 | * @phba: Pointer to HBA context object. |
| 3268 | * |
| 3269 | * This function is the main SLI intialization function. This function |
| 3270 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3271 | * error attention handler code. Caller is not required to hold any |
| 3272 | * locks. This function issues config_port mailbox command to configure |
| 3273 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3274 | * calls the config_port_post function to issue init_link mailbox |
| 3275 | * command and to start the discovery. The function will return zero |
| 3276 | * if successful, else it will return negative error code. |
| 3277 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3278 | int |
| 3279 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3280 | { |
| 3281 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3282 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3283 | |
| 3284 | switch (lpfc_sli_mode) { |
| 3285 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3286 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3287 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3288 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3289 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3290 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3291 | break; |
| 3292 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3293 | mode = 2; |
| 3294 | break; |
| 3295 | case 0: |
| 3296 | case 3: |
| 3297 | break; |
| 3298 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3299 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3300 | "1819 Unrecognized lpfc_sli_mode " |
| 3301 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3302 | |
| 3303 | break; |
| 3304 | } |
| 3305 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3306 | rc = lpfc_sli_config_port(phba, mode); |
| 3307 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3308 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3309 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3310 | "1820 Unable to select SLI-3. " |
| 3311 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3312 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3313 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3314 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | goto lpfc_sli_hba_setup_error; |
| 3316 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3317 | if (phba->sli_rev == 3) { |
| 3318 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3319 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3320 | } else { |
| 3321 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3322 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3323 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3327 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3328 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3329 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | |
| 3331 | if (rc) |
| 3332 | goto lpfc_sli_hba_setup_error; |
| 3333 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3334 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3335 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3336 | rc = lpfc_sli_hbq_setup(phba); |
| 3337 | if (rc) |
| 3338 | goto lpfc_sli_hba_setup_error; |
| 3339 | } |
| 3340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3342 | |
| 3343 | rc = lpfc_config_port_post(phba); |
| 3344 | if (rc) |
| 3345 | goto lpfc_sli_hba_setup_error; |
| 3346 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3347 | return rc; |
| 3348 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3349 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3350 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3351 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3352 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3353 | return rc; |
| 3354 | } |
| 3355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3356 | |
| 3357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3358 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3359 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3360 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3361 | * This is the callback function for mailbox timer. The mailbox |
| 3362 | * timer is armed when a new mailbox command is issued and the timer |
| 3363 | * is deleted when the mailbox complete. The function is called by |
| 3364 | * the kernel timer code when a mailbox does not complete within |
| 3365 | * expected time. This function wakes up the worker thread to |
| 3366 | * process the mailbox timeout and returns. All the processing is |
| 3367 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3368 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | void |
| 3370 | lpfc_mbox_timeout(unsigned long ptr) |
| 3371 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3372 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3374 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3376 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3377 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3378 | if (!tmo_posted) |
| 3379 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3380 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3381 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3382 | if (!tmo_posted) |
| 3383 | lpfc_worker_wake_up(phba); |
| 3384 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | } |
| 3386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3387 | |
| 3388 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3389 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3390 | * @phba: Pointer to HBA context object. |
| 3391 | * |
| 3392 | * This function is called from worker thread when a mailbox command times out. |
| 3393 | * The caller is not required to hold any locks. This function will reset the |
| 3394 | * HBA and recover all the pending commands. |
| 3395 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | void |
| 3397 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3398 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3400 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3401 | struct lpfc_sli *psli = &phba->sli; |
| 3402 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3404 | /* Check the pmbox pointer first. There is a race condition |
| 3405 | * between the mbox timeout handler getting executed in the |
| 3406 | * worklist and the mailbox actually completing. When this |
| 3407 | * race condition occurs, the mbox_active will be NULL. |
| 3408 | */ |
| 3409 | spin_lock_irq(&phba->hbalock); |
| 3410 | if (pmbox == NULL) { |
| 3411 | lpfc_printf_log(phba, KERN_WARNING, |
| 3412 | LOG_MBOX | LOG_SLI, |
| 3413 | "0353 Active Mailbox cleared - mailbox timeout " |
| 3414 | "exiting\n"); |
| 3415 | spin_unlock_irq(&phba->hbalock); |
| 3416 | return; |
| 3417 | } |
| 3418 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3420 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3421 | "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] | 3422 | mb->mbxCommand, |
| 3423 | phba->pport->port_state, |
| 3424 | phba->sli.sli_flag, |
| 3425 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3426 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3428 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3429 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3430 | * it to fail all oustanding SCSI IO. |
| 3431 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3432 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3433 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3434 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3435 | spin_lock_irq(&phba->hbalock); |
| 3436 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3437 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3438 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3439 | |
| 3440 | pring = &psli->ring[psli->fcp_ring]; |
| 3441 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3442 | |
| 3443 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3444 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3445 | |
| 3446 | /* Reset the HBA device */ |
| 3447 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | } |
| 3449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3450 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3451 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3452 | * @phba: Pointer to HBA context object. |
| 3453 | * @pmbox: Pointer to mailbox object. |
| 3454 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3455 | * |
| 3456 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3457 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 3458 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3459 | * The mailbox command can be submitted in polling mode, in which case |
| 3460 | * this function will wait in a polling loop for the completion of the |
| 3461 | * mailbox. |
| 3462 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3463 | * function will submit the command and returns immediately without waiting |
| 3464 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3465 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3466 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3467 | * mailbox is issued in polling mode and there is already a mailbox |
| 3468 | * pending, then the function will return an error. If the mailbox is issued |
| 3469 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3470 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3471 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3472 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3473 | * return codes the caller owns the mailbox command after the return of |
| 3474 | * the function. |
| 3475 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3476 | static int |
| 3477 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 3478 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3480 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3481 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3482 | uint32_t status, evtctr; |
| 3483 | uint32_t ha_copy; |
| 3484 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3485 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3487 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3488 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3489 | int processing_queue = 0; |
| 3490 | |
| 3491 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3492 | if (!pmbox) { |
| 3493 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3494 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 3495 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3496 | return MBX_SUCCESS; |
| 3497 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3498 | processing_queue = 1; |
| 3499 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3500 | pmbox = lpfc_mbox_get(phba); |
| 3501 | if (!pmbox) { |
| 3502 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3503 | return MBX_SUCCESS; |
| 3504 | } |
| 3505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3507 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3508 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3509 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3510 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3511 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3512 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3513 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3514 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3515 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3516 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3520 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3521 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3522 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3523 | goto out_not_finished; |
| 3524 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3525 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3526 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 3527 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 3528 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3529 | goto out_not_finished; |
| 3530 | } |
| 3531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3534 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | status = MBX_SUCCESS; |
| 3536 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3538 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3539 | |
| 3540 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3541 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3542 | "(%d):0311 Mailbox command x%x cannot " |
| 3543 | "issue Data: x%x x%x\n", |
| 3544 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 3545 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3546 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3547 | } |
| 3548 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3549 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3550 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3551 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3552 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3553 | "(%d):2528 Mailbox command x%x cannot " |
| 3554 | "issue Data: x%x x%x\n", |
| 3555 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 3556 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3557 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3558 | } |
| 3559 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3561 | /* Polling for a mbox command when another one is already active |
| 3562 | * is not allowed in SLI. Also, the driver must have established |
| 3563 | * SLI2 mode to queue and process multiple mbox commands. |
| 3564 | */ |
| 3565 | |
| 3566 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3567 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | |
| 3569 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3570 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3571 | "(%d):2529 Mailbox command x%x " |
| 3572 | "cannot issue Data: x%x x%x\n", |
| 3573 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 3574 | pmbox->u.mb.mbxCommand, |
| 3575 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3576 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | } |
| 3578 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3579 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3580 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3582 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3583 | "(%d):2530 Mailbox command x%x " |
| 3584 | "cannot issue Data: x%x x%x\n", |
| 3585 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 3586 | pmbox->u.mb.mbxCommand, |
| 3587 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3588 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3589 | } |
| 3590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | /* Another mailbox command is still being processed, queue this |
| 3592 | * command to be processed later. |
| 3593 | */ |
| 3594 | lpfc_mbox_put(phba, pmbox); |
| 3595 | |
| 3596 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3597 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3598 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3599 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3600 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3601 | mb->mbxCommand, phba->pport->port_state, |
| 3602 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | |
| 3604 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3605 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3607 | if (pmbox->vport) { |
| 3608 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3609 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3610 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3611 | (uint32_t)mb->mbxCommand, |
| 3612 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3613 | } |
| 3614 | else { |
| 3615 | lpfc_debugfs_disc_trc(phba->pport, |
| 3616 | LPFC_DISC_TRC_MBOX, |
| 3617 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3618 | (uint32_t)mb->mbxCommand, |
| 3619 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3620 | } |
| 3621 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | } |
| 3624 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3625 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3626 | |
| 3627 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3628 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3629 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3630 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3632 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3634 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3635 | "(%d):2531 Mailbox command x%x " |
| 3636 | "cannot issue Data: x%x x%x\n", |
| 3637 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 3638 | pmbox->u.mb.mbxCommand, |
| 3639 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3640 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | } |
| 3642 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3643 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3644 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3648 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3649 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3650 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3651 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3652 | mb->mbxCommand, phba->pport->port_state, |
| 3653 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3655 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3656 | if (pmbox->vport) { |
| 3657 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3658 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3659 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3660 | (uint32_t)mb->mbxCommand, |
| 3661 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3662 | } |
| 3663 | else { |
| 3664 | lpfc_debugfs_disc_trc(phba->pport, |
| 3665 | LPFC_DISC_TRC_MBOX, |
| 3666 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3667 | (uint32_t)mb->mbxCommand, |
| 3668 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3669 | } |
| 3670 | } |
| 3671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | psli->slistat.mbox_cmd++; |
| 3673 | evtctr = psli->slistat.mbox_event; |
| 3674 | |
| 3675 | /* next set own bit for the adapter and copy over command word */ |
| 3676 | mb->mbxOwner = OWN_CHIP; |
| 3677 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3678 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3680 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3682 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3683 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3684 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3688 | word */ |
| 3689 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3690 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3691 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3692 | |
| 3693 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3694 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | to_slim = phba->MBslimaddr; |
| 3696 | writel(ldata, to_slim); |
| 3697 | readl(to_slim); /* flush */ |
| 3698 | |
| 3699 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3700 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3701 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | |
| 3707 | switch (flag) { |
| 3708 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3709 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3711 | /* Interrupt board to do it */ |
| 3712 | writel(CA_MBATT, phba->CAregaddr); |
| 3713 | readl(phba->CAregaddr); /* flush */ |
| 3714 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | break; |
| 3716 | |
| 3717 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3718 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3720 | /* Interrupt board to do it */ |
| 3721 | writel(CA_MBATT, phba->CAregaddr); |
| 3722 | readl(phba->CAregaddr); /* flush */ |
| 3723 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3724 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3726 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | word0 = le32_to_cpu(word0); |
| 3728 | } else { |
| 3729 | /* First read mbox status word */ |
| 3730 | word0 = readl(phba->MBslimaddr); |
| 3731 | } |
| 3732 | |
| 3733 | /* Read the HBA Host Attention Register */ |
| 3734 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3735 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3736 | mb->mbxCommand) * |
| 3737 | 1000) + jiffies; |
| 3738 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3740 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3741 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3742 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3743 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3745 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3747 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | /* Check if we took a mbox interrupt while we were |
| 3751 | polling */ |
| 3752 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3753 | && (evtctr != psli->slistat.mbox_event)) |
| 3754 | break; |
| 3755 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3756 | if (i++ > 10) { |
| 3757 | spin_unlock_irqrestore(&phba->hbalock, |
| 3758 | drvr_flag); |
| 3759 | msleep(1); |
| 3760 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3763 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3764 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3765 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | word0 = le32_to_cpu(word0); |
| 3767 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3768 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3769 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | /* Check real SLIM for any errors */ |
| 3771 | slimword0 = readl(phba->MBslimaddr); |
| 3772 | slimmb = (MAILBOX_t *) & slimword0; |
| 3773 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3774 | && slimmb->mbxStatus) { |
| 3775 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3776 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | word0 = slimword0; |
| 3778 | } |
| 3779 | } |
| 3780 | } else { |
| 3781 | /* First copy command data */ |
| 3782 | word0 = readl(phba->MBslimaddr); |
| 3783 | } |
| 3784 | /* Read the HBA Host Attention Register */ |
| 3785 | ha_copy = readl(phba->HAregaddr); |
| 3786 | } |
| 3787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3788 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3790 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | } else { |
| 3792 | /* First copy command data */ |
| 3793 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3794 | MAILBOX_CMD_SIZE); |
| 3795 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3796 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3797 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3799 | mb->un.varDmp.word_cnt); |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | writel(HA_MBATT, phba->HAregaddr); |
| 3804 | readl(phba->HAregaddr); /* flush */ |
| 3805 | |
| 3806 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3807 | status = mb->mbxStatus; |
| 3808 | } |
| 3809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3811 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3812 | |
| 3813 | out_not_finished: |
| 3814 | if (processing_queue) { |
| 3815 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3816 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3817 | } |
| 3818 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 | } |
| 3820 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3821 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3822 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3823 | * @phba: Pointer to HBA context object. |
| 3824 | * @pring: Pointer to driver SLI ring object. |
| 3825 | * @piocb: Pointer to address of newly added command iocb. |
| 3826 | * |
| 3827 | * This function is called with hbalock held to add a command |
| 3828 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3829 | * to the ring. |
| 3830 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3831 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3832 | __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] | 3833 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | { |
| 3835 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3836 | list_add_tail(&piocb->list, &pring->txq); |
| 3837 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | } |
| 3839 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3840 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3841 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3842 | * @phba: Pointer to HBA context object. |
| 3843 | * @pring: Pointer to driver SLI ring object. |
| 3844 | * @piocb: Pointer to address of newly added command iocb. |
| 3845 | * |
| 3846 | * This function is called with hbalock held before a new |
| 3847 | * iocb is submitted to the firmware. This function checks |
| 3848 | * txq to flush the iocbs in txq to Firmware before |
| 3849 | * submitting new iocbs to the Firmware. |
| 3850 | * If there are iocbs in the txq which need to be submitted |
| 3851 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3852 | * of the txq after dequeuing it from txq. |
| 3853 | * If there is no iocb in the txq then the function will return |
| 3854 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3855 | * *piocb to find if there are more commands in the txq. |
| 3856 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | static struct lpfc_iocbq * |
| 3858 | 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] | 3859 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | { |
| 3861 | struct lpfc_iocbq * nextiocb; |
| 3862 | |
| 3863 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3864 | if (!nextiocb) { |
| 3865 | nextiocb = *piocb; |
| 3866 | *piocb = NULL; |
| 3867 | } |
| 3868 | |
| 3869 | return nextiocb; |
| 3870 | } |
| 3871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3872 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3873 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3874 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3875 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3876 | * @piocb: Pointer to command iocb. |
| 3877 | * @flag: Flag indicating if this command can be put into txq. |
| 3878 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3879 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 3880 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 3881 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3882 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 3883 | * this function allows only iocbs for posting buffers. This function finds |
| 3884 | * next available slot in the command ring and posts the command to the |
| 3885 | * available slot and writes the port attention register to request HBA start |
| 3886 | * processing new iocb. If there is no slot available in the ring and |
| 3887 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 3888 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3889 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3890 | * This function is called with hbalock held. The function will return success |
| 3891 | * after it successfully submit the iocb to firmware or after adding to the |
| 3892 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3893 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3894 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3895 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3896 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3897 | { |
| 3898 | struct lpfc_iocbq *nextiocb; |
| 3899 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 3900 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3902 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3903 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3904 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3905 | lpfc_printf_log(phba, KERN_ERR, |
| 3906 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3907 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3908 | piocb->iocb.ulpCommand); |
| 3909 | dump_stack(); |
| 3910 | return IOCB_ERROR; |
| 3911 | } |
| 3912 | |
| 3913 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3914 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3915 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3916 | return IOCB_ERROR; |
| 3917 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3918 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 3919 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 3920 | return IOCB_ERROR; |
| 3921 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | /* |
| 3923 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3924 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3925 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | return IOCB_ERROR; |
| 3927 | |
| 3928 | /* |
| 3929 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3930 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3932 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | goto iocb_busy; |
| 3934 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3937 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | * can be issued if the link is not up. |
| 3939 | */ |
| 3940 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3941 | case CMD_GEN_REQUEST64_CR: |
| 3942 | case CMD_GEN_REQUEST64_CX: |
| 3943 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 3944 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 3945 | FC_FCP_CMND) || |
| 3946 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 3947 | MENLO_TRANSPORT_TYPE)) |
| 3948 | |
| 3949 | goto iocb_busy; |
| 3950 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3951 | case CMD_QUE_RING_BUF_CN: |
| 3952 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3953 | /* |
| 3954 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3955 | * completion, iocb_cmpl MUST be 0. |
| 3956 | */ |
| 3957 | if (piocb->iocb_cmpl) |
| 3958 | piocb->iocb_cmpl = NULL; |
| 3959 | /*FALLTHROUGH*/ |
| 3960 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3961 | case CMD_CLOSE_XRI_CN: |
| 3962 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3963 | break; |
| 3964 | default: |
| 3965 | goto iocb_busy; |
| 3966 | } |
| 3967 | |
| 3968 | /* |
| 3969 | * For FCP commands, we must be in a state where we can process link |
| 3970 | * attention events. |
| 3971 | */ |
| 3972 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3973 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3975 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3976 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3977 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3978 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3979 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3980 | |
| 3981 | if (iocb) |
| 3982 | lpfc_sli_update_ring(phba, pring); |
| 3983 | else |
| 3984 | lpfc_sli_update_full_ring(phba, pring); |
| 3985 | |
| 3986 | if (!piocb) |
| 3987 | return IOCB_SUCCESS; |
| 3988 | |
| 3989 | goto out_busy; |
| 3990 | |
| 3991 | iocb_busy: |
| 3992 | pring->stats.iocb_cmd_delay++; |
| 3993 | |
| 3994 | out_busy: |
| 3995 | |
| 3996 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3998 | return IOCB_SUCCESS; |
| 3999 | } |
| 4000 | |
| 4001 | return IOCB_BUSY; |
| 4002 | } |
| 4003 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 4004 | /** |
| 4005 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 4006 | * |
| 4007 | * This routine wraps the actual lockless version for issusing IOCB function |
| 4008 | * pointer from the lpfc_hba struct. |
| 4009 | * |
| 4010 | * Return codes: |
| 4011 | * IOCB_ERROR - Error |
| 4012 | * IOCB_SUCCESS - Success |
| 4013 | * IOCB_BUSY - Busy |
| 4014 | **/ |
| 4015 | static inline int |
| 4016 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 4017 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 4018 | { |
| 4019 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 4020 | } |
| 4021 | |
| 4022 | /** |
| 4023 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table |
| 4024 | * @phba: The hba struct for which this call is being executed. |
| 4025 | * @dev_grp: The HBA PCI-Device group number. |
| 4026 | * |
| 4027 | * This routine sets up the SLI interface API function jump table in @phba |
| 4028 | * struct. |
| 4029 | * Returns: 0 - success, -ENODEV - failure. |
| 4030 | **/ |
| 4031 | int |
| 4032 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4033 | { |
| 4034 | |
| 4035 | switch (dev_grp) { |
| 4036 | case LPFC_PCI_DEV_LP: |
| 4037 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 4038 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 4039 | break; |
| 4040 | default: |
| 4041 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4042 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 4043 | dev_grp); |
| 4044 | return -ENODEV; |
| 4045 | break; |
| 4046 | } |
| 4047 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 4048 | return 0; |
| 4049 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4050 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4051 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4052 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4053 | * @phba: Pointer to HBA context object. |
| 4054 | * @pring: Pointer to driver SLI ring object. |
| 4055 | * @piocb: Pointer to command iocb. |
| 4056 | * @flag: Flag indicating if this command can be put into txq. |
| 4057 | * |
| 4058 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 4059 | * function. This function gets the hbalock and calls |
| 4060 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 4061 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 4062 | * functions which do not hold hbalock. |
| 4063 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4064 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 4065 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4066 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 4067 | { |
| 4068 | unsigned long iflags; |
| 4069 | int rc; |
| 4070 | |
| 4071 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 4072 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4074 | |
| 4075 | return rc; |
| 4076 | } |
| 4077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4079 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4080 | * @phba: Pointer to HBA context object. |
| 4081 | * |
| 4082 | * This function is called while driver attaches with the |
| 4083 | * HBA to setup the extra ring. The extra ring is used |
| 4084 | * only when driver needs to support target mode functionality |
| 4085 | * or IP over FC functionalities. |
| 4086 | * |
| 4087 | * This function is called with no lock held. |
| 4088 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4089 | static int |
| 4090 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 4091 | { |
| 4092 | struct lpfc_sli *psli; |
| 4093 | struct lpfc_sli_ring *pring; |
| 4094 | |
| 4095 | psli = &phba->sli; |
| 4096 | |
| 4097 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4098 | |
| 4099 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4100 | pring = &psli->ring[psli->fcp_ring]; |
| 4101 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4102 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4103 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4104 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 4105 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4106 | /* and give them to the extra ring */ |
| 4107 | pring = &psli->ring[psli->extra_ring]; |
| 4108 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4109 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4110 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4111 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4112 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 4113 | |
| 4114 | /* Setup default profile for this ring */ |
| 4115 | pring->iotag_max = 4096; |
| 4116 | pring->num_mask = 1; |
| 4117 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4118 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 4119 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4120 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 4121 | return 0; |
| 4122 | } |
| 4123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4125 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4126 | * @phba: Pointer to HBA context object. |
| 4127 | * @pring: Pointer to driver SLI ring object. |
| 4128 | * @iocbq: Pointer to iocb object. |
| 4129 | * |
| 4130 | * This function is called by the slow ring event handler |
| 4131 | * function when there is an ASYNC event iocb in the ring. |
| 4132 | * This function is called with no lock held. |
| 4133 | * Currently this function handles only temperature related |
| 4134 | * ASYNC events. The function decodes the temperature sensor |
| 4135 | * event message and posts events for the management applications. |
| 4136 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4137 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4138 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 4139 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 4140 | { |
| 4141 | IOCB_t *icmd; |
| 4142 | uint16_t evt_code; |
| 4143 | uint16_t temp; |
| 4144 | struct temp_event temp_event_data; |
| 4145 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4146 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4147 | |
| 4148 | icmd = &iocbq->iocb; |
| 4149 | evt_code = icmd->un.asyncstat.evt_code; |
| 4150 | temp = icmd->ulpContext; |
| 4151 | |
| 4152 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 4153 | (evt_code != ASYNC_TEMP_SAFE)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4154 | iocb_w = (uint32_t *) icmd; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4155 | lpfc_printf_log(phba, |
| 4156 | KERN_ERR, |
| 4157 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4158 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4159 | " evt_code 0x%x \n" |
| 4160 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 4161 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 4162 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 4163 | "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] | 4164 | pring->ringno, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4165 | icmd->un.asyncstat.evt_code, |
| 4166 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 4167 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 4168 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 4169 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 4170 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4171 | return; |
| 4172 | } |
| 4173 | temp_event_data.data = (uint32_t)temp; |
| 4174 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4175 | if (evt_code == ASYNC_TEMP_WARN) { |
| 4176 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 4177 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4178 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4179 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4180 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4181 | "corrective action. temperature : %d Celsius\n", |
| 4182 | temp); |
| 4183 | } |
| 4184 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 4185 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 4186 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4187 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4188 | LOG_TEMP, |
| 4189 | "0340 Adapter temperature is OK now. " |
| 4190 | "temperature : %d Celsius\n", |
| 4191 | temp); |
| 4192 | } |
| 4193 | |
| 4194 | /* Send temperature change event to applications */ |
| 4195 | shost = lpfc_shost_from_vport(phba->pport); |
| 4196 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4197 | sizeof(temp_event_data), (char *) &temp_event_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4198 | LPFC_NL_VENDOR_ID); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4199 | |
| 4200 | } |
| 4201 | |
| 4202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4204 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4205 | * @phba: Pointer to HBA context object. |
| 4206 | * |
| 4207 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 4208 | * number of iocbs per ring and iotags. This function is |
| 4209 | * called while driver attach to the HBA and before the |
| 4210 | * interrupts are enabled. So there is no need for locking. |
| 4211 | * |
| 4212 | * This function always returns 0. |
| 4213 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | int |
| 4215 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 4216 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4217 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | struct lpfc_sli *psli = &phba->sli; |
| 4219 | struct lpfc_sli_ring *pring; |
| 4220 | |
| 4221 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 4222 | psli->sli_flag = 0; |
| 4223 | psli->fcp_ring = LPFC_FCP_RING; |
| 4224 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4225 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4227 | psli->iocbq_lookup = NULL; |
| 4228 | psli->iocbq_lookup_len = 0; |
| 4229 | psli->last_iotag = 0; |
| 4230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | for (i = 0; i < psli->num_rings; i++) { |
| 4232 | pring = &psli->ring[i]; |
| 4233 | switch (i) { |
| 4234 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 4235 | /* numCiocb and numRiocb are used in config_port */ |
| 4236 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 4237 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 4238 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 4239 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 4240 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 4241 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4242 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4243 | SLI3_IOCB_CMD_SIZE : |
| 4244 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4245 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4246 | SLI3_IOCB_RSP_SIZE : |
| 4247 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | pring->iotag_ctr = 0; |
| 4249 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4250 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4251 | pring->fast_iotag = pring->iotag_max; |
| 4252 | pring->num_mask = 0; |
| 4253 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4254 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | /* numCiocb and numRiocb are used in config_port */ |
| 4256 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 4257 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4258 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4259 | SLI3_IOCB_CMD_SIZE : |
| 4260 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4261 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4262 | SLI3_IOCB_RSP_SIZE : |
| 4263 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4264 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | pring->num_mask = 0; |
| 4266 | break; |
| 4267 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 4268 | /* numCiocb and numRiocb are used in config_port */ |
| 4269 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 4270 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4271 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4272 | SLI3_IOCB_CMD_SIZE : |
| 4273 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4274 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4275 | SLI3_IOCB_RSP_SIZE : |
| 4276 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4277 | pring->fast_iotag = 0; |
| 4278 | pring->iotag_ctr = 0; |
| 4279 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4280 | pring->lpfc_sli_rcv_async_status = |
| 4281 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | pring->num_mask = 4; |
| 4283 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 4284 | pring->prt[0].rctl = FC_ELS_REQ; |
| 4285 | pring->prt[0].type = FC_ELS_DATA; |
| 4286 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4287 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4288 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 4289 | pring->prt[1].rctl = FC_ELS_RSP; |
| 4290 | pring->prt[1].type = FC_ELS_DATA; |
| 4291 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4292 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 4294 | /* NameServer Inquiry */ |
| 4295 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 4296 | /* NameServer */ |
| 4297 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 4298 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4299 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4300 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 4301 | /* NameServer response */ |
| 4302 | pring->prt[3].rctl = FC_SOL_CTL; |
| 4303 | /* NameServer */ |
| 4304 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 4305 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4306 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | break; |
| 4308 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4309 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4310 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4312 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4314 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 4315 | "SLI2 SLIM Data: x%x x%lx\n", |
| 4316 | phba->brd_no, totiocbsize, |
| 4317 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4319 | if (phba->cfg_multi_ring_support == 2) |
| 4320 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | |
| 4322 | return 0; |
| 4323 | } |
| 4324 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4326 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4327 | * @phba: Pointer to HBA context object. |
| 4328 | * |
| 4329 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4330 | * ring. This function also initializes ring indices of each ring. |
| 4331 | * This function is called during the initialization of the SLI |
| 4332 | * interface of an HBA. |
| 4333 | * This function is called with no lock held and always returns |
| 4334 | * 1. |
| 4335 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | { |
| 4339 | struct lpfc_sli *psli; |
| 4340 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4341 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | |
| 4343 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4346 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4348 | for (i = 0; i < psli->num_rings; i++) { |
| 4349 | pring = &psli->ring[i]; |
| 4350 | pring->ringno = i; |
| 4351 | pring->next_cmdidx = 0; |
| 4352 | pring->local_getidx = 0; |
| 4353 | pring->cmdidx = 0; |
| 4354 | INIT_LIST_HEAD(&pring->txq); |
| 4355 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4356 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4357 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4359 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | spin_unlock_irq(&phba->hbalock); |
| 4361 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | } |
| 4363 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4364 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4365 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4366 | * @vport: Pointer to virtual port object. |
| 4367 | * |
| 4368 | * lpfc_sli_host_down is called to clean up the resources |
| 4369 | * associated with a vport before destroying virtual |
| 4370 | * port data structures. |
| 4371 | * This function does following operations: |
| 4372 | * - Free discovery resources associated with this virtual |
| 4373 | * port. |
| 4374 | * - Free iocbs associated with this virtual port in |
| 4375 | * the txq. |
| 4376 | * - Send abort for all iocb commands associated with this |
| 4377 | * vport in txcmplq. |
| 4378 | * |
| 4379 | * This function is called with no lock held and always returns 1. |
| 4380 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4382 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4383 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4384 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4385 | struct lpfc_hba *phba = vport->phba; |
| 4386 | struct lpfc_sli *psli = &phba->sli; |
| 4387 | struct lpfc_sli_ring *pring; |
| 4388 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4389 | int i; |
| 4390 | unsigned long flags = 0; |
| 4391 | uint16_t prev_pring_flag; |
| 4392 | |
| 4393 | lpfc_cleanup_discovery_resources(vport); |
| 4394 | |
| 4395 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4396 | for (i = 0; i < psli->num_rings; i++) { |
| 4397 | pring = &psli->ring[i]; |
| 4398 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4399 | /* Only slow rings */ |
| 4400 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4401 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4402 | /* Set the lpfc data pending flag */ |
| 4403 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4404 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | /* |
| 4406 | * Error everything on the txq since these iocbs have not been |
| 4407 | * given to the FW yet. |
| 4408 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4409 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4410 | if (iocb->vport != vport) |
| 4411 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4412 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4413 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | /* Next issue ABTS for everything on the txcmplq */ |
| 4417 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4418 | list) { |
| 4419 | if (iocb->vport != vport) |
| 4420 | continue; |
| 4421 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4422 | } |
| 4423 | |
| 4424 | pring->flag = prev_pring_flag; |
| 4425 | } |
| 4426 | |
| 4427 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4428 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4429 | /* Cancel all the IOCBs from the completions list */ |
| 4430 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4431 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4432 | return 1; |
| 4433 | } |
| 4434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4436 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4437 | * @phba: Pointer to HBA context object. |
| 4438 | * |
| 4439 | * This function cleans up all iocb, buffers, mailbox commands |
| 4440 | * while shutting down the HBA. This function is called with no |
| 4441 | * lock held and always returns 1. |
| 4442 | * This function does the following to cleanup driver resources: |
| 4443 | * - Free discovery resources for each virtual port |
| 4444 | * - Cleanup any pending fabric iocbs |
| 4445 | * - Iterate through the iocb txq and free each entry |
| 4446 | * in the list. |
| 4447 | * - Free up any buffer posted to the HBA |
| 4448 | * - Free mailbox commands in the mailbox queue. |
| 4449 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4450 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4451 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4453 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4456 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | LPFC_MBOXQ_t *pmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | int i; |
| 4459 | unsigned long flags = 0; |
| 4460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4461 | lpfc_hba_down_prep(phba); |
| 4462 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4463 | lpfc_fabric_abort_hba(phba); |
| 4464 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4465 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | for (i = 0; i < psli->num_rings; i++) { |
| 4467 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4468 | /* Only slow rings */ |
| 4469 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4470 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4471 | /* Set the lpfc data pending flag */ |
| 4472 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4473 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | |
| 4475 | /* |
| 4476 | * Error everything on the txq since these iocbs have not been |
| 4477 | * given to the FW yet. |
| 4478 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4479 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | pring->txq_cnt = 0; |
| 4481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4482 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4483 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4484 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4485 | /* Cancel all the IOCBs from the completions list */ |
| 4486 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 4487 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4488 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4489 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4490 | list_splice_init(&phba->elsbuf, &completions); |
| 4491 | phba->elsbuf_cnt = 0; |
| 4492 | phba->elsbuf_prev_cnt = 0; |
| 4493 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4494 | |
| 4495 | while (!list_empty(&completions)) { |
| 4496 | list_remove_head(&completions, buf_ptr, |
| 4497 | struct lpfc_dmabuf, list); |
| 4498 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4499 | kfree(buf_ptr); |
| 4500 | } |
| 4501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4502 | /* Return any active mbox cmds */ |
| 4503 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4504 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4505 | |
| 4506 | spin_lock(&phba->pport->work_port_lock); |
| 4507 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4508 | spin_unlock(&phba->pport->work_port_lock); |
| 4509 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4510 | /* Return any pending or completed mbox cmds */ |
| 4511 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4512 | if (psli->mbox_active) { |
| 4513 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4516 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4517 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4518 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4519 | |
| 4520 | while (!list_empty(&completions)) { |
| 4521 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4523 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4525 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4526 | return 1; |
| 4527 | } |
| 4528 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4530 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4531 | * @srcp: Source memory pointer. |
| 4532 | * @destp: Destination memory pointer. |
| 4533 | * @cnt: Number of words required to be copied. |
| 4534 | * |
| 4535 | * This function is used for copying data between driver memory |
| 4536 | * and the SLI memory. This function also changes the endianness |
| 4537 | * of each word if native endianness is different from SLI |
| 4538 | * endianness. This function can be called with or without |
| 4539 | * lock. |
| 4540 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | void |
| 4542 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4543 | { |
| 4544 | uint32_t *src = srcp; |
| 4545 | uint32_t *dest = destp; |
| 4546 | uint32_t ldata; |
| 4547 | int i; |
| 4548 | |
| 4549 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4550 | ldata = *src; |
| 4551 | ldata = le32_to_cpu(ldata); |
| 4552 | *dest = ldata; |
| 4553 | src++; |
| 4554 | dest++; |
| 4555 | } |
| 4556 | } |
| 4557 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4558 | |
| 4559 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4560 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4561 | * @phba: Pointer to HBA context object. |
| 4562 | * @pring: Pointer to driver SLI ring object. |
| 4563 | * @mp: Pointer to driver buffer object. |
| 4564 | * |
| 4565 | * This function is called with no lock held. |
| 4566 | * It always return zero after adding the buffer to the postbufq |
| 4567 | * buffer list. |
| 4568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4570 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4571 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4572 | { |
| 4573 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4574 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4576 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4578 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4579 | return 0; |
| 4580 | } |
| 4581 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4582 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4583 | * 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] | 4584 | * @phba: Pointer to HBA context object. |
| 4585 | * |
| 4586 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4587 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4588 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4589 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4590 | * The function returns the allocated tag. The function is called with |
| 4591 | * no locks held. |
| 4592 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4593 | uint32_t |
| 4594 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4595 | { |
| 4596 | spin_lock_irq(&phba->hbalock); |
| 4597 | phba->buffer_tag_count++; |
| 4598 | /* |
| 4599 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4600 | * a tag assigned by HBQ. |
| 4601 | */ |
| 4602 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4603 | spin_unlock_irq(&phba->hbalock); |
| 4604 | return phba->buffer_tag_count; |
| 4605 | } |
| 4606 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4607 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4608 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4609 | * @phba: Pointer to HBA context object. |
| 4610 | * @pring: Pointer to driver SLI ring object. |
| 4611 | * @tag: Buffer tag. |
| 4612 | * |
| 4613 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4614 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4615 | * iocb is posted to the response ring with the tag of the buffer. |
| 4616 | * This function searches the pring->postbufq list using the tag |
| 4617 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4618 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4619 | * buffer is returned to the caller else NULL is returned. |
| 4620 | * This function is called with no lock held. |
| 4621 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4622 | struct lpfc_dmabuf * |
| 4623 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4624 | uint32_t tag) |
| 4625 | { |
| 4626 | struct lpfc_dmabuf *mp, *next_mp; |
| 4627 | struct list_head *slp = &pring->postbufq; |
| 4628 | |
| 4629 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4630 | spin_lock_irq(&phba->hbalock); |
| 4631 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4632 | if (mp->buffer_tag == tag) { |
| 4633 | list_del_init(&mp->list); |
| 4634 | pring->postbufq_cnt--; |
| 4635 | spin_unlock_irq(&phba->hbalock); |
| 4636 | return mp; |
| 4637 | } |
| 4638 | } |
| 4639 | |
| 4640 | spin_unlock_irq(&phba->hbalock); |
| 4641 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4642 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4643 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4644 | pring->ringno, (unsigned long) tag, |
| 4645 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4646 | |
| 4647 | return NULL; |
| 4648 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4651 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4652 | * @phba: Pointer to HBA context object. |
| 4653 | * @pring: Pointer to driver SLI ring object. |
| 4654 | * @phys: DMA address of the buffer. |
| 4655 | * |
| 4656 | * This function searches the buffer list using the dma_address |
| 4657 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4658 | * corresponding to the dma_address. The function returns the |
| 4659 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4660 | * This function is called by the ct and els unsolicited event |
| 4661 | * handlers to get the buffer associated with the unsolicited |
| 4662 | * event. |
| 4663 | * |
| 4664 | * This function is called with no lock held. |
| 4665 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4666 | struct lpfc_dmabuf * |
| 4667 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4668 | dma_addr_t phys) |
| 4669 | { |
| 4670 | struct lpfc_dmabuf *mp, *next_mp; |
| 4671 | struct list_head *slp = &pring->postbufq; |
| 4672 | |
| 4673 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4674 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4675 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4676 | if (mp->phys == phys) { |
| 4677 | list_del_init(&mp->list); |
| 4678 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4679 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | return mp; |
| 4681 | } |
| 4682 | } |
| 4683 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4685 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4686 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4687 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4688 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4689 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4690 | return NULL; |
| 4691 | } |
| 4692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4694 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4695 | * @phba: Pointer to HBA context object. |
| 4696 | * @cmdiocb: Pointer to driver command iocb object. |
| 4697 | * @rspiocb: Pointer to driver response iocb object. |
| 4698 | * |
| 4699 | * This function is the completion handler for the abort iocbs for |
| 4700 | * ELS commands. This function is called from the ELS ring event |
| 4701 | * handler with no lock held. This function frees memory resources |
| 4702 | * associated with the abort iocb. |
| 4703 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4705 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4706 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4709 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4710 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4711 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4712 | |
| 4713 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4714 | |
| 4715 | if (irsp->ulpStatus) { |
| 4716 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4717 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4718 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4720 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4721 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4722 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4723 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4724 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4725 | "with tag %x context %x, abort status %x, " |
| 4726 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4727 | abort_iocb, abort_iotag, abort_context, |
| 4728 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4729 | |
| 4730 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4731 | * If the iocb is not found in Firmware queue the iocb |
| 4732 | * might have completed already. Do not free it again. |
| 4733 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4734 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4735 | spin_unlock_irq(&phba->hbalock); |
| 4736 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4737 | return; |
| 4738 | } |
| 4739 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4740 | * make sure we have the right iocbq before taking it |
| 4741 | * off the txcmplq and try to call completion routine. |
| 4742 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4743 | if (!abort_iocb || |
| 4744 | abort_iocb->iocb.ulpContext != abort_context || |
| 4745 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4746 | spin_unlock_irq(&phba->hbalock); |
| 4747 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4748 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4749 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4751 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4752 | /* Firmware could still be in progress of DMAing |
| 4753 | * payload, so don't free data buffer till after |
| 4754 | * a hbeat. |
| 4755 | */ |
| 4756 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4757 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4758 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4759 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4760 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4761 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4762 | } |
| 4763 | } |
| 4764 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4765 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | return; |
| 4767 | } |
| 4768 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4769 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4770 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4771 | * @phba: Pointer to HBA context object. |
| 4772 | * @cmdiocb: Pointer to driver command iocb object. |
| 4773 | * @rspiocb: Pointer to driver response iocb object. |
| 4774 | * |
| 4775 | * The function is called from SLI ring event handler with no |
| 4776 | * lock held. This function is the completion handler for ELS commands |
| 4777 | * which are aborted. The function frees memory resources used for |
| 4778 | * the aborted ELS commands. |
| 4779 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4780 | static void |
| 4781 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4782 | struct lpfc_iocbq *rspiocb) |
| 4783 | { |
| 4784 | IOCB_t *irsp = &rspiocb->iocb; |
| 4785 | |
| 4786 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4787 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4788 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4789 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4790 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4791 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4792 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4793 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4794 | else |
| 4795 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4796 | return; |
| 4797 | } |
| 4798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4800 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4801 | * @phba: Pointer to HBA context object. |
| 4802 | * @pring: Pointer to driver SLI ring object. |
| 4803 | * @cmdiocb: Pointer to driver command iocb object. |
| 4804 | * |
| 4805 | * This function issues an abort iocb for the provided command |
| 4806 | * iocb. This function is called with hbalock held. |
| 4807 | * The function returns 0 when it fails due to memory allocation |
| 4808 | * failure or when the command iocb is an abort request. |
| 4809 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4811 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4812 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4813 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4814 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4815 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4816 | IOCB_t *icmd = NULL; |
| 4817 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4818 | int retval = IOCB_ERROR; |
| 4819 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4820 | /* |
| 4821 | * There are certain command types we don't want to abort. And we |
| 4822 | * don't want to abort commands that are already in the process of |
| 4823 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4824 | */ |
| 4825 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4826 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4827 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4828 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4829 | return 0; |
| 4830 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4831 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4832 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4833 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4834 | if ((vport->load_flag & FC_UNLOADING) && |
| 4835 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4836 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4837 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4838 | else |
| 4839 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4840 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4841 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4842 | |
| 4843 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4844 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 | if (abtsiocbp == NULL) |
| 4846 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4848 | /* This signals the response to set the correct status |
| 4849 | * before calling the completion handler. |
| 4850 | */ |
| 4851 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4853 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4854 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4855 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4856 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4858 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4859 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4860 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4861 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4862 | else |
| 4863 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4864 | |
| 4865 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4866 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4867 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4868 | "0339 Abort xri x%x, original iotag x%x, " |
| 4869 | "abort cmd iotag x%x\n", |
| 4870 | iabt->un.acxri.abortContextTag, |
| 4871 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4872 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4873 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4874 | if (retval) |
| 4875 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4876 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4877 | /* |
| 4878 | * Caller to this routine should check for IOCB_ERROR |
| 4879 | * and handle it properly. This routine no longer removes |
| 4880 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4881 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | } |
| 4884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4885 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4886 | * 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] | 4887 | * @iocbq: Pointer to driver iocb object. |
| 4888 | * @vport: Pointer to driver virtual port object. |
| 4889 | * @tgt_id: SCSI ID of the target. |
| 4890 | * @lun_id: LUN ID of the scsi device. |
| 4891 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4892 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4893 | * 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] | 4894 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4895 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4896 | * 1 if the filtering criteria is not met. |
| 4897 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4898 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4899 | * lun_id parameter. |
| 4900 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4901 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4902 | * parameters. |
| 4903 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4904 | * given iocb is for the SCSI host associated with the given vport. |
| 4905 | * This function is called with no locks held. |
| 4906 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4908 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4909 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4910 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4912 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | int rc = 1; |
| 4914 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4915 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4916 | return rc; |
| 4917 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4918 | if (iocbq->vport != vport) |
| 4919 | return rc; |
| 4920 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4921 | 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] | 4922 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4923 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4924 | return rc; |
| 4925 | |
| 4926 | switch (ctx_cmd) { |
| 4927 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4928 | if ((lpfc_cmd->rdata->pnode) && |
| 4929 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4930 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4931 | rc = 0; |
| 4932 | break; |
| 4933 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4934 | if ((lpfc_cmd->rdata->pnode) && |
| 4935 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4936 | rc = 0; |
| 4937 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | case LPFC_CTX_HOST: |
| 4939 | rc = 0; |
| 4940 | break; |
| 4941 | default: |
| 4942 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4943 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | break; |
| 4945 | } |
| 4946 | |
| 4947 | return rc; |
| 4948 | } |
| 4949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4951 | * 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] | 4952 | * @vport: Pointer to virtual port. |
| 4953 | * @tgt_id: SCSI ID of the target. |
| 4954 | * @lun_id: LUN ID of the scsi device. |
| 4955 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4956 | * |
| 4957 | * This function returns number of FCP commands pending for the vport. |
| 4958 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4959 | * commands pending on the vport associated with SCSI device specified |
| 4960 | * by tgt_id and lun_id parameters. |
| 4961 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4962 | * commands pending on the vport associated with SCSI target specified |
| 4963 | * by tgt_id parameter. |
| 4964 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4965 | * commands pending on the vport. |
| 4966 | * This function returns the number of iocbs which satisfy the filter. |
| 4967 | * This function is called without any lock held. |
| 4968 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4970 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4971 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4973 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4974 | struct lpfc_iocbq *iocbq; |
| 4975 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4977 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4978 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4980 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4981 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4982 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4983 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4984 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | return sum; |
| 4986 | } |
| 4987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4988 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4989 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4990 | * @phba: Pointer to HBA context object |
| 4991 | * @cmdiocb: Pointer to command iocb object. |
| 4992 | * @rspiocb: Pointer to response iocb object. |
| 4993 | * |
| 4994 | * This function is called when an aborted FCP iocb completes. This |
| 4995 | * function is called by the ring event handler with no lock held. |
| 4996 | * This function frees the iocb. |
| 4997 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4998 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5000 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 5001 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5002 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 5003 | return; |
| 5004 | } |
| 5005 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5007 | * 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] | 5008 | * @vport: Pointer to virtual port. |
| 5009 | * @pring: Pointer to driver SLI ring object. |
| 5010 | * @tgt_id: SCSI ID of the target. |
| 5011 | * @lun_id: LUN ID of the scsi device. |
| 5012 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 5013 | * |
| 5014 | * This function sends an abort command for every SCSI command |
| 5015 | * associated with the given virtual port pending on the ring |
| 5016 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 5017 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 5018 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 5019 | * parameters |
| 5020 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 5021 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 5022 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 5023 | * FCP iocbs associated with virtual port. |
| 5024 | * This function returns number of iocbs it failed to abort. |
| 5025 | * This function is called with no locks held. |
| 5026 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5028 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 5029 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5030 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5031 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5032 | struct lpfc_iocbq *iocbq; |
| 5033 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5034 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5035 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5036 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5037 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5038 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 5039 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5041 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5042 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5043 | continue; |
| 5044 | |
| 5045 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5046 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | if (abtsiocb == NULL) { |
| 5048 | errcnt++; |
| 5049 | continue; |
| 5050 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5051 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5052 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 5054 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 5055 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 5056 | abtsiocb->iocb.ulpLe = 1; |
| 5057 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5058 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5060 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 5062 | else |
| 5063 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 5064 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 5065 | /* Setup callback routine and issue the command. */ |
| 5066 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5067 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 5068 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5069 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5070 | errcnt++; |
| 5071 | continue; |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | return errcnt; |
| 5076 | } |
| 5077 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5079 | * 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] | 5080 | * @phba: Pointer to HBA context object. |
| 5081 | * @cmdiocbq: Pointer to command iocb. |
| 5082 | * @rspiocbq: Pointer to response iocb. |
| 5083 | * |
| 5084 | * This function is the completion handler for iocbs issued using |
| 5085 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 5086 | * ring event handler function without any lock held. This function |
| 5087 | * can be called from both worker thread context and interrupt |
| 5088 | * context. This function also can be called from other thread which |
| 5089 | * cleans up the SLI layer objects. |
| 5090 | * This function copy the contents of the response iocb to the |
| 5091 | * response iocb memory object provided by the caller of |
| 5092 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 5093 | * sleeps for the iocb completion. |
| 5094 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5095 | static void |
| 5096 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 5097 | struct lpfc_iocbq *cmdiocbq, |
| 5098 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5100 | wait_queue_head_t *pdone_q; |
| 5101 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5103 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5104 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 5105 | if (cmdiocbq->context2 && rspiocbq) |
| 5106 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 5107 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 5108 | |
| 5109 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5110 | if (pdone_q) |
| 5111 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5112 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | return; |
| 5114 | } |
| 5115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5117 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5118 | * @phba: Pointer to HBA context object.. |
| 5119 | * @pring: Pointer to sli ring. |
| 5120 | * @piocb: Pointer to command iocb. |
| 5121 | * @prspiocbq: Pointer to response iocb. |
| 5122 | * @timeout: Timeout in number of seconds. |
| 5123 | * |
| 5124 | * This function issues the iocb to firmware and waits for the |
| 5125 | * iocb to complete. If the iocb command is not |
| 5126 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 5127 | * Caller should not free the iocb resources if this function |
| 5128 | * returns IOCB_TIMEDOUT. |
| 5129 | * The function waits for the iocb completion using an |
| 5130 | * non-interruptible wait. |
| 5131 | * This function will sleep while waiting for iocb completion. |
| 5132 | * So, this function should not be called from any context which |
| 5133 | * does not allow sleeping. Due to the same reason, this function |
| 5134 | * cannot be called with interrupt disabled. |
| 5135 | * This function assumes that the iocb completions occur while |
| 5136 | * this function sleep. So, this function cannot be called from |
| 5137 | * the thread which process iocb completion for this ring. |
| 5138 | * This function clears the iocb_flag of the iocb object before |
| 5139 | * issuing the iocb and the iocb completion handler sets this |
| 5140 | * flag and wakes this thread when the iocb completes. |
| 5141 | * The contents of the response iocb will be copied to prspiocbq |
| 5142 | * by the completion handler when the command completes. |
| 5143 | * This function returns IOCB_SUCCESS when success. |
| 5144 | * This function is called with no lock held. |
| 5145 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5146 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5147 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 5148 | struct lpfc_sli_ring *pring, |
| 5149 | struct lpfc_iocbq *piocb, |
| 5150 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5151 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5152 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5153 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5154 | long timeleft, timeout_req = 0; |
| 5155 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5156 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5157 | |
| 5158 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5159 | * If the caller has provided a response iocbq buffer, then context2 |
| 5160 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5162 | if (prspiocbq) { |
| 5163 | if (piocb->context2) |
| 5164 | return IOCB_ERROR; |
| 5165 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5166 | } |
| 5167 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5168 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 5169 | piocb->context_un.wait_queue = &done_q; |
| 5170 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5171 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5172 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5173 | creg_val = readl(phba->HCregaddr); |
| 5174 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 5175 | writel(creg_val, phba->HCregaddr); |
| 5176 | readl(phba->HCregaddr); /* flush */ |
| 5177 | } |
| 5178 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5179 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 5180 | if (retval == IOCB_SUCCESS) { |
| 5181 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5182 | timeleft = wait_event_timeout(done_q, |
| 5183 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 5184 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5186 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 5187 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5188 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5189 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5190 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5191 | "0338 IOCB wait timeout error - no " |
| 5192 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5193 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5194 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5195 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5196 | "0330 IOCB wake NOT set, " |
| 5197 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5198 | timeout, (timeleft / jiffies)); |
| 5199 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5200 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5201 | } else { |
| 5202 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5203 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5204 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5205 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | } |
| 5207 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 5208 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5209 | creg_val = readl(phba->HCregaddr); |
| 5210 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 5211 | writel(creg_val, phba->HCregaddr); |
| 5212 | readl(phba->HCregaddr); /* flush */ |
| 5213 | } |
| 5214 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5215 | if (prspiocbq) |
| 5216 | piocb->context2 = NULL; |
| 5217 | |
| 5218 | piocb->context_un.wait_queue = NULL; |
| 5219 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5220 | return retval; |
| 5221 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 5222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5224 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5225 | * @phba: Pointer to HBA context object. |
| 5226 | * @pmboxq: Pointer to driver mailbox object. |
| 5227 | * @timeout: Timeout in number of seconds. |
| 5228 | * |
| 5229 | * This function issues the mailbox to firmware and waits for the |
| 5230 | * mailbox command to complete. If the mailbox command is not |
| 5231 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 5232 | * The function waits for the mailbox completion using an |
| 5233 | * interruptible wait. If the thread is woken up due to a |
| 5234 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 5235 | * should not free the mailbox resources, if this function returns |
| 5236 | * MBX_TIMEOUT. |
| 5237 | * This function will sleep while waiting for mailbox completion. |
| 5238 | * So, this function should not be called from any context which |
| 5239 | * does not allow sleeping. Due to the same reason, this function |
| 5240 | * cannot be called with interrupt disabled. |
| 5241 | * This function assumes that the mailbox completion occurs while |
| 5242 | * this function sleep. So, this function cannot be called from |
| 5243 | * the worker thread which processes mailbox completion. |
| 5244 | * This function is called in the context of HBA management |
| 5245 | * applications. |
| 5246 | * This function returns MBX_SUCCESS when successful. |
| 5247 | * This function is called with no lock held. |
| 5248 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5249 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5250 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | uint32_t timeout) |
| 5252 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5253 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5255 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5256 | |
| 5257 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5258 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5259 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5260 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5261 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5262 | /* setup wake call as IOCB callback */ |
| 5263 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 5264 | /* setup context field to pass wait_queue pointer to wake function */ |
| 5265 | pmboxq->context1 = &done_q; |
| 5266 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | /* now issue the command */ |
| 5268 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 5269 | |
| 5270 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5271 | wait_event_interruptible_timeout(done_q, |
| 5272 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 5273 | timeout * HZ); |
| 5274 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5275 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5277 | /* |
| 5278 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 5279 | * else do not free the resources. |
| 5280 | */ |
| 5281 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5283 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5284 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5285 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5286 | } |
| 5287 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | } |
| 5289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | return retval; |
| 5291 | } |
| 5292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5293 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5294 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5295 | * @phba: Pointer to HBA context. |
| 5296 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5297 | * This function is called to shutdown the driver's mailbox sub-system. |
| 5298 | * It first marks the mailbox sub-system is in a block state to prevent |
| 5299 | * the asynchronous mailbox command from issued off the pending mailbox |
| 5300 | * command queue. If the mailbox command sub-system shutdown is due to |
| 5301 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 5302 | * the mailbox sub-system flush routine to forcefully bring down the |
| 5303 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 5304 | * as with offline or HBA function reset), this routine will wait for the |
| 5305 | * outstanding mailbox command to complete before invoking the mailbox |
| 5306 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5307 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5308 | void |
| 5309 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5310 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5311 | struct lpfc_sli *psli = &phba->sli; |
| 5312 | uint8_t actcmd = MBX_HEARTBEAT; |
| 5313 | unsigned long timeout; |
| 5314 | |
| 5315 | spin_lock_irq(&phba->hbalock); |
| 5316 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 5317 | spin_unlock_irq(&phba->hbalock); |
| 5318 | |
| 5319 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| 5320 | spin_lock_irq(&phba->hbalock); |
| 5321 | if (phba->sli.mbox_active) |
| 5322 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
| 5323 | spin_unlock_irq(&phba->hbalock); |
| 5324 | /* Determine how long we might wait for the active mailbox |
| 5325 | * command to be gracefully completed by firmware. |
| 5326 | */ |
| 5327 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * |
| 5328 | 1000) + jiffies; |
| 5329 | while (phba->sli.mbox_active) { |
| 5330 | /* Check active mailbox complete status every 2ms */ |
| 5331 | msleep(2); |
| 5332 | if (time_after(jiffies, timeout)) |
| 5333 | /* Timeout, let the mailbox flush routine to |
| 5334 | * forcefully release active mailbox command |
| 5335 | */ |
| 5336 | break; |
| 5337 | } |
| 5338 | } |
| 5339 | lpfc_sli_mbox_sys_flush(phba); |
| 5340 | } |
| 5341 | |
| 5342 | /** |
| 5343 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 5344 | * @phba: Pointer to HBA context. |
| 5345 | * |
| 5346 | * This function is called to read the SLI3 device error attention registers |
| 5347 | * for possible error attention events. The caller must hold the hostlock |
| 5348 | * with spin_lock_irq(). |
| 5349 | * |
| 5350 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5351 | * Register and returns 0 otherwise. |
| 5352 | **/ |
| 5353 | static int |
| 5354 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 5355 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5356 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5357 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5358 | /* Read chip Host Attention (HA) register */ |
| 5359 | ha_copy = readl(phba->HAregaddr); |
| 5360 | if (ha_copy & HA_ERATT) { |
| 5361 | /* Read host status register to retrieve error event */ |
| 5362 | lpfc_sli_read_hs(phba); |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5363 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5364 | /* Check if there is a deferred error condition is active */ |
| 5365 | if ((HS_FFER1 & phba->work_hs) && |
| 5366 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 5367 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 5368 | spin_lock_irq(&phba->hbalock); |
| 5369 | phba->hba_flag |= DEFER_ERATT; |
| 5370 | spin_unlock_irq(&phba->hbalock); |
| 5371 | /* Clear all interrupt enable conditions */ |
| 5372 | writel(0, phba->HCregaddr); |
| 5373 | readl(phba->HCregaddr); |
| 5374 | } |
| 5375 | |
| 5376 | /* Set the driver HA work bitmap */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5377 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5378 | phba->work_ha |= HA_ERATT; |
| 5379 | /* Indicate polling handles this ERATT */ |
| 5380 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5381 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5382 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5383 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5384 | return 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5385 | } |
| 5386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5388 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5389 | * @phba: Pointer to HBA context. |
| 5390 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5391 | * This function is called from timer soft interrupt context to check HBA's |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5392 | * error attention register bit for error attention events. |
| 5393 | * |
| 5394 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5395 | * Register and returns 0 otherwise. |
| 5396 | **/ |
| 5397 | int |
| 5398 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 5399 | { |
| 5400 | uint32_t ha_copy; |
| 5401 | |
| 5402 | /* If somebody is waiting to handle an eratt, don't process it |
| 5403 | * here. The brdkill function will do this. |
| 5404 | */ |
| 5405 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5406 | return 0; |
| 5407 | |
| 5408 | /* Check if interrupt handler handles this ERATT */ |
| 5409 | spin_lock_irq(&phba->hbalock); |
| 5410 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 5411 | /* Interrupt handler has handled ERATT */ |
| 5412 | spin_unlock_irq(&phba->hbalock); |
| 5413 | return 0; |
| 5414 | } |
| 5415 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5416 | /* |
| 5417 | * If there is deferred error attention, do not check for error |
| 5418 | * attention |
| 5419 | */ |
| 5420 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5421 | spin_unlock_irq(&phba->hbalock); |
| 5422 | return 0; |
| 5423 | } |
| 5424 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5425 | /* If PCI channel is offline, don't process it */ |
| 5426 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5427 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5428 | return 0; |
| 5429 | } |
| 5430 | |
| 5431 | switch (phba->sli_rev) { |
| 5432 | case LPFC_SLI_REV2: |
| 5433 | case LPFC_SLI_REV3: |
| 5434 | /* Read chip Host Attention (HA) register */ |
| 5435 | ha_copy = lpfc_sli_eratt_read(phba); |
| 5436 | break; |
| 5437 | default: |
| 5438 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5439 | "0299 Invalid SLI revision (%d)\n", |
| 5440 | phba->sli_rev); |
| 5441 | ha_copy = 0; |
| 5442 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5443 | } |
| 5444 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5445 | |
| 5446 | return ha_copy; |
| 5447 | } |
| 5448 | |
| 5449 | /** |
| 5450 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 5451 | * @phba: Pointer to HBA context. |
| 5452 | * |
| 5453 | * This inline routine checks whether a device or its PCI slot is in a state |
| 5454 | * that the interrupt should be handled. |
| 5455 | * |
| 5456 | * This function returns 0 if the device or the PCI slot is in a state that |
| 5457 | * interrupt should be handled, otherwise -EIO. |
| 5458 | */ |
| 5459 | static inline int |
| 5460 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 5461 | { |
| 5462 | /* If the pci channel is offline, ignore all the interrupts */ |
| 5463 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5464 | return -EIO; |
| 5465 | |
| 5466 | /* Update device level interrupt statistics */ |
| 5467 | phba->sli.slistat.sli_intr++; |
| 5468 | |
| 5469 | /* Ignore all interrupts during initialization. */ |
| 5470 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5471 | return -EIO; |
| 5472 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5473 | return 0; |
| 5474 | } |
| 5475 | |
| 5476 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5477 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5478 | * @irq: Interrupt number. |
| 5479 | * @dev_id: The device context pointer. |
| 5480 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5481 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5482 | * service routine when device with SLI-3 interface spec is enabled with |
| 5483 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 5484 | * the 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 link attention and ELS ring attention events are |
| 5489 | * handled by the worker thread. The interrupt handler signals the worker |
| 5490 | * thread and returns for these events. This function is called without |
| 5491 | * any lock held. It gets the hbalock to access and update SLI data |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5492 | * structures. |
| 5493 | * |
| 5494 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5495 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5496 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5497 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5498 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5499 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5500 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | uint32_t ha_copy; |
| 5502 | uint32_t work_ha_copy; |
| 5503 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5504 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5505 | uint32_t control; |
| 5506 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5507 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5508 | struct lpfc_vport *vport; |
| 5509 | struct lpfc_nodelist *ndlp; |
| 5510 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5511 | LPFC_MBOXQ_t *pmb; |
| 5512 | int rc; |
| 5513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5514 | /* |
| 5515 | * Get the driver's phba structure from the dev_id and |
| 5516 | * assume the HBA is not interrupting. |
| 5517 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5518 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5519 | |
| 5520 | if (unlikely(!phba)) |
| 5521 | return IRQ_NONE; |
| 5522 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5523 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5524 | * Stuff needs to be attented to when this function is invoked as an |
| 5525 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5526 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5527 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5528 | /* Check device state for handling interrupt */ |
| 5529 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5530 | return IRQ_NONE; |
| 5531 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5532 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5533 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5534 | /* If somebody is waiting to handle an eratt don't process it |
| 5535 | * here. The brdkill function will do this. |
| 5536 | */ |
| 5537 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5538 | ha_copy &= ~HA_ERATT; |
| 5539 | /* Check the need for handling ERATT in interrupt handler */ |
| 5540 | if (ha_copy & HA_ERATT) { |
| 5541 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5542 | /* ERATT polling has handled ERATT */ |
| 5543 | ha_copy &= ~HA_ERATT; |
| 5544 | else |
| 5545 | /* Indicate interrupt handler handles ERATT */ |
| 5546 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5547 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5548 | |
| 5549 | /* |
| 5550 | * If there is deferred error attention, do not check for any |
| 5551 | * interrupt. |
| 5552 | */ |
| 5553 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5554 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5555 | return IRQ_NONE; |
| 5556 | } |
| 5557 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5558 | /* Clear up only attention source related to slow-path */ |
| 5559 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 5560 | phba->HAregaddr); |
| 5561 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5562 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5563 | } else |
| 5564 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5566 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5567 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5568 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5569 | if (work_ha_copy & HA_LATT) { |
| 5570 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5571 | /* |
| 5572 | * Turn off Link Attention interrupts |
| 5573 | * until CLEAR_LA done |
| 5574 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5575 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5576 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5577 | control = readl(phba->HCregaddr); |
| 5578 | control &= ~HC_LAINT_ENA; |
| 5579 | writel(control, phba->HCregaddr); |
| 5580 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5582 | } |
| 5583 | else |
| 5584 | work_ha_copy &= ~HA_LATT; |
| 5585 | } |
| 5586 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5587 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5588 | /* |
| 5589 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5590 | * the only slow ring. |
| 5591 | */ |
| 5592 | status = (work_ha_copy & |
| 5593 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5594 | status >>= (4*LPFC_ELS_RING); |
| 5595 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5596 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5597 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5598 | |
| 5599 | lpfc_debugfs_slow_ring_trc(phba, |
| 5600 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5601 | control, status, |
| 5602 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5603 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5604 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5605 | lpfc_debugfs_slow_ring_trc(phba, |
| 5606 | "ISR Disable ring:" |
| 5607 | "pwork:x%x hawork:x%x wait:x%x", |
| 5608 | phba->work_ha, work_ha_copy, |
| 5609 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5610 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5611 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5612 | control &= |
| 5613 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5614 | writel(control, phba->HCregaddr); |
| 5615 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5616 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5617 | else { |
| 5618 | lpfc_debugfs_slow_ring_trc(phba, |
| 5619 | "ISR slow ring: pwork:" |
| 5620 | "x%x hawork:x%x wait:x%x", |
| 5621 | phba->work_ha, work_ha_copy, |
| 5622 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5623 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5624 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5625 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5626 | } |
| 5627 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5628 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5629 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5630 | lpfc_sli_read_hs(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5631 | /* |
| 5632 | * Check if there is a deferred error condition |
| 5633 | * is active |
| 5634 | */ |
| 5635 | if ((HS_FFER1 & phba->work_hs) && |
| 5636 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 5637 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 5638 | phba->hba_flag |= DEFER_ERATT; |
| 5639 | /* Clear all interrupt enable conditions */ |
| 5640 | writel(0, phba->HCregaddr); |
| 5641 | readl(phba->HCregaddr); |
| 5642 | } |
| 5643 | } |
| 5644 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5645 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5646 | pmb = phba->sli.mbox_active; |
| 5647 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5648 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5649 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5650 | |
| 5651 | /* First check out the status word */ |
| 5652 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5653 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5654 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5655 | /* |
| 5656 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5657 | * mbxStatus <status> |
| 5658 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5659 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5660 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5661 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5662 | "Interrupt mbxCommand x%x " |
| 5663 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5664 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5665 | pmbox->mbxCommand, |
| 5666 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5667 | /* clear mailbox attention bit */ |
| 5668 | work_ha_copy &= ~HA_MBATT; |
| 5669 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5670 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5671 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5672 | phba->last_completion_time = jiffies; |
| 5673 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5674 | if (pmb->mbox_cmpl) { |
| 5675 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5676 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5677 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5678 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5679 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5680 | |
| 5681 | lpfc_debugfs_disc_trc(vport, |
| 5682 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5683 | "MBOX dflt rpi: : " |
| 5684 | "status:x%x rpi:x%x", |
| 5685 | (uint32_t)pmbox->mbxStatus, |
| 5686 | pmbox->un.varWords[0], 0); |
| 5687 | |
| 5688 | if (!pmbox->mbxStatus) { |
| 5689 | mp = (struct lpfc_dmabuf *) |
| 5690 | (pmb->context1); |
| 5691 | ndlp = (struct lpfc_nodelist *) |
| 5692 | pmb->context2; |
| 5693 | |
| 5694 | /* Reg_LOGIN of dflt RPI was |
| 5695 | * successful. new lets get |
| 5696 | * rid of the RPI using the |
| 5697 | * same mbox buffer. |
| 5698 | */ |
| 5699 | lpfc_unreg_login(phba, |
| 5700 | vport->vpi, |
| 5701 | pmbox->un.varWords[0], |
| 5702 | pmb); |
| 5703 | pmb->mbox_cmpl = |
| 5704 | lpfc_mbx_cmpl_dflt_rpi; |
| 5705 | pmb->context1 = mp; |
| 5706 | pmb->context2 = ndlp; |
| 5707 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5708 | rc = lpfc_sli_issue_mbox(phba, |
| 5709 | pmb, |
| 5710 | MBX_NOWAIT); |
| 5711 | if (rc != MBX_BUSY) |
| 5712 | lpfc_printf_log(phba, |
| 5713 | KERN_ERR, |
| 5714 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5715 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5716 | "been MBX_BUSY"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5717 | if (rc != MBX_NOT_FINISHED) |
| 5718 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5719 | } |
| 5720 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5721 | spin_lock_irqsave( |
| 5722 | &phba->pport->work_port_lock, |
| 5723 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5724 | phba->pport->work_port_events &= |
| 5725 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5726 | spin_unlock_irqrestore( |
| 5727 | &phba->pport->work_port_lock, |
| 5728 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5729 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5730 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5731 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5732 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5733 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5734 | if ((work_ha_copy & HA_MBATT) && |
| 5735 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5736 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5737 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5738 | do { |
| 5739 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5740 | MBX_NOWAIT); |
| 5741 | } while (rc == MBX_NOT_FINISHED); |
| 5742 | if (rc != MBX_SUCCESS) |
| 5743 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5744 | LOG_SLI, "0349 rc should be " |
| 5745 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5746 | } |
| 5747 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5748 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5749 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5750 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5751 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5752 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5753 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5754 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5755 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5756 | |
| 5757 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5758 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5759 | * @irq: Interrupt number. |
| 5760 | * @dev_id: The device context pointer. |
| 5761 | * |
| 5762 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5763 | * service routine when device with SLI-3 interface spec is enabled with |
| 5764 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 5765 | * ring event in the HBA. However, when the device is enabled with either |
| 5766 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 5767 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 5768 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 5769 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 5770 | * the intrrupt context. This function is called without any lock held. |
| 5771 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5772 | * |
| 5773 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5774 | * returns IRQ_NONE. |
| 5775 | **/ |
| 5776 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5777 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5778 | { |
| 5779 | struct lpfc_hba *phba; |
| 5780 | uint32_t ha_copy; |
| 5781 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5782 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5783 | |
| 5784 | /* Get the driver's phba structure from the dev_id and |
| 5785 | * assume the HBA is not interrupting. |
| 5786 | */ |
| 5787 | phba = (struct lpfc_hba *) dev_id; |
| 5788 | |
| 5789 | if (unlikely(!phba)) |
| 5790 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | |
| 5792 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5793 | * Stuff needs to be attented to when this function is invoked as an |
| 5794 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5795 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5796 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5797 | /* Check device state for handling interrupt */ |
| 5798 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5799 | return IRQ_NONE; |
| 5800 | /* Need to read HA REG for FCP ring and other ring events */ |
| 5801 | ha_copy = readl(phba->HAregaddr); |
| 5802 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5803 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5804 | /* |
| 5805 | * If there is deferred error attention, do not check for |
| 5806 | * any interrupt. |
| 5807 | */ |
| 5808 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5809 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5810 | return IRQ_NONE; |
| 5811 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5812 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 5813 | phba->HAregaddr); |
| 5814 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5815 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5816 | } else |
| 5817 | ha_copy = phba->ha_copy; |
| 5818 | |
| 5819 | /* |
| 5820 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 5821 | */ |
| 5822 | ha_copy &= ~(phba->work_ha_mask); |
| 5823 | |
| 5824 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5825 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5826 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | lpfc_sli_handle_fast_ring_event(phba, |
| 5828 | &phba->sli.ring[LPFC_FCP_RING], |
| 5829 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5830 | |
| 5831 | if (phba->cfg_multi_ring_support == 2) { |
| 5832 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5833 | * Process all events on extra ring. Take the optimized path |
| 5834 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5835 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5836 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5837 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5838 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5839 | lpfc_sli_handle_fast_ring_event(phba, |
| 5840 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5841 | status); |
| 5842 | } |
| 5843 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5844 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5845 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5846 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5847 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5848 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5849 | * @irq: Interrupt number. |
| 5850 | * @dev_id: The device context pointer. |
| 5851 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5852 | * This function is the HBA device-level interrupt handler to device with |
| 5853 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 5854 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 5855 | * requires driver attention. This function invokes the slow-path interrupt |
| 5856 | * attention handling function and fast-path interrupt attention handling |
| 5857 | * function in turn to process the relevant HBA attention events. This |
| 5858 | * function is called without any lock held. It gets the hbalock to access |
| 5859 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5860 | * |
| 5861 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 5862 | * returns IRQ_NONE. |
| 5863 | **/ |
| 5864 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5865 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5866 | { |
| 5867 | struct lpfc_hba *phba; |
| 5868 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 5869 | unsigned long status1, status2; |
| 5870 | |
| 5871 | /* |
| 5872 | * Get the driver's phba structure from the dev_id and |
| 5873 | * assume the HBA is not interrupting. |
| 5874 | */ |
| 5875 | phba = (struct lpfc_hba *) dev_id; |
| 5876 | |
| 5877 | if (unlikely(!phba)) |
| 5878 | return IRQ_NONE; |
| 5879 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5880 | /* Check device state for handling interrupt */ |
| 5881 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5882 | return IRQ_NONE; |
| 5883 | |
| 5884 | spin_lock(&phba->hbalock); |
| 5885 | phba->ha_copy = readl(phba->HAregaddr); |
| 5886 | if (unlikely(!phba->ha_copy)) { |
| 5887 | spin_unlock(&phba->hbalock); |
| 5888 | return IRQ_NONE; |
| 5889 | } else if (phba->ha_copy & HA_ERATT) { |
| 5890 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5891 | /* ERATT polling has handled ERATT */ |
| 5892 | phba->ha_copy &= ~HA_ERATT; |
| 5893 | else |
| 5894 | /* Indicate interrupt handler handles ERATT */ |
| 5895 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5896 | } |
| 5897 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5898 | /* |
| 5899 | * If there is deferred error attention, do not check for any interrupt. |
| 5900 | */ |
| 5901 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 5902 | spin_unlock_irq(&phba->hbalock); |
| 5903 | return IRQ_NONE; |
| 5904 | } |
| 5905 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5906 | /* Clear attention sources except link and error attentions */ |
| 5907 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5908 | readl(phba->HAregaddr); /* flush */ |
| 5909 | spin_unlock(&phba->hbalock); |
| 5910 | |
| 5911 | /* |
| 5912 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 5913 | */ |
| 5914 | |
| 5915 | /* status of events with mailbox and link attention */ |
| 5916 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 5917 | |
| 5918 | /* status of events with ELS ring */ |
| 5919 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5920 | status2 >>= (4*LPFC_ELS_RING); |
| 5921 | |
| 5922 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5923 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5924 | else |
| 5925 | sp_irq_rc = IRQ_NONE; |
| 5926 | |
| 5927 | /* |
| 5928 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 5929 | */ |
| 5930 | |
| 5931 | /* status of events with FCP ring */ |
| 5932 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5933 | status1 >>= (4*LPFC_FCP_RING); |
| 5934 | |
| 5935 | /* status of events with extra ring */ |
| 5936 | if (phba->cfg_multi_ring_support == 2) { |
| 5937 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5938 | status2 >>= (4*LPFC_EXTRA_RING); |
| 5939 | } else |
| 5940 | status2 = 0; |
| 5941 | |
| 5942 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5943 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5944 | else |
| 5945 | fp_irq_rc = IRQ_NONE; |
| 5946 | |
| 5947 | /* Return device-level interrupt handling status */ |
| 5948 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame^] | 5949 | } /* lpfc_sli_intr_handler */ |