| 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> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 32 | #include <scsi/fc/fc_fs.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 34 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include "lpfc_hw.h" |
| 36 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 37 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 38 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_crtn.h" |
| 43 | #include "lpfc_logmsg.h" |
| 44 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 45 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Define macro to log: Mailbox command x%x cannot issue Data |
| 49 | * This allows multiple uses of lpfc_msgBlk0311 |
| 50 | * w/o perturbing log msg utility. |
| 51 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | lpfc_printf_log(phba, \ |
| 54 | KERN_INFO, \ |
| 55 | LOG_MBOX | LOG_SLI, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 56 | "(%d):0311 Mailbox command x%x cannot " \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 57 | "issue Data: x%x x%x x%x\n", \ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 58 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
| 59 | pmbox->mb.mbxCommand, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 60 | phba->pport->port_state, \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | psli->sli_flag, \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 62 | flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 63 | |
| 64 | |
| 65 | /* There are only four IOCB completion types. */ |
| 66 | typedef enum _lpfc_iocb_type { |
| 67 | LPFC_UNKNOWN_IOCB, |
| 68 | LPFC_UNSOL_IOCB, |
| 69 | LPFC_SOL_IOCB, |
| 70 | LPFC_ABORT_IOCB |
| 71 | } lpfc_iocb_type; |
| 72 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 73 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 74 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 75 | * @phba: Pointer to HBA context object. |
| 76 | * @pring: Pointer to driver SLI ring object. |
| 77 | * |
| 78 | * This function returns pointer to next command iocb entry |
| 79 | * in the command ring. The caller must hold hbalock to prevent |
| 80 | * other threads consume the next command iocb. |
| 81 | * SLI-2/SLI-3 provide different sized iocbs. |
| 82 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 83 | static inline IOCB_t * |
| 84 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 85 | { |
| 86 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 87 | pring->cmdidx * phba->iocb_cmd_size); |
| 88 | } |
| 89 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 90 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 91 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 92 | * @phba: Pointer to HBA context object. |
| 93 | * @pring: Pointer to driver SLI ring object. |
| 94 | * |
| 95 | * This function returns pointer to next response iocb entry |
| 96 | * in the response ring. The caller must hold hbalock to make sure |
| 97 | * that no other thread consume the next response iocb. |
| 98 | * SLI-2/SLI-3 provide different sized iocbs. |
| 99 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 100 | static inline IOCB_t * |
| 101 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 102 | { |
| 103 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 104 | pring->rspidx * phba->iocb_rsp_size); |
| 105 | } |
| 106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 108 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 109 | * @phba: Pointer to HBA context object. |
| 110 | * |
| 111 | * This function is called with hbalock held. This function |
| 112 | * allocates a new driver iocb object from the iocb pool. If the |
| 113 | * allocation is successful, it returns pointer to the newly |
| 114 | * allocated iocb object else it returns NULL. |
| 115 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 116 | static struct lpfc_iocbq * |
| 117 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 118 | { |
| 119 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 120 | struct lpfc_iocbq * iocbq = NULL; |
| 121 | |
| 122 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
| 123 | return iocbq; |
| 124 | } |
| 125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 126 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 127 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 128 | * @phba: Pointer to HBA context object. |
| 129 | * @xritag: XRI value. |
| 130 | * |
| 131 | * This function clears the sglq pointer from the array of acive |
| 132 | * sglq's. The xritag that is passed in is used to index into the |
| 133 | * array. Before the xritag can be used it needs to be adjusted |
| 134 | * by subtracting the xribase. |
| 135 | * |
| 136 | * Returns sglq ponter = success, NULL = Failure. |
| 137 | **/ |
| 138 | static struct lpfc_sglq * |
| 139 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 140 | { |
| 141 | uint16_t adj_xri; |
| 142 | struct lpfc_sglq *sglq; |
| 143 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; |
| 144 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) |
| 145 | return NULL; |
| 146 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; |
| 147 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL; |
| 148 | return sglq; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 153 | * @phba: Pointer to HBA context object. |
| 154 | * @xritag: XRI value. |
| 155 | * |
| 156 | * This function returns the sglq pointer from the array of acive |
| 157 | * sglq's. The xritag that is passed in is used to index into the |
| 158 | * array. Before the xritag can be used it needs to be adjusted |
| 159 | * by subtracting the xribase. |
| 160 | * |
| 161 | * Returns sglq ponter = success, NULL = Failure. |
| 162 | **/ |
| 163 | static struct lpfc_sglq * |
| 164 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 165 | { |
| 166 | uint16_t adj_xri; |
| 167 | struct lpfc_sglq *sglq; |
| 168 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; |
| 169 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) |
| 170 | return NULL; |
| 171 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; |
| 172 | return sglq; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 177 | * @phba: Pointer to HBA context object. |
| 178 | * |
| 179 | * This function is called with hbalock held. This function |
| 180 | * Gets a new driver sglq object from the sglq list. If the |
| 181 | * list is not empty then it is successful, it returns pointer to the newly |
| 182 | * allocated sglq object else it returns NULL. |
| 183 | **/ |
| 184 | static struct lpfc_sglq * |
| 185 | __lpfc_sli_get_sglq(struct lpfc_hba *phba) |
| 186 | { |
| 187 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 188 | struct lpfc_sglq *sglq = NULL; |
| 189 | uint16_t adj_xri; |
| 190 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
| 191 | adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base; |
| 192 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; |
| 193 | return sglq; |
| 194 | } |
| 195 | |
| 196 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 197 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 198 | * @phba: Pointer to HBA context object. |
| 199 | * |
| 200 | * This function is called with no lock held. This function |
| 201 | * allocates a new driver iocb object from the iocb pool. If the |
| 202 | * allocation is successful, it returns pointer to the newly |
| 203 | * allocated iocb object else it returns NULL. |
| 204 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 205 | struct lpfc_iocbq * |
| 206 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 207 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 208 | struct lpfc_iocbq * iocbq = NULL; |
| 209 | unsigned long iflags; |
| 210 | |
| 211 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 212 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 213 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 214 | return iocbq; |
| 215 | } |
| 216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 217 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 218 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 219 | * @phba: Pointer to HBA context object. |
| 220 | * @iocbq: Pointer to driver iocb object. |
| 221 | * |
| 222 | * This function is called with hbalock held to release driver |
| 223 | * iocb object to the iocb pool. The iotag in the iocb object |
| 224 | * does not change for each use of the iocb object. This function |
| 225 | * clears all other fields of the iocb object when it is freed. |
| 226 | **/ |
| 227 | static void |
| 228 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 229 | { |
| 230 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 231 | |
| 232 | /* |
| 233 | * Clean all volatile data fields, preserve iotag and node struct. |
| 234 | */ |
| 235 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 236 | iocbq->sli4_xritag = NO_XRI; |
| 237 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 238 | } |
| 239 | |
| 240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 241 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 242 | * @phba: Pointer to HBA context object. |
| 243 | * @iocbq: Pointer to driver iocb object. |
| 244 | * |
| 245 | * This function is called with hbalock held to release driver |
| 246 | * iocb object to the iocb pool. The iotag in the iocb object |
| 247 | * does not change for each use of the iocb object. This function |
| 248 | * clears all other fields of the iocb object when it is freed. |
| 249 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 250 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 251 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 252 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 253 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 254 | } |
| 255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 257 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 258 | * @phba: Pointer to HBA context object. |
| 259 | * @iocbq: Pointer to driver iocb object. |
| 260 | * |
| 261 | * This function is called with no lock held to release the iocb to |
| 262 | * iocb pool. |
| 263 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 264 | void |
| 265 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 266 | { |
| 267 | unsigned long iflags; |
| 268 | |
| 269 | /* |
| 270 | * Clean all volatile data fields, preserve iotag and node struct. |
| 271 | */ |
| 272 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 273 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 274 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 275 | } |
| 276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 277 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 278 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 279 | * @phba: Pointer to HBA context object. |
| 280 | * @iocblist: List of IOCBs. |
| 281 | * @ulpstatus: ULP status in IOCB command field. |
| 282 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 283 | * |
| 284 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 285 | * on the list by invoking the complete callback function associated with the |
| 286 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 287 | * fields. |
| 288 | **/ |
| 289 | void |
| 290 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 291 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 292 | { |
| 293 | struct lpfc_iocbq *piocb; |
| 294 | |
| 295 | while (!list_empty(iocblist)) { |
| 296 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 297 | |
| 298 | if (!piocb->iocb_cmpl) |
| 299 | lpfc_sli_release_iocbq(phba, piocb); |
| 300 | else { |
| 301 | piocb->iocb.ulpStatus = ulpstatus; |
| 302 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 303 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 304 | } |
| 305 | } |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 310 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 311 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 312 | * |
| 313 | * This function is called by ring event handler function to get the iocb type. |
| 314 | * This function translates the iocb command to an iocb command type used to |
| 315 | * decide the final disposition of each completed IOCB. |
| 316 | * The function returns |
| 317 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 318 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 319 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 320 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 321 | * |
| 322 | * The caller is not required to hold any lock. |
| 323 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | static lpfc_iocb_type |
| 325 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 326 | { |
| 327 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 328 | |
| 329 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 330 | return 0; |
| 331 | |
| 332 | switch (iocb_cmnd) { |
| 333 | case CMD_XMIT_SEQUENCE_CR: |
| 334 | case CMD_XMIT_SEQUENCE_CX: |
| 335 | case CMD_XMIT_BCAST_CN: |
| 336 | case CMD_XMIT_BCAST_CX: |
| 337 | case CMD_ELS_REQUEST_CR: |
| 338 | case CMD_ELS_REQUEST_CX: |
| 339 | case CMD_CREATE_XRI_CR: |
| 340 | case CMD_CREATE_XRI_CX: |
| 341 | case CMD_GET_RPI_CN: |
| 342 | case CMD_XMIT_ELS_RSP_CX: |
| 343 | case CMD_GET_RPI_CR: |
| 344 | case CMD_FCP_IWRITE_CR: |
| 345 | case CMD_FCP_IWRITE_CX: |
| 346 | case CMD_FCP_IREAD_CR: |
| 347 | case CMD_FCP_IREAD_CX: |
| 348 | case CMD_FCP_ICMND_CR: |
| 349 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 350 | case CMD_FCP_TSEND_CX: |
| 351 | case CMD_FCP_TRSP_CX: |
| 352 | case CMD_FCP_TRECEIVE_CX: |
| 353 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | case CMD_ADAPTER_MSG: |
| 355 | case CMD_ADAPTER_DUMP: |
| 356 | case CMD_XMIT_SEQUENCE64_CR: |
| 357 | case CMD_XMIT_SEQUENCE64_CX: |
| 358 | case CMD_XMIT_BCAST64_CN: |
| 359 | case CMD_XMIT_BCAST64_CX: |
| 360 | case CMD_ELS_REQUEST64_CR: |
| 361 | case CMD_ELS_REQUEST64_CX: |
| 362 | case CMD_FCP_IWRITE64_CR: |
| 363 | case CMD_FCP_IWRITE64_CX: |
| 364 | case CMD_FCP_IREAD64_CR: |
| 365 | case CMD_FCP_IREAD64_CX: |
| 366 | case CMD_FCP_ICMND64_CR: |
| 367 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 368 | case CMD_FCP_TSEND64_CX: |
| 369 | case CMD_FCP_TRSP64_CX: |
| 370 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 371 | case CMD_GEN_REQUEST64_CR: |
| 372 | case CMD_GEN_REQUEST64_CX: |
| 373 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 374 | case DSSCMD_IWRITE64_CR: |
| 375 | case DSSCMD_IWRITE64_CX: |
| 376 | case DSSCMD_IREAD64_CR: |
| 377 | case DSSCMD_IREAD64_CX: |
| 378 | case DSSCMD_INVALIDATE_DEK: |
| 379 | case DSSCMD_SET_KEK: |
| 380 | case DSSCMD_GET_KEK_ID: |
| 381 | case DSSCMD_GEN_XFER: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | type = LPFC_SOL_IOCB; |
| 383 | break; |
| 384 | case CMD_ABORT_XRI_CN: |
| 385 | case CMD_ABORT_XRI_CX: |
| 386 | case CMD_CLOSE_XRI_CN: |
| 387 | case CMD_CLOSE_XRI_CX: |
| 388 | case CMD_XRI_ABORTED_CX: |
| 389 | case CMD_ABORT_MXRI64_CN: |
| 390 | type = LPFC_ABORT_IOCB; |
| 391 | break; |
| 392 | case CMD_RCV_SEQUENCE_CX: |
| 393 | case CMD_RCV_ELS_REQ_CX: |
| 394 | case CMD_RCV_SEQUENCE64_CX: |
| 395 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 396 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 397 | case CMD_IOCB_RCV_SEQ64_CX: |
| 398 | case CMD_IOCB_RCV_ELS64_CX: |
| 399 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 400 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 401 | type = LPFC_UNSOL_IOCB; |
| 402 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 403 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 404 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 405 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 406 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 407 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 408 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 409 | case CMD_IOCB_RET_HBQE64_CN: |
| 410 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 411 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 412 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 413 | case CMD_IOCB_LOGENTRY_CN: |
| 414 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 415 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 416 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 417 | type = LPFC_UNKNOWN_IOCB; |
| 418 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 419 | default: |
| 420 | type = LPFC_UNKNOWN_IOCB; |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | return type; |
| 425 | } |
| 426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 428 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 429 | * @phba: Pointer to HBA context object. |
| 430 | * |
| 431 | * This function is called from SLI initialization code |
| 432 | * to configure every ring of the HBA's SLI interface. The |
| 433 | * caller is not required to hold any lock. This function issues |
| 434 | * a config_ring mailbox command for each ring. |
| 435 | * This function returns zero if successful else returns a negative |
| 436 | * error code. |
| 437 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 439 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | { |
| 441 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 442 | LPFC_MBOXQ_t *pmb; |
| 443 | MAILBOX_t *pmbox; |
| 444 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 446 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 447 | if (!pmb) |
| 448 | return -ENOMEM; |
| 449 | pmbox = &pmb->mb; |
| 450 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 452 | lpfc_config_ring(phba, i, pmb); |
| 453 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 454 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 456 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 457 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 458 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 459 | rc, pmbox->mbxCommand, |
| 460 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 462 | ret = -ENXIO; |
| 463 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 464 | } |
| 465 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 466 | mempool_free(pmb, phba->mbox_mem_pool); |
| 467 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 468 | } |
| 469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 470 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 471 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 472 | * @phba: Pointer to HBA context object. |
| 473 | * @pring: Pointer to driver SLI ring object. |
| 474 | * @piocb: Pointer to the driver iocb object. |
| 475 | * |
| 476 | * This function is called with hbalock held. The function adds the |
| 477 | * new iocb to txcmplq of the given ring. This function always returns |
| 478 | * 0. If this function is called for ELS ring, this function checks if |
| 479 | * there is a vport associated with the ELS command. This function also |
| 480 | * starts els_tmofunc timer if this is an ELS command. |
| 481 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 482 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 483 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 484 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 485 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | list_add_tail(&piocb->list, &pring->txcmplq); |
| 487 | pring->txcmplq_cnt++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 488 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 489 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 490 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 491 | if (!piocb->vport) |
| 492 | BUG(); |
| 493 | else |
| 494 | mod_timer(&piocb->vport->els_tmofunc, |
| 495 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 496 | } |
| 497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 499 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | } |
| 501 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 502 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 503 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 504 | * @phba: Pointer to HBA context object. |
| 505 | * @pring: Pointer to driver SLI ring object. |
| 506 | * |
| 507 | * This function is called with hbalock held to get next |
| 508 | * iocb in txq of the given ring. If there is any iocb in |
| 509 | * the txq, the function returns first iocb in the list after |
| 510 | * removing the iocb from the list, else it returns NULL. |
| 511 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 513 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | struct lpfc_iocbq *cmd_iocb; |
| 516 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 517 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 518 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 520 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | } |
| 522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 524 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 525 | * @phba: Pointer to HBA context object. |
| 526 | * @pring: Pointer to driver SLI ring object. |
| 527 | * |
| 528 | * This function is called with hbalock held and the caller must post the |
| 529 | * iocb without releasing the lock. If the caller releases the lock, |
| 530 | * iocb slot returned by the function is not guaranteed to be available. |
| 531 | * The function returns pointer to the next available iocb slot if there |
| 532 | * is available slot in the ring, else it returns NULL. |
| 533 | * If the get index of the ring is ahead of the put index, the function |
| 534 | * will post an error attention event to the worker thread to take the |
| 535 | * HBA to offline state. |
| 536 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | static IOCB_t * |
| 538 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 539 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 540 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 543 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 544 | pring->next_cmdidx = 0; |
| 545 | |
| 546 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 547 | |
| 548 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 549 | |
| 550 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 551 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 552 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 553 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 554 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 555 | pring->local_getidx, max_cmd_idx); |
| 556 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 557 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 558 | /* |
| 559 | * All error attention handlers are posted to |
| 560 | * worker thread |
| 561 | */ |
| 562 | phba->work_ha |= HA_ERATT; |
| 563 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 564 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 565 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 566 | |
| 567 | return NULL; |
| 568 | } |
| 569 | |
| 570 | if (pring->local_getidx == pring->next_cmdidx) |
| 571 | return NULL; |
| 572 | } |
| 573 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 574 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 | } |
| 576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 578 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 579 | * @phba: Pointer to HBA context object. |
| 580 | * @iocbq: Pointer to driver iocb object. |
| 581 | * |
| 582 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 583 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 584 | * array and assigns a new iotag. |
| 585 | * The function returns the allocated iotag if successful, else returns zero. |
| 586 | * Zero is not a valid iotag. |
| 587 | * The caller is not required to hold any lock. |
| 588 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 589 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 592 | struct lpfc_iocbq **new_arr; |
| 593 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 594 | size_t new_len; |
| 595 | struct lpfc_sli *psli = &phba->sli; |
| 596 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 597 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 598 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 599 | iotag = psli->last_iotag; |
| 600 | if(++iotag < psli->iocbq_lookup_len) { |
| 601 | psli->last_iotag = iotag; |
| 602 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 603 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 604 | iocbq->iotag = iotag; |
| 605 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 607 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 608 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 609 | spin_unlock_irq(&phba->hbalock); |
| 610 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 611 | GFP_KERNEL); |
| 612 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 613 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 614 | old_arr = psli->iocbq_lookup; |
| 615 | if (new_len <= psli->iocbq_lookup_len) { |
| 616 | /* highly unprobable case */ |
| 617 | kfree(new_arr); |
| 618 | iotag = psli->last_iotag; |
| 619 | if(++iotag < psli->iocbq_lookup_len) { |
| 620 | psli->last_iotag = iotag; |
| 621 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 622 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 623 | iocbq->iotag = iotag; |
| 624 | return iotag; |
| 625 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 626 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | if (psli->iocbq_lookup) |
| 630 | memcpy(new_arr, old_arr, |
| 631 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 632 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 633 | psli->iocbq_lookup = new_arr; |
| 634 | psli->iocbq_lookup_len = new_len; |
| 635 | psli->last_iotag = iotag; |
| 636 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 637 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 638 | iocbq->iotag = iotag; |
| 639 | kfree(old_arr); |
| 640 | return iotag; |
| 641 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 642 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 643 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 645 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 646 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 647 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 649 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 650 | } |
| 651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 653 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 654 | * @phba: Pointer to HBA context object. |
| 655 | * @pring: Pointer to driver SLI ring object. |
| 656 | * @iocb: Pointer to iocb slot in the ring. |
| 657 | * @nextiocb: Pointer to driver iocb object which need to be |
| 658 | * posted to firmware. |
| 659 | * |
| 660 | * This function is called with hbalock held to post a new iocb to |
| 661 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 662 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 663 | * a completion call back for this iocb else the function will free the |
| 664 | * iocb object. |
| 665 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | static void |
| 667 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 668 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 669 | { |
| 670 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 671 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 672 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 673 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 674 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 675 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 676 | if (pring->ringno == LPFC_ELS_RING) { |
| 677 | lpfc_debugfs_slow_ring_trc(phba, |
| 678 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 679 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 680 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 681 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 682 | } |
| 683 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 684 | /* |
| 685 | * Issue iocb command to adapter |
| 686 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 687 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | wmb(); |
| 689 | pring->stats.iocb_cmd++; |
| 690 | |
| 691 | /* |
| 692 | * If there is no completion routine to call, we can release the |
| 693 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 694 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 695 | */ |
| 696 | if (nextiocb->iocb_cmpl) |
| 697 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 698 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 699 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 700 | |
| 701 | /* |
| 702 | * Let the HBA know what IOCB slot will be the next one the |
| 703 | * driver will put a command into. |
| 704 | */ |
| 705 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 706 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 707 | } |
| 708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 709 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 710 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 711 | * @phba: Pointer to HBA context object. |
| 712 | * @pring: Pointer to driver SLI ring object. |
| 713 | * |
| 714 | * The caller is not required to hold any lock for calling this function. |
| 715 | * This function updates the chip attention bits for the ring to inform firmware |
| 716 | * that there are pending work to be done for this ring and requests an |
| 717 | * interrupt when there is space available in the ring. This function is |
| 718 | * called when the driver is unable to post more iocbs to the ring due |
| 719 | * to unavailability of space in the ring. |
| 720 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 722 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 723 | { |
| 724 | int ringno = pring->ringno; |
| 725 | |
| 726 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 727 | |
| 728 | wmb(); |
| 729 | |
| 730 | /* |
| 731 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 732 | * The HBA will tell us when an IOCB entry is available. |
| 733 | */ |
| 734 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 735 | readl(phba->CAregaddr); /* flush */ |
| 736 | |
| 737 | pring->stats.iocb_cmd_full++; |
| 738 | } |
| 739 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 740 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 741 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 742 | * @phba: Pointer to HBA context object. |
| 743 | * @pring: Pointer to driver SLI ring object. |
| 744 | * |
| 745 | * This function updates the chip attention register bit for the |
| 746 | * given ring to inform HBA that there is more work to be done |
| 747 | * in this ring. The caller is not required to hold any lock. |
| 748 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 750 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | { |
| 752 | int ringno = pring->ringno; |
| 753 | |
| 754 | /* |
| 755 | * Tell the HBA that there is work to do in this ring. |
| 756 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 757 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 758 | wmb(); |
| 759 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 760 | readl(phba->CAregaddr); /* flush */ |
| 761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | } |
| 763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 765 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 766 | * @phba: Pointer to HBA context object. |
| 767 | * @pring: Pointer to driver SLI ring object. |
| 768 | * |
| 769 | * This function is called with hbalock held to post pending iocbs |
| 770 | * in the txq to the firmware. This function is called when driver |
| 771 | * detects space available in the ring. |
| 772 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 773 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | { |
| 776 | IOCB_t *iocb; |
| 777 | struct lpfc_iocbq *nextiocb; |
| 778 | |
| 779 | /* |
| 780 | * Check to see if: |
| 781 | * (a) there is anything on the txq to send |
| 782 | * (b) link is up |
| 783 | * (c) link attention events can be processed (fcp ring only) |
| 784 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 785 | */ |
| 786 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 789 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | |
| 791 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 792 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 793 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 794 | |
| 795 | if (iocb) |
| 796 | lpfc_sli_update_ring(phba, pring); |
| 797 | else |
| 798 | lpfc_sli_update_full_ring(phba, pring); |
| 799 | } |
| 800 | |
| 801 | return; |
| 802 | } |
| 803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 805 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 806 | * @phba: Pointer to HBA context object. |
| 807 | * @hbqno: HBQ number. |
| 808 | * |
| 809 | * This function is called with hbalock held to get the next |
| 810 | * available slot for the given HBQ. If there is free slot |
| 811 | * available for the HBQ it will return pointer to the next available |
| 812 | * HBQ entry else it will return NULL. |
| 813 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 814 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 815 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 816 | { |
| 817 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 818 | |
| 819 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 820 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 821 | hbqp->next_hbqPutIdx = 0; |
| 822 | |
| 823 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 825 | uint32_t getidx = le32_to_cpu(raw_index); |
| 826 | |
| 827 | hbqp->local_hbqGetIdx = getidx; |
| 828 | |
| 829 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 830 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 831 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 832 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 833 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 834 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 835 | hbqp->entry_count); |
| 836 | |
| 837 | phba->link_state = LPFC_HBA_ERROR; |
| 838 | return NULL; |
| 839 | } |
| 840 | |
| 841 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 842 | return NULL; |
| 843 | } |
| 844 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 845 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 846 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 847 | } |
| 848 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 849 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 850 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 851 | * @phba: Pointer to HBA context object. |
| 852 | * |
| 853 | * This function is called with no lock held to free all the |
| 854 | * hbq buffers while uninitializing the SLI interface. It also |
| 855 | * frees the HBQ buffers returned by the firmware but not yet |
| 856 | * processed by the upper layers. |
| 857 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 858 | void |
| 859 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 860 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 861 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 862 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 863 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 864 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 865 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 866 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 867 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 868 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 869 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 870 | for (i = 0; i < hbq_count; ++i) { |
| 871 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 872 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 873 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 874 | list_del(&hbq_buf->dbuf.list); |
| 875 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 876 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 877 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 878 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 879 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 880 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 881 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 882 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 883 | list_del(&hbq_buf->dbuf.list); |
| 884 | if (hbq_buf->tag == -1) { |
| 885 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 886 | (phba, hbq_buf); |
| 887 | } else { |
| 888 | hbqno = hbq_buf->tag >> 16; |
| 889 | if (hbqno >= LPFC_MAX_HBQS) |
| 890 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 891 | (phba, hbq_buf); |
| 892 | else |
| 893 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 894 | hbq_buf); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | /* Mark the HBQs not in use */ |
| 899 | phba->hbq_in_use = 0; |
| 900 | spin_unlock_irqrestore(&phba->hbalock, flags); |
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_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 905 | * @phba: Pointer to HBA context object. |
| 906 | * @hbqno: HBQ number. |
| 907 | * @hbq_buf: Pointer to HBQ buffer. |
| 908 | * |
| 909 | * This function is called with the hbalock held to post a |
| 910 | * hbq buffer to the firmware. If the function finds an empty |
| 911 | * slot in the HBQ, it will post the buffer. The function will return |
| 912 | * pointer to the hbq entry if it successfully post the buffer |
| 913 | * else it will return NULL. |
| 914 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 915 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 916 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 917 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 918 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 919 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 924 | * @phba: Pointer to HBA context object. |
| 925 | * @hbqno: HBQ number. |
| 926 | * @hbq_buf: Pointer to HBQ buffer. |
| 927 | * |
| 928 | * This function is called with the hbalock held to post a hbq buffer to the |
| 929 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 930 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 931 | * it successfully post the buffer else it will return an error. |
| 932 | **/ |
| 933 | static int |
| 934 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 935 | struct hbq_dmabuf *hbq_buf) |
| 936 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 937 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 938 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 939 | |
| 940 | /* Get next HBQ entry slot to use */ |
| 941 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 942 | if (hbqe) { |
| 943 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 944 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 945 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 946 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 947 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 948 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 949 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 950 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 951 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 952 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 953 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 954 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 955 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 956 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 957 | return 0; |
| 958 | } else |
| 959 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 960 | } |
| 961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 962 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 964 | .rn = 1, |
| 965 | .entry_count = 200, |
| 966 | .mask_count = 0, |
| 967 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 968 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 969 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 970 | .init_count = 40, |
| 971 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 972 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 974 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 975 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 976 | .rn = 1, |
| 977 | .entry_count = 200, |
| 978 | .mask_count = 0, |
| 979 | .profile = 0, |
| 980 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 981 | .buffer_count = 0, |
| 982 | .init_count = 0, |
| 983 | .add_count = 5, |
| 984 | }; |
| 985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 986 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 987 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 989 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | }; |
| 991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 992 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 993 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 994 | * @phba: Pointer to HBA context object. |
| 995 | * @hbqno: HBQ number. |
| 996 | * @count: Number of HBQ buffers to be posted. |
| 997 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 998 | * This function is called with no lock held to post more hbq buffers to the |
| 999 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1000 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1001 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1002 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1003 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1004 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1005 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1006 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1007 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1008 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1009 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1010 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1011 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1012 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1013 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1014 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1015 | phba->hbqs[hbqno].buffer_count; |
| 1016 | if (!count) |
| 1017 | return 0; |
| 1018 | /* Allocate HBQ entries */ |
| 1019 | for (i = 0; i < count; i++) { |
| 1020 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1021 | if (!hbq_buffer) |
| 1022 | break; |
| 1023 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1024 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1025 | /* Check whether HBQ is still in use */ |
| 1026 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1027 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1028 | goto err; |
| 1029 | while (!list_empty(&hbq_buf_list)) { |
| 1030 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1031 | dbuf.list); |
| 1032 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1033 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1034 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1035 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1036 | posted++; |
| 1037 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1038 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1039 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1040 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1041 | return posted; |
| 1042 | err: |
| 1043 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1044 | while (!list_empty(&hbq_buf_list)) { |
| 1045 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1046 | dbuf.list); |
| 1047 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1048 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1049 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1053 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1054 | * @phba: Pointer to HBA context object. |
| 1055 | * @qno: HBQ number. |
| 1056 | * |
| 1057 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1058 | * is called with no lock held. The function returns the number of HBQ entries |
| 1059 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1060 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1061 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1062 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1063 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1064 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1065 | lpfc_hbq_defs[qno]->add_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1069 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1070 | * @phba: Pointer to HBA context object. |
| 1071 | * @qno: HBQ queue number. |
| 1072 | * |
| 1073 | * This function is called from SLI initialization code path with |
| 1074 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1075 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1076 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1077 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1078 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1079 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1080 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1081 | lpfc_hbq_defs[qno]->init_count)); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1082 | } |
| 1083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1084 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1085 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1086 | * @phba: Pointer to HBA context object. |
| 1087 | * @hbqno: HBQ number. |
| 1088 | * |
| 1089 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1090 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1091 | **/ |
| 1092 | static struct hbq_dmabuf * |
| 1093 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1094 | { |
| 1095 | struct lpfc_dmabuf *d_buf; |
| 1096 | |
| 1097 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1098 | if (!d_buf) |
| 1099 | return NULL; |
| 1100 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1101 | } |
| 1102 | |
| 1103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1104 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1105 | * @phba: Pointer to HBA context object. |
| 1106 | * @tag: Tag of the hbq buffer. |
| 1107 | * |
| 1108 | * This function is called with hbalock held. This function searches |
| 1109 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1110 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1111 | * it returns NULL. |
| 1112 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1113 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1114 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1115 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1116 | struct lpfc_dmabuf *d_buf; |
| 1117 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1118 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1119 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1120 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1121 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1122 | return NULL; |
| 1123 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1124 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1125 | 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] | 1126 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1127 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1128 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1129 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1130 | } |
| 1131 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1132 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1133 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1134 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1135 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1136 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1137 | } |
| 1138 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1139 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1140 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1141 | * @phba: Pointer to HBA context object. |
| 1142 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1143 | * |
| 1144 | * This function is called with hbalock. This function gives back |
| 1145 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1146 | * post the buffer, it will free the buffer. |
| 1147 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1148 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1149 | 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] | 1150 | { |
| 1151 | uint32_t hbqno; |
| 1152 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1153 | if (hbq_buffer) { |
| 1154 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1155 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1156 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1160 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1161 | * 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] | 1162 | * @mbxCommand: mailbox command code. |
| 1163 | * |
| 1164 | * This function is called by the mailbox event handler function to verify |
| 1165 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1166 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1167 | * and the mailbox event handler will take the HBA offline. |
| 1168 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | static int |
| 1170 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1171 | { |
| 1172 | uint8_t ret; |
| 1173 | |
| 1174 | switch (mbxCommand) { |
| 1175 | case MBX_LOAD_SM: |
| 1176 | case MBX_READ_NV: |
| 1177 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1178 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1179 | case MBX_RUN_BIU_DIAG: |
| 1180 | case MBX_INIT_LINK: |
| 1181 | case MBX_DOWN_LINK: |
| 1182 | case MBX_CONFIG_LINK: |
| 1183 | case MBX_CONFIG_RING: |
| 1184 | case MBX_RESET_RING: |
| 1185 | case MBX_READ_CONFIG: |
| 1186 | case MBX_READ_RCONFIG: |
| 1187 | case MBX_READ_SPARM: |
| 1188 | case MBX_READ_STATUS: |
| 1189 | case MBX_READ_RPI: |
| 1190 | case MBX_READ_XRI: |
| 1191 | case MBX_READ_REV: |
| 1192 | case MBX_READ_LNK_STAT: |
| 1193 | case MBX_REG_LOGIN: |
| 1194 | case MBX_UNREG_LOGIN: |
| 1195 | case MBX_READ_LA: |
| 1196 | case MBX_CLEAR_LA: |
| 1197 | case MBX_DUMP_MEMORY: |
| 1198 | case MBX_DUMP_CONTEXT: |
| 1199 | case MBX_RUN_DIAGS: |
| 1200 | case MBX_RESTART: |
| 1201 | case MBX_UPDATE_CFG: |
| 1202 | case MBX_DOWN_LOAD: |
| 1203 | case MBX_DEL_LD_ENTRY: |
| 1204 | case MBX_RUN_PROGRAM: |
| 1205 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1206 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1208 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1210 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | case MBX_LOAD_AREA: |
| 1212 | case MBX_RUN_BIU_DIAG64: |
| 1213 | case MBX_CONFIG_PORT: |
| 1214 | case MBX_READ_SPARM64: |
| 1215 | case MBX_READ_RPI64: |
| 1216 | case MBX_REG_LOGIN64: |
| 1217 | case MBX_READ_LA64: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1218 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | case MBX_SET_DEBUG: |
| 1220 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1221 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1222 | case MBX_REG_VPI: |
| 1223 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1224 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1225 | case MBX_PORT_CAPABILITIES: |
| 1226 | case MBX_PORT_IOV_CONTROL: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | ret = mbxCommand; |
| 1228 | break; |
| 1229 | default: |
| 1230 | ret = MBX_SHUTDOWN; |
| 1231 | break; |
| 1232 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1235 | |
| 1236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1237 | * 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] | 1238 | * @phba: Pointer to HBA context object. |
| 1239 | * @pmboxq: Pointer to mailbox command. |
| 1240 | * |
| 1241 | * This is completion handler function for mailbox commands issued from |
| 1242 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 1243 | * mailbox event handler function with no lock held. This function |
| 1244 | * will wake up thread waiting on the wait queue pointed by context1 |
| 1245 | * of the mailbox. |
| 1246 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1247 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1248 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | { |
| 1250 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1251 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1252 | |
| 1253 | /* |
| 1254 | * If pdone_q is empty, the driver thread gave up waiting and |
| 1255 | * continued running. |
| 1256 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1257 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1258 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 1260 | if (pdone_q) |
| 1261 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1262 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | return; |
| 1264 | } |
| 1265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1266 | |
| 1267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1268 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1269 | * @phba: Pointer to HBA context object. |
| 1270 | * @pmb: Pointer to mailbox object. |
| 1271 | * |
| 1272 | * This function is the default mailbox completion handler. It |
| 1273 | * frees the memory resources associated with the completed mailbox |
| 1274 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 1275 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 1276 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1278 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | { |
| 1280 | struct lpfc_dmabuf *mp; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1281 | uint16_t rpi; |
| 1282 | int rc; |
| 1283 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1285 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1286 | if (mp) { |
| 1287 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1288 | kfree(mp); |
| 1289 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1290 | |
| 1291 | /* |
| 1292 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 1293 | * is in re-discovery driver need to cleanup the RPI. |
| 1294 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1295 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
| 1296 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && |
| 1297 | !pmb->mb.mbxStatus) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1298 | |
| 1299 | rpi = pmb->mb.un.varWords[0]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
| 1301 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1302 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1303 | if (rc != MBX_NOT_FINISHED) |
| 1304 | return; |
| 1305 | } |
| 1306 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | return; |
| 1309 | } |
| 1310 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1312 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | * @phba: Pointer to HBA context object. |
| 1314 | * |
| 1315 | * This function is called with no lock held. This function processes all |
| 1316 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 1317 | * service routine processes mailbox completion interrupt and adds completed |
| 1318 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 1319 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 1320 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 1321 | * function returns the mailbox commands to the upper layer by calling the |
| 1322 | * completion handler function of each mailbox. |
| 1323 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1325 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1327 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1329 | int rc; |
| 1330 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | |
| 1332 | phba->sli.slistat.mbox_event++; |
| 1333 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1334 | /* Get all completed mailboxe buffers into the cmplq */ |
| 1335 | spin_lock_irq(&phba->hbalock); |
| 1336 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 1337 | spin_unlock_irq(&phba->hbalock); |
| 1338 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1340 | do { |
| 1341 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 1342 | if (pmb == NULL) |
| 1343 | break; |
| 1344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | pmbox = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1347 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 1348 | if (pmb->vport) { |
| 1349 | lpfc_debugfs_disc_trc(pmb->vport, |
| 1350 | LPFC_DISC_TRC_MBOX_VPORT, |
| 1351 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 1352 | (uint32_t)pmbox->mbxCommand, |
| 1353 | pmbox->un.varWords[0], |
| 1354 | pmbox->un.varWords[1]); |
| 1355 | } |
| 1356 | else { |
| 1357 | lpfc_debugfs_disc_trc(phba->pport, |
| 1358 | LPFC_DISC_TRC_MBOX, |
| 1359 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 1360 | (uint32_t)pmbox->mbxCommand, |
| 1361 | pmbox->un.varWords[0], |
| 1362 | pmbox->un.varWords[1]); |
| 1363 | } |
| 1364 | } |
| 1365 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1366 | /* |
| 1367 | * It is a fatal error if unknown mbox command completion. |
| 1368 | */ |
| 1369 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 1370 | MBX_SHUTDOWN) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | /* Unknow mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1372 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1373 | "(%d):0323 Unknown Mailbox command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1374 | "%x Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1375 | pmb->vport ? pmb->vport->vpi : 0, |
| 1376 | pmbox->mbxCommand); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | phba->work_hs = HS_FFER3; |
| 1379 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1380 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | } |
| 1382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | if (pmbox->mbxStatus) { |
| 1384 | phba->sli.slistat.mbox_stat_err++; |
| 1385 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 1386 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1387 | lpfc_printf_log(phba, KERN_INFO, |
| 1388 | LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1389 | "(%d):0305 Mbox cmd cmpl " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1390 | "error - RETRYing Data: x%x " |
| 1391 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1392 | pmb->vport ? pmb->vport->vpi :0, |
| 1393 | pmbox->mbxCommand, |
| 1394 | pmbox->mbxStatus, |
| 1395 | pmbox->un.varWords[0], |
| 1396 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | pmbox->mbxStatus = 0; |
| 1398 | pmbox->mbxOwner = OWN_HOST; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 1403 | if (rc == MBX_SUCCESS) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1404 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1409 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1410 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | "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] | 1412 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1413 | pmbox->mbxCommand, |
| 1414 | pmb->mbox_cmpl, |
| 1415 | *((uint32_t *) pmbox), |
| 1416 | pmbox->un.varWords[0], |
| 1417 | pmbox->un.varWords[1], |
| 1418 | pmbox->un.varWords[2], |
| 1419 | pmbox->un.varWords[3], |
| 1420 | pmbox->un.varWords[4], |
| 1421 | pmbox->un.varWords[5], |
| 1422 | pmbox->un.varWords[6], |
| 1423 | pmbox->un.varWords[7]); |
| 1424 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1425 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1427 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1428 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1432 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1433 | * @phba: Pointer to HBA context object. |
| 1434 | * @pring: Pointer to driver SLI ring object. |
| 1435 | * @tag: buffer tag. |
| 1436 | * |
| 1437 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 1438 | * is set in the tag the buffer is posted for a particular exchange, |
| 1439 | * the function will return the buffer without replacing the buffer. |
| 1440 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 1441 | * returns the buffer and also posts another buffer to the firmware. |
| 1442 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1443 | static struct lpfc_dmabuf * |
| 1444 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1445 | struct lpfc_sli_ring *pring, |
| 1446 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1447 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1448 | struct hbq_dmabuf *hbq_entry; |
| 1449 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1450 | if (tag & QUE_BUFTAG_BIT) |
| 1451 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 1452 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 1453 | if (!hbq_entry) |
| 1454 | return NULL; |
| 1455 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1456 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1457 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1458 | /** |
| 1459 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 1460 | * @phba: Pointer to HBA context object. |
| 1461 | * @pring: Pointer to driver SLI ring object. |
| 1462 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 1463 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 1464 | * @fch_type: the type for the first frame of the sequence. |
| 1465 | * |
| 1466 | * This function is called with no lock held. This function uses the r_ctl and |
| 1467 | * type of the received sequence to find the correct callback function to call |
| 1468 | * to process the sequence. |
| 1469 | **/ |
| 1470 | static int |
| 1471 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1472 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 1473 | uint32_t fch_type) |
| 1474 | { |
| 1475 | int i; |
| 1476 | |
| 1477 | /* unSolicited Responses */ |
| 1478 | if (pring->prt[0].profile) { |
| 1479 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 1480 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 1481 | saveq); |
| 1482 | return 1; |
| 1483 | } |
| 1484 | /* We must search, based on rctl / type |
| 1485 | for the right routine */ |
| 1486 | for (i = 0; i < pring->num_mask; i++) { |
| 1487 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 1488 | (pring->prt[i].type == fch_type)) { |
| 1489 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1490 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 1491 | (phba, pring, saveq); |
| 1492 | return 1; |
| 1493 | } |
| 1494 | } |
| 1495 | return 0; |
| 1496 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1497 | |
| 1498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1499 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1500 | * @phba: Pointer to HBA context object. |
| 1501 | * @pring: Pointer to driver SLI ring object. |
| 1502 | * @saveq: Pointer to the unsolicited iocb. |
| 1503 | * |
| 1504 | * This function is called with no lock held by the ring event handler |
| 1505 | * when there is an unsolicited iocb posted to the response ring by the |
| 1506 | * firmware. This function gets the buffer associated with the iocbs |
| 1507 | * and calls the event handler for the ring. This function handles both |
| 1508 | * qring buffers and hbq buffers. |
| 1509 | * When the function returns 1 the caller can free the iocb object otherwise |
| 1510 | * upper layer functions will free the iocb objects. |
| 1511 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | static int |
| 1513 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1514 | struct lpfc_iocbq *saveq) |
| 1515 | { |
| 1516 | IOCB_t * irsp; |
| 1517 | WORD5 * w5p; |
| 1518 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1519 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1520 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1521 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | |
| 1523 | match = 0; |
| 1524 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1525 | |
| 1526 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 1527 | if (pring->lpfc_sli_rcv_async_status) |
| 1528 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 1529 | else |
| 1530 | lpfc_printf_log(phba, |
| 1531 | KERN_WARNING, |
| 1532 | LOG_SLI, |
| 1533 | "0316 Ring %d handler: unexpected " |
| 1534 | "ASYNC_STATUS iocb received evt_code " |
| 1535 | "0x%x\n", |
| 1536 | pring->ringno, |
| 1537 | irsp->un.asyncstat.evt_code); |
| 1538 | return 1; |
| 1539 | } |
| 1540 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1541 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 1542 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 1543 | if (irsp->ulpBdeCount > 0) { |
| 1544 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1545 | irsp->un.ulpWord[3]); |
| 1546 | lpfc_in_buf_free(phba, dmzbuf); |
| 1547 | } |
| 1548 | |
| 1549 | if (irsp->ulpBdeCount > 1) { |
| 1550 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1551 | irsp->unsli3.sli3Words[3]); |
| 1552 | lpfc_in_buf_free(phba, dmzbuf); |
| 1553 | } |
| 1554 | |
| 1555 | if (irsp->ulpBdeCount > 2) { |
| 1556 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 1557 | irsp->unsli3.sli3Words[7]); |
| 1558 | lpfc_in_buf_free(phba, dmzbuf); |
| 1559 | } |
| 1560 | |
| 1561 | return 1; |
| 1562 | } |
| 1563 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1564 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1565 | if (irsp->ulpBdeCount != 0) { |
| 1566 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1567 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1568 | if (!saveq->context2) |
| 1569 | lpfc_printf_log(phba, |
| 1570 | KERN_ERR, |
| 1571 | LOG_SLI, |
| 1572 | "0341 Ring %d Cannot find buffer for " |
| 1573 | "an unsolicited iocb. tag 0x%x\n", |
| 1574 | pring->ringno, |
| 1575 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1576 | } |
| 1577 | if (irsp->ulpBdeCount == 2) { |
| 1578 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1579 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1580 | if (!saveq->context3) |
| 1581 | lpfc_printf_log(phba, |
| 1582 | KERN_ERR, |
| 1583 | LOG_SLI, |
| 1584 | "0342 Ring %d Cannot find buffer for an" |
| 1585 | " unsolicited iocb. tag 0x%x\n", |
| 1586 | pring->ringno, |
| 1587 | irsp->unsli3.sli3Words[7]); |
| 1588 | } |
| 1589 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1590 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1591 | if (irsp->ulpBdeCount != 0) { |
| 1592 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 1593 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1594 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1595 | lpfc_printf_log(phba, |
| 1596 | KERN_ERR, |
| 1597 | LOG_SLI, |
| 1598 | "0343 Ring %d Cannot find " |
| 1599 | "buffer for an unsolicited iocb" |
| 1600 | ". tag 0x%x\n", pring->ringno, |
| 1601 | irsp->un.ulpWord[3]); |
| 1602 | } |
| 1603 | if (irsp->ulpBdeCount == 2) { |
| 1604 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 1605 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1606 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 1607 | lpfc_printf_log(phba, |
| 1608 | KERN_ERR, |
| 1609 | LOG_SLI, |
| 1610 | "0344 Ring %d Cannot find " |
| 1611 | "buffer for an unsolicited " |
| 1612 | "iocb. tag 0x%x\n", |
| 1613 | pring->ringno, |
| 1614 | irsp->unsli3.sli3Words[7]); |
| 1615 | } |
| 1616 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1617 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 1618 | if (irsp->ulpBdeCount != 0 && |
| 1619 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 1620 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 1621 | int found = 0; |
| 1622 | |
| 1623 | /* search continue save q for same XRI */ |
| 1624 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
| 1625 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { |
| 1626 | list_add_tail(&saveq->list, &iocbq->list); |
| 1627 | found = 1; |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | if (!found) |
| 1632 | list_add_tail(&saveq->clist, |
| 1633 | &pring->iocb_continue_saveq); |
| 1634 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 1635 | list_del_init(&iocbq->clist); |
| 1636 | saveq = iocbq; |
| 1637 | irsp = &(saveq->iocb); |
| 1638 | } else |
| 1639 | return 0; |
| 1640 | } |
| 1641 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 1642 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 1643 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
| 1644 | Rctl = FC_ELS_REQ; |
| 1645 | Type = FC_ELS_DATA; |
| 1646 | } else { |
| 1647 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 1648 | Rctl = w5p->hcsw.Rctl; |
| 1649 | Type = w5p->hcsw.Type; |
| 1650 | |
| 1651 | /* Firmware Workaround */ |
| 1652 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 1653 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 1654 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 1655 | Rctl = FC_ELS_REQ; |
| 1656 | Type = FC_ELS_DATA; |
| 1657 | w5p->hcsw.Rctl = Rctl; |
| 1658 | w5p->hcsw.Type = Type; |
| 1659 | } |
| 1660 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1661 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1662 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1663 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1664 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1665 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1666 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1667 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1668 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1669 | } |
| 1670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1672 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1673 | * @phba: Pointer to HBA context object. |
| 1674 | * @pring: Pointer to driver SLI ring object. |
| 1675 | * @prspiocb: Pointer to response iocb object. |
| 1676 | * |
| 1677 | * This function looks up the iocb_lookup table to get the command iocb |
| 1678 | * corresponding to the given response iocb using the iotag of the |
| 1679 | * response iocb. This function is called with the hbalock held. |
| 1680 | * This function returns the command iocb object if it finds the command |
| 1681 | * iocb else returns NULL. |
| 1682 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1683 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1684 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 1685 | struct lpfc_sli_ring *pring, |
| 1686 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 1689 | uint16_t iotag; |
| 1690 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1691 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1693 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1694 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1695 | list_del_init(&cmd_iocb->list); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1696 | pring->txcmplq_cnt--; |
| 1697 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | } |
| 1699 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1701 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1702 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1703 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1704 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | return NULL; |
| 1706 | } |
| 1707 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1708 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1709 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 1710 | * @phba: Pointer to HBA context object. |
| 1711 | * @pring: Pointer to driver SLI ring object. |
| 1712 | * @iotag: IOCB tag. |
| 1713 | * |
| 1714 | * This function looks up the iocb_lookup table to get the command iocb |
| 1715 | * corresponding to the given iotag. This function is called with the |
| 1716 | * hbalock held. |
| 1717 | * This function returns the command iocb object if it finds the command |
| 1718 | * iocb else returns NULL. |
| 1719 | **/ |
| 1720 | static struct lpfc_iocbq * |
| 1721 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 1722 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 1723 | { |
| 1724 | struct lpfc_iocbq *cmd_iocb; |
| 1725 | |
| 1726 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 1727 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
| 1728 | list_del_init(&cmd_iocb->list); |
| 1729 | pring->txcmplq_cnt--; |
| 1730 | return cmd_iocb; |
| 1731 | } |
| 1732 | |
| 1733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 1734 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 1735 | iotag, phba->sli.last_iotag); |
| 1736 | return NULL; |
| 1737 | } |
| 1738 | |
| 1739 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1740 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1741 | * @phba: Pointer to HBA context object. |
| 1742 | * @pring: Pointer to driver SLI ring object. |
| 1743 | * @saveq: Pointer to the response iocb to be processed. |
| 1744 | * |
| 1745 | * This function is called by the ring event handler for non-fcp |
| 1746 | * rings when there is a new response iocb in the response ring. |
| 1747 | * The caller is not required to hold any locks. This function |
| 1748 | * gets the command iocb associated with the response iocb and |
| 1749 | * calls the completion handler for the command iocb. If there |
| 1750 | * is no completion handler, the function will free the resources |
| 1751 | * associated with command iocb. If the response iocb is for |
| 1752 | * an already aborted command iocb, the status of the completion |
| 1753 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 1754 | * This function always returns 1. |
| 1755 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | struct lpfc_iocbq *saveq) |
| 1759 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | int rc = 1; |
| 1762 | unsigned long iflag; |
| 1763 | |
| 1764 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1765 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1766 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1767 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1768 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | if (cmdiocbp) { |
| 1770 | if (cmdiocbp->iocb_cmpl) { |
| 1771 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1772 | * If an ELS command failed send an event to mgmt |
| 1773 | * application. |
| 1774 | */ |
| 1775 | if (saveq->iocb.ulpStatus && |
| 1776 | (pring->ringno == LPFC_ELS_RING) && |
| 1777 | (cmdiocbp->iocb.ulpCommand == |
| 1778 | CMD_ELS_REQUEST64_CR)) |
| 1779 | lpfc_send_els_failure_event(phba, |
| 1780 | cmdiocbp, saveq); |
| 1781 | |
| 1782 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | * Post all ELS completions to the worker thread. |
| 1784 | * All other are passed to the completion callback. |
| 1785 | */ |
| 1786 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1787 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 1788 | cmdiocbp->iocb_flag &= |
| 1789 | ~LPFC_DRIVER_ABORTED; |
| 1790 | saveq->iocb.ulpStatus = |
| 1791 | IOSTAT_LOCAL_REJECT; |
| 1792 | saveq->iocb.un.ulpWord[4] = |
| 1793 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1794 | |
| 1795 | /* Firmware could still be in progress |
| 1796 | * of DMAing payload, so don't free data |
| 1797 | * buffer till after a hbeat. |
| 1798 | */ |
| 1799 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1800 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1802 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1803 | } else |
| 1804 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1805 | } else { |
| 1806 | /* |
| 1807 | * Unknown initiating command based on the response iotag. |
| 1808 | * This could be the case on the ELS ring because of |
| 1809 | * lpfc_els_abort(). |
| 1810 | */ |
| 1811 | if (pring->ringno != LPFC_ELS_RING) { |
| 1812 | /* |
| 1813 | * Ring <ringno> handler: unexpected completion IoTag |
| 1814 | * <IoTag> |
| 1815 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1816 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1817 | "0322 Ring %d handler: " |
| 1818 | "unexpected completion IoTag x%x " |
| 1819 | "Data: x%x x%x x%x x%x\n", |
| 1820 | pring->ringno, |
| 1821 | saveq->iocb.ulpIoTag, |
| 1822 | saveq->iocb.ulpStatus, |
| 1823 | saveq->iocb.un.ulpWord[4], |
| 1824 | saveq->iocb.ulpCommand, |
| 1825 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | } |
| 1827 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 1828 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | return rc; |
| 1830 | } |
| 1831 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1832 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1833 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1834 | * @phba: Pointer to HBA context object. |
| 1835 | * @pring: Pointer to driver SLI ring object. |
| 1836 | * |
| 1837 | * This function is called from the iocb ring event handlers when |
| 1838 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 1839 | * an error attention condition to the worker thread and the worker |
| 1840 | * thread will transition the HBA to offline state. |
| 1841 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1842 | static void |
| 1843 | 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] | 1844 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1845 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1846 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1847 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1848 | * rsp ring <portRspMax> |
| 1849 | */ |
| 1850 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1851 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1852 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1853 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1854 | pring->numRiocb); |
| 1855 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1857 | |
| 1858 | /* |
| 1859 | * All error attention handlers are posted to |
| 1860 | * worker thread |
| 1861 | */ |
| 1862 | phba->work_ha |= HA_ERATT; |
| 1863 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1864 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1865 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1866 | |
| 1867 | return; |
| 1868 | } |
| 1869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1871 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1872 | * @ptr: Pointer to address of HBA context object. |
| 1873 | * |
| 1874 | * This function is invoked by the Error Attention polling timer when the |
| 1875 | * timer times out. It will check the SLI Error Attention register for |
| 1876 | * possible attention events. If so, it will post an Error Attention event |
| 1877 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 1878 | * Error Attention polling timer for the next poll. |
| 1879 | **/ |
| 1880 | void lpfc_poll_eratt(unsigned long ptr) |
| 1881 | { |
| 1882 | struct lpfc_hba *phba; |
| 1883 | uint32_t eratt = 0; |
| 1884 | |
| 1885 | phba = (struct lpfc_hba *)ptr; |
| 1886 | |
| 1887 | /* Check chip HA register for error event */ |
| 1888 | eratt = lpfc_sli_check_eratt(phba); |
| 1889 | |
| 1890 | if (eratt) |
| 1891 | /* Tell the worker thread there is work to do */ |
| 1892 | lpfc_worker_wake_up(phba); |
| 1893 | else |
| 1894 | /* Restart the timer for next eratt poll */ |
| 1895 | mod_timer(&phba->eratt_poll, jiffies + |
| 1896 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 1897 | return; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1901 | * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1902 | * @phba: Pointer to HBA context object. |
| 1903 | * |
| 1904 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, |
| 1905 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING |
| 1906 | * is enabled. |
| 1907 | * |
| 1908 | * The caller does not hold any lock. |
| 1909 | * The function processes each response iocb in the response ring until it |
| 1910 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 1911 | * LE bit set. The function will call the completion handler of the command iocb |
| 1912 | * if the response iocb indicates a completion for a command iocb or it is |
| 1913 | * an abort completion. |
| 1914 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1916 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | struct lpfc_sli *psli = &phba->sli; |
| 1918 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1919 | IOCB_t *irsp = NULL; |
| 1920 | IOCB_t *entry = NULL; |
| 1921 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 1922 | struct lpfc_iocbq rspiocbq; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1923 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1924 | uint32_t status; |
| 1925 | uint32_t portRspPut, portRspMax; |
| 1926 | int type; |
| 1927 | uint32_t rsp_cmpl = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1928 | uint32_t ha_copy; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1929 | unsigned long iflags; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1930 | |
| 1931 | pring->stats.iocb_event++; |
| 1932 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1933 | /* |
| 1934 | * The next available response entry should never exceed the maximum |
| 1935 | * entries. If it does, treat it as an adapter hardware error. |
| 1936 | */ |
| 1937 | portRspMax = pring->numRiocb; |
| 1938 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 1939 | if (unlikely(portRspPut >= portRspMax)) { |
| 1940 | lpfc_sli_rsp_pointers_error(phba, pring); |
| 1941 | return; |
| 1942 | } |
| 1943 | |
| 1944 | rmb(); |
| 1945 | while (pring->rspidx != portRspPut) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1946 | entry = lpfc_resp_iocb(phba, pring); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1947 | if (++pring->rspidx >= portRspMax) |
| 1948 | pring->rspidx = 0; |
| 1949 | |
| 1950 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 1951 | (uint32_t *) &rspiocbq.iocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1952 | phba->iocb_rsp_size); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1953 | irsp = &rspiocbq.iocb; |
| 1954 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 1955 | pring->stats.iocb_rsp++; |
| 1956 | rsp_cmpl++; |
| 1957 | |
| 1958 | if (unlikely(irsp->ulpStatus)) { |
| 1959 | /* Rsp ring <ringno> error: IOCB */ |
| 1960 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1961 | "0326 Rsp Ring %d error: IOCB Data: " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1962 | "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] | 1963 | pring->ringno, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1964 | irsp->un.ulpWord[0], |
| 1965 | irsp->un.ulpWord[1], |
| 1966 | irsp->un.ulpWord[2], |
| 1967 | irsp->un.ulpWord[3], |
| 1968 | irsp->un.ulpWord[4], |
| 1969 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1970 | *(uint32_t *)&irsp->un1, |
| 1971 | *((uint32_t *)&irsp->un1 + 1)); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | switch (type) { |
| 1975 | case LPFC_ABORT_IOCB: |
| 1976 | case LPFC_SOL_IOCB: |
| 1977 | /* |
| 1978 | * Idle exchange closed via ABTS from port. No iocb |
| 1979 | * resources need to be recovered. |
| 1980 | */ |
| 1981 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1982 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1983 | "0314 IOCB cmd 0x%x " |
| 1984 | "processed. Skipping " |
| 1985 | "completion", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 1986 | irsp->ulpCommand); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1987 | break; |
| 1988 | } |
| 1989 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1990 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1991 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 1992 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1994 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
| 1995 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 1996 | &rspiocbq); |
| 1997 | } |
| 1998 | break; |
| 1999 | default: |
| 2000 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2001 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2002 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2003 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2004 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2005 | dev_warn(&((phba->pcidev)->dev), |
| 2006 | "lpfc%d: %s\n", |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2007 | phba->brd_no, adaptermsg); |
| 2008 | } else { |
| 2009 | /* Unknown IOCB command */ |
| 2010 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2011 | "0321 Unknown IOCB command " |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2012 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2013 | type, irsp->ulpCommand, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2014 | irsp->ulpStatus, |
| 2015 | irsp->ulpIoTag, |
| 2016 | irsp->ulpContext); |
| 2017 | } |
| 2018 | break; |
| 2019 | } |
| 2020 | |
| 2021 | /* |
| 2022 | * The response IOCB has been processed. Update the ring |
| 2023 | * pointer in SLIM. If the port response put pointer has not |
| 2024 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2025 | * response put pointer. |
| 2026 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2027 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2028 | |
| 2029 | if (pring->rspidx == portRspPut) |
| 2030 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2031 | } |
| 2032 | |
| 2033 | ha_copy = readl(phba->HAregaddr); |
| 2034 | ha_copy >>= (LPFC_FCP_RING * 4); |
| 2035 | |
| 2036 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2037 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2038 | pring->stats.iocb_rsp_full++; |
| 2039 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); |
| 2040 | writel(status, phba->CAregaddr); |
| 2041 | readl(phba->CAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2043 | } |
| 2044 | if ((ha_copy & HA_R0CE_RSP) && |
| 2045 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2047 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2048 | pring->stats.iocb_cmd_empty++; |
| 2049 | |
| 2050 | /* Force update of the local copy of cmdGetInx */ |
| 2051 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2052 | lpfc_sli_resume_iocb(phba, pring); |
| 2053 | |
| 2054 | if ((pring->lpfc_sli_cmd_available)) |
| 2055 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2057 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | return; |
| 2061 | } |
| 2062 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2064 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2065 | * @phba: Pointer to HBA context object. |
| 2066 | * @pring: Pointer to driver SLI ring object. |
| 2067 | * @mask: Host attention register mask for this ring. |
| 2068 | * |
| 2069 | * This function is called from the interrupt context when there is a ring |
| 2070 | * event for the fcp ring. The caller does not hold any lock. |
| 2071 | * The function processes each response iocb in the response ring until it |
| 2072 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with |
| 2073 | * LE bit set. The function will call the completion handler of the command iocb |
| 2074 | * if the response iocb indicates a completion for a command iocb or it is |
| 2075 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2076 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2078 | * to check it explicitly. This function always returns 1. |
| 2079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2082 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2084 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2086 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2088 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | uint32_t status; |
| 2090 | uint32_t portRspPut, portRspMax; |
| 2091 | int rc = 1; |
| 2092 | lpfc_iocb_type type; |
| 2093 | unsigned long iflag; |
| 2094 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | pring->stats.iocb_event++; |
| 2098 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | /* |
| 2100 | * The next available response entry should never exceed the maximum |
| 2101 | * entries. If it does, treat it as an adapter hardware error. |
| 2102 | */ |
| 2103 | portRspMax = pring->numRiocb; |
| 2104 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2105 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2106 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | return 1; |
| 2109 | } |
| 2110 | |
| 2111 | rmb(); |
| 2112 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2113 | /* |
| 2114 | * Fetch an entry off the ring and copy it into a local data |
| 2115 | * structure. The copy involves a byte-swap since the |
| 2116 | * network byte order and pci byte orders are different. |
| 2117 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2118 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2119 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2120 | |
| 2121 | if (++pring->rspidx >= portRspMax) |
| 2122 | pring->rspidx = 0; |
| 2123 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2124 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2125 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2126 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2127 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2128 | irsp = &rspiocbq.iocb; |
| 2129 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2131 | pring->stats.iocb_rsp++; |
| 2132 | rsp_cmpl++; |
| 2133 | |
| 2134 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2135 | /* |
| 2136 | * If resource errors reported from HBA, reduce |
| 2137 | * queuedepths of the SCSI device. |
| 2138 | */ |
| 2139 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2140 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2141 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2142 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2143 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2144 | } |
| 2145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | /* Rsp ring <ringno> error: IOCB */ |
| 2147 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2148 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2149 | "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] | 2150 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2151 | irsp->un.ulpWord[0], |
| 2152 | irsp->un.ulpWord[1], |
| 2153 | irsp->un.ulpWord[2], |
| 2154 | irsp->un.ulpWord[3], |
| 2155 | irsp->un.ulpWord[4], |
| 2156 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2157 | *(uint32_t *)&irsp->un1, |
| 2158 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | switch (type) { |
| 2162 | case LPFC_ABORT_IOCB: |
| 2163 | case LPFC_SOL_IOCB: |
| 2164 | /* |
| 2165 | * Idle exchange closed via ABTS from port. No iocb |
| 2166 | * resources need to be recovered. |
| 2167 | */ |
| 2168 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2169 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2170 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2171 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2172 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2173 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | break; |
| 2175 | } |
| 2176 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2177 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2178 | &rspiocbq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2180 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
| 2181 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2182 | &rspiocbq); |
| 2183 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2184 | spin_unlock_irqrestore(&phba->hbalock, |
| 2185 | iflag); |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2186 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2187 | &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | spin_lock_irqsave(&phba->hbalock, |
Jamie Wellnitz | b808608 | 2006-02-28 22:33:12 -0500 | [diff] [blame] | 2189 | iflag); |
| 2190 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | } |
| 2192 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2193 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2194 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2195 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2197 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | default: |
| 2199 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2200 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2201 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2202 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2203 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2204 | dev_warn(&((phba->pcidev)->dev), |
| 2205 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | phba->brd_no, adaptermsg); |
| 2207 | } else { |
| 2208 | /* Unknown IOCB command */ |
| 2209 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2210 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2211 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2212 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2213 | irsp->ulpStatus, |
| 2214 | irsp->ulpIoTag, |
| 2215 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | } |
| 2217 | break; |
| 2218 | } |
| 2219 | |
| 2220 | /* |
| 2221 | * The response IOCB has been processed. Update the ring |
| 2222 | * pointer in SLIM. If the port response put pointer has not |
| 2223 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2224 | * response put pointer. |
| 2225 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2226 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 | |
| 2228 | if (pring->rspidx == portRspPut) |
| 2229 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2230 | } |
| 2231 | |
| 2232 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 2233 | pring->stats.iocb_rsp_full++; |
| 2234 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2235 | writel(status, phba->CAregaddr); |
| 2236 | readl(phba->CAregaddr); |
| 2237 | } |
| 2238 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2239 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2240 | pring->stats.iocb_cmd_empty++; |
| 2241 | |
| 2242 | /* Force update of the local copy of cmdGetInx */ |
| 2243 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2244 | lpfc_sli_resume_iocb(phba, pring); |
| 2245 | |
| 2246 | if ((pring->lpfc_sli_cmd_available)) |
| 2247 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2248 | |
| 2249 | } |
| 2250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | return rc; |
| 2253 | } |
| 2254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2255 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2256 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 2257 | * @phba: Pointer to HBA context object. |
| 2258 | * @pring: Pointer to driver SLI ring object. |
| 2259 | * @rspiocbp: Pointer to driver response IOCB object. |
| 2260 | * |
| 2261 | * This function is called from the worker thread when there is a slow-path |
| 2262 | * response IOCB to process. This function chains all the response iocbs until |
| 2263 | * seeing the iocb with the LE bit set. The function will call |
| 2264 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 2265 | * completion of a command iocb. The function will call the |
| 2266 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 2267 | * The function frees the resources or calls the completion handler if this |
| 2268 | * iocb is an abort completion. The function returns NULL when the response |
| 2269 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 2270 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 2271 | * response iocb passed in. |
| 2272 | **/ |
| 2273 | static struct lpfc_iocbq * |
| 2274 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2275 | struct lpfc_iocbq *rspiocbp) |
| 2276 | { |
| 2277 | struct lpfc_iocbq *saveq; |
| 2278 | struct lpfc_iocbq *cmdiocbp; |
| 2279 | struct lpfc_iocbq *next_iocb; |
| 2280 | IOCB_t *irsp = NULL; |
| 2281 | uint32_t free_saveq; |
| 2282 | uint8_t iocb_cmd_type; |
| 2283 | lpfc_iocb_type type; |
| 2284 | unsigned long iflag; |
| 2285 | int rc; |
| 2286 | |
| 2287 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2288 | /* First add the response iocb to the countinueq list */ |
| 2289 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 2290 | pring->iocb_continueq_cnt++; |
| 2291 | |
| 2292 | /* Now, determine whetehr the list is completed for processing */ |
| 2293 | irsp = &rspiocbp->iocb; |
| 2294 | if (irsp->ulpLe) { |
| 2295 | /* |
| 2296 | * By default, the driver expects to free all resources |
| 2297 | * associated with this iocb completion. |
| 2298 | */ |
| 2299 | free_saveq = 1; |
| 2300 | saveq = list_get_first(&pring->iocb_continueq, |
| 2301 | struct lpfc_iocbq, list); |
| 2302 | irsp = &(saveq->iocb); |
| 2303 | list_del_init(&pring->iocb_continueq); |
| 2304 | pring->iocb_continueq_cnt = 0; |
| 2305 | |
| 2306 | pring->stats.iocb_rsp++; |
| 2307 | |
| 2308 | /* |
| 2309 | * If resource errors reported from HBA, reduce |
| 2310 | * queuedepths of the SCSI device. |
| 2311 | */ |
| 2312 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2313 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2314 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2315 | phba->lpfc_rampdown_queue_depth(phba); |
| 2316 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2317 | } |
| 2318 | |
| 2319 | if (irsp->ulpStatus) { |
| 2320 | /* Rsp ring <ringno> error: IOCB */ |
| 2321 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 2322 | "0328 Rsp Ring %d error: " |
| 2323 | "IOCB Data: " |
| 2324 | "x%x x%x x%x x%x " |
| 2325 | "x%x x%x x%x x%x " |
| 2326 | "x%x x%x x%x x%x " |
| 2327 | "x%x x%x x%x x%x\n", |
| 2328 | pring->ringno, |
| 2329 | irsp->un.ulpWord[0], |
| 2330 | irsp->un.ulpWord[1], |
| 2331 | irsp->un.ulpWord[2], |
| 2332 | irsp->un.ulpWord[3], |
| 2333 | irsp->un.ulpWord[4], |
| 2334 | irsp->un.ulpWord[5], |
| 2335 | *(((uint32_t *) irsp) + 6), |
| 2336 | *(((uint32_t *) irsp) + 7), |
| 2337 | *(((uint32_t *) irsp) + 8), |
| 2338 | *(((uint32_t *) irsp) + 9), |
| 2339 | *(((uint32_t *) irsp) + 10), |
| 2340 | *(((uint32_t *) irsp) + 11), |
| 2341 | *(((uint32_t *) irsp) + 12), |
| 2342 | *(((uint32_t *) irsp) + 13), |
| 2343 | *(((uint32_t *) irsp) + 14), |
| 2344 | *(((uint32_t *) irsp) + 15)); |
| 2345 | } |
| 2346 | |
| 2347 | /* |
| 2348 | * Fetch the IOCB command type and call the correct completion |
| 2349 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 2350 | * get freed back to the lpfc_iocb_list by the discovery |
| 2351 | * kernel thread. |
| 2352 | */ |
| 2353 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 2354 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 2355 | switch (type) { |
| 2356 | case LPFC_SOL_IOCB: |
| 2357 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2358 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 2359 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2360 | break; |
| 2361 | |
| 2362 | case LPFC_UNSOL_IOCB: |
| 2363 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2364 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 2365 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2366 | if (!rc) |
| 2367 | free_saveq = 0; |
| 2368 | break; |
| 2369 | |
| 2370 | case LPFC_ABORT_IOCB: |
| 2371 | cmdiocbp = NULL; |
| 2372 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 2373 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 2374 | saveq); |
| 2375 | if (cmdiocbp) { |
| 2376 | /* Call the specified completion routine */ |
| 2377 | if (cmdiocbp->iocb_cmpl) { |
| 2378 | spin_unlock_irqrestore(&phba->hbalock, |
| 2379 | iflag); |
| 2380 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 2381 | saveq); |
| 2382 | spin_lock_irqsave(&phba->hbalock, |
| 2383 | iflag); |
| 2384 | } else |
| 2385 | __lpfc_sli_release_iocbq(phba, |
| 2386 | cmdiocbp); |
| 2387 | } |
| 2388 | break; |
| 2389 | |
| 2390 | case LPFC_UNKNOWN_IOCB: |
| 2391 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2392 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2393 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2394 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 2395 | MAX_MSG_DATA); |
| 2396 | dev_warn(&((phba->pcidev)->dev), |
| 2397 | "lpfc%d: %s\n", |
| 2398 | phba->brd_no, adaptermsg); |
| 2399 | } else { |
| 2400 | /* Unknown IOCB command */ |
| 2401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2402 | "0335 Unknown IOCB " |
| 2403 | "command Data: x%x " |
| 2404 | "x%x x%x x%x\n", |
| 2405 | irsp->ulpCommand, |
| 2406 | irsp->ulpStatus, |
| 2407 | irsp->ulpIoTag, |
| 2408 | irsp->ulpContext); |
| 2409 | } |
| 2410 | break; |
| 2411 | } |
| 2412 | |
| 2413 | if (free_saveq) { |
| 2414 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 2415 | &saveq->list, list) { |
| 2416 | list_del(&rspiocbp->list); |
| 2417 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 2418 | } |
| 2419 | __lpfc_sli_release_iocbq(phba, saveq); |
| 2420 | } |
| 2421 | rspiocbp = NULL; |
| 2422 | } |
| 2423 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2424 | return rspiocbp; |
| 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2429 | * @phba: Pointer to HBA context object. |
| 2430 | * @pring: Pointer to driver SLI ring object. |
| 2431 | * @mask: Host attention register mask for this ring. |
| 2432 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2433 | * This routine wraps the actual slow_ring event process routine from the |
| 2434 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2435 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2436 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2437 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 2438 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2440 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 2441 | } |
| 2442 | |
| 2443 | /** |
| 2444 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 2445 | * @phba: Pointer to HBA context object. |
| 2446 | * @pring: Pointer to driver SLI ring object. |
| 2447 | * @mask: Host attention register mask for this ring. |
| 2448 | * |
| 2449 | * This function is called from the worker thread when there is a ring event |
| 2450 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 2451 | * remove each response iocb in the response ring and calls the handle |
| 2452 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 2453 | **/ |
| 2454 | static void |
| 2455 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 2456 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 2457 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2458 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | IOCB_t *entry; |
| 2460 | IOCB_t *irsp = NULL; |
| 2461 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2464 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2466 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | pring->stats.iocb_event++; |
| 2469 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2470 | /* |
| 2471 | * The next available response entry should never exceed the maximum |
| 2472 | * entries. If it does, treat it as an adapter hardware error. |
| 2473 | */ |
| 2474 | portRspMax = pring->numRiocb; |
| 2475 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2476 | if (portRspPut >= portRspMax) { |
| 2477 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2478 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | * rsp ring <portRspMax> |
| 2480 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2481 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2482 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2483 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2484 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2486 | phba->link_state = LPFC_HBA_ERROR; |
| 2487 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | |
| 2489 | phba->work_hs = HS_FFER3; |
| 2490 | lpfc_handle_eratt(phba); |
| 2491 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2492 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | while (pring->rspidx != portRspPut) { |
| 2497 | /* |
| 2498 | * Build a completion list and call the appropriate handler. |
| 2499 | * The process is to get the next available response iocb, get |
| 2500 | * a free iocb from the list, copy the response data into the |
| 2501 | * free iocb, insert to the continuation list, and update the |
| 2502 | * next response index to slim. This process makes response |
| 2503 | * iocb's in the ring available to DMA as fast as possible but |
| 2504 | * pays a penalty for a copy operation. Since the iocb is |
| 2505 | * only 32 bytes, this penalty is considered small relative to |
| 2506 | * the PCI reads for register values and a slim write. When |
| 2507 | * the ulpLe field is set, the entire Command has been |
| 2508 | * received. |
| 2509 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2510 | entry = lpfc_resp_iocb(phba, pring); |
| 2511 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2512 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2513 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | if (rspiocbp == NULL) { |
| 2515 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2516 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | break; |
| 2518 | } |
| 2519 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2520 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 2521 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | irsp = &rspiocbp->iocb; |
| 2523 | |
| 2524 | if (++pring->rspidx >= portRspMax) |
| 2525 | pring->rspidx = 0; |
| 2526 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2527 | if (pring->ringno == LPFC_ELS_RING) { |
| 2528 | lpfc_debugfs_slow_ring_trc(phba, |
| 2529 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 2530 | *(((uint32_t *) irsp) + 4), |
| 2531 | *(((uint32_t *) irsp) + 6), |
| 2532 | *(((uint32_t *) irsp) + 7)); |
| 2533 | } |
| 2534 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2535 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2536 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2537 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2538 | /* Handle the response IOCB */ |
| 2539 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 2540 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | |
| 2542 | /* |
| 2543 | * If the port response put pointer has not been updated, sync |
| 2544 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 2545 | * response put pointer. |
| 2546 | */ |
| 2547 | if (pring->rspidx == portRspPut) { |
| 2548 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2549 | } |
| 2550 | } /* while (pring->rspidx != portRspPut) */ |
| 2551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | /* At least one response entry has been freed */ |
| 2554 | pring->stats.iocb_rsp_full++; |
| 2555 | /* SET RxRE_RSP in Chip Att register */ |
| 2556 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 2557 | writel(status, phba->CAregaddr); |
| 2558 | readl(phba->CAregaddr); /* flush */ |
| 2559 | } |
| 2560 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 2561 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 2562 | pring->stats.iocb_cmd_empty++; |
| 2563 | |
| 2564 | /* Force update of the local copy of cmdGetInx */ |
| 2565 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 2566 | lpfc_sli_resume_iocb(phba, pring); |
| 2567 | |
| 2568 | if ((pring->lpfc_sli_cmd_available)) |
| 2569 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 2570 | |
| 2571 | } |
| 2572 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2573 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2574 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | } |
| 2576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2578 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2579 | * @phba: Pointer to HBA context object. |
| 2580 | * @pring: Pointer to driver SLI ring object. |
| 2581 | * |
| 2582 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 2583 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 2584 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 2585 | * the return of this function. The caller is not required to hold any locks. |
| 2586 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2587 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 2589 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2590 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2593 | if (pring->ringno == LPFC_ELS_RING) { |
| 2594 | lpfc_fabric_abort_hba(phba); |
| 2595 | } |
| 2596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | /* Error everything on txq and txcmplq |
| 2598 | * First do the txq. |
| 2599 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2600 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2601 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2602 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | |
| 2604 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2605 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 2606 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 2607 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2608 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 2609 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2610 | /* Cancel all the IOCBs from the completions list */ |
| 2611 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 2612 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | } |
| 2614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2616 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2617 | * @phba: Pointer to HBA context object. |
| 2618 | * |
| 2619 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 2620 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 2621 | * for all the iocb commands in txcmplq, they will just be returned with |
| 2622 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 2623 | * slot has been permanently disabled. |
| 2624 | **/ |
| 2625 | void |
| 2626 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 2627 | { |
| 2628 | LIST_HEAD(txq); |
| 2629 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2630 | struct lpfc_sli *psli = &phba->sli; |
| 2631 | struct lpfc_sli_ring *pring; |
| 2632 | |
| 2633 | /* Currently, only one fcp ring */ |
| 2634 | pring = &psli->ring[psli->fcp_ring]; |
| 2635 | |
| 2636 | spin_lock_irq(&phba->hbalock); |
| 2637 | /* Retrieve everything on txq */ |
| 2638 | list_splice_init(&pring->txq, &txq); |
| 2639 | pring->txq_cnt = 0; |
| 2640 | |
| 2641 | /* Retrieve everything on the txcmplq */ |
| 2642 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 2643 | pring->txcmplq_cnt = 0; |
| 2644 | spin_unlock_irq(&phba->hbalock); |
| 2645 | |
| 2646 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2647 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 2648 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2649 | |
| 2650 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2651 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 2652 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2656 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2657 | * @phba: Pointer to HBA context object. |
| 2658 | * @mask: Bit mask to be checked. |
| 2659 | * |
| 2660 | * This function reads the host status register and compares |
| 2661 | * with the provided bit mask to check if HBA completed |
| 2662 | * the restart. This function will wait in a loop for the |
| 2663 | * HBA to complete restart. If the HBA does not restart within |
| 2664 | * 15 iterations, the function will reset the HBA again. The |
| 2665 | * function returns 1 when HBA fail to restart otherwise returns |
| 2666 | * zero. |
| 2667 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2668 | static int |
| 2669 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2671 | uint32_t status; |
| 2672 | int i = 0; |
| 2673 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2675 | /* Read the HBA Host Status Register */ |
| 2676 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2678 | /* |
| 2679 | * Check status register every 100ms for 5 retries, then every |
| 2680 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 2681 | * every 2.5 sec for 4. |
| 2682 | * Break our of the loop if errors occurred during init. |
| 2683 | */ |
| 2684 | while (((status & mask) != mask) && |
| 2685 | !(status & HS_FFERM) && |
| 2686 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2688 | if (i <= 5) |
| 2689 | msleep(10); |
| 2690 | else if (i <= 10) |
| 2691 | msleep(500); |
| 2692 | else |
| 2693 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2695 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2697 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2698 | lpfc_sli_brdrestart(phba); |
| 2699 | } |
| 2700 | /* Read the HBA Host Status Register */ |
| 2701 | status = readl(phba->HSregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2704 | /* Check to see if any errors occurred during init */ |
| 2705 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2706 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2707 | retval = 1; |
| 2708 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2710 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | } |
| 2712 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 2713 | /** |
| 2714 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 2715 | * @phba: Pointer to HBA context object. |
| 2716 | * @mask: Bit mask to be checked. |
| 2717 | * |
| 2718 | * This function checks the host status register to check if HBA is |
| 2719 | * ready. This function will wait in a loop for the HBA to be ready |
| 2720 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 2721 | * function again. The function returns 1 when HBA fail to be ready |
| 2722 | * otherwise returns zero. |
| 2723 | **/ |
| 2724 | static int |
| 2725 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 2726 | { |
| 2727 | uint32_t status; |
| 2728 | int retval = 0; |
| 2729 | |
| 2730 | /* Read the HBA Host Status Register */ |
| 2731 | status = lpfc_sli4_post_status_check(phba); |
| 2732 | |
| 2733 | if (status) { |
| 2734 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 2735 | lpfc_sli_brdrestart(phba); |
| 2736 | status = lpfc_sli4_post_status_check(phba); |
| 2737 | } |
| 2738 | |
| 2739 | /* Check to see if any errors occurred during init */ |
| 2740 | if (status) { |
| 2741 | phba->link_state = LPFC_HBA_ERROR; |
| 2742 | retval = 1; |
| 2743 | } else |
| 2744 | phba->sli4_hba.intr_enable = 0; |
| 2745 | |
| 2746 | return retval; |
| 2747 | } |
| 2748 | |
| 2749 | /** |
| 2750 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 2751 | * @phba: Pointer to HBA context object. |
| 2752 | * @mask: Bit mask to be checked. |
| 2753 | * |
| 2754 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 2755 | * from the API jump table function pointer from the lpfc_hba struct. |
| 2756 | **/ |
| 2757 | int |
| 2758 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 2759 | { |
| 2760 | return phba->lpfc_sli_brdready(phba, mask); |
| 2761 | } |
| 2762 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2763 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 2764 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2766 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2767 | * @phba: Pointer to HBA context object. |
| 2768 | * |
| 2769 | * This function is called before resetting an HBA. This |
| 2770 | * function requests HBA to quiesce DMAs before a reset. |
| 2771 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2773 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2774 | uint32_t __iomem *resp_buf; |
| 2775 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2776 | volatile uint32_t mbox; |
| 2777 | uint32_t hc_copy; |
| 2778 | int i; |
| 2779 | uint8_t hdrtype; |
| 2780 | |
| 2781 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 2782 | if (hdrtype != 0x80 || |
| 2783 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 2784 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 2785 | return; |
| 2786 | |
| 2787 | /* |
| 2788 | * Tell the other part of the chip to suspend temporarily all |
| 2789 | * its DMA activity. |
| 2790 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2791 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2792 | |
| 2793 | /* Disable the error attention */ |
| 2794 | hc_copy = readl(phba->HCregaddr); |
| 2795 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 2796 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2797 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2798 | |
| 2799 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2800 | /* Clear Chip error bit */ |
| 2801 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | mbox = 0; |
| 2806 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 2807 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 2808 | |
| 2809 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 2810 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2811 | writel(mbox, mbox_buf); |
| 2812 | |
| 2813 | for (i = 0; |
| 2814 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) |
| 2815 | mdelay(1); |
| 2816 | |
| 2817 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
| 2818 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2819 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2820 | goto restore_hc; |
| 2821 | else |
| 2822 | goto clear_errat; |
| 2823 | } |
| 2824 | |
| 2825 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
| 2826 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) |
| 2827 | mdelay(1); |
| 2828 | |
| 2829 | clear_errat: |
| 2830 | |
| 2831 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) |
| 2832 | mdelay(1); |
| 2833 | |
| 2834 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 2835 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2836 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2840 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2841 | writel(hc_copy, phba->HCregaddr); |
| 2842 | readl(phba->HCregaddr); /* flush */ |
| 2843 | } |
| 2844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2845 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2846 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2847 | * @phba: Pointer to HBA context object. |
| 2848 | * |
| 2849 | * This function issues a kill_board mailbox command and waits for |
| 2850 | * the error attention interrupt. This function is called for stopping |
| 2851 | * the firmware processing. The caller is not required to hold any |
| 2852 | * locks. This function calls lpfc_hba_down_post function to free |
| 2853 | * any pending commands after the kill. The function will return 1 when it |
| 2854 | * fails to kill the board else will return 0. |
| 2855 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2856 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2859 | struct lpfc_sli *psli; |
| 2860 | LPFC_MBOXQ_t *pmb; |
| 2861 | uint32_t status; |
| 2862 | uint32_t ha_copy; |
| 2863 | int retval; |
| 2864 | int i = 0; |
| 2865 | |
| 2866 | psli = &phba->sli; |
| 2867 | |
| 2868 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2869 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2870 | "0329 Kill HBA Data: x%x x%x\n", |
| 2871 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2872 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2873 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2874 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2875 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2876 | |
| 2877 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2878 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2879 | status = readl(phba->HCregaddr); |
| 2880 | status &= ~HC_ERINT_ENA; |
| 2881 | writel(status, phba->HCregaddr); |
| 2882 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | phba->link_flag |= LS_IGNORE_ERATT; |
| 2884 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2885 | |
| 2886 | lpfc_kill_board(phba, pmb); |
| 2887 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2888 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2889 | |
| 2890 | if (retval != MBX_SUCCESS) { |
| 2891 | if (retval != MBX_BUSY) |
| 2892 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2893 | spin_lock_irq(&phba->hbalock); |
| 2894 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2895 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2896 | return 1; |
| 2897 | } |
| 2898 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2899 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 2900 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2901 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2902 | |
| 2903 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 2904 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 2905 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 2906 | * board is now undefined. |
| 2907 | */ |
| 2908 | ha_copy = readl(phba->HAregaddr); |
| 2909 | |
| 2910 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 2911 | mdelay(100); |
| 2912 | ha_copy = readl(phba->HAregaddr); |
| 2913 | } |
| 2914 | |
| 2915 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2916 | if (ha_copy & HA_ERATT) { |
| 2917 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2918 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 2919 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2921 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2922 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 2923 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2924 | |
| 2925 | psli->mbox_active = NULL; |
| 2926 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2927 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2928 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2929 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2930 | } |
| 2931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2932 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2933 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2934 | * @phba: Pointer to HBA context object. |
| 2935 | * |
| 2936 | * This function resets the HBA by writing HC_INITFF to the control |
| 2937 | * register. After the HBA resets, this function resets all the iocb ring |
| 2938 | * indices. This function disables PCI layer parity checking during |
| 2939 | * the reset. |
| 2940 | * This function returns 0 always. |
| 2941 | * The caller is not required to hold any locks. |
| 2942 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2943 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2944 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2945 | { |
| 2946 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2948 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2951 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2952 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2953 | /* Reset HBA */ |
| 2954 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2955 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2956 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | |
| 2958 | /* perform board reset */ |
| 2959 | phba->fc_eventTag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2960 | phba->pport->fc_myDID = 0; |
| 2961 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2963 | /* Turn off parity checking and serr during the physical reset */ |
| 2964 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 2965 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 2966 | (cfg_value & |
| 2967 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 2968 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2969 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 2970 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2971 | /* Now toggle INITFF bit in the Host Control Register */ |
| 2972 | writel(HC_INITFF, phba->HCregaddr); |
| 2973 | mdelay(1); |
| 2974 | readl(phba->HCregaddr); /* flush */ |
| 2975 | writel(0, phba->HCregaddr); |
| 2976 | readl(phba->HCregaddr); /* flush */ |
| 2977 | |
| 2978 | /* Restore PCI cmd register */ |
| 2979 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | |
| 2981 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2982 | for (i = 0; i < psli->num_rings; i++) { |
| 2983 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | pring->flag = 0; |
| 2985 | pring->rspidx = 0; |
| 2986 | pring->next_cmdidx = 0; |
| 2987 | pring->local_getidx = 0; |
| 2988 | pring->cmdidx = 0; |
| 2989 | pring->missbufcnt = 0; |
| 2990 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2991 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2992 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2993 | return 0; |
| 2994 | } |
| 2995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2996 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 2997 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 2998 | * @phba: Pointer to HBA context object. |
| 2999 | * |
| 3000 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3001 | * checking during resets the device. The caller is not required to hold |
| 3002 | * any locks. |
| 3003 | * |
| 3004 | * This function returns 0 always. |
| 3005 | **/ |
| 3006 | int |
| 3007 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3008 | { |
| 3009 | struct lpfc_sli *psli = &phba->sli; |
| 3010 | uint16_t cfg_value; |
| 3011 | uint8_t qindx; |
| 3012 | |
| 3013 | /* Reset HBA */ |
| 3014 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3015 | "0295 Reset HBA Data: x%x x%x\n", |
| 3016 | phba->pport->port_state, psli->sli_flag); |
| 3017 | |
| 3018 | /* perform board reset */ |
| 3019 | phba->fc_eventTag = 0; |
| 3020 | phba->pport->fc_myDID = 0; |
| 3021 | phba->pport->fc_prevDID = 0; |
| 3022 | |
| 3023 | /* Turn off parity checking and serr during the physical reset */ |
| 3024 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3025 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3026 | (cfg_value & |
| 3027 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3028 | |
| 3029 | spin_lock_irq(&phba->hbalock); |
| 3030 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3031 | phba->fcf.fcf_flag = 0; |
| 3032 | /* Clean up the child queue list for the CQs */ |
| 3033 | list_del_init(&phba->sli4_hba.mbx_wq->list); |
| 3034 | list_del_init(&phba->sli4_hba.els_wq->list); |
| 3035 | list_del_init(&phba->sli4_hba.hdr_rq->list); |
| 3036 | list_del_init(&phba->sli4_hba.dat_rq->list); |
| 3037 | list_del_init(&phba->sli4_hba.mbx_cq->list); |
| 3038 | list_del_init(&phba->sli4_hba.els_cq->list); |
| 3039 | list_del_init(&phba->sli4_hba.rxq_cq->list); |
| 3040 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
| 3041 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); |
| 3042 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) |
| 3043 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); |
| 3044 | spin_unlock_irq(&phba->hbalock); |
| 3045 | |
| 3046 | /* Now physically reset the device */ |
| 3047 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3048 | "0389 Performing PCI function reset!\n"); |
| 3049 | /* Perform FCoE PCI function reset */ |
| 3050 | lpfc_pci_function_reset(phba); |
| 3051 | |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
| 3055 | /** |
| 3056 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3057 | * @phba: Pointer to HBA context object. |
| 3058 | * |
| 3059 | * This function is called in the SLI initialization code path to |
| 3060 | * restart the HBA. The caller is not required to hold any lock. |
| 3061 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3062 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3063 | * function to free any pending commands. The function enables |
| 3064 | * POST only during the first initialization. The function returns zero. |
| 3065 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3066 | * command before the return of this function. |
| 3067 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 3068 | static int |
| 3069 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3070 | { |
| 3071 | MAILBOX_t *mb; |
| 3072 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3073 | volatile uint32_t word0; |
| 3074 | void __iomem *to_slim; |
| 3075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3076 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3077 | |
| 3078 | psli = &phba->sli; |
| 3079 | |
| 3080 | /* Restart HBA */ |
| 3081 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3082 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3083 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3084 | |
| 3085 | word0 = 0; |
| 3086 | mb = (MAILBOX_t *) &word0; |
| 3087 | mb->mbxCommand = MBX_RESTART; |
| 3088 | mb->mbxHc = 1; |
| 3089 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3090 | lpfc_reset_barrier(phba); |
| 3091 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3092 | to_slim = phba->MBslimaddr; |
| 3093 | writel(*(uint32_t *) mb, to_slim); |
| 3094 | readl(to_slim); /* flush */ |
| 3095 | |
| 3096 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3097 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3098 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3099 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3100 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3101 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3102 | writel(*(uint32_t *) mb, to_slim); |
| 3103 | readl(to_slim); /* flush */ |
| 3104 | |
| 3105 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3106 | phba->pport->stopped = 0; |
| 3107 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 3108 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3110 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 3111 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3112 | psli->stats_start = get_seconds(); |
| 3113 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3114 | /* Give the INITFF and Post time to settle. */ |
| 3115 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3117 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3118 | |
| 3119 | return 0; |
| 3120 | } |
| 3121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3122 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 3123 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 3124 | * @phba: Pointer to HBA context object. |
| 3125 | * |
| 3126 | * This function is called in the SLI initialization code path to restart |
| 3127 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 3128 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 3129 | * free any pending commands. |
| 3130 | **/ |
| 3131 | static int |
| 3132 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 3133 | { |
| 3134 | struct lpfc_sli *psli = &phba->sli; |
| 3135 | |
| 3136 | |
| 3137 | /* Restart HBA */ |
| 3138 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3139 | "0296 Restart HBA Data: x%x x%x\n", |
| 3140 | phba->pport->port_state, psli->sli_flag); |
| 3141 | |
| 3142 | lpfc_sli4_brdreset(phba); |
| 3143 | |
| 3144 | spin_lock_irq(&phba->hbalock); |
| 3145 | phba->pport->stopped = 0; |
| 3146 | phba->link_state = LPFC_INIT_START; |
| 3147 | phba->hba_flag = 0; |
| 3148 | spin_unlock_irq(&phba->hbalock); |
| 3149 | |
| 3150 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3151 | psli->stats_start = get_seconds(); |
| 3152 | |
| 3153 | lpfc_hba_down_post(phba); |
| 3154 | |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 3160 | * @phba: Pointer to HBA context object. |
| 3161 | * |
| 3162 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 3163 | * API jump table function pointer from the lpfc_hba struct. |
| 3164 | **/ |
| 3165 | int |
| 3166 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 3167 | { |
| 3168 | return phba->lpfc_sli_brdrestart(phba); |
| 3169 | } |
| 3170 | |
| 3171 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3172 | * 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] | 3173 | * @phba: Pointer to HBA context object. |
| 3174 | * |
| 3175 | * This function is called after a HBA restart to wait for successful |
| 3176 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 3177 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 3178 | * iteration, the function will restart the HBA again. The function returns |
| 3179 | * zero if HBA successfully restarted else returns negative error code. |
| 3180 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | static int |
| 3182 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 3183 | { |
| 3184 | uint32_t status, i = 0; |
| 3185 | |
| 3186 | /* Read the HBA Host Status Register */ |
| 3187 | status = readl(phba->HSregaddr); |
| 3188 | |
| 3189 | /* Check status register to see what current state is */ |
| 3190 | i = 0; |
| 3191 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 3192 | |
| 3193 | /* Check every 100ms for 5 retries, then every 500ms for 5, then |
| 3194 | * every 2.5 sec for 5, then reset board and every 2.5 sec for |
| 3195 | * 4. |
| 3196 | */ |
| 3197 | if (i++ >= 20) { |
| 3198 | /* Adapter failed to init, timeout, status reg |
| 3199 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3201 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3202 | "timeout, status reg x%x, " |
| 3203 | "FW Data: A8 x%x AC x%x\n", status, |
| 3204 | readl(phba->MBslimaddr + 0xa8), |
| 3205 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3207 | return -ETIMEDOUT; |
| 3208 | } |
| 3209 | |
| 3210 | /* Check to see if any errors occurred during init */ |
| 3211 | if (status & HS_FFERM) { |
| 3212 | /* ERROR: During chipset initialization */ |
| 3213 | /* Adapter failed to init, chipset, status reg |
| 3214 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3216 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3217 | "chipset, status reg x%x, " |
| 3218 | "FW Data: A8 x%x AC x%x\n", status, |
| 3219 | readl(phba->MBslimaddr + 0xa8), |
| 3220 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3221 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3222 | return -EIO; |
| 3223 | } |
| 3224 | |
| 3225 | if (i <= 5) { |
| 3226 | msleep(10); |
| 3227 | } else if (i <= 10) { |
| 3228 | msleep(500); |
| 3229 | } else { |
| 3230 | msleep(2500); |
| 3231 | } |
| 3232 | |
| 3233 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3234 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3235 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3236 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | } |
| 3238 | /* Read the HBA Host Status Register */ |
| 3239 | status = readl(phba->HSregaddr); |
| 3240 | } |
| 3241 | |
| 3242 | /* Check to see if any errors occurred during init */ |
| 3243 | if (status & HS_FFERM) { |
| 3244 | /* ERROR: During chipset initialization */ |
| 3245 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3247 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3248 | "status reg x%x, " |
| 3249 | "FW Data: A8 x%x AC x%x\n", status, |
| 3250 | readl(phba->MBslimaddr + 0xa8), |
| 3251 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3252 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | return -EIO; |
| 3254 | } |
| 3255 | |
| 3256 | /* Clear all interrupt enable conditions */ |
| 3257 | writel(0, phba->HCregaddr); |
| 3258 | readl(phba->HCregaddr); /* flush */ |
| 3259 | |
| 3260 | /* setup host attn register */ |
| 3261 | writel(0xffffffff, phba->HAregaddr); |
| 3262 | readl(phba->HAregaddr); /* flush */ |
| 3263 | return 0; |
| 3264 | } |
| 3265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3267 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3268 | * |
| 3269 | * This function calculates and returns the number of HBQs required to be |
| 3270 | * configured. |
| 3271 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3272 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3273 | lpfc_sli_hbq_count(void) |
| 3274 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3275 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3276 | } |
| 3277 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3278 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3279 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3280 | * |
| 3281 | * This function adds the number of hbq entries in every HBQ to get |
| 3282 | * the total number of hbq entries required for the HBA and returns |
| 3283 | * the total count. |
| 3284 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3285 | static int |
| 3286 | lpfc_sli_hbq_entry_count(void) |
| 3287 | { |
| 3288 | int hbq_count = lpfc_sli_hbq_count(); |
| 3289 | int count = 0; |
| 3290 | int i; |
| 3291 | |
| 3292 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3293 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3294 | return count; |
| 3295 | } |
| 3296 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3297 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3298 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3299 | * |
| 3300 | * This function calculates amount of memory required for all hbq entries |
| 3301 | * to be configured and returns the total memory required. |
| 3302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3304 | lpfc_sli_hbq_size(void) |
| 3305 | { |
| 3306 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 3307 | } |
| 3308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3310 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3311 | * @phba: Pointer to HBA context object. |
| 3312 | * |
| 3313 | * This function is called during the SLI initialization to configure |
| 3314 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 3315 | * required to hold any locks. This function will return zero if successful |
| 3316 | * else it will return negative error code. |
| 3317 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3318 | static int |
| 3319 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 3320 | { |
| 3321 | int hbq_count = lpfc_sli_hbq_count(); |
| 3322 | LPFC_MBOXQ_t *pmb; |
| 3323 | MAILBOX_t *pmbox; |
| 3324 | uint32_t hbqno; |
| 3325 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3326 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3327 | /* Get a Mailbox buffer to setup mailbox |
| 3328 | * commands for HBA initialization |
| 3329 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3330 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3331 | |
| 3332 | if (!pmb) |
| 3333 | return -ENOMEM; |
| 3334 | |
| 3335 | pmbox = &pmb->mb; |
| 3336 | |
| 3337 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 3338 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 3339 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3340 | |
| 3341 | hbq_entry_index = 0; |
| 3342 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 3343 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 3344 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 3345 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 3346 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3347 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3348 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 3349 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3350 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 3351 | |
| 3352 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 3353 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 3354 | mbxStatus <status>, ring <num> */ |
| 3355 | |
| 3356 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3357 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3358 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3359 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3360 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3361 | pmbox->mbxStatus, hbqno); |
| 3362 | |
| 3363 | phba->link_state = LPFC_HBA_ERROR; |
| 3364 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3365 | return ENXIO; |
| 3366 | } |
| 3367 | } |
| 3368 | phba->hbq_count = hbq_count; |
| 3369 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3370 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3372 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3373 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 3374 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3375 | return 0; |
| 3376 | } |
| 3377 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3378 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3379 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3380 | * @phba: Pointer to HBA context object. |
| 3381 | * @sli_mode: sli mode - 2/3 |
| 3382 | * |
| 3383 | * This function is called by the sli intialization code path |
| 3384 | * to issue config_port mailbox command. This function restarts the |
| 3385 | * HBA firmware and issues a config_port mailbox command to configure |
| 3386 | * the SLI interface in the sli mode specified by sli_mode |
| 3387 | * variable. The caller is not required to hold any locks. |
| 3388 | * The function returns 0 if successful, else returns negative error |
| 3389 | * code. |
| 3390 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3391 | int |
| 3392 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | { |
| 3394 | LPFC_MBOXQ_t *pmb; |
| 3395 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 3396 | |
| 3397 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3398 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | return -ENOMEM; |
| 3401 | } |
| 3402 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3403 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3406 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3407 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3408 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3409 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | rc = lpfc_sli_chipset_init(phba); |
| 3411 | if (rc) |
| 3412 | break; |
| 3413 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 3415 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3416 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | resetcount++; |
| 3418 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3419 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 3420 | * value of 0 means the call was successful. Any other |
| 3421 | * nonzero value is a failure, but if ERESTART is returned, |
| 3422 | * the driver may reset the HBA and try again. |
| 3423 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | rc = lpfc_config_port_prep(phba); |
| 3425 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3426 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3428 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | break; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3430 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | lpfc_config_port(phba, pmb); |
| 3432 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3433 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 3434 | LPFC_SLI3_HBQ_ENABLED | |
| 3435 | LPFC_SLI3_CRP_ENABLED | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3436 | LPFC_SLI3_INB_ENABLED | |
| 3437 | LPFC_SLI3_BG_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3438 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3440 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3441 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3442 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | spin_unlock_irq(&phba->hbalock); |
| 3446 | rc = -ENXIO; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3447 | } else |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3448 | done = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3450 | if (!done) { |
| 3451 | rc = -EINVAL; |
| 3452 | goto do_prep_failed; |
| 3453 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3454 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { |
| 3455 | if (!pmb->mb.un.varCfgPort.cMA) { |
| 3456 | rc = -ENXIO; |
| 3457 | goto do_prep_failed; |
| 3458 | } |
| 3459 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { |
| 3460 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 3461 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; |
| 3462 | } else |
| 3463 | phba->max_vpi = 0; |
| 3464 | if (pmb->mb.un.varCfgPort.gerbm) |
| 3465 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
| 3466 | if (pmb->mb.un.varCfgPort.gcrp) |
| 3467 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
| 3468 | if (pmb->mb.un.varCfgPort.ginb) { |
| 3469 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3470 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3471 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
| 3472 | phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy; |
| 3473 | phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter; |
| 3474 | phba->inb_last_counter = |
| 3475 | phba->mbox->us.s3_inb_pgp.counter; |
| 3476 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3477 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3478 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
| 3479 | phba->inb_ha_copy = NULL; |
| 3480 | phba->inb_counter = NULL; |
| 3481 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3482 | |
| 3483 | if (phba->cfg_enable_bg) { |
| 3484 | if (pmb->mb.un.varCfgPort.gbg) |
| 3485 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 3486 | else |
| 3487 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3488 | "0443 Adapter did not grant " |
| 3489 | "BlockGuard\n"); |
| 3490 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3491 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 3492 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3493 | phba->port_gp = phba->mbox->us.s2.port; |
| 3494 | phba->inb_ha_copy = NULL; |
| 3495 | phba->inb_counter = NULL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3496 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3497 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3498 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3499 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3500 | return rc; |
| 3501 | } |
| 3502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3503 | |
| 3504 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3505 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3506 | * @phba: Pointer to HBA context object. |
| 3507 | * |
| 3508 | * This function is the main SLI intialization function. This function |
| 3509 | * is called by the HBA intialization code, HBA reset code and HBA |
| 3510 | * error attention handler code. Caller is not required to hold any |
| 3511 | * locks. This function issues config_port mailbox command to configure |
| 3512 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 3513 | * calls the config_port_post function to issue init_link mailbox |
| 3514 | * command and to start the discovery. The function will return zero |
| 3515 | * if successful, else it will return negative error code. |
| 3516 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3517 | int |
| 3518 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 3519 | { |
| 3520 | uint32_t rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3521 | int mode = 3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3522 | |
| 3523 | switch (lpfc_sli_mode) { |
| 3524 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3525 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3526 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3527 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3529 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3530 | break; |
| 3531 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3532 | mode = 2; |
| 3533 | break; |
| 3534 | case 0: |
| 3535 | case 3: |
| 3536 | break; |
| 3537 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3539 | "1819 Unrecognized lpfc_sli_mode " |
| 3540 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3541 | |
| 3542 | break; |
| 3543 | } |
| 3544 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3545 | rc = lpfc_sli_config_port(phba, mode); |
| 3546 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3547 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3549 | "1820 Unable to select SLI-3. " |
| 3550 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3551 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3552 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3553 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | goto lpfc_sli_hba_setup_error; |
| 3555 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3556 | if (phba->sli_rev == 3) { |
| 3557 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 3558 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3559 | } else { |
| 3560 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 3561 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3566 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 3567 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3568 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | |
| 3570 | if (rc) |
| 3571 | goto lpfc_sli_hba_setup_error; |
| 3572 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3573 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3574 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 3575 | rc = lpfc_sli_hbq_setup(phba); |
| 3576 | if (rc) |
| 3577 | goto lpfc_sli_hba_setup_error; |
| 3578 | } |
| 3579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
| 3581 | |
| 3582 | rc = lpfc_config_port_post(phba); |
| 3583 | if (rc) |
| 3584 | goto lpfc_sli_hba_setup_error; |
| 3585 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3586 | return rc; |
| 3587 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3588 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3589 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3590 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3591 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | return rc; |
| 3593 | } |
| 3594 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 3595 | /** |
| 3596 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 3597 | * @phba: Pointer to HBA context object. |
| 3598 | * @mboxq: mailbox pointer. |
| 3599 | * This function issue a dump mailbox command to read config region |
| 3600 | * 23 and parse the records in the region and populate driver |
| 3601 | * data structure. |
| 3602 | **/ |
| 3603 | static int |
| 3604 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, |
| 3605 | LPFC_MBOXQ_t *mboxq) |
| 3606 | { |
| 3607 | struct lpfc_dmabuf *mp; |
| 3608 | struct lpfc_mqe *mqe; |
| 3609 | uint32_t data_length; |
| 3610 | int rc; |
| 3611 | |
| 3612 | /* Program the default value of vlan_id and fc_map */ |
| 3613 | phba->valid_vlan = 0; |
| 3614 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 3615 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 3616 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 3617 | |
| 3618 | mqe = &mboxq->u.mqe; |
| 3619 | if (lpfc_dump_fcoe_param(phba, mboxq)) |
| 3620 | return -ENOMEM; |
| 3621 | |
| 3622 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 3623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3624 | |
| 3625 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 3626 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 3627 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 3628 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 3629 | "CQ: x%x x%x x%x x%x\n", |
| 3630 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 3631 | bf_get(lpfc_mqe_command, mqe), |
| 3632 | bf_get(lpfc_mqe_status, mqe), |
| 3633 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 3634 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 3635 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 3636 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 3637 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 3638 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 3639 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 3640 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 3641 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 3642 | mboxq->mcqe.word0, |
| 3643 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 3644 | mboxq->mcqe.trailer); |
| 3645 | |
| 3646 | if (rc) { |
| 3647 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3648 | kfree(mp); |
| 3649 | return -EIO; |
| 3650 | } |
| 3651 | data_length = mqe->un.mb_words[5]; |
| 3652 | if (data_length > DMP_FCOEPARAM_RGN_SIZE) |
| 3653 | return -EIO; |
| 3654 | |
| 3655 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 3656 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3657 | kfree(mp); |
| 3658 | return 0; |
| 3659 | } |
| 3660 | |
| 3661 | /** |
| 3662 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 3663 | * @phba: pointer to lpfc hba data structure. |
| 3664 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 3665 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 3666 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 3667 | * On output, the number of data bytes in @vpd. |
| 3668 | * |
| 3669 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 3670 | * addition, this routine gets the port vpd data. |
| 3671 | * |
| 3672 | * Return codes |
| 3673 | * 0 - sucessful |
| 3674 | * ENOMEM - could not allocated memory. |
| 3675 | **/ |
| 3676 | static int |
| 3677 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 3678 | uint8_t *vpd, uint32_t *vpd_size) |
| 3679 | { |
| 3680 | int rc = 0; |
| 3681 | uint32_t dma_size; |
| 3682 | struct lpfc_dmabuf *dmabuf; |
| 3683 | struct lpfc_mqe *mqe; |
| 3684 | |
| 3685 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3686 | if (!dmabuf) |
| 3687 | return -ENOMEM; |
| 3688 | |
| 3689 | /* |
| 3690 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 3691 | * mailbox command. |
| 3692 | */ |
| 3693 | dma_size = *vpd_size; |
| 3694 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 3695 | dma_size, |
| 3696 | &dmabuf->phys, |
| 3697 | GFP_KERNEL); |
| 3698 | if (!dmabuf->virt) { |
| 3699 | kfree(dmabuf); |
| 3700 | return -ENOMEM; |
| 3701 | } |
| 3702 | memset(dmabuf->virt, 0, dma_size); |
| 3703 | |
| 3704 | /* |
| 3705 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 3706 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 3707 | * in SLI3. This code corrects the conflicts. |
| 3708 | */ |
| 3709 | lpfc_read_rev(phba, mboxq); |
| 3710 | mqe = &mboxq->u.mqe; |
| 3711 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 3712 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 3713 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 3714 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 3715 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 3716 | |
| 3717 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3718 | if (rc) { |
| 3719 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 3720 | dmabuf->virt, dmabuf->phys); |
| 3721 | return -EIO; |
| 3722 | } |
| 3723 | |
| 3724 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 3725 | "(%d):0380 Mailbox cmd x%x Status x%x " |
| 3726 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 3727 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 3728 | "CQ: x%x x%x x%x x%x\n", |
| 3729 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 3730 | bf_get(lpfc_mqe_command, mqe), |
| 3731 | bf_get(lpfc_mqe_status, mqe), |
| 3732 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 3733 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 3734 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 3735 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 3736 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 3737 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 3738 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 3739 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 3740 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 3741 | mboxq->mcqe.word0, |
| 3742 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 3743 | mboxq->mcqe.trailer); |
| 3744 | |
| 3745 | /* |
| 3746 | * The available vpd length cannot be bigger than the |
| 3747 | * DMA buffer passed to the port. Catch the less than |
| 3748 | * case and update the caller's size. |
| 3749 | */ |
| 3750 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 3751 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 3752 | |
| 3753 | lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size); |
| 3754 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 3755 | dmabuf->virt, dmabuf->phys); |
| 3756 | kfree(dmabuf); |
| 3757 | return 0; |
| 3758 | } |
| 3759 | |
| 3760 | /** |
| 3761 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 3762 | * @phba: pointer to lpfc hba data structure. |
| 3763 | * |
| 3764 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 3765 | * event queues |
| 3766 | **/ |
| 3767 | static void |
| 3768 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 3769 | { |
| 3770 | uint8_t fcp_eqidx; |
| 3771 | |
| 3772 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 3773 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
| 3774 | lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM); |
| 3775 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
| 3776 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 3777 | LPFC_QUEUE_REARM); |
| 3778 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
| 3779 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
| 3780 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], |
| 3781 | LPFC_QUEUE_REARM); |
| 3782 | } |
| 3783 | |
| 3784 | /** |
| 3785 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 3786 | * @phba: Pointer to HBA context object. |
| 3787 | * |
| 3788 | * This function is the main SLI4 device intialization PCI function. This |
| 3789 | * function is called by the HBA intialization code, HBA reset code and |
| 3790 | * HBA error attention handler code. Caller is not required to hold any |
| 3791 | * locks. |
| 3792 | **/ |
| 3793 | int |
| 3794 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 3795 | { |
| 3796 | int rc; |
| 3797 | LPFC_MBOXQ_t *mboxq; |
| 3798 | struct lpfc_mqe *mqe; |
| 3799 | uint8_t *vpd; |
| 3800 | uint32_t vpd_size; |
| 3801 | uint32_t ftr_rsp = 0; |
| 3802 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 3803 | struct lpfc_vport *vport = phba->pport; |
| 3804 | struct lpfc_dmabuf *mp; |
| 3805 | |
| 3806 | /* Perform a PCI function reset to start from clean */ |
| 3807 | rc = lpfc_pci_function_reset(phba); |
| 3808 | if (unlikely(rc)) |
| 3809 | return -ENODEV; |
| 3810 | |
| 3811 | /* Check the HBA Host Status Register for readyness */ |
| 3812 | rc = lpfc_sli4_post_status_check(phba); |
| 3813 | if (unlikely(rc)) |
| 3814 | return -ENODEV; |
| 3815 | else { |
| 3816 | spin_lock_irq(&phba->hbalock); |
| 3817 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 3818 | spin_unlock_irq(&phba->hbalock); |
| 3819 | } |
| 3820 | |
| 3821 | /* |
| 3822 | * Allocate a single mailbox container for initializing the |
| 3823 | * port. |
| 3824 | */ |
| 3825 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3826 | if (!mboxq) |
| 3827 | return -ENOMEM; |
| 3828 | |
| 3829 | /* |
| 3830 | * Continue initialization with default values even if driver failed |
| 3831 | * to read FCoE param config regions |
| 3832 | */ |
| 3833 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) |
| 3834 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 3835 | "2570 Failed to read FCoE parameters \n"); |
| 3836 | |
| 3837 | /* Issue READ_REV to collect vpd and FW information. */ |
| 3838 | vpd_size = PAGE_SIZE; |
| 3839 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 3840 | if (!vpd) { |
| 3841 | rc = -ENOMEM; |
| 3842 | goto out_free_mbox; |
| 3843 | } |
| 3844 | |
| 3845 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
| 3846 | if (unlikely(rc)) |
| 3847 | goto out_free_vpd; |
| 3848 | |
| 3849 | mqe = &mboxq->u.mqe; |
| 3850 | if ((bf_get(lpfc_mbx_rd_rev_sli_lvl, |
| 3851 | &mqe->un.read_rev) != LPFC_SLI_REV4) || |
| 3852 | (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev) == 0)) { |
| 3853 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3854 | "0376 READ_REV Error. SLI Level %d " |
| 3855 | "FCoE enabled %d\n", |
| 3856 | bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev), |
| 3857 | bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)); |
| 3858 | rc = -EIO; |
| 3859 | goto out_free_vpd; |
| 3860 | } |
| 3861 | /* Single threaded at this point, no need for lock */ |
| 3862 | spin_lock_irq(&phba->hbalock); |
| 3863 | phba->hba_flag |= HBA_FCOE_SUPPORT; |
| 3864 | spin_unlock_irq(&phba->hbalock); |
| 3865 | /* |
| 3866 | * Evaluate the read rev and vpd data. Populate the driver |
| 3867 | * state with the results. If this routine fails, the failure |
| 3868 | * is not fatal as the driver will use generic values. |
| 3869 | */ |
| 3870 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 3871 | if (unlikely(!rc)) { |
| 3872 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3873 | "0377 Error %d parsing vpd. " |
| 3874 | "Using defaults.\n", rc); |
| 3875 | rc = 0; |
| 3876 | } |
| 3877 | |
| 3878 | /* By now, we should determine the SLI revision, hard code for now */ |
| 3879 | phba->sli_rev = LPFC_SLI_REV4; |
| 3880 | |
| 3881 | /* |
| 3882 | * Discover the port's supported feature set and match it against the |
| 3883 | * hosts requests. |
| 3884 | */ |
| 3885 | lpfc_request_features(phba, mboxq); |
| 3886 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3887 | if (unlikely(rc)) { |
| 3888 | rc = -EIO; |
| 3889 | goto out_free_vpd; |
| 3890 | } |
| 3891 | |
| 3892 | /* |
| 3893 | * The port must support FCP initiator mode as this is the |
| 3894 | * only mode running in the host. |
| 3895 | */ |
| 3896 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 3897 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 3898 | "0378 No support for fcpi mode.\n"); |
| 3899 | ftr_rsp++; |
| 3900 | } |
| 3901 | |
| 3902 | /* |
| 3903 | * If the port cannot support the host's requested features |
| 3904 | * then turn off the global config parameters to disable the |
| 3905 | * feature in the driver. This is not a fatal error. |
| 3906 | */ |
| 3907 | if ((phba->cfg_enable_bg) && |
| 3908 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 3909 | ftr_rsp++; |
| 3910 | |
| 3911 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 3912 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 3913 | ftr_rsp++; |
| 3914 | |
| 3915 | if (ftr_rsp) { |
| 3916 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 3917 | "0379 Feature Mismatch Data: x%08x %08x " |
| 3918 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 3919 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 3920 | phba->cfg_enable_npiv, phba->max_vpi); |
| 3921 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 3922 | phba->cfg_enable_bg = 0; |
| 3923 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 3924 | phba->cfg_enable_npiv = 0; |
| 3925 | } |
| 3926 | |
| 3927 | /* These SLI3 features are assumed in SLI4 */ |
| 3928 | spin_lock_irq(&phba->hbalock); |
| 3929 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 3930 | spin_unlock_irq(&phba->hbalock); |
| 3931 | |
| 3932 | /* Read the port's service parameters. */ |
| 3933 | lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 3934 | mboxq->vport = vport; |
| 3935 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3936 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 3937 | if (rc == MBX_SUCCESS) { |
| 3938 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 3939 | rc = 0; |
| 3940 | } |
| 3941 | |
| 3942 | /* |
| 3943 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 3944 | * it to the mbuf pool. |
| 3945 | */ |
| 3946 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3947 | kfree(mp); |
| 3948 | mboxq->context1 = NULL; |
| 3949 | if (unlikely(rc)) { |
| 3950 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3951 | "0382 READ_SPARAM command failed " |
| 3952 | "status %d, mbxStatus x%x\n", |
| 3953 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 3954 | phba->link_state = LPFC_HBA_ERROR; |
| 3955 | rc = -EIO; |
| 3956 | goto out_free_vpd; |
| 3957 | } |
| 3958 | |
| 3959 | if (phba->cfg_soft_wwnn) |
| 3960 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 3961 | vport->fc_sparam.nodeName.u.wwn); |
| 3962 | if (phba->cfg_soft_wwpn) |
| 3963 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 3964 | vport->fc_sparam.portName.u.wwn); |
| 3965 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 3966 | sizeof(struct lpfc_name)); |
| 3967 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 3968 | sizeof(struct lpfc_name)); |
| 3969 | |
| 3970 | /* Update the fc_host data structures with new wwn. */ |
| 3971 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3972 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 3973 | |
| 3974 | /* Register SGL pool to the device using non-embedded mailbox command */ |
| 3975 | rc = lpfc_sli4_post_sgl_list(phba); |
| 3976 | if (unlikely(rc)) { |
| 3977 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3978 | "0582 Error %d during sgl post operation", rc); |
| 3979 | rc = -ENODEV; |
| 3980 | goto out_free_vpd; |
| 3981 | } |
| 3982 | |
| 3983 | /* Register SCSI SGL pool to the device */ |
| 3984 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 3985 | if (unlikely(rc)) { |
| 3986 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 3987 | "0383 Error %d during scsi sgl post opeation", |
| 3988 | rc); |
| 3989 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 3990 | /* A pci function reset will repost them */ |
| 3991 | rc = -ENODEV; |
| 3992 | goto out_free_vpd; |
| 3993 | } |
| 3994 | |
| 3995 | /* Post the rpi header region to the device. */ |
| 3996 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 3997 | if (unlikely(rc)) { |
| 3998 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 3999 | "0393 Error %d during rpi post operation\n", |
| 4000 | rc); |
| 4001 | rc = -ENODEV; |
| 4002 | goto out_free_vpd; |
| 4003 | } |
| 4004 | /* Temporary initialization of lpfc_fip_flag to non-fip */ |
| 4005 | bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0); |
| 4006 | |
| 4007 | /* Set up all the queues to the device */ |
| 4008 | rc = lpfc_sli4_queue_setup(phba); |
| 4009 | if (unlikely(rc)) { |
| 4010 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4011 | "0381 Error %d during queue setup.\n ", rc); |
| 4012 | goto out_stop_timers; |
| 4013 | } |
| 4014 | |
| 4015 | /* Arm the CQs and then EQs on device */ |
| 4016 | lpfc_sli4_arm_cqeq_intr(phba); |
| 4017 | |
| 4018 | /* Indicate device interrupt mode */ |
| 4019 | phba->sli4_hba.intr_enable = 1; |
| 4020 | |
| 4021 | /* Allow asynchronous mailbox command to go through */ |
| 4022 | spin_lock_irq(&phba->hbalock); |
| 4023 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4024 | spin_unlock_irq(&phba->hbalock); |
| 4025 | |
| 4026 | /* Post receive buffers to the device */ |
| 4027 | lpfc_sli4_rb_setup(phba); |
| 4028 | |
| 4029 | /* Start the ELS watchdog timer */ |
| 4030 | /* |
| 4031 | * The driver for SLI4 is not yet ready to process timeouts |
| 4032 | * or interrupts. Once it is, the comment bars can be removed. |
| 4033 | */ |
| 4034 | /* mod_timer(&vport->els_tmofunc, |
| 4035 | * jiffies + HZ * (phba->fc_ratov*2)); */ |
| 4036 | |
| 4037 | /* Start heart beat timer */ |
| 4038 | mod_timer(&phba->hb_tmofunc, |
| 4039 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 4040 | phba->hb_outstanding = 0; |
| 4041 | phba->last_completion_time = jiffies; |
| 4042 | |
| 4043 | /* Start error attention (ERATT) polling timer */ |
| 4044 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 4045 | |
| 4046 | /* |
| 4047 | * The port is ready, set the host's link state to LINK_DOWN |
| 4048 | * in preparation for link interrupts. |
| 4049 | */ |
| 4050 | lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed); |
| 4051 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4052 | lpfc_set_loopback_flag(phba); |
| 4053 | /* Change driver state to LPFC_LINK_DOWN right before init link */ |
| 4054 | spin_lock_irq(&phba->hbalock); |
| 4055 | phba->link_state = LPFC_LINK_DOWN; |
| 4056 | spin_unlock_irq(&phba->hbalock); |
| 4057 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 4058 | if (unlikely(rc != MBX_NOT_FINISHED)) { |
| 4059 | kfree(vpd); |
| 4060 | return 0; |
| 4061 | } else |
| 4062 | rc = -EIO; |
| 4063 | |
| 4064 | /* Unset all the queues set up in this routine when error out */ |
| 4065 | if (rc) |
| 4066 | lpfc_sli4_queue_unset(phba); |
| 4067 | |
| 4068 | out_stop_timers: |
| 4069 | if (rc) |
| 4070 | lpfc_stop_hba_timers(phba); |
| 4071 | out_free_vpd: |
| 4072 | kfree(vpd); |
| 4073 | out_free_mbox: |
| 4074 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4075 | return rc; |
| 4076 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4077 | |
| 4078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4079 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4080 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4081 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4082 | * This is the callback function for mailbox timer. The mailbox |
| 4083 | * timer is armed when a new mailbox command is issued and the timer |
| 4084 | * is deleted when the mailbox complete. The function is called by |
| 4085 | * the kernel timer code when a mailbox does not complete within |
| 4086 | * expected time. This function wakes up the worker thread to |
| 4087 | * process the mailbox timeout and returns. All the processing is |
| 4088 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 4089 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | void |
| 4091 | lpfc_mbox_timeout(unsigned long ptr) |
| 4092 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4093 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4095 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4097 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4098 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | if (!tmo_posted) |
| 4100 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 4101 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 4102 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4103 | if (!tmo_posted) |
| 4104 | lpfc_worker_wake_up(phba); |
| 4105 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | } |
| 4107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4108 | |
| 4109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4110 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4111 | * @phba: Pointer to HBA context object. |
| 4112 | * |
| 4113 | * This function is called from worker thread when a mailbox command times out. |
| 4114 | * The caller is not required to hold any locks. This function will reset the |
| 4115 | * HBA and recover all the pending commands. |
| 4116 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | void |
| 4118 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 4119 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
| 4121 | MAILBOX_t *mb = &pmbox->mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4122 | struct lpfc_sli *psli = &phba->sli; |
| 4123 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4125 | /* Check the pmbox pointer first. There is a race condition |
| 4126 | * between the mbox timeout handler getting executed in the |
| 4127 | * worklist and the mailbox actually completing. When this |
| 4128 | * race condition occurs, the mbox_active will be NULL. |
| 4129 | */ |
| 4130 | spin_lock_irq(&phba->hbalock); |
| 4131 | if (pmbox == NULL) { |
| 4132 | lpfc_printf_log(phba, KERN_WARNING, |
| 4133 | LOG_MBOX | LOG_SLI, |
| 4134 | "0353 Active Mailbox cleared - mailbox timeout " |
| 4135 | "exiting\n"); |
| 4136 | spin_unlock_irq(&phba->hbalock); |
| 4137 | return; |
| 4138 | } |
| 4139 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4141 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4142 | "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] | 4143 | mb->mbxCommand, |
| 4144 | phba->pport->port_state, |
| 4145 | phba->sli.sli_flag, |
| 4146 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4147 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4149 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 4150 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
| 4151 | * it to fail all oustanding SCSI IO. |
| 4152 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4153 | spin_lock_irq(&phba->pport->work_port_lock); |
| 4154 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 4155 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 4156 | spin_lock_irq(&phba->hbalock); |
| 4157 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4158 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4159 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4160 | |
| 4161 | pring = &psli->ring[psli->fcp_ring]; |
| 4162 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4163 | |
| 4164 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 4165 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4166 | |
| 4167 | /* Reset the HBA device */ |
| 4168 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4169 | } |
| 4170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4171 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4172 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4173 | * @phba: Pointer to HBA context object. |
| 4174 | * @pmbox: Pointer to mailbox object. |
| 4175 | * @flag: Flag indicating how the mailbox need to be processed. |
| 4176 | * |
| 4177 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4178 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 4179 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4180 | * The mailbox command can be submitted in polling mode, in which case |
| 4181 | * this function will wait in a polling loop for the completion of the |
| 4182 | * mailbox. |
| 4183 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 4184 | * function will submit the command and returns immediately without waiting |
| 4185 | * for the mailbox completion. The no_wait is supported only when HBA |
| 4186 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 4187 | * The SLI interface allows only one mailbox pending at a time. If the |
| 4188 | * mailbox is issued in polling mode and there is already a mailbox |
| 4189 | * pending, then the function will return an error. If the mailbox is issued |
| 4190 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 4191 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 4192 | * The sli layer owns the mailbox object until the completion of mailbox |
| 4193 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 4194 | * return codes the caller owns the mailbox command after the return of |
| 4195 | * the function. |
| 4196 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4197 | static int |
| 4198 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 4199 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4200 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4202 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4203 | uint32_t status, evtctr; |
| 4204 | uint32_t ha_copy; |
| 4205 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4206 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4208 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4209 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4210 | int processing_queue = 0; |
| 4211 | |
| 4212 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 4213 | if (!pmbox) { |
| 4214 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4215 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 4216 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 4217 | return MBX_SUCCESS; |
| 4218 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4219 | processing_queue = 1; |
| 4220 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 4221 | pmbox = lpfc_mbox_get(phba); |
| 4222 | if (!pmbox) { |
| 4223 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 4224 | return MBX_SUCCESS; |
| 4225 | } |
| 4226 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4227 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4228 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4229 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4230 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4231 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4232 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4233 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4234 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4235 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4236 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4237 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 4241 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4242 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 4243 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 4244 | goto out_not_finished; |
| 4245 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 4246 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 4247 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 4248 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 4249 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 4250 | goto out_not_finished; |
| 4251 | } |
| 4252 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4254 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4255 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4256 | status = MBX_SUCCESS; |
| 4257 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4258 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 4259 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4260 | |
| 4261 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4262 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4263 | "(%d):0311 Mailbox command x%x cannot " |
| 4264 | "issue Data: x%x x%x\n", |
| 4265 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 4266 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4267 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4268 | } |
| 4269 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4270 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
| 4271 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4273 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4274 | "(%d):2528 Mailbox command x%x cannot " |
| 4275 | "issue Data: x%x x%x\n", |
| 4276 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 4277 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4278 | goto out_not_finished; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4279 | } |
| 4280 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4281 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 4282 | /* Polling for a mbox command when another one is already active |
| 4283 | * is not allowed in SLI. Also, the driver must have established |
| 4284 | * SLI2 mode to queue and process multiple mbox commands. |
| 4285 | */ |
| 4286 | |
| 4287 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | |
| 4290 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4291 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4292 | "(%d):2529 Mailbox command x%x " |
| 4293 | "cannot issue Data: x%x x%x\n", |
| 4294 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 4295 | pmbox->u.mb.mbxCommand, |
| 4296 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4297 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | } |
| 4299 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4300 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4301 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4303 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4304 | "(%d):2530 Mailbox command x%x " |
| 4305 | "cannot issue Data: x%x x%x\n", |
| 4306 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 4307 | pmbox->u.mb.mbxCommand, |
| 4308 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4309 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | } |
| 4311 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4312 | /* Another mailbox command is still being processed, queue this |
| 4313 | * command to be processed later. |
| 4314 | */ |
| 4315 | lpfc_mbox_put(phba, pmbox); |
| 4316 | |
| 4317 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4318 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4319 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4320 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4321 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 4322 | mb->mbxCommand, phba->pport->port_state, |
| 4323 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | |
| 4325 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4326 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4328 | if (pmbox->vport) { |
| 4329 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 4330 | LPFC_DISC_TRC_MBOX_VPORT, |
| 4331 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 4332 | (uint32_t)mb->mbxCommand, |
| 4333 | mb->un.varWords[0], mb->un.varWords[1]); |
| 4334 | } |
| 4335 | else { |
| 4336 | lpfc_debugfs_disc_trc(phba->pport, |
| 4337 | LPFC_DISC_TRC_MBOX, |
| 4338 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 4339 | (uint32_t)mb->mbxCommand, |
| 4340 | mb->un.varWords[0], mb->un.varWords[1]); |
| 4341 | } |
| 4342 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4343 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | } |
| 4345 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 4347 | |
| 4348 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 4349 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4350 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4351 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4352 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4353 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4355 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4356 | "(%d):2531 Mailbox command x%x " |
| 4357 | "cannot issue Data: x%x x%x\n", |
| 4358 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 4359 | pmbox->u.mb.mbxCommand, |
| 4360 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4361 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | } |
| 4363 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 4364 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 4365 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4369 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4370 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4371 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4372 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4373 | mb->mbxCommand, phba->pport->port_state, |
| 4374 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4375 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4376 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 4377 | if (pmbox->vport) { |
| 4378 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 4379 | LPFC_DISC_TRC_MBOX_VPORT, |
| 4380 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 4381 | (uint32_t)mb->mbxCommand, |
| 4382 | mb->un.varWords[0], mb->un.varWords[1]); |
| 4383 | } |
| 4384 | else { |
| 4385 | lpfc_debugfs_disc_trc(phba->pport, |
| 4386 | LPFC_DISC_TRC_MBOX, |
| 4387 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 4388 | (uint32_t)mb->mbxCommand, |
| 4389 | mb->un.varWords[0], mb->un.varWords[1]); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4393 | psli->slistat.mbox_cmd++; |
| 4394 | evtctr = psli->slistat.mbox_event; |
| 4395 | |
| 4396 | /* next set own bit for the adapter and copy over command word */ |
| 4397 | mb->mbxOwner = OWN_CHIP; |
| 4398 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4399 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4400 | /* First copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4401 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4402 | } else { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4403 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4405 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | /* First copy mbox command data to HBA SLIM, skip past first |
| 4409 | word */ |
| 4410 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 4411 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 4412 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 4413 | |
| 4414 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4415 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4416 | to_slim = phba->MBslimaddr; |
| 4417 | writel(ldata, to_slim); |
| 4418 | readl(to_slim); /* flush */ |
| 4419 | |
| 4420 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 4421 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4422 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | |
| 4428 | switch (flag) { |
| 4429 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4430 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4432 | /* Interrupt board to do it */ |
| 4433 | writel(CA_MBATT, phba->CAregaddr); |
| 4434 | readl(phba->CAregaddr); /* flush */ |
| 4435 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4436 | break; |
| 4437 | |
| 4438 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4439 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4441 | /* Interrupt board to do it */ |
| 4442 | writel(CA_MBATT, phba->CAregaddr); |
| 4443 | readl(phba->CAregaddr); /* flush */ |
| 4444 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4445 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4446 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4447 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | word0 = le32_to_cpu(word0); |
| 4449 | } else { |
| 4450 | /* First read mbox status word */ |
| 4451 | word0 = readl(phba->MBslimaddr); |
| 4452 | } |
| 4453 | |
| 4454 | /* Read the HBA Host Attention Register */ |
| 4455 | ha_copy = readl(phba->HAregaddr); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4456 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 4457 | mb->mbxCommand) * |
| 4458 | 1000) + jiffies; |
| 4459 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4460 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4461 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 4462 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4464 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4465 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4466 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4467 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4468 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | /* Check if we took a mbox interrupt while we were |
| 4472 | polling */ |
| 4473 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 4474 | && (evtctr != psli->slistat.mbox_event)) |
| 4475 | break; |
| 4476 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4477 | if (i++ > 10) { |
| 4478 | spin_unlock_irqrestore(&phba->hbalock, |
| 4479 | drvr_flag); |
| 4480 | msleep(1); |
| 4481 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 4482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4484 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4485 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4486 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | word0 = le32_to_cpu(word0); |
| 4488 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 4489 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4490 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | /* Check real SLIM for any errors */ |
| 4492 | slimword0 = readl(phba->MBslimaddr); |
| 4493 | slimmb = (MAILBOX_t *) & slimword0; |
| 4494 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 4495 | && slimmb->mbxStatus) { |
| 4496 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4497 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4498 | word0 = slimword0; |
| 4499 | } |
| 4500 | } |
| 4501 | } else { |
| 4502 | /* First copy command data */ |
| 4503 | word0 = readl(phba->MBslimaddr); |
| 4504 | } |
| 4505 | /* Read the HBA Host Attention Register */ |
| 4506 | ha_copy = readl(phba->HAregaddr); |
| 4507 | } |
| 4508 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4509 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4511 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | } else { |
| 4513 | /* First copy command data */ |
| 4514 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 4515 | MAILBOX_CMD_SIZE); |
| 4516 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && |
| 4517 | pmbox->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4518 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4519 | phba->MBslimaddr + DMP_RSP_OFFSET, |
| 4520 | mb->un.varDmp.word_cnt); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | writel(HA_MBATT, phba->HAregaddr); |
| 4525 | readl(phba->HAregaddr); /* flush */ |
| 4526 | |
| 4527 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 4528 | status = mb->mbxStatus; |
| 4529 | } |
| 4530 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4531 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 4532 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4533 | |
| 4534 | out_not_finished: |
| 4535 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 4536 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4537 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 4538 | } |
| 4539 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | } |
| 4541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4542 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 4543 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 4544 | * @phba: Pointer to HBA context object. |
| 4545 | * @mboxq: Pointer to mailbox object. |
| 4546 | * |
| 4547 | * The function posts a mailbox to the port. The mailbox is expected |
| 4548 | * to be comletely filled in and ready for the port to operate on it. |
| 4549 | * This routine executes a synchronous completion operation on the |
| 4550 | * mailbox by polling for its completion. |
| 4551 | * |
| 4552 | * The caller must not be holding any locks when calling this routine. |
| 4553 | * |
| 4554 | * Returns: |
| 4555 | * MBX_SUCCESS - mailbox posted successfully |
| 4556 | * Any of the MBX error values. |
| 4557 | **/ |
| 4558 | static int |
| 4559 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 4560 | { |
| 4561 | int rc = MBX_SUCCESS; |
| 4562 | unsigned long iflag; |
| 4563 | uint32_t db_ready; |
| 4564 | uint32_t mcqe_status; |
| 4565 | uint32_t mbx_cmnd; |
| 4566 | unsigned long timeout; |
| 4567 | struct lpfc_sli *psli = &phba->sli; |
| 4568 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 4569 | struct lpfc_bmbx_create *mbox_rgn; |
| 4570 | struct dma_address *dma_address; |
| 4571 | struct lpfc_register bmbx_reg; |
| 4572 | |
| 4573 | /* |
| 4574 | * Only one mailbox can be active to the bootstrap mailbox region |
| 4575 | * at a time and there is no queueing provided. |
| 4576 | */ |
| 4577 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4578 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 4579 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4580 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4581 | "(%d):2532 Mailbox command x%x (x%x) " |
| 4582 | "cannot issue Data: x%x x%x\n", |
| 4583 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4584 | mboxq->u.mb.mbxCommand, |
| 4585 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4586 | psli->sli_flag, MBX_POLL); |
| 4587 | return MBXERR_ERROR; |
| 4588 | } |
| 4589 | /* The server grabs the token and owns it until release */ |
| 4590 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 4591 | phba->sli.mbox_active = mboxq; |
| 4592 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4593 | |
| 4594 | /* |
| 4595 | * Initialize the bootstrap memory region to avoid stale data areas |
| 4596 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 4597 | * the bmbx mailbox region. |
| 4598 | */ |
| 4599 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 4600 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 4601 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 4602 | sizeof(struct lpfc_mqe)); |
| 4603 | |
| 4604 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 4605 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 4606 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 4607 | |
| 4608 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) |
| 4609 | * 1000) + jiffies; |
| 4610 | do { |
| 4611 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 4612 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 4613 | if (!db_ready) |
| 4614 | msleep(2); |
| 4615 | |
| 4616 | if (time_after(jiffies, timeout)) { |
| 4617 | rc = MBXERR_ERROR; |
| 4618 | goto exit; |
| 4619 | } |
| 4620 | } while (!db_ready); |
| 4621 | |
| 4622 | /* Post the low mailbox dma address to the port. */ |
| 4623 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
| 4624 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) |
| 4625 | * 1000) + jiffies; |
| 4626 | do { |
| 4627 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 4628 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 4629 | if (!db_ready) |
| 4630 | msleep(2); |
| 4631 | |
| 4632 | if (time_after(jiffies, timeout)) { |
| 4633 | rc = MBXERR_ERROR; |
| 4634 | goto exit; |
| 4635 | } |
| 4636 | } while (!db_ready); |
| 4637 | |
| 4638 | /* |
| 4639 | * Read the CQ to ensure the mailbox has completed. |
| 4640 | * If so, update the mailbox status so that the upper layers |
| 4641 | * can complete the request normally. |
| 4642 | */ |
| 4643 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 4644 | sizeof(struct lpfc_mqe)); |
| 4645 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 4646 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 4647 | sizeof(struct lpfc_mcqe)); |
| 4648 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
| 4649 | |
| 4650 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ |
| 4651 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 4652 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); |
| 4653 | rc = MBXERR_ERROR; |
| 4654 | } |
| 4655 | |
| 4656 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4657 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " |
| 4658 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 4659 | " x%x x%x CQ: x%x x%x x%x x%x\n", |
| 4660 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4661 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4662 | bf_get(lpfc_mqe_status, mb), |
| 4663 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 4664 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 4665 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 4666 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 4667 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 4668 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 4669 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 4670 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4671 | mboxq->mcqe.trailer); |
| 4672 | exit: |
| 4673 | /* We are holding the token, no needed for lock when release */ |
| 4674 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 4675 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 4676 | phba->sli.mbox_active = NULL; |
| 4677 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 4678 | return rc; |
| 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 4683 | * @phba: Pointer to HBA context object. |
| 4684 | * @pmbox: Pointer to mailbox object. |
| 4685 | * @flag: Flag indicating how the mailbox need to be processed. |
| 4686 | * |
| 4687 | * This function is called by discovery code and HBA management code to submit |
| 4688 | * a mailbox command to firmware with SLI-4 interface spec. |
| 4689 | * |
| 4690 | * Return codes the caller owns the mailbox command after the return of the |
| 4691 | * function. |
| 4692 | **/ |
| 4693 | static int |
| 4694 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4695 | uint32_t flag) |
| 4696 | { |
| 4697 | struct lpfc_sli *psli = &phba->sli; |
| 4698 | unsigned long iflags; |
| 4699 | int rc; |
| 4700 | |
| 4701 | /* Detect polling mode and jump to a handler */ |
| 4702 | if (!phba->sli4_hba.intr_enable) { |
| 4703 | if (flag == MBX_POLL) |
| 4704 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 4705 | else |
| 4706 | rc = -EIO; |
| 4707 | if (rc != MBX_SUCCESS) |
| 4708 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4709 | "(%d):2541 Mailbox command x%x " |
| 4710 | "(x%x) cannot issue Data: x%x x%x\n", |
| 4711 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4712 | mboxq->u.mb.mbxCommand, |
| 4713 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4714 | psli->sli_flag, flag); |
| 4715 | return rc; |
| 4716 | } else if (flag == MBX_POLL) { |
| 4717 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4718 | "(%d):2542 Mailbox command x%x (x%x) " |
| 4719 | "cannot issue Data: x%x x%x\n", |
| 4720 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4721 | mboxq->u.mb.mbxCommand, |
| 4722 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4723 | psli->sli_flag, flag); |
| 4724 | return -EIO; |
| 4725 | } |
| 4726 | |
| 4727 | /* Now, interrupt mode asynchrous mailbox command */ |
| 4728 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 4729 | if (rc) { |
| 4730 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4731 | "(%d):2543 Mailbox command x%x (x%x) " |
| 4732 | "cannot issue Data: x%x x%x\n", |
| 4733 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4734 | mboxq->u.mb.mbxCommand, |
| 4735 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4736 | psli->sli_flag, flag); |
| 4737 | goto out_not_finished; |
| 4738 | } |
| 4739 | rc = lpfc_mbox_dev_check(phba); |
| 4740 | if (unlikely(rc)) { |
| 4741 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4742 | "(%d):2544 Mailbox command x%x (x%x) " |
| 4743 | "cannot issue Data: x%x x%x\n", |
| 4744 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4745 | mboxq->u.mb.mbxCommand, |
| 4746 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4747 | psli->sli_flag, flag); |
| 4748 | goto out_not_finished; |
| 4749 | } |
| 4750 | |
| 4751 | /* Put the mailbox command to the driver internal FIFO */ |
| 4752 | psli->slistat.mbox_busy++; |
| 4753 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4754 | lpfc_mbox_put(phba, mboxq); |
| 4755 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4756 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4757 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
| 4758 | "x%x (x%x) x%x x%x x%x\n", |
| 4759 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 4760 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4761 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4762 | phba->pport->port_state, |
| 4763 | psli->sli_flag, MBX_NOWAIT); |
| 4764 | /* Wake up worker thread to transport mailbox command from head */ |
| 4765 | lpfc_worker_wake_up(phba); |
| 4766 | |
| 4767 | return MBX_BUSY; |
| 4768 | |
| 4769 | out_not_finished: |
| 4770 | return MBX_NOT_FINISHED; |
| 4771 | } |
| 4772 | |
| 4773 | /** |
| 4774 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 4775 | * @phba: Pointer to HBA context object. |
| 4776 | * |
| 4777 | * This function is called by worker thread to send a mailbox command to |
| 4778 | * SLI4 HBA firmware. |
| 4779 | * |
| 4780 | **/ |
| 4781 | int |
| 4782 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 4783 | { |
| 4784 | struct lpfc_sli *psli = &phba->sli; |
| 4785 | LPFC_MBOXQ_t *mboxq; |
| 4786 | int rc = MBX_SUCCESS; |
| 4787 | unsigned long iflags; |
| 4788 | struct lpfc_mqe *mqe; |
| 4789 | uint32_t mbx_cmnd; |
| 4790 | |
| 4791 | /* Check interrupt mode before post async mailbox command */ |
| 4792 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 4793 | return MBX_NOT_FINISHED; |
| 4794 | |
| 4795 | /* Check for mailbox command service token */ |
| 4796 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4797 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 4798 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4799 | return MBX_NOT_FINISHED; |
| 4800 | } |
| 4801 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 4802 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4803 | return MBX_NOT_FINISHED; |
| 4804 | } |
| 4805 | if (unlikely(phba->sli.mbox_active)) { |
| 4806 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4807 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4808 | "0384 There is pending active mailbox cmd\n"); |
| 4809 | return MBX_NOT_FINISHED; |
| 4810 | } |
| 4811 | /* Take the mailbox command service token */ |
| 4812 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 4813 | |
| 4814 | /* Get the next mailbox command from head of queue */ |
| 4815 | mboxq = lpfc_mbox_get(phba); |
| 4816 | |
| 4817 | /* If no more mailbox command waiting for post, we're done */ |
| 4818 | if (!mboxq) { |
| 4819 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 4820 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4821 | return MBX_SUCCESS; |
| 4822 | } |
| 4823 | phba->sli.mbox_active = mboxq; |
| 4824 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4825 | |
| 4826 | /* Check device readiness for posting mailbox command */ |
| 4827 | rc = lpfc_mbox_dev_check(phba); |
| 4828 | if (unlikely(rc)) |
| 4829 | /* Driver clean routine will clean up pending mailbox */ |
| 4830 | goto out_not_finished; |
| 4831 | |
| 4832 | /* Prepare the mbox command to be posted */ |
| 4833 | mqe = &mboxq->u.mqe; |
| 4834 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 4835 | |
| 4836 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 4837 | mod_timer(&psli->mbox_tmo, (jiffies + |
| 4838 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); |
| 4839 | |
| 4840 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4841 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " |
| 4842 | "x%x x%x\n", |
| 4843 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 4844 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4845 | phba->pport->port_state, psli->sli_flag); |
| 4846 | |
| 4847 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 4848 | if (mboxq->vport) { |
| 4849 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 4850 | LPFC_DISC_TRC_MBOX_VPORT, |
| 4851 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 4852 | mbx_cmnd, mqe->un.mb_words[0], |
| 4853 | mqe->un.mb_words[1]); |
| 4854 | } else { |
| 4855 | lpfc_debugfs_disc_trc(phba->pport, |
| 4856 | LPFC_DISC_TRC_MBOX, |
| 4857 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 4858 | mbx_cmnd, mqe->un.mb_words[0], |
| 4859 | mqe->un.mb_words[1]); |
| 4860 | } |
| 4861 | } |
| 4862 | psli->slistat.mbox_cmd++; |
| 4863 | |
| 4864 | /* Post the mailbox command to the port */ |
| 4865 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 4866 | if (rc != MBX_SUCCESS) { |
| 4867 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 4868 | "(%d):2533 Mailbox command x%x (x%x) " |
| 4869 | "cannot issue Data: x%x x%x\n", |
| 4870 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4871 | mboxq->u.mb.mbxCommand, |
| 4872 | lpfc_sli4_mbox_opcode_get(phba, mboxq), |
| 4873 | psli->sli_flag, MBX_NOWAIT); |
| 4874 | goto out_not_finished; |
| 4875 | } |
| 4876 | |
| 4877 | return rc; |
| 4878 | |
| 4879 | out_not_finished: |
| 4880 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4881 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 4882 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 4883 | /* Release the token */ |
| 4884 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 4885 | phba->sli.mbox_active = NULL; |
| 4886 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4887 | |
| 4888 | return MBX_NOT_FINISHED; |
| 4889 | } |
| 4890 | |
| 4891 | /** |
| 4892 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 4893 | * @phba: Pointer to HBA context object. |
| 4894 | * @pmbox: Pointer to mailbox object. |
| 4895 | * @flag: Flag indicating how the mailbox need to be processed. |
| 4896 | * |
| 4897 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 4898 | * the API jump table function pointer from the lpfc_hba struct. |
| 4899 | * |
| 4900 | * Return codes the caller owns the mailbox command after the return of the |
| 4901 | * function. |
| 4902 | **/ |
| 4903 | int |
| 4904 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 4905 | { |
| 4906 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 4907 | } |
| 4908 | |
| 4909 | /** |
| 4910 | * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table |
| 4911 | * @phba: The hba struct for which this call is being executed. |
| 4912 | * @dev_grp: The HBA PCI-Device group number. |
| 4913 | * |
| 4914 | * This routine sets up the mbox interface API function jump table in @phba |
| 4915 | * struct. |
| 4916 | * Returns: 0 - success, -ENODEV - failure. |
| 4917 | **/ |
| 4918 | int |
| 4919 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4920 | { |
| 4921 | |
| 4922 | switch (dev_grp) { |
| 4923 | case LPFC_PCI_DEV_LP: |
| 4924 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 4925 | phba->lpfc_sli_handle_slow_ring_event = |
| 4926 | lpfc_sli_handle_slow_ring_event_s3; |
| 4927 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 4928 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 4929 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 4930 | break; |
| 4931 | case LPFC_PCI_DEV_OC: |
| 4932 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 4933 | phba->lpfc_sli_handle_slow_ring_event = |
| 4934 | lpfc_sli_handle_slow_ring_event_s4; |
| 4935 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 4936 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 4937 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 4938 | break; |
| 4939 | default: |
| 4940 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4941 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 4942 | dev_grp); |
| 4943 | return -ENODEV; |
| 4944 | break; |
| 4945 | } |
| 4946 | return 0; |
| 4947 | } |
| 4948 | |
| 4949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4950 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4951 | * @phba: Pointer to HBA context object. |
| 4952 | * @pring: Pointer to driver SLI ring object. |
| 4953 | * @piocb: Pointer to address of newly added command iocb. |
| 4954 | * |
| 4955 | * This function is called with hbalock held to add a command |
| 4956 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 4957 | * to the ring. |
| 4958 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4959 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4960 | __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] | 4961 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | { |
| 4963 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 4964 | list_add_tail(&piocb->list, &pring->txq); |
| 4965 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | } |
| 4967 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4969 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4970 | * @phba: Pointer to HBA context object. |
| 4971 | * @pring: Pointer to driver SLI ring object. |
| 4972 | * @piocb: Pointer to address of newly added command iocb. |
| 4973 | * |
| 4974 | * This function is called with hbalock held before a new |
| 4975 | * iocb is submitted to the firmware. This function checks |
| 4976 | * txq to flush the iocbs in txq to Firmware before |
| 4977 | * submitting new iocbs to the Firmware. |
| 4978 | * If there are iocbs in the txq which need to be submitted |
| 4979 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 4980 | * of the txq after dequeuing it from txq. |
| 4981 | * If there is no iocb in the txq then the function will return |
| 4982 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 4983 | * *piocb to find if there are more commands in the txq. |
| 4984 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4985 | static struct lpfc_iocbq * |
| 4986 | 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] | 4987 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | { |
| 4989 | struct lpfc_iocbq * nextiocb; |
| 4990 | |
| 4991 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 4992 | if (!nextiocb) { |
| 4993 | nextiocb = *piocb; |
| 4994 | *piocb = NULL; |
| 4995 | } |
| 4996 | |
| 4997 | return nextiocb; |
| 4998 | } |
| 4999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5000 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5001 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5002 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5003 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5004 | * @piocb: Pointer to command iocb. |
| 5005 | * @flag: Flag indicating if this command can be put into txq. |
| 5006 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5007 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 5008 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 5009 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 5010 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 5011 | * this function allows only iocbs for posting buffers. This function finds |
| 5012 | * next available slot in the command ring and posts the command to the |
| 5013 | * available slot and writes the port attention register to request HBA start |
| 5014 | * processing new iocb. If there is no slot available in the ring and |
| 5015 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 5016 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5017 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5018 | * This function is called with hbalock held. The function will return success |
| 5019 | * after it successfully submit the iocb to firmware or after adding to the |
| 5020 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5021 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5022 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5023 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 5025 | { |
| 5026 | struct lpfc_iocbq *nextiocb; |
| 5027 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5028 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5029 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5030 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 5031 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 5032 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 5033 | lpfc_printf_log(phba, KERN_ERR, |
| 5034 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5035 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5036 | piocb->iocb.ulpCommand); |
| 5037 | dump_stack(); |
| 5038 | return IOCB_ERROR; |
| 5039 | } |
| 5040 | |
| 5041 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 5042 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 5043 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 5044 | return IOCB_ERROR; |
| 5045 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5046 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 5047 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 5048 | return IOCB_ERROR; |
| 5049 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | /* |
| 5051 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 5052 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5053 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5054 | return IOCB_ERROR; |
| 5055 | |
| 5056 | /* |
| 5057 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5058 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5059 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5060 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5061 | goto iocb_busy; |
| 5062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5063 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5064 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5065 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5066 | * can be issued if the link is not up. |
| 5067 | */ |
| 5068 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5069 | case CMD_GEN_REQUEST64_CR: |
| 5070 | case CMD_GEN_REQUEST64_CX: |
| 5071 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 5072 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
| 5073 | FC_FCP_CMND) || |
| 5074 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 5075 | MENLO_TRANSPORT_TYPE)) |
| 5076 | |
| 5077 | goto iocb_busy; |
| 5078 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5079 | case CMD_QUE_RING_BUF_CN: |
| 5080 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5081 | /* |
| 5082 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 5083 | * completion, iocb_cmpl MUST be 0. |
| 5084 | */ |
| 5085 | if (piocb->iocb_cmpl) |
| 5086 | piocb->iocb_cmpl = NULL; |
| 5087 | /*FALLTHROUGH*/ |
| 5088 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5089 | case CMD_CLOSE_XRI_CN: |
| 5090 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5091 | break; |
| 5092 | default: |
| 5093 | goto iocb_busy; |
| 5094 | } |
| 5095 | |
| 5096 | /* |
| 5097 | * For FCP commands, we must be in a state where we can process link |
| 5098 | * attention events. |
| 5099 | */ |
| 5100 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5101 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5102 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5103 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 5106 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 5107 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 5108 | |
| 5109 | if (iocb) |
| 5110 | lpfc_sli_update_ring(phba, pring); |
| 5111 | else |
| 5112 | lpfc_sli_update_full_ring(phba, pring); |
| 5113 | |
| 5114 | if (!piocb) |
| 5115 | return IOCB_SUCCESS; |
| 5116 | |
| 5117 | goto out_busy; |
| 5118 | |
| 5119 | iocb_busy: |
| 5120 | pring->stats.iocb_cmd_delay++; |
| 5121 | |
| 5122 | out_busy: |
| 5123 | |
| 5124 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5125 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5126 | return IOCB_SUCCESS; |
| 5127 | } |
| 5128 | |
| 5129 | return IOCB_BUSY; |
| 5130 | } |
| 5131 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5132 | /** |
| 5133 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 5134 | * |
| 5135 | * This routine wraps the actual lockless version for issusing IOCB function |
| 5136 | * pointer from the lpfc_hba struct. |
| 5137 | * |
| 5138 | * Return codes: |
| 5139 | * IOCB_ERROR - Error |
| 5140 | * IOCB_SUCCESS - Success |
| 5141 | * IOCB_BUSY - Busy |
| 5142 | **/ |
| 5143 | static inline int |
| 5144 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 5145 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 5146 | { |
| 5147 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 5148 | } |
| 5149 | |
| 5150 | /** |
| 5151 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table |
| 5152 | * @phba: The hba struct for which this call is being executed. |
| 5153 | * @dev_grp: The HBA PCI-Device group number. |
| 5154 | * |
| 5155 | * This routine sets up the SLI interface API function jump table in @phba |
| 5156 | * struct. |
| 5157 | * Returns: 0 - success, -ENODEV - failure. |
| 5158 | **/ |
| 5159 | int |
| 5160 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5161 | { |
| 5162 | |
| 5163 | switch (dev_grp) { |
| 5164 | case LPFC_PCI_DEV_LP: |
| 5165 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 5166 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 5167 | break; |
| 5168 | default: |
| 5169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5170 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 5171 | dev_grp); |
| 5172 | return -ENODEV; |
| 5173 | break; |
| 5174 | } |
| 5175 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 5176 | return 0; |
| 5177 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5178 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5180 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5181 | * @phba: Pointer to HBA context object. |
| 5182 | * @pring: Pointer to driver SLI ring object. |
| 5183 | * @piocb: Pointer to command iocb. |
| 5184 | * @flag: Flag indicating if this command can be put into txq. |
| 5185 | * |
| 5186 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 5187 | * function. This function gets the hbalock and calls |
| 5188 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 5189 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 5190 | * functions which do not hold hbalock. |
| 5191 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5192 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5193 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5194 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 5195 | { |
| 5196 | unsigned long iflags; |
| 5197 | int rc; |
| 5198 | |
| 5199 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5200 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5201 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 5202 | |
| 5203 | return rc; |
| 5204 | } |
| 5205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5207 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5208 | * @phba: Pointer to HBA context object. |
| 5209 | * |
| 5210 | * This function is called while driver attaches with the |
| 5211 | * HBA to setup the extra ring. The extra ring is used |
| 5212 | * only when driver needs to support target mode functionality |
| 5213 | * or IP over FC functionalities. |
| 5214 | * |
| 5215 | * This function is called with no lock held. |
| 5216 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 5217 | static int |
| 5218 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 5219 | { |
| 5220 | struct lpfc_sli *psli; |
| 5221 | struct lpfc_sli_ring *pring; |
| 5222 | |
| 5223 | psli = &phba->sli; |
| 5224 | |
| 5225 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5226 | |
| 5227 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 5228 | pring = &psli->ring[psli->fcp_ring]; |
| 5229 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 5230 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 5231 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 5232 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 5233 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5234 | /* and give them to the extra ring */ |
| 5235 | pring = &psli->ring[psli->extra_ring]; |
| 5236 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 5237 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 5238 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 5239 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 5240 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 5241 | |
| 5242 | /* Setup default profile for this ring */ |
| 5243 | pring->iotag_max = 4096; |
| 5244 | pring->num_mask = 1; |
| 5245 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5246 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 5247 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 5248 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 5249 | return 0; |
| 5250 | } |
| 5251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5253 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5254 | * @phba: Pointer to HBA context object. |
| 5255 | * @pring: Pointer to driver SLI ring object. |
| 5256 | * @iocbq: Pointer to iocb object. |
| 5257 | * |
| 5258 | * This function is called by the slow ring event handler |
| 5259 | * function when there is an ASYNC event iocb in the ring. |
| 5260 | * This function is called with no lock held. |
| 5261 | * Currently this function handles only temperature related |
| 5262 | * ASYNC events. The function decodes the temperature sensor |
| 5263 | * event message and posts events for the management applications. |
| 5264 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5265 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5266 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 5267 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 5268 | { |
| 5269 | IOCB_t *icmd; |
| 5270 | uint16_t evt_code; |
| 5271 | uint16_t temp; |
| 5272 | struct temp_event temp_event_data; |
| 5273 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5274 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5275 | |
| 5276 | icmd = &iocbq->iocb; |
| 5277 | evt_code = icmd->un.asyncstat.evt_code; |
| 5278 | temp = icmd->ulpContext; |
| 5279 | |
| 5280 | if ((evt_code != ASYNC_TEMP_WARN) && |
| 5281 | (evt_code != ASYNC_TEMP_SAFE)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5282 | iocb_w = (uint32_t *) icmd; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5283 | lpfc_printf_log(phba, |
| 5284 | KERN_ERR, |
| 5285 | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 5286 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5287 | " evt_code 0x%x \n" |
| 5288 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 5289 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 5290 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 5291 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5292 | pring->ringno, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5293 | icmd->un.asyncstat.evt_code, |
| 5294 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 5295 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 5296 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 5297 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 5298 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5299 | return; |
| 5300 | } |
| 5301 | temp_event_data.data = (uint32_t)temp; |
| 5302 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5303 | if (evt_code == ASYNC_TEMP_WARN) { |
| 5304 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5305 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5306 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5307 | LOG_TEMP, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 5308 | "0347 Adapter is very hot, please take " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5309 | "corrective action. temperature : %d Celsius\n", |
| 5310 | temp); |
| 5311 | } |
| 5312 | if (evt_code == ASYNC_TEMP_SAFE) { |
| 5313 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5314 | lpfc_printf_log(phba, |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5315 | KERN_ERR, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5316 | LOG_TEMP, |
| 5317 | "0340 Adapter temperature is OK now. " |
| 5318 | "temperature : %d Celsius\n", |
| 5319 | temp); |
| 5320 | } |
| 5321 | |
| 5322 | /* Send temperature change event to applications */ |
| 5323 | shost = lpfc_shost_from_vport(phba->pport); |
| 5324 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5325 | sizeof(temp_event_data), (char *) &temp_event_data, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5326 | LPFC_NL_VENDOR_ID); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5327 | |
| 5328 | } |
| 5329 | |
| 5330 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5331 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5332 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5333 | * @phba: Pointer to HBA context object. |
| 5334 | * |
| 5335 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 5336 | * number of iocbs per ring and iotags. This function is |
| 5337 | * called while driver attach to the HBA and before the |
| 5338 | * interrupts are enabled. So there is no need for locking. |
| 5339 | * |
| 5340 | * This function always returns 0. |
| 5341 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5342 | int |
| 5343 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 5344 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5345 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | struct lpfc_sli *psli = &phba->sli; |
| 5347 | struct lpfc_sli_ring *pring; |
| 5348 | |
| 5349 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 5350 | psli->sli_flag = 0; |
| 5351 | psli->fcp_ring = LPFC_FCP_RING; |
| 5352 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5353 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5354 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5355 | psli->iocbq_lookup = NULL; |
| 5356 | psli->iocbq_lookup_len = 0; |
| 5357 | psli->last_iotag = 0; |
| 5358 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5359 | for (i = 0; i < psli->num_rings; i++) { |
| 5360 | pring = &psli->ring[i]; |
| 5361 | switch (i) { |
| 5362 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 5363 | /* numCiocb and numRiocb are used in config_port */ |
| 5364 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 5365 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 5366 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 5367 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 5368 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 5369 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5370 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5371 | SLI3_IOCB_CMD_SIZE : |
| 5372 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5373 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5374 | SLI3_IOCB_RSP_SIZE : |
| 5375 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5376 | pring->iotag_ctr = 0; |
| 5377 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5378 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5379 | pring->fast_iotag = pring->iotag_max; |
| 5380 | pring->num_mask = 0; |
| 5381 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 5382 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5383 | /* numCiocb and numRiocb are used in config_port */ |
| 5384 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 5385 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5386 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5387 | SLI3_IOCB_CMD_SIZE : |
| 5388 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5389 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5390 | SLI3_IOCB_RSP_SIZE : |
| 5391 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5392 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5393 | pring->num_mask = 0; |
| 5394 | break; |
| 5395 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 5396 | /* numCiocb and numRiocb are used in config_port */ |
| 5397 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 5398 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5399 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5400 | SLI3_IOCB_CMD_SIZE : |
| 5401 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5402 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5403 | SLI3_IOCB_RSP_SIZE : |
| 5404 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5405 | pring->fast_iotag = 0; |
| 5406 | pring->iotag_ctr = 0; |
| 5407 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 5408 | pring->lpfc_sli_rcv_async_status = |
| 5409 | lpfc_sli_async_event_handler; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5410 | pring->num_mask = 4; |
| 5411 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 5412 | pring->prt[0].rctl = FC_ELS_REQ; |
| 5413 | pring->prt[0].type = FC_ELS_DATA; |
| 5414 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5415 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5416 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 5417 | pring->prt[1].rctl = FC_ELS_RSP; |
| 5418 | pring->prt[1].type = FC_ELS_DATA; |
| 5419 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5420 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5421 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 5422 | /* NameServer Inquiry */ |
| 5423 | pring->prt[2].rctl = FC_UNSOL_CTL; |
| 5424 | /* NameServer */ |
| 5425 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; |
| 5426 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5427 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5428 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 5429 | /* NameServer response */ |
| 5430 | pring->prt[3].rctl = FC_SOL_CTL; |
| 5431 | /* NameServer */ |
| 5432 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; |
| 5433 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5434 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | break; |
| 5436 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5437 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5438 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5439 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5440 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5441 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5442 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 5443 | "SLI2 SLIM Data: x%x x%lx\n", |
| 5444 | phba->brd_no, totiocbsize, |
| 5445 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5446 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 5447 | if (phba->cfg_multi_ring_support == 2) |
| 5448 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5449 | |
| 5450 | return 0; |
| 5451 | } |
| 5452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5454 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5455 | * @phba: Pointer to HBA context object. |
| 5456 | * |
| 5457 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 5458 | * ring. This function also initializes ring indices of each ring. |
| 5459 | * This function is called during the initialization of the SLI |
| 5460 | * interface of an HBA. |
| 5461 | * This function is called with no lock held and always returns |
| 5462 | * 1. |
| 5463 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5464 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5465 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | { |
| 5467 | struct lpfc_sli *psli; |
| 5468 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5469 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5470 | |
| 5471 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5472 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5473 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5474 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5475 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 5476 | for (i = 0; i < psli->num_rings; i++) { |
| 5477 | pring = &psli->ring[i]; |
| 5478 | pring->ringno = i; |
| 5479 | pring->next_cmdidx = 0; |
| 5480 | pring->local_getidx = 0; |
| 5481 | pring->cmdidx = 0; |
| 5482 | INIT_LIST_HEAD(&pring->txq); |
| 5483 | INIT_LIST_HEAD(&pring->txcmplq); |
| 5484 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 5485 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5486 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5487 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5488 | spin_unlock_irq(&phba->hbalock); |
| 5489 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | } |
| 5491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5493 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5494 | * @vport: Pointer to virtual port object. |
| 5495 | * |
| 5496 | * lpfc_sli_host_down is called to clean up the resources |
| 5497 | * associated with a vport before destroying virtual |
| 5498 | * port data structures. |
| 5499 | * This function does following operations: |
| 5500 | * - Free discovery resources associated with this virtual |
| 5501 | * port. |
| 5502 | * - Free iocbs associated with this virtual port in |
| 5503 | * the txq. |
| 5504 | * - Send abort for all iocb commands associated with this |
| 5505 | * vport in txcmplq. |
| 5506 | * |
| 5507 | * This function is called with no lock held and always returns 1. |
| 5508 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5509 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5510 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 5511 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5512 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5513 | struct lpfc_hba *phba = vport->phba; |
| 5514 | struct lpfc_sli *psli = &phba->sli; |
| 5515 | struct lpfc_sli_ring *pring; |
| 5516 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5517 | int i; |
| 5518 | unsigned long flags = 0; |
| 5519 | uint16_t prev_pring_flag; |
| 5520 | |
| 5521 | lpfc_cleanup_discovery_resources(vport); |
| 5522 | |
| 5523 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5524 | for (i = 0; i < psli->num_rings; i++) { |
| 5525 | pring = &psli->ring[i]; |
| 5526 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5527 | /* Only slow rings */ |
| 5528 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5529 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5530 | /* Set the lpfc data pending flag */ |
| 5531 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 5532 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5533 | /* |
| 5534 | * Error everything on the txq since these iocbs have not been |
| 5535 | * given to the FW yet. |
| 5536 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5537 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 5538 | if (iocb->vport != vport) |
| 5539 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5540 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5541 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | /* Next issue ABTS for everything on the txcmplq */ |
| 5545 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 5546 | list) { |
| 5547 | if (iocb->vport != vport) |
| 5548 | continue; |
| 5549 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 5550 | } |
| 5551 | |
| 5552 | pring->flag = prev_pring_flag; |
| 5553 | } |
| 5554 | |
| 5555 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5556 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5557 | /* Cancel all the IOCBs from the completions list */ |
| 5558 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5559 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5560 | return 1; |
| 5561 | } |
| 5562 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5563 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5564 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5565 | * @phba: Pointer to HBA context object. |
| 5566 | * |
| 5567 | * This function cleans up all iocb, buffers, mailbox commands |
| 5568 | * while shutting down the HBA. This function is called with no |
| 5569 | * lock held and always returns 1. |
| 5570 | * This function does the following to cleanup driver resources: |
| 5571 | * - Free discovery resources for each virtual port |
| 5572 | * - Cleanup any pending fabric iocbs |
| 5573 | * - Iterate through the iocb txq and free each entry |
| 5574 | * in the list. |
| 5575 | * - Free up any buffer posted to the HBA |
| 5576 | * - Free mailbox commands in the mailbox queue. |
| 5577 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5578 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5579 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5580 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5581 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5582 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5583 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5584 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5585 | LPFC_MBOXQ_t *pmb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5586 | int i; |
| 5587 | unsigned long flags = 0; |
| 5588 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5589 | lpfc_hba_down_prep(phba); |
| 5590 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5591 | lpfc_fabric_abort_hba(phba); |
| 5592 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5593 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5594 | for (i = 0; i < psli->num_rings; i++) { |
| 5595 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5596 | /* Only slow rings */ |
| 5597 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5598 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5599 | /* Set the lpfc data pending flag */ |
| 5600 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 5601 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5602 | |
| 5603 | /* |
| 5604 | * Error everything on the txq since these iocbs have not been |
| 5605 | * given to the FW yet. |
| 5606 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5607 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5608 | pring->txq_cnt = 0; |
| 5609 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5610 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5611 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5612 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5613 | /* Cancel all the IOCBs from the completions list */ |
| 5614 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 5615 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5616 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5617 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5618 | list_splice_init(&phba->elsbuf, &completions); |
| 5619 | phba->elsbuf_cnt = 0; |
| 5620 | phba->elsbuf_prev_cnt = 0; |
| 5621 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5622 | |
| 5623 | while (!list_empty(&completions)) { |
| 5624 | list_remove_head(&completions, buf_ptr, |
| 5625 | struct lpfc_dmabuf, list); |
| 5626 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 5627 | kfree(buf_ptr); |
| 5628 | } |
| 5629 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5630 | /* Return any active mbox cmds */ |
| 5631 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5632 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 5633 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5634 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 5635 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5636 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 5637 | return 1; |
| 5638 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5639 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 5640 | /** |
| 5641 | * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA |
| 5642 | * @phba: Pointer to HBA context object. |
| 5643 | * |
| 5644 | * This function cleans up all queues, iocb, buffers, mailbox commands while |
| 5645 | * shutting down the SLI4 HBA FCoE function. This function is called with no |
| 5646 | * lock held and always returns 1. |
| 5647 | * |
| 5648 | * This function does the following to cleanup driver FCoE function resources: |
| 5649 | * - Free discovery resources for each virtual port |
| 5650 | * - Cleanup any pending fabric iocbs |
| 5651 | * - Iterate through the iocb txq and free each entry in the list. |
| 5652 | * - Free up any buffer posted to the HBA. |
| 5653 | * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc. |
| 5654 | * - Free mailbox commands in the mailbox queue. |
| 5655 | **/ |
| 5656 | int |
| 5657 | lpfc_sli4_hba_down(struct lpfc_hba *phba) |
| 5658 | { |
| 5659 | /* Stop the SLI4 device port */ |
| 5660 | lpfc_stop_port(phba); |
| 5661 | |
| 5662 | /* Tear down the queues in the HBA */ |
| 5663 | lpfc_sli4_queue_unset(phba); |
| 5664 | |
| 5665 | /* unregister default FCFI from the HBA */ |
| 5666 | lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi); |
| 5667 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5668 | return 1; |
| 5669 | } |
| 5670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5672 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5673 | * @srcp: Source memory pointer. |
| 5674 | * @destp: Destination memory pointer. |
| 5675 | * @cnt: Number of words required to be copied. |
| 5676 | * |
| 5677 | * This function is used for copying data between driver memory |
| 5678 | * and the SLI memory. This function also changes the endianness |
| 5679 | * of each word if native endianness is different from SLI |
| 5680 | * endianness. This function can be called with or without |
| 5681 | * lock. |
| 5682 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5683 | void |
| 5684 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 5685 | { |
| 5686 | uint32_t *src = srcp; |
| 5687 | uint32_t *dest = destp; |
| 5688 | uint32_t ldata; |
| 5689 | int i; |
| 5690 | |
| 5691 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 5692 | ldata = *src; |
| 5693 | ldata = le32_to_cpu(ldata); |
| 5694 | *dest = ldata; |
| 5695 | src++; |
| 5696 | dest++; |
| 5697 | } |
| 5698 | } |
| 5699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5700 | |
| 5701 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5702 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5703 | * @phba: Pointer to HBA context object. |
| 5704 | * @pring: Pointer to driver SLI ring object. |
| 5705 | * @mp: Pointer to driver buffer object. |
| 5706 | * |
| 5707 | * This function is called with no lock held. |
| 5708 | * It always return zero after adding the buffer to the postbufq |
| 5709 | * buffer list. |
| 5710 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5711 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5712 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5713 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5714 | { |
| 5715 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 5716 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5717 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5718 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5719 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5720 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5721 | return 0; |
| 5722 | } |
| 5723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5725 | * 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] | 5726 | * @phba: Pointer to HBA context object. |
| 5727 | * |
| 5728 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 5729 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 5730 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 5731 | * does not conflict with tags of buffer posted for unsolicited events. |
| 5732 | * The function returns the allocated tag. The function is called with |
| 5733 | * no locks held. |
| 5734 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 5735 | uint32_t |
| 5736 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 5737 | { |
| 5738 | spin_lock_irq(&phba->hbalock); |
| 5739 | phba->buffer_tag_count++; |
| 5740 | /* |
| 5741 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 5742 | * a tag assigned by HBQ. |
| 5743 | */ |
| 5744 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 5745 | spin_unlock_irq(&phba->hbalock); |
| 5746 | return phba->buffer_tag_count; |
| 5747 | } |
| 5748 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5749 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5750 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5751 | * @phba: Pointer to HBA context object. |
| 5752 | * @pring: Pointer to driver SLI ring object. |
| 5753 | * @tag: Buffer tag. |
| 5754 | * |
| 5755 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 5756 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 5757 | * iocb is posted to the response ring with the tag of the buffer. |
| 5758 | * This function searches the pring->postbufq list using the tag |
| 5759 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 5760 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 5761 | * buffer is returned to the caller else NULL is returned. |
| 5762 | * This function is called with no lock held. |
| 5763 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 5764 | struct lpfc_dmabuf * |
| 5765 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5766 | uint32_t tag) |
| 5767 | { |
| 5768 | struct lpfc_dmabuf *mp, *next_mp; |
| 5769 | struct list_head *slp = &pring->postbufq; |
| 5770 | |
| 5771 | /* Search postbufq, from the begining, looking for a match on tag */ |
| 5772 | spin_lock_irq(&phba->hbalock); |
| 5773 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 5774 | if (mp->buffer_tag == tag) { |
| 5775 | list_del_init(&mp->list); |
| 5776 | pring->postbufq_cnt--; |
| 5777 | spin_unlock_irq(&phba->hbalock); |
| 5778 | return mp; |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | spin_unlock_irq(&phba->hbalock); |
| 5783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5784 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 5785 | "ring %d Data x%lx x%p x%p x%x\n", |
| 5786 | pring->ringno, (unsigned long) tag, |
| 5787 | slp->next, slp->prev, pring->postbufq_cnt); |
| 5788 | |
| 5789 | return NULL; |
| 5790 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5793 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5794 | * @phba: Pointer to HBA context object. |
| 5795 | * @pring: Pointer to driver SLI ring object. |
| 5796 | * @phys: DMA address of the buffer. |
| 5797 | * |
| 5798 | * This function searches the buffer list using the dma_address |
| 5799 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 5800 | * corresponding to the dma_address. The function returns the |
| 5801 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 5802 | * This function is called by the ct and els unsolicited event |
| 5803 | * handlers to get the buffer associated with the unsolicited |
| 5804 | * event. |
| 5805 | * |
| 5806 | * This function is called with no lock held. |
| 5807 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5808 | struct lpfc_dmabuf * |
| 5809 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5810 | dma_addr_t phys) |
| 5811 | { |
| 5812 | struct lpfc_dmabuf *mp, *next_mp; |
| 5813 | struct list_head *slp = &pring->postbufq; |
| 5814 | |
| 5815 | /* Search postbufq, from the begining, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5816 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5817 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 5818 | if (mp->phys == phys) { |
| 5819 | list_del_init(&mp->list); |
| 5820 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5821 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5822 | return mp; |
| 5823 | } |
| 5824 | } |
| 5825 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5826 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5828 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5829 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5830 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5831 | slp->next, slp->prev, pring->postbufq_cnt); |
| 5832 | return NULL; |
| 5833 | } |
| 5834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5836 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5837 | * @phba: Pointer to HBA context object. |
| 5838 | * @cmdiocb: Pointer to driver command iocb object. |
| 5839 | * @rspiocb: Pointer to driver response iocb object. |
| 5840 | * |
| 5841 | * This function is the completion handler for the abort iocbs for |
| 5842 | * ELS commands. This function is called from the ELS ring event |
| 5843 | * handler with no lock held. This function frees memory resources |
| 5844 | * associated with the abort iocb. |
| 5845 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5846 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5847 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5848 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5849 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5850 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5851 | uint16_t abort_iotag, abort_context; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5852 | struct lpfc_iocbq *abort_iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5853 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5854 | |
| 5855 | abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5856 | |
| 5857 | if (irsp->ulpStatus) { |
| 5858 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 5859 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 5860 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5861 | spin_lock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5862 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
| 5863 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; |
| 5864 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5865 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5866 | "0327 Cannot abort els iocb %p " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5867 | "with tag %x context %x, abort status %x, " |
| 5868 | "abort code %x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5869 | abort_iocb, abort_iotag, abort_context, |
| 5870 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5871 | |
| 5872 | /* |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5873 | * If the iocb is not found in Firmware queue the iocb |
| 5874 | * might have completed already. Do not free it again. |
| 5875 | */ |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 5876 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5877 | spin_unlock_irq(&phba->hbalock); |
| 5878 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 5879 | return; |
| 5880 | } |
| 5881 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5882 | * make sure we have the right iocbq before taking it |
| 5883 | * off the txcmplq and try to call completion routine. |
| 5884 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5885 | if (!abort_iocb || |
| 5886 | abort_iocb->iocb.ulpContext != abort_context || |
| 5887 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) |
| 5888 | spin_unlock_irq(&phba->hbalock); |
| 5889 | else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5890 | list_del_init(&abort_iocb->list); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5891 | pring->txcmplq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5892 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5893 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 5894 | /* Firmware could still be in progress of DMAing |
| 5895 | * payload, so don't free data buffer till after |
| 5896 | * a hbeat. |
| 5897 | */ |
| 5898 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; |
| 5899 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5900 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 5901 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5902 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5903 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 5904 | } |
| 5905 | } |
| 5906 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5907 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5908 | return; |
| 5909 | } |
| 5910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5912 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5913 | * @phba: Pointer to HBA context object. |
| 5914 | * @cmdiocb: Pointer to driver command iocb object. |
| 5915 | * @rspiocb: Pointer to driver response iocb object. |
| 5916 | * |
| 5917 | * The function is called from SLI ring event handler with no |
| 5918 | * lock held. This function is the completion handler for ELS commands |
| 5919 | * which are aborted. The function frees memory resources used for |
| 5920 | * the aborted ELS commands. |
| 5921 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5922 | static void |
| 5923 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5924 | struct lpfc_iocbq *rspiocb) |
| 5925 | { |
| 5926 | IOCB_t *irsp = &rspiocb->iocb; |
| 5927 | |
| 5928 | /* ELS cmd tag <ulpIoTag> completes */ |
| 5929 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5930 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5932 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5933 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5934 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 5935 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 5936 | else |
| 5937 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5938 | return; |
| 5939 | } |
| 5940 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5941 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5942 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5943 | * @phba: Pointer to HBA context object. |
| 5944 | * @pring: Pointer to driver SLI ring object. |
| 5945 | * @cmdiocb: Pointer to driver command iocb object. |
| 5946 | * |
| 5947 | * This function issues an abort iocb for the provided command |
| 5948 | * iocb. This function is called with hbalock held. |
| 5949 | * The function returns 0 when it fails due to memory allocation |
| 5950 | * failure or when the command iocb is an abort request. |
| 5951 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5952 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5953 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5954 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5955 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5956 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 5957 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5958 | IOCB_t *icmd = NULL; |
| 5959 | IOCB_t *iabt = NULL; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5960 | int retval = IOCB_ERROR; |
| 5961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5962 | /* |
| 5963 | * There are certain command types we don't want to abort. And we |
| 5964 | * don't want to abort commands that are already in the process of |
| 5965 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5966 | */ |
| 5967 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5968 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5969 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5970 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5971 | return 0; |
| 5972 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5973 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
| 5974 | * callback so that nothing happens when it finishes. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5975 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5976 | if ((vport->load_flag & FC_UNLOADING) && |
| 5977 | (pring->ringno == LPFC_ELS_RING)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5978 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 5979 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 5980 | else |
| 5981 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5982 | goto abort_iotag_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5983 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5984 | |
| 5985 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5986 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5987 | if (abtsiocbp == NULL) |
| 5988 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5989 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5990 | /* This signals the response to set the correct status |
| 5991 | * before calling the completion handler. |
| 5992 | */ |
| 5993 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 5994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5995 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5996 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 5997 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 5998 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 5999 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
| 6000 | else |
| 6001 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6002 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6003 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6005 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6006 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 6007 | else |
| 6008 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 6009 | |
| 6010 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 6011 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6012 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 6013 | "0339 Abort xri x%x, original iotag x%x, " |
| 6014 | "abort cmd iotag x%x\n", |
| 6015 | iabt->un.acxri.abortContextTag, |
| 6016 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6017 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6018 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6019 | if (retval) |
| 6020 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6021 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6022 | /* |
| 6023 | * Caller to this routine should check for IOCB_ERROR |
| 6024 | * and handle it properly. This routine no longer removes |
| 6025 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6026 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6027 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6028 | } |
| 6029 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6031 | * 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] | 6032 | * @iocbq: Pointer to driver iocb object. |
| 6033 | * @vport: Pointer to driver virtual port object. |
| 6034 | * @tgt_id: SCSI ID of the target. |
| 6035 | * @lun_id: LUN ID of the scsi device. |
| 6036 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 6037 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6038 | * 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] | 6039 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 6040 | * 0 if the filtering criteria is met for the given iocb and will return |
| 6041 | * 1 if the filtering criteria is not met. |
| 6042 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 6043 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 6044 | * lun_id parameter. |
| 6045 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 6046 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 6047 | * parameters. |
| 6048 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 6049 | * given iocb is for the SCSI host associated with the given vport. |
| 6050 | * This function is called with no locks held. |
| 6051 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6052 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6053 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 6054 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6055 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6056 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6057 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6058 | int rc = 1; |
| 6059 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6060 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 6061 | return rc; |
| 6062 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6063 | if (iocbq->vport != vport) |
| 6064 | return rc; |
| 6065 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6066 | 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] | 6067 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6068 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6069 | return rc; |
| 6070 | |
| 6071 | switch (ctx_cmd) { |
| 6072 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6073 | if ((lpfc_cmd->rdata->pnode) && |
| 6074 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 6075 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6076 | rc = 0; |
| 6077 | break; |
| 6078 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6079 | if ((lpfc_cmd->rdata->pnode) && |
| 6080 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6081 | rc = 0; |
| 6082 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6083 | case LPFC_CTX_HOST: |
| 6084 | rc = 0; |
| 6085 | break; |
| 6086 | default: |
| 6087 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 6088 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6089 | break; |
| 6090 | } |
| 6091 | |
| 6092 | return rc; |
| 6093 | } |
| 6094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6095 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6096 | * 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] | 6097 | * @vport: Pointer to virtual port. |
| 6098 | * @tgt_id: SCSI ID of the target. |
| 6099 | * @lun_id: LUN ID of the scsi device. |
| 6100 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 6101 | * |
| 6102 | * This function returns number of FCP commands pending for the vport. |
| 6103 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 6104 | * commands pending on the vport associated with SCSI device specified |
| 6105 | * by tgt_id and lun_id parameters. |
| 6106 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 6107 | * commands pending on the vport associated with SCSI target specified |
| 6108 | * by tgt_id parameter. |
| 6109 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 6110 | * commands pending on the vport. |
| 6111 | * This function returns the number of iocbs which satisfy the filter. |
| 6112 | * This function is called without any lock held. |
| 6113 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6114 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6115 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 6116 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6117 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6118 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6119 | struct lpfc_iocbq *iocbq; |
| 6120 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6121 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6122 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 6123 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6124 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6125 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 6126 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6127 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6128 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6129 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6130 | return sum; |
| 6131 | } |
| 6132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6133 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6134 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6135 | * @phba: Pointer to HBA context object |
| 6136 | * @cmdiocb: Pointer to command iocb object. |
| 6137 | * @rspiocb: Pointer to response iocb object. |
| 6138 | * |
| 6139 | * This function is called when an aborted FCP iocb completes. This |
| 6140 | * function is called by the ring event handler with no lock held. |
| 6141 | * This function frees the iocb. |
| 6142 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 6143 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6144 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6145 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 6146 | { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6147 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 6148 | return; |
| 6149 | } |
| 6150 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6151 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6152 | * 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] | 6153 | * @vport: Pointer to virtual port. |
| 6154 | * @pring: Pointer to driver SLI ring object. |
| 6155 | * @tgt_id: SCSI ID of the target. |
| 6156 | * @lun_id: LUN ID of the scsi device. |
| 6157 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 6158 | * |
| 6159 | * This function sends an abort command for every SCSI command |
| 6160 | * associated with the given virtual port pending on the ring |
| 6161 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 6162 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 6163 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 6164 | * parameters |
| 6165 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 6166 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 6167 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 6168 | * FCP iocbs associated with virtual port. |
| 6169 | * This function returns number of iocbs it failed to abort. |
| 6170 | * This function is called with no locks held. |
| 6171 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6172 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6173 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 6174 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6175 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6176 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6177 | struct lpfc_iocbq *iocbq; |
| 6178 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6179 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6180 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6181 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6182 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6183 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 6184 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6185 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6186 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6187 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6188 | continue; |
| 6189 | |
| 6190 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6191 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6192 | if (abtsiocb == NULL) { |
| 6193 | errcnt++; |
| 6194 | continue; |
| 6195 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6196 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 6197 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6198 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 6199 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6200 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6201 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 6202 | else |
| 6203 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6204 | abtsiocb->iocb.ulpLe = 1; |
| 6205 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6206 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6207 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6208 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6209 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 6210 | else |
| 6211 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 6212 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 6213 | /* Setup callback routine and issue the command. */ |
| 6214 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6215 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 6216 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6217 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6218 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | errcnt++; |
| 6220 | continue; |
| 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | return errcnt; |
| 6225 | } |
| 6226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6227 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6228 | * 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] | 6229 | * @phba: Pointer to HBA context object. |
| 6230 | * @cmdiocbq: Pointer to command iocb. |
| 6231 | * @rspiocbq: Pointer to response iocb. |
| 6232 | * |
| 6233 | * This function is the completion handler for iocbs issued using |
| 6234 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 6235 | * ring event handler function without any lock held. This function |
| 6236 | * can be called from both worker thread context and interrupt |
| 6237 | * context. This function also can be called from other thread which |
| 6238 | * cleans up the SLI layer objects. |
| 6239 | * This function copy the contents of the response iocb to the |
| 6240 | * response iocb memory object provided by the caller of |
| 6241 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 6242 | * sleeps for the iocb completion. |
| 6243 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6244 | static void |
| 6245 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 6246 | struct lpfc_iocbq *cmdiocbq, |
| 6247 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6248 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6249 | wait_queue_head_t *pdone_q; |
| 6250 | unsigned long iflags; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6251 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6252 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6253 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 6254 | if (cmdiocbq->context2 && rspiocbq) |
| 6255 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 6256 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 6257 | |
| 6258 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6259 | if (pdone_q) |
| 6260 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6261 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6262 | return; |
| 6263 | } |
| 6264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6266 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6267 | * @phba: Pointer to HBA context object.. |
| 6268 | * @pring: Pointer to sli ring. |
| 6269 | * @piocb: Pointer to command iocb. |
| 6270 | * @prspiocbq: Pointer to response iocb. |
| 6271 | * @timeout: Timeout in number of seconds. |
| 6272 | * |
| 6273 | * This function issues the iocb to firmware and waits for the |
| 6274 | * iocb to complete. If the iocb command is not |
| 6275 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 6276 | * Caller should not free the iocb resources if this function |
| 6277 | * returns IOCB_TIMEDOUT. |
| 6278 | * The function waits for the iocb completion using an |
| 6279 | * non-interruptible wait. |
| 6280 | * This function will sleep while waiting for iocb completion. |
| 6281 | * So, this function should not be called from any context which |
| 6282 | * does not allow sleeping. Due to the same reason, this function |
| 6283 | * cannot be called with interrupt disabled. |
| 6284 | * This function assumes that the iocb completions occur while |
| 6285 | * this function sleep. So, this function cannot be called from |
| 6286 | * the thread which process iocb completion for this ring. |
| 6287 | * This function clears the iocb_flag of the iocb object before |
| 6288 | * issuing the iocb and the iocb completion handler sets this |
| 6289 | * flag and wakes this thread when the iocb completes. |
| 6290 | * The contents of the response iocb will be copied to prspiocbq |
| 6291 | * by the completion handler when the command completes. |
| 6292 | * This function returns IOCB_SUCCESS when success. |
| 6293 | * This function is called with no lock held. |
| 6294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6295 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6296 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6297 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6298 | struct lpfc_iocbq *piocb, |
| 6299 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6300 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6301 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 6302 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6303 | long timeleft, timeout_req = 0; |
| 6304 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6305 | uint32_t creg_val; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6306 | |
| 6307 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6308 | * If the caller has provided a response iocbq buffer, then context2 |
| 6309 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6310 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6311 | if (prspiocbq) { |
| 6312 | if (piocb->context2) |
| 6313 | return IOCB_ERROR; |
| 6314 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6315 | } |
| 6316 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6317 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 6318 | piocb->context_un.wait_queue = &done_q; |
| 6319 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6320 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6321 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6322 | creg_val = readl(phba->HCregaddr); |
| 6323 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 6324 | writel(creg_val, phba->HCregaddr); |
| 6325 | readl(phba->HCregaddr); /* flush */ |
| 6326 | } |
| 6327 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6328 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6329 | if (retval == IOCB_SUCCESS) { |
| 6330 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6331 | timeleft = wait_event_timeout(done_q, |
| 6332 | piocb->iocb_flag & LPFC_IO_WAKE, |
| 6333 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6334 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6335 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 6336 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6337 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6338 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6339 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6340 | "0338 IOCB wait timeout error - no " |
| 6341 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6342 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6343 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6344 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6345 | "0330 IOCB wake NOT set, " |
| 6346 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6347 | timeout, (timeleft / jiffies)); |
| 6348 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6349 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6350 | } else { |
| 6351 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6352 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6353 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6354 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6355 | } |
| 6356 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 6357 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6358 | creg_val = readl(phba->HCregaddr); |
| 6359 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 6360 | writel(creg_val, phba->HCregaddr); |
| 6361 | readl(phba->HCregaddr); /* flush */ |
| 6362 | } |
| 6363 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6364 | if (prspiocbq) |
| 6365 | piocb->context2 = NULL; |
| 6366 | |
| 6367 | piocb->context_un.wait_queue = NULL; |
| 6368 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6369 | return retval; |
| 6370 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 6371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6372 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6373 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6374 | * @phba: Pointer to HBA context object. |
| 6375 | * @pmboxq: Pointer to driver mailbox object. |
| 6376 | * @timeout: Timeout in number of seconds. |
| 6377 | * |
| 6378 | * This function issues the mailbox to firmware and waits for the |
| 6379 | * mailbox command to complete. If the mailbox command is not |
| 6380 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 6381 | * The function waits for the mailbox completion using an |
| 6382 | * interruptible wait. If the thread is woken up due to a |
| 6383 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 6384 | * should not free the mailbox resources, if this function returns |
| 6385 | * MBX_TIMEOUT. |
| 6386 | * This function will sleep while waiting for mailbox completion. |
| 6387 | * So, this function should not be called from any context which |
| 6388 | * does not allow sleeping. Due to the same reason, this function |
| 6389 | * cannot be called with interrupt disabled. |
| 6390 | * This function assumes that the mailbox completion occurs while |
| 6391 | * this function sleep. So, this function cannot be called from |
| 6392 | * the worker thread which processes mailbox completion. |
| 6393 | * This function is called in the context of HBA management |
| 6394 | * applications. |
| 6395 | * This function returns MBX_SUCCESS when successful. |
| 6396 | * This function is called with no lock held. |
| 6397 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6398 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6399 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6400 | uint32_t timeout) |
| 6401 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 6402 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6403 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6404 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6405 | |
| 6406 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6407 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6408 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6409 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6410 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6411 | /* setup wake call as IOCB callback */ |
| 6412 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 6413 | /* setup context field to pass wait_queue pointer to wake function */ |
| 6414 | pmboxq->context1 = &done_q; |
| 6415 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6416 | /* now issue the command */ |
| 6417 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 6418 | |
| 6419 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6420 | wait_event_interruptible_timeout(done_q, |
| 6421 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 6422 | timeout * HZ); |
| 6423 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6424 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6425 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6426 | /* |
| 6427 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 6428 | * else do not free the resources. |
| 6429 | */ |
| 6430 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6431 | retval = MBX_SUCCESS; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6432 | else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 6433 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6434 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 6435 | } |
| 6436 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6437 | } |
| 6438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6439 | return retval; |
| 6440 | } |
| 6441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6442 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6443 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6444 | * @phba: Pointer to HBA context. |
| 6445 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6446 | * This function is called to shutdown the driver's mailbox sub-system. |
| 6447 | * It first marks the mailbox sub-system is in a block state to prevent |
| 6448 | * the asynchronous mailbox command from issued off the pending mailbox |
| 6449 | * command queue. If the mailbox command sub-system shutdown is due to |
| 6450 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 6451 | * the mailbox sub-system flush routine to forcefully bring down the |
| 6452 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 6453 | * as with offline or HBA function reset), this routine will wait for the |
| 6454 | * outstanding mailbox command to complete before invoking the mailbox |
| 6455 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6456 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6457 | void |
| 6458 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 6459 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6460 | struct lpfc_sli *psli = &phba->sli; |
| 6461 | uint8_t actcmd = MBX_HEARTBEAT; |
| 6462 | unsigned long timeout; |
| 6463 | |
| 6464 | spin_lock_irq(&phba->hbalock); |
| 6465 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 6466 | spin_unlock_irq(&phba->hbalock); |
| 6467 | |
| 6468 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| 6469 | spin_lock_irq(&phba->hbalock); |
| 6470 | if (phba->sli.mbox_active) |
| 6471 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
| 6472 | spin_unlock_irq(&phba->hbalock); |
| 6473 | /* Determine how long we might wait for the active mailbox |
| 6474 | * command to be gracefully completed by firmware. |
| 6475 | */ |
| 6476 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * |
| 6477 | 1000) + jiffies; |
| 6478 | while (phba->sli.mbox_active) { |
| 6479 | /* Check active mailbox complete status every 2ms */ |
| 6480 | msleep(2); |
| 6481 | if (time_after(jiffies, timeout)) |
| 6482 | /* Timeout, let the mailbox flush routine to |
| 6483 | * forcefully release active mailbox command |
| 6484 | */ |
| 6485 | break; |
| 6486 | } |
| 6487 | } |
| 6488 | lpfc_sli_mbox_sys_flush(phba); |
| 6489 | } |
| 6490 | |
| 6491 | /** |
| 6492 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 6493 | * @phba: Pointer to HBA context. |
| 6494 | * |
| 6495 | * This function is called to read the SLI3 device error attention registers |
| 6496 | * for possible error attention events. The caller must hold the hostlock |
| 6497 | * with spin_lock_irq(). |
| 6498 | * |
| 6499 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 6500 | * Register and returns 0 otherwise. |
| 6501 | **/ |
| 6502 | static int |
| 6503 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 6504 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6505 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 6506 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6507 | /* Read chip Host Attention (HA) register */ |
| 6508 | ha_copy = readl(phba->HAregaddr); |
| 6509 | if (ha_copy & HA_ERATT) { |
| 6510 | /* Read host status register to retrieve error event */ |
| 6511 | lpfc_sli_read_hs(phba); |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 6512 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6513 | /* Check if there is a deferred error condition is active */ |
| 6514 | if ((HS_FFER1 & phba->work_hs) && |
| 6515 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 6516 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 6517 | spin_lock_irq(&phba->hbalock); |
| 6518 | phba->hba_flag |= DEFER_ERATT; |
| 6519 | spin_unlock_irq(&phba->hbalock); |
| 6520 | /* Clear all interrupt enable conditions */ |
| 6521 | writel(0, phba->HCregaddr); |
| 6522 | readl(phba->HCregaddr); |
| 6523 | } |
| 6524 | |
| 6525 | /* Set the driver HA work bitmap */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6526 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6527 | phba->work_ha |= HA_ERATT; |
| 6528 | /* Indicate polling handles this ERATT */ |
| 6529 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6530 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6531 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 6532 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6533 | return 0; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 6534 | } |
| 6535 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6536 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6537 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 6538 | * @phba: Pointer to HBA context. |
| 6539 | * |
| 6540 | * This function is called to read the SLI4 device error attention registers |
| 6541 | * for possible error attention events. The caller must hold the hostlock |
| 6542 | * with spin_lock_irq(). |
| 6543 | * |
| 6544 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 6545 | * Register and returns 0 otherwise. |
| 6546 | **/ |
| 6547 | static int |
| 6548 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 6549 | { |
| 6550 | uint32_t uerr_sta_hi, uerr_sta_lo; |
| 6551 | uint32_t onlnreg0, onlnreg1; |
| 6552 | |
| 6553 | /* For now, use the SLI4 device internal unrecoverable error |
| 6554 | * registers for error attention. This can be changed later. |
| 6555 | */ |
| 6556 | onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr); |
| 6557 | onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr); |
| 6558 | if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) { |
| 6559 | uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr); |
| 6560 | uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr); |
| 6561 | if (uerr_sta_lo || uerr_sta_hi) { |
| 6562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6563 | "1423 HBA Unrecoverable error: " |
| 6564 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 6565 | "online0_reg=0x%x, online1_reg=0x%x\n", |
| 6566 | uerr_sta_lo, uerr_sta_hi, |
| 6567 | onlnreg0, onlnreg1); |
| 6568 | /* TEMP: as the driver error recover logic is not |
| 6569 | * fully developed, we just log the error message |
| 6570 | * and the device error attention action is now |
| 6571 | * temporarily disabled. |
| 6572 | */ |
| 6573 | return 0; |
| 6574 | phba->work_status[0] = uerr_sta_lo; |
| 6575 | phba->work_status[1] = uerr_sta_hi; |
| 6576 | spin_lock_irq(&phba->hbalock); |
| 6577 | /* Set the driver HA work bitmap */ |
| 6578 | phba->work_ha |= HA_ERATT; |
| 6579 | /* Indicate polling handles this ERATT */ |
| 6580 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 6581 | spin_unlock_irq(&phba->hbalock); |
| 6582 | return 1; |
| 6583 | } |
| 6584 | } |
| 6585 | return 0; |
| 6586 | } |
| 6587 | |
| 6588 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6589 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6590 | * @phba: Pointer to HBA context. |
| 6591 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6592 | * This function is called from timer soft interrupt context to check HBA's |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6593 | * error attention register bit for error attention events. |
| 6594 | * |
| 6595 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
| 6596 | * Register and returns 0 otherwise. |
| 6597 | **/ |
| 6598 | int |
| 6599 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 6600 | { |
| 6601 | uint32_t ha_copy; |
| 6602 | |
| 6603 | /* If somebody is waiting to handle an eratt, don't process it |
| 6604 | * here. The brdkill function will do this. |
| 6605 | */ |
| 6606 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 6607 | return 0; |
| 6608 | |
| 6609 | /* Check if interrupt handler handles this ERATT */ |
| 6610 | spin_lock_irq(&phba->hbalock); |
| 6611 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 6612 | /* Interrupt handler has handled ERATT */ |
| 6613 | spin_unlock_irq(&phba->hbalock); |
| 6614 | return 0; |
| 6615 | } |
| 6616 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6617 | /* |
| 6618 | * If there is deferred error attention, do not check for error |
| 6619 | * attention |
| 6620 | */ |
| 6621 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6622 | spin_unlock_irq(&phba->hbalock); |
| 6623 | return 0; |
| 6624 | } |
| 6625 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6626 | /* If PCI channel is offline, don't process it */ |
| 6627 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6628 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6629 | return 0; |
| 6630 | } |
| 6631 | |
| 6632 | switch (phba->sli_rev) { |
| 6633 | case LPFC_SLI_REV2: |
| 6634 | case LPFC_SLI_REV3: |
| 6635 | /* Read chip Host Attention (HA) register */ |
| 6636 | ha_copy = lpfc_sli_eratt_read(phba); |
| 6637 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame^] | 6638 | case LPFC_SLI_REV4: |
| 6639 | /* Read devcie Uncoverable Error (UERR) registers */ |
| 6640 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 6641 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6642 | default: |
| 6643 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6644 | "0299 Invalid SLI revision (%d)\n", |
| 6645 | phba->sli_rev); |
| 6646 | ha_copy = 0; |
| 6647 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6648 | } |
| 6649 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6650 | |
| 6651 | return ha_copy; |
| 6652 | } |
| 6653 | |
| 6654 | /** |
| 6655 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 6656 | * @phba: Pointer to HBA context. |
| 6657 | * |
| 6658 | * This inline routine checks whether a device or its PCI slot is in a state |
| 6659 | * that the interrupt should be handled. |
| 6660 | * |
| 6661 | * This function returns 0 if the device or the PCI slot is in a state that |
| 6662 | * interrupt should be handled, otherwise -EIO. |
| 6663 | */ |
| 6664 | static inline int |
| 6665 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 6666 | { |
| 6667 | /* If the pci channel is offline, ignore all the interrupts */ |
| 6668 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 6669 | return -EIO; |
| 6670 | |
| 6671 | /* Update device level interrupt statistics */ |
| 6672 | phba->sli.slistat.sli_intr++; |
| 6673 | |
| 6674 | /* Ignore all interrupts during initialization. */ |
| 6675 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 6676 | return -EIO; |
| 6677 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6678 | return 0; |
| 6679 | } |
| 6680 | |
| 6681 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6682 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6683 | * @irq: Interrupt number. |
| 6684 | * @dev_id: The device context pointer. |
| 6685 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6686 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6687 | * service routine when device with SLI-3 interface spec is enabled with |
| 6688 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 6689 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 6690 | * interrupt mode, this function is called as part of the device-level |
| 6691 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 6692 | * is undergoing initialization, the interrupt handler will not process |
| 6693 | * the interrupt. The link attention and ELS ring attention events are |
| 6694 | * handled by the worker thread. The interrupt handler signals the worker |
| 6695 | * thread and returns for these events. This function is called without |
| 6696 | * any lock held. It gets the hbalock to access and update SLI data |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6697 | * structures. |
| 6698 | * |
| 6699 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 6700 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6701 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6702 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6703 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6704 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6705 | struct lpfc_hba *phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6706 | uint32_t ha_copy; |
| 6707 | uint32_t work_ha_copy; |
| 6708 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6709 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6710 | uint32_t control; |
| 6711 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6712 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6713 | struct lpfc_vport *vport; |
| 6714 | struct lpfc_nodelist *ndlp; |
| 6715 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6716 | LPFC_MBOXQ_t *pmb; |
| 6717 | int rc; |
| 6718 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6719 | /* |
| 6720 | * Get the driver's phba structure from the dev_id and |
| 6721 | * assume the HBA is not interrupting. |
| 6722 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6723 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6724 | |
| 6725 | if (unlikely(!phba)) |
| 6726 | return IRQ_NONE; |
| 6727 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6728 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6729 | * Stuff needs to be attented to when this function is invoked as an |
| 6730 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6731 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6732 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6733 | /* Check device state for handling interrupt */ |
| 6734 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6735 | return IRQ_NONE; |
| 6736 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6737 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6738 | ha_copy = readl(phba->HAregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6739 | /* If somebody is waiting to handle an eratt don't process it |
| 6740 | * here. The brdkill function will do this. |
| 6741 | */ |
| 6742 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 6743 | ha_copy &= ~HA_ERATT; |
| 6744 | /* Check the need for handling ERATT in interrupt handler */ |
| 6745 | if (ha_copy & HA_ERATT) { |
| 6746 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 6747 | /* ERATT polling has handled ERATT */ |
| 6748 | ha_copy &= ~HA_ERATT; |
| 6749 | else |
| 6750 | /* Indicate interrupt handler handles ERATT */ |
| 6751 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 6752 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6753 | |
| 6754 | /* |
| 6755 | * If there is deferred error attention, do not check for any |
| 6756 | * interrupt. |
| 6757 | */ |
| 6758 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6759 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6760 | return IRQ_NONE; |
| 6761 | } |
| 6762 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6763 | /* Clear up only attention source related to slow-path */ |
| 6764 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 6765 | phba->HAregaddr); |
| 6766 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6767 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6768 | } else |
| 6769 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6770 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6771 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 6772 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6773 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6774 | if (work_ha_copy & HA_LATT) { |
| 6775 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 6776 | /* |
| 6777 | * Turn off Link Attention interrupts |
| 6778 | * until CLEAR_LA done |
| 6779 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6780 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6781 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
| 6782 | control = readl(phba->HCregaddr); |
| 6783 | control &= ~HC_LAINT_ENA; |
| 6784 | writel(control, phba->HCregaddr); |
| 6785 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6786 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6787 | } |
| 6788 | else |
| 6789 | work_ha_copy &= ~HA_LATT; |
| 6790 | } |
| 6791 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6792 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6793 | /* |
| 6794 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 6795 | * the only slow ring. |
| 6796 | */ |
| 6797 | status = (work_ha_copy & |
| 6798 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 6799 | status >>= (4*LPFC_ELS_RING); |
| 6800 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6801 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6802 | control = readl(phba->HCregaddr); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 6803 | |
| 6804 | lpfc_debugfs_slow_ring_trc(phba, |
| 6805 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 6806 | control, status, |
| 6807 | (uint32_t)phba->sli.slistat.sli_intr); |
| 6808 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6809 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 6810 | lpfc_debugfs_slow_ring_trc(phba, |
| 6811 | "ISR Disable ring:" |
| 6812 | "pwork:x%x hawork:x%x wait:x%x", |
| 6813 | phba->work_ha, work_ha_copy, |
| 6814 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6815 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 6816 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6817 | control &= |
| 6818 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6819 | writel(control, phba->HCregaddr); |
| 6820 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6821 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 6822 | else { |
| 6823 | lpfc_debugfs_slow_ring_trc(phba, |
| 6824 | "ISR slow ring: pwork:" |
| 6825 | "x%x hawork:x%x wait:x%x", |
| 6826 | phba->work_ha, work_ha_copy, |
| 6827 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6828 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 6829 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6830 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6831 | } |
| 6832 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6833 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6834 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6835 | lpfc_sli_read_hs(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6836 | /* |
| 6837 | * Check if there is a deferred error condition |
| 6838 | * is active |
| 6839 | */ |
| 6840 | if ((HS_FFER1 & phba->work_hs) && |
| 6841 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
| 6842 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { |
| 6843 | phba->hba_flag |= DEFER_ERATT; |
| 6844 | /* Clear all interrupt enable conditions */ |
| 6845 | writel(0, phba->HCregaddr); |
| 6846 | readl(phba->HCregaddr); |
| 6847 | } |
| 6848 | } |
| 6849 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6850 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6851 | pmb = phba->sli.mbox_active; |
| 6852 | pmbox = &pmb->mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6853 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6854 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6855 | |
| 6856 | /* First check out the status word */ |
| 6857 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 6858 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6859 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6860 | /* |
| 6861 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 6862 | * mbxStatus <status> |
| 6863 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6864 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6865 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6866 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6867 | "Interrupt mbxCommand x%x " |
| 6868 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6869 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6870 | pmbox->mbxCommand, |
| 6871 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6872 | /* clear mailbox attention bit */ |
| 6873 | work_ha_copy &= ~HA_MBATT; |
| 6874 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 6875 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6876 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6877 | phba->last_completion_time = jiffies; |
| 6878 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6879 | if (pmb->mbox_cmpl) { |
| 6880 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 6881 | MAILBOX_CMD_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6882 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6883 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 6884 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 6885 | |
| 6886 | lpfc_debugfs_disc_trc(vport, |
| 6887 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6888 | "MBOX dflt rpi: : " |
| 6889 | "status:x%x rpi:x%x", |
| 6890 | (uint32_t)pmbox->mbxStatus, |
| 6891 | pmbox->un.varWords[0], 0); |
| 6892 | |
| 6893 | if (!pmbox->mbxStatus) { |
| 6894 | mp = (struct lpfc_dmabuf *) |
| 6895 | (pmb->context1); |
| 6896 | ndlp = (struct lpfc_nodelist *) |
| 6897 | pmb->context2; |
| 6898 | |
| 6899 | /* Reg_LOGIN of dflt RPI was |
| 6900 | * successful. new lets get |
| 6901 | * rid of the RPI using the |
| 6902 | * same mbox buffer. |
| 6903 | */ |
| 6904 | lpfc_unreg_login(phba, |
| 6905 | vport->vpi, |
| 6906 | pmbox->un.varWords[0], |
| 6907 | pmb); |
| 6908 | pmb->mbox_cmpl = |
| 6909 | lpfc_mbx_cmpl_dflt_rpi; |
| 6910 | pmb->context1 = mp; |
| 6911 | pmb->context2 = ndlp; |
| 6912 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6913 | rc = lpfc_sli_issue_mbox(phba, |
| 6914 | pmb, |
| 6915 | MBX_NOWAIT); |
| 6916 | if (rc != MBX_BUSY) |
| 6917 | lpfc_printf_log(phba, |
| 6918 | KERN_ERR, |
| 6919 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6920 | "0350 rc should have" |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6921 | "been MBX_BUSY"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6922 | if (rc != MBX_NOT_FINISHED) |
| 6923 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6924 | } |
| 6925 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6926 | spin_lock_irqsave( |
| 6927 | &phba->pport->work_port_lock, |
| 6928 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6929 | phba->pport->work_port_events &= |
| 6930 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6931 | spin_unlock_irqrestore( |
| 6932 | &phba->pport->work_port_lock, |
| 6933 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6934 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6935 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 6936 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6937 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6938 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6939 | if ((work_ha_copy & HA_MBATT) && |
| 6940 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6941 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6942 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6943 | do { |
| 6944 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 6945 | MBX_NOWAIT); |
| 6946 | } while (rc == MBX_NOT_FINISHED); |
| 6947 | if (rc != MBX_SUCCESS) |
| 6948 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 6949 | LOG_SLI, "0349 rc should be " |
| 6950 | "MBX_SUCCESS"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6951 | } |
| 6952 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6953 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6954 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6955 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6956 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6957 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6958 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6959 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6960 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6961 | |
| 6962 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6963 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6964 | * @irq: Interrupt number. |
| 6965 | * @dev_id: The device context pointer. |
| 6966 | * |
| 6967 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6968 | * service routine when device with SLI-3 interface spec is enabled with |
| 6969 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 6970 | * ring event in the HBA. However, when the device is enabled with either |
| 6971 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 6972 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 6973 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 6974 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 6975 | * the intrrupt context. This function is called without any lock held. |
| 6976 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6977 | * |
| 6978 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 6979 | * returns IRQ_NONE. |
| 6980 | **/ |
| 6981 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6982 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6983 | { |
| 6984 | struct lpfc_hba *phba; |
| 6985 | uint32_t ha_copy; |
| 6986 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6987 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6988 | |
| 6989 | /* Get the driver's phba structure from the dev_id and |
| 6990 | * assume the HBA is not interrupting. |
| 6991 | */ |
| 6992 | phba = (struct lpfc_hba *) dev_id; |
| 6993 | |
| 6994 | if (unlikely(!phba)) |
| 6995 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6996 | |
| 6997 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6998 | * Stuff needs to be attented to when this function is invoked as an |
| 6999 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7000 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7001 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7002 | /* Check device state for handling interrupt */ |
| 7003 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7004 | return IRQ_NONE; |
| 7005 | /* Need to read HA REG for FCP ring and other ring events */ |
| 7006 | ha_copy = readl(phba->HAregaddr); |
| 7007 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7008 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7009 | /* |
| 7010 | * If there is deferred error attention, do not check for |
| 7011 | * any interrupt. |
| 7012 | */ |
| 7013 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7014 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7015 | return IRQ_NONE; |
| 7016 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7017 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 7018 | phba->HAregaddr); |
| 7019 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7020 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7021 | } else |
| 7022 | ha_copy = phba->ha_copy; |
| 7023 | |
| 7024 | /* |
| 7025 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 7026 | */ |
| 7027 | ha_copy &= ~(phba->work_ha_mask); |
| 7028 | |
| 7029 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7030 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7031 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7032 | lpfc_sli_handle_fast_ring_event(phba, |
| 7033 | &phba->sli.ring[LPFC_FCP_RING], |
| 7034 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 7035 | |
| 7036 | if (phba->cfg_multi_ring_support == 2) { |
| 7037 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7038 | * Process all events on extra ring. Take the optimized path |
| 7039 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 7040 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7041 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 7042 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7043 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 7044 | lpfc_sli_handle_fast_ring_event(phba, |
| 7045 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 7046 | status); |
| 7047 | } |
| 7048 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7049 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7050 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7051 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7052 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7053 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7054 | * @irq: Interrupt number. |
| 7055 | * @dev_id: The device context pointer. |
| 7056 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7057 | * This function is the HBA device-level interrupt handler to device with |
| 7058 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 7059 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 7060 | * requires driver attention. This function invokes the slow-path interrupt |
| 7061 | * attention handling function and fast-path interrupt attention handling |
| 7062 | * function in turn to process the relevant HBA attention events. This |
| 7063 | * function is called without any lock held. It gets the hbalock to access |
| 7064 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7065 | * |
| 7066 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 7067 | * returns IRQ_NONE. |
| 7068 | **/ |
| 7069 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7070 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7071 | { |
| 7072 | struct lpfc_hba *phba; |
| 7073 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 7074 | unsigned long status1, status2; |
| 7075 | |
| 7076 | /* |
| 7077 | * Get the driver's phba structure from the dev_id and |
| 7078 | * assume the HBA is not interrupting. |
| 7079 | */ |
| 7080 | phba = (struct lpfc_hba *) dev_id; |
| 7081 | |
| 7082 | if (unlikely(!phba)) |
| 7083 | return IRQ_NONE; |
| 7084 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7085 | /* Check device state for handling interrupt */ |
| 7086 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7087 | return IRQ_NONE; |
| 7088 | |
| 7089 | spin_lock(&phba->hbalock); |
| 7090 | phba->ha_copy = readl(phba->HAregaddr); |
| 7091 | if (unlikely(!phba->ha_copy)) { |
| 7092 | spin_unlock(&phba->hbalock); |
| 7093 | return IRQ_NONE; |
| 7094 | } else if (phba->ha_copy & HA_ERATT) { |
| 7095 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 7096 | /* ERATT polling has handled ERATT */ |
| 7097 | phba->ha_copy &= ~HA_ERATT; |
| 7098 | else |
| 7099 | /* Indicate interrupt handler handles ERATT */ |
| 7100 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 7101 | } |
| 7102 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7103 | /* |
| 7104 | * If there is deferred error attention, do not check for any interrupt. |
| 7105 | */ |
| 7106 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7107 | spin_unlock_irq(&phba->hbalock); |
| 7108 | return IRQ_NONE; |
| 7109 | } |
| 7110 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7111 | /* Clear attention sources except link and error attentions */ |
| 7112 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
| 7113 | readl(phba->HAregaddr); /* flush */ |
| 7114 | spin_unlock(&phba->hbalock); |
| 7115 | |
| 7116 | /* |
| 7117 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 7118 | */ |
| 7119 | |
| 7120 | /* status of events with mailbox and link attention */ |
| 7121 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 7122 | |
| 7123 | /* status of events with ELS ring */ |
| 7124 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 7125 | status2 >>= (4*LPFC_ELS_RING); |
| 7126 | |
| 7127 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7128 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7129 | else |
| 7130 | sp_irq_rc = IRQ_NONE; |
| 7131 | |
| 7132 | /* |
| 7133 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 7134 | */ |
| 7135 | |
| 7136 | /* status of events with FCP ring */ |
| 7137 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 7138 | status1 >>= (4*LPFC_FCP_RING); |
| 7139 | |
| 7140 | /* status of events with extra ring */ |
| 7141 | if (phba->cfg_multi_ring_support == 2) { |
| 7142 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 7143 | status2 >>= (4*LPFC_EXTRA_RING); |
| 7144 | } else |
| 7145 | status2 = 0; |
| 7146 | |
| 7147 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7148 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7149 | else |
| 7150 | fp_irq_rc = IRQ_NONE; |
| 7151 | |
| 7152 | /* Return device-level interrupt handling status */ |
| 7153 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7154 | } /* lpfc_sli_intr_handler */ |