| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_cmnd.h> |
| 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 31 | #include <scsi/scsi_transport_fc.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_scsi.h" |
| 38 | #include "lpfc.h" |
| 39 | #include "lpfc_crtn.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 42 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 46 | * This allows multiple uses of lpfc_msgBlk0311 |
| 47 | * w/o perturbing log msg utility. |
| 48 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | lpfc_printf_log(phba, \ |
| 51 | KERN_INFO, \ |
| 52 | LOG_MBOX | LOG_SLI, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 53 | "(%d):0311 Mailbox command x%x cannot " \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 | "issue Data: x%x x%x x%x\n", \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 55 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 56 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | |
| 62 | /* There are only four IOCB completion types. */ |
| 63 | typedef enum _lpfc_iocb_type { |
| 64 | LPFC_UNKNOWN_IOCB, |
| 65 | LPFC_UNSOL_IOCB, |
| 66 | LPFC_SOL_IOCB, |
| 67 | LPFC_ABORT_IOCB |
| 68 | } lpfc_iocb_type; |
| 69 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 70 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 71 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 72 | * @phba: Pointer to HBA context object. |
| 73 | * @pring: Pointer to driver SLI ring object. |
| 74 | * |
| 75 | * This function returns pointer to next command iocb entry |
| 76 | * in the command ring. The caller must hold hbalock to prevent |
| 77 | * other threads consume the next command iocb. |
| 78 | * SLI-2/SLI-3 provide different sized iocbs. |
| 79 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 80 | static inline IOCB_t * |
| 81 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 82 | { |
| 83 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 84 | pring->cmdidx * phba->iocb_cmd_size); |
| 85 | } |
| 86 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 87 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 88 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 89 | * @phba: Pointer to HBA context object. |
| 90 | * @pring: Pointer to driver SLI ring object. |
| 91 | * |
| 92 | * This function returns pointer to next response iocb entry |
| 93 | * in the response ring. The caller must hold hbalock to make sure |
| 94 | * that no other thread consume the next response iocb. |
| 95 | * SLI-2/SLI-3 provide different sized iocbs. |
| 96 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 97 | static inline IOCB_t * |
| 98 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 99 | { |
| 100 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 101 | pring->rspidx * phba->iocb_rsp_size); |
| 102 | } |
| 103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 105 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 106 | * @phba: Pointer to HBA context object. |
| 107 | * |
| 108 | * This function is called with hbalock held. This function |
| 109 | * allocates a new driver iocb object from the iocb pool. If the |
| 110 | * allocation is successful, it returns pointer to the newly |
| 111 | * allocated iocb object else it returns NULL. |
| 112 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 113 | static struct lpfc_iocbq * |
| 114 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 115 | { |
| 116 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 117 | struct lpfc_iocbq * iocbq = NULL; |
| 118 | |
| 119 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 120 | return iocbq; |
| 121 | } |
| 122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 124 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 125 | * @phba: Pointer to HBA context object. |
| 126 | * |
| 127 | * This function is called with no lock held. This function |
| 128 | * allocates a new driver iocb object from the iocb pool. If the |
| 129 | * allocation is successful, it returns pointer to the newly |
| 130 | * allocated iocb object else it returns NULL. |
| 131 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 132 | struct lpfc_iocbq * |
| 133 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 134 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 135 | struct lpfc_iocbq * iocbq = NULL; |
| 136 | unsigned long iflags; |
| 137 | |
| 138 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 139 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 140 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 141 | return iocbq; |
| 142 | } |
| 143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 145 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 146 | * @phba: Pointer to HBA context object. |
| 147 | * @iocbq: Pointer to driver iocb object. |
| 148 | * |
| 149 | * This function is called with hbalock held to release driver |
| 150 | * iocb object to the iocb pool. The iotag in the iocb object |
| 151 | * does not change for each use of the iocb object. This function |
| 152 | * clears all other fields of the iocb object when it is freed. |
| 153 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 154 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 155 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 156 | { |
| 157 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * Clean all volatile data fields, preserve iotag and node struct. |
| 161 | */ |
| 162 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 163 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 164 | } |
| 165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 167 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 168 | * @phba: Pointer to HBA context object. |
| 169 | * @iocbq: Pointer to driver iocb object. |
| 170 | * |
| 171 | * This function is called with no lock held to release the iocb to |
| 172 | * iocb pool. |
| 173 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 174 | void |
| 175 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 176 | { |
| 177 | unsigned long iflags; |
| 178 | |
| 179 | /* |
| 180 | * Clean all volatile data fields, preserve iotag and node struct. |
| 181 | */ |
| 182 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 183 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 185 | } |
| 186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 188 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 189 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 190 | * |
| 191 | * This function is called by ring event handler function to get the iocb type. |
| 192 | * This function translates the iocb command to an iocb command type used to |
| 193 | * decide the final disposition of each completed IOCB. |
| 194 | * The function returns |
| 195 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 196 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 197 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 198 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 199 | * |
| 200 | * The caller is not required to hold any lock. |
| 201 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | static lpfc_iocb_type |
| 203 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 204 | { |
| 205 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 206 | |
| 207 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 208 | return 0; |
| 209 | |
| 210 | switch (iocb_cmnd) { |
| 211 | case CMD_XMIT_SEQUENCE_CR: |
| 212 | case CMD_XMIT_SEQUENCE_CX: |
| 213 | case CMD_XMIT_BCAST_CN: |
| 214 | case CMD_XMIT_BCAST_CX: |
| 215 | case CMD_ELS_REQUEST_CR: |
| 216 | case CMD_ELS_REQUEST_CX: |
| 217 | case CMD_CREATE_XRI_CR: |
| 218 | case CMD_CREATE_XRI_CX: |
| 219 | case CMD_GET_RPI_CN: |
| 220 | case CMD_XMIT_ELS_RSP_CX: |
| 221 | case CMD_GET_RPI_CR: |
| 222 | case CMD_FCP_IWRITE_CR: |
| 223 | case CMD_FCP_IWRITE_CX: |
| 224 | case CMD_FCP_IREAD_CR: |
| 225 | case CMD_FCP_IREAD_CX: |
| 226 | case CMD_FCP_ICMND_CR: |
| 227 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 228 | case CMD_FCP_TSEND_CX: |
| 229 | case CMD_FCP_TRSP_CX: |
| 230 | case CMD_FCP_TRECEIVE_CX: |
| 231 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | case CMD_ADAPTER_MSG: |
| 233 | case CMD_ADAPTER_DUMP: |
| 234 | case CMD_XMIT_SEQUENCE64_CR: |
| 235 | case CMD_XMIT_SEQUENCE64_CX: |
| 236 | case CMD_XMIT_BCAST64_CN: |
| 237 | case CMD_XMIT_BCAST64_CX: |
| 238 | case CMD_ELS_REQUEST64_CR: |
| 239 | case CMD_ELS_REQUEST64_CX: |
| 240 | case CMD_FCP_IWRITE64_CR: |
| 241 | case CMD_FCP_IWRITE64_CX: |
| 242 | case CMD_FCP_IREAD64_CR: |
| 243 | case CMD_FCP_IREAD64_CX: |
| 244 | case CMD_FCP_ICMND64_CR: |
| 245 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 246 | case CMD_FCP_TSEND64_CX: |
| 247 | case CMD_FCP_TRSP64_CX: |
| 248 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | case CMD_GEN_REQUEST64_CR: |
| 250 | case CMD_GEN_REQUEST64_CX: |
| 251 | case CMD_XMIT_ELS_RSP64_CX: |
| 252 | type = LPFC_SOL_IOCB; |
| 253 | break; |
| 254 | case CMD_ABORT_XRI_CN: |
| 255 | case CMD_ABORT_XRI_CX: |
| 256 | case CMD_CLOSE_XRI_CN: |
| 257 | case CMD_CLOSE_XRI_CX: |
| 258 | case CMD_XRI_ABORTED_CX: |
| 259 | case CMD_ABORT_MXRI64_CN: |
| 260 | type = LPFC_ABORT_IOCB; |
| 261 | break; |
| 262 | case CMD_RCV_SEQUENCE_CX: |
| 263 | case CMD_RCV_ELS_REQ_CX: |
| 264 | case CMD_RCV_SEQUENCE64_CX: |
| 265 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 266 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 267 | case CMD_IOCB_RCV_SEQ64_CX: |
| 268 | case CMD_IOCB_RCV_ELS64_CX: |
| 269 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 270 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | type = LPFC_UNSOL_IOCB; |
| 272 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 273 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 274 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 275 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 276 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 277 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 278 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 279 | case CMD_IOCB_RET_HBQE64_CN: |
| 280 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 281 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 282 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 283 | case CMD_IOCB_LOGENTRY_CN: |
| 284 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 285 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 286 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 287 | type = LPFC_UNKNOWN_IOCB; |
| 288 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | default: |
| 290 | type = LPFC_UNKNOWN_IOCB; |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | return type; |
| 295 | } |
| 296 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 297 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 298 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 299 | * @phba: Pointer to HBA context object. |
| 300 | * |
| 301 | * This function is called from SLI initialization code |
| 302 | * to configure every ring of the HBA's SLI interface. The |
| 303 | * caller is not required to hold any lock. This function issues |
| 304 | * a config_ring mailbox command for each ring. |
| 305 | * This function returns zero if successful else returns a negative |
| 306 | * error code. |
| 307 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 309 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 310 | { |
| 311 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 312 | LPFC_MBOXQ_t *pmb; |
| 313 | MAILBOX_t *pmbox; |
| 314 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 316 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 317 | if (!pmb) |
| 318 | return -ENOMEM; |
| 319 | pmbox = &pmb->mb; |
| 320 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 | lpfc_config_ring(phba, i, pmb); |
| 323 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 324 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 326 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 328 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 329 | rc, pmbox->mbxCommand, |
| 330 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 331 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 332 | ret = -ENXIO; |
| 333 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | } |
| 335 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 336 | mempool_free(pmb, phba->mbox_mem_pool); |
| 337 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 338 | } |
| 339 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 340 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 341 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 342 | * @phba: Pointer to HBA context object. |
| 343 | * @pring: Pointer to driver SLI ring object. |
| 344 | * @piocb: Pointer to the driver iocb object. |
| 345 | * |
| 346 | * This function is called with hbalock held. The function adds the |
| 347 | * new iocb to txcmplq of the given ring. This function always returns |
| 348 | * 0. If this function is called for ELS ring, this function checks if |
| 349 | * there is a vport associated with the ELS command. This function also |
| 350 | * starts els_tmofunc timer if this is an ELS command. |
| 351 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 353 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 354 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 356 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 357 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 359 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 360 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 361 | if (!piocb->vport) |
| 362 | BUG(); |
| 363 | else |
| 364 | mod_timer(&piocb->vport->els_tmofunc, |
| 365 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 366 | } |
| 367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 368 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 369 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | } |
| 371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 372 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 373 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 374 | * @phba: Pointer to HBA context object. |
| 375 | * @pring: Pointer to driver SLI ring object. |
| 376 | * |
| 377 | * This function is called with hbalock held to get next |
| 378 | * iocb in txq of the given ring. If there is any iocb in |
| 379 | * the txq, the function returns first iocb in the list after |
| 380 | * removing the iocb from the list, else it returns NULL. |
| 381 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 383 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | struct lpfc_iocbq *cmd_iocb; |
| 386 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 387 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 388 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 389 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 390 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 391 | } |
| 392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 393 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 394 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 395 | * @phba: Pointer to HBA context object. |
| 396 | * @pring: Pointer to driver SLI ring object. |
| 397 | * |
| 398 | * This function is called with hbalock held and the caller must post the |
| 399 | * iocb without releasing the lock. If the caller releases the lock, |
| 400 | * iocb slot returned by the function is not guaranteed to be available. |
| 401 | * The function returns pointer to the next available iocb slot if there |
| 402 | * is available slot in the ring, else it returns NULL. |
| 403 | * If the get index of the ring is ahead of the put index, the function |
| 404 | * will post an error attention event to the worker thread to take the |
| 405 | * HBA to offline state. |
| 406 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | static IOCB_t * |
| 408 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 409 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 410 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 413 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 414 | pring->next_cmdidx = 0; |
| 415 | |
| 416 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 417 | |
| 418 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 419 | |
| 420 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 421 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 422 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 423 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 424 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | pring->local_getidx, max_cmd_idx); |
| 426 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 427 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | /* |
| 429 | * All error attention handlers are posted to |
| 430 | * worker thread |
| 431 | */ |
| 432 | phba->work_ha |= HA_ERATT; |
| 433 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 434 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 435 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | |
| 437 | return NULL; |
| 438 | } |
| 439 | |
| 440 | if (pring->local_getidx == pring->next_cmdidx) |
| 441 | return NULL; |
| 442 | } |
| 443 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 444 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | } |
| 446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 448 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 449 | * @phba: Pointer to HBA context object. |
| 450 | * @iocbq: Pointer to driver iocb object. |
| 451 | * |
| 452 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 453 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 454 | * array and assigns a new iotag. |
| 455 | * The function returns the allocated iotag if successful, else returns zero. |
| 456 | * Zero is not a valid iotag. |
| 457 | * The caller is not required to hold any lock. |
| 458 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 459 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 460 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 462 | struct lpfc_iocbq **new_arr; |
| 463 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 464 | size_t new_len; |
| 465 | struct lpfc_sli *psli = &phba->sli; |
| 466 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 468 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 469 | iotag = psli->last_iotag; |
| 470 | if(++iotag < psli->iocbq_lookup_len) { |
| 471 | psli->last_iotag = iotag; |
| 472 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 473 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 474 | iocbq->iotag = iotag; |
| 475 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 476 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 477 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 478 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 479 | spin_unlock_irq(&phba->hbalock); |
| 480 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 481 | GFP_KERNEL); |
| 482 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 483 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 484 | old_arr = psli->iocbq_lookup; |
| 485 | if (new_len <= psli->iocbq_lookup_len) { |
| 486 | /* highly unprobable case */ |
| 487 | kfree(new_arr); |
| 488 | iotag = psli->last_iotag; |
| 489 | if(++iotag < psli->iocbq_lookup_len) { |
| 490 | psli->last_iotag = iotag; |
| 491 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 492 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 493 | iocbq->iotag = iotag; |
| 494 | return iotag; |
| 495 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 496 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | if (psli->iocbq_lookup) |
| 500 | memcpy(new_arr, old_arr, |
| 501 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 502 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 503 | psli->iocbq_lookup = new_arr; |
| 504 | psli->iocbq_lookup_len = new_len; |
| 505 | psli->last_iotag = iotag; |
| 506 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 508 | iocbq->iotag = iotag; |
| 509 | kfree(old_arr); |
| 510 | return iotag; |
| 511 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 512 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 513 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 515 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 516 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 517 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 519 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 520 | } |
| 521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 522 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 523 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 524 | * @phba: Pointer to HBA context object. |
| 525 | * @pring: Pointer to driver SLI ring object. |
| 526 | * @iocb: Pointer to iocb slot in the ring. |
| 527 | * @nextiocb: Pointer to driver iocb object which need to be |
| 528 | * posted to firmware. |
| 529 | * |
| 530 | * This function is called with hbalock held to post a new iocb to |
| 531 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 532 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 533 | * a completion call back for this iocb else the function will free the |
| 534 | * iocb object. |
| 535 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | static void |
| 537 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 538 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 539 | { |
| 540 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 541 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 543 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 544 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 545 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 546 | if (pring->ringno == LPFC_ELS_RING) { |
| 547 | lpfc_debugfs_slow_ring_trc(phba, |
| 548 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 549 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 550 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 551 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 552 | } |
| 553 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 554 | /* |
| 555 | * Issue iocb command to adapter |
| 556 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 557 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 558 | wmb(); |
| 559 | pring->stats.iocb_cmd++; |
| 560 | |
| 561 | /* |
| 562 | * If there is no completion routine to call, we can release the |
| 563 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 564 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 565 | */ |
| 566 | if (nextiocb->iocb_cmpl) |
| 567 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 568 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 569 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * Let the HBA know what IOCB slot will be the next one the |
| 573 | * driver will put a command into. |
| 574 | */ |
| 575 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 576 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 577 | } |
| 578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 579 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 580 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 581 | * @phba: Pointer to HBA context object. |
| 582 | * @pring: Pointer to driver SLI ring object. |
| 583 | * |
| 584 | * The caller is not required to hold any lock for calling this function. |
| 585 | * This function updates the chip attention bits for the ring to inform firmware |
| 586 | * that there are pending work to be done for this ring and requests an |
| 587 | * interrupt when there is space available in the ring. This function is |
| 588 | * called when the driver is unable to post more iocbs to the ring due |
| 589 | * to unavailability of space in the ring. |
| 590 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 592 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | { |
| 594 | int ringno = pring->ringno; |
| 595 | |
| 596 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 597 | |
| 598 | wmb(); |
| 599 | |
| 600 | /* |
| 601 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 602 | * The HBA will tell us when an IOCB entry is available. |
| 603 | */ |
| 604 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 605 | readl(phba->CAregaddr); /* flush */ |
| 606 | |
| 607 | pring->stats.iocb_cmd_full++; |
| 608 | } |
| 609 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 610 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 611 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 612 | * @phba: Pointer to HBA context object. |
| 613 | * @pring: Pointer to driver SLI ring object. |
| 614 | * |
| 615 | * This function updates the chip attention register bit for the |
| 616 | * given ring to inform HBA that there is more work to be done |
| 617 | * in this ring. The caller is not required to hold any lock. |
| 618 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 620 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | { |
| 622 | int ringno = pring->ringno; |
| 623 | |
| 624 | /* |
| 625 | * Tell the HBA that there is work to do in this ring. |
| 626 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 627 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 628 | wmb(); |
| 629 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 630 | readl(phba->CAregaddr); /* flush */ |
| 631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | } |
| 633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 635 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 636 | * @phba: Pointer to HBA context object. |
| 637 | * @pring: Pointer to driver SLI ring object. |
| 638 | * |
| 639 | * This function is called with hbalock held to post pending iocbs |
| 640 | * in the txq to the firmware. This function is called when driver |
| 641 | * detects space available in the ring. |
| 642 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 644 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | { |
| 646 | IOCB_t *iocb; |
| 647 | struct lpfc_iocbq *nextiocb; |
| 648 | |
| 649 | /* |
| 650 | * Check to see if: |
| 651 | * (a) there is anything on the txq to send |
| 652 | * (b) link is up |
| 653 | * (c) link attention events can be processed (fcp ring only) |
| 654 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 655 | */ |
| 656 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 657 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 658 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 659 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | |
| 661 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 662 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 663 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 664 | |
| 665 | if (iocb) |
| 666 | lpfc_sli_update_ring(phba, pring); |
| 667 | else |
| 668 | lpfc_sli_update_full_ring(phba, pring); |
| 669 | } |
| 670 | |
| 671 | return; |
| 672 | } |
| 673 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 674 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 675 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 676 | * @phba: Pointer to HBA context object. |
| 677 | * @hbqno: HBQ number. |
| 678 | * |
| 679 | * This function is called with hbalock held to get the next |
| 680 | * available slot for the given HBQ. If there is free slot |
| 681 | * available for the HBQ it will return pointer to the next available |
| 682 | * HBQ entry else it will return NULL. |
| 683 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 684 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 685 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 686 | { |
| 687 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 688 | |
| 689 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 690 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 691 | hbqp->next_hbqPutIdx = 0; |
| 692 | |
| 693 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 694 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 695 | uint32_t getidx = le32_to_cpu(raw_index); |
| 696 | |
| 697 | hbqp->local_hbqGetIdx = getidx; |
| 698 | |
| 699 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 700 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 701 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 702 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 703 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 704 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 705 | hbqp->entry_count); |
| 706 | |
| 707 | phba->link_state = LPFC_HBA_ERROR; |
| 708 | return NULL; |
| 709 | } |
| 710 | |
| 711 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 712 | return NULL; |
| 713 | } |
| 714 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 715 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 716 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 717 | } |
| 718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 719 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 720 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 721 | * @phba: Pointer to HBA context object. |
| 722 | * |
| 723 | * This function is called with no lock held to free all the |
| 724 | * hbq buffers while uninitializing the SLI interface. It also |
| 725 | * frees the HBQ buffers returned by the firmware but not yet |
| 726 | * processed by the upper layers. |
| 727 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 728 | void |
| 729 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 730 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 731 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 732 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 733 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 734 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 735 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 736 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 737 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 738 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 739 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 740 | for (i = 0; i < hbq_count; ++i) { |
| 741 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 742 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 743 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 744 | list_del(&hbq_buf->dbuf.list); |
| 745 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 746 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 747 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 748 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 749 | /* Return all HBQ buffer that are in-fly */ |
| 750 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 751 | &phba->hbqbuf_in_list, list) { |
| 752 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 753 | list_del(&hbq_buf->dbuf.list); |
| 754 | if (hbq_buf->tag == -1) { |
| 755 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 756 | (phba, hbq_buf); |
| 757 | } else { |
| 758 | hbqno = hbq_buf->tag >> 16; |
| 759 | if (hbqno >= LPFC_MAX_HBQS) |
| 760 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 761 | (phba, hbq_buf); |
| 762 | else |
| 763 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 764 | hbq_buf); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /* Mark the HBQs not in use */ |
| 769 | phba->hbq_in_use = 0; |
| 770 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 771 | } |
| 772 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 774 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 775 | * @phba: Pointer to HBA context object. |
| 776 | * @hbqno: HBQ number. |
| 777 | * @hbq_buf: Pointer to HBQ buffer. |
| 778 | * |
| 779 | * This function is called with the hbalock held to post a |
| 780 | * hbq buffer to the firmware. If the function finds an empty |
| 781 | * slot in the HBQ, it will post the buffer. The function will return |
| 782 | * pointer to the hbq entry if it successfully post the buffer |
| 783 | * else it will return NULL. |
| 784 | **/ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 785 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 787 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 788 | { |
| 789 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 790 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 791 | |
| 792 | /* Get next HBQ entry slot to use */ |
| 793 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 794 | if (hbqe) { |
| 795 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 796 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 798 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 799 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 800 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 801 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 802 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 803 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 804 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 805 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 806 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 807 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 808 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 809 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 810 | return hbqe; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 811 | } |
| 812 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 813 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 814 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 815 | .rn = 1, |
| 816 | .entry_count = 200, |
| 817 | .mask_count = 0, |
| 818 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 819 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 820 | .buffer_count = 0, |
| 821 | .init_count = 20, |
| 822 | .add_count = 5, |
| 823 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 825 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 826 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 827 | .rn = 1, |
| 828 | .entry_count = 200, |
| 829 | .mask_count = 0, |
| 830 | .profile = 0, |
| 831 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 832 | .buffer_count = 0, |
| 833 | .init_count = 0, |
| 834 | .add_count = 5, |
| 835 | }; |
| 836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 837 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 838 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 839 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 840 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 841 | }; |
| 842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 844 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 845 | * @phba: Pointer to HBA context object. |
| 846 | * @hbqno: HBQ number. |
| 847 | * @count: Number of HBQ buffers to be posted. |
| 848 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 849 | * This function is called with no lock held to post more hbq buffers to the |
| 850 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 851 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 852 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 853 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 854 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 855 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 856 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 857 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 858 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 859 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 860 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 861 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 862 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 863 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 864 | lpfc_hbq_defs[hbqno]->entry_count) |
| 865 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 866 | phba->hbqs[hbqno].buffer_count; |
| 867 | if (!count) |
| 868 | return 0; |
| 869 | /* Allocate HBQ entries */ |
| 870 | for (i = 0; i < count; i++) { |
| 871 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 872 | if (!hbq_buffer) |
| 873 | break; |
| 874 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 875 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 876 | /* Check whether HBQ is still in use */ |
| 877 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 878 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 879 | goto err; |
| 880 | while (!list_empty(&hbq_buf_list)) { |
| 881 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 882 | dbuf.list); |
| 883 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 884 | (hbqno << 16)); |
| 885 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 886 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 887 | posted++; |
| 888 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 889 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 890 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 891 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 892 | return posted; |
| 893 | err: |
| 894 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 895 | while (!list_empty(&hbq_buf_list)) { |
| 896 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 897 | dbuf.list); |
| 898 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 899 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 900 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 901 | } |
| 902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 903 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 904 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 905 | * @phba: Pointer to HBA context object. |
| 906 | * @qno: HBQ number. |
| 907 | * |
| 908 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 909 | * is called with no lock held. The function returns the number of HBQ entries |
| 910 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 911 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 912 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 913 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 914 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 915 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 916 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 917 | } |
| 918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 920 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 921 | * @phba: Pointer to HBA context object. |
| 922 | * @qno: HBQ queue number. |
| 923 | * |
| 924 | * This function is called from SLI initialization code path with |
| 925 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 926 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 927 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 928 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 929 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 930 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 931 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 932 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 933 | } |
| 934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 935 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 936 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 937 | * @phba: Pointer to HBA context object. |
| 938 | * @tag: Tag of the hbq buffer. |
| 939 | * |
| 940 | * This function is called with hbalock held. This function searches |
| 941 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 942 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 943 | * it returns NULL. |
| 944 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 945 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 946 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 947 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 948 | struct lpfc_dmabuf *d_buf; |
| 949 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 950 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 951 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 952 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 953 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 954 | return NULL; |
| 955 | |
| 956 | 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] | 957 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 958 | if (hbq_buf->tag == tag) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 959 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 960 | } |
| 961 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 962 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 963 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 964 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 966 | } |
| 967 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 969 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 970 | * @phba: Pointer to HBA context object. |
| 971 | * @hbq_buffer: Pointer to HBQ buffer. |
| 972 | * |
| 973 | * This function is called with hbalock. This function gives back |
| 974 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 975 | * post the buffer, it will free the buffer. |
| 976 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 977 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 978 | 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] | 979 | { |
| 980 | uint32_t hbqno; |
| 981 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 982 | if (hbq_buffer) { |
| 983 | hbqno = hbq_buffer->tag >> 16; |
| 984 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
| 985 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 986 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 991 | * 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] | 992 | * @mbxCommand: mailbox command code. |
| 993 | * |
| 994 | * This function is called by the mailbox event handler function to verify |
| 995 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 996 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 997 | * and the mailbox event handler will take the HBA offline. |
| 998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | static int |
| 1000 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1001 | { |
| 1002 | uint8_t ret; |
| 1003 | |
| 1004 | switch (mbxCommand) { |
| 1005 | case MBX_LOAD_SM: |
| 1006 | case MBX_READ_NV: |
| 1007 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1008 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | case MBX_RUN_BIU_DIAG: |
| 1010 | case MBX_INIT_LINK: |
| 1011 | case MBX_DOWN_LINK: |
| 1012 | case MBX_CONFIG_LINK: |
| 1013 | case MBX_CONFIG_RING: |
| 1014 | case MBX_RESET_RING: |
| 1015 | case MBX_READ_CONFIG: |
| 1016 | case MBX_READ_RCONFIG: |
| 1017 | case MBX_READ_SPARM: |
| 1018 | case MBX_READ_STATUS: |
| 1019 | case MBX_READ_RPI: |
| 1020 | case MBX_READ_XRI: |
| 1021 | case MBX_READ_REV: |
| 1022 | case MBX_READ_LNK_STAT: |
| 1023 | case MBX_REG_LOGIN: |
| 1024 | case MBX_UNREG_LOGIN: |
| 1025 | case MBX_READ_LA: |
| 1026 | case MBX_CLEAR_LA: |
| 1027 | case MBX_DUMP_MEMORY: |
| 1028 | case MBX_DUMP_CONTEXT: |
| 1029 | case MBX_RUN_DIAGS: |
| 1030 | case MBX_RESTART: |
| 1031 | case MBX_UPDATE_CFG: |
| 1032 | case MBX_DOWN_LOAD: |
| 1033 | case MBX_DEL_LD_ENTRY: |
| 1034 | case MBX_RUN_PROGRAM: |
| 1035 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1036 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1038 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1040 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | case MBX_LOAD_AREA: |
| 1042 | case MBX_RUN_BIU_DIAG64: |
| 1043 | case MBX_CONFIG_PORT: |
| 1044 | case MBX_READ_SPARM64: |
| 1045 | case MBX_READ_RPI64: |
| 1046 | case MBX_REG_LOGIN64: |
| 1047 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1048 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | case MBX_SET_DEBUG: |
| 1050 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1051 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1052 | case MBX_REG_VPI: |
| 1053 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1054 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1055 | case MBX_PORT_CAPABILITIES: |
| 1056 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | ret = mbxCommand; |
| 1058 | break; |
| 1059 | default: |
| 1060 | ret = MBX_SHUTDOWN; |
| 1061 | break; |
| 1062 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1063 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1065 | |
| 1066 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1067 | * 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] | 1068 | * @phba: Pointer to HBA context object. |
| 1069 | * @pmboxq: Pointer to mailbox command. |
| 1070 | * |
| 1071 | * This is completion handler function for mailbox commands issued from |
| 1072 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1073 | * mailbox event handler function with no lock held. This function |
| 1074 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1075 | * of the mailbox. |
| 1076 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1078 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | { |
| 1080 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1081 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | |
| 1083 | /* |
| 1084 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1085 | * continued running. |
| 1086 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1087 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1088 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1090 | if (pdone_q) |
| 1091 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1092 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1096 | |
| 1097 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1098 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1099 | * @phba: Pointer to HBA context object. |
| 1100 | * @pmb: Pointer to mailbox object. |
| 1101 | * |
| 1102 | * This function is the default mailbox completion handler. It |
| 1103 | * frees the memory resources associated with the completed mailbox |
| 1104 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1105 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1106 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1107 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1109 | { |
| 1110 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1111 | uint16_t rpi; |
| 1112 | int rc; |
| 1113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1114 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1116 | if (mp) { |
| 1117 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1118 | kfree(mp); |
| 1119 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1120 | |
| 1121 | /* |
| 1122 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1123 | * is in re-discovery driver need to cleanup the RPI. |
| 1124 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1126 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1127 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1128 | |
| 1129 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1130 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1131 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1132 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1133 | if (rc != MBX_NOT_FINISHED) |
| 1134 | return; |
| 1135 | } |
| 1136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1137 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1138 | return; |
| 1139 | } |
| 1140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1141 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1142 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1143 | * @phba: Pointer to HBA context object. |
| 1144 | * |
| 1145 | * This function is called with no lock held. This function processes all |
| 1146 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1147 | * service routine processes mailbox completion interrupt and adds completed |
| 1148 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1149 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1150 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1151 | * function returns the mailbox commands to the upper layer by calling the |
| 1152 | * completion handler function of each mailbox. |
| 1153 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1155 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1157 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1159 | int rc; |
| 1160 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1161 | |
| 1162 | phba->sli.slistat.mbox_event++; |
| 1163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1164 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1165 | spin_lock_irq(&phba->hbalock); |
| 1166 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1167 | spin_unlock_irq(&phba->hbalock); |
| 1168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1170 | do { |
| 1171 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1172 | if (pmb == NULL) |
| 1173 | break; |
| 1174 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1178 | if (pmb->vport) { |
| 1179 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1180 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1181 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1182 | (uint32_t)pmbox->mbxCommand, |
| 1183 | pmbox->un.varWords[0], |
| 1184 | pmbox->un.varWords[1]); |
| 1185 | } |
| 1186 | else { |
| 1187 | lpfc_debugfs_disc_trc(phba->pport, |
| 1188 | LPFC_DISC_TRC_MBOX, |
| 1189 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1190 | (uint32_t)pmbox->mbxCommand, |
| 1191 | pmbox->un.varWords[0], |
| 1192 | pmbox->un.varWords[1]); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | /* |
| 1197 | * It is a fatal error if unknown mbox command completion. |
| 1198 | */ |
| 1199 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1200 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1202 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1203 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1204 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1205 | pmb->vport ? pmb->vport->vpi : 0, |
| 1206 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1207 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | phba->work_hs = HS_FFER3; |
| 1209 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1210 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | } |
| 1212 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | if (pmbox->mbxStatus) { |
| 1214 | phba->sli.slistat.mbox_stat_err++; |
| 1215 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1216 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1217 | lpfc_printf_log(phba, KERN_INFO, |
| 1218 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1219 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1220 | "error - RETRYing Data: x%x " |
| 1221 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1222 | pmb->vport ? pmb->vport->vpi :0, |
| 1223 | pmbox->mbxCommand, |
| 1224 | pmbox->mbxStatus, |
| 1225 | pmbox->un.varWords[0], |
| 1226 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | pmbox->mbxStatus = 0; |
| 1228 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1229 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1231 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1233 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1234 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1239 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1240 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1241 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1242 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | pmbox->mbxCommand, |
| 1244 | pmb->mbox_cmpl, |
| 1245 | *((uint32_t *) pmbox), |
| 1246 | pmbox->un.varWords[0], |
| 1247 | pmbox->un.varWords[1], |
| 1248 | pmbox->un.varWords[2], |
| 1249 | pmbox->un.varWords[3], |
| 1250 | pmbox->un.varWords[4], |
| 1251 | pmbox->un.varWords[5], |
| 1252 | pmbox->un.varWords[6], |
| 1253 | pmbox->un.varWords[7]); |
| 1254 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1255 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1257 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1258 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1261 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1262 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1263 | * @phba: Pointer to HBA context object. |
| 1264 | * @pring: Pointer to driver SLI ring object. |
| 1265 | * @tag: buffer tag. |
| 1266 | * |
| 1267 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1268 | * is set in the tag the buffer is posted for a particular exchange, |
| 1269 | * the function will return the buffer without replacing the buffer. |
| 1270 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1271 | * returns the buffer and also posts another buffer to the firmware. |
| 1272 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1273 | static struct lpfc_dmabuf * |
| 1274 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1275 | struct lpfc_sli_ring *pring, |
| 1276 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1277 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1278 | struct hbq_dmabuf *hbq_entry; |
| 1279 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1280 | if (tag & QUE_BUFTAG_BIT) |
| 1281 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1282 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 1283 | if (!hbq_entry) |
| 1284 | return NULL; |
| 1285 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1286 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1288 | |
| 1289 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1290 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1291 | * @phba: Pointer to HBA context object. |
| 1292 | * @pring: Pointer to driver SLI ring object. |
| 1293 | * @saveq: Pointer to the unsolicited iocb. |
| 1294 | * |
| 1295 | * This function is called with no lock held by the ring event handler |
| 1296 | * when there is an unsolicited iocb posted to the response ring by the |
| 1297 | * firmware. This function gets the buffer associated with the iocbs |
| 1298 | * and calls the event handler for the ring. This function handles both |
| 1299 | * qring buffers and hbq buffers. |
| 1300 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1301 | * upper layer functions will free the iocb objects. |
| 1302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | static int |
| 1304 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1305 | struct lpfc_iocbq *saveq) |
| 1306 | { |
| 1307 | IOCB_t * irsp; |
| 1308 | WORD5 * w5p; |
| 1309 | uint32_t Rctl, Type; |
| 1310 | uint32_t match, i; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1311 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1312 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | |
| 1314 | match = 0; |
| 1315 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1316 | |
| 1317 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1318 | if (pring->lpfc_sli_rcv_async_status) |
| 1319 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1320 | else |
| 1321 | lpfc_printf_log(phba, |
| 1322 | KERN_WARNING, |
| 1323 | LOG_SLI, |
| 1324 | "0316 Ring %d handler: unexpected " |
| 1325 | "ASYNC_STATUS iocb received evt_code " |
| 1326 | "0x%x\n", |
| 1327 | pring->ringno, |
| 1328 | irsp->un.asyncstat.evt_code); |
| 1329 | return 1; |
| 1330 | } |
| 1331 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1332 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1333 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1334 | if (irsp->ulpBdeCount > 0) { |
| 1335 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1336 | irsp->un.ulpWord[3]); |
| 1337 | lpfc_in_buf_free(phba, dmzbuf); |
| 1338 | } |
| 1339 | |
| 1340 | if (irsp->ulpBdeCount > 1) { |
| 1341 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1342 | irsp->unsli3.sli3Words[3]); |
| 1343 | lpfc_in_buf_free(phba, dmzbuf); |
| 1344 | } |
| 1345 | |
| 1346 | if (irsp->ulpBdeCount > 2) { |
| 1347 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1348 | irsp->unsli3.sli3Words[7]); |
| 1349 | lpfc_in_buf_free(phba, dmzbuf); |
| 1350 | } |
| 1351 | |
| 1352 | return 1; |
| 1353 | } |
| 1354 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1355 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1356 | if (irsp->ulpBdeCount != 0) { |
| 1357 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1358 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1359 | if (!saveq->context2) |
| 1360 | lpfc_printf_log(phba, |
| 1361 | KERN_ERR, |
| 1362 | LOG_SLI, |
| 1363 | "0341 Ring %d Cannot find buffer for " |
| 1364 | "an unsolicited iocb. tag 0x%x\n", |
| 1365 | pring->ringno, |
| 1366 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1367 | } |
| 1368 | if (irsp->ulpBdeCount == 2) { |
| 1369 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1370 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1371 | if (!saveq->context3) |
| 1372 | lpfc_printf_log(phba, |
| 1373 | KERN_ERR, |
| 1374 | LOG_SLI, |
| 1375 | "0342 Ring %d Cannot find buffer for an" |
| 1376 | " unsolicited iocb. tag 0x%x\n", |
| 1377 | pring->ringno, |
| 1378 | irsp->unsli3.sli3Words[7]); |
| 1379 | } |
| 1380 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1381 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1382 | if (irsp->ulpBdeCount != 0) { |
| 1383 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1384 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1385 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1386 | lpfc_printf_log(phba, |
| 1387 | KERN_ERR, |
| 1388 | LOG_SLI, |
| 1389 | "0343 Ring %d Cannot find " |
| 1390 | "buffer for an unsolicited iocb" |
| 1391 | ". tag 0x%x\n", pring->ringno, |
| 1392 | irsp->un.ulpWord[3]); |
| 1393 | } |
| 1394 | if (irsp->ulpBdeCount == 2) { |
| 1395 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1396 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1397 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1398 | lpfc_printf_log(phba, |
| 1399 | KERN_ERR, |
| 1400 | LOG_SLI, |
| 1401 | "0344 Ring %d Cannot find " |
| 1402 | "buffer for an unsolicited " |
| 1403 | "iocb. tag 0x%x\n", |
| 1404 | pring->ringno, |
| 1405 | irsp->unsli3.sli3Words[7]); |
| 1406 | } |
| 1407 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1408 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1409 | if (irsp->ulpBdeCount != 0 && |
| 1410 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1411 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1412 | int found = 0; |
| 1413 | |
| 1414 | /* search continue save q for same XRI */ |
| 1415 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1416 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1417 | list_add_tail(&saveq->list, &iocbq->list); |
| 1418 | found = 1; |
| 1419 | break; |
| 1420 | } |
| 1421 | } |
| 1422 | if (!found) |
| 1423 | list_add_tail(&saveq->clist, |
| 1424 | &pring->iocb_continue_saveq); |
| 1425 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1426 | list_del_init(&iocbq->clist); |
| 1427 | saveq = iocbq; |
| 1428 | irsp = &(saveq->iocb); |
| 1429 | } else |
| 1430 | return 0; |
| 1431 | } |
| 1432 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1433 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1434 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1435 | Rctl = FC_ELS_REQ; |
| 1436 | Type = FC_ELS_DATA; |
| 1437 | } else { |
| 1438 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1439 | Rctl = w5p->hcsw.Rctl; |
| 1440 | Type = w5p->hcsw.Type; |
| 1441 | |
| 1442 | /* Firmware Workaround */ |
| 1443 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1444 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1445 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1446 | Rctl = FC_ELS_REQ; |
| 1447 | Type = FC_ELS_DATA; |
| 1448 | w5p->hcsw.Rctl = Rctl; |
| 1449 | w5p->hcsw.Type = Type; |
| 1450 | } |
| 1451 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1452 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | /* unSolicited Responses */ |
| 1454 | if (pring->prt[0].profile) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1455 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1456 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1457 | saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | match = 1; |
| 1459 | } else { |
| 1460 | /* We must search, based on rctl / type |
| 1461 | for the right routine */ |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1462 | for (i = 0; i < pring->num_mask; i++) { |
| 1463 | if ((pring->prt[i].rctl == Rctl) |
| 1464 | && (pring->prt[i].type == Type)) { |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1465 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1466 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1467 | (phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | match = 1; |
| 1469 | break; |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | if (match == 0) { |
| 1474 | /* Unexpected Rctl / Type received */ |
| 1475 | /* Ring <ringno> handler: unexpected |
| 1476 | Rctl <Rctl> Type <Type> received */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1477 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1478 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1480 | pring->ringno, Rctl, Type); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1482 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1483 | } |
| 1484 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1486 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1487 | * @phba: Pointer to HBA context object. |
| 1488 | * @pring: Pointer to driver SLI ring object. |
| 1489 | * @prspiocb: Pointer to response iocb object. |
| 1490 | * |
| 1491 | * This function looks up the iocb_lookup table to get the command iocb |
| 1492 | * corresponding to the given response iocb using the iotag of the |
| 1493 | * response iocb. This function is called with the hbalock held. |
| 1494 | * This function returns the command iocb object if it finds the command |
| 1495 | * iocb else returns NULL. |
| 1496 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1499 | struct lpfc_sli_ring *pring, |
| 1500 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1503 | uint16_t iotag; |
| 1504 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1505 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1507 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1508 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1509 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1510 | pring->txcmplq_cnt--; |
| 1511 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1514 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1515 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1516 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1517 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1518 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1519 | return NULL; |
| 1520 | } |
| 1521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1522 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1523 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1524 | * @phba: Pointer to HBA context object. |
| 1525 | * @pring: Pointer to driver SLI ring object. |
| 1526 | * @saveq: Pointer to the response iocb to be processed. |
| 1527 | * |
| 1528 | * This function is called by the ring event handler for non-fcp |
| 1529 | * rings when there is a new response iocb in the response ring. |
| 1530 | * The caller is not required to hold any locks. This function |
| 1531 | * gets the command iocb associated with the response iocb and |
| 1532 | * calls the completion handler for the command iocb. If there |
| 1533 | * is no completion handler, the function will free the resources |
| 1534 | * associated with command iocb. If the response iocb is for |
| 1535 | * an already aborted command iocb, the status of the completion |
| 1536 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1537 | * This function always returns 1. |
| 1538 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1539 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1540 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | struct lpfc_iocbq *saveq) |
| 1542 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1543 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | int rc = 1; |
| 1545 | unsigned long iflag; |
| 1546 | |
| 1547 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1548 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1549 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1551 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | if (cmdiocbp) { |
| 1553 | if (cmdiocbp->iocb_cmpl) { |
| 1554 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1555 | * If an ELS command failed send an event to mgmt |
| 1556 | * application. |
| 1557 | */ |
| 1558 | if (saveq->iocb.ulpStatus && |
| 1559 | (pring->ringno == LPFC_ELS_RING) && |
| 1560 | (cmdiocbp->iocb.ulpCommand == |
| 1561 | CMD_ELS_REQUEST64_CR)) |
| 1562 | lpfc_send_els_failure_event(phba, |
| 1563 | cmdiocbp, saveq); |
| 1564 | |
| 1565 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | * Post all ELS completions to the worker thread. |
| 1567 | * All other are passed to the completion callback. |
| 1568 | */ |
| 1569 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1570 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1571 | cmdiocbp->iocb_flag &= |
| 1572 | ~LPFC_DRIVER_ABORTED; |
| 1573 | saveq->iocb.ulpStatus = |
| 1574 | IOSTAT_LOCAL_REJECT; |
| 1575 | saveq->iocb.un.ulpWord[4] = |
| 1576 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1577 | |
| 1578 | /* Firmware could still be in progress |
| 1579 | * of DMAing payload, so don't free data |
| 1580 | * buffer till after a hbeat. |
| 1581 | */ |
| 1582 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1583 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1585 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1586 | } else |
| 1587 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | } else { |
| 1589 | /* |
| 1590 | * Unknown initiating command based on the response iotag. |
| 1591 | * This could be the case on the ELS ring because of |
| 1592 | * lpfc_els_abort(). |
| 1593 | */ |
| 1594 | if (pring->ringno != LPFC_ELS_RING) { |
| 1595 | /* |
| 1596 | * Ring <ringno> handler: unexpected completion IoTag |
| 1597 | * <IoTag> |
| 1598 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1599 | lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI, |
| 1600 | "0322 Ring %d handler: " |
| 1601 | "unexpected completion IoTag x%x " |
| 1602 | "Data: x%x x%x x%x x%x\n", |
| 1603 | pring->ringno, |
| 1604 | saveq->iocb.ulpIoTag, |
| 1605 | saveq->iocb.ulpStatus, |
| 1606 | saveq->iocb.un.ulpWord[4], |
| 1607 | saveq->iocb.ulpCommand, |
| 1608 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | } |
| 1610 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1611 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | return rc; |
| 1613 | } |
| 1614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1616 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1617 | * @phba: Pointer to HBA context object. |
| 1618 | * @pring: Pointer to driver SLI ring object. |
| 1619 | * |
| 1620 | * This function is called from the iocb ring event handlers when |
| 1621 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1622 | * an error attention condition to the worker thread and the worker |
| 1623 | * thread will transition the HBA to offline state. |
| 1624 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | static void |
| 1626 | 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] | 1627 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1628 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1629 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1630 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1631 | * rsp ring <portRspMax> |
| 1632 | */ |
| 1633 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1634 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1635 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1636 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1637 | pring->numRiocb); |
| 1638 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1639 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1640 | |
| 1641 | /* |
| 1642 | * All error attention handlers are posted to |
| 1643 | * worker thread |
| 1644 | */ |
| 1645 | phba->work_ha |= HA_ERATT; |
| 1646 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1647 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1648 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1649 | |
| 1650 | return; |
| 1651 | } |
| 1652 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1653 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1654 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1655 | * @ptr: Pointer to address of HBA context object. |
| 1656 | * |
| 1657 | * This function is invoked by the Error Attention polling timer when the |
| 1658 | * timer times out. It will check the SLI Error Attention register for |
| 1659 | * possible attention events. If so, it will post an Error Attention event |
| 1660 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1661 | * Error Attention polling timer for the next poll. |
| 1662 | **/ |
| 1663 | void lpfc_poll_eratt(unsigned long ptr) |
| 1664 | { |
| 1665 | struct lpfc_hba *phba; |
| 1666 | uint32_t eratt = 0; |
| 1667 | |
| 1668 | phba = (struct lpfc_hba *)ptr; |
| 1669 | |
| 1670 | /* Check chip HA register for error event */ |
| 1671 | eratt = lpfc_sli_check_eratt(phba); |
| 1672 | |
| 1673 | if (eratt) |
| 1674 | /* Tell the worker thread there is work to do */ |
| 1675 | lpfc_worker_wake_up(phba); |
| 1676 | else |
| 1677 | /* Restart the timer for next eratt poll */ |
| 1678 | mod_timer(&phba->eratt_poll, jiffies + |
| 1679 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1684 | * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1685 | * @phba: Pointer to HBA context object. |
| 1686 | * |
| 1687 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1688 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1689 | * is enabled. |
| 1690 | * |
| 1691 | * The caller does not hold any lock. |
| 1692 | * The function processes each response iocb in the response ring until it |
| 1693 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1694 | * LE bit set. The function will call the completion handler of the command iocb |
| 1695 | * if the response iocb indicates a completion for a command iocb or it is |
| 1696 | * an abort completion. |
| 1697 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1699 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | struct lpfc_sli *psli = &phba->sli; |
| 1701 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1702 | IOCB_t *irsp = NULL; |
| 1703 | IOCB_t *entry = NULL; |
| 1704 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1705 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1706 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1707 | uint32_t status; |
| 1708 | uint32_t portRspPut, portRspMax; |
| 1709 | int type; |
| 1710 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1711 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1712 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1713 | |
| 1714 | pring->stats.iocb_event++; |
| 1715 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1716 | /* |
| 1717 | * The next available response entry should never exceed the maximum |
| 1718 | * entries. If it does, treat it as an adapter hardware error. |
| 1719 | */ |
| 1720 | portRspMax = pring->numRiocb; |
| 1721 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1722 | if (unlikely(portRspPut >= portRspMax)) { |
| 1723 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1724 | return; |
| 1725 | } |
| 1726 | |
| 1727 | rmb(); |
| 1728 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1729 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1730 | if (++pring->rspidx >= portRspMax) |
| 1731 | pring->rspidx = 0; |
| 1732 | |
| 1733 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1734 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1735 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1736 | irsp = &rspiocbq.iocb; |
| 1737 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1738 | pring->stats.iocb_rsp++; |
| 1739 | rsp_cmpl++; |
| 1740 | |
| 1741 | if (unlikely(irsp->ulpStatus)) { |
| 1742 | /* Rsp ring <ringno> error: IOCB */ |
| 1743 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1744 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1745 | "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] | 1746 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1747 | irsp->un.ulpWord[0], |
| 1748 | irsp->un.ulpWord[1], |
| 1749 | irsp->un.ulpWord[2], |
| 1750 | irsp->un.ulpWord[3], |
| 1751 | irsp->un.ulpWord[4], |
| 1752 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1753 | *(uint32_t *)&irsp->un1, |
| 1754 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | switch (type) { |
| 1758 | case LPFC_ABORT_IOCB: |
| 1759 | case LPFC_SOL_IOCB: |
| 1760 | /* |
| 1761 | * Idle exchange closed via ABTS from port. No iocb |
| 1762 | * resources need to be recovered. |
| 1763 | */ |
| 1764 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1765 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1766 | "0314 IOCB cmd 0x%x " |
| 1767 | "processed. Skipping " |
| 1768 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1769 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1770 | break; |
| 1771 | } |
| 1772 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1773 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1774 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1775 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1776 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1777 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1778 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1779 | &rspiocbq); |
| 1780 | } |
| 1781 | break; |
| 1782 | default: |
| 1783 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1784 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1785 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1786 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1787 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1788 | dev_warn(&((phba->pcidev)->dev), |
| 1789 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1790 | phba->brd_no, adaptermsg); |
| 1791 | } else { |
| 1792 | /* Unknown IOCB command */ |
| 1793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1794 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1795 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1796 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1797 | irsp->ulpStatus, |
| 1798 | irsp->ulpIoTag, |
| 1799 | irsp->ulpContext); |
| 1800 | } |
| 1801 | break; |
| 1802 | } |
| 1803 | |
| 1804 | /* |
| 1805 | * The response IOCB has been processed. Update the ring |
| 1806 | * pointer in SLIM. If the port response put pointer has not |
| 1807 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 1808 | * response put pointer. |
| 1809 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1810 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1811 | |
| 1812 | if (pring->rspidx == portRspPut) |
| 1813 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1814 | } |
| 1815 | |
| 1816 | ha_copy = readl(phba->HAregaddr); |
| 1817 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 1818 | |
| 1819 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1820 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1821 | pring->stats.iocb_rsp_full++; |
| 1822 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 1823 | writel(status, phba->CAregaddr); |
| 1824 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1825 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1826 | } |
| 1827 | if ((ha_copy & HA_R0CE_RSP) && |
| 1828 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1830 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 1831 | pring->stats.iocb_cmd_empty++; |
| 1832 | |
| 1833 | /* Force update of the local copy of cmdGetInx */ |
| 1834 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1835 | lpfc_sli_resume_iocb(phba, pring); |
| 1836 | |
| 1837 | if ((pring->lpfc_sli_cmd_available)) |
| 1838 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 1839 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | return; |
| 1844 | } |
| 1845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1846 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 1847 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1848 | * @phba: Pointer to HBA context object. |
| 1849 | * @pring: Pointer to driver SLI ring object. |
| 1850 | * @mask: Host attention register mask for this ring. |
| 1851 | * |
| 1852 | * This function is called from the interrupt context when there is a ring |
| 1853 | * event for the fcp ring. The caller does not hold any lock. |
| 1854 | * The function processes each response iocb in the response ring until it |
| 1855 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1856 | * LE bit set. The function will call the completion handler of the command iocb |
| 1857 | * if the response iocb indicates a completion for a command iocb or it is |
| 1858 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 1859 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1861 | * to check it explicitly. This function always returns 1. |
| 1862 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 1865 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1867 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1869 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1871 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | uint32_t status; |
| 1873 | uint32_t portRspPut, portRspMax; |
| 1874 | int rc = 1; |
| 1875 | lpfc_iocb_type type; |
| 1876 | unsigned long iflag; |
| 1877 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | pring->stats.iocb_event++; |
| 1881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | /* |
| 1883 | * The next available response entry should never exceed the maximum |
| 1884 | * entries. If it does, treat it as an adapter hardware error. |
| 1885 | */ |
| 1886 | portRspMax = pring->numRiocb; |
| 1887 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1888 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1889 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | return 1; |
| 1892 | } |
| 1893 | |
| 1894 | rmb(); |
| 1895 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1896 | /* |
| 1897 | * Fetch an entry off the ring and copy it into a local data |
| 1898 | * structure. The copy involves a byte-swap since the |
| 1899 | * network byte order and pci byte orders are different. |
| 1900 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1901 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1902 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1903 | |
| 1904 | if (++pring->rspidx >= portRspMax) |
| 1905 | pring->rspidx = 0; |
| 1906 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1907 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1908 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1909 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1910 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 1911 | irsp = &rspiocbq.iocb; |
| 1912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1914 | pring->stats.iocb_rsp++; |
| 1915 | rsp_cmpl++; |
| 1916 | |
| 1917 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1918 | /* |
| 1919 | * If resource errors reported from HBA, reduce |
| 1920 | * queuedepths of the SCSI device. |
| 1921 | */ |
| 1922 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1923 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 1924 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 1925 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1926 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1927 | } |
| 1928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | /* Rsp ring <ringno> error: IOCB */ |
| 1930 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1931 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | "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] | 1933 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1934 | irsp->un.ulpWord[0], |
| 1935 | irsp->un.ulpWord[1], |
| 1936 | irsp->un.ulpWord[2], |
| 1937 | irsp->un.ulpWord[3], |
| 1938 | irsp->un.ulpWord[4], |
| 1939 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1940 | *(uint32_t *)&irsp->un1, |
| 1941 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | switch (type) { |
| 1945 | case LPFC_ABORT_IOCB: |
| 1946 | case LPFC_SOL_IOCB: |
| 1947 | /* |
| 1948 | * Idle exchange closed via ABTS from port. No iocb |
| 1949 | * resources need to be recovered. |
| 1950 | */ |
| 1951 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1952 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1953 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1954 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1955 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1956 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | break; |
| 1958 | } |
| 1959 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1960 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1961 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1963 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 1964 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1965 | &rspiocbq); |
| 1966 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1967 | spin_unlock_irqrestore(&phba->hbalock, |
| 1968 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1969 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1970 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 1972 | iflag); |
| 1973 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | } |
| 1975 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1976 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1977 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1978 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1979 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1980 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | default: |
| 1982 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 1983 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 1984 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 1985 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 1986 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1987 | dev_warn(&((phba->pcidev)->dev), |
| 1988 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | phba->brd_no, adaptermsg); |
| 1990 | } else { |
| 1991 | /* Unknown IOCB command */ |
| 1992 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1993 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1994 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1995 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1996 | irsp->ulpStatus, |
| 1997 | irsp->ulpIoTag, |
| 1998 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | } |
| 2000 | break; |
| 2001 | } |
| 2002 | |
| 2003 | /* |
| 2004 | * The response IOCB has been processed. Update the ring |
| 2005 | * pointer in SLIM. If the port response put pointer has not |
| 2006 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2007 | * response put pointer. |
| 2008 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2009 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | |
| 2011 | if (pring->rspidx == portRspPut) |
| 2012 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2013 | } |
| 2014 | |
| 2015 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2016 | pring->stats.iocb_rsp_full++; |
| 2017 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2018 | writel(status, phba->CAregaddr); |
| 2019 | readl(phba->CAregaddr); |
| 2020 | } |
| 2021 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2022 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2023 | pring->stats.iocb_cmd_empty++; |
| 2024 | |
| 2025 | /* Force update of the local copy of cmdGetInx */ |
| 2026 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2027 | lpfc_sli_resume_iocb(phba, pring); |
| 2028 | |
| 2029 | if ((pring->lpfc_sli_cmd_available)) |
| 2030 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2031 | |
| 2032 | } |
| 2033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | return rc; |
| 2036 | } |
| 2037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2038 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2039 | * lpfc_sli_handle_slow_ring_event - Handle ring events for non-FCP rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2040 | * @phba: Pointer to HBA context object. |
| 2041 | * @pring: Pointer to driver SLI ring object. |
| 2042 | * @mask: Host attention register mask for this ring. |
| 2043 | * |
| 2044 | * This function is called from the worker thread when there is a ring |
| 2045 | * event for non-fcp rings. The caller does not hold any lock . |
| 2046 | * The function processes each response iocb in the response ring until it |
| 2047 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2048 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the |
| 2049 | * response iocb indicates a completion of a command iocb. The function |
| 2050 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited |
| 2051 | * iocb. The function frees the resources or calls the completion handler if |
| 2052 | * this iocb is an abort completion. The function returns 0 when the allocated |
| 2053 | * iocbs are not freed, otherwise returns 1. |
| 2054 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2056 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2057 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2059 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | IOCB_t *entry; |
| 2061 | IOCB_t *irsp = NULL; |
| 2062 | struct lpfc_iocbq *rspiocbp = NULL; |
| 2063 | struct lpfc_iocbq *next_iocb; |
| 2064 | struct lpfc_iocbq *cmdiocbp; |
| 2065 | struct lpfc_iocbq *saveq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | uint8_t iocb_cmd_type; |
| 2067 | lpfc_iocb_type type; |
| 2068 | uint32_t status, free_saveq; |
| 2069 | uint32_t portRspPut, portRspMax; |
| 2070 | int rc = 1; |
| 2071 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2073 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | pring->stats.iocb_event++; |
| 2076 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | /* |
| 2078 | * The next available response entry should never exceed the maximum |
| 2079 | * entries. If it does, treat it as an adapter hardware error. |
| 2080 | */ |
| 2081 | portRspMax = pring->numRiocb; |
| 2082 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2083 | if (portRspPut >= portRspMax) { |
| 2084 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2085 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | * rsp ring <portRspMax> |
| 2087 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2088 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2089 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2090 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2091 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2093 | phba->link_state = LPFC_HBA_ERROR; |
| 2094 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
| 2096 | phba->work_hs = HS_FFER3; |
| 2097 | lpfc_handle_eratt(phba); |
| 2098 | |
| 2099 | return 1; |
| 2100 | } |
| 2101 | |
| 2102 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | while (pring->rspidx != portRspPut) { |
| 2104 | /* |
| 2105 | * Build a completion list and call the appropriate handler. |
| 2106 | * The process is to get the next available response iocb, get |
| 2107 | * a free iocb from the list, copy the response data into the |
| 2108 | * free iocb, insert to the continuation list, and update the |
| 2109 | * next response index to slim. This process makes response |
| 2110 | * iocb's in the ring available to DMA as fast as possible but |
| 2111 | * pays a penalty for a copy operation. Since the iocb is |
| 2112 | * only 32 bytes, this penalty is considered small relative to |
| 2113 | * the PCI reads for register values and a slim write. When |
| 2114 | * the ulpLe field is set, the entire Command has been |
| 2115 | * received. |
| 2116 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2117 | entry = lpfc_resp_iocb(phba, pring); |
| 2118 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2119 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2120 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | if (rspiocbp == NULL) { |
| 2122 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2123 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | break; |
| 2125 | } |
| 2126 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2127 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2128 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | irsp = &rspiocbp->iocb; |
| 2130 | |
| 2131 | if (++pring->rspidx >= portRspMax) |
| 2132 | pring->rspidx = 0; |
| 2133 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2134 | if (pring->ringno == LPFC_ELS_RING) { |
| 2135 | lpfc_debugfs_slow_ring_trc(phba, |
| 2136 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2137 | *(((uint32_t *) irsp) + 4), |
| 2138 | *(((uint32_t *) irsp) + 6), |
| 2139 | *(((uint32_t *) irsp) + 7)); |
| 2140 | } |
| 2141 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2142 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2144 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | |
| 2146 | pring->iocb_continueq_cnt++; |
| 2147 | if (irsp->ulpLe) { |
| 2148 | /* |
| 2149 | * By default, the driver expects to free all resources |
| 2150 | * associated with this iocb completion. |
| 2151 | */ |
| 2152 | free_saveq = 1; |
| 2153 | saveq = list_get_first(&pring->iocb_continueq, |
| 2154 | struct lpfc_iocbq, list); |
| 2155 | irsp = &(saveq->iocb); |
| 2156 | list_del_init(&pring->iocb_continueq); |
| 2157 | pring->iocb_continueq_cnt = 0; |
| 2158 | |
| 2159 | pring->stats.iocb_rsp++; |
| 2160 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | /* |
| 2162 | * If resource errors reported from HBA, reduce |
| 2163 | * queuedepths of the SCSI device. |
| 2164 | */ |
| 2165 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2166 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2167 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2168 | lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2169 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2170 | } |
| 2171 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2172 | if (irsp->ulpStatus) { |
| 2173 | /* Rsp ring <ringno> error: IOCB */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2174 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2175 | "0328 Rsp Ring %d error: " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2176 | "IOCB Data: " |
| 2177 | "x%x x%x x%x x%x " |
| 2178 | "x%x x%x x%x x%x " |
| 2179 | "x%x x%x x%x x%x " |
| 2180 | "x%x x%x x%x x%x\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2181 | pring->ringno, |
| 2182 | irsp->un.ulpWord[0], |
| 2183 | irsp->un.ulpWord[1], |
| 2184 | irsp->un.ulpWord[2], |
| 2185 | irsp->un.ulpWord[3], |
| 2186 | irsp->un.ulpWord[4], |
| 2187 | irsp->un.ulpWord[5], |
| 2188 | *(((uint32_t *) irsp) + 6), |
| 2189 | *(((uint32_t *) irsp) + 7), |
| 2190 | *(((uint32_t *) irsp) + 8), |
| 2191 | *(((uint32_t *) irsp) + 9), |
| 2192 | *(((uint32_t *) irsp) + 10), |
| 2193 | *(((uint32_t *) irsp) + 11), |
| 2194 | *(((uint32_t *) irsp) + 12), |
| 2195 | *(((uint32_t *) irsp) + 13), |
| 2196 | *(((uint32_t *) irsp) + 14), |
| 2197 | *(((uint32_t *) irsp) + 15)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | /* |
| 2201 | * Fetch the IOCB command type and call the correct |
| 2202 | * completion routine. Solicited and Unsolicited |
| 2203 | * IOCBs on the ELS ring get freed back to the |
| 2204 | * lpfc_iocb_list by the discovery kernel thread. |
| 2205 | */ |
| 2206 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2207 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2208 | if (type == LPFC_SOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2209 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2211 | saveq); |
| 2212 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | } else if (type == LPFC_UNSOL_IOCB) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2214 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2216 | saveq); |
| 2217 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2218 | if (!rc) |
| 2219 | free_saveq = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | } else if (type == LPFC_ABORT_IOCB) { |
| 2221 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && |
| 2222 | ((cmdiocbp = |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2223 | lpfc_sli_iocbq_lookup(phba, pring, |
| 2224 | saveq)))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2225 | /* Call the specified completion |
| 2226 | routine */ |
| 2227 | if (cmdiocbp->iocb_cmpl) { |
| 2228 | spin_unlock_irqrestore( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2229 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | iflag); |
| 2231 | (cmdiocbp->iocb_cmpl) (phba, |
| 2232 | cmdiocbp, saveq); |
| 2233 | spin_lock_irqsave( |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | &phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2236 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2237 | __lpfc_sli_release_iocbq(phba, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2238 | cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | } |
| 2240 | } else if (type == LPFC_UNKNOWN_IOCB) { |
| 2241 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2242 | |
| 2243 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2244 | |
| 2245 | memset(adaptermsg, 0, |
| 2246 | LPFC_MAX_ADPTMSG); |
| 2247 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2248 | MAX_MSG_DATA); |
| 2249 | dev_warn(&((phba->pcidev)->dev), |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2250 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | phba->brd_no, adaptermsg); |
| 2252 | } else { |
| 2253 | /* Unknown IOCB command */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2254 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2255 | "0335 Unknown IOCB " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2256 | "command Data: x%x " |
| 2257 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2258 | irsp->ulpCommand, |
| 2259 | irsp->ulpStatus, |
| 2260 | irsp->ulpIoTag, |
| 2261 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | if (free_saveq) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2266 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2267 | &saveq->list, list) { |
| 2268 | list_del(&rspiocbp->list); |
| 2269 | __lpfc_sli_release_iocbq(phba, |
| 2270 | rspiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2272 | __lpfc_sli_release_iocbq(phba, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2274 | rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | /* |
| 2278 | * If the port response put pointer has not been updated, sync |
| 2279 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2280 | * response put pointer. |
| 2281 | */ |
| 2282 | if (pring->rspidx == portRspPut) { |
| 2283 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2284 | } |
| 2285 | } /* while (pring->rspidx != portRspPut) */ |
| 2286 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2287 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | /* At least one response entry has been freed */ |
| 2289 | pring->stats.iocb_rsp_full++; |
| 2290 | /* SET RxRE_RSP in Chip Att register */ |
| 2291 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2292 | writel(status, phba->CAregaddr); |
| 2293 | readl(phba->CAregaddr); /* flush */ |
| 2294 | } |
| 2295 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2296 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2297 | pring->stats.iocb_cmd_empty++; |
| 2298 | |
| 2299 | /* Force update of the local copy of cmdGetInx */ |
| 2300 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2301 | lpfc_sli_resume_iocb(phba, pring); |
| 2302 | |
| 2303 | if ((pring->lpfc_sli_cmd_available)) |
| 2304 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2305 | |
| 2306 | } |
| 2307 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2308 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | return rc; |
| 2310 | } |
| 2311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2313 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2314 | * @phba: Pointer to HBA context object. |
| 2315 | * @pring: Pointer to driver SLI ring object. |
| 2316 | * |
| 2317 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2318 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2319 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2320 | * the return of this function. The caller is not required to hold any locks. |
| 2321 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2322 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2323 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2324 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2325 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2327 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2329 | if (pring->ringno == LPFC_ELS_RING) { |
| 2330 | lpfc_fabric_abort_hba(phba); |
| 2331 | } |
| 2332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | /* Error everything on txq and txcmplq |
| 2334 | * First do the txq. |
| 2335 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2336 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2337 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | |
| 2340 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2341 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2342 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2345 | |
| 2346 | while (!list_empty(&completions)) { |
| 2347 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | cmd = &iocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2349 | list_del_init(&iocb->list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2351 | if (!iocb->iocb_cmpl) |
| 2352 | lpfc_sli_release_iocbq(phba, iocb); |
| 2353 | else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2355 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | } |
| 2360 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2361 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2362 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2363 | * @phba: Pointer to HBA context object. |
| 2364 | * |
| 2365 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2366 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2367 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2368 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2369 | * slot has been permanently disabled. |
| 2370 | **/ |
| 2371 | void |
| 2372 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2373 | { |
| 2374 | LIST_HEAD(txq); |
| 2375 | LIST_HEAD(txcmplq); |
| 2376 | struct lpfc_iocbq *iocb; |
| 2377 | IOCB_t *cmd = NULL; |
| 2378 | struct lpfc_sli *psli = &phba->sli; |
| 2379 | struct lpfc_sli_ring *pring; |
| 2380 | |
| 2381 | /* Currently, only one fcp ring */ |
| 2382 | pring = &psli->ring[psli->fcp_ring]; |
| 2383 | |
| 2384 | spin_lock_irq(&phba->hbalock); |
| 2385 | /* Retrieve everything on txq */ |
| 2386 | list_splice_init(&pring->txq, &txq); |
| 2387 | pring->txq_cnt = 0; |
| 2388 | |
| 2389 | /* Retrieve everything on the txcmplq */ |
| 2390 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2391 | pring->txcmplq_cnt = 0; |
| 2392 | spin_unlock_irq(&phba->hbalock); |
| 2393 | |
| 2394 | /* Flush the txq */ |
| 2395 | while (!list_empty(&txq)) { |
| 2396 | iocb = list_get_first(&txq, struct lpfc_iocbq, list); |
| 2397 | cmd = &iocb->iocb; |
| 2398 | list_del_init(&iocb->list); |
| 2399 | |
| 2400 | if (!iocb->iocb_cmpl) |
| 2401 | lpfc_sli_release_iocbq(phba, iocb); |
| 2402 | else { |
| 2403 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2404 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2405 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | /* Flush the txcmpq */ |
| 2410 | while (!list_empty(&txcmplq)) { |
| 2411 | iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list); |
| 2412 | cmd = &iocb->iocb; |
| 2413 | list_del_init(&iocb->list); |
| 2414 | |
| 2415 | if (!iocb->iocb_cmpl) |
| 2416 | lpfc_sli_release_iocbq(phba, iocb); |
| 2417 | else { |
| 2418 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 2419 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 2420 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 2421 | } |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2426 | * lpfc_sli_brdready - Check for host status bits |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2427 | * @phba: Pointer to HBA context object. |
| 2428 | * @mask: Bit mask to be checked. |
| 2429 | * |
| 2430 | * This function reads the host status register and compares |
| 2431 | * with the provided bit mask to check if HBA completed |
| 2432 | * the restart. This function will wait in a loop for the |
| 2433 | * HBA to complete restart. If the HBA does not restart within |
| 2434 | * 15 iterations, the function will reset the HBA again. The |
| 2435 | * function returns 1 when HBA fail to restart otherwise returns |
| 2436 | * zero. |
| 2437 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2438 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2439 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2441 | uint32_t status; |
| 2442 | int i = 0; |
| 2443 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2445 | /* Read the HBA Host Status Register */ |
| 2446 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2448 | /* |
| 2449 | * Check status register every 100ms for 5 retries, then every |
| 2450 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2451 | * every 2.5 sec for 4. |
| 2452 | * Break our of the loop if errors occurred during init. |
| 2453 | */ |
| 2454 | while (((status & mask) != mask) && |
| 2455 | !(status & HS_FFERM) && |
| 2456 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2458 | if (i <= 5) |
| 2459 | msleep(10); |
| 2460 | else if (i <= 10) |
| 2461 | msleep(500); |
| 2462 | else |
| 2463 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2465 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2466 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2467 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2468 | lpfc_sli_brdrestart(phba); |
| 2469 | } |
| 2470 | /* Read the HBA Host Status Register */ |
| 2471 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2474 | /* Check to see if any errors occurred during init */ |
| 2475 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2476 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2477 | retval = 1; |
| 2478 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2480 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | } |
| 2482 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2483 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2484 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2486 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2487 | * @phba: Pointer to HBA context object. |
| 2488 | * |
| 2489 | * This function is called before resetting an HBA. This |
| 2490 | * function requests HBA to quiesce DMAs before a reset. |
| 2491 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2492 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2493 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2494 | uint32_t __iomem *resp_buf; |
| 2495 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2496 | volatile uint32_t mbox; |
| 2497 | uint32_t hc_copy; |
| 2498 | int i; |
| 2499 | uint8_t hdrtype; |
| 2500 | |
| 2501 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2502 | if (hdrtype != 0x80 || |
| 2503 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2504 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2505 | return; |
| 2506 | |
| 2507 | /* |
| 2508 | * Tell the other part of the chip to suspend temporarily all |
| 2509 | * its DMA activity. |
| 2510 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2511 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2512 | |
| 2513 | /* Disable the error attention */ |
| 2514 | hc_copy = readl(phba->HCregaddr); |
| 2515 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2516 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2517 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2518 | |
| 2519 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2520 | /* Clear Chip error bit */ |
| 2521 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2522 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | mbox = 0; |
| 2526 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2527 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2528 | |
| 2529 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2530 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2531 | writel(mbox, mbox_buf); |
| 2532 | |
| 2533 | for (i = 0; |
| 2534 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2535 | mdelay(1); |
| 2536 | |
| 2537 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2538 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2539 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2540 | goto restore_hc; |
| 2541 | else |
| 2542 | goto clear_errat; |
| 2543 | } |
| 2544 | |
| 2545 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2546 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2547 | mdelay(1); |
| 2548 | |
| 2549 | clear_errat: |
| 2550 | |
| 2551 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2552 | mdelay(1); |
| 2553 | |
| 2554 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2555 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2556 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2560 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2561 | writel(hc_copy, phba->HCregaddr); |
| 2562 | readl(phba->HCregaddr); /* flush */ |
| 2563 | } |
| 2564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2566 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2567 | * @phba: Pointer to HBA context object. |
| 2568 | * |
| 2569 | * This function issues a kill_board mailbox command and waits for |
| 2570 | * the error attention interrupt. This function is called for stopping |
| 2571 | * the firmware processing. The caller is not required to hold any |
| 2572 | * locks. This function calls lpfc_hba_down_post function to free |
| 2573 | * any pending commands after the kill. The function will return 1 when it |
| 2574 | * fails to kill the board else will return 0. |
| 2575 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2576 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2579 | struct lpfc_sli *psli; |
| 2580 | LPFC_MBOXQ_t *pmb; |
| 2581 | uint32_t status; |
| 2582 | uint32_t ha_copy; |
| 2583 | int retval; |
| 2584 | int i = 0; |
| 2585 | |
| 2586 | psli = &phba->sli; |
| 2587 | |
| 2588 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2589 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2590 | "0329 Kill HBA Data: x%x x%x\n", |
| 2591 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2592 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2593 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2594 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2595 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2596 | |
| 2597 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2598 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2599 | status = readl(phba->HCregaddr); |
| 2600 | status &= ~HC_ERINT_ENA; |
| 2601 | writel(status, phba->HCregaddr); |
| 2602 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2603 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2604 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2605 | |
| 2606 | lpfc_kill_board(phba, pmb); |
| 2607 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2608 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2609 | |
| 2610 | if (retval != MBX_SUCCESS) { |
| 2611 | if (retval != MBX_BUSY) |
| 2612 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2613 | spin_lock_irq(&phba->hbalock); |
| 2614 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2615 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2616 | return 1; |
| 2617 | } |
| 2618 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2619 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2620 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2621 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2622 | |
| 2623 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2624 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2625 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2626 | * board is now undefined. |
| 2627 | */ |
| 2628 | ha_copy = readl(phba->HAregaddr); |
| 2629 | |
| 2630 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2631 | mdelay(100); |
| 2632 | ha_copy = readl(phba->HAregaddr); |
| 2633 | } |
| 2634 | |
| 2635 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2636 | if (ha_copy & HA_ERATT) { |
| 2637 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2638 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2639 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2640 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2641 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2643 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2644 | |
| 2645 | psli->mbox_active = NULL; |
| 2646 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2647 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2650 | } |
| 2651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2653 | * lpfc_sli_brdreset - Reset the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2654 | * @phba: Pointer to HBA context object. |
| 2655 | * |
| 2656 | * This function resets the HBA by writing HC_INITFF to the control |
| 2657 | * register. After the HBA resets, this function resets all the iocb ring |
| 2658 | * indices. This function disables PCI layer parity checking during |
| 2659 | * the reset. |
| 2660 | * This function returns 0 always. |
| 2661 | * The caller is not required to hold any locks. |
| 2662 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2663 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2664 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2665 | { |
| 2666 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2668 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2671 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2673 | /* Reset HBA */ |
| 2674 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2675 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2676 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | |
| 2678 | /* perform board reset */ |
| 2679 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2680 | phba->pport->fc_myDID = 0; |
| 2681 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2683 | /* Turn off parity checking and serr during the physical reset */ |
| 2684 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2685 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2686 | (cfg_value & |
| 2687 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2688 | |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 2689 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2690 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2691 | writel(HC_INITFF, phba->HCregaddr); |
| 2692 | mdelay(1); |
| 2693 | readl(phba->HCregaddr); /* flush */ |
| 2694 | writel(0, phba->HCregaddr); |
| 2695 | readl(phba->HCregaddr); /* flush */ |
| 2696 | |
| 2697 | /* Restore PCI cmd register */ |
| 2698 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | |
| 2700 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2701 | for (i = 0; i < psli->num_rings; i++) { |
| 2702 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | pring->flag = 0; |
| 2704 | pring->rspidx = 0; |
| 2705 | pring->next_cmdidx = 0; |
| 2706 | pring->local_getidx = 0; |
| 2707 | pring->cmdidx = 0; |
| 2708 | pring->missbufcnt = 0; |
| 2709 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2711 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2712 | return 0; |
| 2713 | } |
| 2714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2715 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2716 | * lpfc_sli_brdrestart - Restart the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2717 | * @phba: Pointer to HBA context object. |
| 2718 | * |
| 2719 | * This function is called in the SLI initialization code path to |
| 2720 | * restart the HBA. The caller is not required to hold any lock. |
| 2721 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 2722 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 2723 | * function to free any pending commands. The function enables |
| 2724 | * POST only during the first initialization. The function returns zero. |
| 2725 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 2726 | * command before the return of this function. |
| 2727 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2728 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2730 | { |
| 2731 | MAILBOX_t *mb; |
| 2732 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2733 | volatile uint32_t word0; |
| 2734 | void __iomem *to_slim; |
| 2735 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2737 | |
| 2738 | psli = &phba->sli; |
| 2739 | |
| 2740 | /* Restart HBA */ |
| 2741 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2742 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2744 | |
| 2745 | word0 = 0; |
| 2746 | mb = (MAILBOX_t *) &word0; |
| 2747 | mb->mbxCommand = MBX_RESTART; |
| 2748 | mb->mbxHc = 1; |
| 2749 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2750 | lpfc_reset_barrier(phba); |
| 2751 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2752 | to_slim = phba->MBslimaddr; |
| 2753 | writel(*(uint32_t *) mb, to_slim); |
| 2754 | readl(to_slim); /* flush */ |
| 2755 | |
| 2756 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2757 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2758 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2759 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2760 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2761 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2762 | writel(*(uint32_t *) mb, to_slim); |
| 2763 | readl(to_slim); /* flush */ |
| 2764 | |
| 2765 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2766 | phba->pport->stopped = 0; |
| 2767 | phba->link_state = LPFC_INIT_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2768 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2769 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2770 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2771 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 2772 | psli->stats_start = get_seconds(); |
| 2773 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2774 | /* Give the INITFF and Post time to settle. */ |
| 2775 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2777 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | |
| 2779 | return 0; |
| 2780 | } |
| 2781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2782 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2783 | * 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] | 2784 | * @phba: Pointer to HBA context object. |
| 2785 | * |
| 2786 | * This function is called after a HBA restart to wait for successful |
| 2787 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 2788 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 2789 | * iteration, the function will restart the HBA again. The function returns |
| 2790 | * zero if HBA successfully restarted else returns negative error code. |
| 2791 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | static int |
| 2793 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 2794 | { |
| 2795 | uint32_t status, i = 0; |
| 2796 | |
| 2797 | /* Read the HBA Host Status Register */ |
| 2798 | status = readl(phba->HSregaddr); |
| 2799 | |
| 2800 | /* Check status register to see what current state is */ |
| 2801 | i = 0; |
| 2802 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 2803 | |
| 2804 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 2805 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 2806 | * 4. |
| 2807 | */ |
| 2808 | if (i++ >= 20) { |
| 2809 | /* Adapter failed to init, timeout, status reg |
| 2810 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2812 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2813 | "timeout, status reg x%x, " |
| 2814 | "FW Data: A8 x%x AC x%x\n", status, |
| 2815 | readl(phba->MBslimaddr + 0xa8), |
| 2816 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2817 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 | return -ETIMEDOUT; |
| 2819 | } |
| 2820 | |
| 2821 | /* Check to see if any errors occurred during init */ |
| 2822 | if (status & HS_FFERM) { |
| 2823 | /* ERROR: During chipset initialization */ |
| 2824 | /* Adapter failed to init, chipset, status reg |
| 2825 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2826 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2827 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2828 | "chipset, status reg x%x, " |
| 2829 | "FW Data: A8 x%x AC x%x\n", status, |
| 2830 | readl(phba->MBslimaddr + 0xa8), |
| 2831 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2832 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | return -EIO; |
| 2834 | } |
| 2835 | |
| 2836 | if (i <= 5) { |
| 2837 | msleep(10); |
| 2838 | } else if (i <= 10) { |
| 2839 | msleep(500); |
| 2840 | } else { |
| 2841 | msleep(2500); |
| 2842 | } |
| 2843 | |
| 2844 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2845 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2846 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2847 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2848 | } |
| 2849 | /* Read the HBA Host Status Register */ |
| 2850 | status = readl(phba->HSregaddr); |
| 2851 | } |
| 2852 | |
| 2853 | /* Check to see if any errors occurred during init */ |
| 2854 | if (status & HS_FFERM) { |
| 2855 | /* ERROR: During chipset initialization */ |
| 2856 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2858 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2859 | "status reg x%x, " |
| 2860 | "FW Data: A8 x%x AC x%x\n", status, |
| 2861 | readl(phba->MBslimaddr + 0xa8), |
| 2862 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2863 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | return -EIO; |
| 2865 | } |
| 2866 | |
| 2867 | /* Clear all interrupt enable conditions */ |
| 2868 | writel(0, phba->HCregaddr); |
| 2869 | readl(phba->HCregaddr); /* flush */ |
| 2870 | |
| 2871 | /* setup host attn register */ |
| 2872 | writel(0xffffffff, phba->HAregaddr); |
| 2873 | readl(phba->HAregaddr); /* flush */ |
| 2874 | return 0; |
| 2875 | } |
| 2876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2877 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2878 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2879 | * |
| 2880 | * This function calculates and returns the number of HBQs required to be |
| 2881 | * configured. |
| 2882 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2883 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2884 | lpfc_sli_hbq_count(void) |
| 2885 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2886 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2887 | } |
| 2888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2890 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2891 | * |
| 2892 | * This function adds the number of hbq entries in every HBQ to get |
| 2893 | * the total number of hbq entries required for the HBA and returns |
| 2894 | * the total count. |
| 2895 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2896 | static int |
| 2897 | lpfc_sli_hbq_entry_count(void) |
| 2898 | { |
| 2899 | int hbq_count = lpfc_sli_hbq_count(); |
| 2900 | int count = 0; |
| 2901 | int i; |
| 2902 | |
| 2903 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2904 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2905 | return count; |
| 2906 | } |
| 2907 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2909 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2910 | * |
| 2911 | * This function calculates amount of memory required for all hbq entries |
| 2912 | * to be configured and returns the total memory required. |
| 2913 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2915 | lpfc_sli_hbq_size(void) |
| 2916 | { |
| 2917 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 2918 | } |
| 2919 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2920 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2921 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2922 | * @phba: Pointer to HBA context object. |
| 2923 | * |
| 2924 | * This function is called during the SLI initialization to configure |
| 2925 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 2926 | * required to hold any locks. This function will return zero if successful |
| 2927 | * else it will return negative error code. |
| 2928 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2929 | static int |
| 2930 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 2931 | { |
| 2932 | int hbq_count = lpfc_sli_hbq_count(); |
| 2933 | LPFC_MBOXQ_t *pmb; |
| 2934 | MAILBOX_t *pmbox; |
| 2935 | uint32_t hbqno; |
| 2936 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2937 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2938 | /* Get a Mailbox buffer to setup mailbox |
| 2939 | * commands for HBA initialization |
| 2940 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2941 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2942 | |
| 2943 | if (!pmb) |
| 2944 | return -ENOMEM; |
| 2945 | |
| 2946 | pmbox = &pmb->mb; |
| 2947 | |
| 2948 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 2949 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2950 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2951 | |
| 2952 | hbq_entry_index = 0; |
| 2953 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 2954 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 2955 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 2956 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 2957 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2958 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2959 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 2960 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2961 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 2962 | |
| 2963 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 2964 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 2965 | mbxStatus <status>, ring <num> */ |
| 2966 | |
| 2967 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2968 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2969 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2970 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2971 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2972 | pmbox->mbxStatus, hbqno); |
| 2973 | |
| 2974 | phba->link_state = LPFC_HBA_ERROR; |
| 2975 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2976 | return ENXIO; |
| 2977 | } |
| 2978 | } |
| 2979 | phba->hbq_count = hbq_count; |
| 2980 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2981 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2984 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 2985 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2986 | return 0; |
| 2987 | } |
| 2988 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2989 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 2990 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2991 | * @phba: Pointer to HBA context object. |
| 2992 | * @sli_mode: sli mode - 2/3 |
| 2993 | * |
| 2994 | * This function is called by the sli intialization code path |
| 2995 | * to issue config_port mailbox command. This function restarts the |
| 2996 | * HBA firmware and issues a config_port mailbox command to configure |
| 2997 | * the SLI interface in the sli mode specified by sli_mode |
| 2998 | * variable. The caller is not required to hold any locks. |
| 2999 | * The function returns 0 if successful, else returns negative error |
| 3000 | * code. |
| 3001 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3002 | int |
| 3003 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | { |
| 3005 | LPFC_MBOXQ_t *pmb; |
| 3006 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3007 | |
| 3008 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3009 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3010 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3011 | return -ENOMEM; |
| 3012 | } |
| 3013 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3014 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3016 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3017 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3019 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3020 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | rc = lpfc_sli_chipset_init(phba); |
| 3022 | if (rc) |
| 3023 | break; |
| 3024 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3025 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3026 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3027 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | resetcount++; |
| 3029 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3030 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3031 | * value of 0 means the call was successful. Any other |
| 3032 | * nonzero value is a failure, but if ERESTART is returned, |
| 3033 | * the driver may reset the HBA and try again. |
| 3034 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | rc = lpfc_config_port_prep(phba); |
| 3036 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3037 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3039 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3041 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | lpfc_config_port(phba, pmb); |
| 3043 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3044 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3045 | LPFC_SLI3_HBQ_ENABLED | |
| 3046 | LPFC_SLI3_CRP_ENABLED | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3047 | LPFC_SLI3_INB_ENABLED | |
| 3048 | LPFC_SLI3_BG_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3049 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3051 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3052 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3053 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3054 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | spin_unlock_irq(&phba->hbalock); |
| 3057 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3058 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3059 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3061 | if (!done) { |
| 3062 | rc = -EINVAL; |
| 3063 | goto do_prep_failed; |
| 3064 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3065 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3066 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3067 | rc = -ENXIO; |
| 3068 | goto do_prep_failed; |
| 3069 | } |
| 3070 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3071 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3072 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3073 | } else |
| 3074 | phba->max_vpi = 0; |
| 3075 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3076 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3077 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3078 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3079 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3080 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3081 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3082 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3083 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3084 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3085 | phba->inb_last_counter = |
| 3086 | phba->mbox->us.s3_inb_pgp.counter; |
| 3087 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3088 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3089 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3090 | phba->inb_ha_copy = NULL; |
| 3091 | phba->inb_counter = NULL; |
| 3092 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3093 | |
| 3094 | if (phba->cfg_enable_bg) { |
| 3095 | if (pmb->mb.un.varCfgPort.gbg) |
| 3096 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 3097 | else |
| 3098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3099 | "0443 Adapter did not grant " |
| 3100 | "BlockGuard\n"); |
| 3101 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3102 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3103 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3104 | phba->port_gp = phba->mbox->us.s2.port; |
| 3105 | phba->inb_ha_copy = NULL; |
| 3106 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3107 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3108 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3109 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3110 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3111 | return rc; |
| 3112 | } |
| 3113 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3114 | |
| 3115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3116 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3117 | * @phba: Pointer to HBA context object. |
| 3118 | * |
| 3119 | * This function is the main SLI intialization function. This function |
| 3120 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3121 | * error attention handler code. Caller is not required to hold any |
| 3122 | * locks. This function issues config_port mailbox command to configure |
| 3123 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3124 | * calls the config_port_post function to issue init_link mailbox |
| 3125 | * command and to start the discovery. The function will return zero |
| 3126 | * if successful, else it will return negative error code. |
| 3127 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3128 | int |
| 3129 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3130 | { |
| 3131 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3132 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3133 | |
| 3134 | switch (lpfc_sli_mode) { |
| 3135 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3136 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3137 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3138 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3139 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3140 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | break; |
| 3142 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3143 | mode = 2; |
| 3144 | break; |
| 3145 | case 0: |
| 3146 | case 3: |
| 3147 | break; |
| 3148 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3150 | "1819 Unrecognized lpfc_sli_mode " |
| 3151 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3152 | |
| 3153 | break; |
| 3154 | } |
| 3155 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3156 | rc = lpfc_sli_config_port(phba, mode); |
| 3157 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3158 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3159 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3160 | "1820 Unable to select SLI-3. " |
| 3161 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3162 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3163 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3164 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | goto lpfc_sli_hba_setup_error; |
| 3166 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3167 | if (phba->sli_rev == 3) { |
| 3168 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3169 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3170 | } else { |
| 3171 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3172 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3173 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3177 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3178 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3179 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3180 | |
| 3181 | if (rc) |
| 3182 | goto lpfc_sli_hba_setup_error; |
| 3183 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3184 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3185 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3186 | rc = lpfc_sli_hbq_setup(phba); |
| 3187 | if (rc) |
| 3188 | goto lpfc_sli_hba_setup_error; |
| 3189 | } |
| 3190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3192 | |
| 3193 | rc = lpfc_config_port_post(phba); |
| 3194 | if (rc) |
| 3195 | goto lpfc_sli_hba_setup_error; |
| 3196 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3197 | return rc; |
| 3198 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3199 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3200 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3201 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3202 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | return rc; |
| 3204 | } |
| 3205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3206 | |
| 3207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3208 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3209 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3210 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3211 | * This is the callback function for mailbox timer. The mailbox |
| 3212 | * timer is armed when a new mailbox command is issued and the timer |
| 3213 | * is deleted when the mailbox complete. The function is called by |
| 3214 | * the kernel timer code when a mailbox does not complete within |
| 3215 | * expected time. This function wakes up the worker thread to |
| 3216 | * process the mailbox timeout and returns. All the processing is |
| 3217 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 3218 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3219 | void |
| 3220 | lpfc_mbox_timeout(unsigned long ptr) |
| 3221 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3222 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3224 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3226 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3227 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3228 | if (!tmo_posted) |
| 3229 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 3230 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 3231 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3232 | if (!tmo_posted) |
| 3233 | lpfc_worker_wake_up(phba); |
| 3234 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | } |
| 3236 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3237 | |
| 3238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3239 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3240 | * @phba: Pointer to HBA context object. |
| 3241 | * |
| 3242 | * This function is called from worker thread when a mailbox command times out. |
| 3243 | * The caller is not required to hold any locks. This function will reset the |
| 3244 | * HBA and recover all the pending commands. |
| 3245 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | void |
| 3247 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 3248 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 3250 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3251 | struct lpfc_sli *psli = &phba->sli; |
| 3252 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3255 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3256 | "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] | 3257 | mb->mbxCommand, |
| 3258 | phba->pport->port_state, |
| 3259 | phba->sli.sli_flag, |
| 3260 | phba->sli.mbox_active); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3262 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 3263 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 3264 | * it to fail all oustanding SCSI IO. |
| 3265 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | spin_lock_irq(&phba->pport->work_port_lock); |
| 3267 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 3268 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 3269 | spin_lock_irq(&phba->hbalock); |
| 3270 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3271 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3272 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3273 | |
| 3274 | pring = &psli->ring[psli->fcp_ring]; |
| 3275 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3276 | |
| 3277 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3278 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3279 | /* |
| 3280 | * lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 3281 | * on oustanding mailbox commands. |
| 3282 | */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3283 | /* If resets are disabled then set error state and return. */ |
| 3284 | if (!phba->cfg_enable_hba_reset) { |
| 3285 | phba->link_state = LPFC_HBA_ERROR; |
| 3286 | return; |
| 3287 | } |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3288 | lpfc_offline_prep(phba); |
| 3289 | lpfc_offline(phba); |
| 3290 | lpfc_sli_brdrestart(phba); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3291 | lpfc_online(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3292 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | return; |
| 3294 | } |
| 3295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3296 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3297 | * lpfc_sli_issue_mbox - Issue a mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3298 | * @phba: Pointer to HBA context object. |
| 3299 | * @pmbox: Pointer to mailbox object. |
| 3300 | * @flag: Flag indicating how the mailbox need to be processed. |
| 3301 | * |
| 3302 | * This function is called by discovery code and HBA management code |
| 3303 | * to submit a mailbox command to firmware. This function gets the |
| 3304 | * hbalock to protect the data structures. |
| 3305 | * The mailbox command can be submitted in polling mode, in which case |
| 3306 | * this function will wait in a polling loop for the completion of the |
| 3307 | * mailbox. |
| 3308 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 3309 | * function will submit the command and returns immediately without waiting |
| 3310 | * for the mailbox completion. The no_wait is supported only when HBA |
| 3311 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 3312 | * The SLI interface allows only one mailbox pending at a time. If the |
| 3313 | * mailbox is issued in polling mode and there is already a mailbox |
| 3314 | * pending, then the function will return an error. If the mailbox is issued |
| 3315 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 3316 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 3317 | * The sli layer owns the mailbox object until the completion of mailbox |
| 3318 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 3319 | * return codes the caller owns the mailbox command after the return of |
| 3320 | * the function. |
| 3321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3323 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | uint32_t status, evtctr; |
| 3328 | uint32_t ha_copy; |
| 3329 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3330 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3332 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3334 | int processing_queue = 0; |
| 3335 | |
| 3336 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3337 | if (!pmbox) { |
| 3338 | /* processing mbox queue from intr_handler */ |
| 3339 | processing_queue = 1; |
| 3340 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3341 | pmbox = lpfc_mbox_get(phba); |
| 3342 | if (!pmbox) { |
| 3343 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3344 | return MBX_SUCCESS; |
| 3345 | } |
| 3346 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3348 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3349 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3350 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3351 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3352 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3353 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3354 | "1806 Mbox x%x failed. No vport\n", |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3355 | pmbox->mb.mbxCommand); |
| 3356 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3357 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3358 | } |
| 3359 | } |
| 3360 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3361 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3362 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 3363 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3364 | goto out_not_finished; |
| 3365 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3366 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3368 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | mb = &pmbox->mb; |
| 3370 | status = MBX_SUCCESS; |
| 3371 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 3373 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3374 | |
| 3375 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3376 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3377 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3378 | } |
| 3379 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3380 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 3381 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3383 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3384 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3385 | } |
| 3386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 3388 | /* Polling for a mbox command when another one is already active |
| 3389 | * is not allowed in SLI. Also, the driver must have established |
| 3390 | * SLI2 mode to queue and process multiple mbox commands. |
| 3391 | */ |
| 3392 | |
| 3393 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | |
| 3396 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3397 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3398 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3404 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3405 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | } |
| 3407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | /* Another mailbox command is still being processed, queue this |
| 3409 | * command to be processed later. |
| 3410 | */ |
| 3411 | lpfc_mbox_put(phba, pmbox); |
| 3412 | |
| 3413 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3414 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3415 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3416 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3417 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 3418 | mb->mbxCommand, phba->pport->port_state, |
| 3419 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3420 | |
| 3421 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3424 | if (pmbox->vport) { |
| 3425 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3426 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3427 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 3428 | (uint32_t)mb->mbxCommand, |
| 3429 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3430 | } |
| 3431 | else { |
| 3432 | lpfc_debugfs_disc_trc(phba->pport, |
| 3433 | LPFC_DISC_TRC_MBOX, |
| 3434 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 3435 | (uint32_t)mb->mbxCommand, |
| 3436 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3437 | } |
| 3438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3439 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | } |
| 3441 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 3443 | |
| 3444 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 3445 | if (flag != MBX_POLL) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3446 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
| 3447 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3449 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3451 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3452 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | } |
| 3454 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 3455 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 3456 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3460 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3461 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3463 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3464 | mb->mbxCommand, phba->pport->port_state, |
| 3465 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3467 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 3468 | if (pmbox->vport) { |
| 3469 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 3470 | LPFC_DISC_TRC_MBOX_VPORT, |
| 3471 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 3472 | (uint32_t)mb->mbxCommand, |
| 3473 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3474 | } |
| 3475 | else { |
| 3476 | lpfc_debugfs_disc_trc(phba->pport, |
| 3477 | LPFC_DISC_TRC_MBOX, |
| 3478 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 3479 | (uint32_t)mb->mbxCommand, |
| 3480 | mb->un.varWords[0], mb->un.varWords[1]); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | psli->slistat.mbox_cmd++; |
| 3485 | evtctr = psli->slistat.mbox_event; |
| 3486 | |
| 3487 | /* next set own bit for the adapter and copy over command word */ |
| 3488 | mb->mbxOwner = OWN_CHIP; |
| 3489 | |
| 3490 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3492 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3494 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3496 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /* First copy mbox command data to HBA SLIM, skip past first |
| 3500 | word */ |
| 3501 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 3502 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 3503 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 3504 | |
| 3505 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3506 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | to_slim = phba->MBslimaddr; |
| 3508 | writel(ldata, to_slim); |
| 3509 | readl(to_slim); /* flush */ |
| 3510 | |
| 3511 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3512 | /* switch over to host mailbox */ |
| 3513 | psli->sli_flag |= LPFC_SLI2_ACTIVE; |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | |
| 3519 | switch (flag) { |
| 3520 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3521 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3522 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3523 | /* Interrupt board to do it */ |
| 3524 | writel(CA_MBATT, phba->CAregaddr); |
| 3525 | readl(phba->CAregaddr); /* flush */ |
| 3526 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3527 | break; |
| 3528 | |
| 3529 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3530 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3532 | /* Interrupt board to do it */ |
| 3533 | writel(CA_MBATT, phba->CAregaddr); |
| 3534 | readl(phba->CAregaddr); /* flush */ |
| 3535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3537 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3538 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3539 | word0 = le32_to_cpu(word0); |
| 3540 | } else { |
| 3541 | /* First read mbox status word */ |
| 3542 | word0 = readl(phba->MBslimaddr); |
| 3543 | } |
| 3544 | |
| 3545 | /* Read the HBA Host Attention Register */ |
| 3546 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3547 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3548 | mb->mbxCommand) * |
| 3549 | 1000) + jiffies; |
| 3550 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3552 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 3553 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3554 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3555 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3557 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3559 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | /* Check if we took a mbox interrupt while we were |
| 3563 | polling */ |
| 3564 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 3565 | && (evtctr != psli->slistat.mbox_event)) |
| 3566 | break; |
| 3567 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3568 | if (i++ > 10) { |
| 3569 | spin_unlock_irqrestore(&phba->hbalock, |
| 3570 | drvr_flag); |
| 3571 | msleep(1); |
| 3572 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 3573 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | |
| 3575 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| 3576 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3577 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | word0 = le32_to_cpu(word0); |
| 3579 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 3580 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3581 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | /* Check real SLIM for any errors */ |
| 3583 | slimword0 = readl(phba->MBslimaddr); |
| 3584 | slimmb = (MAILBOX_t *) & slimword0; |
| 3585 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 3586 | && slimmb->mbxStatus) { |
| 3587 | psli->sli_flag &= |
| 3588 | ~LPFC_SLI2_ACTIVE; |
| 3589 | word0 = slimword0; |
| 3590 | } |
| 3591 | } |
| 3592 | } else { |
| 3593 | /* First copy command data */ |
| 3594 | word0 = readl(phba->MBslimaddr); |
| 3595 | } |
| 3596 | /* Read the HBA Host Attention Register */ |
| 3597 | ha_copy = readl(phba->HAregaddr); |
| 3598 | } |
| 3599 | |
| 3600 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3602 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | } else { |
| 3604 | /* First copy command data */ |
| 3605 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 3606 | MAILBOX_CMD_SIZE); |
| 3607 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 3608 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3609 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3610 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 3611 | mb->un.varDmp.word_cnt); |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | writel(HA_MBATT, phba->HAregaddr); |
| 3616 | readl(phba->HAregaddr); /* flush */ |
| 3617 | |
| 3618 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 3619 | status = mb->mbxStatus; |
| 3620 | } |
| 3621 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 3623 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3624 | |
| 3625 | out_not_finished: |
| 3626 | if (processing_queue) { |
| 3627 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; |
| 3628 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 3629 | } |
| 3630 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | } |
| 3632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3634 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3635 | * @phba: Pointer to HBA context object. |
| 3636 | * @pring: Pointer to driver SLI ring object. |
| 3637 | * @piocb: Pointer to address of newly added command iocb. |
| 3638 | * |
| 3639 | * This function is called with hbalock held to add a command |
| 3640 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 3641 | * to the ring. |
| 3642 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3643 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3644 | __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] | 3645 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3646 | { |
| 3647 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 3648 | list_add_tail(&piocb->list, &pring->txq); |
| 3649 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | } |
| 3651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3653 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3654 | * @phba: Pointer to HBA context object. |
| 3655 | * @pring: Pointer to driver SLI ring object. |
| 3656 | * @piocb: Pointer to address of newly added command iocb. |
| 3657 | * |
| 3658 | * This function is called with hbalock held before a new |
| 3659 | * iocb is submitted to the firmware. This function checks |
| 3660 | * txq to flush the iocbs in txq to Firmware before |
| 3661 | * submitting new iocbs to the Firmware. |
| 3662 | * If there are iocbs in the txq which need to be submitted |
| 3663 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 3664 | * of the txq after dequeuing it from txq. |
| 3665 | * If there is no iocb in the txq then the function will return |
| 3666 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 3667 | * *piocb to find if there are more commands in the txq. |
| 3668 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | static struct lpfc_iocbq * |
| 3670 | 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] | 3671 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | { |
| 3673 | struct lpfc_iocbq * nextiocb; |
| 3674 | |
| 3675 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 3676 | if (!nextiocb) { |
| 3677 | nextiocb = *piocb; |
| 3678 | *piocb = NULL; |
| 3679 | } |
| 3680 | |
| 3681 | return nextiocb; |
| 3682 | } |
| 3683 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3684 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3685 | * __lpfc_sli_issue_iocb - Lockless version of lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3686 | * @phba: Pointer to HBA context object. |
| 3687 | * @pring: Pointer to driver SLI ring object. |
| 3688 | * @piocb: Pointer to command iocb. |
| 3689 | * @flag: Flag indicating if this command can be put into txq. |
| 3690 | * |
| 3691 | * __lpfc_sli_issue_iocb is used by other functions in the driver |
| 3692 | * to issue an iocb command to the HBA. If the PCI slot is recovering |
| 3693 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 3694 | * flag is turned on, the function returns IOCB_ERROR. |
| 3695 | * When the link is down, this function allows only iocbs for |
| 3696 | * posting buffers. |
| 3697 | * This function finds next available slot in the command ring and |
| 3698 | * posts the command to the available slot and writes the port |
| 3699 | * attention register to request HBA start processing new iocb. |
| 3700 | * If there is no slot available in the ring and |
| 3701 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the |
| 3702 | * txq, otherwise the function returns IOCB_BUSY. |
| 3703 | * |
| 3704 | * This function is called with hbalock held. |
| 3705 | * The function will return success after it successfully submit the |
| 3706 | * iocb to firmware or after adding to the txq. |
| 3707 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3708 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3709 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3711 | { |
| 3712 | struct lpfc_iocbq *nextiocb; |
| 3713 | IOCB_t *iocb; |
| 3714 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3715 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 3716 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 3717 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 3718 | lpfc_printf_log(phba, KERN_ERR, |
| 3719 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3720 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3721 | piocb->iocb.ulpCommand); |
| 3722 | dump_stack(); |
| 3723 | return IOCB_ERROR; |
| 3724 | } |
| 3725 | |
| 3726 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3727 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 3728 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 3729 | return IOCB_ERROR; |
| 3730 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | /* |
| 3732 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 3733 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3734 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | return IOCB_ERROR; |
| 3736 | |
| 3737 | /* |
| 3738 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3739 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3741 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | goto iocb_busy; |
| 3743 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3745 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3746 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | * can be issued if the link is not up. |
| 3748 | */ |
| 3749 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3750 | case CMD_GEN_REQUEST64_CR: |
| 3751 | case CMD_GEN_REQUEST64_CX: |
| 3752 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 3753 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 3754 | FC_FCP_CMND) || |
| 3755 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 3756 | MENLO_TRANSPORT_TYPE)) |
| 3757 | |
| 3758 | goto iocb_busy; |
| 3759 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | case CMD_QUE_RING_BUF_CN: |
| 3761 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | /* |
| 3763 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 3764 | * completion, iocb_cmpl MUST be 0. |
| 3765 | */ |
| 3766 | if (piocb->iocb_cmpl) |
| 3767 | piocb->iocb_cmpl = NULL; |
| 3768 | /*FALLTHROUGH*/ |
| 3769 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 3770 | case CMD_CLOSE_XRI_CN: |
| 3771 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | break; |
| 3773 | default: |
| 3774 | goto iocb_busy; |
| 3775 | } |
| 3776 | |
| 3777 | /* |
| 3778 | * For FCP commands, we must be in a state where we can process link |
| 3779 | * attention events. |
| 3780 | */ |
| 3781 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3782 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3784 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 3787 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 3788 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 3789 | |
| 3790 | if (iocb) |
| 3791 | lpfc_sli_update_ring(phba, pring); |
| 3792 | else |
| 3793 | lpfc_sli_update_full_ring(phba, pring); |
| 3794 | |
| 3795 | if (!piocb) |
| 3796 | return IOCB_SUCCESS; |
| 3797 | |
| 3798 | goto out_busy; |
| 3799 | |
| 3800 | iocb_busy: |
| 3801 | pring->stats.iocb_cmd_delay++; |
| 3802 | |
| 3803 | out_busy: |
| 3804 | |
| 3805 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3806 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | return IOCB_SUCCESS; |
| 3808 | } |
| 3809 | |
| 3810 | return IOCB_BUSY; |
| 3811 | } |
| 3812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3813 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3814 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3815 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3816 | * @phba: Pointer to HBA context object. |
| 3817 | * @pring: Pointer to driver SLI ring object. |
| 3818 | * @piocb: Pointer to command iocb. |
| 3819 | * @flag: Flag indicating if this command can be put into txq. |
| 3820 | * |
| 3821 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 3822 | * function. This function gets the hbalock and calls |
| 3823 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 3824 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 3825 | * functions which do not hold hbalock. |
| 3826 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3827 | int |
| 3828 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3829 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 3830 | { |
| 3831 | unsigned long iflags; |
| 3832 | int rc; |
| 3833 | |
| 3834 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 3835 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); |
| 3836 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 3837 | |
| 3838 | return rc; |
| 3839 | } |
| 3840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3842 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3843 | * @phba: Pointer to HBA context object. |
| 3844 | * |
| 3845 | * This function is called while driver attaches with the |
| 3846 | * HBA to setup the extra ring. The extra ring is used |
| 3847 | * only when driver needs to support target mode functionality |
| 3848 | * or IP over FC functionalities. |
| 3849 | * |
| 3850 | * This function is called with no lock held. |
| 3851 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3852 | static int |
| 3853 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 3854 | { |
| 3855 | struct lpfc_sli *psli; |
| 3856 | struct lpfc_sli_ring *pring; |
| 3857 | |
| 3858 | psli = &phba->sli; |
| 3859 | |
| 3860 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3861 | |
| 3862 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3863 | pring = &psli->ring[psli->fcp_ring]; |
| 3864 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3865 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3866 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3867 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3868 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3869 | /* and give them to the extra ring */ |
| 3870 | pring = &psli->ring[psli->extra_ring]; |
| 3871 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3872 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3873 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3874 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3875 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 3876 | |
| 3877 | /* Setup default profile for this ring */ |
| 3878 | pring->iotag_max = 4096; |
| 3879 | pring->num_mask = 1; |
| 3880 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3881 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 3882 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3883 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 3884 | return 0; |
| 3885 | } |
| 3886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3888 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3889 | * @phba: Pointer to HBA context object. |
| 3890 | * @pring: Pointer to driver SLI ring object. |
| 3891 | * @iocbq: Pointer to iocb object. |
| 3892 | * |
| 3893 | * This function is called by the slow ring event handler |
| 3894 | * function when there is an ASYNC event iocb in the ring. |
| 3895 | * This function is called with no lock held. |
| 3896 | * Currently this function handles only temperature related |
| 3897 | * ASYNC events. The function decodes the temperature sensor |
| 3898 | * event message and posts events for the management applications. |
| 3899 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3900 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3901 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 3902 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 3903 | { |
| 3904 | IOCB_t *icmd; |
| 3905 | uint16_t evt_code; |
| 3906 | uint16_t temp; |
| 3907 | struct temp_event temp_event_data; |
| 3908 | struct Scsi_Host *shost; |
| 3909 | |
| 3910 | icmd = &iocbq->iocb; |
| 3911 | evt_code = icmd->un.asyncstat.evt_code; |
| 3912 | temp = icmd->ulpContext; |
| 3913 | |
| 3914 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 3915 | (evt_code != ASYNC_TEMP_SAFE)) { |
| 3916 | lpfc_printf_log(phba, |
| 3917 | KERN_ERR, |
| 3918 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3919 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3920 | " evt_code 0x%x\n", |
| 3921 | pring->ringno, |
| 3922 | icmd->un.asyncstat.evt_code); |
| 3923 | return; |
| 3924 | } |
| 3925 | temp_event_data.data = (uint32_t)temp; |
| 3926 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 3927 | if (evt_code == ASYNC_TEMP_WARN) { |
| 3928 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 3929 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3930 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3931 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 3932 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3933 | "corrective action. temperature : %d Celsius\n", |
| 3934 | temp); |
| 3935 | } |
| 3936 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 3937 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 3938 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3939 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3940 | LOG_TEMP, |
| 3941 | "0340 Adapter temperature is OK now. " |
| 3942 | "temperature : %d Celsius\n", |
| 3943 | temp); |
| 3944 | } |
| 3945 | |
| 3946 | /* Send temperature change event to applications */ |
| 3947 | shost = lpfc_shost_from_vport(phba->pport); |
| 3948 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 3949 | sizeof(temp_event_data), (char *) &temp_event_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3950 | LPFC_NL_VENDOR_ID); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 3951 | |
| 3952 | } |
| 3953 | |
| 3954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 3956 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3957 | * @phba: Pointer to HBA context object. |
| 3958 | * |
| 3959 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 3960 | * number of iocbs per ring and iotags. This function is |
| 3961 | * called while driver attach to the HBA and before the |
| 3962 | * interrupts are enabled. So there is no need for locking. |
| 3963 | * |
| 3964 | * This function always returns 0. |
| 3965 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | int |
| 3967 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 3968 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3969 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | struct lpfc_sli *psli = &phba->sli; |
| 3971 | struct lpfc_sli_ring *pring; |
| 3972 | |
| 3973 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 3974 | psli->sli_flag = 0; |
| 3975 | psli->fcp_ring = LPFC_FCP_RING; |
| 3976 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3977 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3979 | psli->iocbq_lookup = NULL; |
| 3980 | psli->iocbq_lookup_len = 0; |
| 3981 | psli->last_iotag = 0; |
| 3982 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3983 | for (i = 0; i < psli->num_rings; i++) { |
| 3984 | pring = &psli->ring[i]; |
| 3985 | switch (i) { |
| 3986 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 3987 | /* numCiocb and numRiocb are used in config_port */ |
| 3988 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 3989 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 3990 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 3991 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 3992 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 3993 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3994 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3995 | SLI3_IOCB_CMD_SIZE : |
| 3996 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3997 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3998 | SLI3_IOCB_RSP_SIZE : |
| 3999 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4000 | pring->iotag_ctr = 0; |
| 4001 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4002 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | pring->fast_iotag = pring->iotag_max; |
| 4004 | pring->num_mask = 0; |
| 4005 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4006 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4007 | /* numCiocb and numRiocb are used in config_port */ |
| 4008 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 4009 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4010 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4011 | SLI3_IOCB_CMD_SIZE : |
| 4012 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4013 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4014 | SLI3_IOCB_RSP_SIZE : |
| 4015 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4017 | pring->num_mask = 0; |
| 4018 | break; |
| 4019 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 4020 | /* numCiocb and numRiocb are used in config_port */ |
| 4021 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 4022 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4023 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4024 | SLI3_IOCB_CMD_SIZE : |
| 4025 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4026 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4027 | SLI3_IOCB_RSP_SIZE : |
| 4028 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | pring->fast_iotag = 0; |
| 4030 | pring->iotag_ctr = 0; |
| 4031 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 4032 | pring->lpfc_sli_rcv_async_status = |
| 4033 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | pring->num_mask = 4; |
| 4035 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 4036 | pring->prt[0].rctl = FC_ELS_REQ; |
| 4037 | pring->prt[0].type = FC_ELS_DATA; |
| 4038 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4039 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 4041 | pring->prt[1].rctl = FC_ELS_RSP; |
| 4042 | pring->prt[1].type = FC_ELS_DATA; |
| 4043 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 4046 | /* NameServer Inquiry */ |
| 4047 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 4048 | /* NameServer */ |
| 4049 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 4050 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4051 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 4053 | /* NameServer response */ |
| 4054 | pring->prt[3].rctl = FC_SOL_CTL; |
| 4055 | /* NameServer */ |
| 4056 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 4057 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4058 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | break; |
| 4060 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4061 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4062 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4064 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4066 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 4067 | "SLI2 SLIM Data: x%x x%lx\n", |
| 4068 | phba->brd_no, totiocbsize, |
| 4069 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4071 | if (phba->cfg_multi_ring_support == 2) |
| 4072 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4077 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4078 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4079 | * @phba: Pointer to HBA context object. |
| 4080 | * |
| 4081 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 4082 | * ring. This function also initializes ring indices of each ring. |
| 4083 | * This function is called during the initialization of the SLI |
| 4084 | * interface of an HBA. |
| 4085 | * This function is called with no lock held and always returns |
| 4086 | * 1. |
| 4087 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4089 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | { |
| 4091 | struct lpfc_sli *psli; |
| 4092 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4093 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | |
| 4095 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4096 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4098 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 4100 | for (i = 0; i < psli->num_rings; i++) { |
| 4101 | pring = &psli->ring[i]; |
| 4102 | pring->ringno = i; |
| 4103 | pring->next_cmdidx = 0; |
| 4104 | pring->local_getidx = 0; |
| 4105 | pring->cmdidx = 0; |
| 4106 | INIT_LIST_HEAD(&pring->txq); |
| 4107 | INIT_LIST_HEAD(&pring->txcmplq); |
| 4108 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 4109 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4111 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4112 | spin_unlock_irq(&phba->hbalock); |
| 4113 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4114 | } |
| 4115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4117 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4118 | * @vport: Pointer to virtual port object. |
| 4119 | * |
| 4120 | * lpfc_sli_host_down is called to clean up the resources |
| 4121 | * associated with a vport before destroying virtual |
| 4122 | * port data structures. |
| 4123 | * This function does following operations: |
| 4124 | * - Free discovery resources associated with this virtual |
| 4125 | * port. |
| 4126 | * - Free iocbs associated with this virtual port in |
| 4127 | * the txq. |
| 4128 | * - Send abort for all iocb commands associated with this |
| 4129 | * vport in txcmplq. |
| 4130 | * |
| 4131 | * This function is called with no lock held and always returns 1. |
| 4132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4134 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 4135 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4136 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4137 | struct lpfc_hba *phba = vport->phba; |
| 4138 | struct lpfc_sli *psli = &phba->sli; |
| 4139 | struct lpfc_sli_ring *pring; |
| 4140 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4141 | int i; |
| 4142 | unsigned long flags = 0; |
| 4143 | uint16_t prev_pring_flag; |
| 4144 | |
| 4145 | lpfc_cleanup_discovery_resources(vport); |
| 4146 | |
| 4147 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4148 | for (i = 0; i < psli->num_rings; i++) { |
| 4149 | pring = &psli->ring[i]; |
| 4150 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4151 | /* Only slow rings */ |
| 4152 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4153 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4154 | /* Set the lpfc data pending flag */ |
| 4155 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4156 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4157 | /* |
| 4158 | * Error everything on the txq since these iocbs have not been |
| 4159 | * given to the FW yet. |
| 4160 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4161 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 4162 | if (iocb->vport != vport) |
| 4163 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4164 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4165 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /* Next issue ABTS for everything on the txcmplq */ |
| 4169 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 4170 | list) { |
| 4171 | if (iocb->vport != vport) |
| 4172 | continue; |
| 4173 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 4174 | } |
| 4175 | |
| 4176 | pring->flag = prev_pring_flag; |
| 4177 | } |
| 4178 | |
| 4179 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4180 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4181 | while (!list_empty(&completions)) { |
| 4182 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
| 4183 | |
| 4184 | if (!iocb->iocb_cmpl) |
| 4185 | lpfc_sli_release_iocbq(phba, iocb); |
| 4186 | else { |
| 4187 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4188 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4189 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 4190 | } |
| 4191 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4192 | return 1; |
| 4193 | } |
| 4194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4196 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4197 | * @phba: Pointer to HBA context object. |
| 4198 | * |
| 4199 | * This function cleans up all iocb, buffers, mailbox commands |
| 4200 | * while shutting down the HBA. This function is called with no |
| 4201 | * lock held and always returns 1. |
| 4202 | * This function does the following to cleanup driver resources: |
| 4203 | * - Free discovery resources for each virtual port |
| 4204 | * - Cleanup any pending fabric iocbs |
| 4205 | * - Iterate through the iocb txq and free each entry |
| 4206 | * in the list. |
| 4207 | * - Free up any buffer posted to the HBA |
| 4208 | * - Free mailbox commands in the mailbox queue. |
| 4209 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4210 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4211 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4212 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4213 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4214 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4215 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4216 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | LPFC_MBOXQ_t *pmb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4218 | struct lpfc_iocbq *iocb; |
| 4219 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4220 | int i; |
| 4221 | unsigned long flags = 0; |
| 4222 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | lpfc_hba_down_prep(phba); |
| 4224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4225 | lpfc_fabric_abort_hba(phba); |
| 4226 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | for (i = 0; i < psli->num_rings; i++) { |
| 4229 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4230 | /* Only slow rings */ |
| 4231 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4232 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4233 | /* Set the lpfc data pending flag */ |
| 4234 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 4235 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | |
| 4237 | /* |
| 4238 | * Error everything on the txq since these iocbs have not been |
| 4239 | * given to the FW yet. |
| 4240 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4241 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | pring->txq_cnt = 0; |
| 4243 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4244 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4246 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4247 | while (!list_empty(&completions)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4248 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4249 | cmd = &iocb->iocb; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4251 | if (!iocb->iocb_cmpl) |
| 4252 | lpfc_sli_release_iocbq(phba, iocb); |
| 4253 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4254 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4255 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; |
| 4256 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4258 | } |
| 4259 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4260 | spin_lock_irqsave(&phba->hbalock, flags); |
| 4261 | list_splice_init(&phba->elsbuf, &completions); |
| 4262 | phba->elsbuf_cnt = 0; |
| 4263 | phba->elsbuf_prev_cnt = 0; |
| 4264 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4265 | |
| 4266 | while (!list_empty(&completions)) { |
| 4267 | list_remove_head(&completions, buf_ptr, |
| 4268 | struct lpfc_dmabuf, list); |
| 4269 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 4270 | kfree(buf_ptr); |
| 4271 | } |
| 4272 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | /* Return any active mbox cmds */ |
| 4274 | del_timer_sync(&psli->mbox_tmo); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4275 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4276 | |
| 4277 | spin_lock(&phba->pport->work_port_lock); |
| 4278 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4279 | spin_unlock(&phba->pport->work_port_lock); |
| 4280 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4281 | /* Return any pending or completed mbox cmds */ |
| 4282 | list_splice_init(&phba->sli.mboxq, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4283 | if (psli->mbox_active) { |
| 4284 | list_add_tail(&psli->mbox_active->list, &completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4285 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4286 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4288 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4289 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 4290 | |
| 4291 | while (!list_empty(&completions)) { |
| 4292 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 4294 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4295 | pmb->mbox_cmpl(phba,pmb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4296 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4297 | return 1; |
| 4298 | } |
| 4299 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4301 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4302 | * @srcp: Source memory pointer. |
| 4303 | * @destp: Destination memory pointer. |
| 4304 | * @cnt: Number of words required to be copied. |
| 4305 | * |
| 4306 | * This function is used for copying data between driver memory |
| 4307 | * and the SLI memory. This function also changes the endianness |
| 4308 | * of each word if native endianness is different from SLI |
| 4309 | * endianness. This function can be called with or without |
| 4310 | * lock. |
| 4311 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | void |
| 4313 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 4314 | { |
| 4315 | uint32_t *src = srcp; |
| 4316 | uint32_t *dest = destp; |
| 4317 | uint32_t ldata; |
| 4318 | int i; |
| 4319 | |
| 4320 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 4321 | ldata = *src; |
| 4322 | ldata = le32_to_cpu(ldata); |
| 4323 | *dest = ldata; |
| 4324 | src++; |
| 4325 | dest++; |
| 4326 | } |
| 4327 | } |
| 4328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4329 | |
| 4330 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4331 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4332 | * @phba: Pointer to HBA context object. |
| 4333 | * @pring: Pointer to driver SLI ring object. |
| 4334 | * @mp: Pointer to driver buffer object. |
| 4335 | * |
| 4336 | * This function is called with no lock held. |
| 4337 | * It always return zero after adding the buffer to the postbufq |
| 4338 | * buffer list. |
| 4339 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4342 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | { |
| 4344 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 4345 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4346 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4349 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | return 0; |
| 4351 | } |
| 4352 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4354 | * 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] | 4355 | * @phba: Pointer to HBA context object. |
| 4356 | * |
| 4357 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 4358 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 4359 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 4360 | * does not conflict with tags of buffer posted for unsolicited events. |
| 4361 | * The function returns the allocated tag. The function is called with |
| 4362 | * no locks held. |
| 4363 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4364 | uint32_t |
| 4365 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 4366 | { |
| 4367 | spin_lock_irq(&phba->hbalock); |
| 4368 | phba->buffer_tag_count++; |
| 4369 | /* |
| 4370 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 4371 | * a tag assigned by HBQ. |
| 4372 | */ |
| 4373 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 4374 | spin_unlock_irq(&phba->hbalock); |
| 4375 | return phba->buffer_tag_count; |
| 4376 | } |
| 4377 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4378 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4379 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4380 | * @phba: Pointer to HBA context object. |
| 4381 | * @pring: Pointer to driver SLI ring object. |
| 4382 | * @tag: Buffer tag. |
| 4383 | * |
| 4384 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 4385 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 4386 | * iocb is posted to the response ring with the tag of the buffer. |
| 4387 | * This function searches the pring->postbufq list using the tag |
| 4388 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 4389 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 4390 | * buffer is returned to the caller else NULL is returned. |
| 4391 | * This function is called with no lock held. |
| 4392 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4393 | struct lpfc_dmabuf * |
| 4394 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4395 | uint32_t tag) |
| 4396 | { |
| 4397 | struct lpfc_dmabuf *mp, *next_mp; |
| 4398 | struct list_head *slp = &pring->postbufq; |
| 4399 | |
| 4400 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 4401 | spin_lock_irq(&phba->hbalock); |
| 4402 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4403 | if (mp->buffer_tag == tag) { |
| 4404 | list_del_init(&mp->list); |
| 4405 | pring->postbufq_cnt--; |
| 4406 | spin_unlock_irq(&phba->hbalock); |
| 4407 | return mp; |
| 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | spin_unlock_irq(&phba->hbalock); |
| 4412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4413 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4414 | "ring %d Data x%lx x%p x%p x%x\n", |
| 4415 | pring->ringno, (unsigned long) tag, |
| 4416 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4417 | |
| 4418 | return NULL; |
| 4419 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4422 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4423 | * @phba: Pointer to HBA context object. |
| 4424 | * @pring: Pointer to driver SLI ring object. |
| 4425 | * @phys: DMA address of the buffer. |
| 4426 | * |
| 4427 | * This function searches the buffer list using the dma_address |
| 4428 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 4429 | * corresponding to the dma_address. The function returns the |
| 4430 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 4431 | * This function is called by the ct and els unsolicited event |
| 4432 | * handlers to get the buffer associated with the unsolicited |
| 4433 | * event. |
| 4434 | * |
| 4435 | * This function is called with no lock held. |
| 4436 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4437 | struct lpfc_dmabuf * |
| 4438 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4439 | dma_addr_t phys) |
| 4440 | { |
| 4441 | struct lpfc_dmabuf *mp, *next_mp; |
| 4442 | struct list_head *slp = &pring->postbufq; |
| 4443 | |
| 4444 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4445 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4446 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 4447 | if (mp->phys == phys) { |
| 4448 | list_del_init(&mp->list); |
| 4449 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4451 | return mp; |
| 4452 | } |
| 4453 | } |
| 4454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4457 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4459 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | slp->next, slp->prev, pring->postbufq_cnt); |
| 4461 | return NULL; |
| 4462 | } |
| 4463 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4464 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4465 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4466 | * @phba: Pointer to HBA context object. |
| 4467 | * @cmdiocb: Pointer to driver command iocb object. |
| 4468 | * @rspiocb: Pointer to driver response iocb object. |
| 4469 | * |
| 4470 | * This function is the completion handler for the abort iocbs for |
| 4471 | * ELS commands. This function is called from the ELS ring event |
| 4472 | * handler with no lock held. This function frees memory resources |
| 4473 | * associated with the abort iocb. |
| 4474 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4476 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4477 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4478 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4479 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4480 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4481 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4482 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4483 | |
| 4484 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4485 | |
| 4486 | if (irsp->ulpStatus) { |
| 4487 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 4488 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 4489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4490 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4491 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 4492 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 4493 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4494 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4495 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4496 | "with tag %x context %x, abort status %x, " |
| 4497 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4498 | abort_iocb, abort_iotag, abort_context, |
| 4499 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4500 | |
| 4501 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4502 | * If the iocb is not found in Firmware queue the iocb |
| 4503 | * might have completed already. Do not free it again. |
| 4504 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 4505 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4506 | spin_unlock_irq(&phba->hbalock); |
| 4507 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 4508 | return; |
| 4509 | } |
| 4510 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4511 | * make sure we have the right iocbq before taking it |
| 4512 | * off the txcmplq and try to call completion routine. |
| 4513 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | if (!abort_iocb || |
| 4515 | abort_iocb->iocb.ulpContext != abort_context || |
| 4516 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 4517 | spin_unlock_irq(&phba->hbalock); |
| 4518 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4519 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4520 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4521 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4522 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4523 | /* Firmware could still be in progress of DMAing |
| 4524 | * payload, so don't free data buffer till after |
| 4525 | * a hbeat. |
| 4526 | */ |
| 4527 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 4528 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4529 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 4530 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4531 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4532 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 4533 | } |
| 4534 | } |
| 4535 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4536 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | return; |
| 4538 | } |
| 4539 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4540 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4541 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4542 | * @phba: Pointer to HBA context object. |
| 4543 | * @cmdiocb: Pointer to driver command iocb object. |
| 4544 | * @rspiocb: Pointer to driver response iocb object. |
| 4545 | * |
| 4546 | * The function is called from SLI ring event handler with no |
| 4547 | * lock held. This function is the completion handler for ELS commands |
| 4548 | * which are aborted. The function frees memory resources used for |
| 4549 | * the aborted ELS commands. |
| 4550 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4551 | static void |
| 4552 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4553 | struct lpfc_iocbq *rspiocb) |
| 4554 | { |
| 4555 | IOCB_t *irsp = &rspiocb->iocb; |
| 4556 | |
| 4557 | /* ELS cmd tag <ulpIoTag> completes */ |
| 4558 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4559 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4560 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4561 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4562 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4563 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 4564 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 4565 | else |
| 4566 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4567 | return; |
| 4568 | } |
| 4569 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4570 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4571 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4572 | * @phba: Pointer to HBA context object. |
| 4573 | * @pring: Pointer to driver SLI ring object. |
| 4574 | * @cmdiocb: Pointer to driver command iocb object. |
| 4575 | * |
| 4576 | * This function issues an abort iocb for the provided command |
| 4577 | * iocb. This function is called with hbalock held. |
| 4578 | * The function returns 0 when it fails due to memory allocation |
| 4579 | * failure or when the command iocb is an abort request. |
| 4580 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4581 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4583 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4584 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4586 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4587 | IOCB_t *icmd = NULL; |
| 4588 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4589 | int retval = IOCB_ERROR; |
| 4590 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4591 | /* |
| 4592 | * There are certain command types we don't want to abort. And we |
| 4593 | * don't want to abort commands that are already in the process of |
| 4594 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4595 | */ |
| 4596 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4597 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4598 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4599 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4600 | return 0; |
| 4601 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4602 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 4603 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4604 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4605 | if ((vport->load_flag & FC_UNLOADING) && |
| 4606 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4607 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 4608 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 4609 | else |
| 4610 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4611 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | |
| 4614 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4615 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4616 | if (abtsiocbp == NULL) |
| 4617 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4618 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4619 | /* This signals the response to set the correct status |
| 4620 | * before calling the completion handler. |
| 4621 | */ |
| 4622 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 4623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4624 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4625 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4626 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
| 4627 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4629 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4630 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4632 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 4633 | else |
| 4634 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 4635 | |
| 4636 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4637 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4638 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 4639 | "0339 Abort xri x%x, original iotag x%x, " |
| 4640 | "abort cmd iotag x%x\n", |
| 4641 | iabt->un.acxri.abortContextTag, |
| 4642 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4643 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4644 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4645 | if (retval) |
| 4646 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4647 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4648 | /* |
| 4649 | * Caller to this routine should check for IOCB_ERROR |
| 4650 | * and handle it properly. This routine no longer removes |
| 4651 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4652 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4653 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4654 | } |
| 4655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4657 | * 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] | 4658 | * @iocbq: Pointer to driver iocb object. |
| 4659 | * @vport: Pointer to driver virtual port object. |
| 4660 | * @tgt_id: SCSI ID of the target. |
| 4661 | * @lun_id: LUN ID of the scsi device. |
| 4662 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 4663 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4664 | * 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] | 4665 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 4666 | * 0 if the filtering criteria is met for the given iocb and will return |
| 4667 | * 1 if the filtering criteria is not met. |
| 4668 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 4669 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 4670 | * lun_id parameter. |
| 4671 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 4672 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 4673 | * parameters. |
| 4674 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 4675 | * given iocb is for the SCSI host associated with the given vport. |
| 4676 | * This function is called with no locks held. |
| 4677 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4678 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4679 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 4680 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4681 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4682 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4683 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4684 | int rc = 1; |
| 4685 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4686 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 4687 | return rc; |
| 4688 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4689 | if (iocbq->vport != vport) |
| 4690 | return rc; |
| 4691 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4692 | 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] | 4693 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4694 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4695 | return rc; |
| 4696 | |
| 4697 | switch (ctx_cmd) { |
| 4698 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4699 | if ((lpfc_cmd->rdata->pnode) && |
| 4700 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 4701 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | rc = 0; |
| 4703 | break; |
| 4704 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 4705 | if ((lpfc_cmd->rdata->pnode) && |
| 4706 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | rc = 0; |
| 4708 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | case LPFC_CTX_HOST: |
| 4710 | rc = 0; |
| 4711 | break; |
| 4712 | default: |
| 4713 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4714 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | return rc; |
| 4719 | } |
| 4720 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4721 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4722 | * 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] | 4723 | * @vport: Pointer to virtual port. |
| 4724 | * @tgt_id: SCSI ID of the target. |
| 4725 | * @lun_id: LUN ID of the scsi device. |
| 4726 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4727 | * |
| 4728 | * This function returns number of FCP commands pending for the vport. |
| 4729 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 4730 | * commands pending on the vport associated with SCSI device specified |
| 4731 | * by tgt_id and lun_id parameters. |
| 4732 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 4733 | * commands pending on the vport associated with SCSI target specified |
| 4734 | * by tgt_id parameter. |
| 4735 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 4736 | * commands pending on the vport. |
| 4737 | * This function returns the number of iocbs which satisfy the filter. |
| 4738 | * This function is called without any lock held. |
| 4739 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4741 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 4742 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4744 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4745 | struct lpfc_iocbq *iocbq; |
| 4746 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4748 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 4749 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4750 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4751 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 4752 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4753 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4754 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4755 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | return sum; |
| 4757 | } |
| 4758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4760 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4761 | * @phba: Pointer to HBA context object |
| 4762 | * @cmdiocb: Pointer to command iocb object. |
| 4763 | * @rspiocb: Pointer to response iocb object. |
| 4764 | * |
| 4765 | * This function is called when an aborted FCP iocb completes. This |
| 4766 | * function is called by the ring event handler with no lock held. |
| 4767 | * This function frees the iocb. |
| 4768 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4769 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4770 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4771 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4772 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4773 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4774 | return; |
| 4775 | } |
| 4776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4778 | * 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] | 4779 | * @vport: Pointer to virtual port. |
| 4780 | * @pring: Pointer to driver SLI ring object. |
| 4781 | * @tgt_id: SCSI ID of the target. |
| 4782 | * @lun_id: LUN ID of the scsi device. |
| 4783 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 4784 | * |
| 4785 | * This function sends an abort command for every SCSI command |
| 4786 | * associated with the given virtual port pending on the ring |
| 4787 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 4788 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 4789 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 4790 | * parameters |
| 4791 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 4792 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 4793 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 4794 | * FCP iocbs associated with virtual port. |
| 4795 | * This function returns number of iocbs it failed to abort. |
| 4796 | * This function is called with no locks held. |
| 4797 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4798 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4799 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 4800 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4802 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4803 | struct lpfc_iocbq *iocbq; |
| 4804 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4805 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4806 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4807 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4808 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4809 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 4810 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4811 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4812 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4813 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4814 | continue; |
| 4815 | |
| 4816 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4817 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4818 | if (abtsiocb == NULL) { |
| 4819 | errcnt++; |
| 4820 | continue; |
| 4821 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4822 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 4823 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 4825 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
| 4826 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| 4827 | abtsiocb->iocb.ulpLe = 1; |
| 4828 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4829 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4831 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 4833 | else |
| 4834 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 4835 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 4836 | /* Setup callback routine and issue the command. */ |
| 4837 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
| 4839 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4840 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4841 | errcnt++; |
| 4842 | continue; |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | return errcnt; |
| 4847 | } |
| 4848 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4849 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4850 | * 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] | 4851 | * @phba: Pointer to HBA context object. |
| 4852 | * @cmdiocbq: Pointer to command iocb. |
| 4853 | * @rspiocbq: Pointer to response iocb. |
| 4854 | * |
| 4855 | * This function is the completion handler for iocbs issued using |
| 4856 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 4857 | * ring event handler function without any lock held. This function |
| 4858 | * can be called from both worker thread context and interrupt |
| 4859 | * context. This function also can be called from other thread which |
| 4860 | * cleans up the SLI layer objects. |
| 4861 | * This function copy the contents of the response iocb to the |
| 4862 | * response iocb memory object provided by the caller of |
| 4863 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4864 | * sleeps for the iocb completion. |
| 4865 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4866 | static void |
| 4867 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 4868 | struct lpfc_iocbq *cmdiocbq, |
| 4869 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4871 | wait_queue_head_t *pdone_q; |
| 4872 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4874 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4875 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 4876 | if (cmdiocbq->context2 && rspiocbq) |
| 4877 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 4878 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 4879 | |
| 4880 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4881 | if (pdone_q) |
| 4882 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4883 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4884 | return; |
| 4885 | } |
| 4886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4888 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4889 | * @phba: Pointer to HBA context object.. |
| 4890 | * @pring: Pointer to sli ring. |
| 4891 | * @piocb: Pointer to command iocb. |
| 4892 | * @prspiocbq: Pointer to response iocb. |
| 4893 | * @timeout: Timeout in number of seconds. |
| 4894 | * |
| 4895 | * This function issues the iocb to firmware and waits for the |
| 4896 | * iocb to complete. If the iocb command is not |
| 4897 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 4898 | * Caller should not free the iocb resources if this function |
| 4899 | * returns IOCB_TIMEDOUT. |
| 4900 | * The function waits for the iocb completion using an |
| 4901 | * non-interruptible wait. |
| 4902 | * This function will sleep while waiting for iocb completion. |
| 4903 | * So, this function should not be called from any context which |
| 4904 | * does not allow sleeping. Due to the same reason, this function |
| 4905 | * cannot be called with interrupt disabled. |
| 4906 | * This function assumes that the iocb completions occur while |
| 4907 | * this function sleep. So, this function cannot be called from |
| 4908 | * the thread which process iocb completion for this ring. |
| 4909 | * This function clears the iocb_flag of the iocb object before |
| 4910 | * issuing the iocb and the iocb completion handler sets this |
| 4911 | * flag and wakes this thread when the iocb completes. |
| 4912 | * The contents of the response iocb will be copied to prspiocbq |
| 4913 | * by the completion handler when the command completes. |
| 4914 | * This function returns IOCB_SUCCESS when success. |
| 4915 | * This function is called with no lock held. |
| 4916 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4918 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
| 4919 | struct lpfc_sli_ring *pring, |
| 4920 | struct lpfc_iocbq *piocb, |
| 4921 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4922 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4923 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 4924 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4925 | long timeleft, timeout_req = 0; |
| 4926 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4927 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4928 | |
| 4929 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4930 | * If the caller has provided a response iocbq buffer, then context2 |
| 4931 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4933 | if (prspiocbq) { |
| 4934 | if (piocb->context2) |
| 4935 | return IOCB_ERROR; |
| 4936 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | } |
| 4938 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4939 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 4940 | piocb->context_un.wait_queue = &done_q; |
| 4941 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4943 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4944 | creg_val = readl(phba->HCregaddr); |
| 4945 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 4946 | writel(creg_val, phba->HCregaddr); |
| 4947 | readl(phba->HCregaddr); /* flush */ |
| 4948 | } |
| 4949 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4950 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
| 4951 | if (retval == IOCB_SUCCESS) { |
| 4952 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4953 | timeleft = wait_event_timeout(done_q, |
| 4954 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 4955 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4957 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 4958 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4959 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4960 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4961 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4962 | "0338 IOCB wait timeout error - no " |
| 4963 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4964 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4965 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4966 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4967 | "0330 IOCB wake NOT set, " |
| 4968 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4969 | timeout, (timeleft / jiffies)); |
| 4970 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4972 | } else { |
| 4973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4974 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4975 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4976 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | } |
| 4978 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4979 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 4980 | creg_val = readl(phba->HCregaddr); |
| 4981 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 4982 | writel(creg_val, phba->HCregaddr); |
| 4983 | readl(phba->HCregaddr); /* flush */ |
| 4984 | } |
| 4985 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4986 | if (prspiocbq) |
| 4987 | piocb->context2 = NULL; |
| 4988 | |
| 4989 | piocb->context_un.wait_queue = NULL; |
| 4990 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4991 | return retval; |
| 4992 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 4993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 4995 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4996 | * @phba: Pointer to HBA context object. |
| 4997 | * @pmboxq: Pointer to driver mailbox object. |
| 4998 | * @timeout: Timeout in number of seconds. |
| 4999 | * |
| 5000 | * This function issues the mailbox to firmware and waits for the |
| 5001 | * mailbox command to complete. If the mailbox command is not |
| 5002 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 5003 | * The function waits for the mailbox completion using an |
| 5004 | * interruptible wait. If the thread is woken up due to a |
| 5005 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 5006 | * should not free the mailbox resources, if this function returns |
| 5007 | * MBX_TIMEOUT. |
| 5008 | * This function will sleep while waiting for mailbox completion. |
| 5009 | * So, this function should not be called from any context which |
| 5010 | * does not allow sleeping. Due to the same reason, this function |
| 5011 | * cannot be called with interrupt disabled. |
| 5012 | * This function assumes that the mailbox completion occurs while |
| 5013 | * this function sleep. So, this function cannot be called from |
| 5014 | * the worker thread which processes mailbox completion. |
| 5015 | * This function is called in the context of HBA management |
| 5016 | * applications. |
| 5017 | * This function returns MBX_SUCCESS when successful. |
| 5018 | * This function is called with no lock held. |
| 5019 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5020 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5021 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | uint32_t timeout) |
| 5023 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 5024 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5025 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5026 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | |
| 5028 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5029 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5030 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5032 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5033 | /* setup wake call as IOCB callback */ |
| 5034 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 5035 | /* setup context field to pass wait_queue pointer to wake function */ |
| 5036 | pmboxq->context1 = &done_q; |
| 5037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5038 | /* now issue the command */ |
| 5039 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 5040 | |
| 5041 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5042 | wait_event_interruptible_timeout(done_q, |
| 5043 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 5044 | timeout * HZ); |
| 5045 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5046 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5048 | /* |
| 5049 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 5050 | * else do not free the resources. |
| 5051 | */ |
| 5052 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5054 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 5055 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5056 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 5057 | } |
| 5058 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | } |
| 5060 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | return retval; |
| 5062 | } |
| 5063 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 5065 | * lpfc_sli_flush_mbox_queue - mailbox queue cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5066 | * @phba: Pointer to HBA context. |
| 5067 | * |
| 5068 | * This function is called to cleanup any pending mailbox |
| 5069 | * objects in the driver queue before bringing the HBA offline. |
| 5070 | * This function is called while resetting the HBA. |
| 5071 | * The function is called without any lock held. The function |
| 5072 | * takes hbalock to update SLI data structure. |
| 5073 | * This function returns 1 when there is an active mailbox |
| 5074 | * command pending else returns 0. |
| 5075 | **/ |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5076 | int |
| 5077 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) |
| 5078 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5079 | struct lpfc_vport *vport = phba->pport; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5080 | int i = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5081 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5082 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5083 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5084 | if (i++ > LPFC_MBOX_TMO * 1000) |
| 5085 | return 1; |
| 5086 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5087 | /* |
| 5088 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd |
| 5089 | * did finish. This way we won't get the misleading |
| 5090 | * "Stray Mailbox Interrupt" message. |
| 5091 | */ |
| 5092 | spin_lock_irq(&phba->hbalock); |
| 5093 | ha_copy = phba->work_ha; |
| 5094 | phba->work_ha &= ~HA_MBATT; |
| 5095 | spin_unlock_irq(&phba->hbalock); |
| 5096 | |
| 5097 | if (ha_copy & HA_MBATT) |
| 5098 | if (lpfc_sli_handle_mb_event(phba) == 0) |
| 5099 | i = 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 5100 | |
| 5101 | msleep(1); |
| 5102 | } |
| 5103 | |
| 5104 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; |
| 5105 | } |
| 5106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 5108 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5109 | * @phba: Pointer to HBA context. |
| 5110 | * |
| 5111 | * This function is called form timer soft interrupt context to check HBA's |
| 5112 | * error attention register bit for error attention events. |
| 5113 | * |
| 5114 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 5115 | * Register and returns 0 otherwise. |
| 5116 | **/ |
| 5117 | int |
| 5118 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 5119 | { |
| 5120 | uint32_t ha_copy; |
| 5121 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 5122 | /* If PCI channel is offline, don't process it */ |
| 5123 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5124 | return 0; |
| 5125 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5126 | /* If somebody is waiting to handle an eratt, don't process it |
| 5127 | * here. The brdkill function will do this. |
| 5128 | */ |
| 5129 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5130 | return 0; |
| 5131 | |
| 5132 | /* Check if interrupt handler handles this ERATT */ |
| 5133 | spin_lock_irq(&phba->hbalock); |
| 5134 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 5135 | /* Interrupt handler has handled ERATT */ |
| 5136 | spin_unlock_irq(&phba->hbalock); |
| 5137 | return 0; |
| 5138 | } |
| 5139 | |
| 5140 | /* Read chip Host Attention (HA) register */ |
| 5141 | ha_copy = readl(phba->HAregaddr); |
| 5142 | if (ha_copy & HA_ERATT) { |
| 5143 | /* Read host status register to retrieve error event */ |
| 5144 | lpfc_sli_read_hs(phba); |
| 5145 | /* Set the driver HA work bitmap */ |
| 5146 | phba->work_ha |= HA_ERATT; |
| 5147 | /* Indicate polling handles this ERATT */ |
| 5148 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5149 | spin_unlock_irq(&phba->hbalock); |
| 5150 | return 1; |
| 5151 | } |
| 5152 | spin_unlock_irq(&phba->hbalock); |
| 5153 | return 0; |
| 5154 | } |
| 5155 | |
| 5156 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 5157 | * lpfc_sp_intr_handler - The slow-path interrupt handler of lpfc driver |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5158 | * @irq: Interrupt number. |
| 5159 | * @dev_id: The device context pointer. |
| 5160 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5161 | * This function is directly called from the PCI layer as an interrupt |
| 5162 | * service routine when the device is enabled with MSI-X multi-message |
| 5163 | * interrupt mode and there are slow-path events in the HBA. However, |
| 5164 | * when the device is enabled with either MSI or Pin-IRQ interrupt mode, |
| 5165 | * this function is called as part of the device-level interrupt handler. |
| 5166 | * When the PCI slot is in error recovery or the HBA is undergoing |
| 5167 | * initialization, the interrupt handler will not process the interrupt. |
| 5168 | * The link attention and ELS ring attention events are handled by the |
| 5169 | * worker thread. The interrupt handler signals the worker thread and |
| 5170 | * and returns for these events. This function is called without any |
| 5171 | * lock held. It gets the hbalock to access and update SLI data |
| 5172 | * structures. |
| 5173 | * |
| 5174 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5175 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5176 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5177 | irqreturn_t |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5178 | lpfc_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5180 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | uint32_t ha_copy; |
| 5182 | uint32_t work_ha_copy; |
| 5183 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5184 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | uint32_t control; |
| 5186 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5187 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5188 | struct lpfc_vport *vport; |
| 5189 | struct lpfc_nodelist *ndlp; |
| 5190 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5191 | LPFC_MBOXQ_t *pmb; |
| 5192 | int rc; |
| 5193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5194 | /* |
| 5195 | * Get the driver's phba structure from the dev_id and |
| 5196 | * assume the HBA is not interrupting. |
| 5197 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5198 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5199 | |
| 5200 | if (unlikely(!phba)) |
| 5201 | return IRQ_NONE; |
| 5202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5203 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5204 | * Stuff needs to be attented to when this function is invoked as an |
| 5205 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5206 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5207 | if (phba->intr_type == MSIX) { |
| 5208 | /* If the pci channel is offline, ignore all the interrupts */ |
| 5209 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5210 | return IRQ_NONE; |
| 5211 | /* Update device-level interrupt statistics */ |
| 5212 | phba->sli.slistat.sli_intr++; |
| 5213 | /* Ignore all interrupts during initialization. */ |
| 5214 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5215 | return IRQ_NONE; |
| 5216 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5217 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5218 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5219 | /* If somebody is waiting to handle an eratt don't process it |
| 5220 | * here. The brdkill function will do this. |
| 5221 | */ |
| 5222 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 5223 | ha_copy &= ~HA_ERATT; |
| 5224 | /* Check the need for handling ERATT in interrupt handler */ |
| 5225 | if (ha_copy & HA_ERATT) { |
| 5226 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5227 | /* ERATT polling has handled ERATT */ |
| 5228 | ha_copy &= ~HA_ERATT; |
| 5229 | else |
| 5230 | /* Indicate interrupt handler handles ERATT */ |
| 5231 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5232 | } |
| 5233 | /* Clear up only attention source related to slow-path */ |
| 5234 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 5235 | phba->HAregaddr); |
| 5236 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5237 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5238 | } else |
| 5239 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5240 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5241 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 5242 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5243 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5244 | if (work_ha_copy & HA_LATT) { |
| 5245 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 5246 | /* |
| 5247 | * Turn off Link Attention interrupts |
| 5248 | * until CLEAR_LA done |
| 5249 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5250 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 5252 | control = readl(phba->HCregaddr); |
| 5253 | control &= ~HC_LAINT_ENA; |
| 5254 | writel(control, phba->HCregaddr); |
| 5255 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5256 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | } |
| 5258 | else |
| 5259 | work_ha_copy &= ~HA_LATT; |
| 5260 | } |
| 5261 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5262 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5263 | /* |
| 5264 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 5265 | * the only slow ring. |
| 5266 | */ |
| 5267 | status = (work_ha_copy & |
| 5268 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5269 | status >>= (4*LPFC_ELS_RING); |
| 5270 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5271 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5272 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5273 | |
| 5274 | lpfc_debugfs_slow_ring_trc(phba, |
| 5275 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 5276 | control, status, |
| 5277 | (uint32_t)phba->sli.slistat.sli_intr); |
| 5278 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5279 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5280 | lpfc_debugfs_slow_ring_trc(phba, |
| 5281 | "ISR Disable ring:" |
| 5282 | "pwork:x%x hawork:x%x wait:x%x", |
| 5283 | phba->work_ha, work_ha_copy, |
| 5284 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5285 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5286 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5287 | control &= |
| 5288 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | writel(control, phba->HCregaddr); |
| 5290 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5291 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5292 | else { |
| 5293 | lpfc_debugfs_slow_ring_trc(phba, |
| 5294 | "ISR slow ring: pwork:" |
| 5295 | "x%x hawork:x%x wait:x%x", |
| 5296 | phba->work_ha, work_ha_copy, |
| 5297 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5298 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 5299 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5300 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5301 | } |
| 5302 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5303 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5304 | if (work_ha_copy & HA_ERATT) |
| 5305 | lpfc_sli_read_hs(phba); |
| 5306 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5307 | pmb = phba->sli.mbox_active; |
| 5308 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5309 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5310 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5311 | |
| 5312 | /* First check out the status word */ |
| 5313 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 5314 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5315 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5316 | /* |
| 5317 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 5318 | * mbxStatus <status> |
| 5319 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5320 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5321 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5322 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5323 | "Interrupt mbxCommand x%x " |
| 5324 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5325 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5326 | pmbox->mbxCommand, |
| 5327 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5328 | /* clear mailbox attention bit */ |
| 5329 | work_ha_copy &= ~HA_MBATT; |
| 5330 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5331 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5332 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5333 | phba->last_completion_time = jiffies; |
| 5334 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5335 | if (pmb->mbox_cmpl) { |
| 5336 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 5337 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5338 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5339 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 5340 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 5341 | |
| 5342 | lpfc_debugfs_disc_trc(vport, |
| 5343 | LPFC_DISC_TRC_MBOX_VPORT, |
| 5344 | "MBOX dflt rpi: : " |
| 5345 | "status:x%x rpi:x%x", |
| 5346 | (uint32_t)pmbox->mbxStatus, |
| 5347 | pmbox->un.varWords[0], 0); |
| 5348 | |
| 5349 | if (!pmbox->mbxStatus) { |
| 5350 | mp = (struct lpfc_dmabuf *) |
| 5351 | (pmb->context1); |
| 5352 | ndlp = (struct lpfc_nodelist *) |
| 5353 | pmb->context2; |
| 5354 | |
| 5355 | /* Reg_LOGIN of dflt RPI was |
| 5356 | * successful. new lets get |
| 5357 | * rid of the RPI using the |
| 5358 | * same mbox buffer. |
| 5359 | */ |
| 5360 | lpfc_unreg_login(phba, |
| 5361 | vport->vpi, |
| 5362 | pmbox->un.varWords[0], |
| 5363 | pmb); |
| 5364 | pmb->mbox_cmpl = |
| 5365 | lpfc_mbx_cmpl_dflt_rpi; |
| 5366 | pmb->context1 = mp; |
| 5367 | pmb->context2 = ndlp; |
| 5368 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5369 | rc = lpfc_sli_issue_mbox(phba, |
| 5370 | pmb, |
| 5371 | MBX_NOWAIT); |
| 5372 | if (rc != MBX_BUSY) |
| 5373 | lpfc_printf_log(phba, |
| 5374 | KERN_ERR, |
| 5375 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5376 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5377 | "been MBX_BUSY"); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5378 | goto send_current_mbox; |
| 5379 | } |
| 5380 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5381 | spin_lock_irqsave( |
| 5382 | &phba->pport->work_port_lock, |
| 5383 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5384 | phba->pport->work_port_events &= |
| 5385 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5386 | spin_unlock_irqrestore( |
| 5387 | &phba->pport->work_port_lock, |
| 5388 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5389 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5390 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 5391 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5392 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5393 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5394 | if ((work_ha_copy & HA_MBATT) && |
| 5395 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5396 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5397 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5398 | do { |
| 5399 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 5400 | MBX_NOWAIT); |
| 5401 | } while (rc == MBX_NOT_FINISHED); |
| 5402 | if (rc != MBX_SUCCESS) |
| 5403 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 5404 | LOG_SLI, "0349 rc should be " |
| 5405 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5406 | } |
| 5407 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5408 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5409 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5410 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5411 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5412 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5413 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5415 | } /* lpfc_sp_intr_handler */ |
| 5416 | |
| 5417 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 5418 | * lpfc_fp_intr_handler - The fast-path interrupt handler of lpfc driver |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5419 | * @irq: Interrupt number. |
| 5420 | * @dev_id: The device context pointer. |
| 5421 | * |
| 5422 | * This function is directly called from the PCI layer as an interrupt |
| 5423 | * service routine when the device is enabled with MSI-X multi-message |
| 5424 | * interrupt mode and there is a fast-path FCP IOCB ring event in the |
| 5425 | * HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 5426 | * interrupt mode, this function is called as part of the device-level |
| 5427 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 5428 | * is undergoing initialization, the interrupt handler will not process |
| 5429 | * the interrupt. The SCSI FCP fast-path ring event are handled in the |
| 5430 | * intrrupt context. This function is called without any lock held. It |
| 5431 | * gets the hbalock to access and update SLI data structures. |
| 5432 | * |
| 5433 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 5434 | * returns IRQ_NONE. |
| 5435 | **/ |
| 5436 | irqreturn_t |
| 5437 | lpfc_fp_intr_handler(int irq, void *dev_id) |
| 5438 | { |
| 5439 | struct lpfc_hba *phba; |
| 5440 | uint32_t ha_copy; |
| 5441 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5442 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5443 | |
| 5444 | /* Get the driver's phba structure from the dev_id and |
| 5445 | * assume the HBA is not interrupting. |
| 5446 | */ |
| 5447 | phba = (struct lpfc_hba *) dev_id; |
| 5448 | |
| 5449 | if (unlikely(!phba)) |
| 5450 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5451 | |
| 5452 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5453 | * Stuff needs to be attented to when this function is invoked as an |
| 5454 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5455 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5456 | if (phba->intr_type == MSIX) { |
| 5457 | /* If pci channel is offline, ignore all the interrupts */ |
| 5458 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5459 | return IRQ_NONE; |
| 5460 | /* Update device-level interrupt statistics */ |
| 5461 | phba->sli.slistat.sli_intr++; |
| 5462 | /* Ignore all interrupts during initialization. */ |
| 5463 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5464 | return IRQ_NONE; |
| 5465 | /* Need to read HA REG for FCP ring and other ring events */ |
| 5466 | ha_copy = readl(phba->HAregaddr); |
| 5467 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5468 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5469 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 5470 | phba->HAregaddr); |
| 5471 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5472 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5473 | } else |
| 5474 | ha_copy = phba->ha_copy; |
| 5475 | |
| 5476 | /* |
| 5477 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 5478 | */ |
| 5479 | ha_copy &= ~(phba->work_ha_mask); |
| 5480 | |
| 5481 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5483 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | lpfc_sli_handle_fast_ring_event(phba, |
| 5485 | &phba->sli.ring[LPFC_FCP_RING], |
| 5486 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5487 | |
| 5488 | if (phba->cfg_multi_ring_support == 2) { |
| 5489 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5490 | * Process all events on extra ring. Take the optimized path |
| 5491 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5492 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5493 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5494 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5495 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5496 | lpfc_sli_handle_fast_ring_event(phba, |
| 5497 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 5498 | status); |
| 5499 | } |
| 5500 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5501 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5502 | } /* lpfc_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5503 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5504 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame^] | 5505 | * lpfc_intr_handler - The device-level interrupt handler of lpfc driver |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5506 | * @irq: Interrupt number. |
| 5507 | * @dev_id: The device context pointer. |
| 5508 | * |
| 5509 | * This function is the device-level interrupt handler called from the PCI |
| 5510 | * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is |
| 5511 | * an event in the HBA which requires driver attention. This function |
| 5512 | * invokes the slow-path interrupt attention handling function and fast-path |
| 5513 | * interrupt attention handling function in turn to process the relevant |
| 5514 | * HBA attention events. This function is called without any lock held. It |
| 5515 | * gets the hbalock to access and update SLI data structures. |
| 5516 | * |
| 5517 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 5518 | * returns IRQ_NONE. |
| 5519 | **/ |
| 5520 | irqreturn_t |
| 5521 | lpfc_intr_handler(int irq, void *dev_id) |
| 5522 | { |
| 5523 | struct lpfc_hba *phba; |
| 5524 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 5525 | unsigned long status1, status2; |
| 5526 | |
| 5527 | /* |
| 5528 | * Get the driver's phba structure from the dev_id and |
| 5529 | * assume the HBA is not interrupting. |
| 5530 | */ |
| 5531 | phba = (struct lpfc_hba *) dev_id; |
| 5532 | |
| 5533 | if (unlikely(!phba)) |
| 5534 | return IRQ_NONE; |
| 5535 | |
| 5536 | /* If the pci channel is offline, ignore all the interrupts. */ |
| 5537 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5538 | return IRQ_NONE; |
| 5539 | |
| 5540 | /* Update device level interrupt statistics */ |
| 5541 | phba->sli.slistat.sli_intr++; |
| 5542 | |
| 5543 | /* Ignore all interrupts during initialization. */ |
| 5544 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 5545 | return IRQ_NONE; |
| 5546 | |
| 5547 | spin_lock(&phba->hbalock); |
| 5548 | phba->ha_copy = readl(phba->HAregaddr); |
| 5549 | if (unlikely(!phba->ha_copy)) { |
| 5550 | spin_unlock(&phba->hbalock); |
| 5551 | return IRQ_NONE; |
| 5552 | } else if (phba->ha_copy & HA_ERATT) { |
| 5553 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 5554 | /* ERATT polling has handled ERATT */ |
| 5555 | phba->ha_copy &= ~HA_ERATT; |
| 5556 | else |
| 5557 | /* Indicate interrupt handler handles ERATT */ |
| 5558 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 5559 | } |
| 5560 | |
| 5561 | /* Clear attention sources except link and error attentions */ |
| 5562 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 5563 | readl(phba->HAregaddr); /* flush */ |
| 5564 | spin_unlock(&phba->hbalock); |
| 5565 | |
| 5566 | /* |
| 5567 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 5568 | */ |
| 5569 | |
| 5570 | /* status of events with mailbox and link attention */ |
| 5571 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 5572 | |
| 5573 | /* status of events with ELS ring */ |
| 5574 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 5575 | status2 >>= (4*LPFC_ELS_RING); |
| 5576 | |
| 5577 | if (status1 || (status2 & HA_RXMASK)) |
| 5578 | sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id); |
| 5579 | else |
| 5580 | sp_irq_rc = IRQ_NONE; |
| 5581 | |
| 5582 | /* |
| 5583 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 5584 | */ |
| 5585 | |
| 5586 | /* status of events with FCP ring */ |
| 5587 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 5588 | status1 >>= (4*LPFC_FCP_RING); |
| 5589 | |
| 5590 | /* status of events with extra ring */ |
| 5591 | if (phba->cfg_multi_ring_support == 2) { |
| 5592 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 5593 | status2 >>= (4*LPFC_EXTRA_RING); |
| 5594 | } else |
| 5595 | status2 = 0; |
| 5596 | |
| 5597 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
| 5598 | fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id); |
| 5599 | else |
| 5600 | fp_irq_rc = IRQ_NONE; |
| 5601 | |
| 5602 | /* Return device-level interrupt handling status */ |
| 5603 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
| 5604 | } /* lpfc_intr_handler */ |