| 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 | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 28 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | #include <scsi/scsi_cmnd.h> |
| 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 32 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 33 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 34 | #include <linux/aer.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_crtn.h" |
| 45 | #include "lpfc_logmsg.h" |
| 46 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 47 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 48 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | |
| 50 | /* There are only four IOCB completion types. */ |
| 51 | typedef enum _lpfc_iocb_type { |
| 52 | LPFC_UNKNOWN_IOCB, |
| 53 | LPFC_UNSOL_IOCB, |
| 54 | LPFC_SOL_IOCB, |
| 55 | LPFC_ABORT_IOCB |
| 56 | } lpfc_iocb_type; |
| 57 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 58 | |
| 59 | /* Provide function prototypes local to this module. */ |
| 60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 61 | uint32_t); |
| 62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 63 | uint8_t *, uint32_t *); |
| 64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 65 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 67 | struct hbq_dmabuf *); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 68 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
| 69 | struct lpfc_cqe *); |
| 70 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 71 | static IOCB_t * |
| 72 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 73 | { |
| 74 | return &iocbq->iocb; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 79 | * @q: The Work Queue to operate on. |
| 80 | * @wqe: The work Queue Entry to put on the Work queue. |
| 81 | * |
| 82 | * This routine will copy the contents of @wqe to the next available entry on |
| 83 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 84 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 85 | * successful. If no entries are available on @q then this function will return |
| 86 | * -ENOMEM. |
| 87 | * The caller is expected to hold the hbalock when calling this routine. |
| 88 | **/ |
| 89 | static uint32_t |
| 90 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 91 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 92 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 93 | struct lpfc_register doorbell; |
| 94 | uint32_t host_index; |
| 95 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 96 | /* sanity check on queue memory */ |
| 97 | if (unlikely(!q)) |
| 98 | return -ENOMEM; |
| 99 | temp_wqe = q->qe[q->host_index].wqe; |
| 100 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 101 | /* If the host has not yet processed the next entry then we are done */ |
| 102 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 103 | return -ENOMEM; |
| 104 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 105 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 106 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 107 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 108 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 109 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 110 | |
| 111 | /* Update the host index before invoking device */ |
| 112 | host_index = q->host_index; |
| 113 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 114 | |
| 115 | /* Ring Doorbell */ |
| 116 | doorbell.word0 = 0; |
| 117 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); |
| 118 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); |
| 119 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); |
| 120 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); |
| 121 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 128 | * @q: The Work Queue to operate on. |
| 129 | * @index: The index to advance the hba index to. |
| 130 | * |
| 131 | * This routine will update the HBA index of a queue to reflect consumption of |
| 132 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 133 | * an entry the host calls this function to update the queue's internal |
| 134 | * pointers. This routine returns the number of entries that were consumed by |
| 135 | * the HBA. |
| 136 | **/ |
| 137 | static uint32_t |
| 138 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 139 | { |
| 140 | uint32_t released = 0; |
| 141 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 142 | /* sanity check on queue memory */ |
| 143 | if (unlikely(!q)) |
| 144 | return 0; |
| 145 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 146 | if (q->hba_index == index) |
| 147 | return 0; |
| 148 | do { |
| 149 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 150 | released++; |
| 151 | } while (q->hba_index != index); |
| 152 | return released; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 157 | * @q: The Mailbox Queue to operate on. |
| 158 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 159 | * |
| 160 | * This routine will copy the contents of @mqe to the next available entry on |
| 161 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 162 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 163 | * successful. If no entries are available on @q then this function will return |
| 164 | * -ENOMEM. |
| 165 | * The caller is expected to hold the hbalock when calling this routine. |
| 166 | **/ |
| 167 | static uint32_t |
| 168 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 169 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 170 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 171 | struct lpfc_register doorbell; |
| 172 | uint32_t host_index; |
| 173 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 174 | /* sanity check on queue memory */ |
| 175 | if (unlikely(!q)) |
| 176 | return -ENOMEM; |
| 177 | temp_mqe = q->qe[q->host_index].mqe; |
| 178 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 179 | /* If the host has not yet processed the next entry then we are done */ |
| 180 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 181 | return -ENOMEM; |
| 182 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 183 | /* Save off the mailbox pointer for completion */ |
| 184 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 185 | |
| 186 | /* Update the host index before invoking device */ |
| 187 | host_index = q->host_index; |
| 188 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 189 | |
| 190 | /* Ring Doorbell */ |
| 191 | doorbell.word0 = 0; |
| 192 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 193 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 194 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
| 195 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 201 | * @q: The Mailbox Queue to operate on. |
| 202 | * |
| 203 | * This routine will update the HBA index of a queue to reflect consumption of |
| 204 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 205 | * an entry the host calls this function to update the queue's internal |
| 206 | * pointers. This routine returns the number of entries that were consumed by |
| 207 | * the HBA. |
| 208 | **/ |
| 209 | static uint32_t |
| 210 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 211 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 212 | /* sanity check on queue memory */ |
| 213 | if (unlikely(!q)) |
| 214 | return 0; |
| 215 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 216 | /* Clear the mailbox pointer for completion */ |
| 217 | q->phba->mbox = NULL; |
| 218 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 224 | * @q: The Event Queue to get the first valid EQE from |
| 225 | * |
| 226 | * This routine will get the first valid Event Queue Entry from @q, update |
| 227 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 228 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 229 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 230 | **/ |
| 231 | static struct lpfc_eqe * |
| 232 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 233 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 234 | struct lpfc_eqe *eqe; |
| 235 | |
| 236 | /* sanity check on queue memory */ |
| 237 | if (unlikely(!q)) |
| 238 | return NULL; |
| 239 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 240 | |
| 241 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 242 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 243 | return NULL; |
| 244 | /* If the host has not yet processed the next entry then we are done */ |
| 245 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 246 | return NULL; |
| 247 | |
| 248 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 249 | return eqe; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 254 | * @q: The Event Queue that the host has completed processing for. |
| 255 | * @arm: Indicates whether the host wants to arms this CQ. |
| 256 | * |
| 257 | * This routine will mark all Event Queue Entries on @q, from the last |
| 258 | * known completed entry to the last entry that was processed, as completed |
| 259 | * by clearing the valid bit for each completion queue entry. Then it will |
| 260 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 261 | * The internal host index in the @q will be updated by this routine to indicate |
| 262 | * that the host has finished processing the entries. The @arm parameter |
| 263 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 264 | * |
| 265 | * This function will return the number of EQEs that were popped. |
| 266 | **/ |
| 267 | uint32_t |
| 268 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 269 | { |
| 270 | uint32_t released = 0; |
| 271 | struct lpfc_eqe *temp_eqe; |
| 272 | struct lpfc_register doorbell; |
| 273 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 274 | /* sanity check on queue memory */ |
| 275 | if (unlikely(!q)) |
| 276 | return 0; |
| 277 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 278 | /* while there are valid entries */ |
| 279 | while (q->hba_index != q->host_index) { |
| 280 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 281 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 282 | released++; |
| 283 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 284 | } |
| 285 | if (unlikely(released == 0 && !arm)) |
| 286 | return 0; |
| 287 | |
| 288 | /* ring doorbell for number popped */ |
| 289 | doorbell.word0 = 0; |
| 290 | if (arm) { |
| 291 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 292 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 293 | } |
| 294 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 295 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 296 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 297 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 298 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 299 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 300 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 301 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 302 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 303 | return released; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 308 | * @q: The Completion Queue to get the first valid CQE from |
| 309 | * |
| 310 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 311 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 312 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 313 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 314 | **/ |
| 315 | static struct lpfc_cqe * |
| 316 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 317 | { |
| 318 | struct lpfc_cqe *cqe; |
| 319 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 320 | /* sanity check on queue memory */ |
| 321 | if (unlikely(!q)) |
| 322 | return NULL; |
| 323 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 324 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 325 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 326 | return NULL; |
| 327 | /* If the host has not yet processed the next entry then we are done */ |
| 328 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 329 | return NULL; |
| 330 | |
| 331 | cqe = q->qe[q->hba_index].cqe; |
| 332 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 333 | return cqe; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 338 | * @q: The Completion Queue that the host has completed processing for. |
| 339 | * @arm: Indicates whether the host wants to arms this CQ. |
| 340 | * |
| 341 | * This routine will mark all Completion queue entries on @q, from the last |
| 342 | * known completed entry to the last entry that was processed, as completed |
| 343 | * by clearing the valid bit for each completion queue entry. Then it will |
| 344 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 345 | * The internal host index in the @q will be updated by this routine to indicate |
| 346 | * that the host has finished processing the entries. The @arm parameter |
| 347 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 348 | * |
| 349 | * This function will return the number of CQEs that were released. |
| 350 | **/ |
| 351 | uint32_t |
| 352 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 353 | { |
| 354 | uint32_t released = 0; |
| 355 | struct lpfc_cqe *temp_qe; |
| 356 | struct lpfc_register doorbell; |
| 357 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 358 | /* sanity check on queue memory */ |
| 359 | if (unlikely(!q)) |
| 360 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 361 | /* while there are valid entries */ |
| 362 | while (q->hba_index != q->host_index) { |
| 363 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 364 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 365 | released++; |
| 366 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 367 | } |
| 368 | if (unlikely(released == 0 && !arm)) |
| 369 | return 0; |
| 370 | |
| 371 | /* ring doorbell for number popped */ |
| 372 | doorbell.word0 = 0; |
| 373 | if (arm) |
| 374 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 375 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 376 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 377 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 378 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 379 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 380 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 381 | return released; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 386 | * @q: The Header Receive Queue to operate on. |
| 387 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 388 | * |
| 389 | * This routine will copy the contents of @wqe to the next available entry on |
| 390 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 391 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 392 | * index that the rqe was copied to if successful. If no entries are available |
| 393 | * on @q then this function will return -ENOMEM. |
| 394 | * The caller is expected to hold the hbalock when calling this routine. |
| 395 | **/ |
| 396 | static int |
| 397 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 398 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 399 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 400 | struct lpfc_rqe *temp_hrqe; |
| 401 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 402 | struct lpfc_register doorbell; |
| 403 | int put_index = hq->host_index; |
| 404 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 405 | /* sanity check on queue memory */ |
| 406 | if (unlikely(!hq) || unlikely(!dq)) |
| 407 | return -ENOMEM; |
| 408 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 409 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 410 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 411 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 412 | return -EINVAL; |
| 413 | if (hq->host_index != dq->host_index) |
| 414 | return -EINVAL; |
| 415 | /* If the host has not yet processed the next entry then we are done */ |
| 416 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 417 | return -EBUSY; |
| 418 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 419 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 420 | |
| 421 | /* Update the host index to point to the next slot */ |
| 422 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 423 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 424 | |
| 425 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 426 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 427 | doorbell.word0 = 0; |
| 428 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 429 | hq->entry_repost); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 430 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
| 431 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); |
| 432 | } |
| 433 | return put_index; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 438 | * @q: The Header Receive Queue to operate on. |
| 439 | * |
| 440 | * This routine will update the HBA index of a queue to reflect consumption of |
| 441 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 442 | * consumed an entry the host calls this function to update the queue's |
| 443 | * internal pointers. This routine returns the number of entries that were |
| 444 | * consumed by the HBA. |
| 445 | **/ |
| 446 | static uint32_t |
| 447 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 448 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 449 | /* sanity check on queue memory */ |
| 450 | if (unlikely(!hq) || unlikely(!dq)) |
| 451 | return 0; |
| 452 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 453 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 454 | return 0; |
| 455 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 456 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 457 | return 1; |
| 458 | } |
| 459 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 460 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 461 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 462 | * @phba: Pointer to HBA context object. |
| 463 | * @pring: Pointer to driver SLI ring object. |
| 464 | * |
| 465 | * This function returns pointer to next command iocb entry |
| 466 | * in the command ring. The caller must hold hbalock to prevent |
| 467 | * other threads consume the next command iocb. |
| 468 | * SLI-2/SLI-3 provide different sized iocbs. |
| 469 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 470 | static inline IOCB_t * |
| 471 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 472 | { |
| 473 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 474 | pring->cmdidx * phba->iocb_cmd_size); |
| 475 | } |
| 476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 478 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 479 | * @phba: Pointer to HBA context object. |
| 480 | * @pring: Pointer to driver SLI ring object. |
| 481 | * |
| 482 | * This function returns pointer to next response iocb entry |
| 483 | * in the response ring. The caller must hold hbalock to make sure |
| 484 | * that no other thread consume the next response iocb. |
| 485 | * SLI-2/SLI-3 provide different sized iocbs. |
| 486 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 487 | static inline IOCB_t * |
| 488 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 489 | { |
| 490 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 491 | pring->rspidx * phba->iocb_rsp_size); |
| 492 | } |
| 493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 494 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 495 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 496 | * @phba: Pointer to HBA context object. |
| 497 | * |
| 498 | * This function is called with hbalock held. This function |
| 499 | * allocates a new driver iocb object from the iocb pool. If the |
| 500 | * allocation is successful, it returns pointer to the newly |
| 501 | * allocated iocb object else it returns NULL. |
| 502 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 503 | static struct lpfc_iocbq * |
| 504 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 505 | { |
| 506 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 507 | struct lpfc_iocbq * iocbq = NULL; |
| 508 | |
| 509 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 510 | if (iocbq) |
| 511 | phba->iocb_cnt++; |
| 512 | if (phba->iocb_cnt > phba->iocb_max) |
| 513 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 514 | return iocbq; |
| 515 | } |
| 516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 517 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 518 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 519 | * @phba: Pointer to HBA context object. |
| 520 | * @xritag: XRI value. |
| 521 | * |
| 522 | * This function clears the sglq pointer from the array of acive |
| 523 | * sglq's. The xritag that is passed in is used to index into the |
| 524 | * array. Before the xritag can be used it needs to be adjusted |
| 525 | * by subtracting the xribase. |
| 526 | * |
| 527 | * Returns sglq ponter = success, NULL = Failure. |
| 528 | **/ |
| 529 | static struct lpfc_sglq * |
| 530 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 531 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 532 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 533 | |
| 534 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 535 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 536 | return sglq; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 541 | * @phba: Pointer to HBA context object. |
| 542 | * @xritag: XRI value. |
| 543 | * |
| 544 | * This function returns the sglq pointer from the array of acive |
| 545 | * sglq's. The xritag that is passed in is used to index into the |
| 546 | * array. Before the xritag can be used it needs to be adjusted |
| 547 | * by subtracting the xribase. |
| 548 | * |
| 549 | * Returns sglq ponter = success, NULL = Failure. |
| 550 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 551 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 552 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 553 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 554 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 555 | |
| 556 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 557 | return sglq; |
| 558 | } |
| 559 | |
| 560 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 561 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 562 | * @phba: Pointer to HBA context object. |
| 563 | * @xritag: xri used in this exchange. |
| 564 | * @rrq: The RRQ to be cleared. |
| 565 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 566 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 567 | void |
| 568 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 569 | uint16_t xritag, |
| 570 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 571 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 572 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 573 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 574 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 575 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 576 | |
| 577 | /* The target DID could have been swapped (cable swap) |
| 578 | * we should use the ndlp from the findnode if it is |
| 579 | * available. |
| 580 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 581 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 582 | ndlp = rrq->ndlp; |
| 583 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 584 | if (!ndlp) |
| 585 | goto out; |
| 586 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 587 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 588 | rrq->send_rrq = 0; |
| 589 | rrq->xritag = 0; |
| 590 | rrq->rrq_stop_time = 0; |
| 591 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 592 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 593 | mempool_free(rrq, phba->rrq_pool); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 598 | * @phba: Pointer to HBA context object. |
| 599 | * |
| 600 | * This function is called with hbalock held. This function |
| 601 | * Checks if stop_time (ratov from setting rrq active) has |
| 602 | * been reached, if it has and the send_rrq flag is set then |
| 603 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 604 | * then it will just call the routine to clear the rrq and |
| 605 | * free the rrq resource. |
| 606 | * The timer is set to the next rrq that is going to expire before |
| 607 | * leaving the routine. |
| 608 | * |
| 609 | **/ |
| 610 | void |
| 611 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 612 | { |
| 613 | struct lpfc_node_rrq *rrq; |
| 614 | struct lpfc_node_rrq *nextrrq; |
| 615 | unsigned long next_time; |
| 616 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 617 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 618 | |
| 619 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 620 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 621 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 622 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 623 | &phba->active_rrq_list, list) { |
| 624 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 625 | list_move(&rrq->list, &send_rrq); |
| 626 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 627 | next_time = rrq->rrq_stop_time; |
| 628 | } |
| 629 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 630 | if (!list_empty(&phba->active_rrq_list)) |
| 631 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 632 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 633 | list_del(&rrq->list); |
| 634 | if (!rrq->send_rrq) |
| 635 | /* this call will free the rrq */ |
| 636 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 637 | else if (lpfc_send_rrq(phba, rrq)) { |
| 638 | /* if we send the rrq then the completion handler |
| 639 | * will clear the bit in the xribitmap. |
| 640 | */ |
| 641 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 642 | rrq); |
| 643 | } |
| 644 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /** |
| 648 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 649 | * @vport: Pointer to vport context object. |
| 650 | * @xri: The xri used in the exchange. |
| 651 | * @did: The targets DID for this exchange. |
| 652 | * |
| 653 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 654 | * rrq = rrq for this xri and target. |
| 655 | **/ |
| 656 | struct lpfc_node_rrq * |
| 657 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 658 | { |
| 659 | struct lpfc_hba *phba = vport->phba; |
| 660 | struct lpfc_node_rrq *rrq; |
| 661 | struct lpfc_node_rrq *nextrrq; |
| 662 | unsigned long iflags; |
| 663 | |
| 664 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 665 | return NULL; |
| 666 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 667 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 668 | if (rrq->vport == vport && rrq->xritag == xri && |
| 669 | rrq->nlp_DID == did){ |
| 670 | list_del(&rrq->list); |
| 671 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 672 | return rrq; |
| 673 | } |
| 674 | } |
| 675 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 676 | return NULL; |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 681 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 682 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 683 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 684 | * phba->active_rrq_list and clear the rrq. |
| 685 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 686 | **/ |
| 687 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 688 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 689 | |
| 690 | { |
| 691 | struct lpfc_hba *phba = vport->phba; |
| 692 | struct lpfc_node_rrq *rrq; |
| 693 | struct lpfc_node_rrq *nextrrq; |
| 694 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 695 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 696 | |
| 697 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 698 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 699 | if (!ndlp) { |
| 700 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 701 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 702 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 703 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 704 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 705 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 706 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 707 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 708 | |
| 709 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 710 | list_del(&rrq->list); |
| 711 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 712 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
| 716 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 717 | * @phba: Pointer to HBA context object. |
| 718 | * |
| 719 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 720 | * calling __lpfc_clr_active_rrq |
| 721 | * |
| 722 | **/ |
| 723 | void |
| 724 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 725 | { |
| 726 | struct lpfc_node_rrq *rrq; |
| 727 | struct lpfc_node_rrq *nextrrq; |
| 728 | unsigned long next_time; |
| 729 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 730 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 731 | |
| 732 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 733 | return; |
| 734 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 735 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 736 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 737 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 738 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 739 | |
| 740 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 741 | list_del(&rrq->list); |
| 742 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 743 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 744 | if (!list_empty(&phba->active_rrq_list)) |
| 745 | mod_timer(&phba->rrq_tmr, next_time); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 750 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 751 | * @phba: Pointer to HBA context object. |
| 752 | * @ndlp: Targets nodelist pointer for this exchange. |
| 753 | * @xritag the xri in the bitmap to test. |
| 754 | * |
| 755 | * This function is called with hbalock held. This function |
| 756 | * returns 0 = rrq not active for this xri |
| 757 | * 1 = rrq is valid for this xri. |
| 758 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 759 | int |
| 760 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 761 | uint16_t xritag) |
| 762 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 763 | if (!ndlp) |
| 764 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 765 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 766 | return 1; |
| 767 | else |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 773 | * @phba: Pointer to HBA context object. |
| 774 | * @ndlp: nodelist pointer for this target. |
| 775 | * @xritag: xri used in this exchange. |
| 776 | * @rxid: Remote Exchange ID. |
| 777 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 778 | * |
| 779 | * This function takes the hbalock. |
| 780 | * The active bit is always set in the active rrq xri_bitmap even |
| 781 | * if there is no slot avaiable for the other rrq information. |
| 782 | * |
| 783 | * returns 0 rrq actived for this xri |
| 784 | * < 0 No memory or invalid ndlp. |
| 785 | **/ |
| 786 | int |
| 787 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 788 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 789 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 790 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 791 | struct lpfc_node_rrq *rrq; |
| 792 | int empty; |
| 793 | |
| 794 | if (!ndlp) |
| 795 | return -EINVAL; |
| 796 | |
| 797 | if (!phba->cfg_enable_rrq) |
| 798 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 799 | |
| 800 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 801 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 802 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 803 | goto out; |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 | * set the active bit even if there is no mem available. |
| 808 | */ |
| 809 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 810 | goto out; |
| 811 | |
| 812 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 813 | goto out; |
| 814 | |
| 815 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 816 | goto out; |
| 817 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 818 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 819 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 820 | if (!rrq) { |
| 821 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 822 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 823 | " DID:0x%x Send:%d\n", |
| 824 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 825 | return -EINVAL; |
| 826 | } |
| 827 | rrq->send_rrq = send_rrq; |
| 828 | rrq->xritag = xritag; |
| 829 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 830 | rrq->ndlp = ndlp; |
| 831 | rrq->nlp_DID = ndlp->nlp_DID; |
| 832 | rrq->vport = ndlp->vport; |
| 833 | rrq->rxid = rxid; |
| 834 | rrq->send_rrq = send_rrq; |
| 835 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 836 | empty = list_empty(&phba->active_rrq_list); |
| 837 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 838 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 839 | if (empty) |
| 840 | lpfc_worker_wake_up(phba); |
| 841 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 842 | return 0; |
| 843 | out: |
| 844 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 845 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 846 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 847 | " DID:0x%x Send:%d\n", |
| 848 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 849 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 853 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 854 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 855 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 856 | * |
| 857 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 858 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 859 | * list is not empty then it is successful, it returns pointer to the newly |
| 860 | * allocated sglq object else it returns NULL. |
| 861 | **/ |
| 862 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 863 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 864 | { |
| 865 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 866 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 867 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | struct lpfc_scsi_buf *lpfc_cmd; |
| 869 | struct lpfc_nodelist *ndlp; |
| 870 | int found = 0; |
| 871 | |
| 872 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 873 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 874 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 875 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 876 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 877 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 878 | else |
| 879 | ndlp = piocbq->context1; |
| 880 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 881 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 882 | start_sglq = sglq; |
| 883 | while (!found) { |
| 884 | if (!sglq) |
| 885 | return NULL; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 886 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 887 | /* This xri has an rrq outstanding for this DID. |
| 888 | * put it back in the list and get another xri. |
| 889 | */ |
| 890 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 891 | sglq = NULL; |
| 892 | list_remove_head(lpfc_sgl_list, sglq, |
| 893 | struct lpfc_sglq, list); |
| 894 | if (sglq == start_sglq) { |
| 895 | sglq = NULL; |
| 896 | break; |
| 897 | } else |
| 898 | continue; |
| 899 | } |
| 900 | sglq->ndlp = ndlp; |
| 901 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 902 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 903 | sglq->state = SGL_ALLOCATED; |
| 904 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 905 | return sglq; |
| 906 | } |
| 907 | |
| 908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 909 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 910 | * @phba: Pointer to HBA context object. |
| 911 | * |
| 912 | * This function is called with no lock held. This function |
| 913 | * allocates a new driver iocb object from the iocb pool. If the |
| 914 | * allocation is successful, it returns pointer to the newly |
| 915 | * allocated iocb object else it returns NULL. |
| 916 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | struct lpfc_iocbq * |
| 918 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 919 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | struct lpfc_iocbq * iocbq = NULL; |
| 921 | unsigned long iflags; |
| 922 | |
| 923 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 924 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 925 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 926 | return iocbq; |
| 927 | } |
| 928 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 929 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 930 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 931 | * @phba: Pointer to HBA context object. |
| 932 | * @iocbq: Pointer to driver iocb object. |
| 933 | * |
| 934 | * This function is called with hbalock held to release driver |
| 935 | * iocb object to the iocb pool. The iotag in the iocb object |
| 936 | * does not change for each use of the iocb object. This function |
| 937 | * clears all other fields of the iocb object when it is freed. |
| 938 | * The sqlq structure that holds the xritag and phys and virtual |
| 939 | * mappings for the scatter gather list is retrieved from the |
| 940 | * active array of sglq. The get of the sglq pointer also clears |
| 941 | * the entry in the array. If the status of the IO indiactes that |
| 942 | * this IO was aborted then the sglq entry it put on the |
| 943 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 944 | * IO has good status or fails for any other reason then the sglq |
| 945 | * entry is added to the free list (lpfc_sgl_list). |
| 946 | **/ |
| 947 | static void |
| 948 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 949 | { |
| 950 | struct lpfc_sglq *sglq; |
| 951 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 952 | unsigned long iflag = 0; |
| 953 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 954 | |
| 955 | if (iocbq->sli4_xritag == NO_XRI) |
| 956 | sglq = NULL; |
| 957 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 958 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 959 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 960 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 961 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 962 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 963 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 964 | iflag); |
| 965 | list_add(&sglq->list, |
| 966 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 967 | spin_unlock_irqrestore( |
| 968 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 969 | } else { |
| 970 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 971 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 972 | list_add_tail(&sglq->list, |
| 973 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 974 | |
| 975 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 976 | if (pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 977 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 978 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | |
| 982 | /* |
| 983 | * Clean all volatile data fields, preserve iotag and node struct. |
| 984 | */ |
| 985 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 986 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 987 | iocbq->sli4_xritag = NO_XRI; |
| 988 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 989 | } |
| 990 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 991 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 992 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 993 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 994 | * @phba: Pointer to HBA context object. |
| 995 | * @iocbq: Pointer to driver iocb object. |
| 996 | * |
| 997 | * This function is called with hbalock held to release driver |
| 998 | * iocb object to the iocb pool. The iotag in the iocb object |
| 999 | * does not change for each use of the iocb object. This function |
| 1000 | * clears all other fields of the iocb object when it is freed. |
| 1001 | **/ |
| 1002 | static void |
| 1003 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1004 | { |
| 1005 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1006 | |
| 1007 | /* |
| 1008 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1009 | */ |
| 1010 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1011 | iocbq->sli4_xritag = NO_XRI; |
| 1012 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1013 | } |
| 1014 | |
| 1015 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1016 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1017 | * @phba: Pointer to HBA context object. |
| 1018 | * @iocbq: Pointer to driver iocb object. |
| 1019 | * |
| 1020 | * This function is called with hbalock held to release driver |
| 1021 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1022 | * does not change for each use of the iocb object. This function |
| 1023 | * clears all other fields of the iocb object when it is freed. |
| 1024 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1025 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1027 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1028 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1029 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1030 | } |
| 1031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1033 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1034 | * @phba: Pointer to HBA context object. |
| 1035 | * @iocbq: Pointer to driver iocb object. |
| 1036 | * |
| 1037 | * This function is called with no lock held to release the iocb to |
| 1038 | * iocb pool. |
| 1039 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1040 | void |
| 1041 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1042 | { |
| 1043 | unsigned long iflags; |
| 1044 | |
| 1045 | /* |
| 1046 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1047 | */ |
| 1048 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1049 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1050 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1051 | } |
| 1052 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1053 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1054 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1055 | * @phba: Pointer to HBA context object. |
| 1056 | * @iocblist: List of IOCBs. |
| 1057 | * @ulpstatus: ULP status in IOCB command field. |
| 1058 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1059 | * |
| 1060 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1061 | * on the list by invoking the complete callback function associated with the |
| 1062 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1063 | * fields. |
| 1064 | **/ |
| 1065 | void |
| 1066 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1067 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1068 | { |
| 1069 | struct lpfc_iocbq *piocb; |
| 1070 | |
| 1071 | while (!list_empty(iocblist)) { |
| 1072 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 1073 | |
| 1074 | if (!piocb->iocb_cmpl) |
| 1075 | lpfc_sli_release_iocbq(phba, piocb); |
| 1076 | else { |
| 1077 | piocb->iocb.ulpStatus = ulpstatus; |
| 1078 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1079 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1080 | } |
| 1081 | } |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1086 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1087 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1088 | * |
| 1089 | * This function is called by ring event handler function to get the iocb type. |
| 1090 | * This function translates the iocb command to an iocb command type used to |
| 1091 | * decide the final disposition of each completed IOCB. |
| 1092 | * The function returns |
| 1093 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1094 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1095 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1096 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1097 | * |
| 1098 | * The caller is not required to hold any lock. |
| 1099 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | static lpfc_iocb_type |
| 1101 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1102 | { |
| 1103 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1104 | |
| 1105 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1106 | return 0; |
| 1107 | |
| 1108 | switch (iocb_cmnd) { |
| 1109 | case CMD_XMIT_SEQUENCE_CR: |
| 1110 | case CMD_XMIT_SEQUENCE_CX: |
| 1111 | case CMD_XMIT_BCAST_CN: |
| 1112 | case CMD_XMIT_BCAST_CX: |
| 1113 | case CMD_ELS_REQUEST_CR: |
| 1114 | case CMD_ELS_REQUEST_CX: |
| 1115 | case CMD_CREATE_XRI_CR: |
| 1116 | case CMD_CREATE_XRI_CX: |
| 1117 | case CMD_GET_RPI_CN: |
| 1118 | case CMD_XMIT_ELS_RSP_CX: |
| 1119 | case CMD_GET_RPI_CR: |
| 1120 | case CMD_FCP_IWRITE_CR: |
| 1121 | case CMD_FCP_IWRITE_CX: |
| 1122 | case CMD_FCP_IREAD_CR: |
| 1123 | case CMD_FCP_IREAD_CX: |
| 1124 | case CMD_FCP_ICMND_CR: |
| 1125 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1126 | case CMD_FCP_TSEND_CX: |
| 1127 | case CMD_FCP_TRSP_CX: |
| 1128 | case CMD_FCP_TRECEIVE_CX: |
| 1129 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1130 | case CMD_ADAPTER_MSG: |
| 1131 | case CMD_ADAPTER_DUMP: |
| 1132 | case CMD_XMIT_SEQUENCE64_CR: |
| 1133 | case CMD_XMIT_SEQUENCE64_CX: |
| 1134 | case CMD_XMIT_BCAST64_CN: |
| 1135 | case CMD_XMIT_BCAST64_CX: |
| 1136 | case CMD_ELS_REQUEST64_CR: |
| 1137 | case CMD_ELS_REQUEST64_CX: |
| 1138 | case CMD_FCP_IWRITE64_CR: |
| 1139 | case CMD_FCP_IWRITE64_CX: |
| 1140 | case CMD_FCP_IREAD64_CR: |
| 1141 | case CMD_FCP_IREAD64_CX: |
| 1142 | case CMD_FCP_ICMND64_CR: |
| 1143 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1144 | case CMD_FCP_TSEND64_CX: |
| 1145 | case CMD_FCP_TRSP64_CX: |
| 1146 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1147 | case CMD_GEN_REQUEST64_CR: |
| 1148 | case CMD_GEN_REQUEST64_CX: |
| 1149 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1150 | case DSSCMD_IWRITE64_CR: |
| 1151 | case DSSCMD_IWRITE64_CX: |
| 1152 | case DSSCMD_IREAD64_CR: |
| 1153 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | type = LPFC_SOL_IOCB; |
| 1155 | break; |
| 1156 | case CMD_ABORT_XRI_CN: |
| 1157 | case CMD_ABORT_XRI_CX: |
| 1158 | case CMD_CLOSE_XRI_CN: |
| 1159 | case CMD_CLOSE_XRI_CX: |
| 1160 | case CMD_XRI_ABORTED_CX: |
| 1161 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1162 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | type = LPFC_ABORT_IOCB; |
| 1164 | break; |
| 1165 | case CMD_RCV_SEQUENCE_CX: |
| 1166 | case CMD_RCV_ELS_REQ_CX: |
| 1167 | case CMD_RCV_SEQUENCE64_CX: |
| 1168 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1169 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1170 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1171 | case CMD_IOCB_RCV_ELS64_CX: |
| 1172 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1173 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1174 | type = LPFC_UNSOL_IOCB; |
| 1175 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1176 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1177 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1178 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1179 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1180 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1181 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1182 | case CMD_IOCB_RET_HBQE64_CN: |
| 1183 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1184 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1185 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1186 | case CMD_IOCB_LOGENTRY_CN: |
| 1187 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1188 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1189 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1190 | type = LPFC_UNKNOWN_IOCB; |
| 1191 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1192 | default: |
| 1193 | type = LPFC_UNKNOWN_IOCB; |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | return type; |
| 1198 | } |
| 1199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1201 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | * @phba: Pointer to HBA context object. |
| 1203 | * |
| 1204 | * This function is called from SLI initialization code |
| 1205 | * to configure every ring of the HBA's SLI interface. The |
| 1206 | * caller is not required to hold any lock. This function issues |
| 1207 | * a config_ring mailbox command for each ring. |
| 1208 | * This function returns zero if successful else returns a negative |
| 1209 | * error code. |
| 1210 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1212 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | { |
| 1214 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1215 | LPFC_MBOXQ_t *pmb; |
| 1216 | MAILBOX_t *pmbox; |
| 1217 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1219 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1220 | if (!pmb) |
| 1221 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1222 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1223 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | lpfc_config_ring(phba, i, pmb); |
| 1226 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1227 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1229 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1231 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1232 | rc, pmbox->mbxCommand, |
| 1233 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1234 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1235 | ret = -ENXIO; |
| 1236 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | } |
| 1238 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1239 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1240 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1241 | } |
| 1242 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1243 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1244 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1245 | * @phba: Pointer to HBA context object. |
| 1246 | * @pring: Pointer to driver SLI ring object. |
| 1247 | * @piocb: Pointer to the driver iocb object. |
| 1248 | * |
| 1249 | * This function is called with hbalock held. The function adds the |
| 1250 | * new iocb to txcmplq of the given ring. This function always returns |
| 1251 | * 0. If this function is called for ELS ring, this function checks if |
| 1252 | * there is a vport associated with the ELS command. This function also |
| 1253 | * starts els_tmofunc timer if this is an ELS command. |
| 1254 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1255 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1256 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1257 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1260 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1262 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
| 1263 | pring->txcmplq_max = pring->txcmplq_cnt; |
| 1264 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1265 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1266 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1267 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1268 | if (!piocb->vport) |
| 1269 | BUG(); |
| 1270 | else |
| 1271 | mod_timer(&piocb->vport->els_tmofunc, |
| 1272 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1273 | } |
| 1274 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | } |
| 1278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1279 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1280 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1281 | * @phba: Pointer to HBA context object. |
| 1282 | * @pring: Pointer to driver SLI ring object. |
| 1283 | * |
| 1284 | * This function is called with hbalock held to get next |
| 1285 | * iocb in txq of the given ring. If there is any iocb in |
| 1286 | * the txq, the function returns first iocb in the list after |
| 1287 | * removing the iocb from the list, else it returns NULL. |
| 1288 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1289 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1290 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | struct lpfc_iocbq *cmd_iocb; |
| 1293 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1294 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 1295 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1297 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1298 | } |
| 1299 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1301 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1302 | * @phba: Pointer to HBA context object. |
| 1303 | * @pring: Pointer to driver SLI ring object. |
| 1304 | * |
| 1305 | * This function is called with hbalock held and the caller must post the |
| 1306 | * iocb without releasing the lock. If the caller releases the lock, |
| 1307 | * iocb slot returned by the function is not guaranteed to be available. |
| 1308 | * The function returns pointer to the next available iocb slot if there |
| 1309 | * is available slot in the ring, else it returns NULL. |
| 1310 | * If the get index of the ring is ahead of the put index, the function |
| 1311 | * will post an error attention event to the worker thread to take the |
| 1312 | * HBA to offline state. |
| 1313 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | static IOCB_t * |
| 1315 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1316 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1317 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1319 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 1320 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 1321 | pring->next_cmdidx = 0; |
| 1322 | |
| 1323 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 1324 | |
| 1325 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1326 | |
| 1327 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 1328 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1329 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1330 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1331 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | pring->local_getidx, max_cmd_idx); |
| 1333 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1334 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | /* |
| 1336 | * All error attention handlers are posted to |
| 1337 | * worker thread |
| 1338 | */ |
| 1339 | phba->work_ha |= HA_ERATT; |
| 1340 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1341 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1342 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | |
| 1344 | return NULL; |
| 1345 | } |
| 1346 | |
| 1347 | if (pring->local_getidx == pring->next_cmdidx) |
| 1348 | return NULL; |
| 1349 | } |
| 1350 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1351 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | } |
| 1353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1354 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1355 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1356 | * @phba: Pointer to HBA context object. |
| 1357 | * @iocbq: Pointer to driver iocb object. |
| 1358 | * |
| 1359 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1360 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1361 | * array and assigns a new iotag. |
| 1362 | * The function returns the allocated iotag if successful, else returns zero. |
| 1363 | * Zero is not a valid iotag. |
| 1364 | * The caller is not required to hold any lock. |
| 1365 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1366 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1367 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1369 | struct lpfc_iocbq **new_arr; |
| 1370 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1371 | size_t new_len; |
| 1372 | struct lpfc_sli *psli = &phba->sli; |
| 1373 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1375 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1376 | iotag = psli->last_iotag; |
| 1377 | if(++iotag < psli->iocbq_lookup_len) { |
| 1378 | psli->last_iotag = iotag; |
| 1379 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1381 | iocbq->iotag = iotag; |
| 1382 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1383 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1384 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1385 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1386 | spin_unlock_irq(&phba->hbalock); |
| 1387 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1388 | GFP_KERNEL); |
| 1389 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1390 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1391 | old_arr = psli->iocbq_lookup; |
| 1392 | if (new_len <= psli->iocbq_lookup_len) { |
| 1393 | /* highly unprobable case */ |
| 1394 | kfree(new_arr); |
| 1395 | iotag = psli->last_iotag; |
| 1396 | if(++iotag < psli->iocbq_lookup_len) { |
| 1397 | psli->last_iotag = iotag; |
| 1398 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1399 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1400 | iocbq->iotag = iotag; |
| 1401 | return iotag; |
| 1402 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1403 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1404 | return 0; |
| 1405 | } |
| 1406 | if (psli->iocbq_lookup) |
| 1407 | memcpy(new_arr, old_arr, |
| 1408 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1409 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1410 | psli->iocbq_lookup = new_arr; |
| 1411 | psli->iocbq_lookup_len = new_len; |
| 1412 | psli->last_iotag = iotag; |
| 1413 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1414 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1415 | iocbq->iotag = iotag; |
| 1416 | kfree(old_arr); |
| 1417 | return iotag; |
| 1418 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1419 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1420 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1421 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1422 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1423 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1424 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1426 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | } |
| 1428 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1429 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1430 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1431 | * @phba: Pointer to HBA context object. |
| 1432 | * @pring: Pointer to driver SLI ring object. |
| 1433 | * @iocb: Pointer to iocb slot in the ring. |
| 1434 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1435 | * posted to firmware. |
| 1436 | * |
| 1437 | * This function is called with hbalock held to post a new iocb to |
| 1438 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1439 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1440 | * a completion call back for this iocb else the function will free the |
| 1441 | * iocb object. |
| 1442 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | static void |
| 1444 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1445 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1446 | { |
| 1447 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1448 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1450 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1452 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1453 | if (pring->ringno == LPFC_ELS_RING) { |
| 1454 | lpfc_debugfs_slow_ring_trc(phba, |
| 1455 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1456 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1457 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1458 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1459 | } |
| 1460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | /* |
| 1462 | * Issue iocb command to adapter |
| 1463 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1464 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | wmb(); |
| 1466 | pring->stats.iocb_cmd++; |
| 1467 | |
| 1468 | /* |
| 1469 | * If there is no completion routine to call, we can release the |
| 1470 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1471 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1472 | */ |
| 1473 | if (nextiocb->iocb_cmpl) |
| 1474 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1475 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1476 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | |
| 1478 | /* |
| 1479 | * Let the HBA know what IOCB slot will be the next one the |
| 1480 | * driver will put a command into. |
| 1481 | */ |
| 1482 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1483 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | } |
| 1485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1487 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1488 | * @phba: Pointer to HBA context object. |
| 1489 | * @pring: Pointer to driver SLI ring object. |
| 1490 | * |
| 1491 | * The caller is not required to hold any lock for calling this function. |
| 1492 | * This function updates the chip attention bits for the ring to inform firmware |
| 1493 | * that there are pending work to be done for this ring and requests an |
| 1494 | * interrupt when there is space available in the ring. This function is |
| 1495 | * called when the driver is unable to post more iocbs to the ring due |
| 1496 | * to unavailability of space in the ring. |
| 1497 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1498 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1499 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | { |
| 1501 | int ringno = pring->ringno; |
| 1502 | |
| 1503 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1504 | |
| 1505 | wmb(); |
| 1506 | |
| 1507 | /* |
| 1508 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1509 | * The HBA will tell us when an IOCB entry is available. |
| 1510 | */ |
| 1511 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1512 | readl(phba->CAregaddr); /* flush */ |
| 1513 | |
| 1514 | pring->stats.iocb_cmd_full++; |
| 1515 | } |
| 1516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1518 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1519 | * @phba: Pointer to HBA context object. |
| 1520 | * @pring: Pointer to driver SLI ring object. |
| 1521 | * |
| 1522 | * This function updates the chip attention register bit for the |
| 1523 | * given ring to inform HBA that there is more work to be done |
| 1524 | * in this ring. The caller is not required to hold any lock. |
| 1525 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1526 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1527 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | { |
| 1529 | int ringno = pring->ringno; |
| 1530 | |
| 1531 | /* |
| 1532 | * Tell the HBA that there is work to do in this ring. |
| 1533 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1534 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1535 | wmb(); |
| 1536 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1537 | readl(phba->CAregaddr); /* flush */ |
| 1538 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1541 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1542 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1543 | * @phba: Pointer to HBA context object. |
| 1544 | * @pring: Pointer to driver SLI ring object. |
| 1545 | * |
| 1546 | * This function is called with hbalock held to post pending iocbs |
| 1547 | * in the txq to the firmware. This function is called when driver |
| 1548 | * detects space available in the ring. |
| 1549 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | { |
| 1553 | IOCB_t *iocb; |
| 1554 | struct lpfc_iocbq *nextiocb; |
| 1555 | |
| 1556 | /* |
| 1557 | * Check to see if: |
| 1558 | * (a) there is anything on the txq to send |
| 1559 | * (b) link is up |
| 1560 | * (c) link attention events can be processed (fcp ring only) |
| 1561 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1562 | */ |
| 1563 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1564 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1566 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | |
| 1568 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1569 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1570 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1571 | |
| 1572 | if (iocb) |
| 1573 | lpfc_sli_update_ring(phba, pring); |
| 1574 | else |
| 1575 | lpfc_sli_update_full_ring(phba, pring); |
| 1576 | } |
| 1577 | |
| 1578 | return; |
| 1579 | } |
| 1580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1582 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1583 | * @phba: Pointer to HBA context object. |
| 1584 | * @hbqno: HBQ number. |
| 1585 | * |
| 1586 | * This function is called with hbalock held to get the next |
| 1587 | * available slot for the given HBQ. If there is free slot |
| 1588 | * available for the HBQ it will return pointer to the next available |
| 1589 | * HBQ entry else it will return NULL. |
| 1590 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1591 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1592 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1593 | { |
| 1594 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1595 | |
| 1596 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1597 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1598 | hbqp->next_hbqPutIdx = 0; |
| 1599 | |
| 1600 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1601 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1602 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1603 | |
| 1604 | hbqp->local_hbqGetIdx = getidx; |
| 1605 | |
| 1606 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1607 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1608 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1609 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1610 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1611 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1612 | hbqp->entry_count); |
| 1613 | |
| 1614 | phba->link_state = LPFC_HBA_ERROR; |
| 1615 | return NULL; |
| 1616 | } |
| 1617 | |
| 1618 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1619 | return NULL; |
| 1620 | } |
| 1621 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1622 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1623 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1624 | } |
| 1625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1627 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | * @phba: Pointer to HBA context object. |
| 1629 | * |
| 1630 | * This function is called with no lock held to free all the |
| 1631 | * hbq buffers while uninitializing the SLI interface. It also |
| 1632 | * frees the HBQ buffers returned by the firmware but not yet |
| 1633 | * processed by the upper layers. |
| 1634 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1635 | void |
| 1636 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1637 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1638 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1639 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1640 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1641 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1642 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1643 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1644 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1645 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1646 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1647 | for (i = 0; i < hbq_count; ++i) { |
| 1648 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1649 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1650 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1651 | list_del(&hbq_buf->dbuf.list); |
| 1652 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1653 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1654 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1655 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1656 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1657 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1658 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1659 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1660 | list_del(&hbq_buf->dbuf.list); |
| 1661 | if (hbq_buf->tag == -1) { |
| 1662 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1663 | (phba, hbq_buf); |
| 1664 | } else { |
| 1665 | hbqno = hbq_buf->tag >> 16; |
| 1666 | if (hbqno >= LPFC_MAX_HBQS) |
| 1667 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1668 | (phba, hbq_buf); |
| 1669 | else |
| 1670 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1671 | hbq_buf); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /* Mark the HBQs not in use */ |
| 1676 | phba->hbq_in_use = 0; |
| 1677 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1678 | } |
| 1679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1681 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1682 | * @phba: Pointer to HBA context object. |
| 1683 | * @hbqno: HBQ number. |
| 1684 | * @hbq_buf: Pointer to HBQ buffer. |
| 1685 | * |
| 1686 | * This function is called with the hbalock held to post a |
| 1687 | * hbq buffer to the firmware. If the function finds an empty |
| 1688 | * slot in the HBQ, it will post the buffer. The function will return |
| 1689 | * pointer to the hbq entry if it successfully post the buffer |
| 1690 | * else it will return NULL. |
| 1691 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1692 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1693 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1694 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1695 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1696 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1697 | } |
| 1698 | |
| 1699 | /** |
| 1700 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1701 | * @phba: Pointer to HBA context object. |
| 1702 | * @hbqno: HBQ number. |
| 1703 | * @hbq_buf: Pointer to HBQ buffer. |
| 1704 | * |
| 1705 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1706 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1707 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1708 | * it successfully post the buffer else it will return an error. |
| 1709 | **/ |
| 1710 | static int |
| 1711 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1712 | struct hbq_dmabuf *hbq_buf) |
| 1713 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1714 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1715 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1716 | |
| 1717 | /* Get next HBQ entry slot to use */ |
| 1718 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1719 | if (hbqe) { |
| 1720 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1721 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1722 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1723 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1724 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1725 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1726 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1727 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1728 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1729 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1730 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1731 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1732 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1733 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1734 | return 0; |
| 1735 | } else |
| 1736 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1737 | } |
| 1738 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1739 | /** |
| 1740 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1741 | * @phba: Pointer to HBA context object. |
| 1742 | * @hbqno: HBQ number. |
| 1743 | * @hbq_buf: Pointer to HBQ buffer. |
| 1744 | * |
| 1745 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1746 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1747 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1748 | **/ |
| 1749 | static int |
| 1750 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1751 | struct hbq_dmabuf *hbq_buf) |
| 1752 | { |
| 1753 | int rc; |
| 1754 | struct lpfc_rqe hrqe; |
| 1755 | struct lpfc_rqe drqe; |
| 1756 | |
| 1757 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1758 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1759 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1760 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1761 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1762 | &hrqe, &drqe); |
| 1763 | if (rc < 0) |
| 1764 | return rc; |
| 1765 | hbq_buf->tag = rc; |
| 1766 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1770 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1771 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1772 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1773 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1774 | .mask_count = 0, |
| 1775 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1776 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1777 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1778 | .init_count = 40, |
| 1779 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1780 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1782 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1783 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1784 | .rn = 1, |
| 1785 | .entry_count = 200, |
| 1786 | .mask_count = 0, |
| 1787 | .profile = 0, |
| 1788 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1789 | .buffer_count = 0, |
| 1790 | .init_count = 0, |
| 1791 | .add_count = 5, |
| 1792 | }; |
| 1793 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1794 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1795 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1796 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1797 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1798 | }; |
| 1799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1800 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1801 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1802 | * @phba: Pointer to HBA context object. |
| 1803 | * @hbqno: HBQ number. |
| 1804 | * @count: Number of HBQ buffers to be posted. |
| 1805 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1806 | * This function is called with no lock held to post more hbq buffers to the |
| 1807 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1808 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1809 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1810 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1811 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1812 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1813 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1814 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1815 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1816 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1817 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1818 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1819 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1820 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1821 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1822 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1823 | phba->hbqs[hbqno].buffer_count; |
| 1824 | if (!count) |
| 1825 | return 0; |
| 1826 | /* Allocate HBQ entries */ |
| 1827 | for (i = 0; i < count; i++) { |
| 1828 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1829 | if (!hbq_buffer) |
| 1830 | break; |
| 1831 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1832 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1833 | /* Check whether HBQ is still in use */ |
| 1834 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1835 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1836 | goto err; |
| 1837 | while (!list_empty(&hbq_buf_list)) { |
| 1838 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1839 | dbuf.list); |
| 1840 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1841 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1842 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1843 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1844 | posted++; |
| 1845 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1846 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1848 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1849 | return posted; |
| 1850 | err: |
| 1851 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1852 | while (!list_empty(&hbq_buf_list)) { |
| 1853 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1854 | dbuf.list); |
| 1855 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1856 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1858 | } |
| 1859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1861 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1862 | * @phba: Pointer to HBA context object. |
| 1863 | * @qno: HBQ number. |
| 1864 | * |
| 1865 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1866 | * is called with no lock held. The function returns the number of HBQ entries |
| 1867 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1868 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1869 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1870 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1871 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1872 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1873 | return 0; |
| 1874 | else |
| 1875 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1876 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1877 | } |
| 1878 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1879 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1880 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | * @phba: Pointer to HBA context object. |
| 1882 | * @qno: HBQ queue number. |
| 1883 | * |
| 1884 | * This function is called from SLI initialization code path with |
| 1885 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1886 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1887 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1888 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1889 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1890 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1891 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1892 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1893 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1894 | else |
| 1895 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1896 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1897 | } |
| 1898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1899 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1900 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1901 | * @phba: Pointer to HBA context object. |
| 1902 | * @hbqno: HBQ number. |
| 1903 | * |
| 1904 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1905 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1906 | **/ |
| 1907 | static struct hbq_dmabuf * |
| 1908 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1909 | { |
| 1910 | struct lpfc_dmabuf *d_buf; |
| 1911 | |
| 1912 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1913 | if (!d_buf) |
| 1914 | return NULL; |
| 1915 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1916 | } |
| 1917 | |
| 1918 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1919 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1920 | * @phba: Pointer to HBA context object. |
| 1921 | * @tag: Tag of the hbq buffer. |
| 1922 | * |
| 1923 | * This function is called with hbalock held. This function searches |
| 1924 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1925 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1926 | * it returns NULL. |
| 1927 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1928 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1929 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1930 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1931 | struct lpfc_dmabuf *d_buf; |
| 1932 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1933 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1934 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1935 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1936 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1937 | return NULL; |
| 1938 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1939 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1940 | 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] | 1941 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1942 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1943 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1944 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1945 | } |
| 1946 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1947 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1948 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1949 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1950 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1951 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1952 | } |
| 1953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1955 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1956 | * @phba: Pointer to HBA context object. |
| 1957 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1958 | * |
| 1959 | * This function is called with hbalock. This function gives back |
| 1960 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1961 | * post the buffer, it will free the buffer. |
| 1962 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1963 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1964 | 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] | 1965 | { |
| 1966 | uint32_t hbqno; |
| 1967 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1968 | if (hbq_buffer) { |
| 1969 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1970 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1971 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1972 | } |
| 1973 | } |
| 1974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1975 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1976 | * 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] | 1977 | * @mbxCommand: mailbox command code. |
| 1978 | * |
| 1979 | * This function is called by the mailbox event handler function to verify |
| 1980 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1981 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1982 | * and the mailbox event handler will take the HBA offline. |
| 1983 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | static int |
| 1985 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1986 | { |
| 1987 | uint8_t ret; |
| 1988 | |
| 1989 | switch (mbxCommand) { |
| 1990 | case MBX_LOAD_SM: |
| 1991 | case MBX_READ_NV: |
| 1992 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1993 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | case MBX_RUN_BIU_DIAG: |
| 1995 | case MBX_INIT_LINK: |
| 1996 | case MBX_DOWN_LINK: |
| 1997 | case MBX_CONFIG_LINK: |
| 1998 | case MBX_CONFIG_RING: |
| 1999 | case MBX_RESET_RING: |
| 2000 | case MBX_READ_CONFIG: |
| 2001 | case MBX_READ_RCONFIG: |
| 2002 | case MBX_READ_SPARM: |
| 2003 | case MBX_READ_STATUS: |
| 2004 | case MBX_READ_RPI: |
| 2005 | case MBX_READ_XRI: |
| 2006 | case MBX_READ_REV: |
| 2007 | case MBX_READ_LNK_STAT: |
| 2008 | case MBX_REG_LOGIN: |
| 2009 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2010 | case MBX_CLEAR_LA: |
| 2011 | case MBX_DUMP_MEMORY: |
| 2012 | case MBX_DUMP_CONTEXT: |
| 2013 | case MBX_RUN_DIAGS: |
| 2014 | case MBX_RESTART: |
| 2015 | case MBX_UPDATE_CFG: |
| 2016 | case MBX_DOWN_LOAD: |
| 2017 | case MBX_DEL_LD_ENTRY: |
| 2018 | case MBX_RUN_PROGRAM: |
| 2019 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2020 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2022 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2024 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | case MBX_LOAD_AREA: |
| 2026 | case MBX_RUN_BIU_DIAG64: |
| 2027 | case MBX_CONFIG_PORT: |
| 2028 | case MBX_READ_SPARM64: |
| 2029 | case MBX_READ_RPI64: |
| 2030 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2031 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2032 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | case MBX_SET_DEBUG: |
| 2034 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2035 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2036 | case MBX_REG_VPI: |
| 2037 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2038 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2039 | case MBX_PORT_CAPABILITIES: |
| 2040 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2041 | case MBX_SLI4_CONFIG: |
| 2042 | case MBX_SLI4_REQ_FTRS: |
| 2043 | case MBX_REG_FCFI: |
| 2044 | case MBX_UNREG_FCFI: |
| 2045 | case MBX_REG_VFI: |
| 2046 | case MBX_UNREG_VFI: |
| 2047 | case MBX_INIT_VPI: |
| 2048 | case MBX_INIT_VFI: |
| 2049 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2050 | case MBX_READ_EVENT_LOG_STATUS: |
| 2051 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2052 | case MBX_SECURITY_MGMT: |
| 2053 | case MBX_AUTH_PORT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | ret = mbxCommand; |
| 2055 | break; |
| 2056 | default: |
| 2057 | ret = MBX_SHUTDOWN; |
| 2058 | break; |
| 2059 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2060 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2062 | |
| 2063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2064 | * 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] | 2065 | * @phba: Pointer to HBA context object. |
| 2066 | * @pmboxq: Pointer to mailbox command. |
| 2067 | * |
| 2068 | * This is completion handler function for mailbox commands issued from |
| 2069 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2070 | * mailbox event handler function with no lock held. This function |
| 2071 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2072 | * of the mailbox. |
| 2073 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2074 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | { |
| 2077 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2078 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | |
| 2080 | /* |
| 2081 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2082 | * continued running. |
| 2083 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2084 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2085 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2087 | if (pdone_q) |
| 2088 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2089 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | return; |
| 2091 | } |
| 2092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2093 | |
| 2094 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2095 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2096 | * @phba: Pointer to HBA context object. |
| 2097 | * @pmb: Pointer to mailbox object. |
| 2098 | * |
| 2099 | * This function is the default mailbox completion handler. It |
| 2100 | * frees the memory resources associated with the completed mailbox |
| 2101 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2102 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2103 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2105 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2107 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2109 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2110 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2111 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2112 | int rc; |
| 2113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | if (mp) { |
| 2117 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2118 | kfree(mp); |
| 2119 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2120 | |
| 2121 | /* |
| 2122 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2123 | * is in re-discovery driver need to cleanup the RPI. |
| 2124 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2126 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2127 | !pmb->u.mb.mbxStatus) { |
| 2128 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2129 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2130 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2131 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2132 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2133 | if (rc != MBX_NOT_FINISHED) |
| 2134 | return; |
| 2135 | } |
| 2136 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2137 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2138 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2139 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2140 | shost = lpfc_shost_from_vport(vport); |
| 2141 | spin_lock_irq(shost->host_lock); |
| 2142 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2143 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2144 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2145 | } |
| 2146 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2147 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2148 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2149 | lpfc_nlp_put(ndlp); |
| 2150 | pmb->context2 = NULL; |
| 2151 | } |
| 2152 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2153 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2154 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2155 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2156 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2157 | "2860 SLI authentication is required " |
| 2158 | "for INIT_LINK but has not done yet\n"); |
| 2159 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2160 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2161 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2162 | else |
| 2163 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | } |
| 2165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2167 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2168 | * @phba: Pointer to HBA context object. |
| 2169 | * |
| 2170 | * This function is called with no lock held. This function processes all |
| 2171 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2172 | * service routine processes mailbox completion interrupt and adds completed |
| 2173 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2174 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2175 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2176 | * function returns the mailbox commands to the upper layer by calling the |
| 2177 | * completion handler function of each mailbox. |
| 2178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2182 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | int rc; |
| 2185 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | |
| 2187 | phba->sli.slistat.mbox_event++; |
| 2188 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2189 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2190 | spin_lock_irq(&phba->hbalock); |
| 2191 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2192 | spin_unlock_irq(&phba->hbalock); |
| 2193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2195 | do { |
| 2196 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2197 | if (pmb == NULL) |
| 2198 | break; |
| 2199 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2200 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2202 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2203 | if (pmb->vport) { |
| 2204 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2205 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2206 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2207 | (uint32_t)pmbox->mbxCommand, |
| 2208 | pmbox->un.varWords[0], |
| 2209 | pmbox->un.varWords[1]); |
| 2210 | } |
| 2211 | else { |
| 2212 | lpfc_debugfs_disc_trc(phba->pport, |
| 2213 | LPFC_DISC_TRC_MBOX, |
| 2214 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2215 | (uint32_t)pmbox->mbxCommand, |
| 2216 | pmbox->un.varWords[0], |
| 2217 | pmbox->un.varWords[1]); |
| 2218 | } |
| 2219 | } |
| 2220 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | /* |
| 2222 | * It is a fatal error if unknown mbox command completion. |
| 2223 | */ |
| 2224 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2225 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2226 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2227 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2228 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2229 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2230 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2231 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2232 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2233 | pmb), |
| 2234 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2235 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2236 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | phba->work_hs = HS_FFER3; |
| 2238 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2239 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | } |
| 2241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | if (pmbox->mbxStatus) { |
| 2243 | phba->sli.slistat.mbox_stat_err++; |
| 2244 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2245 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2246 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2247 | LOG_MBOX | LOG_SLI, |
| 2248 | "(%d):0305 Mbox cmd cmpl " |
| 2249 | "error - RETRYing Data: x%x " |
| 2250 | "(x%x/x%x) x%x x%x x%x\n", |
| 2251 | pmb->vport ? pmb->vport->vpi : 0, |
| 2252 | pmbox->mbxCommand, |
| 2253 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2254 | pmb), |
| 2255 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2256 | pmb), |
| 2257 | pmbox->mbxStatus, |
| 2258 | pmbox->un.varWords[0], |
| 2259 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | pmbox->mbxStatus = 0; |
| 2261 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2263 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2264 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2269 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2270 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | "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] | 2272 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2274 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2275 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2276 | pmb->mbox_cmpl, |
| 2277 | *((uint32_t *) pmbox), |
| 2278 | pmbox->un.varWords[0], |
| 2279 | pmbox->un.varWords[1], |
| 2280 | pmbox->un.varWords[2], |
| 2281 | pmbox->un.varWords[3], |
| 2282 | pmbox->un.varWords[4], |
| 2283 | pmbox->un.varWords[5], |
| 2284 | pmbox->un.varWords[6], |
| 2285 | pmbox->un.varWords[7]); |
| 2286 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2287 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2290 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2294 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | * @phba: Pointer to HBA context object. |
| 2296 | * @pring: Pointer to driver SLI ring object. |
| 2297 | * @tag: buffer tag. |
| 2298 | * |
| 2299 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2300 | * is set in the tag the buffer is posted for a particular exchange, |
| 2301 | * the function will return the buffer without replacing the buffer. |
| 2302 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2303 | * returns the buffer and also posts another buffer to the firmware. |
| 2304 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2305 | static struct lpfc_dmabuf * |
| 2306 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2307 | struct lpfc_sli_ring *pring, |
| 2308 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2309 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2310 | struct hbq_dmabuf *hbq_entry; |
| 2311 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2312 | if (tag & QUE_BUFTAG_BIT) |
| 2313 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2314 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2315 | if (!hbq_entry) |
| 2316 | return NULL; |
| 2317 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2318 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2319 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2320 | /** |
| 2321 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2322 | * @phba: Pointer to HBA context object. |
| 2323 | * @pring: Pointer to driver SLI ring object. |
| 2324 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2325 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2326 | * @fch_type: the type for the first frame of the sequence. |
| 2327 | * |
| 2328 | * This function is called with no lock held. This function uses the r_ctl and |
| 2329 | * type of the received sequence to find the correct callback function to call |
| 2330 | * to process the sequence. |
| 2331 | **/ |
| 2332 | static int |
| 2333 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2334 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2335 | uint32_t fch_type) |
| 2336 | { |
| 2337 | int i; |
| 2338 | |
| 2339 | /* unSolicited Responses */ |
| 2340 | if (pring->prt[0].profile) { |
| 2341 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2342 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2343 | saveq); |
| 2344 | return 1; |
| 2345 | } |
| 2346 | /* We must search, based on rctl / type |
| 2347 | for the right routine */ |
| 2348 | for (i = 0; i < pring->num_mask; i++) { |
| 2349 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2350 | (pring->prt[i].type == fch_type)) { |
| 2351 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2352 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2353 | (phba, pring, saveq); |
| 2354 | return 1; |
| 2355 | } |
| 2356 | } |
| 2357 | return 0; |
| 2358 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2359 | |
| 2360 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2361 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2362 | * @phba: Pointer to HBA context object. |
| 2363 | * @pring: Pointer to driver SLI ring object. |
| 2364 | * @saveq: Pointer to the unsolicited iocb. |
| 2365 | * |
| 2366 | * This function is called with no lock held by the ring event handler |
| 2367 | * when there is an unsolicited iocb posted to the response ring by the |
| 2368 | * firmware. This function gets the buffer associated with the iocbs |
| 2369 | * and calls the event handler for the ring. This function handles both |
| 2370 | * qring buffers and hbq buffers. |
| 2371 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2372 | * upper layer functions will free the iocb objects. |
| 2373 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | static int |
| 2375 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2376 | struct lpfc_iocbq *saveq) |
| 2377 | { |
| 2378 | IOCB_t * irsp; |
| 2379 | WORD5 * w5p; |
| 2380 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2381 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2382 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2383 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | |
| 2385 | match = 0; |
| 2386 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2387 | |
| 2388 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2389 | if (pring->lpfc_sli_rcv_async_status) |
| 2390 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2391 | else |
| 2392 | lpfc_printf_log(phba, |
| 2393 | KERN_WARNING, |
| 2394 | LOG_SLI, |
| 2395 | "0316 Ring %d handler: unexpected " |
| 2396 | "ASYNC_STATUS iocb received evt_code " |
| 2397 | "0x%x\n", |
| 2398 | pring->ringno, |
| 2399 | irsp->un.asyncstat.evt_code); |
| 2400 | return 1; |
| 2401 | } |
| 2402 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2403 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2404 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2405 | if (irsp->ulpBdeCount > 0) { |
| 2406 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2407 | irsp->un.ulpWord[3]); |
| 2408 | lpfc_in_buf_free(phba, dmzbuf); |
| 2409 | } |
| 2410 | |
| 2411 | if (irsp->ulpBdeCount > 1) { |
| 2412 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2413 | irsp->unsli3.sli3Words[3]); |
| 2414 | lpfc_in_buf_free(phba, dmzbuf); |
| 2415 | } |
| 2416 | |
| 2417 | if (irsp->ulpBdeCount > 2) { |
| 2418 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2419 | irsp->unsli3.sli3Words[7]); |
| 2420 | lpfc_in_buf_free(phba, dmzbuf); |
| 2421 | } |
| 2422 | |
| 2423 | return 1; |
| 2424 | } |
| 2425 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2426 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2427 | if (irsp->ulpBdeCount != 0) { |
| 2428 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2430 | if (!saveq->context2) |
| 2431 | lpfc_printf_log(phba, |
| 2432 | KERN_ERR, |
| 2433 | LOG_SLI, |
| 2434 | "0341 Ring %d Cannot find buffer for " |
| 2435 | "an unsolicited iocb. tag 0x%x\n", |
| 2436 | pring->ringno, |
| 2437 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2438 | } |
| 2439 | if (irsp->ulpBdeCount == 2) { |
| 2440 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2441 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2442 | if (!saveq->context3) |
| 2443 | lpfc_printf_log(phba, |
| 2444 | KERN_ERR, |
| 2445 | LOG_SLI, |
| 2446 | "0342 Ring %d Cannot find buffer for an" |
| 2447 | " unsolicited iocb. tag 0x%x\n", |
| 2448 | pring->ringno, |
| 2449 | irsp->unsli3.sli3Words[7]); |
| 2450 | } |
| 2451 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2452 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2453 | if (irsp->ulpBdeCount != 0) { |
| 2454 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2455 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2456 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2457 | lpfc_printf_log(phba, |
| 2458 | KERN_ERR, |
| 2459 | LOG_SLI, |
| 2460 | "0343 Ring %d Cannot find " |
| 2461 | "buffer for an unsolicited iocb" |
| 2462 | ". tag 0x%x\n", pring->ringno, |
| 2463 | irsp->un.ulpWord[3]); |
| 2464 | } |
| 2465 | if (irsp->ulpBdeCount == 2) { |
| 2466 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2467 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2468 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2469 | lpfc_printf_log(phba, |
| 2470 | KERN_ERR, |
| 2471 | LOG_SLI, |
| 2472 | "0344 Ring %d Cannot find " |
| 2473 | "buffer for an unsolicited " |
| 2474 | "iocb. tag 0x%x\n", |
| 2475 | pring->ringno, |
| 2476 | irsp->unsli3.sli3Words[7]); |
| 2477 | } |
| 2478 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2479 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2480 | if (irsp->ulpBdeCount != 0 && |
| 2481 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2482 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2483 | int found = 0; |
| 2484 | |
| 2485 | /* search continue save q for same XRI */ |
| 2486 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2487 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2488 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2489 | list_add_tail(&saveq->list, &iocbq->list); |
| 2490 | found = 1; |
| 2491 | break; |
| 2492 | } |
| 2493 | } |
| 2494 | if (!found) |
| 2495 | list_add_tail(&saveq->clist, |
| 2496 | &pring->iocb_continue_saveq); |
| 2497 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2498 | list_del_init(&iocbq->clist); |
| 2499 | saveq = iocbq; |
| 2500 | irsp = &(saveq->iocb); |
| 2501 | } else |
| 2502 | return 0; |
| 2503 | } |
| 2504 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2505 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2506 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2507 | Rctl = FC_RCTL_ELS_REQ; |
| 2508 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2509 | } else { |
| 2510 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2511 | Rctl = w5p->hcsw.Rctl; |
| 2512 | Type = w5p->hcsw.Type; |
| 2513 | |
| 2514 | /* Firmware Workaround */ |
| 2515 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2516 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2517 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2518 | Rctl = FC_RCTL_ELS_REQ; |
| 2519 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2520 | w5p->hcsw.Rctl = Rctl; |
| 2521 | w5p->hcsw.Type = Type; |
| 2522 | } |
| 2523 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2524 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2525 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2526 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2527 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2528 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2529 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2530 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2531 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | } |
| 2533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2535 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2536 | * @phba: Pointer to HBA context object. |
| 2537 | * @pring: Pointer to driver SLI ring object. |
| 2538 | * @prspiocb: Pointer to response iocb object. |
| 2539 | * |
| 2540 | * This function looks up the iocb_lookup table to get the command iocb |
| 2541 | * corresponding to the given response iocb using the iotag of the |
| 2542 | * response iocb. This function is called with the hbalock held. |
| 2543 | * This function returns the command iocb object if it finds the command |
| 2544 | * iocb else returns NULL. |
| 2545 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2547 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2548 | struct lpfc_sli_ring *pring, |
| 2549 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2551 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2552 | uint16_t iotag; |
| 2553 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2554 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2556 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2557 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | list_del_init(&cmd_iocb->list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2559 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
| 2560 | pring->txcmplq_cnt--; |
| 2561 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; |
| 2562 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2563 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | } |
| 2565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2567 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2568 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2569 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2570 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | return NULL; |
| 2572 | } |
| 2573 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2574 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2575 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2576 | * @phba: Pointer to HBA context object. |
| 2577 | * @pring: Pointer to driver SLI ring object. |
| 2578 | * @iotag: IOCB tag. |
| 2579 | * |
| 2580 | * This function looks up the iocb_lookup table to get the command iocb |
| 2581 | * corresponding to the given iotag. This function is called with the |
| 2582 | * hbalock held. |
| 2583 | * This function returns the command iocb object if it finds the command |
| 2584 | * iocb else returns NULL. |
| 2585 | **/ |
| 2586 | static struct lpfc_iocbq * |
| 2587 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2588 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2589 | { |
| 2590 | struct lpfc_iocbq *cmd_iocb; |
| 2591 | |
| 2592 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2593 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
| 2594 | list_del_init(&cmd_iocb->list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2595 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
| 2596 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; |
| 2597 | pring->txcmplq_cnt--; |
| 2598 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2599 | return cmd_iocb; |
| 2600 | } |
| 2601 | |
| 2602 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2603 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2604 | iotag, phba->sli.last_iotag); |
| 2605 | return NULL; |
| 2606 | } |
| 2607 | |
| 2608 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2609 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2610 | * @phba: Pointer to HBA context object. |
| 2611 | * @pring: Pointer to driver SLI ring object. |
| 2612 | * @saveq: Pointer to the response iocb to be processed. |
| 2613 | * |
| 2614 | * This function is called by the ring event handler for non-fcp |
| 2615 | * rings when there is a new response iocb in the response ring. |
| 2616 | * The caller is not required to hold any locks. This function |
| 2617 | * gets the command iocb associated with the response iocb and |
| 2618 | * calls the completion handler for the command iocb. If there |
| 2619 | * is no completion handler, the function will free the resources |
| 2620 | * associated with command iocb. If the response iocb is for |
| 2621 | * an already aborted command iocb, the status of the completion |
| 2622 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2623 | * This function always returns 1. |
| 2624 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2626 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | struct lpfc_iocbq *saveq) |
| 2628 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2629 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | int rc = 1; |
| 2631 | unsigned long iflag; |
| 2632 | |
| 2633 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2634 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2635 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2637 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | if (cmdiocbp) { |
| 2639 | if (cmdiocbp->iocb_cmpl) { |
| 2640 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2641 | * If an ELS command failed send an event to mgmt |
| 2642 | * application. |
| 2643 | */ |
| 2644 | if (saveq->iocb.ulpStatus && |
| 2645 | (pring->ringno == LPFC_ELS_RING) && |
| 2646 | (cmdiocbp->iocb.ulpCommand == |
| 2647 | CMD_ELS_REQUEST64_CR)) |
| 2648 | lpfc_send_els_failure_event(phba, |
| 2649 | cmdiocbp, saveq); |
| 2650 | |
| 2651 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | * Post all ELS completions to the worker thread. |
| 2653 | * All other are passed to the completion callback. |
| 2654 | */ |
| 2655 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2656 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2657 | (cmdiocbp->iocb_flag & |
| 2658 | LPFC_DRIVER_ABORTED)) { |
| 2659 | spin_lock_irqsave(&phba->hbalock, |
| 2660 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2661 | cmdiocbp->iocb_flag &= |
| 2662 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2663 | spin_unlock_irqrestore(&phba->hbalock, |
| 2664 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2665 | saveq->iocb.ulpStatus = |
| 2666 | IOSTAT_LOCAL_REJECT; |
| 2667 | saveq->iocb.un.ulpWord[4] = |
| 2668 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2669 | |
| 2670 | /* Firmware could still be in progress |
| 2671 | * of DMAing payload, so don't free data |
| 2672 | * buffer till after a hbeat. |
| 2673 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2674 | spin_lock_irqsave(&phba->hbalock, |
| 2675 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2676 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2677 | spin_unlock_irqrestore(&phba->hbalock, |
| 2678 | iflag); |
| 2679 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2680 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2681 | if (saveq->iocb_flag & |
| 2682 | LPFC_EXCHANGE_BUSY) { |
| 2683 | /* Set cmdiocb flag for the |
| 2684 | * exchange busy so sgl (xri) |
| 2685 | * will not be released until |
| 2686 | * the abort xri is received |
| 2687 | * from hba. |
| 2688 | */ |
| 2689 | spin_lock_irqsave( |
| 2690 | &phba->hbalock, iflag); |
| 2691 | cmdiocbp->iocb_flag |= |
| 2692 | LPFC_EXCHANGE_BUSY; |
| 2693 | spin_unlock_irqrestore( |
| 2694 | &phba->hbalock, iflag); |
| 2695 | } |
| 2696 | if (cmdiocbp->iocb_flag & |
| 2697 | LPFC_DRIVER_ABORTED) { |
| 2698 | /* |
| 2699 | * Clear LPFC_DRIVER_ABORTED |
| 2700 | * bit in case it was driver |
| 2701 | * initiated abort. |
| 2702 | */ |
| 2703 | spin_lock_irqsave( |
| 2704 | &phba->hbalock, iflag); |
| 2705 | cmdiocbp->iocb_flag &= |
| 2706 | ~LPFC_DRIVER_ABORTED; |
| 2707 | spin_unlock_irqrestore( |
| 2708 | &phba->hbalock, iflag); |
| 2709 | cmdiocbp->iocb.ulpStatus = |
| 2710 | IOSTAT_LOCAL_REJECT; |
| 2711 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2712 | IOERR_ABORT_REQUESTED; |
| 2713 | /* |
| 2714 | * For SLI4, irsiocb contains |
| 2715 | * NO_XRI in sli_xritag, it |
| 2716 | * shall not affect releasing |
| 2717 | * sgl (xri) process. |
| 2718 | */ |
| 2719 | saveq->iocb.ulpStatus = |
| 2720 | IOSTAT_LOCAL_REJECT; |
| 2721 | saveq->iocb.un.ulpWord[4] = |
| 2722 | IOERR_SLI_ABORTED; |
| 2723 | spin_lock_irqsave( |
| 2724 | &phba->hbalock, iflag); |
| 2725 | saveq->iocb_flag |= |
| 2726 | LPFC_DELAY_MEM_FREE; |
| 2727 | spin_unlock_irqrestore( |
| 2728 | &phba->hbalock, iflag); |
| 2729 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2730 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2733 | } else |
| 2734 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | } else { |
| 2736 | /* |
| 2737 | * Unknown initiating command based on the response iotag. |
| 2738 | * This could be the case on the ELS ring because of |
| 2739 | * lpfc_els_abort(). |
| 2740 | */ |
| 2741 | if (pring->ringno != LPFC_ELS_RING) { |
| 2742 | /* |
| 2743 | * Ring <ringno> handler: unexpected completion IoTag |
| 2744 | * <IoTag> |
| 2745 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2746 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2747 | "0322 Ring %d handler: " |
| 2748 | "unexpected completion IoTag x%x " |
| 2749 | "Data: x%x x%x x%x x%x\n", |
| 2750 | pring->ringno, |
| 2751 | saveq->iocb.ulpIoTag, |
| 2752 | saveq->iocb.ulpStatus, |
| 2753 | saveq->iocb.un.ulpWord[4], |
| 2754 | saveq->iocb.ulpCommand, |
| 2755 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | } |
| 2757 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2758 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | return rc; |
| 2760 | } |
| 2761 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2763 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2764 | * @phba: Pointer to HBA context object. |
| 2765 | * @pring: Pointer to driver SLI ring object. |
| 2766 | * |
| 2767 | * This function is called from the iocb ring event handlers when |
| 2768 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2769 | * an error attention condition to the worker thread and the worker |
| 2770 | * thread will transition the HBA to offline state. |
| 2771 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | static void |
| 2773 | 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] | 2774 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2775 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2776 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2777 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2778 | * rsp ring <portRspMax> |
| 2779 | */ |
| 2780 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2781 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2782 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2783 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2784 | pring->numRiocb); |
| 2785 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2787 | |
| 2788 | /* |
| 2789 | * All error attention handlers are posted to |
| 2790 | * worker thread |
| 2791 | */ |
| 2792 | phba->work_ha |= HA_ERATT; |
| 2793 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2794 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2795 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2796 | |
| 2797 | return; |
| 2798 | } |
| 2799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2800 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2801 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2802 | * @ptr: Pointer to address of HBA context object. |
| 2803 | * |
| 2804 | * This function is invoked by the Error Attention polling timer when the |
| 2805 | * timer times out. It will check the SLI Error Attention register for |
| 2806 | * possible attention events. If so, it will post an Error Attention event |
| 2807 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2808 | * Error Attention polling timer for the next poll. |
| 2809 | **/ |
| 2810 | void lpfc_poll_eratt(unsigned long ptr) |
| 2811 | { |
| 2812 | struct lpfc_hba *phba; |
| 2813 | uint32_t eratt = 0; |
| 2814 | |
| 2815 | phba = (struct lpfc_hba *)ptr; |
| 2816 | |
| 2817 | /* Check chip HA register for error event */ |
| 2818 | eratt = lpfc_sli_check_eratt(phba); |
| 2819 | |
| 2820 | if (eratt) |
| 2821 | /* Tell the worker thread there is work to do */ |
| 2822 | lpfc_worker_wake_up(phba); |
| 2823 | else |
| 2824 | /* Restart the timer for next eratt poll */ |
| 2825 | mod_timer(&phba->eratt_poll, jiffies + |
| 2826 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2827 | return; |
| 2828 | } |
| 2829 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2831 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2832 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2833 | * @phba: Pointer to HBA context object. |
| 2834 | * @pring: Pointer to driver SLI ring object. |
| 2835 | * @mask: Host attention register mask for this ring. |
| 2836 | * |
| 2837 | * This function is called from the interrupt context when there is a ring |
| 2838 | * event for the fcp ring. The caller does not hold any lock. |
| 2839 | * The function processes each response iocb in the response ring until it |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2840 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2841 | * LE bit set. The function will call the completion handler of the command iocb |
| 2842 | * if the response iocb indicates a completion for a command iocb or it is |
| 2843 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2844 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2846 | * to check it explicitly. |
| 2847 | */ |
| 2848 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2849 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2850 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2852 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2854 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2856 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | uint32_t status; |
| 2858 | uint32_t portRspPut, portRspMax; |
| 2859 | int rc = 1; |
| 2860 | lpfc_iocb_type type; |
| 2861 | unsigned long iflag; |
| 2862 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2864 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | pring->stats.iocb_event++; |
| 2866 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | /* |
| 2868 | * The next available response entry should never exceed the maximum |
| 2869 | * entries. If it does, treat it as an adapter hardware error. |
| 2870 | */ |
| 2871 | portRspMax = pring->numRiocb; |
| 2872 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2873 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2874 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2875 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | return 1; |
| 2877 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2878 | if (phba->fcp_ring_in_use) { |
| 2879 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2880 | return 1; |
| 2881 | } else |
| 2882 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2883 | |
| 2884 | rmb(); |
| 2885 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2886 | /* |
| 2887 | * Fetch an entry off the ring and copy it into a local data |
| 2888 | * structure. The copy involves a byte-swap since the |
| 2889 | * network byte order and pci byte orders are different. |
| 2890 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2891 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2892 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2893 | |
| 2894 | if (++pring->rspidx >= portRspMax) |
| 2895 | pring->rspidx = 0; |
| 2896 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2897 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2898 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2899 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2900 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2901 | irsp = &rspiocbq.iocb; |
| 2902 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2903 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2904 | pring->stats.iocb_rsp++; |
| 2905 | rsp_cmpl++; |
| 2906 | |
| 2907 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2908 | /* |
| 2909 | * If resource errors reported from HBA, reduce |
| 2910 | * queuedepths of the SCSI device. |
| 2911 | */ |
| 2912 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2913 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2914 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2915 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2916 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2917 | } |
| 2918 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | /* Rsp ring <ringno> error: IOCB */ |
| 2920 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2921 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2922 | "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] | 2923 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | irsp->un.ulpWord[0], |
| 2925 | irsp->un.ulpWord[1], |
| 2926 | irsp->un.ulpWord[2], |
| 2927 | irsp->un.ulpWord[3], |
| 2928 | irsp->un.ulpWord[4], |
| 2929 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2930 | *(uint32_t *)&irsp->un1, |
| 2931 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | switch (type) { |
| 2935 | case LPFC_ABORT_IOCB: |
| 2936 | case LPFC_SOL_IOCB: |
| 2937 | /* |
| 2938 | * Idle exchange closed via ABTS from port. No iocb |
| 2939 | * resources need to be recovered. |
| 2940 | */ |
| 2941 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2942 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2943 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2944 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2945 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2946 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | break; |
| 2948 | } |
| 2949 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2950 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2951 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2952 | if (unlikely(!cmdiocbq)) |
| 2953 | break; |
| 2954 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 2955 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 2956 | if (cmdiocbq->iocb_cmpl) { |
| 2957 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2958 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2959 | &rspiocbq); |
| 2960 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2961 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2963 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2964 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2965 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2966 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2967 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | default: |
| 2969 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2970 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2971 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2972 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2973 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2974 | dev_warn(&((phba->pcidev)->dev), |
| 2975 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2976 | phba->brd_no, adaptermsg); |
| 2977 | } else { |
| 2978 | /* Unknown IOCB command */ |
| 2979 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2980 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2981 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2982 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | irsp->ulpStatus, |
| 2984 | irsp->ulpIoTag, |
| 2985 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | } |
| 2987 | break; |
| 2988 | } |
| 2989 | |
| 2990 | /* |
| 2991 | * The response IOCB has been processed. Update the ring |
| 2992 | * pointer in SLIM. If the port response put pointer has not |
| 2993 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2994 | * response put pointer. |
| 2995 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2996 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | |
| 2998 | if (pring->rspidx == portRspPut) |
| 2999 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3000 | } |
| 3001 | |
| 3002 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3003 | pring->stats.iocb_rsp_full++; |
| 3004 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3005 | writel(status, phba->CAregaddr); |
| 3006 | readl(phba->CAregaddr); |
| 3007 | } |
| 3008 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3009 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3010 | pring->stats.iocb_cmd_empty++; |
| 3011 | |
| 3012 | /* Force update of the local copy of cmdGetInx */ |
| 3013 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 3014 | lpfc_sli_resume_iocb(phba, pring); |
| 3015 | |
| 3016 | if ((pring->lpfc_sli_cmd_available)) |
| 3017 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3018 | |
| 3019 | } |
| 3020 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3021 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | return rc; |
| 3024 | } |
| 3025 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3026 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3027 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3028 | * @phba: Pointer to HBA context object. |
| 3029 | * @pring: Pointer to driver SLI ring object. |
| 3030 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3031 | * |
| 3032 | * This function is called from the worker thread when there is a slow-path |
| 3033 | * response IOCB to process. This function chains all the response iocbs until |
| 3034 | * seeing the iocb with the LE bit set. The function will call |
| 3035 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3036 | * completion of a command iocb. The function will call the |
| 3037 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3038 | * The function frees the resources or calls the completion handler if this |
| 3039 | * iocb is an abort completion. The function returns NULL when the response |
| 3040 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3041 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3042 | * response iocb passed in. |
| 3043 | **/ |
| 3044 | static struct lpfc_iocbq * |
| 3045 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3046 | struct lpfc_iocbq *rspiocbp) |
| 3047 | { |
| 3048 | struct lpfc_iocbq *saveq; |
| 3049 | struct lpfc_iocbq *cmdiocbp; |
| 3050 | struct lpfc_iocbq *next_iocb; |
| 3051 | IOCB_t *irsp = NULL; |
| 3052 | uint32_t free_saveq; |
| 3053 | uint8_t iocb_cmd_type; |
| 3054 | lpfc_iocb_type type; |
| 3055 | unsigned long iflag; |
| 3056 | int rc; |
| 3057 | |
| 3058 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3059 | /* First add the response iocb to the countinueq list */ |
| 3060 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3061 | pring->iocb_continueq_cnt++; |
| 3062 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3063 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3064 | irsp = &rspiocbp->iocb; |
| 3065 | if (irsp->ulpLe) { |
| 3066 | /* |
| 3067 | * By default, the driver expects to free all resources |
| 3068 | * associated with this iocb completion. |
| 3069 | */ |
| 3070 | free_saveq = 1; |
| 3071 | saveq = list_get_first(&pring->iocb_continueq, |
| 3072 | struct lpfc_iocbq, list); |
| 3073 | irsp = &(saveq->iocb); |
| 3074 | list_del_init(&pring->iocb_continueq); |
| 3075 | pring->iocb_continueq_cnt = 0; |
| 3076 | |
| 3077 | pring->stats.iocb_rsp++; |
| 3078 | |
| 3079 | /* |
| 3080 | * If resource errors reported from HBA, reduce |
| 3081 | * queuedepths of the SCSI device. |
| 3082 | */ |
| 3083 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 3084 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 3085 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3086 | phba->lpfc_rampdown_queue_depth(phba); |
| 3087 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3088 | } |
| 3089 | |
| 3090 | if (irsp->ulpStatus) { |
| 3091 | /* Rsp ring <ringno> error: IOCB */ |
| 3092 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3093 | "0328 Rsp Ring %d error: " |
| 3094 | "IOCB Data: " |
| 3095 | "x%x x%x x%x x%x " |
| 3096 | "x%x x%x x%x x%x " |
| 3097 | "x%x x%x x%x x%x " |
| 3098 | "x%x x%x x%x x%x\n", |
| 3099 | pring->ringno, |
| 3100 | irsp->un.ulpWord[0], |
| 3101 | irsp->un.ulpWord[1], |
| 3102 | irsp->un.ulpWord[2], |
| 3103 | irsp->un.ulpWord[3], |
| 3104 | irsp->un.ulpWord[4], |
| 3105 | irsp->un.ulpWord[5], |
| 3106 | *(((uint32_t *) irsp) + 6), |
| 3107 | *(((uint32_t *) irsp) + 7), |
| 3108 | *(((uint32_t *) irsp) + 8), |
| 3109 | *(((uint32_t *) irsp) + 9), |
| 3110 | *(((uint32_t *) irsp) + 10), |
| 3111 | *(((uint32_t *) irsp) + 11), |
| 3112 | *(((uint32_t *) irsp) + 12), |
| 3113 | *(((uint32_t *) irsp) + 13), |
| 3114 | *(((uint32_t *) irsp) + 14), |
| 3115 | *(((uint32_t *) irsp) + 15)); |
| 3116 | } |
| 3117 | |
| 3118 | /* |
| 3119 | * Fetch the IOCB command type and call the correct completion |
| 3120 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3121 | * get freed back to the lpfc_iocb_list by the discovery |
| 3122 | * kernel thread. |
| 3123 | */ |
| 3124 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3125 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3126 | switch (type) { |
| 3127 | case LPFC_SOL_IOCB: |
| 3128 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3129 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3130 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3131 | break; |
| 3132 | |
| 3133 | case LPFC_UNSOL_IOCB: |
| 3134 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3135 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3136 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3137 | if (!rc) |
| 3138 | free_saveq = 0; |
| 3139 | break; |
| 3140 | |
| 3141 | case LPFC_ABORT_IOCB: |
| 3142 | cmdiocbp = NULL; |
| 3143 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3144 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3145 | saveq); |
| 3146 | if (cmdiocbp) { |
| 3147 | /* Call the specified completion routine */ |
| 3148 | if (cmdiocbp->iocb_cmpl) { |
| 3149 | spin_unlock_irqrestore(&phba->hbalock, |
| 3150 | iflag); |
| 3151 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3152 | saveq); |
| 3153 | spin_lock_irqsave(&phba->hbalock, |
| 3154 | iflag); |
| 3155 | } else |
| 3156 | __lpfc_sli_release_iocbq(phba, |
| 3157 | cmdiocbp); |
| 3158 | } |
| 3159 | break; |
| 3160 | |
| 3161 | case LPFC_UNKNOWN_IOCB: |
| 3162 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3163 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3164 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3165 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3166 | MAX_MSG_DATA); |
| 3167 | dev_warn(&((phba->pcidev)->dev), |
| 3168 | "lpfc%d: %s\n", |
| 3169 | phba->brd_no, adaptermsg); |
| 3170 | } else { |
| 3171 | /* Unknown IOCB command */ |
| 3172 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3173 | "0335 Unknown IOCB " |
| 3174 | "command Data: x%x " |
| 3175 | "x%x x%x x%x\n", |
| 3176 | irsp->ulpCommand, |
| 3177 | irsp->ulpStatus, |
| 3178 | irsp->ulpIoTag, |
| 3179 | irsp->ulpContext); |
| 3180 | } |
| 3181 | break; |
| 3182 | } |
| 3183 | |
| 3184 | if (free_saveq) { |
| 3185 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3186 | &saveq->list, list) { |
| 3187 | list_del(&rspiocbp->list); |
| 3188 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3189 | } |
| 3190 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3191 | } |
| 3192 | rspiocbp = NULL; |
| 3193 | } |
| 3194 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3195 | return rspiocbp; |
| 3196 | } |
| 3197 | |
| 3198 | /** |
| 3199 | * 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] | 3200 | * @phba: Pointer to HBA context object. |
| 3201 | * @pring: Pointer to driver SLI ring object. |
| 3202 | * @mask: Host attention register mask for this ring. |
| 3203 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3204 | * This routine wraps the actual slow_ring event process routine from the |
| 3205 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3206 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3207 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3208 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3209 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3210 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3211 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3216 | * @phba: Pointer to HBA context object. |
| 3217 | * @pring: Pointer to driver SLI ring object. |
| 3218 | * @mask: Host attention register mask for this ring. |
| 3219 | * |
| 3220 | * This function is called from the worker thread when there is a ring event |
| 3221 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3222 | * remove each response iocb in the response ring and calls the handle |
| 3223 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3224 | **/ |
| 3225 | static void |
| 3226 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3227 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3228 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3229 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | IOCB_t *entry; |
| 3231 | IOCB_t *irsp = NULL; |
| 3232 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3233 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3235 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3237 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3238 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | pring->stats.iocb_event++; |
| 3240 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | /* |
| 3242 | * The next available response entry should never exceed the maximum |
| 3243 | * entries. If it does, treat it as an adapter hardware error. |
| 3244 | */ |
| 3245 | portRspMax = pring->numRiocb; |
| 3246 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3247 | if (portRspPut >= portRspMax) { |
| 3248 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3249 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | * rsp ring <portRspMax> |
| 3251 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3252 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3253 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3254 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3255 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3257 | phba->link_state = LPFC_HBA_ERROR; |
| 3258 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | |
| 3260 | phba->work_hs = HS_FFER3; |
| 3261 | lpfc_handle_eratt(phba); |
| 3262 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3263 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | while (pring->rspidx != portRspPut) { |
| 3268 | /* |
| 3269 | * Build a completion list and call the appropriate handler. |
| 3270 | * The process is to get the next available response iocb, get |
| 3271 | * a free iocb from the list, copy the response data into the |
| 3272 | * free iocb, insert to the continuation list, and update the |
| 3273 | * next response index to slim. This process makes response |
| 3274 | * iocb's in the ring available to DMA as fast as possible but |
| 3275 | * pays a penalty for a copy operation. Since the iocb is |
| 3276 | * only 32 bytes, this penalty is considered small relative to |
| 3277 | * the PCI reads for register values and a slim write. When |
| 3278 | * the ulpLe field is set, the entire Command has been |
| 3279 | * received. |
| 3280 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3281 | entry = lpfc_resp_iocb(phba, pring); |
| 3282 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3283 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3284 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | if (rspiocbp == NULL) { |
| 3286 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3287 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | break; |
| 3289 | } |
| 3290 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3291 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3292 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | irsp = &rspiocbp->iocb; |
| 3294 | |
| 3295 | if (++pring->rspidx >= portRspMax) |
| 3296 | pring->rspidx = 0; |
| 3297 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3298 | if (pring->ringno == LPFC_ELS_RING) { |
| 3299 | lpfc_debugfs_slow_ring_trc(phba, |
| 3300 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3301 | *(((uint32_t *) irsp) + 4), |
| 3302 | *(((uint32_t *) irsp) + 6), |
| 3303 | *(((uint32_t *) irsp) + 7)); |
| 3304 | } |
| 3305 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3306 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3308 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3309 | /* Handle the response IOCB */ |
| 3310 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3311 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | |
| 3313 | /* |
| 3314 | * If the port response put pointer has not been updated, sync |
| 3315 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3316 | * response put pointer. |
| 3317 | */ |
| 3318 | if (pring->rspidx == portRspPut) { |
| 3319 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3320 | } |
| 3321 | } /* while (pring->rspidx != portRspPut) */ |
| 3322 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3323 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | /* At least one response entry has been freed */ |
| 3325 | pring->stats.iocb_rsp_full++; |
| 3326 | /* SET RxRE_RSP in Chip Att register */ |
| 3327 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3328 | writel(status, phba->CAregaddr); |
| 3329 | readl(phba->CAregaddr); /* flush */ |
| 3330 | } |
| 3331 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3332 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3333 | pring->stats.iocb_cmd_empty++; |
| 3334 | |
| 3335 | /* Force update of the local copy of cmdGetInx */ |
| 3336 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 3337 | lpfc_sli_resume_iocb(phba, pring); |
| 3338 | |
| 3339 | if ((pring->lpfc_sli_cmd_available)) |
| 3340 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3341 | |
| 3342 | } |
| 3343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3345 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | } |
| 3347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3348 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3349 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3350 | * @phba: Pointer to HBA context object. |
| 3351 | * @pring: Pointer to driver SLI ring object. |
| 3352 | * @mask: Host attention register mask for this ring. |
| 3353 | * |
| 3354 | * This function is called from the worker thread when there is a pending |
| 3355 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3356 | * queue. The caller does not hold any lock. The function will remove each |
| 3357 | * response iocb from the response worker queue and calls the handle |
| 3358 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3359 | **/ |
| 3360 | static void |
| 3361 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3362 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3363 | { |
| 3364 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3365 | struct hbq_dmabuf *dmabuf; |
| 3366 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3367 | unsigned long iflag; |
| 3368 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3369 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3370 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3371 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3372 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3373 | /* Get the response iocb from the head of work queue */ |
| 3374 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3375 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3376 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3377 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3378 | |
| 3379 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3380 | case CQE_CODE_COMPL_WQE: |
| 3381 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3382 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3383 | /* Translate ELS WCQE to response IOCBQ */ |
| 3384 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3385 | irspiocbq); |
| 3386 | if (irspiocbq) |
| 3387 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3388 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3389 | break; |
| 3390 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3391 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3392 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3393 | cq_event); |
| 3394 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3395 | break; |
| 3396 | default: |
| 3397 | break; |
| 3398 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3403 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3404 | * @phba: Pointer to HBA context object. |
| 3405 | * @pring: Pointer to driver SLI ring object. |
| 3406 | * |
| 3407 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3408 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3409 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3410 | * the return of this function. The caller is not required to hold any locks. |
| 3411 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3412 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3414 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3415 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3418 | if (pring->ringno == LPFC_ELS_RING) { |
| 3419 | lpfc_fabric_abort_hba(phba); |
| 3420 | } |
| 3421 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | /* Error everything on txq and txcmplq |
| 3423 | * First do the txq. |
| 3424 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3426 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | |
| 3429 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3430 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3431 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3433 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3434 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3435 | /* Cancel all the IOCBs from the completions list */ |
| 3436 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3437 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | } |
| 3439 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3441 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3442 | * @phba: Pointer to HBA context object. |
| 3443 | * |
| 3444 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3445 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3446 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3447 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3448 | * slot has been permanently disabled. |
| 3449 | **/ |
| 3450 | void |
| 3451 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3452 | { |
| 3453 | LIST_HEAD(txq); |
| 3454 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3455 | struct lpfc_sli *psli = &phba->sli; |
| 3456 | struct lpfc_sli_ring *pring; |
| 3457 | |
| 3458 | /* Currently, only one fcp ring */ |
| 3459 | pring = &psli->ring[psli->fcp_ring]; |
| 3460 | |
| 3461 | spin_lock_irq(&phba->hbalock); |
| 3462 | /* Retrieve everything on txq */ |
| 3463 | list_splice_init(&pring->txq, &txq); |
| 3464 | pring->txq_cnt = 0; |
| 3465 | |
| 3466 | /* Retrieve everything on the txcmplq */ |
| 3467 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3468 | pring->txcmplq_cnt = 0; |
| 3469 | spin_unlock_irq(&phba->hbalock); |
| 3470 | |
| 3471 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3472 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3473 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3474 | |
| 3475 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3476 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3477 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3481 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3482 | * @phba: Pointer to HBA context object. |
| 3483 | * @mask: Bit mask to be checked. |
| 3484 | * |
| 3485 | * This function reads the host status register and compares |
| 3486 | * with the provided bit mask to check if HBA completed |
| 3487 | * the restart. This function will wait in a loop for the |
| 3488 | * HBA to complete restart. If the HBA does not restart within |
| 3489 | * 15 iterations, the function will reset the HBA again. The |
| 3490 | * function returns 1 when HBA fail to restart otherwise returns |
| 3491 | * zero. |
| 3492 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3493 | static int |
| 3494 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3496 | uint32_t status; |
| 3497 | int i = 0; |
| 3498 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3500 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3501 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3502 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3504 | /* |
| 3505 | * Check status register every 100ms for 5 retries, then every |
| 3506 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3507 | * every 2.5 sec for 4. |
| 3508 | * Break our of the loop if errors occurred during init. |
| 3509 | */ |
| 3510 | while (((status & mask) != mask) && |
| 3511 | !(status & HS_FFERM) && |
| 3512 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3514 | if (i <= 5) |
| 3515 | msleep(10); |
| 3516 | else if (i <= 10) |
| 3517 | msleep(500); |
| 3518 | else |
| 3519 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3521 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3523 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3524 | lpfc_sli_brdrestart(phba); |
| 3525 | } |
| 3526 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3527 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3528 | retval = 1; |
| 3529 | break; |
| 3530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3533 | /* Check to see if any errors occurred during init */ |
| 3534 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3536 | "2751 Adapter failed to restart, " |
| 3537 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3538 | status, |
| 3539 | readl(phba->MBslimaddr + 0xa8), |
| 3540 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3541 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3542 | retval = 1; |
| 3543 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3545 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | } |
| 3547 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3548 | /** |
| 3549 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3550 | * @phba: Pointer to HBA context object. |
| 3551 | * @mask: Bit mask to be checked. |
| 3552 | * |
| 3553 | * This function checks the host status register to check if HBA is |
| 3554 | * ready. This function will wait in a loop for the HBA to be ready |
| 3555 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3556 | * function again. The function returns 1 when HBA fail to be ready |
| 3557 | * otherwise returns zero. |
| 3558 | **/ |
| 3559 | static int |
| 3560 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3561 | { |
| 3562 | uint32_t status; |
| 3563 | int retval = 0; |
| 3564 | |
| 3565 | /* Read the HBA Host Status Register */ |
| 3566 | status = lpfc_sli4_post_status_check(phba); |
| 3567 | |
| 3568 | if (status) { |
| 3569 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3570 | lpfc_sli_brdrestart(phba); |
| 3571 | status = lpfc_sli4_post_status_check(phba); |
| 3572 | } |
| 3573 | |
| 3574 | /* Check to see if any errors occurred during init */ |
| 3575 | if (status) { |
| 3576 | phba->link_state = LPFC_HBA_ERROR; |
| 3577 | retval = 1; |
| 3578 | } else |
| 3579 | phba->sli4_hba.intr_enable = 0; |
| 3580 | |
| 3581 | return retval; |
| 3582 | } |
| 3583 | |
| 3584 | /** |
| 3585 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3586 | * @phba: Pointer to HBA context object. |
| 3587 | * @mask: Bit mask to be checked. |
| 3588 | * |
| 3589 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3590 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3591 | **/ |
| 3592 | int |
| 3593 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3594 | { |
| 3595 | return phba->lpfc_sli_brdready(phba, mask); |
| 3596 | } |
| 3597 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3598 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3601 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3602 | * @phba: Pointer to HBA context object. |
| 3603 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3604 | * This function is called before resetting an HBA. This function is called |
| 3605 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3606 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3607 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3608 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3609 | uint32_t __iomem *resp_buf; |
| 3610 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3611 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3612 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3613 | int i; |
| 3614 | uint8_t hdrtype; |
| 3615 | |
| 3616 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3617 | if (hdrtype != 0x80 || |
| 3618 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3619 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3620 | return; |
| 3621 | |
| 3622 | /* |
| 3623 | * Tell the other part of the chip to suspend temporarily all |
| 3624 | * its DMA activity. |
| 3625 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3626 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3627 | |
| 3628 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3629 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3630 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3631 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3632 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3633 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3634 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3635 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3636 | return; |
| 3637 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3638 | /* Clear Chip error bit */ |
| 3639 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3640 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | mbox = 0; |
| 3644 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3645 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3646 | |
| 3647 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3648 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3649 | writel(mbox, mbox_buf); |
| 3650 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3651 | for (i = 0; i < 50; i++) { |
| 3652 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3653 | return; |
| 3654 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3655 | mdelay(1); |
| 3656 | else |
| 3657 | break; |
| 3658 | } |
| 3659 | resp_data = 0; |
| 3660 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3661 | return; |
| 3662 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3663 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3664 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3665 | goto restore_hc; |
| 3666 | else |
| 3667 | goto clear_errat; |
| 3668 | } |
| 3669 | |
| 3670 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3671 | resp_data = 0; |
| 3672 | for (i = 0; i < 500; i++) { |
| 3673 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3674 | return; |
| 3675 | if (resp_data != mbox) |
| 3676 | mdelay(1); |
| 3677 | else |
| 3678 | break; |
| 3679 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3680 | |
| 3681 | clear_errat: |
| 3682 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3683 | while (++i < 500) { |
| 3684 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3685 | return; |
| 3686 | if (!(ha_copy & HA_ERATT)) |
| 3687 | mdelay(1); |
| 3688 | else |
| 3689 | break; |
| 3690 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3691 | |
| 3692 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3693 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3694 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3698 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3699 | writel(hc_copy, phba->HCregaddr); |
| 3700 | readl(phba->HCregaddr); /* flush */ |
| 3701 | } |
| 3702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3704 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3705 | * @phba: Pointer to HBA context object. |
| 3706 | * |
| 3707 | * This function issues a kill_board mailbox command and waits for |
| 3708 | * the error attention interrupt. This function is called for stopping |
| 3709 | * the firmware processing. The caller is not required to hold any |
| 3710 | * locks. This function calls lpfc_hba_down_post function to free |
| 3711 | * any pending commands after the kill. The function will return 1 when it |
| 3712 | * fails to kill the board else will return 0. |
| 3713 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3714 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3715 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3717 | struct lpfc_sli *psli; |
| 3718 | LPFC_MBOXQ_t *pmb; |
| 3719 | uint32_t status; |
| 3720 | uint32_t ha_copy; |
| 3721 | int retval; |
| 3722 | int i = 0; |
| 3723 | |
| 3724 | psli = &phba->sli; |
| 3725 | |
| 3726 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3727 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3728 | "0329 Kill HBA Data: x%x x%x\n", |
| 3729 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3730 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3731 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3732 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3733 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3734 | |
| 3735 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3736 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3737 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3738 | spin_unlock_irq(&phba->hbalock); |
| 3739 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3740 | return 1; |
| 3741 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3742 | status &= ~HC_ERINT_ENA; |
| 3743 | writel(status, phba->HCregaddr); |
| 3744 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3745 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3746 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3747 | |
| 3748 | lpfc_kill_board(phba, pmb); |
| 3749 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3750 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3751 | |
| 3752 | if (retval != MBX_SUCCESS) { |
| 3753 | if (retval != MBX_BUSY) |
| 3754 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3755 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3756 | "2752 KILL_BOARD command failed retval %d\n", |
| 3757 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3758 | spin_lock_irq(&phba->hbalock); |
| 3759 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3760 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3761 | return 1; |
| 3762 | } |
| 3763 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3764 | spin_lock_irq(&phba->hbalock); |
| 3765 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3766 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3767 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3768 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3769 | |
| 3770 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3771 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3772 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3773 | * board is now undefined. |
| 3774 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3775 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3776 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3777 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3778 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3779 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3780 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3784 | if (ha_copy & HA_ERATT) { |
| 3785 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3787 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3789 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3790 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3791 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3792 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3793 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3794 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3795 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3796 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3797 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3798 | } |
| 3799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3800 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3801 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3802 | * @phba: Pointer to HBA context object. |
| 3803 | * |
| 3804 | * This function resets the HBA by writing HC_INITFF to the control |
| 3805 | * register. After the HBA resets, this function resets all the iocb ring |
| 3806 | * indices. This function disables PCI layer parity checking during |
| 3807 | * the reset. |
| 3808 | * This function returns 0 always. |
| 3809 | * The caller is not required to hold any locks. |
| 3810 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3811 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3812 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3813 | { |
| 3814 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3816 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3818 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3819 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3821 | /* Reset HBA */ |
| 3822 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3823 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3824 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | |
| 3826 | /* perform board reset */ |
| 3827 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3828 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3829 | phba->pport->fc_myDID = 0; |
| 3830 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3832 | /* Turn off parity checking and serr during the physical reset */ |
| 3833 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3834 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3835 | (cfg_value & |
| 3836 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3837 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3838 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3839 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3840 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3841 | writel(HC_INITFF, phba->HCregaddr); |
| 3842 | mdelay(1); |
| 3843 | readl(phba->HCregaddr); /* flush */ |
| 3844 | writel(0, phba->HCregaddr); |
| 3845 | readl(phba->HCregaddr); /* flush */ |
| 3846 | |
| 3847 | /* Restore PCI cmd register */ |
| 3848 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | |
| 3850 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3851 | for (i = 0; i < psli->num_rings; i++) { |
| 3852 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | pring->flag = 0; |
| 3854 | pring->rspidx = 0; |
| 3855 | pring->next_cmdidx = 0; |
| 3856 | pring->local_getidx = 0; |
| 3857 | pring->cmdidx = 0; |
| 3858 | pring->missbufcnt = 0; |
| 3859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3861 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3862 | return 0; |
| 3863 | } |
| 3864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3865 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3866 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3867 | * @phba: Pointer to HBA context object. |
| 3868 | * |
| 3869 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3870 | * checking during resets the device. The caller is not required to hold |
| 3871 | * any locks. |
| 3872 | * |
| 3873 | * This function returns 0 always. |
| 3874 | **/ |
| 3875 | int |
| 3876 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3877 | { |
| 3878 | struct lpfc_sli *psli = &phba->sli; |
| 3879 | uint16_t cfg_value; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3880 | |
| 3881 | /* Reset HBA */ |
| 3882 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3883 | "0295 Reset HBA Data: x%x x%x\n", |
| 3884 | phba->pport->port_state, psli->sli_flag); |
| 3885 | |
| 3886 | /* perform board reset */ |
| 3887 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3888 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3889 | phba->pport->fc_myDID = 0; |
| 3890 | phba->pport->fc_prevDID = 0; |
| 3891 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3892 | spin_lock_irq(&phba->hbalock); |
| 3893 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3894 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3895 | spin_unlock_irq(&phba->hbalock); |
| 3896 | |
| 3897 | /* Now physically reset the device */ |
| 3898 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3899 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3900 | |
| 3901 | /* Turn off parity checking and serr during the physical reset */ |
| 3902 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3903 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3904 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3905 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3906 | /* Perform FCoE PCI function reset */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 3907 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3908 | lpfc_pci_function_reset(phba); |
| 3909 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3910 | /* Restore PCI cmd register */ |
| 3911 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3912 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3913 | return 0; |
| 3914 | } |
| 3915 | |
| 3916 | /** |
| 3917 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3918 | * @phba: Pointer to HBA context object. |
| 3919 | * |
| 3920 | * This function is called in the SLI initialization code path to |
| 3921 | * restart the HBA. The caller is not required to hold any lock. |
| 3922 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3923 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3924 | * function to free any pending commands. The function enables |
| 3925 | * POST only during the first initialization. The function returns zero. |
| 3926 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3927 | * command before the return of this function. |
| 3928 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3929 | static int |
| 3930 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3931 | { |
| 3932 | MAILBOX_t *mb; |
| 3933 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3934 | volatile uint32_t word0; |
| 3935 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3936 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3937 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3939 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3940 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 3941 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 3942 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3943 | psli = &phba->sli; |
| 3944 | |
| 3945 | /* Restart HBA */ |
| 3946 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3947 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3948 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3949 | |
| 3950 | word0 = 0; |
| 3951 | mb = (MAILBOX_t *) &word0; |
| 3952 | mb->mbxCommand = MBX_RESTART; |
| 3953 | mb->mbxHc = 1; |
| 3954 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3955 | lpfc_reset_barrier(phba); |
| 3956 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3957 | to_slim = phba->MBslimaddr; |
| 3958 | writel(*(uint32_t *) mb, to_slim); |
| 3959 | readl(to_slim); /* flush */ |
| 3960 | |
| 3961 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3962 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3963 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3964 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3965 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3966 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3967 | writel(*(uint32_t *) mb, to_slim); |
| 3968 | readl(to_slim); /* flush */ |
| 3969 | |
| 3970 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | phba->pport->stopped = 0; |
| 3972 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3973 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3974 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3975 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 3976 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3977 | psli->stats_start = get_seconds(); |
| 3978 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3979 | /* Give the INITFF and Post time to settle. */ |
| 3980 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3982 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 3983 | if (hba_aer_enabled) |
| 3984 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 3985 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3986 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3987 | |
| 3988 | return 0; |
| 3989 | } |
| 3990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3991 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3992 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 3993 | * @phba: Pointer to HBA context object. |
| 3994 | * |
| 3995 | * This function is called in the SLI initialization code path to restart |
| 3996 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 3997 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 3998 | * free any pending commands. |
| 3999 | **/ |
| 4000 | static int |
| 4001 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4002 | { |
| 4003 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4004 | uint32_t hba_aer_enabled; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4005 | |
| 4006 | /* Restart HBA */ |
| 4007 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4008 | "0296 Restart HBA Data: x%x x%x\n", |
| 4009 | phba->pport->port_state, psli->sli_flag); |
| 4010 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4011 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4012 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4013 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4014 | lpfc_sli4_brdreset(phba); |
| 4015 | |
| 4016 | spin_lock_irq(&phba->hbalock); |
| 4017 | phba->pport->stopped = 0; |
| 4018 | phba->link_state = LPFC_INIT_START; |
| 4019 | phba->hba_flag = 0; |
| 4020 | spin_unlock_irq(&phba->hbalock); |
| 4021 | |
| 4022 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4023 | psli->stats_start = get_seconds(); |
| 4024 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4025 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4026 | if (hba_aer_enabled) |
| 4027 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4028 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4029 | lpfc_hba_down_post(phba); |
| 4030 | |
| 4031 | return 0; |
| 4032 | } |
| 4033 | |
| 4034 | /** |
| 4035 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4036 | * @phba: Pointer to HBA context object. |
| 4037 | * |
| 4038 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4039 | * API jump table function pointer from the lpfc_hba struct. |
| 4040 | **/ |
| 4041 | int |
| 4042 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4043 | { |
| 4044 | return phba->lpfc_sli_brdrestart(phba); |
| 4045 | } |
| 4046 | |
| 4047 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4048 | * 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] | 4049 | * @phba: Pointer to HBA context object. |
| 4050 | * |
| 4051 | * This function is called after a HBA restart to wait for successful |
| 4052 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4053 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4054 | * iteration, the function will restart the HBA again. The function returns |
| 4055 | * zero if HBA successfully restarted else returns negative error code. |
| 4056 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4057 | static int |
| 4058 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4059 | { |
| 4060 | uint32_t status, i = 0; |
| 4061 | |
| 4062 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4063 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4064 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4065 | |
| 4066 | /* Check status register to see what current state is */ |
| 4067 | i = 0; |
| 4068 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4069 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4070 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4071 | * retries, then every 1 sec for 50 retires for a total of |
| 4072 | * ~60 seconds before reset the board again and check every |
| 4073 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4074 | * board ready is required by the Falcon FIPS zeroization |
| 4075 | * complete, and any reset the board in between shall cause |
| 4076 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4078 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | /* Adapter failed to init, timeout, status reg |
| 4080 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4081 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4082 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4083 | "timeout, status reg x%x, " |
| 4084 | "FW Data: A8 x%x AC x%x\n", status, |
| 4085 | readl(phba->MBslimaddr + 0xa8), |
| 4086 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | return -ETIMEDOUT; |
| 4089 | } |
| 4090 | |
| 4091 | /* Check to see if any errors occurred during init */ |
| 4092 | if (status & HS_FFERM) { |
| 4093 | /* ERROR: During chipset initialization */ |
| 4094 | /* Adapter failed to init, chipset, status reg |
| 4095 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4096 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4097 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4098 | "chipset, status reg x%x, " |
| 4099 | "FW Data: A8 x%x AC x%x\n", status, |
| 4100 | readl(phba->MBslimaddr + 0xa8), |
| 4101 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | return -EIO; |
| 4104 | } |
| 4105 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4106 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4108 | else if (i <= 100) |
| 4109 | msleep(100); |
| 4110 | else |
| 4111 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4113 | if (i == 150) { |
| 4114 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4115 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4116 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | } |
| 4118 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4119 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4120 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | /* Check to see if any errors occurred during init */ |
| 4124 | if (status & HS_FFERM) { |
| 4125 | /* ERROR: During chipset initialization */ |
| 4126 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4128 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4129 | "status reg x%x, " |
| 4130 | "FW Data: A8 x%x AC x%x\n", status, |
| 4131 | readl(phba->MBslimaddr + 0xa8), |
| 4132 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4133 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | return -EIO; |
| 4135 | } |
| 4136 | |
| 4137 | /* Clear all interrupt enable conditions */ |
| 4138 | writel(0, phba->HCregaddr); |
| 4139 | readl(phba->HCregaddr); /* flush */ |
| 4140 | |
| 4141 | /* setup host attn register */ |
| 4142 | writel(0xffffffff, phba->HAregaddr); |
| 4143 | readl(phba->HAregaddr); /* flush */ |
| 4144 | return 0; |
| 4145 | } |
| 4146 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4148 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4149 | * |
| 4150 | * This function calculates and returns the number of HBQs required to be |
| 4151 | * configured. |
| 4152 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4153 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4154 | lpfc_sli_hbq_count(void) |
| 4155 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4156 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4157 | } |
| 4158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4160 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4161 | * |
| 4162 | * This function adds the number of hbq entries in every HBQ to get |
| 4163 | * the total number of hbq entries required for the HBA and returns |
| 4164 | * the total count. |
| 4165 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4166 | static int |
| 4167 | lpfc_sli_hbq_entry_count(void) |
| 4168 | { |
| 4169 | int hbq_count = lpfc_sli_hbq_count(); |
| 4170 | int count = 0; |
| 4171 | int i; |
| 4172 | |
| 4173 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4174 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4175 | return count; |
| 4176 | } |
| 4177 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4178 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4179 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4180 | * |
| 4181 | * This function calculates amount of memory required for all hbq entries |
| 4182 | * to be configured and returns the total memory required. |
| 4183 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4184 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4185 | lpfc_sli_hbq_size(void) |
| 4186 | { |
| 4187 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4188 | } |
| 4189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4191 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4192 | * @phba: Pointer to HBA context object. |
| 4193 | * |
| 4194 | * This function is called during the SLI initialization to configure |
| 4195 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4196 | * required to hold any locks. This function will return zero if successful |
| 4197 | * else it will return negative error code. |
| 4198 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4199 | static int |
| 4200 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4201 | { |
| 4202 | int hbq_count = lpfc_sli_hbq_count(); |
| 4203 | LPFC_MBOXQ_t *pmb; |
| 4204 | MAILBOX_t *pmbox; |
| 4205 | uint32_t hbqno; |
| 4206 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4207 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4208 | /* Get a Mailbox buffer to setup mailbox |
| 4209 | * commands for HBA initialization |
| 4210 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4211 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4212 | |
| 4213 | if (!pmb) |
| 4214 | return -ENOMEM; |
| 4215 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4216 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4217 | |
| 4218 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4219 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4220 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4221 | |
| 4222 | hbq_entry_index = 0; |
| 4223 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4224 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4225 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4226 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4227 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4228 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4229 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4230 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4231 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4232 | |
| 4233 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4234 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4235 | mbxStatus <status>, ring <num> */ |
| 4236 | |
| 4237 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4238 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4239 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4240 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4241 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4242 | pmbox->mbxStatus, hbqno); |
| 4243 | |
| 4244 | phba->link_state = LPFC_HBA_ERROR; |
| 4245 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4246 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4247 | } |
| 4248 | } |
| 4249 | phba->hbq_count = hbq_count; |
| 4250 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4251 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4252 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4253 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4254 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4255 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4256 | return 0; |
| 4257 | } |
| 4258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4259 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4260 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4261 | * @phba: Pointer to HBA context object. |
| 4262 | * |
| 4263 | * This function is called during the SLI initialization to configure |
| 4264 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4265 | * required to hold any locks. This function will return zero if successful |
| 4266 | * else it will return negative error code. |
| 4267 | **/ |
| 4268 | static int |
| 4269 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4270 | { |
| 4271 | phba->hbq_in_use = 1; |
| 4272 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4273 | phba->hbq_count = 1; |
| 4274 | /* Initially populate or replenish the HBQs */ |
| 4275 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4276 | return 0; |
| 4277 | } |
| 4278 | |
| 4279 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4280 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4281 | * @phba: Pointer to HBA context object. |
| 4282 | * @sli_mode: sli mode - 2/3 |
| 4283 | * |
| 4284 | * This function is called by the sli intialization code path |
| 4285 | * to issue config_port mailbox command. This function restarts the |
| 4286 | * HBA firmware and issues a config_port mailbox command to configure |
| 4287 | * the SLI interface in the sli mode specified by sli_mode |
| 4288 | * variable. The caller is not required to hold any locks. |
| 4289 | * The function returns 0 if successful, else returns negative error |
| 4290 | * code. |
| 4291 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4292 | int |
| 4293 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | { |
| 4295 | LPFC_MBOXQ_t *pmb; |
| 4296 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4297 | |
| 4298 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4299 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | return -ENOMEM; |
| 4302 | } |
| 4303 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4304 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4307 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4309 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4310 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | rc = lpfc_sli_chipset_init(phba); |
| 4312 | if (rc) |
| 4313 | break; |
| 4314 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4315 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4316 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | resetcount++; |
| 4319 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4320 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4321 | * value of 0 means the call was successful. Any other |
| 4322 | * nonzero value is a failure, but if ERESTART is returned, |
| 4323 | * the driver may reset the HBA and try again. |
| 4324 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | rc = lpfc_config_port_prep(phba); |
| 4326 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4327 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4329 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | lpfc_config_port(phba, pmb); |
| 4334 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4335 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4336 | LPFC_SLI3_HBQ_ENABLED | |
| 4337 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4338 | LPFC_SLI3_BG_ENABLED | |
| 4339 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4340 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4342 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4343 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4344 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4345 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4346 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | spin_unlock_irq(&phba->hbalock); |
| 4348 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4349 | } else { |
| 4350 | /* Allow asynchronous mailbox command to go through */ |
| 4351 | spin_lock_irq(&phba->hbalock); |
| 4352 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4353 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4354 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4355 | |
| 4356 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4357 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4358 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4359 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4360 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4362 | if (!done) { |
| 4363 | rc = -EINVAL; |
| 4364 | goto do_prep_failed; |
| 4365 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4366 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4367 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4368 | rc = -ENXIO; |
| 4369 | goto do_prep_failed; |
| 4370 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4371 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4372 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4373 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4374 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4375 | phba->max_vpi : phba->max_vports; |
| 4376 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4377 | } else |
| 4378 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4379 | phba->fips_level = 0; |
| 4380 | phba->fips_spec_rev = 0; |
| 4381 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4382 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4383 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4384 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4385 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4386 | "2850 Security Crypto Active. FIPS x%d " |
| 4387 | "(Spec Rev: x%d)", |
| 4388 | phba->fips_level, phba->fips_spec_rev); |
| 4389 | } |
| 4390 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4392 | "2856 Config Port Security Crypto " |
| 4393 | "Error: x%x ", |
| 4394 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4395 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4396 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4397 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4398 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4399 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4400 | |
| 4401 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4402 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4403 | |
| 4404 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4405 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4406 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4407 | else |
| 4408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4409 | "0443 Adapter did not grant " |
| 4410 | "BlockGuard\n"); |
| 4411 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4412 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4413 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4414 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4415 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4416 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4417 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4418 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4419 | return rc; |
| 4420 | } |
| 4421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4422 | |
| 4423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4424 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4425 | * @phba: Pointer to HBA context object. |
| 4426 | * |
| 4427 | * This function is the main SLI intialization function. This function |
| 4428 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4429 | * error attention handler code. Caller is not required to hold any |
| 4430 | * locks. This function issues config_port mailbox command to configure |
| 4431 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4432 | * calls the config_port_post function to issue init_link mailbox |
| 4433 | * command and to start the discovery. The function will return zero |
| 4434 | * if successful, else it will return negative error code. |
| 4435 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4436 | int |
| 4437 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4438 | { |
| 4439 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4440 | int mode = 3, i; |
| 4441 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4442 | |
| 4443 | switch (lpfc_sli_mode) { |
| 4444 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4445 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4447 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4448 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4449 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4450 | break; |
| 4451 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4452 | mode = 2; |
| 4453 | break; |
| 4454 | case 0: |
| 4455 | case 3: |
| 4456 | break; |
| 4457 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4459 | "1819 Unrecognized lpfc_sli_mode " |
| 4460 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4461 | |
| 4462 | break; |
| 4463 | } |
| 4464 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4465 | rc = lpfc_sli_config_port(phba, mode); |
| 4466 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4467 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4469 | "1820 Unable to select SLI-3. " |
| 4470 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4471 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4472 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4473 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | goto lpfc_sli_hba_setup_error; |
| 4475 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4476 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4477 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4478 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4479 | if (!rc) { |
| 4480 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4481 | "2709 This device supports " |
| 4482 | "Advanced Error Reporting (AER)\n"); |
| 4483 | spin_lock_irq(&phba->hbalock); |
| 4484 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4485 | spin_unlock_irq(&phba->hbalock); |
| 4486 | } else { |
| 4487 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4488 | "2708 This device does not support " |
| 4489 | "Advanced Error Reporting (AER)\n"); |
| 4490 | phba->cfg_aer_support = 0; |
| 4491 | } |
| 4492 | } |
| 4493 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4494 | if (phba->sli_rev == 3) { |
| 4495 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4496 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4497 | } else { |
| 4498 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4499 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4500 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4504 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4505 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4506 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4507 | |
| 4508 | if (rc) |
| 4509 | goto lpfc_sli_hba_setup_error; |
| 4510 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4511 | /* Initialize VPIs. */ |
| 4512 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4513 | /* |
| 4514 | * The VPI bitmask and physical ID array are allocated |
| 4515 | * and initialized once only - at driver load. A port |
| 4516 | * reset doesn't need to reinitialize this memory. |
| 4517 | */ |
| 4518 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4519 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4520 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4521 | GFP_KERNEL); |
| 4522 | if (!phba->vpi_bmask) { |
| 4523 | rc = -ENOMEM; |
| 4524 | goto lpfc_sli_hba_setup_error; |
| 4525 | } |
| 4526 | |
| 4527 | phba->vpi_ids = kzalloc( |
| 4528 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4529 | GFP_KERNEL); |
| 4530 | if (!phba->vpi_ids) { |
| 4531 | kfree(phba->vpi_bmask); |
| 4532 | rc = -ENOMEM; |
| 4533 | goto lpfc_sli_hba_setup_error; |
| 4534 | } |
| 4535 | for (i = 0; i < phba->max_vpi; i++) |
| 4536 | phba->vpi_ids[i] = i; |
| 4537 | } |
| 4538 | } |
| 4539 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4540 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4541 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4542 | rc = lpfc_sli_hbq_setup(phba); |
| 4543 | if (rc) |
| 4544 | goto lpfc_sli_hba_setup_error; |
| 4545 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4546 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4547 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4548 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4549 | |
| 4550 | rc = lpfc_config_port_post(phba); |
| 4551 | if (rc) |
| 4552 | goto lpfc_sli_hba_setup_error; |
| 4553 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4554 | return rc; |
| 4555 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4556 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4557 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4558 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4559 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | return rc; |
| 4561 | } |
| 4562 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4563 | /** |
| 4564 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4565 | * @phba: Pointer to HBA context object. |
| 4566 | * @mboxq: mailbox pointer. |
| 4567 | * This function issue a dump mailbox command to read config region |
| 4568 | * 23 and parse the records in the region and populate driver |
| 4569 | * data structure. |
| 4570 | **/ |
| 4571 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4572 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4573 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4574 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4575 | struct lpfc_dmabuf *mp; |
| 4576 | struct lpfc_mqe *mqe; |
| 4577 | uint32_t data_length; |
| 4578 | int rc; |
| 4579 | |
| 4580 | /* Program the default value of vlan_id and fc_map */ |
| 4581 | phba->valid_vlan = 0; |
| 4582 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4583 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4584 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4585 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4586 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4587 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4588 | return -ENOMEM; |
| 4589 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4590 | mqe = &mboxq->u.mqe; |
| 4591 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4592 | rc = -ENOMEM; |
| 4593 | goto out_free_mboxq; |
| 4594 | } |
| 4595 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4596 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4597 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4598 | |
| 4599 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4600 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4601 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4602 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4603 | "CQ: x%x x%x x%x x%x\n", |
| 4604 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4605 | bf_get(lpfc_mqe_command, mqe), |
| 4606 | bf_get(lpfc_mqe_status, mqe), |
| 4607 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4608 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4609 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4610 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4611 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4612 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4613 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4614 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4615 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4616 | mboxq->mcqe.word0, |
| 4617 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4618 | mboxq->mcqe.trailer); |
| 4619 | |
| 4620 | if (rc) { |
| 4621 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4622 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4623 | rc = -EIO; |
| 4624 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4625 | } |
| 4626 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4627 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4628 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4629 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4630 | rc = -EIO; |
| 4631 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4632 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4633 | |
| 4634 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4635 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4636 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4637 | rc = 0; |
| 4638 | |
| 4639 | out_free_mboxq: |
| 4640 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4641 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | /** |
| 4645 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4646 | * @phba: pointer to lpfc hba data structure. |
| 4647 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4648 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4649 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4650 | * On output, the number of data bytes in @vpd. |
| 4651 | * |
| 4652 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4653 | * addition, this routine gets the port vpd data. |
| 4654 | * |
| 4655 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4656 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4657 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4658 | **/ |
| 4659 | static int |
| 4660 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4661 | uint8_t *vpd, uint32_t *vpd_size) |
| 4662 | { |
| 4663 | int rc = 0; |
| 4664 | uint32_t dma_size; |
| 4665 | struct lpfc_dmabuf *dmabuf; |
| 4666 | struct lpfc_mqe *mqe; |
| 4667 | |
| 4668 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4669 | if (!dmabuf) |
| 4670 | return -ENOMEM; |
| 4671 | |
| 4672 | /* |
| 4673 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4674 | * mailbox command. |
| 4675 | */ |
| 4676 | dma_size = *vpd_size; |
| 4677 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4678 | dma_size, |
| 4679 | &dmabuf->phys, |
| 4680 | GFP_KERNEL); |
| 4681 | if (!dmabuf->virt) { |
| 4682 | kfree(dmabuf); |
| 4683 | return -ENOMEM; |
| 4684 | } |
| 4685 | memset(dmabuf->virt, 0, dma_size); |
| 4686 | |
| 4687 | /* |
| 4688 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4689 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4690 | * in SLI3. This code corrects the conflicts. |
| 4691 | */ |
| 4692 | lpfc_read_rev(phba, mboxq); |
| 4693 | mqe = &mboxq->u.mqe; |
| 4694 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4695 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4696 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4697 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4698 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4699 | |
| 4700 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4701 | if (rc) { |
| 4702 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4703 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4704 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | return -EIO; |
| 4706 | } |
| 4707 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4708 | /* |
| 4709 | * The available vpd length cannot be bigger than the |
| 4710 | * DMA buffer passed to the port. Catch the less than |
| 4711 | * case and update the caller's size. |
| 4712 | */ |
| 4713 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4714 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4715 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4716 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4717 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4718 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4719 | dmabuf->virt, dmabuf->phys); |
| 4720 | kfree(dmabuf); |
| 4721 | return 0; |
| 4722 | } |
| 4723 | |
| 4724 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4725 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4726 | * @phba: pointer to lpfc hba data structure. |
| 4727 | * |
| 4728 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4729 | * is attached to. |
| 4730 | * |
| 4731 | * Return codes |
| 4732 | * 0 - sucessful |
| 4733 | * otherwise - failed to retrieve physical port name |
| 4734 | **/ |
| 4735 | static int |
| 4736 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4737 | { |
| 4738 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4739 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4740 | struct lpfc_controller_attribute *cntl_attr; |
| 4741 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4742 | void *virtaddr = NULL; |
| 4743 | uint32_t alloclen, reqlen; |
| 4744 | uint32_t shdr_status, shdr_add_status; |
| 4745 | union lpfc_sli4_cfg_shdr *shdr; |
| 4746 | char cport_name = 0; |
| 4747 | int rc; |
| 4748 | |
| 4749 | /* We assume nothing at this point */ |
| 4750 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4751 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4752 | |
| 4753 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4754 | if (!mboxq) |
| 4755 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4756 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4757 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4758 | lpfc_sli4_read_config(phba); |
| 4759 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4760 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4761 | |
| 4762 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4763 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4764 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4765 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4766 | LPFC_SLI4_MBX_NEMBED); |
| 4767 | if (alloclen < reqlen) { |
| 4768 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4769 | "3084 Allocated DMA memory size (%d) is " |
| 4770 | "less than the requested DMA memory size " |
| 4771 | "(%d)\n", alloclen, reqlen); |
| 4772 | rc = -ENOMEM; |
| 4773 | goto out_free_mboxq; |
| 4774 | } |
| 4775 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4776 | virtaddr = mboxq->sge_array->addr[0]; |
| 4777 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4778 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4779 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4780 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4781 | if (shdr_status || shdr_add_status || rc) { |
| 4782 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4783 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4784 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4785 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4786 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4787 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4788 | rc, shdr_status, shdr_add_status); |
| 4789 | rc = -ENXIO; |
| 4790 | goto out_free_mboxq; |
| 4791 | } |
| 4792 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4793 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4794 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4795 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4796 | phba->sli4_hba.lnk_info.lnk_no = |
| 4797 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4798 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4799 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4800 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4801 | phba->sli4_hba.lnk_info.lnk_no); |
| 4802 | |
| 4803 | retrieve_ppname: |
| 4804 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4805 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4806 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4807 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4808 | LPFC_SLI4_MBX_EMBED); |
| 4809 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4810 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4811 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4812 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4813 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4814 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4815 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4816 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4817 | if (shdr_status || shdr_add_status || rc) { |
| 4818 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4819 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4820 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4821 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4822 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4823 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4824 | rc, shdr_status, shdr_add_status); |
| 4825 | rc = -ENXIO; |
| 4826 | goto out_free_mboxq; |
| 4827 | } |
| 4828 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4829 | case LPFC_LINK_NUMBER_0: |
| 4830 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4831 | &get_port_name->u.response); |
| 4832 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4833 | break; |
| 4834 | case LPFC_LINK_NUMBER_1: |
| 4835 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4836 | &get_port_name->u.response); |
| 4837 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4838 | break; |
| 4839 | case LPFC_LINK_NUMBER_2: |
| 4840 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4841 | &get_port_name->u.response); |
| 4842 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4843 | break; |
| 4844 | case LPFC_LINK_NUMBER_3: |
| 4845 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4846 | &get_port_name->u.response); |
| 4847 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4848 | break; |
| 4849 | default: |
| 4850 | break; |
| 4851 | } |
| 4852 | |
| 4853 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4854 | phba->Port[0] = cport_name; |
| 4855 | phba->Port[1] = '\0'; |
| 4856 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4857 | "3091 SLI get port name: %s\n", phba->Port); |
| 4858 | } |
| 4859 | |
| 4860 | out_free_mboxq: |
| 4861 | if (rc != MBX_TIMEOUT) { |
| 4862 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4863 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4864 | else |
| 4865 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4866 | } |
| 4867 | return rc; |
| 4868 | } |
| 4869 | |
| 4870 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4871 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4872 | * @phba: pointer to lpfc hba data structure. |
| 4873 | * |
| 4874 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4875 | * event queues |
| 4876 | **/ |
| 4877 | static void |
| 4878 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4879 | { |
| 4880 | uint8_t fcp_eqidx; |
| 4881 | |
| 4882 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4883 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4884 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4885 | if (phba->sli4_hba.fcp_cq) { |
| 4886 | do |
| 4887 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4888 | LPFC_QUEUE_REARM); |
| 4889 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
| 4890 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4891 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4892 | if (phba->sli4_hba.fp_eq) { |
| 4893 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 4894 | fcp_eqidx++) |
| 4895 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], |
| 4896 | LPFC_QUEUE_REARM); |
| 4897 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4901 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4902 | * @phba: Pointer to HBA context object. |
| 4903 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4904 | * @extnt_count: buffer to hold port available extent count. |
| 4905 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4906 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4907 | * This function calls the port and retrievs the number of available |
| 4908 | * extents and their size for a particular extent type. |
| 4909 | * |
| 4910 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4911 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4912 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4913 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 4914 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 4915 | { |
| 4916 | int rc = 0; |
| 4917 | uint32_t length; |
| 4918 | uint32_t mbox_tmo; |
| 4919 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 4920 | LPFC_MBOXQ_t *mbox; |
| 4921 | |
| 4922 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4923 | if (!mbox) |
| 4924 | return -ENOMEM; |
| 4925 | |
| 4926 | /* Find out how many extents are available for this resource type */ |
| 4927 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 4928 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 4929 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4930 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 4931 | length, LPFC_SLI4_MBX_EMBED); |
| 4932 | |
| 4933 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 4934 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 4935 | LPFC_SLI4_MBX_EMBED); |
| 4936 | if (unlikely(rc)) { |
| 4937 | rc = -EIO; |
| 4938 | goto err_exit; |
| 4939 | } |
| 4940 | |
| 4941 | if (!phba->sli4_hba.intr_enable) |
| 4942 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 4943 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 4944 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4945 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 4946 | } |
| 4947 | if (unlikely(rc)) { |
| 4948 | rc = -EIO; |
| 4949 | goto err_exit; |
| 4950 | } |
| 4951 | |
| 4952 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 4953 | if (bf_get(lpfc_mbox_hdr_status, |
| 4954 | &rsrc_info->header.cfg_shdr.response)) { |
| 4955 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 4956 | "2930 Failed to get resource extents " |
| 4957 | "Status 0x%x Add'l Status 0x%x\n", |
| 4958 | bf_get(lpfc_mbox_hdr_status, |
| 4959 | &rsrc_info->header.cfg_shdr.response), |
| 4960 | bf_get(lpfc_mbox_hdr_add_status, |
| 4961 | &rsrc_info->header.cfg_shdr.response)); |
| 4962 | rc = -EIO; |
| 4963 | goto err_exit; |
| 4964 | } |
| 4965 | |
| 4966 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 4967 | &rsrc_info->u.rsp); |
| 4968 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 4969 | &rsrc_info->u.rsp); |
| 4970 | err_exit: |
| 4971 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4972 | return rc; |
| 4973 | } |
| 4974 | |
| 4975 | /** |
| 4976 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 4977 | * @phba: Pointer to HBA context object. |
| 4978 | * @type: The extent type to check. |
| 4979 | * |
| 4980 | * This function reads the current available extents from the port and checks |
| 4981 | * if the extent count or extent size has changed since the last access. |
| 4982 | * Callers use this routine post port reset to understand if there is a |
| 4983 | * extent reprovisioning requirement. |
| 4984 | * |
| 4985 | * Returns: |
| 4986 | * -Error: error indicates problem. |
| 4987 | * 1: Extent count or size has changed. |
| 4988 | * 0: No changes. |
| 4989 | **/ |
| 4990 | static int |
| 4991 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 4992 | { |
| 4993 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 4994 | uint16_t size_diff, rsrc_ext_size; |
| 4995 | int rc = 0; |
| 4996 | struct lpfc_rsrc_blks *rsrc_entry; |
| 4997 | struct list_head *rsrc_blk_list = NULL; |
| 4998 | |
| 4999 | size_diff = 0; |
| 5000 | curr_ext_cnt = 0; |
| 5001 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5002 | &rsrc_ext_cnt, |
| 5003 | &rsrc_ext_size); |
| 5004 | if (unlikely(rc)) |
| 5005 | return -EIO; |
| 5006 | |
| 5007 | switch (type) { |
| 5008 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5009 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5010 | break; |
| 5011 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5012 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5013 | break; |
| 5014 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5015 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5016 | break; |
| 5017 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5018 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5019 | break; |
| 5020 | default: |
| 5021 | break; |
| 5022 | } |
| 5023 | |
| 5024 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5025 | curr_ext_cnt++; |
| 5026 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5027 | size_diff++; |
| 5028 | } |
| 5029 | |
| 5030 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5031 | rc = 1; |
| 5032 | |
| 5033 | return rc; |
| 5034 | } |
| 5035 | |
| 5036 | /** |
| 5037 | * lpfc_sli4_cfg_post_extnts - |
| 5038 | * @phba: Pointer to HBA context object. |
| 5039 | * @extnt_cnt - number of available extents. |
| 5040 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5041 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5042 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5043 | * |
| 5044 | * This function executes the extents allocation request. It also |
| 5045 | * takes care of the amount of memory needed to allocate or get the |
| 5046 | * allocated extents. It is the caller's responsibility to evaluate |
| 5047 | * the response. |
| 5048 | * |
| 5049 | * Returns: |
| 5050 | * -Error: Error value describes the condition found. |
| 5051 | * 0: if successful |
| 5052 | **/ |
| 5053 | static int |
| 5054 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt, |
| 5055 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5056 | { |
| 5057 | int rc = 0; |
| 5058 | uint32_t req_len; |
| 5059 | uint32_t emb_len; |
| 5060 | uint32_t alloc_len, mbox_tmo; |
| 5061 | |
| 5062 | /* Calculate the total requested length of the dma memory */ |
| 5063 | req_len = *extnt_cnt * sizeof(uint16_t); |
| 5064 | |
| 5065 | /* |
| 5066 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5067 | * accounts for extents-specific word. |
| 5068 | */ |
| 5069 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5070 | sizeof(uint32_t); |
| 5071 | |
| 5072 | /* |
| 5073 | * Presume the allocation and response will fit into an embedded |
| 5074 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5075 | */ |
| 5076 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5077 | if (req_len > emb_len) { |
| 5078 | req_len = *extnt_cnt * sizeof(uint16_t) + |
| 5079 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5080 | sizeof(uint32_t); |
| 5081 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5082 | } |
| 5083 | |
| 5084 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5085 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5086 | req_len, *emb); |
| 5087 | if (alloc_len < req_len) { |
| 5088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5089 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5090 | "less than the requested DMA memory " |
| 5091 | "size (x%x)\n", alloc_len, req_len); |
| 5092 | return -ENOMEM; |
| 5093 | } |
| 5094 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb); |
| 5095 | if (unlikely(rc)) |
| 5096 | return -EIO; |
| 5097 | |
| 5098 | if (!phba->sli4_hba.intr_enable) |
| 5099 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5100 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5101 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5102 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5103 | } |
| 5104 | |
| 5105 | if (unlikely(rc)) |
| 5106 | rc = -EIO; |
| 5107 | return rc; |
| 5108 | } |
| 5109 | |
| 5110 | /** |
| 5111 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5112 | * @phba: Pointer to HBA context object. |
| 5113 | * @type: The resource extent type to allocate. |
| 5114 | * |
| 5115 | * This function allocates the number of elements for the specified |
| 5116 | * resource type. |
| 5117 | **/ |
| 5118 | static int |
| 5119 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5120 | { |
| 5121 | bool emb = false; |
| 5122 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5123 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5124 | uint16_t *ids; |
| 5125 | int i, rc; |
| 5126 | unsigned long longs; |
| 5127 | unsigned long *bmask; |
| 5128 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5129 | LPFC_MBOXQ_t *mbox; |
| 5130 | uint32_t length; |
| 5131 | struct lpfc_id_range *id_array = NULL; |
| 5132 | void *virtaddr = NULL; |
| 5133 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5134 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5135 | struct list_head *ext_blk_list; |
| 5136 | |
| 5137 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5138 | &rsrc_cnt, |
| 5139 | &rsrc_size); |
| 5140 | if (unlikely(rc)) |
| 5141 | return -EIO; |
| 5142 | |
| 5143 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5144 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5145 | "3009 No available Resource Extents " |
| 5146 | "for resource type 0x%x: Count: 0x%x, " |
| 5147 | "Size 0x%x\n", type, rsrc_cnt, |
| 5148 | rsrc_size); |
| 5149 | return -ENOMEM; |
| 5150 | } |
| 5151 | |
| 5152 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT, |
| 5153 | "2903 Available Resource Extents " |
| 5154 | "for resource type 0x%x: Count: 0x%x, " |
| 5155 | "Size 0x%x\n", type, rsrc_cnt, |
| 5156 | rsrc_size); |
| 5157 | |
| 5158 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5159 | if (!mbox) |
| 5160 | return -ENOMEM; |
| 5161 | |
| 5162 | rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox); |
| 5163 | if (unlikely(rc)) { |
| 5164 | rc = -EIO; |
| 5165 | goto err_exit; |
| 5166 | } |
| 5167 | |
| 5168 | /* |
| 5169 | * Figure out where the response is located. Then get local pointers |
| 5170 | * to the response data. The port does not guarantee to respond to |
| 5171 | * all extents counts request so update the local variable with the |
| 5172 | * allocated count from the port. |
| 5173 | */ |
| 5174 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5175 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5176 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5177 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5178 | } else { |
| 5179 | virtaddr = mbox->sge_array->addr[0]; |
| 5180 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5181 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5182 | id_array = &n_rsrc->id; |
| 5183 | } |
| 5184 | |
| 5185 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5186 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5187 | |
| 5188 | /* |
| 5189 | * Based on the resource size and count, correct the base and max |
| 5190 | * resource values. |
| 5191 | */ |
| 5192 | length = sizeof(struct lpfc_rsrc_blks); |
| 5193 | switch (type) { |
| 5194 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5195 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5196 | sizeof(unsigned long), |
| 5197 | GFP_KERNEL); |
| 5198 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5199 | rc = -ENOMEM; |
| 5200 | goto err_exit; |
| 5201 | } |
| 5202 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5203 | sizeof(uint16_t), |
| 5204 | GFP_KERNEL); |
| 5205 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5206 | kfree(phba->sli4_hba.rpi_bmask); |
| 5207 | rc = -ENOMEM; |
| 5208 | goto err_exit; |
| 5209 | } |
| 5210 | |
| 5211 | /* |
| 5212 | * The next_rpi was initialized with the maximum available |
| 5213 | * count but the port may allocate a smaller number. Catch |
| 5214 | * that case and update the next_rpi. |
| 5215 | */ |
| 5216 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5217 | |
| 5218 | /* Initialize local ptrs for common extent processing later. */ |
| 5219 | bmask = phba->sli4_hba.rpi_bmask; |
| 5220 | ids = phba->sli4_hba.rpi_ids; |
| 5221 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5222 | break; |
| 5223 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5224 | phba->vpi_bmask = kzalloc(longs * |
| 5225 | sizeof(unsigned long), |
| 5226 | GFP_KERNEL); |
| 5227 | if (unlikely(!phba->vpi_bmask)) { |
| 5228 | rc = -ENOMEM; |
| 5229 | goto err_exit; |
| 5230 | } |
| 5231 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5232 | sizeof(uint16_t), |
| 5233 | GFP_KERNEL); |
| 5234 | if (unlikely(!phba->vpi_ids)) { |
| 5235 | kfree(phba->vpi_bmask); |
| 5236 | rc = -ENOMEM; |
| 5237 | goto err_exit; |
| 5238 | } |
| 5239 | |
| 5240 | /* Initialize local ptrs for common extent processing later. */ |
| 5241 | bmask = phba->vpi_bmask; |
| 5242 | ids = phba->vpi_ids; |
| 5243 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5244 | break; |
| 5245 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5246 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5247 | sizeof(unsigned long), |
| 5248 | GFP_KERNEL); |
| 5249 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5250 | rc = -ENOMEM; |
| 5251 | goto err_exit; |
| 5252 | } |
| 5253 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5254 | sizeof(uint16_t), |
| 5255 | GFP_KERNEL); |
| 5256 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5257 | kfree(phba->sli4_hba.xri_bmask); |
| 5258 | rc = -ENOMEM; |
| 5259 | goto err_exit; |
| 5260 | } |
| 5261 | |
| 5262 | /* Initialize local ptrs for common extent processing later. */ |
| 5263 | bmask = phba->sli4_hba.xri_bmask; |
| 5264 | ids = phba->sli4_hba.xri_ids; |
| 5265 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5266 | break; |
| 5267 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5268 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5269 | sizeof(unsigned long), |
| 5270 | GFP_KERNEL); |
| 5271 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5272 | rc = -ENOMEM; |
| 5273 | goto err_exit; |
| 5274 | } |
| 5275 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5276 | sizeof(uint16_t), |
| 5277 | GFP_KERNEL); |
| 5278 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5279 | kfree(phba->sli4_hba.vfi_bmask); |
| 5280 | rc = -ENOMEM; |
| 5281 | goto err_exit; |
| 5282 | } |
| 5283 | |
| 5284 | /* Initialize local ptrs for common extent processing later. */ |
| 5285 | bmask = phba->sli4_hba.vfi_bmask; |
| 5286 | ids = phba->sli4_hba.vfi_ids; |
| 5287 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5288 | break; |
| 5289 | default: |
| 5290 | /* Unsupported Opcode. Fail call. */ |
| 5291 | id_array = NULL; |
| 5292 | bmask = NULL; |
| 5293 | ids = NULL; |
| 5294 | ext_blk_list = NULL; |
| 5295 | goto err_exit; |
| 5296 | } |
| 5297 | |
| 5298 | /* |
| 5299 | * Complete initializing the extent configuration with the |
| 5300 | * allocated ids assigned to this function. The bitmask serves |
| 5301 | * as an index into the array and manages the available ids. The |
| 5302 | * array just stores the ids communicated to the port via the wqes. |
| 5303 | */ |
| 5304 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5305 | if ((i % 2) == 0) |
| 5306 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5307 | &id_array[k]); |
| 5308 | else |
| 5309 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5310 | &id_array[k]); |
| 5311 | |
| 5312 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5313 | if (unlikely(!rsrc_blks)) { |
| 5314 | rc = -ENOMEM; |
| 5315 | kfree(bmask); |
| 5316 | kfree(ids); |
| 5317 | goto err_exit; |
| 5318 | } |
| 5319 | rsrc_blks->rsrc_start = rsrc_id; |
| 5320 | rsrc_blks->rsrc_size = rsrc_size; |
| 5321 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5322 | rsrc_start = rsrc_id; |
| 5323 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5324 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5325 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5326 | |
| 5327 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5328 | ids[j] = rsrc_id; |
| 5329 | rsrc_id++; |
| 5330 | j++; |
| 5331 | } |
| 5332 | /* Entire word processed. Get next word.*/ |
| 5333 | if ((i % 2) == 1) |
| 5334 | k++; |
| 5335 | } |
| 5336 | err_exit: |
| 5337 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5338 | return rc; |
| 5339 | } |
| 5340 | |
| 5341 | /** |
| 5342 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5343 | * @phba: Pointer to HBA context object. |
| 5344 | * @type: the extent's type. |
| 5345 | * |
| 5346 | * This function deallocates all extents of a particular resource type. |
| 5347 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5348 | * is the caller's responsibility to release all kernel memory resources. |
| 5349 | **/ |
| 5350 | static int |
| 5351 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5352 | { |
| 5353 | int rc; |
| 5354 | uint32_t length, mbox_tmo = 0; |
| 5355 | LPFC_MBOXQ_t *mbox; |
| 5356 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5357 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5358 | |
| 5359 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5360 | if (!mbox) |
| 5361 | return -ENOMEM; |
| 5362 | |
| 5363 | /* |
| 5364 | * This function sends an embedded mailbox because it only sends the |
| 5365 | * the resource type. All extents of this type are released by the |
| 5366 | * port. |
| 5367 | */ |
| 5368 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5369 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5370 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5371 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5372 | length, LPFC_SLI4_MBX_EMBED); |
| 5373 | |
| 5374 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5375 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5376 | LPFC_SLI4_MBX_EMBED); |
| 5377 | if (unlikely(rc)) { |
| 5378 | rc = -EIO; |
| 5379 | goto out_free_mbox; |
| 5380 | } |
| 5381 | if (!phba->sli4_hba.intr_enable) |
| 5382 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5383 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5384 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5385 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5386 | } |
| 5387 | if (unlikely(rc)) { |
| 5388 | rc = -EIO; |
| 5389 | goto out_free_mbox; |
| 5390 | } |
| 5391 | |
| 5392 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5393 | if (bf_get(lpfc_mbox_hdr_status, |
| 5394 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5395 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5396 | "2919 Failed to release resource extents " |
| 5397 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5398 | "Resource memory not released.\n", |
| 5399 | type, |
| 5400 | bf_get(lpfc_mbox_hdr_status, |
| 5401 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5402 | bf_get(lpfc_mbox_hdr_add_status, |
| 5403 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5404 | rc = -EIO; |
| 5405 | goto out_free_mbox; |
| 5406 | } |
| 5407 | |
| 5408 | /* Release kernel memory resources for the specific type. */ |
| 5409 | switch (type) { |
| 5410 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5411 | kfree(phba->vpi_bmask); |
| 5412 | kfree(phba->vpi_ids); |
| 5413 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5414 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5415 | &phba->lpfc_vpi_blk_list, list) { |
| 5416 | list_del_init(&rsrc_blk->list); |
| 5417 | kfree(rsrc_blk); |
| 5418 | } |
| 5419 | break; |
| 5420 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5421 | kfree(phba->sli4_hba.xri_bmask); |
| 5422 | kfree(phba->sli4_hba.xri_ids); |
| 5423 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5424 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5425 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5426 | list_del_init(&rsrc_blk->list); |
| 5427 | kfree(rsrc_blk); |
| 5428 | } |
| 5429 | break; |
| 5430 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5431 | kfree(phba->sli4_hba.vfi_bmask); |
| 5432 | kfree(phba->sli4_hba.vfi_ids); |
| 5433 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5434 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5435 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5436 | list_del_init(&rsrc_blk->list); |
| 5437 | kfree(rsrc_blk); |
| 5438 | } |
| 5439 | break; |
| 5440 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5441 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5442 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5443 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5444 | list_del_init(&rsrc_blk->list); |
| 5445 | kfree(rsrc_blk); |
| 5446 | } |
| 5447 | break; |
| 5448 | default: |
| 5449 | break; |
| 5450 | } |
| 5451 | |
| 5452 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5453 | |
| 5454 | out_free_mbox: |
| 5455 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5456 | return rc; |
| 5457 | } |
| 5458 | |
| 5459 | /** |
| 5460 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5461 | * @phba: Pointer to HBA context object. |
| 5462 | * |
| 5463 | * This function allocates all SLI4 resource identifiers. |
| 5464 | **/ |
| 5465 | int |
| 5466 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5467 | { |
| 5468 | int i, rc, error = 0; |
| 5469 | uint16_t count, base; |
| 5470 | unsigned long longs; |
| 5471 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5472 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5473 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5474 | if (phba->sli4_hba.extents_in_use) { |
| 5475 | /* |
| 5476 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5477 | * resource extent count must be read and allocated before |
| 5478 | * provisioning the resource id arrays. |
| 5479 | */ |
| 5480 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5481 | LPFC_IDX_RSRC_RDY) { |
| 5482 | /* |
| 5483 | * Extent-based resources are set - the driver could |
| 5484 | * be in a port reset. Figure out if any corrective |
| 5485 | * actions need to be taken. |
| 5486 | */ |
| 5487 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5488 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5489 | if (rc != 0) |
| 5490 | error++; |
| 5491 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5492 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5493 | if (rc != 0) |
| 5494 | error++; |
| 5495 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5496 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5497 | if (rc != 0) |
| 5498 | error++; |
| 5499 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5500 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5501 | if (rc != 0) |
| 5502 | error++; |
| 5503 | |
| 5504 | /* |
| 5505 | * It's possible that the number of resources |
| 5506 | * provided to this port instance changed between |
| 5507 | * resets. Detect this condition and reallocate |
| 5508 | * resources. Otherwise, there is no action. |
| 5509 | */ |
| 5510 | if (error) { |
| 5511 | lpfc_printf_log(phba, KERN_INFO, |
| 5512 | LOG_MBOX | LOG_INIT, |
| 5513 | "2931 Detected extent resource " |
| 5514 | "change. Reallocating all " |
| 5515 | "extents.\n"); |
| 5516 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5517 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5518 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5519 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5520 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5521 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5522 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5523 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5524 | } else |
| 5525 | return 0; |
| 5526 | } |
| 5527 | |
| 5528 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5529 | if (unlikely(rc)) |
| 5530 | goto err_exit; |
| 5531 | |
| 5532 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5533 | if (unlikely(rc)) |
| 5534 | goto err_exit; |
| 5535 | |
| 5536 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5537 | if (unlikely(rc)) |
| 5538 | goto err_exit; |
| 5539 | |
| 5540 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5541 | if (unlikely(rc)) |
| 5542 | goto err_exit; |
| 5543 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5544 | LPFC_IDX_RSRC_RDY); |
| 5545 | return rc; |
| 5546 | } else { |
| 5547 | /* |
| 5548 | * The port does not support resource extents. The XRI, VPI, |
| 5549 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5550 | * Just allocate the bitmasks and provision the resource id |
| 5551 | * arrays. If a port reset is active, the resources don't |
| 5552 | * need any action - just exit. |
| 5553 | */ |
| 5554 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5555 | LPFC_IDX_RSRC_RDY) { |
| 5556 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5557 | lpfc_sli4_remove_rpis(phba); |
| 5558 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5559 | /* RPIs. */ |
| 5560 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
| 5561 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5562 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5563 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5564 | sizeof(unsigned long), |
| 5565 | GFP_KERNEL); |
| 5566 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5567 | rc = -ENOMEM; |
| 5568 | goto err_exit; |
| 5569 | } |
| 5570 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5571 | sizeof(uint16_t), |
| 5572 | GFP_KERNEL); |
| 5573 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5574 | rc = -ENOMEM; |
| 5575 | goto free_rpi_bmask; |
| 5576 | } |
| 5577 | |
| 5578 | for (i = 0; i < count; i++) |
| 5579 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5580 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 5581 | lpfc_sli4_node_prep(phba); |
| 5582 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5583 | /* VPIs. */ |
| 5584 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
| 5585 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5586 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5587 | phba->vpi_bmask = kzalloc(longs * |
| 5588 | sizeof(unsigned long), |
| 5589 | GFP_KERNEL); |
| 5590 | if (unlikely(!phba->vpi_bmask)) { |
| 5591 | rc = -ENOMEM; |
| 5592 | goto free_rpi_ids; |
| 5593 | } |
| 5594 | phba->vpi_ids = kzalloc(count * |
| 5595 | sizeof(uint16_t), |
| 5596 | GFP_KERNEL); |
| 5597 | if (unlikely(!phba->vpi_ids)) { |
| 5598 | rc = -ENOMEM; |
| 5599 | goto free_vpi_bmask; |
| 5600 | } |
| 5601 | |
| 5602 | for (i = 0; i < count; i++) |
| 5603 | phba->vpi_ids[i] = base + i; |
| 5604 | |
| 5605 | /* XRIs. */ |
| 5606 | count = phba->sli4_hba.max_cfg_param.max_xri; |
| 5607 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5608 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5609 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5610 | sizeof(unsigned long), |
| 5611 | GFP_KERNEL); |
| 5612 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5613 | rc = -ENOMEM; |
| 5614 | goto free_vpi_ids; |
| 5615 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5616 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
| 5617 | phba->sli4_hba.xri_count = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5618 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5619 | sizeof(uint16_t), |
| 5620 | GFP_KERNEL); |
| 5621 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5622 | rc = -ENOMEM; |
| 5623 | goto free_xri_bmask; |
| 5624 | } |
| 5625 | |
| 5626 | for (i = 0; i < count; i++) |
| 5627 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5628 | |
| 5629 | /* VFIs. */ |
| 5630 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
| 5631 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5632 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5633 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5634 | sizeof(unsigned long), |
| 5635 | GFP_KERNEL); |
| 5636 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5637 | rc = -ENOMEM; |
| 5638 | goto free_xri_ids; |
| 5639 | } |
| 5640 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5641 | sizeof(uint16_t), |
| 5642 | GFP_KERNEL); |
| 5643 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5644 | rc = -ENOMEM; |
| 5645 | goto free_vfi_bmask; |
| 5646 | } |
| 5647 | |
| 5648 | for (i = 0; i < count; i++) |
| 5649 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5650 | |
| 5651 | /* |
| 5652 | * Mark all resources ready. An HBA reset doesn't need |
| 5653 | * to reset the initialization. |
| 5654 | */ |
| 5655 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5656 | LPFC_IDX_RSRC_RDY); |
| 5657 | return 0; |
| 5658 | } |
| 5659 | |
| 5660 | free_vfi_bmask: |
| 5661 | kfree(phba->sli4_hba.vfi_bmask); |
| 5662 | free_xri_ids: |
| 5663 | kfree(phba->sli4_hba.xri_ids); |
| 5664 | free_xri_bmask: |
| 5665 | kfree(phba->sli4_hba.xri_bmask); |
| 5666 | free_vpi_ids: |
| 5667 | kfree(phba->vpi_ids); |
| 5668 | free_vpi_bmask: |
| 5669 | kfree(phba->vpi_bmask); |
| 5670 | free_rpi_ids: |
| 5671 | kfree(phba->sli4_hba.rpi_ids); |
| 5672 | free_rpi_bmask: |
| 5673 | kfree(phba->sli4_hba.rpi_bmask); |
| 5674 | err_exit: |
| 5675 | return rc; |
| 5676 | } |
| 5677 | |
| 5678 | /** |
| 5679 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5680 | * @phba: Pointer to HBA context object. |
| 5681 | * |
| 5682 | * This function allocates the number of elements for the specified |
| 5683 | * resource type. |
| 5684 | **/ |
| 5685 | int |
| 5686 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5687 | { |
| 5688 | if (phba->sli4_hba.extents_in_use) { |
| 5689 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5690 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5691 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5692 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5693 | } else { |
| 5694 | kfree(phba->vpi_bmask); |
| 5695 | kfree(phba->vpi_ids); |
| 5696 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5697 | kfree(phba->sli4_hba.xri_bmask); |
| 5698 | kfree(phba->sli4_hba.xri_ids); |
| 5699 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5700 | kfree(phba->sli4_hba.vfi_bmask); |
| 5701 | kfree(phba->sli4_hba.vfi_ids); |
| 5702 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5703 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5704 | } |
| 5705 | |
| 5706 | return 0; |
| 5707 | } |
| 5708 | |
| 5709 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5710 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5711 | * @phba: Pointer to HBA context object. |
| 5712 | * @type: The resource extent type. |
| 5713 | * @extnt_count: buffer to hold port extent count response |
| 5714 | * @extnt_size: buffer to hold port extent size response. |
| 5715 | * |
| 5716 | * This function calls the port to read the host allocated extents |
| 5717 | * for a particular type. |
| 5718 | **/ |
| 5719 | int |
| 5720 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5721 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5722 | { |
| 5723 | bool emb; |
| 5724 | int rc = 0; |
| 5725 | uint16_t curr_blks = 0; |
| 5726 | uint32_t req_len, emb_len; |
| 5727 | uint32_t alloc_len, mbox_tmo; |
| 5728 | struct list_head *blk_list_head; |
| 5729 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5730 | LPFC_MBOXQ_t *mbox; |
| 5731 | void *virtaddr = NULL; |
| 5732 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5733 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5734 | union lpfc_sli4_cfg_shdr *shdr; |
| 5735 | |
| 5736 | switch (type) { |
| 5737 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5738 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5739 | break; |
| 5740 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5741 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5742 | break; |
| 5743 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5744 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5745 | break; |
| 5746 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5747 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5748 | break; |
| 5749 | default: |
| 5750 | return -EIO; |
| 5751 | } |
| 5752 | |
| 5753 | /* Count the number of extents currently allocatd for this type. */ |
| 5754 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5755 | if (curr_blks == 0) { |
| 5756 | /* |
| 5757 | * The GET_ALLOCATED mailbox does not return the size, |
| 5758 | * just the count. The size should be just the size |
| 5759 | * stored in the current allocated block and all sizes |
| 5760 | * for an extent type are the same so set the return |
| 5761 | * value now. |
| 5762 | */ |
| 5763 | *extnt_size = rsrc_blk->rsrc_size; |
| 5764 | } |
| 5765 | curr_blks++; |
| 5766 | } |
| 5767 | |
| 5768 | /* Calculate the total requested length of the dma memory. */ |
| 5769 | req_len = curr_blks * sizeof(uint16_t); |
| 5770 | |
| 5771 | /* |
| 5772 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5773 | * accounts for extents-specific word. |
| 5774 | */ |
| 5775 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5776 | sizeof(uint32_t); |
| 5777 | |
| 5778 | /* |
| 5779 | * Presume the allocation and response will fit into an embedded |
| 5780 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5781 | */ |
| 5782 | emb = LPFC_SLI4_MBX_EMBED; |
| 5783 | req_len = emb_len; |
| 5784 | if (req_len > emb_len) { |
| 5785 | req_len = curr_blks * sizeof(uint16_t) + |
| 5786 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5787 | sizeof(uint32_t); |
| 5788 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5789 | } |
| 5790 | |
| 5791 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5792 | if (!mbox) |
| 5793 | return -ENOMEM; |
| 5794 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5795 | |
| 5796 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5797 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5798 | req_len, emb); |
| 5799 | if (alloc_len < req_len) { |
| 5800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5801 | "2983 Allocated DMA memory size (x%x) is " |
| 5802 | "less than the requested DMA memory " |
| 5803 | "size (x%x)\n", alloc_len, req_len); |
| 5804 | rc = -ENOMEM; |
| 5805 | goto err_exit; |
| 5806 | } |
| 5807 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5808 | if (unlikely(rc)) { |
| 5809 | rc = -EIO; |
| 5810 | goto err_exit; |
| 5811 | } |
| 5812 | |
| 5813 | if (!phba->sli4_hba.intr_enable) |
| 5814 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5815 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5816 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5817 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5818 | } |
| 5819 | |
| 5820 | if (unlikely(rc)) { |
| 5821 | rc = -EIO; |
| 5822 | goto err_exit; |
| 5823 | } |
| 5824 | |
| 5825 | /* |
| 5826 | * Figure out where the response is located. Then get local pointers |
| 5827 | * to the response data. The port does not guarantee to respond to |
| 5828 | * all extents counts request so update the local variable with the |
| 5829 | * allocated count from the port. |
| 5830 | */ |
| 5831 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5832 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5833 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5834 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5835 | } else { |
| 5836 | virtaddr = mbox->sge_array->addr[0]; |
| 5837 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5838 | shdr = &n_rsrc->cfg_shdr; |
| 5839 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5840 | } |
| 5841 | |
| 5842 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5843 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5844 | "2984 Failed to read allocated resources " |
| 5845 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5846 | type, |
| 5847 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5848 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5849 | rc = -EIO; |
| 5850 | goto err_exit; |
| 5851 | } |
| 5852 | err_exit: |
| 5853 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5854 | return rc; |
| 5855 | } |
| 5856 | |
| 5857 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5858 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 5859 | * @phba: Pointer to HBA context object. |
| 5860 | * |
| 5861 | * This function is the main SLI4 device intialization PCI function. This |
| 5862 | * function is called by the HBA intialization code, HBA reset code and |
| 5863 | * HBA error attention handler code. Caller is not required to hold any |
| 5864 | * locks. |
| 5865 | **/ |
| 5866 | int |
| 5867 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 5868 | { |
| 5869 | int rc; |
| 5870 | LPFC_MBOXQ_t *mboxq; |
| 5871 | struct lpfc_mqe *mqe; |
| 5872 | uint8_t *vpd; |
| 5873 | uint32_t vpd_size; |
| 5874 | uint32_t ftr_rsp = 0; |
| 5875 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 5876 | struct lpfc_vport *vport = phba->pport; |
| 5877 | struct lpfc_dmabuf *mp; |
| 5878 | |
| 5879 | /* Perform a PCI function reset to start from clean */ |
| 5880 | rc = lpfc_pci_function_reset(phba); |
| 5881 | if (unlikely(rc)) |
| 5882 | return -ENODEV; |
| 5883 | |
| 5884 | /* Check the HBA Host Status Register for readyness */ |
| 5885 | rc = lpfc_sli4_post_status_check(phba); |
| 5886 | if (unlikely(rc)) |
| 5887 | return -ENODEV; |
| 5888 | else { |
| 5889 | spin_lock_irq(&phba->hbalock); |
| 5890 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 5891 | spin_unlock_irq(&phba->hbalock); |
| 5892 | } |
| 5893 | |
| 5894 | /* |
| 5895 | * Allocate a single mailbox container for initializing the |
| 5896 | * port. |
| 5897 | */ |
| 5898 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5899 | if (!mboxq) |
| 5900 | return -ENOMEM; |
| 5901 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5902 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5903 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5904 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 5905 | if (!vpd) { |
| 5906 | rc = -ENOMEM; |
| 5907 | goto out_free_mbox; |
| 5908 | } |
| 5909 | |
| 5910 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5911 | if (unlikely(rc)) { |
| 5912 | kfree(vpd); |
| 5913 | goto out_free_mbox; |
| 5914 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5915 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5916 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 5917 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5918 | phba->hba_flag |= HBA_FCOE_MODE; |
| 5919 | else |
| 5920 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5921 | |
| 5922 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 5923 | LPFC_DCBX_CEE_MODE) |
| 5924 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 5925 | else |
| 5926 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 5927 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 5928 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5929 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5930 | "0376 READ_REV Error. SLI Level %d " |
| 5931 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5932 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5933 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5934 | kfree(vpd); |
| 5935 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5936 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5937 | |
| 5938 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5939 | * Continue initialization with default values even if driver failed |
| 5940 | * to read FCoE param config regions, only read parameters if the |
| 5941 | * board is FCoE |
| 5942 | */ |
| 5943 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 5944 | lpfc_sli4_read_fcoe_params(phba)) |
| 5945 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 5946 | "2570 Failed to read FCoE parameters\n"); |
| 5947 | |
| 5948 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5949 | * Retrieve sli4 device physical port name, failure of doing it |
| 5950 | * is considered as non-fatal. |
| 5951 | */ |
| 5952 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 5953 | if (!rc) |
| 5954 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5955 | "3080 Successful retrieving SLI4 device " |
| 5956 | "physical port name: %s.\n", phba->Port); |
| 5957 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5958 | /* |
| 5959 | * Evaluate the read rev and vpd data. Populate the driver |
| 5960 | * state with the results. If this routine fails, the failure |
| 5961 | * is not fatal as the driver will use generic values. |
| 5962 | */ |
| 5963 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 5964 | if (unlikely(!rc)) { |
| 5965 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5966 | "0377 Error %d parsing vpd. " |
| 5967 | "Using defaults.\n", rc); |
| 5968 | rc = 0; |
| 5969 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5970 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5971 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 5972 | /* Save information as VPD data */ |
| 5973 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 5974 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 5975 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 5976 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 5977 | &mqe->un.read_rev); |
| 5978 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 5979 | &mqe->un.read_rev); |
| 5980 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 5981 | &mqe->un.read_rev); |
| 5982 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 5983 | &mqe->un.read_rev); |
| 5984 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 5985 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 5986 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 5987 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 5988 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 5989 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 5990 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5991 | "(%d):0380 READ_REV Status x%x " |
| 5992 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 5993 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5994 | bf_get(lpfc_mqe_status, mqe), |
| 5995 | phba->vpd.rev.opFwName, |
| 5996 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 5997 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5998 | |
| 5999 | /* |
| 6000 | * Discover the port's supported feature set and match it against the |
| 6001 | * hosts requests. |
| 6002 | */ |
| 6003 | lpfc_request_features(phba, mboxq); |
| 6004 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6005 | if (unlikely(rc)) { |
| 6006 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6007 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | /* |
| 6011 | * The port must support FCP initiator mode as this is the |
| 6012 | * only mode running in the host. |
| 6013 | */ |
| 6014 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6015 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6016 | "0378 No support for fcpi mode.\n"); |
| 6017 | ftr_rsp++; |
| 6018 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6019 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6020 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6021 | else |
| 6022 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6023 | /* |
| 6024 | * If the port cannot support the host's requested features |
| 6025 | * then turn off the global config parameters to disable the |
| 6026 | * feature in the driver. This is not a fatal error. |
| 6027 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6028 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6029 | if (phba->cfg_enable_bg) { |
| 6030 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6031 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6032 | else |
| 6033 | ftr_rsp++; |
| 6034 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6035 | |
| 6036 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6037 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6038 | ftr_rsp++; |
| 6039 | |
| 6040 | if (ftr_rsp) { |
| 6041 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6042 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6043 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6044 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6045 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6046 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6047 | phba->cfg_enable_bg = 0; |
| 6048 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6049 | phba->cfg_enable_npiv = 0; |
| 6050 | } |
| 6051 | |
| 6052 | /* These SLI3 features are assumed in SLI4 */ |
| 6053 | spin_lock_irq(&phba->hbalock); |
| 6054 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6055 | spin_unlock_irq(&phba->hbalock); |
| 6056 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6057 | /* |
| 6058 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6059 | * calls depends on these resources to complete port setup. |
| 6060 | */ |
| 6061 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6062 | if (rc) { |
| 6063 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6064 | "2920 Failed to alloc Resource IDs " |
| 6065 | "rc = x%x\n", rc); |
| 6066 | goto out_free_mbox; |
| 6067 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6068 | /* update physical xri mappings in the scsi buffers */ |
| 6069 | lpfc_scsi_buf_update(phba); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6070 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6071 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6072 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6073 | if (rc) { |
| 6074 | phba->link_state = LPFC_HBA_ERROR; |
| 6075 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6076 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6077 | } |
| 6078 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6079 | mboxq->vport = vport; |
| 6080 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6081 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6082 | if (rc == MBX_SUCCESS) { |
| 6083 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6084 | rc = 0; |
| 6085 | } |
| 6086 | |
| 6087 | /* |
| 6088 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6089 | * it to the mbuf pool. |
| 6090 | */ |
| 6091 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6092 | kfree(mp); |
| 6093 | mboxq->context1 = NULL; |
| 6094 | if (unlikely(rc)) { |
| 6095 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6096 | "0382 READ_SPARAM command failed " |
| 6097 | "status %d, mbxStatus x%x\n", |
| 6098 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6099 | phba->link_state = LPFC_HBA_ERROR; |
| 6100 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6101 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6102 | } |
| 6103 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6104 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6105 | |
| 6106 | /* Update the fc_host data structures with new wwn. */ |
| 6107 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6108 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6109 | |
| 6110 | /* Register SGL pool to the device using non-embedded mailbox command */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6111 | if (!phba->sli4_hba.extents_in_use) { |
| 6112 | rc = lpfc_sli4_post_els_sgl_list(phba); |
| 6113 | if (unlikely(rc)) { |
| 6114 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6115 | "0582 Error %d during els sgl post " |
| 6116 | "operation\n", rc); |
| 6117 | rc = -ENODEV; |
| 6118 | goto out_free_mbox; |
| 6119 | } |
| 6120 | } else { |
| 6121 | rc = lpfc_sli4_post_els_sgl_list_ext(phba); |
| 6122 | if (unlikely(rc)) { |
| 6123 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6124 | "2560 Error %d during els sgl post " |
| 6125 | "operation\n", rc); |
| 6126 | rc = -ENODEV; |
| 6127 | goto out_free_mbox; |
| 6128 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | /* Register SCSI SGL pool to the device */ |
| 6132 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6133 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6134 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6135 | "0383 Error %d during scsi sgl post " |
| 6136 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6137 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6138 | /* A pci function reset will repost them */ |
| 6139 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6140 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | /* Post the rpi header region to the device. */ |
| 6144 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6145 | if (unlikely(rc)) { |
| 6146 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6147 | "0393 Error %d during rpi post operation\n", |
| 6148 | rc); |
| 6149 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6150 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6151 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6152 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6153 | /* Create all the SLI4 queues */ |
| 6154 | rc = lpfc_sli4_queue_create(phba); |
| 6155 | if (rc) { |
| 6156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6157 | "3089 Failed to allocate queues\n"); |
| 6158 | rc = -ENODEV; |
| 6159 | goto out_stop_timers; |
| 6160 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6161 | /* Set up all the queues to the device */ |
| 6162 | rc = lpfc_sli4_queue_setup(phba); |
| 6163 | if (unlikely(rc)) { |
| 6164 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6165 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6166 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | /* Arm the CQs and then EQs on device */ |
| 6170 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6171 | |
| 6172 | /* Indicate device interrupt mode */ |
| 6173 | phba->sli4_hba.intr_enable = 1; |
| 6174 | |
| 6175 | /* Allow asynchronous mailbox command to go through */ |
| 6176 | spin_lock_irq(&phba->hbalock); |
| 6177 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6178 | spin_unlock_irq(&phba->hbalock); |
| 6179 | |
| 6180 | /* Post receive buffers to the device */ |
| 6181 | lpfc_sli4_rb_setup(phba); |
| 6182 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6183 | /* Reset HBA FCF states after HBA reset */ |
| 6184 | phba->fcf.fcf_flag = 0; |
| 6185 | phba->fcf.current_rec.flag = 0; |
| 6186 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6187 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6188 | mod_timer(&vport->els_tmofunc, |
| 6189 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6190 | |
| 6191 | /* Start heart beat timer */ |
| 6192 | mod_timer(&phba->hb_tmofunc, |
| 6193 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6194 | phba->hb_outstanding = 0; |
| 6195 | phba->last_completion_time = jiffies; |
| 6196 | |
| 6197 | /* Start error attention (ERATT) polling timer */ |
| 6198 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6199 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6200 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6201 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6202 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6203 | if (!rc) { |
| 6204 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6205 | "2829 This device supports " |
| 6206 | "Advanced Error Reporting (AER)\n"); |
| 6207 | spin_lock_irq(&phba->hbalock); |
| 6208 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6209 | spin_unlock_irq(&phba->hbalock); |
| 6210 | } else { |
| 6211 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6212 | "2830 This device does not support " |
| 6213 | "Advanced Error Reporting (AER)\n"); |
| 6214 | phba->cfg_aer_support = 0; |
| 6215 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6216 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6217 | } |
| 6218 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6219 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6220 | /* |
| 6221 | * The FC Port needs to register FCFI (index 0) |
| 6222 | */ |
| 6223 | lpfc_reg_fcfi(phba, mboxq); |
| 6224 | mboxq->vport = phba->pport; |
| 6225 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6226 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6227 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6228 | rc = 0; |
| 6229 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6230 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6231 | |
| 6232 | /* Check if the port is configured to be disabled */ |
| 6233 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6234 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6235 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6236 | /* |
| 6237 | * The port is ready, set the host's link state to LINK_DOWN |
| 6238 | * in preparation for link interrupts. |
| 6239 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6240 | spin_lock_irq(&phba->hbalock); |
| 6241 | phba->link_state = LPFC_LINK_DOWN; |
| 6242 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6243 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6244 | (phba->hba_flag & LINK_DISABLED)) { |
| 6245 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6246 | "3103 Adapter Link is disabled.\n"); |
| 6247 | lpfc_down_link(phba, mboxq); |
| 6248 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6249 | if (rc != MBX_SUCCESS) { |
| 6250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6251 | "3104 Adapter failed to issue " |
| 6252 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6253 | goto out_unset_queue; |
| 6254 | } |
| 6255 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6256 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6257 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6258 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6259 | if (rc) |
| 6260 | goto out_unset_queue; |
| 6261 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6262 | } |
| 6263 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6264 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6265 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6266 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6267 | lpfc_sli4_queue_unset(phba); |
| 6268 | out_destroy_queue: |
| 6269 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6270 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6271 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6272 | out_free_mbox: |
| 6273 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6274 | return rc; |
| 6275 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6276 | |
| 6277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6278 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6279 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6280 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6281 | * This is the callback function for mailbox timer. The mailbox |
| 6282 | * timer is armed when a new mailbox command is issued and the timer |
| 6283 | * is deleted when the mailbox complete. The function is called by |
| 6284 | * the kernel timer code when a mailbox does not complete within |
| 6285 | * expected time. This function wakes up the worker thread to |
| 6286 | * process the mailbox timeout and returns. All the processing is |
| 6287 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6288 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6289 | void |
| 6290 | lpfc_mbox_timeout(unsigned long ptr) |
| 6291 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6292 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6293 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6294 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6296 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6297 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6298 | if (!tmo_posted) |
| 6299 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6300 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6301 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6302 | if (!tmo_posted) |
| 6303 | lpfc_worker_wake_up(phba); |
| 6304 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6305 | } |
| 6306 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6307 | |
| 6308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6309 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6310 | * @phba: Pointer to HBA context object. |
| 6311 | * |
| 6312 | * This function is called from worker thread when a mailbox command times out. |
| 6313 | * The caller is not required to hold any locks. This function will reset the |
| 6314 | * HBA and recover all the pending commands. |
| 6315 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6316 | void |
| 6317 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6318 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6319 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6320 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6321 | struct lpfc_sli *psli = &phba->sli; |
| 6322 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6323 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6324 | /* Check the pmbox pointer first. There is a race condition |
| 6325 | * between the mbox timeout handler getting executed in the |
| 6326 | * worklist and the mailbox actually completing. When this |
| 6327 | * race condition occurs, the mbox_active will be NULL. |
| 6328 | */ |
| 6329 | spin_lock_irq(&phba->hbalock); |
| 6330 | if (pmbox == NULL) { |
| 6331 | lpfc_printf_log(phba, KERN_WARNING, |
| 6332 | LOG_MBOX | LOG_SLI, |
| 6333 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6334 | "exiting\n"); |
| 6335 | spin_unlock_irq(&phba->hbalock); |
| 6336 | return; |
| 6337 | } |
| 6338 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6339 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6340 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6341 | "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] | 6342 | mb->mbxCommand, |
| 6343 | phba->pport->port_state, |
| 6344 | phba->sli.sli_flag, |
| 6345 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6346 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6347 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6348 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6349 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6350 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6351 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6352 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6353 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6354 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6355 | spin_lock_irq(&phba->hbalock); |
| 6356 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6357 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6358 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6359 | |
| 6360 | pring = &psli->ring[psli->fcp_ring]; |
| 6361 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6362 | |
| 6363 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6364 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6365 | |
| 6366 | /* Reset the HBA device */ |
| 6367 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6368 | } |
| 6369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6370 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6371 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6372 | * @phba: Pointer to HBA context object. |
| 6373 | * @pmbox: Pointer to mailbox object. |
| 6374 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6375 | * |
| 6376 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6377 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6378 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6379 | * The mailbox command can be submitted in polling mode, in which case |
| 6380 | * this function will wait in a polling loop for the completion of the |
| 6381 | * mailbox. |
| 6382 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6383 | * function will submit the command and returns immediately without waiting |
| 6384 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6385 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6386 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6387 | * mailbox is issued in polling mode and there is already a mailbox |
| 6388 | * pending, then the function will return an error. If the mailbox is issued |
| 6389 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6390 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6391 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6392 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6393 | * return codes the caller owns the mailbox command after the return of |
| 6394 | * the function. |
| 6395 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6396 | static int |
| 6397 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6398 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6399 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6400 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6401 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6402 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6403 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6404 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6405 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6406 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6407 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6408 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6409 | int processing_queue = 0; |
| 6410 | |
| 6411 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6412 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6413 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6414 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6415 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6416 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6417 | return MBX_SUCCESS; |
| 6418 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6419 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6420 | pmbox = lpfc_mbox_get(phba); |
| 6421 | if (!pmbox) { |
| 6422 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6423 | return MBX_SUCCESS; |
| 6424 | } |
| 6425 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6426 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6427 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6428 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6429 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6430 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6431 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6432 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6433 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6434 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6435 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6436 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6437 | } |
| 6438 | } |
| 6439 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6440 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6441 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6442 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6443 | goto out_not_finished; |
| 6444 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6445 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6446 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6447 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6448 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6449 | goto out_not_finished; |
| 6450 | } |
| 6451 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6452 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6453 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6454 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6455 | status = MBX_SUCCESS; |
| 6456 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6457 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6458 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6459 | |
| 6460 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6461 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6462 | "(%d):0311 Mailbox command x%x cannot " |
| 6463 | "issue Data: x%x x%x\n", |
| 6464 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6465 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6466 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6467 | } |
| 6468 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6469 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
| 6470 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6471 | !(hc_copy & HC_MBINT_ENA)) { |
| 6472 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6473 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6474 | "(%d):2528 Mailbox command x%x cannot " |
| 6475 | "issue Data: x%x x%x\n", |
| 6476 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6477 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6478 | goto out_not_finished; |
| 6479 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6480 | } |
| 6481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6482 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6483 | /* Polling for a mbox command when another one is already active |
| 6484 | * is not allowed in SLI. Also, the driver must have established |
| 6485 | * SLI2 mode to queue and process multiple mbox commands. |
| 6486 | */ |
| 6487 | |
| 6488 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6489 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6490 | |
| 6491 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6492 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6493 | "(%d):2529 Mailbox command x%x " |
| 6494 | "cannot issue Data: x%x x%x\n", |
| 6495 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6496 | pmbox->u.mb.mbxCommand, |
| 6497 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6498 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6499 | } |
| 6500 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6501 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6502 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6503 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6504 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6505 | "(%d):2530 Mailbox command x%x " |
| 6506 | "cannot issue Data: x%x x%x\n", |
| 6507 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6508 | pmbox->u.mb.mbxCommand, |
| 6509 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6510 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6511 | } |
| 6512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6513 | /* Another mailbox command is still being processed, queue this |
| 6514 | * command to be processed later. |
| 6515 | */ |
| 6516 | lpfc_mbox_put(phba, pmbox); |
| 6517 | |
| 6518 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6519 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6520 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6521 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6522 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 6523 | mb->mbxCommand, phba->pport->port_state, |
| 6524 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6525 | |
| 6526 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6527 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6528 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6529 | if (pmbox->vport) { |
| 6530 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6531 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6532 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 6533 | (uint32_t)mb->mbxCommand, |
| 6534 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6535 | } |
| 6536 | else { |
| 6537 | lpfc_debugfs_disc_trc(phba->pport, |
| 6538 | LPFC_DISC_TRC_MBOX, |
| 6539 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 6540 | (uint32_t)mb->mbxCommand, |
| 6541 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6542 | } |
| 6543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6544 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6545 | } |
| 6546 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6547 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6548 | |
| 6549 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6550 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6551 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6552 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6553 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6554 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6555 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6556 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6557 | "(%d):2531 Mailbox command x%x " |
| 6558 | "cannot issue Data: x%x x%x\n", |
| 6559 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6560 | pmbox->u.mb.mbxCommand, |
| 6561 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6562 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6563 | } |
| 6564 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6565 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6566 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6570 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6571 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6572 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6573 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6574 | mb->mbxCommand, phba->pport->port_state, |
| 6575 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6576 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6577 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 6578 | if (pmbox->vport) { |
| 6579 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6580 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6581 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 6582 | (uint32_t)mb->mbxCommand, |
| 6583 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6584 | } |
| 6585 | else { |
| 6586 | lpfc_debugfs_disc_trc(phba->pport, |
| 6587 | LPFC_DISC_TRC_MBOX, |
| 6588 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 6589 | (uint32_t)mb->mbxCommand, |
| 6590 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6591 | } |
| 6592 | } |
| 6593 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6594 | psli->slistat.mbox_cmd++; |
| 6595 | evtctr = psli->slistat.mbox_event; |
| 6596 | |
| 6597 | /* next set own bit for the adapter and copy over command word */ |
| 6598 | mb->mbxOwner = OWN_CHIP; |
| 6599 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6600 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6601 | /* Populate mbox extension offset word. */ |
| 6602 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
| 6603 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6604 | = (uint8_t *)phba->mbox_ext |
| 6605 | - (uint8_t *)phba->mbox; |
| 6606 | } |
| 6607 | |
| 6608 | /* Copy the mailbox extension data */ |
| 6609 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6610 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6611 | (uint8_t *)phba->mbox_ext, |
| 6612 | pmbox->in_ext_byte_len); |
| 6613 | } |
| 6614 | /* Copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6615 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6616 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6617 | /* Populate mbox extension offset word. */ |
| 6618 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
| 6619 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6620 | = MAILBOX_HBA_EXT_OFFSET; |
| 6621 | |
| 6622 | /* Copy the mailbox extension data */ |
| 6623 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6624 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6625 | MAILBOX_HBA_EXT_OFFSET, |
| 6626 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6627 | |
| 6628 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6629 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6630 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6631 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6632 | } |
| 6633 | |
| 6634 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6635 | word */ |
| 6636 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 6637 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 6638 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6639 | |
| 6640 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6641 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6642 | to_slim = phba->MBslimaddr; |
| 6643 | writel(ldata, to_slim); |
| 6644 | readl(to_slim); /* flush */ |
| 6645 | |
| 6646 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6647 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6648 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6653 | |
| 6654 | switch (flag) { |
| 6655 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6656 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6657 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6658 | /* Interrupt board to do it */ |
| 6659 | writel(CA_MBATT, phba->CAregaddr); |
| 6660 | readl(phba->CAregaddr); /* flush */ |
| 6661 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6662 | break; |
| 6663 | |
| 6664 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6665 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6666 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6667 | /* Interrupt board to do it */ |
| 6668 | writel(CA_MBATT, phba->CAregaddr); |
| 6669 | readl(phba->CAregaddr); /* flush */ |
| 6670 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6671 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6672 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6673 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6674 | word0 = le32_to_cpu(word0); |
| 6675 | } else { |
| 6676 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6677 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6678 | spin_unlock_irqrestore(&phba->hbalock, |
| 6679 | drvr_flag); |
| 6680 | goto out_not_finished; |
| 6681 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6682 | } |
| 6683 | |
| 6684 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6685 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6686 | spin_unlock_irqrestore(&phba->hbalock, |
| 6687 | drvr_flag); |
| 6688 | goto out_not_finished; |
| 6689 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6690 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6691 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6692 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6693 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6694 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6695 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6696 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6697 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6698 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6699 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6700 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6701 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | /* Check if we took a mbox interrupt while we were |
| 6705 | polling */ |
| 6706 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6707 | && (evtctr != psli->slistat.mbox_event)) |
| 6708 | break; |
| 6709 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6710 | if (i++ > 10) { |
| 6711 | spin_unlock_irqrestore(&phba->hbalock, |
| 6712 | drvr_flag); |
| 6713 | msleep(1); |
| 6714 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6715 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6716 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6717 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6718 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6719 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6720 | word0 = le32_to_cpu(word0); |
| 6721 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6722 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6723 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6724 | /* Check real SLIM for any errors */ |
| 6725 | slimword0 = readl(phba->MBslimaddr); |
| 6726 | slimmb = (MAILBOX_t *) & slimword0; |
| 6727 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6728 | && slimmb->mbxStatus) { |
| 6729 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6730 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6731 | word0 = slimword0; |
| 6732 | } |
| 6733 | } |
| 6734 | } else { |
| 6735 | /* First copy command data */ |
| 6736 | word0 = readl(phba->MBslimaddr); |
| 6737 | } |
| 6738 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6739 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6740 | spin_unlock_irqrestore(&phba->hbalock, |
| 6741 | drvr_flag); |
| 6742 | goto out_not_finished; |
| 6743 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6744 | } |
| 6745 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6746 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6747 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6748 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6749 | /* Copy the mailbox extension data */ |
| 6750 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6751 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 6752 | pmbox->context2, |
| 6753 | pmbox->out_ext_byte_len); |
| 6754 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6755 | } else { |
| 6756 | /* First copy command data */ |
| 6757 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 6758 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6759 | /* Copy the mailbox extension data */ |
| 6760 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6761 | lpfc_memcpy_from_slim(pmbox->context2, |
| 6762 | phba->MBslimaddr + |
| 6763 | MAILBOX_HBA_EXT_OFFSET, |
| 6764 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | writel(HA_MBATT, phba->HAregaddr); |
| 6769 | readl(phba->HAregaddr); /* flush */ |
| 6770 | |
| 6771 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 6772 | status = mb->mbxStatus; |
| 6773 | } |
| 6774 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6775 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6776 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6777 | |
| 6778 | out_not_finished: |
| 6779 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6780 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6781 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 6782 | } |
| 6783 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6784 | } |
| 6785 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6786 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6787 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 6788 | * @phba: Pointer to HBA context object. |
| 6789 | * |
| 6790 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 6791 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 6792 | * possible outstanding mailbox command before return. |
| 6793 | * |
| 6794 | * Returns: |
| 6795 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 6796 | * the outstanding mailbox command timed out. |
| 6797 | **/ |
| 6798 | static int |
| 6799 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 6800 | { |
| 6801 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6802 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6803 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6804 | |
| 6805 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 6806 | spin_lock_irq(&phba->hbalock); |
| 6807 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6808 | /* Determine how long we might wait for the active mailbox |
| 6809 | * command to be gracefully completed by firmware. |
| 6810 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6811 | if (phba->sli.mbox_active) |
| 6812 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 6813 | phba->sli.mbox_active) * |
| 6814 | 1000) + jiffies; |
| 6815 | spin_unlock_irq(&phba->hbalock); |
| 6816 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6817 | /* Wait for the outstnading mailbox command to complete */ |
| 6818 | while (phba->sli.mbox_active) { |
| 6819 | /* Check active mailbox complete status every 2ms */ |
| 6820 | msleep(2); |
| 6821 | if (time_after(jiffies, timeout)) { |
| 6822 | /* Timeout, marked the outstanding cmd not complete */ |
| 6823 | rc = 1; |
| 6824 | break; |
| 6825 | } |
| 6826 | } |
| 6827 | |
| 6828 | /* Can not cleanly block async mailbox command, fails it */ |
| 6829 | if (rc) { |
| 6830 | spin_lock_irq(&phba->hbalock); |
| 6831 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6832 | spin_unlock_irq(&phba->hbalock); |
| 6833 | } |
| 6834 | return rc; |
| 6835 | } |
| 6836 | |
| 6837 | /** |
| 6838 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 6839 | * @phba: Pointer to HBA context object. |
| 6840 | * |
| 6841 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 6842 | * commands from the driver internal pending mailbox queue. It makes sure |
| 6843 | * that there is no outstanding mailbox command before resuming posting |
| 6844 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 6845 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 6846 | * mailbox command posting. |
| 6847 | **/ |
| 6848 | static void |
| 6849 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 6850 | { |
| 6851 | struct lpfc_sli *psli = &phba->sli; |
| 6852 | |
| 6853 | spin_lock_irq(&phba->hbalock); |
| 6854 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6855 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 6856 | spin_unlock_irq(&phba->hbalock); |
| 6857 | return; |
| 6858 | } |
| 6859 | |
| 6860 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 6861 | * successful or timeout, after timing-out the outstanding mailbox |
| 6862 | * command shall always be removed, so just unblock posting async |
| 6863 | * mailbox command and resume |
| 6864 | */ |
| 6865 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6866 | spin_unlock_irq(&phba->hbalock); |
| 6867 | |
| 6868 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 6869 | lpfc_worker_wake_up(phba); |
| 6870 | } |
| 6871 | |
| 6872 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6873 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 6874 | * @phba: Pointer to HBA context object. |
| 6875 | * @mboxq: Pointer to mailbox object. |
| 6876 | * |
| 6877 | * The function posts a mailbox to the port. The mailbox is expected |
| 6878 | * to be comletely filled in and ready for the port to operate on it. |
| 6879 | * This routine executes a synchronous completion operation on the |
| 6880 | * mailbox by polling for its completion. |
| 6881 | * |
| 6882 | * The caller must not be holding any locks when calling this routine. |
| 6883 | * |
| 6884 | * Returns: |
| 6885 | * MBX_SUCCESS - mailbox posted successfully |
| 6886 | * Any of the MBX error values. |
| 6887 | **/ |
| 6888 | static int |
| 6889 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 6890 | { |
| 6891 | int rc = MBX_SUCCESS; |
| 6892 | unsigned long iflag; |
| 6893 | uint32_t db_ready; |
| 6894 | uint32_t mcqe_status; |
| 6895 | uint32_t mbx_cmnd; |
| 6896 | unsigned long timeout; |
| 6897 | struct lpfc_sli *psli = &phba->sli; |
| 6898 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 6899 | struct lpfc_bmbx_create *mbox_rgn; |
| 6900 | struct dma_address *dma_address; |
| 6901 | struct lpfc_register bmbx_reg; |
| 6902 | |
| 6903 | /* |
| 6904 | * Only one mailbox can be active to the bootstrap mailbox region |
| 6905 | * at a time and there is no queueing provided. |
| 6906 | */ |
| 6907 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 6908 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6909 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6910 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6911 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6912 | "cannot issue Data: x%x x%x\n", |
| 6913 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6914 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6915 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 6916 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6917 | psli->sli_flag, MBX_POLL); |
| 6918 | return MBXERR_ERROR; |
| 6919 | } |
| 6920 | /* The server grabs the token and owns it until release */ |
| 6921 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6922 | phba->sli.mbox_active = mboxq; |
| 6923 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 6924 | |
| 6925 | /* |
| 6926 | * Initialize the bootstrap memory region to avoid stale data areas |
| 6927 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 6928 | * the bmbx mailbox region. |
| 6929 | */ |
| 6930 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 6931 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 6932 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 6933 | sizeof(struct lpfc_mqe)); |
| 6934 | |
| 6935 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 6936 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6937 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 6938 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6939 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6940 | * 1000) + jiffies; |
| 6941 | do { |
| 6942 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 6943 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 6944 | if (!db_ready) |
| 6945 | msleep(2); |
| 6946 | |
| 6947 | if (time_after(jiffies, timeout)) { |
| 6948 | rc = MBXERR_ERROR; |
| 6949 | goto exit; |
| 6950 | } |
| 6951 | } while (!db_ready); |
| 6952 | |
| 6953 | /* Post the low mailbox dma address to the port. */ |
| 6954 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6955 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6956 | * 1000) + jiffies; |
| 6957 | do { |
| 6958 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 6959 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 6960 | if (!db_ready) |
| 6961 | msleep(2); |
| 6962 | |
| 6963 | if (time_after(jiffies, timeout)) { |
| 6964 | rc = MBXERR_ERROR; |
| 6965 | goto exit; |
| 6966 | } |
| 6967 | } while (!db_ready); |
| 6968 | |
| 6969 | /* |
| 6970 | * Read the CQ to ensure the mailbox has completed. |
| 6971 | * If so, update the mailbox status so that the upper layers |
| 6972 | * can complete the request normally. |
| 6973 | */ |
| 6974 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 6975 | sizeof(struct lpfc_mqe)); |
| 6976 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 6977 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 6978 | sizeof(struct lpfc_mcqe)); |
| 6979 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6980 | /* |
| 6981 | * When the CQE status indicates a failure and the mailbox status |
| 6982 | * indicates success then copy the CQE status into the mailbox status |
| 6983 | * (and prefix it with x4000). |
| 6984 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6985 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6986 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 6987 | bf_set(lpfc_mqe_status, mb, |
| 6988 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6989 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6990 | } else |
| 6991 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6992 | |
| 6993 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6994 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6995 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 6996 | " x%x x%x CQ: x%x x%x x%x x%x\n", |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6997 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 6998 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 6999 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7000 | bf_get(lpfc_mqe_status, mb), |
| 7001 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7002 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7003 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7004 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7005 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7006 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7007 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7008 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7009 | mboxq->mcqe.trailer); |
| 7010 | exit: |
| 7011 | /* We are holding the token, no needed for lock when release */ |
| 7012 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7013 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7014 | phba->sli.mbox_active = NULL; |
| 7015 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7016 | return rc; |
| 7017 | } |
| 7018 | |
| 7019 | /** |
| 7020 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7021 | * @phba: Pointer to HBA context object. |
| 7022 | * @pmbox: Pointer to mailbox object. |
| 7023 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7024 | * |
| 7025 | * This function is called by discovery code and HBA management code to submit |
| 7026 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7027 | * |
| 7028 | * Return codes the caller owns the mailbox command after the return of the |
| 7029 | * function. |
| 7030 | **/ |
| 7031 | static int |
| 7032 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7033 | uint32_t flag) |
| 7034 | { |
| 7035 | struct lpfc_sli *psli = &phba->sli; |
| 7036 | unsigned long iflags; |
| 7037 | int rc; |
| 7038 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7039 | /* dump from issue mailbox command if setup */ |
| 7040 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7041 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7042 | rc = lpfc_mbox_dev_check(phba); |
| 7043 | if (unlikely(rc)) { |
| 7044 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7045 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7046 | "cannot issue Data: x%x x%x\n", |
| 7047 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7048 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7049 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7050 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7051 | psli->sli_flag, flag); |
| 7052 | goto out_not_finished; |
| 7053 | } |
| 7054 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7055 | /* Detect polling mode and jump to a handler */ |
| 7056 | if (!phba->sli4_hba.intr_enable) { |
| 7057 | if (flag == MBX_POLL) |
| 7058 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7059 | else |
| 7060 | rc = -EIO; |
| 7061 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7062 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | "(%d):2541 Mailbox command x%x " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7064 | "(x%x/x%x) cannot issue Data: " |
| 7065 | "x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7066 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7067 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7068 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7069 | mboxq), |
| 7070 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7071 | mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7072 | psli->sli_flag, flag); |
| 7073 | return rc; |
| 7074 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7075 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7076 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7077 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7078 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7079 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7080 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7081 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7082 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7083 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7084 | /* Try to block the asynchronous mailbox posting */ |
| 7085 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7086 | if (!rc) { |
| 7087 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7088 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7089 | if (rc != MBX_SUCCESS) |
| 7090 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7091 | LOG_MBOX | LOG_SLI, |
| 7092 | "(%d):2597 Mailbox command " |
| 7093 | "x%x (x%x/x%x) cannot issue " |
| 7094 | "Data: x%x x%x\n", |
| 7095 | mboxq->vport ? |
| 7096 | mboxq->vport->vpi : 0, |
| 7097 | mboxq->u.mb.mbxCommand, |
| 7098 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7099 | mboxq), |
| 7100 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7101 | mboxq), |
| 7102 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7103 | /* Unblock the async mailbox posting afterward */ |
| 7104 | lpfc_sli4_async_mbox_unblock(phba); |
| 7105 | } |
| 7106 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7107 | } |
| 7108 | |
| 7109 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7110 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7111 | if (rc) { |
| 7112 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7113 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7114 | "cannot issue Data: x%x x%x\n", |
| 7115 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7116 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7117 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7118 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7119 | psli->sli_flag, flag); |
| 7120 | goto out_not_finished; |
| 7121 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7122 | |
| 7123 | /* Put the mailbox command to the driver internal FIFO */ |
| 7124 | psli->slistat.mbox_busy++; |
| 7125 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7126 | lpfc_mbox_put(phba, mboxq); |
| 7127 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7128 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7129 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7130 | "x%x (x%x/x%x) x%x x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7131 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7132 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7133 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7134 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7135 | phba->pport->port_state, |
| 7136 | psli->sli_flag, MBX_NOWAIT); |
| 7137 | /* Wake up worker thread to transport mailbox command from head */ |
| 7138 | lpfc_worker_wake_up(phba); |
| 7139 | |
| 7140 | return MBX_BUSY; |
| 7141 | |
| 7142 | out_not_finished: |
| 7143 | return MBX_NOT_FINISHED; |
| 7144 | } |
| 7145 | |
| 7146 | /** |
| 7147 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7148 | * @phba: Pointer to HBA context object. |
| 7149 | * |
| 7150 | * This function is called by worker thread to send a mailbox command to |
| 7151 | * SLI4 HBA firmware. |
| 7152 | * |
| 7153 | **/ |
| 7154 | int |
| 7155 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7156 | { |
| 7157 | struct lpfc_sli *psli = &phba->sli; |
| 7158 | LPFC_MBOXQ_t *mboxq; |
| 7159 | int rc = MBX_SUCCESS; |
| 7160 | unsigned long iflags; |
| 7161 | struct lpfc_mqe *mqe; |
| 7162 | uint32_t mbx_cmnd; |
| 7163 | |
| 7164 | /* Check interrupt mode before post async mailbox command */ |
| 7165 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7166 | return MBX_NOT_FINISHED; |
| 7167 | |
| 7168 | /* Check for mailbox command service token */ |
| 7169 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7170 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7171 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7172 | return MBX_NOT_FINISHED; |
| 7173 | } |
| 7174 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7175 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7176 | return MBX_NOT_FINISHED; |
| 7177 | } |
| 7178 | if (unlikely(phba->sli.mbox_active)) { |
| 7179 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7180 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7181 | "0384 There is pending active mailbox cmd\n"); |
| 7182 | return MBX_NOT_FINISHED; |
| 7183 | } |
| 7184 | /* Take the mailbox command service token */ |
| 7185 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7186 | |
| 7187 | /* Get the next mailbox command from head of queue */ |
| 7188 | mboxq = lpfc_mbox_get(phba); |
| 7189 | |
| 7190 | /* If no more mailbox command waiting for post, we're done */ |
| 7191 | if (!mboxq) { |
| 7192 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7193 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7194 | return MBX_SUCCESS; |
| 7195 | } |
| 7196 | phba->sli.mbox_active = mboxq; |
| 7197 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7198 | |
| 7199 | /* Check device readiness for posting mailbox command */ |
| 7200 | rc = lpfc_mbox_dev_check(phba); |
| 7201 | if (unlikely(rc)) |
| 7202 | /* Driver clean routine will clean up pending mailbox */ |
| 7203 | goto out_not_finished; |
| 7204 | |
| 7205 | /* Prepare the mbox command to be posted */ |
| 7206 | mqe = &mboxq->u.mqe; |
| 7207 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7208 | |
| 7209 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7210 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7211 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7212 | |
| 7213 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7214 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7215 | "x%x x%x\n", |
| 7216 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7217 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7218 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7219 | phba->pport->port_state, psli->sli_flag); |
| 7220 | |
| 7221 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7222 | if (mboxq->vport) { |
| 7223 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7224 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7225 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7226 | mbx_cmnd, mqe->un.mb_words[0], |
| 7227 | mqe->un.mb_words[1]); |
| 7228 | } else { |
| 7229 | lpfc_debugfs_disc_trc(phba->pport, |
| 7230 | LPFC_DISC_TRC_MBOX, |
| 7231 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7232 | mbx_cmnd, mqe->un.mb_words[0], |
| 7233 | mqe->un.mb_words[1]); |
| 7234 | } |
| 7235 | } |
| 7236 | psli->slistat.mbox_cmd++; |
| 7237 | |
| 7238 | /* Post the mailbox command to the port */ |
| 7239 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7240 | if (rc != MBX_SUCCESS) { |
| 7241 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7242 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7243 | "cannot issue Data: x%x x%x\n", |
| 7244 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7245 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7246 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7247 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7248 | psli->sli_flag, MBX_NOWAIT); |
| 7249 | goto out_not_finished; |
| 7250 | } |
| 7251 | |
| 7252 | return rc; |
| 7253 | |
| 7254 | out_not_finished: |
| 7255 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7256 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7257 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7258 | /* Release the token */ |
| 7259 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7260 | phba->sli.mbox_active = NULL; |
| 7261 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7262 | |
| 7263 | return MBX_NOT_FINISHED; |
| 7264 | } |
| 7265 | |
| 7266 | /** |
| 7267 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7268 | * @phba: Pointer to HBA context object. |
| 7269 | * @pmbox: Pointer to mailbox object. |
| 7270 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7271 | * |
| 7272 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7273 | * the API jump table function pointer from the lpfc_hba struct. |
| 7274 | * |
| 7275 | * Return codes the caller owns the mailbox command after the return of the |
| 7276 | * function. |
| 7277 | **/ |
| 7278 | int |
| 7279 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7280 | { |
| 7281 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7282 | } |
| 7283 | |
| 7284 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7285 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7286 | * @phba: The hba struct for which this call is being executed. |
| 7287 | * @dev_grp: The HBA PCI-Device group number. |
| 7288 | * |
| 7289 | * This routine sets up the mbox interface API function jump table in @phba |
| 7290 | * struct. |
| 7291 | * Returns: 0 - success, -ENODEV - failure. |
| 7292 | **/ |
| 7293 | int |
| 7294 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7295 | { |
| 7296 | |
| 7297 | switch (dev_grp) { |
| 7298 | case LPFC_PCI_DEV_LP: |
| 7299 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7300 | phba->lpfc_sli_handle_slow_ring_event = |
| 7301 | lpfc_sli_handle_slow_ring_event_s3; |
| 7302 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7303 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7304 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7305 | break; |
| 7306 | case LPFC_PCI_DEV_OC: |
| 7307 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7308 | phba->lpfc_sli_handle_slow_ring_event = |
| 7309 | lpfc_sli_handle_slow_ring_event_s4; |
| 7310 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7311 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7312 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7313 | break; |
| 7314 | default: |
| 7315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7316 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7317 | dev_grp); |
| 7318 | return -ENODEV; |
| 7319 | break; |
| 7320 | } |
| 7321 | return 0; |
| 7322 | } |
| 7323 | |
| 7324 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7325 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7326 | * @phba: Pointer to HBA context object. |
| 7327 | * @pring: Pointer to driver SLI ring object. |
| 7328 | * @piocb: Pointer to address of newly added command iocb. |
| 7329 | * |
| 7330 | * This function is called with hbalock held to add a command |
| 7331 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7332 | * to the ring. |
| 7333 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7334 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7335 | __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] | 7336 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7337 | { |
| 7338 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7339 | list_add_tail(&piocb->list, &pring->txq); |
| 7340 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7341 | } |
| 7342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7344 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7345 | * @phba: Pointer to HBA context object. |
| 7346 | * @pring: Pointer to driver SLI ring object. |
| 7347 | * @piocb: Pointer to address of newly added command iocb. |
| 7348 | * |
| 7349 | * This function is called with hbalock held before a new |
| 7350 | * iocb is submitted to the firmware. This function checks |
| 7351 | * txq to flush the iocbs in txq to Firmware before |
| 7352 | * submitting new iocbs to the Firmware. |
| 7353 | * If there are iocbs in the txq which need to be submitted |
| 7354 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7355 | * of the txq after dequeuing it from txq. |
| 7356 | * If there is no iocb in the txq then the function will return |
| 7357 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7358 | * *piocb to find if there are more commands in the txq. |
| 7359 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7360 | static struct lpfc_iocbq * |
| 7361 | 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] | 7362 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7363 | { |
| 7364 | struct lpfc_iocbq * nextiocb; |
| 7365 | |
| 7366 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7367 | if (!nextiocb) { |
| 7368 | nextiocb = *piocb; |
| 7369 | *piocb = NULL; |
| 7370 | } |
| 7371 | |
| 7372 | return nextiocb; |
| 7373 | } |
| 7374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7375 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7376 | * __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] | 7377 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7378 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7379 | * @piocb: Pointer to command iocb. |
| 7380 | * @flag: Flag indicating if this command can be put into txq. |
| 7381 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7382 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7383 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7384 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7385 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7386 | * this function allows only iocbs for posting buffers. This function finds |
| 7387 | * next available slot in the command ring and posts the command to the |
| 7388 | * available slot and writes the port attention register to request HBA start |
| 7389 | * processing new iocb. If there is no slot available in the ring and |
| 7390 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7391 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7392 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7393 | * This function is called with hbalock held. The function will return success |
| 7394 | * after it successfully submit the iocb to firmware or after adding to the |
| 7395 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7396 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7397 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7398 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7399 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7400 | { |
| 7401 | struct lpfc_iocbq *nextiocb; |
| 7402 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7403 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7404 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7405 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7406 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7407 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7408 | lpfc_printf_log(phba, KERN_ERR, |
| 7409 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7410 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7411 | piocb->iocb.ulpCommand); |
| 7412 | dump_stack(); |
| 7413 | return IOCB_ERROR; |
| 7414 | } |
| 7415 | |
| 7416 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7417 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7418 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7419 | return IOCB_ERROR; |
| 7420 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7421 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7422 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7423 | return IOCB_ERROR; |
| 7424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7425 | /* |
| 7426 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7427 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7428 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7429 | return IOCB_ERROR; |
| 7430 | |
| 7431 | /* |
| 7432 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7433 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7434 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7435 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7436 | goto iocb_busy; |
| 7437 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7438 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7439 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7440 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7441 | * can be issued if the link is not up. |
| 7442 | */ |
| 7443 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7444 | case CMD_GEN_REQUEST64_CR: |
| 7445 | case CMD_GEN_REQUEST64_CX: |
| 7446 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7447 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7448 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7449 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7450 | MENLO_TRANSPORT_TYPE)) |
| 7451 | |
| 7452 | goto iocb_busy; |
| 7453 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7454 | case CMD_QUE_RING_BUF_CN: |
| 7455 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7456 | /* |
| 7457 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7458 | * completion, iocb_cmpl MUST be 0. |
| 7459 | */ |
| 7460 | if (piocb->iocb_cmpl) |
| 7461 | piocb->iocb_cmpl = NULL; |
| 7462 | /*FALLTHROUGH*/ |
| 7463 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7464 | case CMD_CLOSE_XRI_CN: |
| 7465 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7466 | break; |
| 7467 | default: |
| 7468 | goto iocb_busy; |
| 7469 | } |
| 7470 | |
| 7471 | /* |
| 7472 | * For FCP commands, we must be in a state where we can process link |
| 7473 | * attention events. |
| 7474 | */ |
| 7475 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7476 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7477 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7478 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7479 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7480 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7481 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7482 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7483 | |
| 7484 | if (iocb) |
| 7485 | lpfc_sli_update_ring(phba, pring); |
| 7486 | else |
| 7487 | lpfc_sli_update_full_ring(phba, pring); |
| 7488 | |
| 7489 | if (!piocb) |
| 7490 | return IOCB_SUCCESS; |
| 7491 | |
| 7492 | goto out_busy; |
| 7493 | |
| 7494 | iocb_busy: |
| 7495 | pring->stats.iocb_cmd_delay++; |
| 7496 | |
| 7497 | out_busy: |
| 7498 | |
| 7499 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7500 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7501 | return IOCB_SUCCESS; |
| 7502 | } |
| 7503 | |
| 7504 | return IOCB_BUSY; |
| 7505 | } |
| 7506 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7507 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7508 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7509 | * @phba: Pointer to HBA context object. |
| 7510 | * @piocb: Pointer to command iocb. |
| 7511 | * @sglq: Pointer to the scatter gather queue object. |
| 7512 | * |
| 7513 | * This routine converts the bpl or bde that is in the IOCB |
| 7514 | * to a sgl list for the sli4 hardware. The physical address |
| 7515 | * of the bpl/bde is converted back to a virtual address. |
| 7516 | * If the IOCB contains a BPL then the list of BDE's is |
| 7517 | * converted to sli4_sge's. If the IOCB contains a single |
| 7518 | * BDE then it is converted to a single sli_sge. |
| 7519 | * The IOCB is still in cpu endianess so the contents of |
| 7520 | * the bpl can be used without byte swapping. |
| 7521 | * |
| 7522 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7523 | **/ |
| 7524 | static uint16_t |
| 7525 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7526 | struct lpfc_sglq *sglq) |
| 7527 | { |
| 7528 | uint16_t xritag = NO_XRI; |
| 7529 | struct ulp_bde64 *bpl = NULL; |
| 7530 | struct ulp_bde64 bde; |
| 7531 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7532 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7533 | IOCB_t *icmd; |
| 7534 | int numBdes = 0; |
| 7535 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7536 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7537 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7538 | |
| 7539 | if (!piocbq || !sglq) |
| 7540 | return xritag; |
| 7541 | |
| 7542 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7543 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7544 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7545 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7546 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7547 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7548 | sizeof(struct ulp_bde64); |
| 7549 | /* The addrHigh and addrLow fields within the IOCB |
| 7550 | * have not been byteswapped yet so there is no |
| 7551 | * need to swap them back. |
| 7552 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7553 | if (piocbq->context3) |
| 7554 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7555 | else |
| 7556 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7557 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7558 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7559 | if (!bpl) |
| 7560 | return xritag; |
| 7561 | |
| 7562 | for (i = 0; i < numBdes; i++) { |
| 7563 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7564 | sgl->addr_hi = bpl->addrHigh; |
| 7565 | sgl->addr_lo = bpl->addrLow; |
| 7566 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7567 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7568 | if ((i+1) == numBdes) |
| 7569 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7570 | else |
| 7571 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7572 | /* swap the size field back to the cpu so we |
| 7573 | * can assign it to the sgl. |
| 7574 | */ |
| 7575 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7576 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7577 | /* The offsets in the sgl need to be accumulated |
| 7578 | * separately for the request and reply lists. |
| 7579 | * The request is always first, the reply follows. |
| 7580 | */ |
| 7581 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7582 | /* add up the reply sg entries */ |
| 7583 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7584 | inbound++; |
| 7585 | /* first inbound? reset the offset */ |
| 7586 | if (inbound == 1) |
| 7587 | offset = 0; |
| 7588 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7589 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7590 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7591 | offset += bde.tus.f.bdeSize; |
| 7592 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7593 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7594 | bpl++; |
| 7595 | sgl++; |
| 7596 | } |
| 7597 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7598 | /* The addrHigh and addrLow fields of the BDE have not |
| 7599 | * been byteswapped yet so they need to be swapped |
| 7600 | * before putting them in the sgl. |
| 7601 | */ |
| 7602 | sgl->addr_hi = |
| 7603 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7604 | sgl->addr_lo = |
| 7605 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7606 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7607 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7608 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7609 | sgl->sge_len = |
| 7610 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7611 | } |
| 7612 | return sglq->sli4_xritag; |
| 7613 | } |
| 7614 | |
| 7615 | /** |
| 7616 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7617 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7618 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7619 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7620 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7621 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7622 | * |
| 7623 | * Return: index into SLI4 fast-path FCP queue index. |
| 7624 | **/ |
| 7625 | static uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7626 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7627 | { |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7628 | ++phba->fcp_qidx; |
| 7629 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) |
| 7630 | phba->fcp_qidx = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7631 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7632 | return phba->fcp_qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | /** |
| 7636 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7637 | * @phba: Pointer to HBA context object. |
| 7638 | * @piocb: Pointer to command iocb. |
| 7639 | * @wqe: Pointer to the work queue entry. |
| 7640 | * |
| 7641 | * This routine converts the iocb command to its Work Queue Entry |
| 7642 | * equivalent. The wqe pointer should not have any fields set when |
| 7643 | * this routine is called because it will memcpy over them. |
| 7644 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7645 | * wqe. |
| 7646 | * |
| 7647 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7648 | **/ |
| 7649 | static int |
| 7650 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7651 | union lpfc_wqe *wqe) |
| 7652 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7653 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7654 | uint8_t ct = 0; |
| 7655 | uint32_t fip; |
| 7656 | uint32_t abort_tag; |
| 7657 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7658 | uint8_t cmnd; |
| 7659 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7660 | uint16_t abrt_iotag; |
| 7661 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7662 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7663 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7664 | int numBdes, i; |
| 7665 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7666 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7667 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7668 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7669 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7670 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7671 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7672 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7673 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7674 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7675 | command_type = ELS_COMMAND_FIP; |
| 7676 | else |
| 7677 | command_type = ELS_COMMAND_NON_FIP; |
| 7678 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7679 | /* Some of the fields are in the right position already */ |
| 7680 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7681 | abort_tag = (uint32_t) iocbq->iotag; |
| 7682 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7683 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7684 | /* words0-2 bpl convert bde */ |
| 7685 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7686 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7687 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7688 | bpl = (struct ulp_bde64 *) |
| 7689 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7690 | if (!bpl) |
| 7691 | return IOCB_ERROR; |
| 7692 | |
| 7693 | /* Should already be byte swapped. */ |
| 7694 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7695 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7696 | /* swap the size field back to the cpu so we |
| 7697 | * can assign it to the sgl. |
| 7698 | */ |
| 7699 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7700 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7701 | total_len = 0; |
| 7702 | for (i = 0; i < numBdes; i++) { |
| 7703 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7704 | total_len += bde.tus.f.bdeSize; |
| 7705 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7706 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7707 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7708 | |
| 7709 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 7710 | cmnd = iocbq->iocb.ulpCommand; |
| 7711 | |
| 7712 | switch (iocbq->iocb.ulpCommand) { |
| 7713 | case CMD_ELS_REQUEST64_CR: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7714 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7715 | if (!iocbq->iocb.ulpLe) { |
| 7716 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7717 | "2007 Only Limited Edition cmd Format" |
| 7718 | " supported 0x%x\n", |
| 7719 | iocbq->iocb.ulpCommand); |
| 7720 | return IOCB_ERROR; |
| 7721 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7722 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7723 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7724 | /* Els_reguest64 has a TMO */ |
| 7725 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 7726 | iocbq->iocb.ulpTimeout); |
| 7727 | /* Need a VF for word 4 set the vf bit*/ |
| 7728 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 7729 | /* And a VFID for word 12 */ |
| 7730 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7731 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7732 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7733 | iocbq->iocb.ulpContext); |
| 7734 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 7735 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7736 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7737 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7738 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 7739 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7740 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7741 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7742 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7743 | &phba->sli4_hba.sli_intf); |
| 7744 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7745 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 7746 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7747 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 7748 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7749 | *pcmd == ELS_CMD_PLOGI)) { |
| 7750 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7751 | bf_set(els_req64_sid, &wqe->els_req, |
| 7752 | iocbq->vport->fc_myDID); |
| 7753 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7754 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7755 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 7756 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7757 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 7758 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7759 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 7760 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7761 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7762 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 7763 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7764 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 7765 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 7766 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 7767 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 7768 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 7769 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7770 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7771 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7772 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 7773 | iocbq->iocb.un.ulpWord[3]); |
| 7774 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7775 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7776 | /* The entire sequence is transmitted for this IOCB */ |
| 7777 | xmit_len = total_len; |
| 7778 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7779 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 7780 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7781 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7782 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 7783 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7784 | /* word4 relative_offset memcpy */ |
| 7785 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7786 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 7787 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 7788 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 7789 | LPFC_WQE_IOD_WRITE); |
| 7790 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 7791 | LPFC_WQE_LENLOC_WORD12); |
| 7792 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7793 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 7794 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7795 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7796 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7797 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 7798 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7799 | /* word4 iocb=rsvd wqe=rsvd */ |
| 7800 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 7801 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7802 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7803 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7804 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 7805 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7806 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 7807 | LPFC_WQE_LENLOC_WORD3); |
| 7808 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7809 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7810 | case CMD_FCP_IWRITE64_CR: |
| 7811 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7812 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7813 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7814 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7815 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7816 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 7817 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 7818 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 7819 | iocbq->iocb.ulpFCP2Rcvy); |
| 7820 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 7821 | /* Always open the exchange */ |
| 7822 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7823 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7824 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 7825 | LPFC_WQE_LENLOC_WORD4); |
| 7826 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 7827 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 7828 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 7829 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 7830 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 7831 | } |
| 7832 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7833 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7834 | case CMD_FCP_IREAD64_CR: |
| 7835 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7836 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7837 | wqe->fcp_iread.payload_offset_len = |
| 7838 | xmit_len + sizeof(struct fcp_rsp); |
| 7839 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 7840 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 7841 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 7842 | iocbq->iocb.ulpFCP2Rcvy); |
| 7843 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7844 | /* Always open the exchange */ |
| 7845 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7846 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 7847 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 7848 | LPFC_WQE_LENLOC_WORD4); |
| 7849 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 7850 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 7851 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 7852 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 7853 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 7854 | } |
| 7855 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7856 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7857 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7858 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 7859 | wqe->fcp_icmd.rsrvd3 = 0; |
| 7860 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7861 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7862 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 7863 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 7864 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7865 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 7866 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 7867 | LPFC_WQE_LENLOC_NONE); |
| 7868 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7869 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7870 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7871 | /* For this command calculate the xmit length of the |
| 7872 | * request bde. |
| 7873 | */ |
| 7874 | xmit_len = 0; |
| 7875 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7876 | sizeof(struct ulp_bde64); |
| 7877 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7878 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7879 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 7880 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7881 | xmit_len += bde.tus.f.bdeSize; |
| 7882 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7883 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 7884 | wqe->gen_req.request_payload_len = xmit_len; |
| 7885 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 7886 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7887 | /* word6 context tag copied in memcpy */ |
| 7888 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 7889 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 7890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7891 | "2015 Invalid CT %x command 0x%x\n", |
| 7892 | ct, iocbq->iocb.ulpCommand); |
| 7893 | return IOCB_ERROR; |
| 7894 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7895 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 7896 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 7897 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 7898 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 7899 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 7900 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 7901 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 7902 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7903 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7904 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7905 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7906 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7907 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7908 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 7909 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7910 | /* word4 iocb=did wge=rsvd. */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7911 | wqe->xmit_els_rsp.rsvd4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7912 | /* word5 iocb=rsvd wge=did */ |
| 7913 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
| 7914 | iocbq->iocb.un.elsreq64.remoteID); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7915 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 7916 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 7917 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 7918 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7919 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7920 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7921 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7922 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7923 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 7924 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7925 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 7926 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 7927 | LPFC_WQE_LENLOC_WORD3); |
| 7928 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7929 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 7930 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7931 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7932 | iocbq->context2)->virt); |
| 7933 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
| 7934 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7935 | bf_set(els_req64_sid, &wqe->els_req, |
| 7936 | iocbq->vport->fc_myDID); |
| 7937 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7938 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7939 | phba->vpi_ids[phba->pport->vpi]); |
| 7940 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7941 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7942 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7943 | case CMD_CLOSE_XRI_CN: |
| 7944 | case CMD_ABORT_XRI_CN: |
| 7945 | case CMD_ABORT_XRI_CX: |
| 7946 | /* words 0-2 memcpy should be 0 rserved */ |
| 7947 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7948 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 7949 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 7950 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 7951 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 7952 | } else |
| 7953 | fip = 0; |
| 7954 | |
| 7955 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7956 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7957 | * The link is down, or the command was ELS_FIP |
| 7958 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7959 | * on the wire. |
| 7960 | */ |
| 7961 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 7962 | else |
| 7963 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 7964 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7965 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 7966 | wqe->abort_cmd.rsrvd5 = 0; |
| 7967 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7968 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 7969 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7970 | /* |
| 7971 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 7972 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 7973 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7974 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 7975 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 7976 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 7977 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7978 | cmnd = CMD_ABORT_XRI_CX; |
| 7979 | command_type = OTHER_COMMAND; |
| 7980 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7981 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 7982 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7983 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7984 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 7985 | * we re-construct this WQE here based on information in |
| 7986 | * iocbq from scratch. |
| 7987 | */ |
| 7988 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7989 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 7990 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7991 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 7992 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7993 | LPFC_ABTS_UNSOL_INT) { |
| 7994 | /* ABTS sent by initiator to CT exchange, the |
| 7995 | * RX_ID field will be filled with the newly |
| 7996 | * allocated responder XRI. |
| 7997 | */ |
| 7998 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 7999 | iocbq->sli4_xritag); |
| 8000 | } else { |
| 8001 | /* ABTS sent by responder to CT exchange, the |
| 8002 | * RX_ID field will be filled with the responder |
| 8003 | * RX_ID from ABTS. |
| 8004 | */ |
| 8005 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8006 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8007 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8008 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8009 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8010 | |
| 8011 | /* Use CT=VPI */ |
| 8012 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8013 | ndlp->nlp_DID); |
| 8014 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8015 | iocbq->iocb.ulpContext); |
| 8016 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8017 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8018 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8019 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8020 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8021 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8022 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8023 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8024 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8025 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8026 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8027 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8028 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8029 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8030 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8031 | } |
| 8032 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8033 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8034 | case CMD_XRI_ABORTED_CX: |
| 8035 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8036 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8037 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8038 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8039 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8040 | default: |
| 8041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8042 | "2014 Invalid command 0x%x\n", |
| 8043 | iocbq->iocb.ulpCommand); |
| 8044 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8045 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8046 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8047 | |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8048 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8049 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8050 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8051 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8052 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8053 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8054 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8055 | return 0; |
| 8056 | } |
| 8057 | |
| 8058 | /** |
| 8059 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8060 | * @phba: Pointer to HBA context object. |
| 8061 | * @ring_number: SLI ring number to issue iocb on. |
| 8062 | * @piocb: Pointer to command iocb. |
| 8063 | * @flag: Flag indicating if this command can be put into txq. |
| 8064 | * |
| 8065 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8066 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8067 | * |
| 8068 | * This function is called with hbalock held. The function will return success |
| 8069 | * after it successfully submit the iocb to firmware or after adding to the |
| 8070 | * txq. |
| 8071 | **/ |
| 8072 | static int |
| 8073 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8074 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8075 | { |
| 8076 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8077 | union lpfc_wqe wqe; |
| 8078 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8079 | |
| 8080 | if (piocb->sli4_xritag == NO_XRI) { |
| 8081 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8082 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8083 | sglq = NULL; |
| 8084 | else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8085 | if (pring->txq_cnt) { |
| 8086 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8087 | __lpfc_sli_ringtx_put(phba, |
| 8088 | pring, piocb); |
| 8089 | return IOCB_SUCCESS; |
| 8090 | } else { |
| 8091 | return IOCB_BUSY; |
| 8092 | } |
| 8093 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8094 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8095 | if (!sglq) { |
| 8096 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8097 | __lpfc_sli_ringtx_put(phba, |
| 8098 | pring, |
| 8099 | piocb); |
| 8100 | return IOCB_SUCCESS; |
| 8101 | } else |
| 8102 | return IOCB_BUSY; |
| 8103 | } |
| 8104 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8105 | } |
| 8106 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8107 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8108 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8109 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8110 | /* |
| 8111 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8112 | * sglq is on the active list |
| 8113 | */ |
| 8114 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); |
| 8115 | if (!sglq) |
| 8116 | return IOCB_ERROR; |
| 8117 | } |
| 8118 | |
| 8119 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8120 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8121 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8122 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8123 | return IOCB_ERROR; |
| 8124 | } |
| 8125 | |
| 8126 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8127 | return IOCB_ERROR; |
| 8128 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8129 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8130 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8131 | /* |
| 8132 | * For FCP command IOCB, get a new WQ index to distribute |
| 8133 | * WQE across the WQsr. On the other hand, for abort IOCB, |
| 8134 | * it carries the same WQ index to the original command |
| 8135 | * IOCB. |
| 8136 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8137 | if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8138 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8139 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8140 | return IOCB_ERROR; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8141 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8142 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8143 | return IOCB_ERROR; |
| 8144 | } else { |
| 8145 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8146 | return IOCB_ERROR; |
| 8147 | } |
| 8148 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8149 | |
| 8150 | return 0; |
| 8151 | } |
| 8152 | |
| 8153 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8154 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8155 | * |
| 8156 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8157 | * pointer from the lpfc_hba struct. |
| 8158 | * |
| 8159 | * Return codes: |
| 8160 | * IOCB_ERROR - Error |
| 8161 | * IOCB_SUCCESS - Success |
| 8162 | * IOCB_BUSY - Busy |
| 8163 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8164 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8165 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8166 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8167 | { |
| 8168 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8169 | } |
| 8170 | |
| 8171 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8172 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8173 | * @phba: The hba struct for which this call is being executed. |
| 8174 | * @dev_grp: The HBA PCI-Device group number. |
| 8175 | * |
| 8176 | * This routine sets up the SLI interface API function jump table in @phba |
| 8177 | * struct. |
| 8178 | * Returns: 0 - success, -ENODEV - failure. |
| 8179 | **/ |
| 8180 | int |
| 8181 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8182 | { |
| 8183 | |
| 8184 | switch (dev_grp) { |
| 8185 | case LPFC_PCI_DEV_LP: |
| 8186 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8187 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8188 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8189 | case LPFC_PCI_DEV_OC: |
| 8190 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8191 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8192 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8193 | default: |
| 8194 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8195 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8196 | dev_grp); |
| 8197 | return -ENODEV; |
| 8198 | break; |
| 8199 | } |
| 8200 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8201 | return 0; |
| 8202 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8203 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8204 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8205 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8206 | * @phba: Pointer to HBA context object. |
| 8207 | * @pring: Pointer to driver SLI ring object. |
| 8208 | * @piocb: Pointer to command iocb. |
| 8209 | * @flag: Flag indicating if this command can be put into txq. |
| 8210 | * |
| 8211 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8212 | * function. This function gets the hbalock and calls |
| 8213 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8214 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8215 | * functions which do not hold hbalock. |
| 8216 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8217 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8218 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8219 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8220 | { |
| 8221 | unsigned long iflags; |
| 8222 | int rc; |
| 8223 | |
| 8224 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8225 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8226 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8227 | |
| 8228 | return rc; |
| 8229 | } |
| 8230 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8232 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8233 | * @phba: Pointer to HBA context object. |
| 8234 | * |
| 8235 | * This function is called while driver attaches with the |
| 8236 | * HBA to setup the extra ring. The extra ring is used |
| 8237 | * only when driver needs to support target mode functionality |
| 8238 | * or IP over FC functionalities. |
| 8239 | * |
| 8240 | * This function is called with no lock held. |
| 8241 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8242 | static int |
| 8243 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8244 | { |
| 8245 | struct lpfc_sli *psli; |
| 8246 | struct lpfc_sli_ring *pring; |
| 8247 | |
| 8248 | psli = &phba->sli; |
| 8249 | |
| 8250 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8251 | |
| 8252 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8253 | pring = &psli->ring[psli->fcp_ring]; |
| 8254 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8255 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8256 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8257 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8258 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8259 | /* and give them to the extra ring */ |
| 8260 | pring = &psli->ring[psli->extra_ring]; |
| 8261 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8262 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8263 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8264 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8265 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8266 | |
| 8267 | /* Setup default profile for this ring */ |
| 8268 | pring->iotag_max = 4096; |
| 8269 | pring->num_mask = 1; |
| 8270 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8271 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8272 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8273 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8274 | return 0; |
| 8275 | } |
| 8276 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8277 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
| 8278 | * @vport: pointer to virtual port object. |
| 8279 | * @ndlp: nodelist pointer for the impacted rport. |
| 8280 | * |
| 8281 | * The driver calls this routine in response to a XRI ABORT CQE |
| 8282 | * event from the port. In this event, the driver is required to |
| 8283 | * recover its login to the rport even though its login may be valid |
| 8284 | * from the driver's perspective. The failed ABTS notice from the |
| 8285 | * port indicates the rport is not responding. |
| 8286 | */ |
| 8287 | static void |
| 8288 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8289 | struct lpfc_nodelist *ndlp) |
| 8290 | { |
| 8291 | struct Scsi_Host *shost; |
| 8292 | struct lpfc_hba *phba; |
| 8293 | unsigned long flags = 0; |
| 8294 | |
| 8295 | shost = lpfc_shost_from_vport(vport); |
| 8296 | phba = vport->phba; |
| 8297 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8298 | lpfc_printf_log(phba, KERN_INFO, |
| 8299 | LOG_SLI, "3093 No rport recovery needed. " |
| 8300 | "rport in state 0x%x\n", |
| 8301 | ndlp->nlp_state); |
| 8302 | return; |
| 8303 | } |
| 8304 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8305 | "3094 Start rport recovery on shost id 0x%x " |
| 8306 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8307 | "flags 0x%x\n", |
| 8308 | shost->host_no, ndlp->nlp_DID, |
| 8309 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8310 | ndlp->nlp_flag); |
| 8311 | /* |
| 8312 | * The rport is not responding. Don't attempt ADISC recovery. |
| 8313 | * Remove the FCP-2 flag to force a PLOGI. |
| 8314 | */ |
| 8315 | spin_lock_irqsave(shost->host_lock, flags); |
| 8316 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8317 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8318 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8319 | NLP_EVT_DEVICE_RECOVERY); |
| 8320 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 8321 | spin_lock_irqsave(shost->host_lock, flags); |
| 8322 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 8323 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8324 | lpfc_disc_start(vport); |
| 8325 | } |
| 8326 | |
| 8327 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8328 | * @phba: Pointer to HBA context object. |
| 8329 | * @iocbq: Pointer to iocb object. |
| 8330 | * |
| 8331 | * The async_event handler calls this routine when it receives |
| 8332 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8333 | * this event when an Abort Sequence request to an rport fails |
| 8334 | * twice in succession. The abort could be originated by the |
| 8335 | * driver or by the port. The ABTS could have been for an ELS |
| 8336 | * or FCP IO. The port only generates this event when an ABTS |
| 8337 | * fails to complete after one retry. |
| 8338 | */ |
| 8339 | static void |
| 8340 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8341 | struct lpfc_iocbq *iocbq) |
| 8342 | { |
| 8343 | struct lpfc_nodelist *ndlp = NULL; |
| 8344 | uint16_t rpi = 0, vpi = 0; |
| 8345 | struct lpfc_vport *vport = NULL; |
| 8346 | |
| 8347 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8348 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8349 | rpi = iocbq->iocb.ulpContext; |
| 8350 | |
| 8351 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8352 | "3092 Port generated ABTS async event " |
| 8353 | "on vpi %d rpi %d status 0x%x\n", |
| 8354 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8355 | |
| 8356 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8357 | if (!vport) |
| 8358 | goto err_exit; |
| 8359 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8360 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8361 | goto err_exit; |
| 8362 | |
| 8363 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8364 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8365 | return; |
| 8366 | |
| 8367 | err_exit: |
| 8368 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8369 | "3095 Event Context not found, no " |
| 8370 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8371 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8372 | vpi, rpi); |
| 8373 | } |
| 8374 | |
| 8375 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8376 | * @phba: pointer to HBA context object. |
| 8377 | * @ndlp: nodelist pointer for the impacted rport. |
| 8378 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8379 | * |
| 8380 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8381 | * port. The port generates this event when an abort exchange request to an |
| 8382 | * rport fails twice in succession with no reply. The abort could be originated |
| 8383 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8384 | */ |
| 8385 | void |
| 8386 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8387 | struct lpfc_nodelist *ndlp, |
| 8388 | struct sli4_wcqe_xri_aborted *axri) |
| 8389 | { |
| 8390 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame^] | 8391 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8392 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8393 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8394 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8395 | "3115 Node Context not found, driver " |
| 8396 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8397 | return; |
| 8398 | } |
| 8399 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8400 | vport = ndlp->vport; |
| 8401 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8402 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame^] | 8403 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8404 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8405 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame^] | 8406 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8407 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8408 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame^] | 8409 | /* |
| 8410 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8411 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8412 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8413 | */ |
| 8414 | ext_status = axri->parameter & WCQE_PARAM_MASK; |
| 8415 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8416 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8417 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8418 | } |
| 8419 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8420 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8421 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8422 | * @phba: Pointer to HBA context object. |
| 8423 | * @pring: Pointer to driver SLI ring object. |
| 8424 | * @iocbq: Pointer to iocb object. |
| 8425 | * |
| 8426 | * This function is called by the slow ring event handler |
| 8427 | * function when there is an ASYNC event iocb in the ring. |
| 8428 | * This function is called with no lock held. |
| 8429 | * Currently this function handles only temperature related |
| 8430 | * ASYNC events. The function decodes the temperature sensor |
| 8431 | * event message and posts events for the management applications. |
| 8432 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8433 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8434 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8435 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8436 | { |
| 8437 | IOCB_t *icmd; |
| 8438 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8439 | struct temp_event temp_event_data; |
| 8440 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8441 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8442 | |
| 8443 | icmd = &iocbq->iocb; |
| 8444 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8445 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8446 | switch (evt_code) { |
| 8447 | case ASYNC_TEMP_WARN: |
| 8448 | case ASYNC_TEMP_SAFE: |
| 8449 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8450 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8451 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8452 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8453 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8454 | "0347 Adapter is very hot, please take " |
| 8455 | "corrective action. temperature : %d Celsius\n", |
| 8456 | (uint32_t) icmd->ulpContext); |
| 8457 | } else { |
| 8458 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8459 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8460 | "0340 Adapter temperature is OK now. " |
| 8461 | "temperature : %d Celsius\n", |
| 8462 | (uint32_t) icmd->ulpContext); |
| 8463 | } |
| 8464 | |
| 8465 | /* Send temperature change event to applications */ |
| 8466 | shost = lpfc_shost_from_vport(phba->pport); |
| 8467 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8468 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8469 | LPFC_NL_VENDOR_ID); |
| 8470 | break; |
| 8471 | case ASYNC_STATUS_CN: |
| 8472 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8473 | break; |
| 8474 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8475 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8476 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8477 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8478 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8479 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8480 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8481 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8482 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8483 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8484 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8485 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8486 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8487 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8488 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8489 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8490 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8491 | } |
| 8492 | |
| 8493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8494 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8495 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8496 | * @phba: Pointer to HBA context object. |
| 8497 | * |
| 8498 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8499 | * number of iocbs per ring and iotags. This function is |
| 8500 | * called while driver attach to the HBA and before the |
| 8501 | * interrupts are enabled. So there is no need for locking. |
| 8502 | * |
| 8503 | * This function always returns 0. |
| 8504 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8505 | int |
| 8506 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8507 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8508 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8509 | struct lpfc_sli *psli = &phba->sli; |
| 8510 | struct lpfc_sli_ring *pring; |
| 8511 | |
| 8512 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 8513 | psli->sli_flag = 0; |
| 8514 | psli->fcp_ring = LPFC_FCP_RING; |
| 8515 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8516 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8517 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8518 | psli->iocbq_lookup = NULL; |
| 8519 | psli->iocbq_lookup_len = 0; |
| 8520 | psli->last_iotag = 0; |
| 8521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8522 | for (i = 0; i < psli->num_rings; i++) { |
| 8523 | pring = &psli->ring[i]; |
| 8524 | switch (i) { |
| 8525 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8526 | /* numCiocb and numRiocb are used in config_port */ |
| 8527 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8528 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8529 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8530 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8531 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8532 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8533 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8534 | SLI3_IOCB_CMD_SIZE : |
| 8535 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8536 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8537 | SLI3_IOCB_RSP_SIZE : |
| 8538 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8539 | pring->iotag_ctr = 0; |
| 8540 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8541 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8542 | pring->fast_iotag = pring->iotag_max; |
| 8543 | pring->num_mask = 0; |
| 8544 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8545 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8546 | /* numCiocb and numRiocb are used in config_port */ |
| 8547 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8548 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8549 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8550 | SLI3_IOCB_CMD_SIZE : |
| 8551 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8552 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8553 | SLI3_IOCB_RSP_SIZE : |
| 8554 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8555 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8556 | pring->num_mask = 0; |
| 8557 | break; |
| 8558 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8559 | /* numCiocb and numRiocb are used in config_port */ |
| 8560 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8561 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8562 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8563 | SLI3_IOCB_CMD_SIZE : |
| 8564 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8565 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8566 | SLI3_IOCB_RSP_SIZE : |
| 8567 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8568 | pring->fast_iotag = 0; |
| 8569 | pring->iotag_ctr = 0; |
| 8570 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8571 | pring->lpfc_sli_rcv_async_status = |
| 8572 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8573 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8574 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8575 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8576 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8577 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8578 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8579 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8580 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8581 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8582 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8583 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8584 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8585 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8586 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8587 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8588 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8589 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8590 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8591 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8592 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8593 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8594 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8595 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8596 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8597 | lpfc_ct_unsol_event; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8598 | /* abort unsolicited sequence */ |
| 8599 | pring->prt[4].profile = 0; /* Mask 4 */ |
| 8600 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; |
| 8601 | pring->prt[4].type = FC_TYPE_BLS; |
| 8602 | pring->prt[4].lpfc_sli_rcv_unsol_event = |
| 8603 | lpfc_sli4_ct_abort_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8604 | break; |
| 8605 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8606 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8607 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8608 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8609 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8610 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8611 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8612 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8613 | phba->brd_no, totiocbsize, |
| 8614 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8615 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8616 | if (phba->cfg_multi_ring_support == 2) |
| 8617 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8618 | |
| 8619 | return 0; |
| 8620 | } |
| 8621 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8622 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8623 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8624 | * @phba: Pointer to HBA context object. |
| 8625 | * |
| 8626 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8627 | * ring. This function also initializes ring indices of each ring. |
| 8628 | * This function is called during the initialization of the SLI |
| 8629 | * interface of an HBA. |
| 8630 | * This function is called with no lock held and always returns |
| 8631 | * 1. |
| 8632 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8633 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8634 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8635 | { |
| 8636 | struct lpfc_sli *psli; |
| 8637 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8638 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8639 | |
| 8640 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8641 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8642 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8643 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8644 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8645 | for (i = 0; i < psli->num_rings; i++) { |
| 8646 | pring = &psli->ring[i]; |
| 8647 | pring->ringno = i; |
| 8648 | pring->next_cmdidx = 0; |
| 8649 | pring->local_getidx = 0; |
| 8650 | pring->cmdidx = 0; |
| 8651 | INIT_LIST_HEAD(&pring->txq); |
| 8652 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8653 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8654 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8655 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8656 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8657 | spin_unlock_irq(&phba->hbalock); |
| 8658 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8659 | } |
| 8660 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8661 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8662 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8663 | * @phba: Pointer to HBA context object. |
| 8664 | * |
| 8665 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8666 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8667 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8668 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8669 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8670 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8671 | * pending mailbox command queue from the various clients must be stopped; |
| 8672 | * either the HBA is in a state that it will never works on the outstanding |
| 8673 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8674 | * mailbox command has been completed. |
| 8675 | **/ |
| 8676 | static void |
| 8677 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8678 | { |
| 8679 | LIST_HEAD(completions); |
| 8680 | struct lpfc_sli *psli = &phba->sli; |
| 8681 | LPFC_MBOXQ_t *pmb; |
| 8682 | unsigned long iflag; |
| 8683 | |
| 8684 | /* Flush all the mailbox commands in the mbox system */ |
| 8685 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8686 | /* The pending mailbox command queue */ |
| 8687 | list_splice_init(&phba->sli.mboxq, &completions); |
| 8688 | /* The outstanding active mailbox command */ |
| 8689 | if (psli->mbox_active) { |
| 8690 | list_add_tail(&psli->mbox_active->list, &completions); |
| 8691 | psli->mbox_active = NULL; |
| 8692 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8693 | } |
| 8694 | /* The completed mailbox command queue */ |
| 8695 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 8696 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8697 | |
| 8698 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 8699 | while (!list_empty(&completions)) { |
| 8700 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 8701 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8702 | if (pmb->mbox_cmpl) |
| 8703 | pmb->mbox_cmpl(phba, pmb); |
| 8704 | } |
| 8705 | } |
| 8706 | |
| 8707 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8708 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8709 | * @vport: Pointer to virtual port object. |
| 8710 | * |
| 8711 | * lpfc_sli_host_down is called to clean up the resources |
| 8712 | * associated with a vport before destroying virtual |
| 8713 | * port data structures. |
| 8714 | * This function does following operations: |
| 8715 | * - Free discovery resources associated with this virtual |
| 8716 | * port. |
| 8717 | * - Free iocbs associated with this virtual port in |
| 8718 | * the txq. |
| 8719 | * - Send abort for all iocb commands associated with this |
| 8720 | * vport in txcmplq. |
| 8721 | * |
| 8722 | * This function is called with no lock held and always returns 1. |
| 8723 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8724 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8725 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 8726 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8727 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8728 | struct lpfc_hba *phba = vport->phba; |
| 8729 | struct lpfc_sli *psli = &phba->sli; |
| 8730 | struct lpfc_sli_ring *pring; |
| 8731 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8732 | int i; |
| 8733 | unsigned long flags = 0; |
| 8734 | uint16_t prev_pring_flag; |
| 8735 | |
| 8736 | lpfc_cleanup_discovery_resources(vport); |
| 8737 | |
| 8738 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8739 | for (i = 0; i < psli->num_rings; i++) { |
| 8740 | pring = &psli->ring[i]; |
| 8741 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8742 | /* Only slow rings */ |
| 8743 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8744 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8745 | /* Set the lpfc data pending flag */ |
| 8746 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8747 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8748 | /* |
| 8749 | * Error everything on the txq since these iocbs have not been |
| 8750 | * given to the FW yet. |
| 8751 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8752 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 8753 | if (iocb->vport != vport) |
| 8754 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8755 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8756 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8757 | } |
| 8758 | |
| 8759 | /* Next issue ABTS for everything on the txcmplq */ |
| 8760 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 8761 | list) { |
| 8762 | if (iocb->vport != vport) |
| 8763 | continue; |
| 8764 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 8765 | } |
| 8766 | |
| 8767 | pring->flag = prev_pring_flag; |
| 8768 | } |
| 8769 | |
| 8770 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 8771 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8772 | /* Cancel all the IOCBs from the completions list */ |
| 8773 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8774 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8775 | return 1; |
| 8776 | } |
| 8777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8779 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8780 | * @phba: Pointer to HBA context object. |
| 8781 | * |
| 8782 | * This function cleans up all iocb, buffers, mailbox commands |
| 8783 | * while shutting down the HBA. This function is called with no |
| 8784 | * lock held and always returns 1. |
| 8785 | * This function does the following to cleanup driver resources: |
| 8786 | * - Free discovery resources for each virtual port |
| 8787 | * - Cleanup any pending fabric iocbs |
| 8788 | * - Iterate through the iocb txq and free each entry |
| 8789 | * in the list. |
| 8790 | * - Free up any buffer posted to the HBA |
| 8791 | * - Free mailbox commands in the mailbox queue. |
| 8792 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8793 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8794 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8795 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8796 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8797 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8798 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 8799 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8800 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8801 | int i; |
| 8802 | |
| 8803 | /* Shutdown the mailbox command sub-system */ |
| 8804 | lpfc_sli_mbox_sys_shutdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8805 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8806 | lpfc_hba_down_prep(phba); |
| 8807 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8808 | lpfc_fabric_abort_hba(phba); |
| 8809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8810 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8811 | for (i = 0; i < psli->num_rings; i++) { |
| 8812 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8813 | /* Only slow rings */ |
| 8814 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8815 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8816 | /* Set the lpfc data pending flag */ |
| 8817 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8818 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8819 | |
| 8820 | /* |
| 8821 | * Error everything on the txq since these iocbs have not been |
| 8822 | * given to the FW yet. |
| 8823 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8824 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8825 | pring->txq_cnt = 0; |
| 8826 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8827 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8828 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8829 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8830 | /* Cancel all the IOCBs from the completions list */ |
| 8831 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8832 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8833 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 8834 | spin_lock_irqsave(&phba->hbalock, flags); |
| 8835 | list_splice_init(&phba->elsbuf, &completions); |
| 8836 | phba->elsbuf_cnt = 0; |
| 8837 | phba->elsbuf_prev_cnt = 0; |
| 8838 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 8839 | |
| 8840 | while (!list_empty(&completions)) { |
| 8841 | list_remove_head(&completions, buf_ptr, |
| 8842 | struct lpfc_dmabuf, list); |
| 8843 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 8844 | kfree(buf_ptr); |
| 8845 | } |
| 8846 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8847 | /* Return any active mbox cmds */ |
| 8848 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8849 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8850 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8851 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8852 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8853 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8854 | return 1; |
| 8855 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8856 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8858 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8859 | * @srcp: Source memory pointer. |
| 8860 | * @destp: Destination memory pointer. |
| 8861 | * @cnt: Number of words required to be copied. |
| 8862 | * |
| 8863 | * This function is used for copying data between driver memory |
| 8864 | * and the SLI memory. This function also changes the endianness |
| 8865 | * of each word if native endianness is different from SLI |
| 8866 | * endianness. This function can be called with or without |
| 8867 | * lock. |
| 8868 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8869 | void |
| 8870 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 8871 | { |
| 8872 | uint32_t *src = srcp; |
| 8873 | uint32_t *dest = destp; |
| 8874 | uint32_t ldata; |
| 8875 | int i; |
| 8876 | |
| 8877 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 8878 | ldata = *src; |
| 8879 | ldata = le32_to_cpu(ldata); |
| 8880 | *dest = ldata; |
| 8881 | src++; |
| 8882 | dest++; |
| 8883 | } |
| 8884 | } |
| 8885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8886 | |
| 8887 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 8888 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 8889 | * @srcp: Source memory pointer. |
| 8890 | * @destp: Destination memory pointer. |
| 8891 | * @cnt: Number of words required to be copied. |
| 8892 | * |
| 8893 | * This function is used for copying data between a data structure |
| 8894 | * with big endian representation to local endianness. |
| 8895 | * This function can be called with or without lock. |
| 8896 | **/ |
| 8897 | void |
| 8898 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 8899 | { |
| 8900 | uint32_t *src = srcp; |
| 8901 | uint32_t *dest = destp; |
| 8902 | uint32_t ldata; |
| 8903 | int i; |
| 8904 | |
| 8905 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 8906 | ldata = *src; |
| 8907 | ldata = be32_to_cpu(ldata); |
| 8908 | *dest = ldata; |
| 8909 | src++; |
| 8910 | dest++; |
| 8911 | } |
| 8912 | } |
| 8913 | |
| 8914 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8915 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8916 | * @phba: Pointer to HBA context object. |
| 8917 | * @pring: Pointer to driver SLI ring object. |
| 8918 | * @mp: Pointer to driver buffer object. |
| 8919 | * |
| 8920 | * This function is called with no lock held. |
| 8921 | * It always return zero after adding the buffer to the postbufq |
| 8922 | * buffer list. |
| 8923 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8924 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8925 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 8926 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8927 | { |
| 8928 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 8929 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8930 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8931 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8932 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8933 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8934 | return 0; |
| 8935 | } |
| 8936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8938 | * 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] | 8939 | * @phba: Pointer to HBA context object. |
| 8940 | * |
| 8941 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 8942 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 8943 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 8944 | * does not conflict with tags of buffer posted for unsolicited events. |
| 8945 | * The function returns the allocated tag. The function is called with |
| 8946 | * no locks held. |
| 8947 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8948 | uint32_t |
| 8949 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 8950 | { |
| 8951 | spin_lock_irq(&phba->hbalock); |
| 8952 | phba->buffer_tag_count++; |
| 8953 | /* |
| 8954 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 8955 | * a tag assigned by HBQ. |
| 8956 | */ |
| 8957 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 8958 | spin_unlock_irq(&phba->hbalock); |
| 8959 | return phba->buffer_tag_count; |
| 8960 | } |
| 8961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8962 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8963 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8964 | * @phba: Pointer to HBA context object. |
| 8965 | * @pring: Pointer to driver SLI ring object. |
| 8966 | * @tag: Buffer tag. |
| 8967 | * |
| 8968 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 8969 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 8970 | * iocb is posted to the response ring with the tag of the buffer. |
| 8971 | * This function searches the pring->postbufq list using the tag |
| 8972 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 8973 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 8974 | * buffer is returned to the caller else NULL is returned. |
| 8975 | * This function is called with no lock held. |
| 8976 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8977 | struct lpfc_dmabuf * |
| 8978 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 8979 | uint32_t tag) |
| 8980 | { |
| 8981 | struct lpfc_dmabuf *mp, *next_mp; |
| 8982 | struct list_head *slp = &pring->postbufq; |
| 8983 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8984 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8985 | spin_lock_irq(&phba->hbalock); |
| 8986 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 8987 | if (mp->buffer_tag == tag) { |
| 8988 | list_del_init(&mp->list); |
| 8989 | pring->postbufq_cnt--; |
| 8990 | spin_unlock_irq(&phba->hbalock); |
| 8991 | return mp; |
| 8992 | } |
| 8993 | } |
| 8994 | |
| 8995 | spin_unlock_irq(&phba->hbalock); |
| 8996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 8997 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8998 | "ring %d Data x%lx x%p x%p x%x\n", |
| 8999 | pring->ringno, (unsigned long) tag, |
| 9000 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9001 | |
| 9002 | return NULL; |
| 9003 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9006 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9007 | * @phba: Pointer to HBA context object. |
| 9008 | * @pring: Pointer to driver SLI ring object. |
| 9009 | * @phys: DMA address of the buffer. |
| 9010 | * |
| 9011 | * This function searches the buffer list using the dma_address |
| 9012 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9013 | * corresponding to the dma_address. The function returns the |
| 9014 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9015 | * This function is called by the ct and els unsolicited event |
| 9016 | * handlers to get the buffer associated with the unsolicited |
| 9017 | * event. |
| 9018 | * |
| 9019 | * This function is called with no lock held. |
| 9020 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9021 | struct lpfc_dmabuf * |
| 9022 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9023 | dma_addr_t phys) |
| 9024 | { |
| 9025 | struct lpfc_dmabuf *mp, *next_mp; |
| 9026 | struct list_head *slp = &pring->postbufq; |
| 9027 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9028 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9029 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9030 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9031 | if (mp->phys == phys) { |
| 9032 | list_del_init(&mp->list); |
| 9033 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9034 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9035 | return mp; |
| 9036 | } |
| 9037 | } |
| 9038 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9039 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9040 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9041 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9042 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9043 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9044 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9045 | return NULL; |
| 9046 | } |
| 9047 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9048 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9049 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9050 | * @phba: Pointer to HBA context object. |
| 9051 | * @cmdiocb: Pointer to driver command iocb object. |
| 9052 | * @rspiocb: Pointer to driver response iocb object. |
| 9053 | * |
| 9054 | * This function is the completion handler for the abort iocbs for |
| 9055 | * ELS commands. This function is called from the ELS ring event |
| 9056 | * handler with no lock held. This function frees memory resources |
| 9057 | * associated with the abort iocb. |
| 9058 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9059 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9060 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9061 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9062 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9063 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9064 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9065 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9066 | |
| 9067 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9068 | |
| 9069 | /* |
| 9070 | * Assume that the port already completed and returned, or |
| 9071 | * will return the iocb. Just Log the message. |
| 9072 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9073 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9074 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9076 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9077 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9078 | if (abort_iotag != 0 && |
| 9079 | abort_iotag <= phba->sli.last_iotag) |
| 9080 | abort_iocb = |
| 9081 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9082 | } else |
| 9083 | /* For sli4 the abort_tag is the XRI, |
| 9084 | * so the abort routine puts the iotag of the iocb |
| 9085 | * being aborted in the context field of the abort |
| 9086 | * IOCB. |
| 9087 | */ |
| 9088 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9089 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9090 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9091 | "0327 Cannot abort els iocb %p " |
| 9092 | "with tag %x context %x, abort status %x, " |
| 9093 | "abort code %x\n", |
| 9094 | abort_iocb, abort_iotag, abort_context, |
| 9095 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9096 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9097 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9098 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9099 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9100 | return; |
| 9101 | } |
| 9102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9104 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9105 | * @phba: Pointer to HBA context object. |
| 9106 | * @cmdiocb: Pointer to driver command iocb object. |
| 9107 | * @rspiocb: Pointer to driver response iocb object. |
| 9108 | * |
| 9109 | * The function is called from SLI ring event handler with no |
| 9110 | * lock held. This function is the completion handler for ELS commands |
| 9111 | * which are aborted. The function frees memory resources used for |
| 9112 | * the aborted ELS commands. |
| 9113 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9114 | static void |
| 9115 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9116 | struct lpfc_iocbq *rspiocb) |
| 9117 | { |
| 9118 | IOCB_t *irsp = &rspiocb->iocb; |
| 9119 | |
| 9120 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9121 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9122 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9123 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9124 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9125 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9126 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9127 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9128 | else |
| 9129 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9130 | return; |
| 9131 | } |
| 9132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9133 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9134 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9135 | * @phba: Pointer to HBA context object. |
| 9136 | * @pring: Pointer to driver SLI ring object. |
| 9137 | * @cmdiocb: Pointer to driver command iocb object. |
| 9138 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9139 | * This function issues an abort iocb for the provided command iocb down to |
| 9140 | * the port. Other than the case the outstanding command iocb is an abort |
| 9141 | * request, this function issues abort out unconditionally. This function is |
| 9142 | * called with hbalock held. The function returns 0 when it fails due to |
| 9143 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9144 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9145 | static int |
| 9146 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9147 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9149 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9150 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9151 | IOCB_t *icmd = NULL; |
| 9152 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9153 | int retval; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9154 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9155 | /* |
| 9156 | * There are certain command types we don't want to abort. And we |
| 9157 | * don't want to abort commands that are already in the process of |
| 9158 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9159 | */ |
| 9160 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9161 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9162 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9163 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9164 | return 0; |
| 9165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9166 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9167 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9168 | if (abtsiocbp == NULL) |
| 9169 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9170 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9171 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9172 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9173 | */ |
| 9174 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9176 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9177 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9178 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9179 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9180 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9181 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9182 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9183 | else |
| 9184 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9185 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9186 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9187 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9188 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9189 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9190 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9191 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9192 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9193 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9194 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9195 | else |
| 9196 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9197 | |
| 9198 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9199 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9200 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9201 | "0339 Abort xri x%x, original iotag x%x, " |
| 9202 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9203 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9204 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9205 | abtsiocbp->iotag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9206 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9207 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9208 | if (retval) |
| 9209 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9210 | |
| 9211 | /* |
| 9212 | * Caller to this routine should check for IOCB_ERROR |
| 9213 | * and handle it properly. This routine no longer removes |
| 9214 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9215 | */ |
| 9216 | return retval; |
| 9217 | } |
| 9218 | |
| 9219 | /** |
| 9220 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9221 | * @phba: Pointer to HBA context object. |
| 9222 | * @pring: Pointer to driver SLI ring object. |
| 9223 | * @cmdiocb: Pointer to driver command iocb object. |
| 9224 | * |
| 9225 | * This function issues an abort iocb for the provided command iocb. In case |
| 9226 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9227 | * ring. Instead, the callback function shall be changed to those commands |
| 9228 | * so that nothing happens when them finishes. This function is called with |
| 9229 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9230 | * request. |
| 9231 | **/ |
| 9232 | int |
| 9233 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9234 | struct lpfc_iocbq *cmdiocb) |
| 9235 | { |
| 9236 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9237 | int retval = IOCB_ERROR; |
| 9238 | IOCB_t *icmd = NULL; |
| 9239 | |
| 9240 | /* |
| 9241 | * There are certain command types we don't want to abort. And we |
| 9242 | * don't want to abort commands that are already in the process of |
| 9243 | * being aborted. |
| 9244 | */ |
| 9245 | icmd = &cmdiocb->iocb; |
| 9246 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9247 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9248 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9249 | return 0; |
| 9250 | |
| 9251 | /* |
| 9252 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9253 | * the callback so that nothing happens when it finishes. |
| 9254 | */ |
| 9255 | if ((vport->load_flag & FC_UNLOADING) && |
| 9256 | (pring->ringno == LPFC_ELS_RING)) { |
| 9257 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9258 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9259 | else |
| 9260 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9261 | goto abort_iotag_exit; |
| 9262 | } |
| 9263 | |
| 9264 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9265 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9266 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9267 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9268 | /* |
| 9269 | * Caller to this routine should check for IOCB_ERROR |
| 9270 | * and handle it properly. This routine no longer removes |
| 9271 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9272 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9273 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9274 | } |
| 9275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9276 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9277 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9278 | * @phba: Pointer to HBA context object. |
| 9279 | * @pring: Pointer to driver SLI ring object. |
| 9280 | * |
| 9281 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9282 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9283 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9284 | * to complete before the return of this function. The caller is not required |
| 9285 | * to hold any locks. |
| 9286 | **/ |
| 9287 | static void |
| 9288 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9289 | { |
| 9290 | LIST_HEAD(completions); |
| 9291 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9292 | |
| 9293 | if (pring->ringno == LPFC_ELS_RING) |
| 9294 | lpfc_fabric_abort_hba(phba); |
| 9295 | |
| 9296 | spin_lock_irq(&phba->hbalock); |
| 9297 | |
| 9298 | /* Take off all the iocbs on txq for cancelling */ |
| 9299 | list_splice_init(&pring->txq, &completions); |
| 9300 | pring->txq_cnt = 0; |
| 9301 | |
| 9302 | /* Next issue ABTS for everything on the txcmplq */ |
| 9303 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9304 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9305 | |
| 9306 | spin_unlock_irq(&phba->hbalock); |
| 9307 | |
| 9308 | /* Cancel all the IOCBs from the completions list */ |
| 9309 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9310 | IOERR_SLI_ABORTED); |
| 9311 | } |
| 9312 | |
| 9313 | /** |
| 9314 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9315 | * @phba: pointer to lpfc HBA data structure. |
| 9316 | * |
| 9317 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9318 | **/ |
| 9319 | void |
| 9320 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9321 | { |
| 9322 | struct lpfc_sli *psli = &phba->sli; |
| 9323 | struct lpfc_sli_ring *pring; |
| 9324 | int i; |
| 9325 | |
| 9326 | for (i = 0; i < psli->num_rings; i++) { |
| 9327 | pring = &psli->ring[i]; |
| 9328 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9329 | } |
| 9330 | } |
| 9331 | |
| 9332 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9333 | * 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] | 9334 | * @iocbq: Pointer to driver iocb object. |
| 9335 | * @vport: Pointer to driver virtual port object. |
| 9336 | * @tgt_id: SCSI ID of the target. |
| 9337 | * @lun_id: LUN ID of the scsi device. |
| 9338 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9339 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9340 | * 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] | 9341 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9342 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9343 | * 1 if the filtering criteria is not met. |
| 9344 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9345 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9346 | * lun_id parameter. |
| 9347 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9348 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9349 | * parameters. |
| 9350 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9351 | * given iocb is for the SCSI host associated with the given vport. |
| 9352 | * This function is called with no locks held. |
| 9353 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9354 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9355 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9356 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9357 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9358 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9359 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9360 | int rc = 1; |
| 9361 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9362 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9363 | return rc; |
| 9364 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9365 | if (iocbq->vport != vport) |
| 9366 | return rc; |
| 9367 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9368 | 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] | 9369 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9370 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9371 | return rc; |
| 9372 | |
| 9373 | switch (ctx_cmd) { |
| 9374 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9375 | if ((lpfc_cmd->rdata->pnode) && |
| 9376 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9377 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9378 | rc = 0; |
| 9379 | break; |
| 9380 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9381 | if ((lpfc_cmd->rdata->pnode) && |
| 9382 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9383 | rc = 0; |
| 9384 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9385 | case LPFC_CTX_HOST: |
| 9386 | rc = 0; |
| 9387 | break; |
| 9388 | default: |
| 9389 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9390 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9391 | break; |
| 9392 | } |
| 9393 | |
| 9394 | return rc; |
| 9395 | } |
| 9396 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9398 | * 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] | 9399 | * @vport: Pointer to virtual port. |
| 9400 | * @tgt_id: SCSI ID of the target. |
| 9401 | * @lun_id: LUN ID of the scsi device. |
| 9402 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9403 | * |
| 9404 | * This function returns number of FCP commands pending for the vport. |
| 9405 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9406 | * commands pending on the vport associated with SCSI device specified |
| 9407 | * by tgt_id and lun_id parameters. |
| 9408 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9409 | * commands pending on the vport associated with SCSI target specified |
| 9410 | * by tgt_id parameter. |
| 9411 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9412 | * commands pending on the vport. |
| 9413 | * This function returns the number of iocbs which satisfy the filter. |
| 9414 | * This function is called without any lock held. |
| 9415 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9416 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9417 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9418 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9419 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9420 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9421 | struct lpfc_iocbq *iocbq; |
| 9422 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9423 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9424 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9425 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9426 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9427 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9428 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9429 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9430 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9432 | return sum; |
| 9433 | } |
| 9434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9436 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9437 | * @phba: Pointer to HBA context object |
| 9438 | * @cmdiocb: Pointer to command iocb object. |
| 9439 | * @rspiocb: Pointer to response iocb object. |
| 9440 | * |
| 9441 | * This function is called when an aborted FCP iocb completes. This |
| 9442 | * function is called by the ring event handler with no lock held. |
| 9443 | * This function frees the iocb. |
| 9444 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9445 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9446 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9447 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9448 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9449 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9450 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9451 | "original iotag x%x, abort cmd iotag x%x " |
| 9452 | "status 0x%x, reason 0x%x\n", |
| 9453 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9454 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9455 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9456 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9457 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9458 | return; |
| 9459 | } |
| 9460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9461 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9462 | * 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] | 9463 | * @vport: Pointer to virtual port. |
| 9464 | * @pring: Pointer to driver SLI ring object. |
| 9465 | * @tgt_id: SCSI ID of the target. |
| 9466 | * @lun_id: LUN ID of the scsi device. |
| 9467 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9468 | * |
| 9469 | * This function sends an abort command for every SCSI command |
| 9470 | * associated with the given virtual port pending on the ring |
| 9471 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9472 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9473 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9474 | * parameters |
| 9475 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9476 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9477 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9478 | * FCP iocbs associated with virtual port. |
| 9479 | * This function returns number of iocbs it failed to abort. |
| 9480 | * This function is called with no locks held. |
| 9481 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9482 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9483 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9484 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9485 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9486 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9487 | struct lpfc_iocbq *iocbq; |
| 9488 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9489 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9490 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9491 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9492 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9493 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9494 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9495 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9496 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9497 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9498 | continue; |
| 9499 | |
| 9500 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9501 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9502 | if (abtsiocb == NULL) { |
| 9503 | errcnt++; |
| 9504 | continue; |
| 9505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9506 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9507 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9508 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9509 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9510 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9511 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9512 | else |
| 9513 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9514 | abtsiocb->iocb.ulpLe = 1; |
| 9515 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9516 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9517 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9518 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9519 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9520 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9521 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9522 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9523 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9524 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9525 | else |
| 9526 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9527 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9528 | /* Setup callback routine and issue the command. */ |
| 9529 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9530 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9531 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9532 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9533 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9534 | errcnt++; |
| 9535 | continue; |
| 9536 | } |
| 9537 | } |
| 9538 | |
| 9539 | return errcnt; |
| 9540 | } |
| 9541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9543 | * 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] | 9544 | * @phba: Pointer to HBA context object. |
| 9545 | * @cmdiocbq: Pointer to command iocb. |
| 9546 | * @rspiocbq: Pointer to response iocb. |
| 9547 | * |
| 9548 | * This function is the completion handler for iocbs issued using |
| 9549 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9550 | * ring event handler function without any lock held. This function |
| 9551 | * can be called from both worker thread context and interrupt |
| 9552 | * context. This function also can be called from other thread which |
| 9553 | * cleans up the SLI layer objects. |
| 9554 | * This function copy the contents of the response iocb to the |
| 9555 | * response iocb memory object provided by the caller of |
| 9556 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9557 | * sleeps for the iocb completion. |
| 9558 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9559 | static void |
| 9560 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9561 | struct lpfc_iocbq *cmdiocbq, |
| 9562 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9563 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9564 | wait_queue_head_t *pdone_q; |
| 9565 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9566 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9567 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9568 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9569 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9570 | if (cmdiocbq->context2 && rspiocbq) |
| 9571 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9572 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9573 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9574 | /* Set the exchange busy flag for task management commands */ |
| 9575 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9576 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9577 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9578 | cur_iocbq); |
| 9579 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9580 | } |
| 9581 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9582 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9583 | if (pdone_q) |
| 9584 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9585 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9586 | return; |
| 9587 | } |
| 9588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9589 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9590 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9591 | * @phba: Pointer to HBA context object.. |
| 9592 | * @piocbq: Pointer to command iocb. |
| 9593 | * @flag: Flag to test. |
| 9594 | * |
| 9595 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9596 | * see if the passed in flag is set. |
| 9597 | * Returns: |
| 9598 | * 1 if flag is set. |
| 9599 | * 0 if flag is not set. |
| 9600 | **/ |
| 9601 | static int |
| 9602 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9603 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9604 | { |
| 9605 | unsigned long iflags; |
| 9606 | int ret; |
| 9607 | |
| 9608 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9609 | ret = piocbq->iocb_flag & flag; |
| 9610 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9611 | return ret; |
| 9612 | |
| 9613 | } |
| 9614 | |
| 9615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9616 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9617 | * @phba: Pointer to HBA context object.. |
| 9618 | * @pring: Pointer to sli ring. |
| 9619 | * @piocb: Pointer to command iocb. |
| 9620 | * @prspiocbq: Pointer to response iocb. |
| 9621 | * @timeout: Timeout in number of seconds. |
| 9622 | * |
| 9623 | * This function issues the iocb to firmware and waits for the |
| 9624 | * iocb to complete. If the iocb command is not |
| 9625 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9626 | * Caller should not free the iocb resources if this function |
| 9627 | * returns IOCB_TIMEDOUT. |
| 9628 | * The function waits for the iocb completion using an |
| 9629 | * non-interruptible wait. |
| 9630 | * This function will sleep while waiting for iocb completion. |
| 9631 | * So, this function should not be called from any context which |
| 9632 | * does not allow sleeping. Due to the same reason, this function |
| 9633 | * cannot be called with interrupt disabled. |
| 9634 | * This function assumes that the iocb completions occur while |
| 9635 | * this function sleep. So, this function cannot be called from |
| 9636 | * the thread which process iocb completion for this ring. |
| 9637 | * This function clears the iocb_flag of the iocb object before |
| 9638 | * issuing the iocb and the iocb completion handler sets this |
| 9639 | * flag and wakes this thread when the iocb completes. |
| 9640 | * The contents of the response iocb will be copied to prspiocbq |
| 9641 | * by the completion handler when the command completes. |
| 9642 | * This function returns IOCB_SUCCESS when success. |
| 9643 | * This function is called with no lock held. |
| 9644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9645 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9646 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9647 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9648 | struct lpfc_iocbq *piocb, |
| 9649 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9650 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9651 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9652 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9653 | long timeleft, timeout_req = 0; |
| 9654 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9655 | uint32_t creg_val; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9656 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9657 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9658 | * If the caller has provided a response iocbq buffer, then context2 |
| 9659 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9660 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9661 | if (prspiocbq) { |
| 9662 | if (piocb->context2) |
| 9663 | return IOCB_ERROR; |
| 9664 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9665 | } |
| 9666 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9667 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9668 | piocb->context_un.wait_queue = &done_q; |
| 9669 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9670 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9671 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9672 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9673 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9674 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9675 | writel(creg_val, phba->HCregaddr); |
| 9676 | readl(phba->HCregaddr); /* flush */ |
| 9677 | } |
| 9678 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9679 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 9680 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9681 | if (retval == IOCB_SUCCESS) { |
| 9682 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9683 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9684 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9685 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9686 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9687 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 9688 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9689 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9690 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9691 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9692 | "0338 IOCB wait timeout error - no " |
| 9693 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9694 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9695 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9697 | "0330 IOCB wake NOT set, " |
| 9698 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9699 | timeout, (timeleft / jiffies)); |
| 9700 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9701 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9702 | } else if (retval == IOCB_BUSY) { |
| 9703 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9704 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 9705 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); |
| 9706 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9707 | } else { |
| 9708 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9709 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9710 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9711 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9712 | } |
| 9713 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9714 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9715 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9716 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9717 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 9718 | writel(creg_val, phba->HCregaddr); |
| 9719 | readl(phba->HCregaddr); /* flush */ |
| 9720 | } |
| 9721 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9722 | if (prspiocbq) |
| 9723 | piocb->context2 = NULL; |
| 9724 | |
| 9725 | piocb->context_un.wait_queue = NULL; |
| 9726 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9727 | return retval; |
| 9728 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9730 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9731 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9732 | * @phba: Pointer to HBA context object. |
| 9733 | * @pmboxq: Pointer to driver mailbox object. |
| 9734 | * @timeout: Timeout in number of seconds. |
| 9735 | * |
| 9736 | * This function issues the mailbox to firmware and waits for the |
| 9737 | * mailbox command to complete. If the mailbox command is not |
| 9738 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 9739 | * The function waits for the mailbox completion using an |
| 9740 | * interruptible wait. If the thread is woken up due to a |
| 9741 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 9742 | * should not free the mailbox resources, if this function returns |
| 9743 | * MBX_TIMEOUT. |
| 9744 | * This function will sleep while waiting for mailbox completion. |
| 9745 | * So, this function should not be called from any context which |
| 9746 | * does not allow sleeping. Due to the same reason, this function |
| 9747 | * cannot be called with interrupt disabled. |
| 9748 | * This function assumes that the mailbox completion occurs while |
| 9749 | * this function sleep. So, this function cannot be called from |
| 9750 | * the worker thread which processes mailbox completion. |
| 9751 | * This function is called in the context of HBA management |
| 9752 | * applications. |
| 9753 | * This function returns MBX_SUCCESS when successful. |
| 9754 | * This function is called with no lock held. |
| 9755 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9756 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9757 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9758 | uint32_t timeout) |
| 9759 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9760 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9761 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9762 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9763 | |
| 9764 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9765 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9766 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9767 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9768 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9769 | /* setup wake call as IOCB callback */ |
| 9770 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 9771 | /* setup context field to pass wait_queue pointer to wake function */ |
| 9772 | pmboxq->context1 = &done_q; |
| 9773 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9774 | /* now issue the command */ |
| 9775 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9776 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9777 | wait_event_interruptible_timeout(done_q, |
| 9778 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 9779 | timeout * HZ); |
| 9780 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9781 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9782 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9783 | /* |
| 9784 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 9785 | * else do not free the resources. |
| 9786 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 9787 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9788 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 9789 | lpfc_sli4_swap_str(phba, pmboxq); |
| 9790 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9791 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9792 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 9793 | } |
| 9794 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9795 | } |
| 9796 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9797 | return retval; |
| 9798 | } |
| 9799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9800 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9801 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9802 | * @phba: Pointer to HBA context. |
| 9803 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9804 | * This function is called to shutdown the driver's mailbox sub-system. |
| 9805 | * It first marks the mailbox sub-system is in a block state to prevent |
| 9806 | * the asynchronous mailbox command from issued off the pending mailbox |
| 9807 | * command queue. If the mailbox command sub-system shutdown is due to |
| 9808 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 9809 | * the mailbox sub-system flush routine to forcefully bring down the |
| 9810 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 9811 | * as with offline or HBA function reset), this routine will wait for the |
| 9812 | * outstanding mailbox command to complete before invoking the mailbox |
| 9813 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9814 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9815 | void |
| 9816 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9817 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9818 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9819 | unsigned long timeout; |
| 9820 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9821 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9822 | spin_lock_irq(&phba->hbalock); |
| 9823 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 9824 | spin_unlock_irq(&phba->hbalock); |
| 9825 | |
| 9826 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| 9827 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9828 | /* Determine how long we might wait for the active mailbox |
| 9829 | * command to be gracefully completed by firmware. |
| 9830 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9831 | if (phba->sli.mbox_active) |
| 9832 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 9833 | phba->sli.mbox_active) * |
| 9834 | 1000) + jiffies; |
| 9835 | spin_unlock_irq(&phba->hbalock); |
| 9836 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9837 | while (phba->sli.mbox_active) { |
| 9838 | /* Check active mailbox complete status every 2ms */ |
| 9839 | msleep(2); |
| 9840 | if (time_after(jiffies, timeout)) |
| 9841 | /* Timeout, let the mailbox flush routine to |
| 9842 | * forcefully release active mailbox command |
| 9843 | */ |
| 9844 | break; |
| 9845 | } |
| 9846 | } |
| 9847 | lpfc_sli_mbox_sys_flush(phba); |
| 9848 | } |
| 9849 | |
| 9850 | /** |
| 9851 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 9852 | * @phba: Pointer to HBA context. |
| 9853 | * |
| 9854 | * This function is called to read the SLI3 device error attention registers |
| 9855 | * for possible error attention events. The caller must hold the hostlock |
| 9856 | * with spin_lock_irq(). |
| 9857 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9858 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9859 | * Register and returns 0 otherwise. |
| 9860 | **/ |
| 9861 | static int |
| 9862 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 9863 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9864 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9865 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9866 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9867 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 9868 | goto unplug_err; |
| 9869 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9870 | if (ha_copy & HA_ERATT) { |
| 9871 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9872 | if (lpfc_sli_read_hs(phba)) |
| 9873 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9874 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9875 | /* Check if there is a deferred error condition is active */ |
| 9876 | if ((HS_FFER1 & phba->work_hs) && |
| 9877 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9878 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9879 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9880 | /* Clear all interrupt enable conditions */ |
| 9881 | writel(0, phba->HCregaddr); |
| 9882 | readl(phba->HCregaddr); |
| 9883 | } |
| 9884 | |
| 9885 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9886 | phba->work_ha |= HA_ERATT; |
| 9887 | /* Indicate polling handles this ERATT */ |
| 9888 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9889 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9890 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9891 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9892 | |
| 9893 | unplug_err: |
| 9894 | /* Set the driver HS work bitmap */ |
| 9895 | phba->work_hs |= UNPLUG_ERR; |
| 9896 | /* Set the driver HA work bitmap */ |
| 9897 | phba->work_ha |= HA_ERATT; |
| 9898 | /* Indicate polling handles this ERATT */ |
| 9899 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 9900 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9901 | } |
| 9902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9903 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9904 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 9905 | * @phba: Pointer to HBA context. |
| 9906 | * |
| 9907 | * This function is called to read the SLI4 device error attention registers |
| 9908 | * for possible error attention events. The caller must hold the hostlock |
| 9909 | * with spin_lock_irq(). |
| 9910 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9911 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9912 | * Register and returns 0 otherwise. |
| 9913 | **/ |
| 9914 | static int |
| 9915 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 9916 | { |
| 9917 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9918 | uint32_t if_type, portsmphr; |
| 9919 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9920 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9921 | /* |
| 9922 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9923 | * registers for error attention. This can be changed later. |
| 9924 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9925 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 9926 | switch (if_type) { |
| 9927 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9928 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 9929 | &uerr_sta_lo) || |
| 9930 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 9931 | &uerr_sta_hi)) { |
| 9932 | phba->work_hs |= UNPLUG_ERR; |
| 9933 | phba->work_ha |= HA_ERATT; |
| 9934 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 9935 | return 1; |
| 9936 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9937 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 9938 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 9939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9940 | "1423 HBA Unrecoverable error: " |
| 9941 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 9942 | "ue_mask_lo_reg=0x%x, " |
| 9943 | "ue_mask_hi_reg=0x%x\n", |
| 9944 | uerr_sta_lo, uerr_sta_hi, |
| 9945 | phba->sli4_hba.ue_mask_lo, |
| 9946 | phba->sli4_hba.ue_mask_hi); |
| 9947 | phba->work_status[0] = uerr_sta_lo; |
| 9948 | phba->work_status[1] = uerr_sta_hi; |
| 9949 | phba->work_ha |= HA_ERATT; |
| 9950 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 9951 | return 1; |
| 9952 | } |
| 9953 | break; |
| 9954 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9955 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 9956 | &portstat_reg.word0) || |
| 9957 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 9958 | &portsmphr)){ |
| 9959 | phba->work_hs |= UNPLUG_ERR; |
| 9960 | phba->work_ha |= HA_ERATT; |
| 9961 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 9962 | return 1; |
| 9963 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9964 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 9965 | phba->work_status[0] = |
| 9966 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 9967 | phba->work_status[1] = |
| 9968 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 9969 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9970 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9971 | "port status reg 0x%x, " |
| 9972 | "port smphr reg 0x%x, " |
| 9973 | "error 1=0x%x, error 2=0x%x\n", |
| 9974 | portstat_reg.word0, |
| 9975 | portsmphr, |
| 9976 | phba->work_status[0], |
| 9977 | phba->work_status[1]); |
| 9978 | phba->work_ha |= HA_ERATT; |
| 9979 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 9980 | return 1; |
| 9981 | } |
| 9982 | break; |
| 9983 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9984 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 9985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9986 | "2886 HBA Error Attention on unsupported " |
| 9987 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 9988 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9989 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9990 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9991 | return 0; |
| 9992 | } |
| 9993 | |
| 9994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9995 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 9996 | * @phba: Pointer to HBA context. |
| 9997 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9998 | * 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] | 9999 | * error attention register bit for error attention events. |
| 10000 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10001 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10002 | * Register and returns 0 otherwise. |
| 10003 | **/ |
| 10004 | int |
| 10005 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10006 | { |
| 10007 | uint32_t ha_copy; |
| 10008 | |
| 10009 | /* If somebody is waiting to handle an eratt, don't process it |
| 10010 | * here. The brdkill function will do this. |
| 10011 | */ |
| 10012 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10013 | return 0; |
| 10014 | |
| 10015 | /* Check if interrupt handler handles this ERATT */ |
| 10016 | spin_lock_irq(&phba->hbalock); |
| 10017 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10018 | /* Interrupt handler has handled ERATT */ |
| 10019 | spin_unlock_irq(&phba->hbalock); |
| 10020 | return 0; |
| 10021 | } |
| 10022 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10023 | /* |
| 10024 | * If there is deferred error attention, do not check for error |
| 10025 | * attention |
| 10026 | */ |
| 10027 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10028 | spin_unlock_irq(&phba->hbalock); |
| 10029 | return 0; |
| 10030 | } |
| 10031 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10032 | /* If PCI channel is offline, don't process it */ |
| 10033 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10034 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10035 | return 0; |
| 10036 | } |
| 10037 | |
| 10038 | switch (phba->sli_rev) { |
| 10039 | case LPFC_SLI_REV2: |
| 10040 | case LPFC_SLI_REV3: |
| 10041 | /* Read chip Host Attention (HA) register */ |
| 10042 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10043 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10044 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10045 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10046 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10047 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10048 | default: |
| 10049 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10050 | "0299 Invalid SLI revision (%d)\n", |
| 10051 | phba->sli_rev); |
| 10052 | ha_copy = 0; |
| 10053 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10054 | } |
| 10055 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10056 | |
| 10057 | return ha_copy; |
| 10058 | } |
| 10059 | |
| 10060 | /** |
| 10061 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10062 | * @phba: Pointer to HBA context. |
| 10063 | * |
| 10064 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10065 | * that the interrupt should be handled. |
| 10066 | * |
| 10067 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10068 | * interrupt should be handled, otherwise -EIO. |
| 10069 | */ |
| 10070 | static inline int |
| 10071 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10072 | { |
| 10073 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10074 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10075 | return -EIO; |
| 10076 | |
| 10077 | /* Update device level interrupt statistics */ |
| 10078 | phba->sli.slistat.sli_intr++; |
| 10079 | |
| 10080 | /* Ignore all interrupts during initialization. */ |
| 10081 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10082 | return -EIO; |
| 10083 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10084 | return 0; |
| 10085 | } |
| 10086 | |
| 10087 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10088 | * 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] | 10089 | * @irq: Interrupt number. |
| 10090 | * @dev_id: The device context pointer. |
| 10091 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10092 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10093 | * service routine when device with SLI-3 interface spec is enabled with |
| 10094 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10095 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10096 | * interrupt mode, this function is called as part of the device-level |
| 10097 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10098 | * is undergoing initialization, the interrupt handler will not process |
| 10099 | * the interrupt. The link attention and ELS ring attention events are |
| 10100 | * handled by the worker thread. The interrupt handler signals the worker |
| 10101 | * thread and returns for these events. This function is called without |
| 10102 | * 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] | 10103 | * structures. |
| 10104 | * |
| 10105 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10106 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10107 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10108 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10109 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10110 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10111 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10112 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10113 | uint32_t work_ha_copy; |
| 10114 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10115 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10116 | uint32_t control; |
| 10117 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10118 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10119 | struct lpfc_vport *vport; |
| 10120 | struct lpfc_nodelist *ndlp; |
| 10121 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10122 | LPFC_MBOXQ_t *pmb; |
| 10123 | int rc; |
| 10124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10125 | /* |
| 10126 | * Get the driver's phba structure from the dev_id and |
| 10127 | * assume the HBA is not interrupting. |
| 10128 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10129 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10130 | |
| 10131 | if (unlikely(!phba)) |
| 10132 | return IRQ_NONE; |
| 10133 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10134 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10135 | * Stuff needs to be attented to when this function is invoked as an |
| 10136 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10137 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10138 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10139 | /* Check device state for handling interrupt */ |
| 10140 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10141 | return IRQ_NONE; |
| 10142 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10143 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10144 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10145 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10146 | /* If somebody is waiting to handle an eratt don't process it |
| 10147 | * here. The brdkill function will do this. |
| 10148 | */ |
| 10149 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10150 | ha_copy &= ~HA_ERATT; |
| 10151 | /* Check the need for handling ERATT in interrupt handler */ |
| 10152 | if (ha_copy & HA_ERATT) { |
| 10153 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10154 | /* ERATT polling has handled ERATT */ |
| 10155 | ha_copy &= ~HA_ERATT; |
| 10156 | else |
| 10157 | /* Indicate interrupt handler handles ERATT */ |
| 10158 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10159 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10160 | |
| 10161 | /* |
| 10162 | * If there is deferred error attention, do not check for any |
| 10163 | * interrupt. |
| 10164 | */ |
| 10165 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10166 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10167 | return IRQ_NONE; |
| 10168 | } |
| 10169 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10170 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10171 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10172 | goto unplug_error; |
| 10173 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10174 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10175 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10176 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10177 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10178 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10179 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10180 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10181 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10182 | } else |
| 10183 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10185 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10186 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10187 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10188 | if (work_ha_copy & HA_LATT) { |
| 10189 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10190 | /* |
| 10191 | * Turn off Link Attention interrupts |
| 10192 | * until CLEAR_LA done |
| 10193 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10194 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10195 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10196 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10197 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10198 | control &= ~HC_LAINT_ENA; |
| 10199 | writel(control, phba->HCregaddr); |
| 10200 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10201 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10202 | } |
| 10203 | else |
| 10204 | work_ha_copy &= ~HA_LATT; |
| 10205 | } |
| 10206 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10207 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10208 | /* |
| 10209 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10210 | * the only slow ring. |
| 10211 | */ |
| 10212 | status = (work_ha_copy & |
| 10213 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10214 | status >>= (4*LPFC_ELS_RING); |
| 10215 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10216 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10217 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10218 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10219 | |
| 10220 | lpfc_debugfs_slow_ring_trc(phba, |
| 10221 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10222 | control, status, |
| 10223 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10224 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10225 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10226 | lpfc_debugfs_slow_ring_trc(phba, |
| 10227 | "ISR Disable ring:" |
| 10228 | "pwork:x%x hawork:x%x wait:x%x", |
| 10229 | phba->work_ha, work_ha_copy, |
| 10230 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10231 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10233 | control &= |
| 10234 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10235 | writel(control, phba->HCregaddr); |
| 10236 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10237 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10238 | else { |
| 10239 | lpfc_debugfs_slow_ring_trc(phba, |
| 10240 | "ISR slow ring: pwork:" |
| 10241 | "x%x hawork:x%x wait:x%x", |
| 10242 | phba->work_ha, work_ha_copy, |
| 10243 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10244 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10245 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10246 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10247 | } |
| 10248 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10249 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10250 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10251 | if (lpfc_sli_read_hs(phba)) |
| 10252 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10253 | /* |
| 10254 | * Check if there is a deferred error condition |
| 10255 | * is active |
| 10256 | */ |
| 10257 | if ((HS_FFER1 & phba->work_hs) && |
| 10258 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10259 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10260 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10261 | phba->hba_flag |= DEFER_ERATT; |
| 10262 | /* Clear all interrupt enable conditions */ |
| 10263 | writel(0, phba->HCregaddr); |
| 10264 | readl(phba->HCregaddr); |
| 10265 | } |
| 10266 | } |
| 10267 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10268 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10269 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10270 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10271 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10272 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10273 | |
| 10274 | /* First check out the status word */ |
| 10275 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10276 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10277 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10278 | /* |
| 10279 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10280 | * mbxStatus <status> |
| 10281 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10282 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10283 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10284 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10285 | "Interrupt mbxCommand x%x " |
| 10286 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10287 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10288 | pmbox->mbxCommand, |
| 10289 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10290 | /* clear mailbox attention bit */ |
| 10291 | work_ha_copy &= ~HA_MBATT; |
| 10292 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10293 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10294 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10295 | phba->last_completion_time = jiffies; |
| 10296 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10297 | if (pmb->mbox_cmpl) { |
| 10298 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10299 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10300 | if (pmb->out_ext_byte_len && |
| 10301 | pmb->context2) |
| 10302 | lpfc_sli_pcimem_bcopy( |
| 10303 | phba->mbox_ext, |
| 10304 | pmb->context2, |
| 10305 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10306 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10307 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10308 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10309 | |
| 10310 | lpfc_debugfs_disc_trc(vport, |
| 10311 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10312 | "MBOX dflt rpi: : " |
| 10313 | "status:x%x rpi:x%x", |
| 10314 | (uint32_t)pmbox->mbxStatus, |
| 10315 | pmbox->un.varWords[0], 0); |
| 10316 | |
| 10317 | if (!pmbox->mbxStatus) { |
| 10318 | mp = (struct lpfc_dmabuf *) |
| 10319 | (pmb->context1); |
| 10320 | ndlp = (struct lpfc_nodelist *) |
| 10321 | pmb->context2; |
| 10322 | |
| 10323 | /* Reg_LOGIN of dflt RPI was |
| 10324 | * successful. new lets get |
| 10325 | * rid of the RPI using the |
| 10326 | * same mbox buffer. |
| 10327 | */ |
| 10328 | lpfc_unreg_login(phba, |
| 10329 | vport->vpi, |
| 10330 | pmbox->un.varWords[0], |
| 10331 | pmb); |
| 10332 | pmb->mbox_cmpl = |
| 10333 | lpfc_mbx_cmpl_dflt_rpi; |
| 10334 | pmb->context1 = mp; |
| 10335 | pmb->context2 = ndlp; |
| 10336 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10337 | rc = lpfc_sli_issue_mbox(phba, |
| 10338 | pmb, |
| 10339 | MBX_NOWAIT); |
| 10340 | if (rc != MBX_BUSY) |
| 10341 | lpfc_printf_log(phba, |
| 10342 | KERN_ERR, |
| 10343 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10344 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10345 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10346 | if (rc != MBX_NOT_FINISHED) |
| 10347 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10348 | } |
| 10349 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10350 | spin_lock_irqsave( |
| 10351 | &phba->pport->work_port_lock, |
| 10352 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10353 | phba->pport->work_port_events &= |
| 10354 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10355 | spin_unlock_irqrestore( |
| 10356 | &phba->pport->work_port_lock, |
| 10357 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10358 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10359 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10360 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10361 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10362 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10363 | if ((work_ha_copy & HA_MBATT) && |
| 10364 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10365 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10366 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10367 | do { |
| 10368 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10369 | MBX_NOWAIT); |
| 10370 | } while (rc == MBX_NOT_FINISHED); |
| 10371 | if (rc != MBX_SUCCESS) |
| 10372 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10373 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10374 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10375 | } |
| 10376 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10377 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10378 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10379 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10380 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10381 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10382 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10383 | unplug_error: |
| 10384 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10385 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10386 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10387 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10388 | |
| 10389 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10390 | * 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] | 10391 | * @irq: Interrupt number. |
| 10392 | * @dev_id: The device context pointer. |
| 10393 | * |
| 10394 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10395 | * service routine when device with SLI-3 interface spec is enabled with |
| 10396 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10397 | * ring event in the HBA. However, when the device is enabled with either |
| 10398 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10399 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10400 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10401 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10402 | * the intrrupt context. This function is called without any lock held. |
| 10403 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10404 | * |
| 10405 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10406 | * returns IRQ_NONE. |
| 10407 | **/ |
| 10408 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10409 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10410 | { |
| 10411 | struct lpfc_hba *phba; |
| 10412 | uint32_t ha_copy; |
| 10413 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10414 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10415 | |
| 10416 | /* Get the driver's phba structure from the dev_id and |
| 10417 | * assume the HBA is not interrupting. |
| 10418 | */ |
| 10419 | phba = (struct lpfc_hba *) dev_id; |
| 10420 | |
| 10421 | if (unlikely(!phba)) |
| 10422 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10423 | |
| 10424 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10425 | * Stuff needs to be attented to when this function is invoked as an |
| 10426 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10427 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10428 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10429 | /* Check device state for handling interrupt */ |
| 10430 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10431 | return IRQ_NONE; |
| 10432 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10433 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10434 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10435 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10436 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10437 | /* |
| 10438 | * If there is deferred error attention, do not check for |
| 10439 | * any interrupt. |
| 10440 | */ |
| 10441 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10442 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10443 | return IRQ_NONE; |
| 10444 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10445 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10446 | phba->HAregaddr); |
| 10447 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10448 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10449 | } else |
| 10450 | ha_copy = phba->ha_copy; |
| 10451 | |
| 10452 | /* |
| 10453 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10454 | */ |
| 10455 | ha_copy &= ~(phba->work_ha_mask); |
| 10456 | |
| 10457 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10458 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10459 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10460 | lpfc_sli_handle_fast_ring_event(phba, |
| 10461 | &phba->sli.ring[LPFC_FCP_RING], |
| 10462 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10463 | |
| 10464 | if (phba->cfg_multi_ring_support == 2) { |
| 10465 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10466 | * Process all events on extra ring. Take the optimized path |
| 10467 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10468 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10469 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10470 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10471 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10472 | lpfc_sli_handle_fast_ring_event(phba, |
| 10473 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10474 | status); |
| 10475 | } |
| 10476 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10477 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10478 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10479 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10480 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10481 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10482 | * @irq: Interrupt number. |
| 10483 | * @dev_id: The device context pointer. |
| 10484 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10485 | * This function is the HBA device-level interrupt handler to device with |
| 10486 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10487 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10488 | * requires driver attention. This function invokes the slow-path interrupt |
| 10489 | * attention handling function and fast-path interrupt attention handling |
| 10490 | * function in turn to process the relevant HBA attention events. This |
| 10491 | * function is called without any lock held. It gets the hbalock to access |
| 10492 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10493 | * |
| 10494 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10495 | * returns IRQ_NONE. |
| 10496 | **/ |
| 10497 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10498 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10499 | { |
| 10500 | struct lpfc_hba *phba; |
| 10501 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10502 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10503 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10504 | |
| 10505 | /* |
| 10506 | * Get the driver's phba structure from the dev_id and |
| 10507 | * assume the HBA is not interrupting. |
| 10508 | */ |
| 10509 | phba = (struct lpfc_hba *) dev_id; |
| 10510 | |
| 10511 | if (unlikely(!phba)) |
| 10512 | return IRQ_NONE; |
| 10513 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10514 | /* Check device state for handling interrupt */ |
| 10515 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10516 | return IRQ_NONE; |
| 10517 | |
| 10518 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10519 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10520 | spin_unlock(&phba->hbalock); |
| 10521 | return IRQ_HANDLED; |
| 10522 | } |
| 10523 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10524 | if (unlikely(!phba->ha_copy)) { |
| 10525 | spin_unlock(&phba->hbalock); |
| 10526 | return IRQ_NONE; |
| 10527 | } else if (phba->ha_copy & HA_ERATT) { |
| 10528 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10529 | /* ERATT polling has handled ERATT */ |
| 10530 | phba->ha_copy &= ~HA_ERATT; |
| 10531 | else |
| 10532 | /* Indicate interrupt handler handles ERATT */ |
| 10533 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10534 | } |
| 10535 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10536 | /* |
| 10537 | * If there is deferred error attention, do not check for any interrupt. |
| 10538 | */ |
| 10539 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10540 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10541 | return IRQ_NONE; |
| 10542 | } |
| 10543 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10544 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10545 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10546 | spin_unlock(&phba->hbalock); |
| 10547 | return IRQ_HANDLED; |
| 10548 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10549 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10550 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10551 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10552 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10553 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10554 | readl(phba->HAregaddr); /* flush */ |
| 10555 | spin_unlock(&phba->hbalock); |
| 10556 | |
| 10557 | /* |
| 10558 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10559 | */ |
| 10560 | |
| 10561 | /* status of events with mailbox and link attention */ |
| 10562 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10563 | |
| 10564 | /* status of events with ELS ring */ |
| 10565 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10566 | status2 >>= (4*LPFC_ELS_RING); |
| 10567 | |
| 10568 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10569 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10570 | else |
| 10571 | sp_irq_rc = IRQ_NONE; |
| 10572 | |
| 10573 | /* |
| 10574 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10575 | */ |
| 10576 | |
| 10577 | /* status of events with FCP ring */ |
| 10578 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10579 | status1 >>= (4*LPFC_FCP_RING); |
| 10580 | |
| 10581 | /* status of events with extra ring */ |
| 10582 | if (phba->cfg_multi_ring_support == 2) { |
| 10583 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10584 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10585 | } else |
| 10586 | status2 = 0; |
| 10587 | |
| 10588 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10589 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10590 | else |
| 10591 | fp_irq_rc = IRQ_NONE; |
| 10592 | |
| 10593 | /* Return device-level interrupt handling status */ |
| 10594 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10595 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10596 | |
| 10597 | /** |
| 10598 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10599 | * @phba: pointer to lpfc hba data structure. |
| 10600 | * |
| 10601 | * This routine is invoked by the worker thread to process all the pending |
| 10602 | * SLI4 FCP abort XRI events. |
| 10603 | **/ |
| 10604 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10605 | { |
| 10606 | struct lpfc_cq_event *cq_event; |
| 10607 | |
| 10608 | /* First, declare the fcp xri abort event has been handled */ |
| 10609 | spin_lock_irq(&phba->hbalock); |
| 10610 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10611 | spin_unlock_irq(&phba->hbalock); |
| 10612 | /* Now, handle all the fcp xri abort events */ |
| 10613 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10614 | /* Get the first event from the head of the event queue */ |
| 10615 | spin_lock_irq(&phba->hbalock); |
| 10616 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10617 | cq_event, struct lpfc_cq_event, list); |
| 10618 | spin_unlock_irq(&phba->hbalock); |
| 10619 | /* Notify aborted XRI for FCP work queue */ |
| 10620 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10621 | /* Free the event processed back to the free pool */ |
| 10622 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10623 | } |
| 10624 | } |
| 10625 | |
| 10626 | /** |
| 10627 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10628 | * @phba: pointer to lpfc hba data structure. |
| 10629 | * |
| 10630 | * This routine is invoked by the worker thread to process all the pending |
| 10631 | * SLI4 els abort xri events. |
| 10632 | **/ |
| 10633 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10634 | { |
| 10635 | struct lpfc_cq_event *cq_event; |
| 10636 | |
| 10637 | /* First, declare the els xri abort event has been handled */ |
| 10638 | spin_lock_irq(&phba->hbalock); |
| 10639 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10640 | spin_unlock_irq(&phba->hbalock); |
| 10641 | /* Now, handle all the els xri abort events */ |
| 10642 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10643 | /* Get the first event from the head of the event queue */ |
| 10644 | spin_lock_irq(&phba->hbalock); |
| 10645 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10646 | cq_event, struct lpfc_cq_event, list); |
| 10647 | spin_unlock_irq(&phba->hbalock); |
| 10648 | /* Notify aborted XRI for ELS work queue */ |
| 10649 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10650 | /* Free the event processed back to the free pool */ |
| 10651 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10652 | } |
| 10653 | } |
| 10654 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10655 | /** |
| 10656 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10657 | * @phba: pointer to lpfc hba data structure |
| 10658 | * @pIocbIn: pointer to the rspiocbq |
| 10659 | * @pIocbOut: pointer to the cmdiocbq |
| 10660 | * @wcqe: pointer to the complete wcqe |
| 10661 | * |
| 10662 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 10663 | * by copying all the IOCB fields from command iocbq and transferring the |
| 10664 | * completion status information from the complete wcqe. |
| 10665 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10666 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10667 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 10668 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10669 | struct lpfc_iocbq *pIocbOut, |
| 10670 | struct lpfc_wcqe_complete *wcqe) |
| 10671 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10672 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10673 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10674 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 10675 | |
| 10676 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 10677 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10678 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10679 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 10680 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10681 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 10682 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 10683 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 10684 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 10685 | wcqe->total_data_placed; |
| 10686 | else |
| 10687 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10688 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10689 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10690 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 10691 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10692 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10693 | /* Convert BG errors for completion status */ |
| 10694 | if (status == CQE_STATUS_DI_ERROR) { |
| 10695 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 10696 | |
| 10697 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 10698 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 10699 | else |
| 10700 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 10701 | |
| 10702 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 10703 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 10704 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10705 | BGS_GUARD_ERR_MASK; |
| 10706 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 10707 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10708 | BGS_APPTAG_ERR_MASK; |
| 10709 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 10710 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10711 | BGS_REFTAG_ERR_MASK; |
| 10712 | |
| 10713 | /* Check to see if there was any good data before the error */ |
| 10714 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 10715 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10716 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 10717 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 10718 | wcqe->total_data_placed; |
| 10719 | } |
| 10720 | |
| 10721 | /* |
| 10722 | * Set ALL the error bits to indicate we don't know what |
| 10723 | * type of error it is. |
| 10724 | */ |
| 10725 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 10726 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10727 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 10728 | BGS_GUARD_ERR_MASK); |
| 10729 | } |
| 10730 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10731 | /* Pick up HBA exchange busy condition */ |
| 10732 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 10733 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10734 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 10735 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10736 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10737 | } |
| 10738 | |
| 10739 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10740 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 10741 | * @phba: Pointer to HBA context object. |
| 10742 | * @wcqe: Pointer to work-queue completion queue entry. |
| 10743 | * |
| 10744 | * This routine handles an ELS work-queue completion event and construct |
| 10745 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 10746 | * discovery engine to handle. |
| 10747 | * |
| 10748 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 10749 | **/ |
| 10750 | static struct lpfc_iocbq * |
| 10751 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 10752 | struct lpfc_iocbq *irspiocbq) |
| 10753 | { |
| 10754 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 10755 | struct lpfc_iocbq *cmdiocbq; |
| 10756 | struct lpfc_wcqe_complete *wcqe; |
| 10757 | unsigned long iflags; |
| 10758 | |
| 10759 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
| 10760 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10761 | pring->stats.iocb_event++; |
| 10762 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 10763 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 10764 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10765 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10766 | |
| 10767 | if (unlikely(!cmdiocbq)) { |
| 10768 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10769 | "0386 ELS complete with no corresponding " |
| 10770 | "cmdiocb: iotag (%d)\n", |
| 10771 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10772 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 10773 | return NULL; |
| 10774 | } |
| 10775 | |
| 10776 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10777 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10778 | |
| 10779 | return irspiocbq; |
| 10780 | } |
| 10781 | |
| 10782 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10783 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 10784 | * @phba: Pointer to HBA context object. |
| 10785 | * @cqe: Pointer to mailbox completion queue entry. |
| 10786 | * |
| 10787 | * This routine process a mailbox completion queue entry with asynchrous |
| 10788 | * event. |
| 10789 | * |
| 10790 | * Return: true if work posted to worker thread, otherwise false. |
| 10791 | **/ |
| 10792 | static bool |
| 10793 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 10794 | { |
| 10795 | struct lpfc_cq_event *cq_event; |
| 10796 | unsigned long iflags; |
| 10797 | |
| 10798 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10799 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 10800 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 10801 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 10802 | |
| 10803 | /* Allocate a new internal CQ_EVENT entry */ |
| 10804 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 10805 | if (!cq_event) { |
| 10806 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 10807 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 10808 | return false; |
| 10809 | } |
| 10810 | |
| 10811 | /* Move the CQE into an asynchronous event entry */ |
| 10812 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 10813 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10814 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 10815 | /* Set the async event flag */ |
| 10816 | phba->hba_flag |= ASYNC_EVENT; |
| 10817 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10818 | |
| 10819 | return true; |
| 10820 | } |
| 10821 | |
| 10822 | /** |
| 10823 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 10824 | * @phba: Pointer to HBA context object. |
| 10825 | * @cqe: Pointer to mailbox completion queue entry. |
| 10826 | * |
| 10827 | * This routine process a mailbox completion queue entry with mailbox |
| 10828 | * completion event. |
| 10829 | * |
| 10830 | * Return: true if work posted to worker thread, otherwise false. |
| 10831 | **/ |
| 10832 | static bool |
| 10833 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 10834 | { |
| 10835 | uint32_t mcqe_status; |
| 10836 | MAILBOX_t *mbox, *pmbox; |
| 10837 | struct lpfc_mqe *mqe; |
| 10838 | struct lpfc_vport *vport; |
| 10839 | struct lpfc_nodelist *ndlp; |
| 10840 | struct lpfc_dmabuf *mp; |
| 10841 | unsigned long iflags; |
| 10842 | LPFC_MBOXQ_t *pmb; |
| 10843 | bool workposted = false; |
| 10844 | int rc; |
| 10845 | |
| 10846 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 10847 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 10848 | goto out_no_mqe_complete; |
| 10849 | |
| 10850 | /* Get the reference to the active mbox command */ |
| 10851 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10852 | pmb = phba->sli.mbox_active; |
| 10853 | if (unlikely(!pmb)) { |
| 10854 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 10855 | "1832 No pending MBOX command to handle\n"); |
| 10856 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10857 | goto out_no_mqe_complete; |
| 10858 | } |
| 10859 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10860 | mqe = &pmb->u.mqe; |
| 10861 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 10862 | mbox = phba->mbox; |
| 10863 | vport = pmb->vport; |
| 10864 | |
| 10865 | /* Reset heartbeat timer */ |
| 10866 | phba->last_completion_time = jiffies; |
| 10867 | del_timer(&phba->sli.mbox_tmo); |
| 10868 | |
| 10869 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 10870 | if (pmb->mbox_cmpl && mbox) |
| 10871 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10872 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10873 | /* |
| 10874 | * For mcqe errors, conditionally move a modified error code to |
| 10875 | * the mbox so that the error will not be missed. |
| 10876 | */ |
| 10877 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 10878 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 10879 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 10880 | bf_set(lpfc_mqe_status, mqe, |
| 10881 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 10882 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10883 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10884 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10885 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 10886 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 10887 | mcqe_status, |
| 10888 | pmbox->un.varWords[0], 0); |
| 10889 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 10890 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 10891 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 10892 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 10893 | * RID of the PPI using the same mbox buffer. |
| 10894 | */ |
| 10895 | lpfc_unreg_login(phba, vport->vpi, |
| 10896 | pmbox->un.varWords[0], pmb); |
| 10897 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 10898 | pmb->context1 = mp; |
| 10899 | pmb->context2 = ndlp; |
| 10900 | pmb->vport = vport; |
| 10901 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 10902 | if (rc != MBX_BUSY) |
| 10903 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10904 | LOG_SLI, "0385 rc should " |
| 10905 | "have been MBX_BUSY\n"); |
| 10906 | if (rc != MBX_NOT_FINISHED) |
| 10907 | goto send_current_mbox; |
| 10908 | } |
| 10909 | } |
| 10910 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 10911 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 10912 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 10913 | |
| 10914 | /* There is mailbox completion work to do */ |
| 10915 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10916 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 10917 | phba->work_ha |= HA_MBATT; |
| 10918 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10919 | workposted = true; |
| 10920 | |
| 10921 | send_current_mbox: |
| 10922 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10923 | /* Release the mailbox command posting token */ |
| 10924 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10925 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 10926 | phba->sli.mbox_active = NULL; |
| 10927 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10928 | /* Wake up worker thread to post the next pending mailbox command */ |
| 10929 | lpfc_worker_wake_up(phba); |
| 10930 | out_no_mqe_complete: |
| 10931 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 10932 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 10933 | return workposted; |
| 10934 | } |
| 10935 | |
| 10936 | /** |
| 10937 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 10938 | * @phba: Pointer to HBA context object. |
| 10939 | * @cqe: Pointer to mailbox completion queue entry. |
| 10940 | * |
| 10941 | * This routine process a mailbox completion queue entry, it invokes the |
| 10942 | * proper mailbox complete handling or asynchrous event handling routine |
| 10943 | * according to the MCQE's async bit. |
| 10944 | * |
| 10945 | * Return: true if work posted to worker thread, otherwise false. |
| 10946 | **/ |
| 10947 | static bool |
| 10948 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 10949 | { |
| 10950 | struct lpfc_mcqe mcqe; |
| 10951 | bool workposted; |
| 10952 | |
| 10953 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 10954 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 10955 | |
| 10956 | /* Invoke the proper event handling routine */ |
| 10957 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 10958 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 10959 | else |
| 10960 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 10961 | return workposted; |
| 10962 | } |
| 10963 | |
| 10964 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10965 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 10966 | * @phba: Pointer to HBA context object. |
| 10967 | * @wcqe: Pointer to work-queue completion queue entry. |
| 10968 | * |
| 10969 | * This routine handles an ELS work-queue completion event. |
| 10970 | * |
| 10971 | * Return: true if work posted to worker thread, otherwise false. |
| 10972 | **/ |
| 10973 | static bool |
| 10974 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, |
| 10975 | struct lpfc_wcqe_complete *wcqe) |
| 10976 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10977 | struct lpfc_iocbq *irspiocbq; |
| 10978 | unsigned long iflags; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10979 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10980 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10981 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10982 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 10983 | if (!irspiocbq) { |
| 10984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10985 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 10986 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
| 10987 | pring->txq_cnt, phba->iocb_cnt, |
| 10988 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, |
| 10989 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10990 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10991 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10992 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10993 | /* Save off the slow-path queue event for work thread to process */ |
| 10994 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10995 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 10996 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10997 | &phba->sli4_hba.sp_queue_event); |
| 10998 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10999 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11000 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11001 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11002 | } |
| 11003 | |
| 11004 | /** |
| 11005 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11006 | * @phba: Pointer to HBA context object. |
| 11007 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11008 | * |
| 11009 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11010 | * proper WQ release routine to the slow-path WQ. |
| 11011 | **/ |
| 11012 | static void |
| 11013 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11014 | struct lpfc_wcqe_release *wcqe) |
| 11015 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11016 | /* sanity check on queue memory */ |
| 11017 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11018 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11019 | /* Check for the slow-path ELS work queue */ |
| 11020 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11021 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11022 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11023 | else |
| 11024 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11025 | "2579 Slow-path wqe consume event carries " |
| 11026 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11027 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11028 | phba->sli4_hba.els_wq->queue_id); |
| 11029 | } |
| 11030 | |
| 11031 | /** |
| 11032 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11033 | * @phba: Pointer to HBA context object. |
| 11034 | * @cq: Pointer to a WQ completion queue. |
| 11035 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11036 | * |
| 11037 | * This routine handles an XRI abort event. |
| 11038 | * |
| 11039 | * Return: true if work posted to worker thread, otherwise false. |
| 11040 | **/ |
| 11041 | static bool |
| 11042 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11043 | struct lpfc_queue *cq, |
| 11044 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11045 | { |
| 11046 | bool workposted = false; |
| 11047 | struct lpfc_cq_event *cq_event; |
| 11048 | unsigned long iflags; |
| 11049 | |
| 11050 | /* Allocate a new internal CQ_EVENT entry */ |
| 11051 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11052 | if (!cq_event) { |
| 11053 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11054 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11055 | return false; |
| 11056 | } |
| 11057 | |
| 11058 | /* Move the CQE into the proper xri abort event list */ |
| 11059 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11060 | switch (cq->subtype) { |
| 11061 | case LPFC_FCP: |
| 11062 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11063 | list_add_tail(&cq_event->list, |
| 11064 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11065 | /* Set the fcp xri abort event flag */ |
| 11066 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11067 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11068 | workposted = true; |
| 11069 | break; |
| 11070 | case LPFC_ELS: |
| 11071 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11072 | list_add_tail(&cq_event->list, |
| 11073 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11074 | /* Set the els xri abort event flag */ |
| 11075 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11076 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11077 | workposted = true; |
| 11078 | break; |
| 11079 | default: |
| 11080 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11081 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11082 | cq->subtype); |
| 11083 | workposted = false; |
| 11084 | break; |
| 11085 | } |
| 11086 | return workposted; |
| 11087 | } |
| 11088 | |
| 11089 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11090 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11091 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11092 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11093 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11094 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11095 | * |
| 11096 | * Return: true if work posted to worker thread, otherwise false. |
| 11097 | **/ |
| 11098 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11099 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11100 | { |
| 11101 | bool workposted = false; |
| 11102 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11103 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11104 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11105 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11106 | unsigned long iflags; |
| 11107 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11108 | /* sanity check on queue memory */ |
| 11109 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11110 | return workposted; |
| 11111 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11112 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11113 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11114 | else |
| 11115 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11116 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11117 | goto out; |
| 11118 | |
| 11119 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11120 | switch (status) { |
| 11121 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11122 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11123 | "2537 Receive Frame Truncated!!\n"); |
| 11124 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11125 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11126 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11127 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11128 | if (!dma_buf) { |
| 11129 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11130 | goto out; |
| 11131 | } |
| 11132 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11133 | /* save off the frame for the word thread to process */ |
| 11134 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11135 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11136 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11137 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11138 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11139 | workposted = true; |
| 11140 | break; |
| 11141 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11142 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
| 11143 | /* Post more buffers if possible */ |
| 11144 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11145 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11146 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11147 | workposted = true; |
| 11148 | break; |
| 11149 | } |
| 11150 | out: |
| 11151 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11152 | } |
| 11153 | |
| 11154 | /** |
| 11155 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11156 | * @phba: Pointer to HBA context object. |
| 11157 | * @cq: Pointer to the completion queue. |
| 11158 | * @wcqe: Pointer to a completion queue entry. |
| 11159 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11160 | * This routine process a slow-path work-queue or receive queue completion queue |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11161 | * entry. |
| 11162 | * |
| 11163 | * Return: true if work posted to worker thread, otherwise false. |
| 11164 | **/ |
| 11165 | static bool |
| 11166 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11167 | struct lpfc_cqe *cqe) |
| 11168 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11169 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11170 | bool workposted = false; |
| 11171 | |
| 11172 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11173 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11174 | |
| 11175 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11176 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11177 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11178 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11179 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11180 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11181 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11182 | break; |
| 11183 | case CQE_CODE_RELEASE_WQE: |
| 11184 | /* Process the WQ release event */ |
| 11185 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11186 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11187 | break; |
| 11188 | case CQE_CODE_XRI_ABORTED: |
| 11189 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11190 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11191 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11192 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11193 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11194 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11195 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11196 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11197 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11198 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11199 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11200 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11201 | default: |
| 11202 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11203 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11204 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11205 | break; |
| 11206 | } |
| 11207 | return workposted; |
| 11208 | } |
| 11209 | |
| 11210 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11211 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11212 | * @phba: Pointer to HBA context object. |
| 11213 | * @eqe: Pointer to fast-path event queue entry. |
| 11214 | * |
| 11215 | * This routine process a event queue entry from the slow-path event queue. |
| 11216 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11217 | * completion event on a completion queue, if not, an error shall be logged |
| 11218 | * and just return. Otherwise, it will get to the corresponding completion |
| 11219 | * queue and process all the entries on that completion queue, rearm the |
| 11220 | * completion queue, and then return. |
| 11221 | * |
| 11222 | **/ |
| 11223 | static void |
| 11224 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 11225 | { |
| 11226 | struct lpfc_queue *cq = NULL, *childq, *speq; |
| 11227 | struct lpfc_cqe *cqe; |
| 11228 | bool workposted = false; |
| 11229 | int ecount = 0; |
| 11230 | uint16_t cqid; |
| 11231 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11232 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11233 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11234 | "0359 Not a valid slow-path completion " |
| 11235 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11236 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11237 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11238 | return; |
| 11239 | } |
| 11240 | |
| 11241 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11242 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11243 | |
| 11244 | /* Search for completion queue pointer matching this cqid */ |
| 11245 | speq = phba->sli4_hba.sp_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11246 | /* sanity check on queue memory */ |
| 11247 | if (unlikely(!speq)) |
| 11248 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11249 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11250 | if (childq->queue_id == cqid) { |
| 11251 | cq = childq; |
| 11252 | break; |
| 11253 | } |
| 11254 | } |
| 11255 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11256 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11257 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11258 | "0365 Slow-path CQ identifier " |
| 11259 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11260 | return; |
| 11261 | } |
| 11262 | |
| 11263 | /* Process all the entries to the CQ */ |
| 11264 | switch (cq->type) { |
| 11265 | case LPFC_MCQ: |
| 11266 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11267 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11268 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11269 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11270 | } |
| 11271 | break; |
| 11272 | case LPFC_WCQ: |
| 11273 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11274 | if (cq->subtype == LPFC_FCP) |
| 11275 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11276 | cqe); |
| 11277 | else |
| 11278 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11279 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11280 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11281 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11282 | } |
| 11283 | break; |
| 11284 | default: |
| 11285 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11286 | "0370 Invalid completion queue type (%d)\n", |
| 11287 | cq->type); |
| 11288 | return; |
| 11289 | } |
| 11290 | |
| 11291 | /* Catch the no cq entry condition, log an error */ |
| 11292 | if (unlikely(ecount == 0)) |
| 11293 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11294 | "0371 No entry from the CQ: identifier " |
| 11295 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11296 | |
| 11297 | /* In any case, flash and re-arm the RCQ */ |
| 11298 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11299 | |
| 11300 | /* wake up worker thread if there are works to be done */ |
| 11301 | if (workposted) |
| 11302 | lpfc_worker_wake_up(phba); |
| 11303 | } |
| 11304 | |
| 11305 | /** |
| 11306 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry |
| 11307 | * @eqe: Pointer to fast-path completion queue entry. |
| 11308 | * |
| 11309 | * This routine process a fast-path work queue completion entry from fast-path |
| 11310 | * event queue for FCP command response completion. |
| 11311 | **/ |
| 11312 | static void |
| 11313 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, |
| 11314 | struct lpfc_wcqe_complete *wcqe) |
| 11315 | { |
| 11316 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
| 11317 | struct lpfc_iocbq *cmdiocbq; |
| 11318 | struct lpfc_iocbq irspiocbq; |
| 11319 | unsigned long iflags; |
| 11320 | |
| 11321 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11322 | pring->stats.iocb_event++; |
| 11323 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11324 | |
| 11325 | /* Check for response status */ |
| 11326 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11327 | /* If resource errors reported from HBA, reduce queue |
| 11328 | * depth of the SCSI device. |
| 11329 | */ |
| 11330 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11331 | IOSTAT_LOCAL_REJECT) && |
| 11332 | (wcqe->parameter == IOERR_NO_RESOURCES)) { |
| 11333 | phba->lpfc_rampdown_queue_depth(phba); |
| 11334 | } |
| 11335 | /* Log the error status */ |
| 11336 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11337 | "0373 FCP complete error: status=x%x, " |
| 11338 | "hw_status=x%x, total_data_specified=%d, " |
| 11339 | "parameter=x%x, word3=x%x\n", |
| 11340 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11341 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11342 | wcqe->total_data_placed, wcqe->parameter, |
| 11343 | wcqe->word3); |
| 11344 | } |
| 11345 | |
| 11346 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
| 11347 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11348 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11349 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11350 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11351 | if (unlikely(!cmdiocbq)) { |
| 11352 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11353 | "0374 FCP complete with no corresponding " |
| 11354 | "cmdiocb: iotag (%d)\n", |
| 11355 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11356 | return; |
| 11357 | } |
| 11358 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11359 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11360 | "0375 FCP cmdiocb not callback function " |
| 11361 | "iotag: (%d)\n", |
| 11362 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11363 | return; |
| 11364 | } |
| 11365 | |
| 11366 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11367 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11368 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11369 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11370 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11371 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11372 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11373 | } |
| 11374 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11375 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11376 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11377 | } |
| 11378 | |
| 11379 | /** |
| 11380 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11381 | * @phba: Pointer to HBA context object. |
| 11382 | * @cq: Pointer to completion queue. |
| 11383 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11384 | * |
| 11385 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11386 | * proper WQ release routine to the slow-path WQ. |
| 11387 | **/ |
| 11388 | static void |
| 11389 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11390 | struct lpfc_wcqe_release *wcqe) |
| 11391 | { |
| 11392 | struct lpfc_queue *childwq; |
| 11393 | bool wqid_matched = false; |
| 11394 | uint16_t fcp_wqid; |
| 11395 | |
| 11396 | /* Check for fast-path FCP work queue release */ |
| 11397 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11398 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11399 | if (childwq->queue_id == fcp_wqid) { |
| 11400 | lpfc_sli4_wq_release(childwq, |
| 11401 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11402 | wqid_matched = true; |
| 11403 | break; |
| 11404 | } |
| 11405 | } |
| 11406 | /* Report warning log message if no match found */ |
| 11407 | if (wqid_matched != true) |
| 11408 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11409 | "2580 Fast-path wqe consume event carries " |
| 11410 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11411 | } |
| 11412 | |
| 11413 | /** |
| 11414 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11415 | * @cq: Pointer to the completion queue. |
| 11416 | * @eqe: Pointer to fast-path completion queue entry. |
| 11417 | * |
| 11418 | * This routine process a fast-path work queue completion entry from fast-path |
| 11419 | * event queue for FCP command response completion. |
| 11420 | **/ |
| 11421 | static int |
| 11422 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11423 | struct lpfc_cqe *cqe) |
| 11424 | { |
| 11425 | struct lpfc_wcqe_release wcqe; |
| 11426 | bool workposted = false; |
| 11427 | |
| 11428 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11429 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11430 | |
| 11431 | /* Check and process for different type of WCQE and dispatch */ |
| 11432 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11433 | case CQE_CODE_COMPL_WQE: |
| 11434 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11435 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11436 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
| 11437 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11438 | break; |
| 11439 | case CQE_CODE_RELEASE_WQE: |
| 11440 | /* Process the WQ release event */ |
| 11441 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11442 | (struct lpfc_wcqe_release *)&wcqe); |
| 11443 | break; |
| 11444 | case CQE_CODE_XRI_ABORTED: |
| 11445 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11446 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11447 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11448 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11449 | break; |
| 11450 | default: |
| 11451 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11452 | "0144 Not a valid WCQE code: x%x\n", |
| 11453 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11454 | break; |
| 11455 | } |
| 11456 | return workposted; |
| 11457 | } |
| 11458 | |
| 11459 | /** |
| 11460 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry |
| 11461 | * @phba: Pointer to HBA context object. |
| 11462 | * @eqe: Pointer to fast-path event queue entry. |
| 11463 | * |
| 11464 | * This routine process a event queue entry from the fast-path event queue. |
| 11465 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11466 | * completion event on a completion queue, if not, an error shall be logged |
| 11467 | * and just return. Otherwise, it will get to the corresponding completion |
| 11468 | * queue and process all the entries on the completion queue, rearm the |
| 11469 | * completion queue, and then return. |
| 11470 | **/ |
| 11471 | static void |
| 11472 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11473 | uint32_t fcp_cqidx) |
| 11474 | { |
| 11475 | struct lpfc_queue *cq; |
| 11476 | struct lpfc_cqe *cqe; |
| 11477 | bool workposted = false; |
| 11478 | uint16_t cqid; |
| 11479 | int ecount = 0; |
| 11480 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11481 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11482 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11483 | "0366 Not a valid fast-path completion " |
| 11484 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11485 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11486 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11487 | return; |
| 11488 | } |
| 11489 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11490 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11491 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11492 | "3146 Fast-path completion queues " |
| 11493 | "does not exist\n"); |
| 11494 | return; |
| 11495 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11496 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; |
| 11497 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11498 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11499 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11500 | "0367 Fast-path completion queue " |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11501 | "(%d) does not exist\n", fcp_cqidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11502 | return; |
| 11503 | } |
| 11504 | |
| 11505 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11506 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11507 | if (unlikely(cqid != cq->queue_id)) { |
| 11508 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11509 | "0368 Miss-matched fast-path completion " |
| 11510 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11511 | cqid, cq->queue_id); |
| 11512 | return; |
| 11513 | } |
| 11514 | |
| 11515 | /* Process all the entries to the CQ */ |
| 11516 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11517 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11518 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11519 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11520 | } |
| 11521 | |
| 11522 | /* Catch the no cq entry condition */ |
| 11523 | if (unlikely(ecount == 0)) |
| 11524 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11525 | "0369 No entry from fast-path completion " |
| 11526 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11527 | |
| 11528 | /* In any case, flash and re-arm the CQ */ |
| 11529 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11530 | |
| 11531 | /* wake up worker thread if there are works to be done */ |
| 11532 | if (workposted) |
| 11533 | lpfc_worker_wake_up(phba); |
| 11534 | } |
| 11535 | |
| 11536 | static void |
| 11537 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11538 | { |
| 11539 | struct lpfc_eqe *eqe; |
| 11540 | |
| 11541 | /* walk all the EQ entries and drop on the floor */ |
| 11542 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11543 | ; |
| 11544 | |
| 11545 | /* Clear and re-arm the EQ */ |
| 11546 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11547 | } |
| 11548 | |
| 11549 | /** |
| 11550 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device |
| 11551 | * @irq: Interrupt number. |
| 11552 | * @dev_id: The device context pointer. |
| 11553 | * |
| 11554 | * This function is directly called from the PCI layer as an interrupt |
| 11555 | * service routine when device with SLI-4 interface spec is enabled with |
| 11556 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11557 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11558 | * interrupt mode, this function is called as part of the device-level |
| 11559 | * interrupt handler. When the PCI slot is in error recovery or the HBA is |
| 11560 | * undergoing initialization, the interrupt handler will not process the |
| 11561 | * interrupt. The link attention and ELS ring attention events are handled |
| 11562 | * by the worker thread. The interrupt handler signals the worker thread |
| 11563 | * and returns for these events. This function is called without any lock |
| 11564 | * held. It gets the hbalock to access and update SLI data structures. |
| 11565 | * |
| 11566 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11567 | * returns IRQ_NONE. |
| 11568 | **/ |
| 11569 | irqreturn_t |
| 11570 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) |
| 11571 | { |
| 11572 | struct lpfc_hba *phba; |
| 11573 | struct lpfc_queue *speq; |
| 11574 | struct lpfc_eqe *eqe; |
| 11575 | unsigned long iflag; |
| 11576 | int ecount = 0; |
| 11577 | |
| 11578 | /* |
| 11579 | * Get the driver's phba structure from the dev_id |
| 11580 | */ |
| 11581 | phba = (struct lpfc_hba *)dev_id; |
| 11582 | |
| 11583 | if (unlikely(!phba)) |
| 11584 | return IRQ_NONE; |
| 11585 | |
| 11586 | /* Get to the EQ struct associated with this vector */ |
| 11587 | speq = phba->sli4_hba.sp_eq; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11588 | if (unlikely(!speq)) |
| 11589 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11590 | |
| 11591 | /* Check device state for handling interrupt */ |
| 11592 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 11593 | /* Check again for link_state with lock held */ |
| 11594 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11595 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11596 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11597 | lpfc_sli4_eq_flush(phba, speq); |
| 11598 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11599 | return IRQ_NONE; |
| 11600 | } |
| 11601 | |
| 11602 | /* |
| 11603 | * Process all the event on FCP slow-path EQ |
| 11604 | */ |
| 11605 | while ((eqe = lpfc_sli4_eq_get(speq))) { |
| 11606 | lpfc_sli4_sp_handle_eqe(phba, eqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11607 | if (!(++ecount % speq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11608 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); |
| 11609 | } |
| 11610 | |
| 11611 | /* Always clear and re-arm the slow-path EQ */ |
| 11612 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); |
| 11613 | |
| 11614 | /* Catch the no cq entry condition */ |
| 11615 | if (unlikely(ecount == 0)) { |
| 11616 | if (phba->intr_type == MSIX) |
| 11617 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11618 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11619 | "0357 MSI-X interrupt with no EQE\n"); |
| 11620 | else |
| 11621 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11622 | return IRQ_NONE; |
| 11623 | } |
| 11624 | |
| 11625 | return IRQ_HANDLED; |
| 11626 | } /* lpfc_sli4_sp_intr_handler */ |
| 11627 | |
| 11628 | /** |
| 11629 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device |
| 11630 | * @irq: Interrupt number. |
| 11631 | * @dev_id: The device context pointer. |
| 11632 | * |
| 11633 | * This function is directly called from the PCI layer as an interrupt |
| 11634 | * service routine when device with SLI-4 interface spec is enabled with |
| 11635 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11636 | * ring event in the HBA. However, when the device is enabled with either |
| 11637 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11638 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11639 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11640 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11641 | * the intrrupt context. This function is called without any lock held. |
| 11642 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11643 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11644 | * equal to that of FCP CQ index. |
| 11645 | * |
| 11646 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11647 | * returns IRQ_NONE. |
| 11648 | **/ |
| 11649 | irqreturn_t |
| 11650 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) |
| 11651 | { |
| 11652 | struct lpfc_hba *phba; |
| 11653 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11654 | struct lpfc_queue *fpeq; |
| 11655 | struct lpfc_eqe *eqe; |
| 11656 | unsigned long iflag; |
| 11657 | int ecount = 0; |
| 11658 | uint32_t fcp_eqidx; |
| 11659 | |
| 11660 | /* Get the driver's phba structure from the dev_id */ |
| 11661 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11662 | phba = fcp_eq_hdl->phba; |
| 11663 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11664 | |
| 11665 | if (unlikely(!phba)) |
| 11666 | return IRQ_NONE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11667 | if (unlikely(!phba->sli4_hba.fp_eq)) |
| 11668 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11669 | |
| 11670 | /* Get to the EQ struct associated with this vector */ |
| 11671 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11672 | if (unlikely(!fpeq)) |
| 11673 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11674 | |
| 11675 | /* Check device state for handling interrupt */ |
| 11676 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 11677 | /* Check again for link_state with lock held */ |
| 11678 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11679 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11680 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11681 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11682 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11683 | return IRQ_NONE; |
| 11684 | } |
| 11685 | |
| 11686 | /* |
| 11687 | * Process all the event on FCP fast-path EQ |
| 11688 | */ |
| 11689 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 11690 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11691 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11692 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
| 11693 | } |
| 11694 | |
| 11695 | /* Always clear and re-arm the fast-path EQ */ |
| 11696 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11697 | |
| 11698 | if (unlikely(ecount == 0)) { |
| 11699 | if (phba->intr_type == MSIX) |
| 11700 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11701 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11702 | "0358 MSI-X interrupt with no EQE\n"); |
| 11703 | else |
| 11704 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11705 | return IRQ_NONE; |
| 11706 | } |
| 11707 | |
| 11708 | return IRQ_HANDLED; |
| 11709 | } /* lpfc_sli4_fp_intr_handler */ |
| 11710 | |
| 11711 | /** |
| 11712 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 11713 | * @irq: Interrupt number. |
| 11714 | * @dev_id: The device context pointer. |
| 11715 | * |
| 11716 | * This function is the device-level interrupt handler to device with SLI-4 |
| 11717 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 11718 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 11719 | * driver attention. This function invokes the slow-path interrupt attention |
| 11720 | * handling function and fast-path interrupt attention handling function in |
| 11721 | * turn to process the relevant HBA attention events. This function is called |
| 11722 | * without any lock held. It gets the hbalock to access and update SLI data |
| 11723 | * structures. |
| 11724 | * |
| 11725 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11726 | * returns IRQ_NONE. |
| 11727 | **/ |
| 11728 | irqreturn_t |
| 11729 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 11730 | { |
| 11731 | struct lpfc_hba *phba; |
| 11732 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11733 | bool fp_handled = false; |
| 11734 | uint32_t fcp_eqidx; |
| 11735 | |
| 11736 | /* Get the driver's phba structure from the dev_id */ |
| 11737 | phba = (struct lpfc_hba *)dev_id; |
| 11738 | |
| 11739 | if (unlikely(!phba)) |
| 11740 | return IRQ_NONE; |
| 11741 | |
| 11742 | /* |
| 11743 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11744 | */ |
| 11745 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); |
| 11746 | |
| 11747 | /* |
| 11748 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11749 | */ |
| 11750 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 11751 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, |
| 11752 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
| 11753 | if (fp_irq_rc == IRQ_HANDLED) |
| 11754 | fp_handled |= true; |
| 11755 | } |
| 11756 | |
| 11757 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; |
| 11758 | } /* lpfc_sli4_intr_handler */ |
| 11759 | |
| 11760 | /** |
| 11761 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 11762 | * @queue: The queue structure to free. |
| 11763 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 11764 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11765 | * the host resident queue. This function must be called after destroying the |
| 11766 | * queue on the HBA. |
| 11767 | **/ |
| 11768 | void |
| 11769 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 11770 | { |
| 11771 | struct lpfc_dmabuf *dmabuf; |
| 11772 | |
| 11773 | if (!queue) |
| 11774 | return; |
| 11775 | |
| 11776 | while (!list_empty(&queue->page_list)) { |
| 11777 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 11778 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 11779 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11780 | dmabuf->virt, dmabuf->phys); |
| 11781 | kfree(dmabuf); |
| 11782 | } |
| 11783 | kfree(queue); |
| 11784 | return; |
| 11785 | } |
| 11786 | |
| 11787 | /** |
| 11788 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 11789 | * @phba: The HBA that this queue is being created on. |
| 11790 | * @entry_size: The size of each queue entry for this queue. |
| 11791 | * @entry count: The number of entries that this queue will handle. |
| 11792 | * |
| 11793 | * This function allocates a queue structure and the DMAable memory used for |
| 11794 | * the host resident queue. This function must be called before creating the |
| 11795 | * queue on the HBA. |
| 11796 | **/ |
| 11797 | struct lpfc_queue * |
| 11798 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 11799 | uint32_t entry_count) |
| 11800 | { |
| 11801 | struct lpfc_queue *queue; |
| 11802 | struct lpfc_dmabuf *dmabuf; |
| 11803 | int x, total_qe_count; |
| 11804 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11805 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11806 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11807 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 11808 | hw_page_size = SLI4_PAGE_SIZE; |
| 11809 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11810 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 11811 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 11812 | if (!queue) |
| 11813 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11814 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 11815 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11816 | INIT_LIST_HEAD(&queue->list); |
| 11817 | INIT_LIST_HEAD(&queue->page_list); |
| 11818 | INIT_LIST_HEAD(&queue->child_list); |
| 11819 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 11820 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 11821 | if (!dmabuf) |
| 11822 | goto out_fail; |
| 11823 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11824 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11825 | GFP_KERNEL); |
| 11826 | if (!dmabuf->virt) { |
| 11827 | kfree(dmabuf); |
| 11828 | goto out_fail; |
| 11829 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11830 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11831 | dmabuf->buffer_tag = x; |
| 11832 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 11833 | /* initialize queue's entry array */ |
| 11834 | dma_pointer = dmabuf->virt; |
| 11835 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11836 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11837 | total_qe_count++, dma_pointer += entry_size) { |
| 11838 | queue->qe[total_qe_count].address = dma_pointer; |
| 11839 | } |
| 11840 | } |
| 11841 | queue->entry_size = entry_size; |
| 11842 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11843 | |
| 11844 | /* |
| 11845 | * entry_repost is calculated based on the number of entries in the |
| 11846 | * queue. This works out except for RQs. If buffers are NOT initially |
| 11847 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 11848 | */ |
| 11849 | queue->entry_repost = (entry_count >> 3); |
| 11850 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 11851 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11852 | queue->phba = phba; |
| 11853 | |
| 11854 | return queue; |
| 11855 | out_fail: |
| 11856 | lpfc_sli4_queue_free(queue); |
| 11857 | return NULL; |
| 11858 | } |
| 11859 | |
| 11860 | /** |
| 11861 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 11862 | * @phba: HBA structure that indicates port to create a queue on. |
| 11863 | * @eq: The queue structure to use to create the event queue. |
| 11864 | * @imax: The maximum interrupt per second limit. |
| 11865 | * |
| 11866 | * This function creates an event queue, as detailed in @eq, on a port, |
| 11867 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 11868 | * |
| 11869 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 11870 | * is used to get the entry count and entry size that are necessary to |
| 11871 | * determine the number of pages to allocate and use for this queue. This |
| 11872 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 11873 | * event queue. This function is asynchronous and will wait for the mailbox |
| 11874 | * command to finish before continuing. |
| 11875 | * |
| 11876 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 11877 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 11878 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11879 | **/ |
| 11880 | uint32_t |
| 11881 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) |
| 11882 | { |
| 11883 | struct lpfc_mbx_eq_create *eq_create; |
| 11884 | LPFC_MBOXQ_t *mbox; |
| 11885 | int rc, length, status = 0; |
| 11886 | struct lpfc_dmabuf *dmabuf; |
| 11887 | uint32_t shdr_status, shdr_add_status; |
| 11888 | union lpfc_sli4_cfg_shdr *shdr; |
| 11889 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 11890 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 11891 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11892 | /* sanity check on queue memory */ |
| 11893 | if (!eq) |
| 11894 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 11895 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 11896 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11897 | |
| 11898 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 11899 | if (!mbox) |
| 11900 | return -ENOMEM; |
| 11901 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 11902 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 11903 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11904 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 11905 | length, LPFC_SLI4_MBX_EMBED); |
| 11906 | eq_create = &mbox->u.mqe.un.eq_create; |
| 11907 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 11908 | eq->page_count); |
| 11909 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 11910 | LPFC_EQE_SIZE); |
| 11911 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 11912 | /* Calculate delay multiper from maximum interrupt per second */ |
| 11913 | dmult = LPFC_DMULT_CONST/imax - 1; |
| 11914 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 11915 | dmult); |
| 11916 | switch (eq->entry_count) { |
| 11917 | default: |
| 11918 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11919 | "0360 Unsupported EQ count. (%d)\n", |
| 11920 | eq->entry_count); |
| 11921 | if (eq->entry_count < 256) |
| 11922 | return -EINVAL; |
| 11923 | /* otherwise default to smallest count (drop through) */ |
| 11924 | case 256: |
| 11925 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 11926 | LPFC_EQ_CNT_256); |
| 11927 | break; |
| 11928 | case 512: |
| 11929 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 11930 | LPFC_EQ_CNT_512); |
| 11931 | break; |
| 11932 | case 1024: |
| 11933 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 11934 | LPFC_EQ_CNT_1024); |
| 11935 | break; |
| 11936 | case 2048: |
| 11937 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 11938 | LPFC_EQ_CNT_2048); |
| 11939 | break; |
| 11940 | case 4096: |
| 11941 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 11942 | LPFC_EQ_CNT_4096); |
| 11943 | break; |
| 11944 | } |
| 11945 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 11946 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11947 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 11948 | putPaddrLow(dmabuf->phys); |
| 11949 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 11950 | putPaddrHigh(dmabuf->phys); |
| 11951 | } |
| 11952 | mbox->vport = phba->pport; |
| 11953 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11954 | mbox->context1 = NULL; |
| 11955 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 11956 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 11957 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 11958 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 11959 | if (shdr_status || shdr_add_status || rc) { |
| 11960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11961 | "2500 EQ_CREATE mailbox failed with " |
| 11962 | "status x%x add_status x%x, mbx status x%x\n", |
| 11963 | shdr_status, shdr_add_status, rc); |
| 11964 | status = -ENXIO; |
| 11965 | } |
| 11966 | eq->type = LPFC_EQ; |
| 11967 | eq->subtype = LPFC_NONE; |
| 11968 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 11969 | if (eq->queue_id == 0xFFFF) |
| 11970 | status = -ENXIO; |
| 11971 | eq->host_index = 0; |
| 11972 | eq->hba_index = 0; |
| 11973 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11974 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11975 | return status; |
| 11976 | } |
| 11977 | |
| 11978 | /** |
| 11979 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 11980 | * @phba: HBA structure that indicates port to create a queue on. |
| 11981 | * @cq: The queue structure to use to create the completion queue. |
| 11982 | * @eq: The event queue to bind this completion queue to. |
| 11983 | * |
| 11984 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 11985 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 11986 | * |
| 11987 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 11988 | * is used to get the entry count and entry size that are necessary to |
| 11989 | * determine the number of pages to allocate and use for this queue. The @eq |
| 11990 | * is used to indicate which event queue to bind this completion queue to. This |
| 11991 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 11992 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 11993 | * command to finish before continuing. |
| 11994 | * |
| 11995 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 11996 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 11997 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11998 | **/ |
| 11999 | uint32_t |
| 12000 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12001 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12002 | { |
| 12003 | struct lpfc_mbx_cq_create *cq_create; |
| 12004 | struct lpfc_dmabuf *dmabuf; |
| 12005 | LPFC_MBOXQ_t *mbox; |
| 12006 | int rc, length, status = 0; |
| 12007 | uint32_t shdr_status, shdr_add_status; |
| 12008 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12009 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12010 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12011 | /* sanity check on queue memory */ |
| 12012 | if (!cq || !eq) |
| 12013 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12014 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12015 | hw_page_size = SLI4_PAGE_SIZE; |
| 12016 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12017 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12018 | if (!mbox) |
| 12019 | return -ENOMEM; |
| 12020 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12021 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12022 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12023 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12024 | length, LPFC_SLI4_MBX_EMBED); |
| 12025 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12026 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12027 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12028 | cq->page_count); |
| 12029 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12030 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12031 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12032 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12033 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12034 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12035 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12036 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12037 | eq->queue_id); |
| 12038 | } else { |
| 12039 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12040 | eq->queue_id); |
| 12041 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12042 | switch (cq->entry_count) { |
| 12043 | default: |
| 12044 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12045 | "0361 Unsupported CQ count. (%d)\n", |
| 12046 | cq->entry_count); |
| 12047 | if (cq->entry_count < 256) |
| 12048 | return -EINVAL; |
| 12049 | /* otherwise default to smallest count (drop through) */ |
| 12050 | case 256: |
| 12051 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12052 | LPFC_CQ_CNT_256); |
| 12053 | break; |
| 12054 | case 512: |
| 12055 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12056 | LPFC_CQ_CNT_512); |
| 12057 | break; |
| 12058 | case 1024: |
| 12059 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12060 | LPFC_CQ_CNT_1024); |
| 12061 | break; |
| 12062 | } |
| 12063 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12064 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12065 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12066 | putPaddrLow(dmabuf->phys); |
| 12067 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12068 | putPaddrHigh(dmabuf->phys); |
| 12069 | } |
| 12070 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12071 | |
| 12072 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12073 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12074 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12075 | if (shdr_status || shdr_add_status || rc) { |
| 12076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12077 | "2501 CQ_CREATE mailbox failed with " |
| 12078 | "status x%x add_status x%x, mbx status x%x\n", |
| 12079 | shdr_status, shdr_add_status, rc); |
| 12080 | status = -ENXIO; |
| 12081 | goto out; |
| 12082 | } |
| 12083 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12084 | if (cq->queue_id == 0xFFFF) { |
| 12085 | status = -ENXIO; |
| 12086 | goto out; |
| 12087 | } |
| 12088 | /* link the cq onto the parent eq child list */ |
| 12089 | list_add_tail(&cq->list, &eq->child_list); |
| 12090 | /* Set up completion queue's type and subtype */ |
| 12091 | cq->type = type; |
| 12092 | cq->subtype = subtype; |
| 12093 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12094 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12095 | cq->host_index = 0; |
| 12096 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12097 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12098 | out: |
| 12099 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12100 | return status; |
| 12101 | } |
| 12102 | |
| 12103 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12104 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12105 | * @phba: HBA structure that indicates port to create a queue on. |
| 12106 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12107 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12108 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12109 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12110 | * This function provides failback (fb) functionality when the |
| 12111 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12112 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12113 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12114 | * This routine cannot fail as all attributes were previously accessed and |
| 12115 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12116 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12117 | static void |
| 12118 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12119 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12120 | { |
| 12121 | struct lpfc_mbx_mq_create *mq_create; |
| 12122 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12123 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12124 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12125 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12126 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12127 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12128 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12129 | length, LPFC_SLI4_MBX_EMBED); |
| 12130 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12131 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12132 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12133 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12134 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12135 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12136 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12137 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12138 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12139 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12140 | break; |
| 12141 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12142 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12143 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12144 | break; |
| 12145 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12146 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12147 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12148 | break; |
| 12149 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12150 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12151 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12152 | break; |
| 12153 | } |
| 12154 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12155 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12156 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12157 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12158 | putPaddrHigh(dmabuf->phys); |
| 12159 | } |
| 12160 | } |
| 12161 | |
| 12162 | /** |
| 12163 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12164 | * @phba: HBA structure that indicates port to create a queue on. |
| 12165 | * @mq: The queue structure to use to create the mailbox queue. |
| 12166 | * @cq: The completion queue to associate with this cq. |
| 12167 | * @subtype: The queue's subtype. |
| 12168 | * |
| 12169 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12170 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12171 | * |
| 12172 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12173 | * is used to get the entry count and entry size that are necessary to |
| 12174 | * determine the number of pages to allocate and use for this queue. This |
| 12175 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12176 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12177 | * command to finish before continuing. |
| 12178 | * |
| 12179 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12180 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12181 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12182 | **/ |
| 12183 | int32_t |
| 12184 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12185 | struct lpfc_queue *cq, uint32_t subtype) |
| 12186 | { |
| 12187 | struct lpfc_mbx_mq_create *mq_create; |
| 12188 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12189 | struct lpfc_dmabuf *dmabuf; |
| 12190 | LPFC_MBOXQ_t *mbox; |
| 12191 | int rc, length, status = 0; |
| 12192 | uint32_t shdr_status, shdr_add_status; |
| 12193 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12194 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12195 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12196 | /* sanity check on queue memory */ |
| 12197 | if (!mq || !cq) |
| 12198 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12199 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12200 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12201 | |
| 12202 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12203 | if (!mbox) |
| 12204 | return -ENOMEM; |
| 12205 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12206 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12207 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12208 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12209 | length, LPFC_SLI4_MBX_EMBED); |
| 12210 | |
| 12211 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12212 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12213 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12214 | &mq_create_ext->u.request, mq->page_count); |
| 12215 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12216 | &mq_create_ext->u.request, 1); |
| 12217 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12218 | &mq_create_ext->u.request, 1); |
| 12219 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12220 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12221 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12222 | &mq_create_ext->u.request, 1); |
| 12223 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12224 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12225 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12226 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12227 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12228 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12229 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12230 | cq->queue_id); |
| 12231 | else |
| 12232 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12233 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12234 | switch (mq->entry_count) { |
| 12235 | default: |
| 12236 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12237 | "0362 Unsupported MQ count. (%d)\n", |
| 12238 | mq->entry_count); |
| 12239 | if (mq->entry_count < 16) |
| 12240 | return -EINVAL; |
| 12241 | /* otherwise default to smallest count (drop through) */ |
| 12242 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12243 | bf_set(lpfc_mq_context_ring_size, |
| 12244 | &mq_create_ext->u.request.context, |
| 12245 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12246 | break; |
| 12247 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12248 | bf_set(lpfc_mq_context_ring_size, |
| 12249 | &mq_create_ext->u.request.context, |
| 12250 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12251 | break; |
| 12252 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12253 | bf_set(lpfc_mq_context_ring_size, |
| 12254 | &mq_create_ext->u.request.context, |
| 12255 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12256 | break; |
| 12257 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12258 | bf_set(lpfc_mq_context_ring_size, |
| 12259 | &mq_create_ext->u.request.context, |
| 12260 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12261 | break; |
| 12262 | } |
| 12263 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12264 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12265 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12266 | putPaddrLow(dmabuf->phys); |
| 12267 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12268 | putPaddrHigh(dmabuf->phys); |
| 12269 | } |
| 12270 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12271 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12272 | &mq_create_ext->u.response); |
| 12273 | if (rc != MBX_SUCCESS) { |
| 12274 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12275 | "2795 MQ_CREATE_EXT failed with " |
| 12276 | "status x%x. Failback to MQ_CREATE.\n", |
| 12277 | rc); |
| 12278 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12279 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12280 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12281 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12282 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12283 | &mq_create->u.response); |
| 12284 | } |
| 12285 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12286 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12287 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12288 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12289 | if (shdr_status || shdr_add_status || rc) { |
| 12290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12291 | "2502 MQ_CREATE mailbox failed with " |
| 12292 | "status x%x add_status x%x, mbx status x%x\n", |
| 12293 | shdr_status, shdr_add_status, rc); |
| 12294 | status = -ENXIO; |
| 12295 | goto out; |
| 12296 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12297 | if (mq->queue_id == 0xFFFF) { |
| 12298 | status = -ENXIO; |
| 12299 | goto out; |
| 12300 | } |
| 12301 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12302 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12303 | mq->subtype = subtype; |
| 12304 | mq->host_index = 0; |
| 12305 | mq->hba_index = 0; |
| 12306 | |
| 12307 | /* link the mq onto the parent cq child list */ |
| 12308 | list_add_tail(&mq->list, &cq->child_list); |
| 12309 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12310 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12311 | return status; |
| 12312 | } |
| 12313 | |
| 12314 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12315 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12316 | * @phba: HBA structure that indicates port to create a queue on. |
| 12317 | * @wq: The queue structure to use to create the work queue. |
| 12318 | * @cq: The completion queue to bind this work queue to. |
| 12319 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12320 | * |
| 12321 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12322 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12323 | * |
| 12324 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12325 | * is used to get the entry count and entry size that are necessary to |
| 12326 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12327 | * is used to indicate which completion queue to bind this work queue to. This |
| 12328 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12329 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12330 | * command to finish before continuing. |
| 12331 | * |
| 12332 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12333 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12334 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12335 | **/ |
| 12336 | uint32_t |
| 12337 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12338 | struct lpfc_queue *cq, uint32_t subtype) |
| 12339 | { |
| 12340 | struct lpfc_mbx_wq_create *wq_create; |
| 12341 | struct lpfc_dmabuf *dmabuf; |
| 12342 | LPFC_MBOXQ_t *mbox; |
| 12343 | int rc, length, status = 0; |
| 12344 | uint32_t shdr_status, shdr_add_status; |
| 12345 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12346 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12347 | struct dma_address *page; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12348 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12349 | /* sanity check on queue memory */ |
| 12350 | if (!wq || !cq) |
| 12351 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12352 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12353 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12354 | |
| 12355 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12356 | if (!mbox) |
| 12357 | return -ENOMEM; |
| 12358 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12359 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12360 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12361 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12362 | length, LPFC_SLI4_MBX_EMBED); |
| 12363 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12364 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12365 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12366 | wq->page_count); |
| 12367 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12368 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12369 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12370 | phba->sli4_hba.pc_sli4_params.wqv); |
| 12371 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12372 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12373 | wq->entry_count); |
| 12374 | switch (wq->entry_size) { |
| 12375 | default: |
| 12376 | case 64: |
| 12377 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12378 | &wq_create->u.request_1, |
| 12379 | LPFC_WQ_WQE_SIZE_64); |
| 12380 | break; |
| 12381 | case 128: |
| 12382 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12383 | &wq_create->u.request_1, |
| 12384 | LPFC_WQ_WQE_SIZE_128); |
| 12385 | break; |
| 12386 | } |
| 12387 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12388 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12389 | page = wq_create->u.request_1.page; |
| 12390 | } else { |
| 12391 | page = wq_create->u.request.page; |
| 12392 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12393 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12394 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12395 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12396 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12397 | } |
| 12398 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12399 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12400 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12401 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12402 | if (shdr_status || shdr_add_status || rc) { |
| 12403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12404 | "2503 WQ_CREATE mailbox failed with " |
| 12405 | "status x%x add_status x%x, mbx status x%x\n", |
| 12406 | shdr_status, shdr_add_status, rc); |
| 12407 | status = -ENXIO; |
| 12408 | goto out; |
| 12409 | } |
| 12410 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12411 | if (wq->queue_id == 0xFFFF) { |
| 12412 | status = -ENXIO; |
| 12413 | goto out; |
| 12414 | } |
| 12415 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12416 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12417 | wq->subtype = subtype; |
| 12418 | wq->host_index = 0; |
| 12419 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12420 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12421 | |
| 12422 | /* link the wq onto the parent cq child list */ |
| 12423 | list_add_tail(&wq->list, &cq->child_list); |
| 12424 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12425 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12426 | return status; |
| 12427 | } |
| 12428 | |
| 12429 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12430 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12431 | * @phba: HBA structure that indicates port to create a queue on. |
| 12432 | * @rq: The queue structure to use for the receive queue. |
| 12433 | * @qno: The associated HBQ number |
| 12434 | * |
| 12435 | * |
| 12436 | * For SLI4 we need to adjust the RQ repost value based on |
| 12437 | * the number of buffers that are initially posted to the RQ. |
| 12438 | */ |
| 12439 | void |
| 12440 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12441 | { |
| 12442 | uint32_t cnt; |
| 12443 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12444 | /* sanity check on queue memory */ |
| 12445 | if (!rq) |
| 12446 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12447 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12448 | |
| 12449 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12450 | cnt = (cnt >> 3); |
| 12451 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12452 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12453 | |
| 12454 | rq->entry_repost = cnt; |
| 12455 | } |
| 12456 | |
| 12457 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12458 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12459 | * @phba: HBA structure that indicates port to create a queue on. |
| 12460 | * @hrq: The queue structure to use to create the header receive queue. |
| 12461 | * @drq: The queue structure to use to create the data receive queue. |
| 12462 | * @cq: The completion queue to bind this work queue to. |
| 12463 | * |
| 12464 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12465 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12466 | * to the HBA. |
| 12467 | * |
| 12468 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12469 | * struct is used to get the entry count that is necessary to determine the |
| 12470 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12471 | * completion queue to bind received buffers that are posted to these queues to. |
| 12472 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12473 | * receive queue pair. This function is asynchronous and will wait for the |
| 12474 | * mailbox command to finish before continuing. |
| 12475 | * |
| 12476 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12477 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12478 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12479 | **/ |
| 12480 | uint32_t |
| 12481 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12482 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12483 | { |
| 12484 | struct lpfc_mbx_rq_create *rq_create; |
| 12485 | struct lpfc_dmabuf *dmabuf; |
| 12486 | LPFC_MBOXQ_t *mbox; |
| 12487 | int rc, length, status = 0; |
| 12488 | uint32_t shdr_status, shdr_add_status; |
| 12489 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12490 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12491 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12492 | /* sanity check on queue memory */ |
| 12493 | if (!hrq || !drq || !cq) |
| 12494 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12495 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12496 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12497 | |
| 12498 | if (hrq->entry_count != drq->entry_count) |
| 12499 | return -EINVAL; |
| 12500 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12501 | if (!mbox) |
| 12502 | return -ENOMEM; |
| 12503 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12504 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12505 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12506 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12507 | length, LPFC_SLI4_MBX_EMBED); |
| 12508 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12509 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12510 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12511 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12512 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12513 | bf_set(lpfc_rq_context_rqe_count_1, |
| 12514 | &rq_create->u.request.context, |
| 12515 | hrq->entry_count); |
| 12516 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12517 | bf_set(lpfc_rq_context_rqe_size, |
| 12518 | &rq_create->u.request.context, |
| 12519 | LPFC_RQE_SIZE_8); |
| 12520 | bf_set(lpfc_rq_context_page_size, |
| 12521 | &rq_create->u.request.context, |
| 12522 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12523 | } else { |
| 12524 | switch (hrq->entry_count) { |
| 12525 | default: |
| 12526 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12527 | "2535 Unsupported RQ count. (%d)\n", |
| 12528 | hrq->entry_count); |
| 12529 | if (hrq->entry_count < 512) |
| 12530 | return -EINVAL; |
| 12531 | /* otherwise default to smallest count (drop through) */ |
| 12532 | case 512: |
| 12533 | bf_set(lpfc_rq_context_rqe_count, |
| 12534 | &rq_create->u.request.context, |
| 12535 | LPFC_RQ_RING_SIZE_512); |
| 12536 | break; |
| 12537 | case 1024: |
| 12538 | bf_set(lpfc_rq_context_rqe_count, |
| 12539 | &rq_create->u.request.context, |
| 12540 | LPFC_RQ_RING_SIZE_1024); |
| 12541 | break; |
| 12542 | case 2048: |
| 12543 | bf_set(lpfc_rq_context_rqe_count, |
| 12544 | &rq_create->u.request.context, |
| 12545 | LPFC_RQ_RING_SIZE_2048); |
| 12546 | break; |
| 12547 | case 4096: |
| 12548 | bf_set(lpfc_rq_context_rqe_count, |
| 12549 | &rq_create->u.request.context, |
| 12550 | LPFC_RQ_RING_SIZE_4096); |
| 12551 | break; |
| 12552 | } |
| 12553 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12554 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12555 | } |
| 12556 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12557 | cq->queue_id); |
| 12558 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12559 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12560 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12561 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12562 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12563 | putPaddrLow(dmabuf->phys); |
| 12564 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12565 | putPaddrHigh(dmabuf->phys); |
| 12566 | } |
| 12567 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12568 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12569 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12570 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12571 | if (shdr_status || shdr_add_status || rc) { |
| 12572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12573 | "2504 RQ_CREATE mailbox failed with " |
| 12574 | "status x%x add_status x%x, mbx status x%x\n", |
| 12575 | shdr_status, shdr_add_status, rc); |
| 12576 | status = -ENXIO; |
| 12577 | goto out; |
| 12578 | } |
| 12579 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12580 | if (hrq->queue_id == 0xFFFF) { |
| 12581 | status = -ENXIO; |
| 12582 | goto out; |
| 12583 | } |
| 12584 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12585 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12586 | hrq->subtype = subtype; |
| 12587 | hrq->host_index = 0; |
| 12588 | hrq->hba_index = 0; |
| 12589 | |
| 12590 | /* now create the data queue */ |
| 12591 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12592 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12593 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12594 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12595 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12596 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12597 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12598 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12599 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12600 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 12601 | LPFC_RQE_SIZE_8); |
| 12602 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 12603 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12604 | } else { |
| 12605 | switch (drq->entry_count) { |
| 12606 | default: |
| 12607 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12608 | "2536 Unsupported RQ count. (%d)\n", |
| 12609 | drq->entry_count); |
| 12610 | if (drq->entry_count < 512) |
| 12611 | return -EINVAL; |
| 12612 | /* otherwise default to smallest count (drop through) */ |
| 12613 | case 512: |
| 12614 | bf_set(lpfc_rq_context_rqe_count, |
| 12615 | &rq_create->u.request.context, |
| 12616 | LPFC_RQ_RING_SIZE_512); |
| 12617 | break; |
| 12618 | case 1024: |
| 12619 | bf_set(lpfc_rq_context_rqe_count, |
| 12620 | &rq_create->u.request.context, |
| 12621 | LPFC_RQ_RING_SIZE_1024); |
| 12622 | break; |
| 12623 | case 2048: |
| 12624 | bf_set(lpfc_rq_context_rqe_count, |
| 12625 | &rq_create->u.request.context, |
| 12626 | LPFC_RQ_RING_SIZE_2048); |
| 12627 | break; |
| 12628 | case 4096: |
| 12629 | bf_set(lpfc_rq_context_rqe_count, |
| 12630 | &rq_create->u.request.context, |
| 12631 | LPFC_RQ_RING_SIZE_4096); |
| 12632 | break; |
| 12633 | } |
| 12634 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12635 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12636 | } |
| 12637 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12638 | cq->queue_id); |
| 12639 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12640 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12641 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 12642 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12643 | putPaddrLow(dmabuf->phys); |
| 12644 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12645 | putPaddrHigh(dmabuf->phys); |
| 12646 | } |
| 12647 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12648 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12649 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12650 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12651 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12652 | if (shdr_status || shdr_add_status || rc) { |
| 12653 | status = -ENXIO; |
| 12654 | goto out; |
| 12655 | } |
| 12656 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12657 | if (drq->queue_id == 0xFFFF) { |
| 12658 | status = -ENXIO; |
| 12659 | goto out; |
| 12660 | } |
| 12661 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12662 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12663 | drq->subtype = subtype; |
| 12664 | drq->host_index = 0; |
| 12665 | drq->hba_index = 0; |
| 12666 | |
| 12667 | /* link the header and data RQs onto the parent cq child list */ |
| 12668 | list_add_tail(&hrq->list, &cq->child_list); |
| 12669 | list_add_tail(&drq->list, &cq->child_list); |
| 12670 | |
| 12671 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12672 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12673 | return status; |
| 12674 | } |
| 12675 | |
| 12676 | /** |
| 12677 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 12678 | * @eq: The queue structure associated with the queue to destroy. |
| 12679 | * |
| 12680 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 12681 | * command, specific to the type of queue, to the HBA. |
| 12682 | * |
| 12683 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 12684 | * |
| 12685 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12686 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12687 | **/ |
| 12688 | uint32_t |
| 12689 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12690 | { |
| 12691 | LPFC_MBOXQ_t *mbox; |
| 12692 | int rc, length, status = 0; |
| 12693 | uint32_t shdr_status, shdr_add_status; |
| 12694 | union lpfc_sli4_cfg_shdr *shdr; |
| 12695 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12696 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12697 | if (!eq) |
| 12698 | return -ENODEV; |
| 12699 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12700 | if (!mbox) |
| 12701 | return -ENOMEM; |
| 12702 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 12703 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12704 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12705 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 12706 | length, LPFC_SLI4_MBX_EMBED); |
| 12707 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 12708 | eq->queue_id); |
| 12709 | mbox->vport = eq->phba->pport; |
| 12710 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12711 | |
| 12712 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 12713 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12714 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12715 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 12716 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12717 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12718 | if (shdr_status || shdr_add_status || rc) { |
| 12719 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12720 | "2505 EQ_DESTROY mailbox failed with " |
| 12721 | "status x%x add_status x%x, mbx status x%x\n", |
| 12722 | shdr_status, shdr_add_status, rc); |
| 12723 | status = -ENXIO; |
| 12724 | } |
| 12725 | |
| 12726 | /* Remove eq from any list */ |
| 12727 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12728 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12729 | return status; |
| 12730 | } |
| 12731 | |
| 12732 | /** |
| 12733 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 12734 | * @cq: The queue structure associated with the queue to destroy. |
| 12735 | * |
| 12736 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 12737 | * command, specific to the type of queue, to the HBA. |
| 12738 | * |
| 12739 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 12740 | * |
| 12741 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12742 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12743 | **/ |
| 12744 | uint32_t |
| 12745 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 12746 | { |
| 12747 | LPFC_MBOXQ_t *mbox; |
| 12748 | int rc, length, status = 0; |
| 12749 | uint32_t shdr_status, shdr_add_status; |
| 12750 | union lpfc_sli4_cfg_shdr *shdr; |
| 12751 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12752 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12753 | if (!cq) |
| 12754 | return -ENODEV; |
| 12755 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12756 | if (!mbox) |
| 12757 | return -ENOMEM; |
| 12758 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 12759 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12760 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12761 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 12762 | length, LPFC_SLI4_MBX_EMBED); |
| 12763 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 12764 | cq->queue_id); |
| 12765 | mbox->vport = cq->phba->pport; |
| 12766 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12767 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 12768 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12769 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12770 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 12771 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12772 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12773 | if (shdr_status || shdr_add_status || rc) { |
| 12774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12775 | "2506 CQ_DESTROY mailbox failed with " |
| 12776 | "status x%x add_status x%x, mbx status x%x\n", |
| 12777 | shdr_status, shdr_add_status, rc); |
| 12778 | status = -ENXIO; |
| 12779 | } |
| 12780 | /* Remove cq from any list */ |
| 12781 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12782 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12783 | return status; |
| 12784 | } |
| 12785 | |
| 12786 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12787 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 12788 | * @qm: The queue structure associated with the queue to destroy. |
| 12789 | * |
| 12790 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 12791 | * command, specific to the type of queue, to the HBA. |
| 12792 | * |
| 12793 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 12794 | * |
| 12795 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12796 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12797 | **/ |
| 12798 | uint32_t |
| 12799 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 12800 | { |
| 12801 | LPFC_MBOXQ_t *mbox; |
| 12802 | int rc, length, status = 0; |
| 12803 | uint32_t shdr_status, shdr_add_status; |
| 12804 | union lpfc_sli4_cfg_shdr *shdr; |
| 12805 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12806 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12807 | if (!mq) |
| 12808 | return -ENODEV; |
| 12809 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12810 | if (!mbox) |
| 12811 | return -ENOMEM; |
| 12812 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 12813 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12814 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12815 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 12816 | length, LPFC_SLI4_MBX_EMBED); |
| 12817 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 12818 | mq->queue_id); |
| 12819 | mbox->vport = mq->phba->pport; |
| 12820 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12821 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 12822 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12823 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12824 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 12825 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12826 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12827 | if (shdr_status || shdr_add_status || rc) { |
| 12828 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12829 | "2507 MQ_DESTROY mailbox failed with " |
| 12830 | "status x%x add_status x%x, mbx status x%x\n", |
| 12831 | shdr_status, shdr_add_status, rc); |
| 12832 | status = -ENXIO; |
| 12833 | } |
| 12834 | /* Remove mq from any list */ |
| 12835 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12836 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12837 | return status; |
| 12838 | } |
| 12839 | |
| 12840 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12841 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 12842 | * @wq: The queue structure associated with the queue to destroy. |
| 12843 | * |
| 12844 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 12845 | * command, specific to the type of queue, to the HBA. |
| 12846 | * |
| 12847 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 12848 | * |
| 12849 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12850 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12851 | **/ |
| 12852 | uint32_t |
| 12853 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 12854 | { |
| 12855 | LPFC_MBOXQ_t *mbox; |
| 12856 | int rc, length, status = 0; |
| 12857 | uint32_t shdr_status, shdr_add_status; |
| 12858 | union lpfc_sli4_cfg_shdr *shdr; |
| 12859 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12860 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12861 | if (!wq) |
| 12862 | return -ENODEV; |
| 12863 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12864 | if (!mbox) |
| 12865 | return -ENOMEM; |
| 12866 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 12867 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12868 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12869 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 12870 | length, LPFC_SLI4_MBX_EMBED); |
| 12871 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 12872 | wq->queue_id); |
| 12873 | mbox->vport = wq->phba->pport; |
| 12874 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12875 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 12876 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12877 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 12878 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12879 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12880 | if (shdr_status || shdr_add_status || rc) { |
| 12881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12882 | "2508 WQ_DESTROY mailbox failed with " |
| 12883 | "status x%x add_status x%x, mbx status x%x\n", |
| 12884 | shdr_status, shdr_add_status, rc); |
| 12885 | status = -ENXIO; |
| 12886 | } |
| 12887 | /* Remove wq from any list */ |
| 12888 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12889 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12890 | return status; |
| 12891 | } |
| 12892 | |
| 12893 | /** |
| 12894 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 12895 | * @rq: The queue structure associated with the queue to destroy. |
| 12896 | * |
| 12897 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 12898 | * command, specific to the type of queue, to the HBA. |
| 12899 | * |
| 12900 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 12901 | * |
| 12902 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 12903 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12904 | **/ |
| 12905 | uint32_t |
| 12906 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12907 | struct lpfc_queue *drq) |
| 12908 | { |
| 12909 | LPFC_MBOXQ_t *mbox; |
| 12910 | int rc, length, status = 0; |
| 12911 | uint32_t shdr_status, shdr_add_status; |
| 12912 | union lpfc_sli4_cfg_shdr *shdr; |
| 12913 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12914 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12915 | if (!hrq || !drq) |
| 12916 | return -ENODEV; |
| 12917 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12918 | if (!mbox) |
| 12919 | return -ENOMEM; |
| 12920 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12921 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12922 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12923 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 12924 | length, LPFC_SLI4_MBX_EMBED); |
| 12925 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 12926 | hrq->queue_id); |
| 12927 | mbox->vport = hrq->phba->pport; |
| 12928 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12929 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 12930 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12931 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12932 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 12933 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12934 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12935 | if (shdr_status || shdr_add_status || rc) { |
| 12936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12937 | "2509 RQ_DESTROY mailbox failed with " |
| 12938 | "status x%x add_status x%x, mbx status x%x\n", |
| 12939 | shdr_status, shdr_add_status, rc); |
| 12940 | if (rc != MBX_TIMEOUT) |
| 12941 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 12942 | return -ENXIO; |
| 12943 | } |
| 12944 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 12945 | drq->queue_id); |
| 12946 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 12947 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12948 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 12949 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12950 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12951 | if (shdr_status || shdr_add_status || rc) { |
| 12952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12953 | "2510 RQ_DESTROY mailbox failed with " |
| 12954 | "status x%x add_status x%x, mbx status x%x\n", |
| 12955 | shdr_status, shdr_add_status, rc); |
| 12956 | status = -ENXIO; |
| 12957 | } |
| 12958 | list_del_init(&hrq->list); |
| 12959 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12960 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12961 | return status; |
| 12962 | } |
| 12963 | |
| 12964 | /** |
| 12965 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 12966 | * @phba: The virtual port for which this call being executed. |
| 12967 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 12968 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 12969 | * @xritag: the xritag that ties this io to the SGL pages. |
| 12970 | * |
| 12971 | * This routine will post the sgl pages for the IO that has the xritag |
| 12972 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 12973 | * creation and persists for as long as the driver is loaded. |
| 12974 | * if the caller has fewer than 256 scatter gather segments to map then |
| 12975 | * pdma_phys_addr1 should be 0. |
| 12976 | * If the caller needs to map more than 256 scatter gather segment then |
| 12977 | * pdma_phys_addr1 should be a valid physical address. |
| 12978 | * physical address for SGLs must be 64 byte aligned. |
| 12979 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 12980 | * the second sgl can have between 1 and 256 entries. |
| 12981 | * |
| 12982 | * Return codes: |
| 12983 | * 0 - Success |
| 12984 | * -ENXIO, -ENOMEM - Failure |
| 12985 | **/ |
| 12986 | int |
| 12987 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 12988 | dma_addr_t pdma_phys_addr0, |
| 12989 | dma_addr_t pdma_phys_addr1, |
| 12990 | uint16_t xritag) |
| 12991 | { |
| 12992 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 12993 | LPFC_MBOXQ_t *mbox; |
| 12994 | int rc; |
| 12995 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12996 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12997 | union lpfc_sli4_cfg_shdr *shdr; |
| 12998 | |
| 12999 | if (xritag == NO_XRI) { |
| 13000 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13001 | "0364 Invalid param:\n"); |
| 13002 | return -EINVAL; |
| 13003 | } |
| 13004 | |
| 13005 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13006 | if (!mbox) |
| 13007 | return -ENOMEM; |
| 13008 | |
| 13009 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13010 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13011 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13012 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13013 | |
| 13014 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13015 | &mbox->u.mqe.un.post_sgl_pages; |
| 13016 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13017 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13018 | |
| 13019 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13020 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13021 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13022 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13023 | |
| 13024 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13025 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13026 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13027 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13028 | if (!phba->sli4_hba.intr_enable) |
| 13029 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13030 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13031 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13032 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13033 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13034 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13035 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13036 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13037 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13038 | if (rc != MBX_TIMEOUT) |
| 13039 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13040 | if (shdr_status || shdr_add_status || rc) { |
| 13041 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13042 | "2511 POST_SGL mailbox failed with " |
| 13043 | "status x%x add_status x%x, mbx status x%x\n", |
| 13044 | shdr_status, shdr_add_status, rc); |
| 13045 | rc = -ENXIO; |
| 13046 | } |
| 13047 | return 0; |
| 13048 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13049 | |
| 13050 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13051 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13052 | * @phba: pointer to lpfc hba data structure. |
| 13053 | * |
| 13054 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13055 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13056 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13057 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13058 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13059 | * Returns |
| 13060 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13061 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13062 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13063 | uint16_t |
| 13064 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13065 | { |
| 13066 | unsigned long xri; |
| 13067 | |
| 13068 | /* |
| 13069 | * Fetch the next logical xri. Because this index is logical, |
| 13070 | * the driver starts at 0 each time. |
| 13071 | */ |
| 13072 | spin_lock_irq(&phba->hbalock); |
| 13073 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13074 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13075 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13076 | spin_unlock_irq(&phba->hbalock); |
| 13077 | return NO_XRI; |
| 13078 | } else { |
| 13079 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13080 | phba->sli4_hba.max_cfg_param.xri_used++; |
| 13081 | phba->sli4_hba.xri_count++; |
| 13082 | } |
| 13083 | |
| 13084 | spin_unlock_irq(&phba->hbalock); |
| 13085 | return xri; |
| 13086 | } |
| 13087 | |
| 13088 | /** |
| 13089 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13090 | * @phba: pointer to lpfc hba data structure. |
| 13091 | * |
| 13092 | * This routine is invoked to release an xri to the pool of |
| 13093 | * available rpis maintained by the driver. |
| 13094 | **/ |
| 13095 | void |
| 13096 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13097 | { |
| 13098 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
| 13099 | phba->sli4_hba.xri_count--; |
| 13100 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13101 | } |
| 13102 | } |
| 13103 | |
| 13104 | /** |
| 13105 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13106 | * @phba: pointer to lpfc hba data structure. |
| 13107 | * |
| 13108 | * This routine is invoked to release an xri to the pool of |
| 13109 | * available rpis maintained by the driver. |
| 13110 | **/ |
| 13111 | void |
| 13112 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13113 | { |
| 13114 | spin_lock_irq(&phba->hbalock); |
| 13115 | __lpfc_sli4_free_xri(phba, xri); |
| 13116 | spin_unlock_irq(&phba->hbalock); |
| 13117 | } |
| 13118 | |
| 13119 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13120 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13121 | * @phba: Pointer to HBA context object. |
| 13122 | * |
| 13123 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13124 | * it will return 0xffff. |
| 13125 | * The function returns the allocated xritag if successful, else returns zero. |
| 13126 | * Zero is not a valid xritag. |
| 13127 | * The caller is not required to hold any lock. |
| 13128 | **/ |
| 13129 | uint16_t |
| 13130 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13131 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13132 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13133 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13134 | xri_index = lpfc_sli4_alloc_xri(phba); |
| 13135 | if (xri_index != NO_XRI) |
| 13136 | return xri_index; |
| 13137 | |
| 13138 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13139 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13140 | " Max XRI is %d, Used XRI is %d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13141 | xri_index, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13142 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13143 | phba->sli4_hba.max_cfg_param.xri_used); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13144 | return NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13145 | } |
| 13146 | |
| 13147 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13148 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13149 | * @phba: pointer to lpfc hba data structure. |
| 13150 | * |
| 13151 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13152 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13153 | * is only called when the driver is loading and after all IO has been |
| 13154 | * stopped. |
| 13155 | **/ |
| 13156 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13157 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13158 | { |
| 13159 | struct lpfc_sglq *sglq_entry; |
| 13160 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13161 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13162 | void *viraddr; |
| 13163 | LPFC_MBOXQ_t *mbox; |
| 13164 | uint32_t reqlen, alloclen, pg_pairs; |
| 13165 | uint32_t mbox_tmo; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13166 | uint16_t xritag_start = 0, lxri = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13167 | int els_xri_cnt, rc = 0; |
| 13168 | uint32_t shdr_status, shdr_add_status; |
| 13169 | union lpfc_sli4_cfg_shdr *shdr; |
| 13170 | |
| 13171 | /* The number of sgls to be posted */ |
| 13172 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 13173 | |
| 13174 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + |
| 13175 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13176 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13177 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13178 | "2559 Block sgl registration required DMA " |
| 13179 | "size (%d) great than a page\n", reqlen); |
| 13180 | return -ENOMEM; |
| 13181 | } |
| 13182 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13183 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13184 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13185 | |
| 13186 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13187 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13188 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13189 | LPFC_SLI4_MBX_NEMBED); |
| 13190 | |
| 13191 | if (alloclen < reqlen) { |
| 13192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13193 | "0285 Allocated DMA memory size (%d) is " |
| 13194 | "less than the requested DMA memory " |
| 13195 | "size (%d)\n", alloclen, reqlen); |
| 13196 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13197 | return -ENOMEM; |
| 13198 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13199 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13200 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13201 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13202 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13203 | |
| 13204 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { |
| 13205 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13206 | |
| 13207 | /* |
| 13208 | * Assign the sglq a physical xri only if the driver has not |
| 13209 | * initialized those resources. A port reset only needs |
| 13210 | * the sglq's posted. |
| 13211 | */ |
| 13212 | if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 13213 | LPFC_XRI_RSRC_RDY) { |
| 13214 | lxri = lpfc_sli4_next_xritag(phba); |
| 13215 | if (lxri == NO_XRI) { |
| 13216 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13217 | return -ENOMEM; |
| 13218 | } |
| 13219 | sglq_entry->sli4_lxritag = lxri; |
| 13220 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 13221 | } |
| 13222 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13223 | /* Set up the sge entry */ |
| 13224 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13225 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13226 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13227 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13228 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13229 | cpu_to_le32(putPaddrLow(0)); |
| 13230 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13231 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13232 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13233 | /* Keep the first xritag on the list */ |
| 13234 | if (pg_pairs == 0) |
| 13235 | xritag_start = sglq_entry->sli4_xritag; |
| 13236 | sgl_pg_pairs++; |
| 13237 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13238 | |
| 13239 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13240 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13241 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13242 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13243 | if (!phba->sli4_hba.intr_enable) |
| 13244 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13245 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13246 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13247 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13248 | } |
| 13249 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13250 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13252 | if (rc != MBX_TIMEOUT) |
| 13253 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13254 | if (shdr_status || shdr_add_status || rc) { |
| 13255 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13256 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13257 | "status x%x add_status x%x mbx status x%x\n", |
| 13258 | shdr_status, shdr_add_status, rc); |
| 13259 | rc = -ENXIO; |
| 13260 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13261 | |
| 13262 | if (rc == 0) |
| 13263 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 13264 | LPFC_XRI_RSRC_RDY); |
| 13265 | return rc; |
| 13266 | } |
| 13267 | |
| 13268 | /** |
| 13269 | * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port. |
| 13270 | * @phba: pointer to lpfc hba data structure. |
| 13271 | * |
| 13272 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13273 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13274 | * is only called when the driver is loading and after all IO has been |
| 13275 | * stopped. |
| 13276 | **/ |
| 13277 | int |
| 13278 | lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) |
| 13279 | { |
| 13280 | struct lpfc_sglq *sglq_entry; |
| 13281 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13282 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13283 | void *viraddr; |
| 13284 | LPFC_MBOXQ_t *mbox; |
| 13285 | uint32_t reqlen, alloclen, index; |
| 13286 | uint32_t mbox_tmo; |
| 13287 | uint16_t rsrc_start, rsrc_size, els_xri_cnt; |
| 13288 | uint16_t xritag_start = 0, lxri = 0; |
| 13289 | struct lpfc_rsrc_blks *rsrc_blk; |
| 13290 | int cnt, ttl_cnt, rc = 0; |
| 13291 | int loop_cnt; |
| 13292 | uint32_t shdr_status, shdr_add_status; |
| 13293 | union lpfc_sli4_cfg_shdr *shdr; |
| 13294 | |
| 13295 | /* The number of sgls to be posted */ |
| 13296 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 13297 | |
| 13298 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + |
| 13299 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
| 13300 | if (reqlen > SLI4_PAGE_SIZE) { |
| 13301 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13302 | "2989 Block sgl registration required DMA " |
| 13303 | "size (%d) great than a page\n", reqlen); |
| 13304 | return -ENOMEM; |
| 13305 | } |
| 13306 | |
| 13307 | cnt = 0; |
| 13308 | ttl_cnt = 0; |
| 13309 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, |
| 13310 | list) { |
| 13311 | rsrc_start = rsrc_blk->rsrc_start; |
| 13312 | rsrc_size = rsrc_blk->rsrc_size; |
| 13313 | |
| 13314 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13315 | "3014 Working ELS Extent start %d, cnt %d\n", |
| 13316 | rsrc_start, rsrc_size); |
| 13317 | |
| 13318 | loop_cnt = min(els_xri_cnt, rsrc_size); |
| 13319 | if (ttl_cnt + loop_cnt >= els_xri_cnt) { |
| 13320 | loop_cnt = els_xri_cnt - ttl_cnt; |
| 13321 | ttl_cnt = els_xri_cnt; |
| 13322 | } |
| 13323 | |
| 13324 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13325 | if (!mbox) |
| 13326 | return -ENOMEM; |
| 13327 | /* |
| 13328 | * Allocate DMA memory and set up the non-embedded mailbox |
| 13329 | * command. |
| 13330 | */ |
| 13331 | alloclen = lpfc_sli4_config(phba, mbox, |
| 13332 | LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13333 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13334 | reqlen, LPFC_SLI4_MBX_NEMBED); |
| 13335 | if (alloclen < reqlen) { |
| 13336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13337 | "2987 Allocated DMA memory size (%d) " |
| 13338 | "is less than the requested DMA memory " |
| 13339 | "size (%d)\n", alloclen, reqlen); |
| 13340 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13341 | return -ENOMEM; |
| 13342 | } |
| 13343 | |
| 13344 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13345 | viraddr = mbox->sge_array->addr[0]; |
| 13346 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13347 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13348 | |
| 13349 | /* |
| 13350 | * The starting resource may not begin at zero. Control |
| 13351 | * the loop variants via the block resource parameters, |
| 13352 | * but handle the sge pointers with a zero-based index |
| 13353 | * that doesn't get reset per loop pass. |
| 13354 | */ |
| 13355 | for (index = rsrc_start; |
| 13356 | index < rsrc_start + loop_cnt; |
| 13357 | index++) { |
| 13358 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt]; |
| 13359 | |
| 13360 | /* |
| 13361 | * Assign the sglq a physical xri only if the driver |
| 13362 | * has not initialized those resources. A port reset |
| 13363 | * only needs the sglq's posted. |
| 13364 | */ |
| 13365 | if (bf_get(lpfc_xri_rsrc_rdy, |
| 13366 | &phba->sli4_hba.sli4_flags) != |
| 13367 | LPFC_XRI_RSRC_RDY) { |
| 13368 | lxri = lpfc_sli4_next_xritag(phba); |
| 13369 | if (lxri == NO_XRI) { |
| 13370 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13371 | rc = -ENOMEM; |
| 13372 | goto err_exit; |
| 13373 | } |
| 13374 | sglq_entry->sli4_lxritag = lxri; |
| 13375 | sglq_entry->sli4_xritag = |
| 13376 | phba->sli4_hba.xri_ids[lxri]; |
| 13377 | } |
| 13378 | |
| 13379 | /* Set up the sge entry */ |
| 13380 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13381 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13382 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13383 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13384 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13385 | cpu_to_le32(putPaddrLow(0)); |
| 13386 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13387 | cpu_to_le32(putPaddrHigh(0)); |
| 13388 | |
| 13389 | /* Track the starting physical XRI for the mailbox. */ |
| 13390 | if (index == rsrc_start) |
| 13391 | xritag_start = sglq_entry->sli4_xritag; |
| 13392 | sgl_pg_pairs++; |
| 13393 | cnt++; |
| 13394 | } |
| 13395 | |
| 13396 | /* Complete initialization and perform endian conversion. */ |
| 13397 | rsrc_blk->rsrc_used += loop_cnt; |
| 13398 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13399 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt); |
| 13400 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13401 | |
| 13402 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13403 | "3015 Post ELS Extent SGL, start %d, " |
| 13404 | "cnt %d, used %d\n", |
| 13405 | xritag_start, loop_cnt, rsrc_blk->rsrc_used); |
| 13406 | if (!phba->sli4_hba.intr_enable) |
| 13407 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13408 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13409 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13410 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13411 | } |
| 13412 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13413 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 13414 | &shdr->response); |
| 13415 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 13416 | &shdr->response); |
| 13417 | if (rc != MBX_TIMEOUT) |
| 13418 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13419 | if (shdr_status || shdr_add_status || rc) { |
| 13420 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13421 | "2988 POST_SGL_BLOCK mailbox " |
| 13422 | "command failed status x%x " |
| 13423 | "add_status x%x mbx status x%x\n", |
| 13424 | shdr_status, shdr_add_status, rc); |
| 13425 | rc = -ENXIO; |
| 13426 | goto err_exit; |
| 13427 | } |
| 13428 | if (ttl_cnt >= els_xri_cnt) |
| 13429 | break; |
| 13430 | } |
| 13431 | |
| 13432 | err_exit: |
| 13433 | if (rc == 0) |
| 13434 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 13435 | LPFC_XRI_RSRC_RDY); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13436 | return rc; |
| 13437 | } |
| 13438 | |
| 13439 | /** |
| 13440 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13441 | * @phba: pointer to lpfc hba data structure. |
| 13442 | * @sblist: pointer to scsi buffer list. |
| 13443 | * @count: number of scsi buffers on the list. |
| 13444 | * |
| 13445 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13446 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13447 | * No Lock is held. |
| 13448 | * |
| 13449 | **/ |
| 13450 | int |
| 13451 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, |
| 13452 | int cnt) |
| 13453 | { |
| 13454 | struct lpfc_scsi_buf *psb; |
| 13455 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13456 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13457 | void *viraddr; |
| 13458 | LPFC_MBOXQ_t *mbox; |
| 13459 | uint32_t reqlen, alloclen, pg_pairs; |
| 13460 | uint32_t mbox_tmo; |
| 13461 | uint16_t xritag_start = 0; |
| 13462 | int rc = 0; |
| 13463 | uint32_t shdr_status, shdr_add_status; |
| 13464 | dma_addr_t pdma_phys_bpl1; |
| 13465 | union lpfc_sli4_cfg_shdr *shdr; |
| 13466 | |
| 13467 | /* Calculate the requested length of the dma memory */ |
| 13468 | reqlen = cnt * sizeof(struct sgl_page_pairs) + |
| 13469 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13470 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13471 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13472 | "0217 Block sgl registration required DMA " |
| 13473 | "size (%d) great than a page\n", reqlen); |
| 13474 | return -ENOMEM; |
| 13475 | } |
| 13476 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13477 | if (!mbox) { |
| 13478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13479 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13480 | return -ENOMEM; |
| 13481 | } |
| 13482 | |
| 13483 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13484 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13485 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13486 | LPFC_SLI4_MBX_NEMBED); |
| 13487 | |
| 13488 | if (alloclen < reqlen) { |
| 13489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13490 | "2561 Allocated DMA memory size (%d) is " |
| 13491 | "less than the requested DMA memory " |
| 13492 | "size (%d)\n", alloclen, reqlen); |
| 13493 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13494 | return -ENOMEM; |
| 13495 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13496 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13498 | viraddr = mbox->sge_array->addr[0]; |
| 13499 | |
| 13500 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13501 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13502 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13503 | |
| 13504 | pg_pairs = 0; |
| 13505 | list_for_each_entry(psb, sblist, list) { |
| 13506 | /* Set up the sge entry */ |
| 13507 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13508 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13509 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13510 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13511 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13512 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13513 | else |
| 13514 | pdma_phys_bpl1 = 0; |
| 13515 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13516 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13517 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13518 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13519 | /* Keep the first xritag on the list */ |
| 13520 | if (pg_pairs == 0) |
| 13521 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13522 | sgl_pg_pairs++; |
| 13523 | pg_pairs++; |
| 13524 | } |
| 13525 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13526 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13527 | /* Perform endian conversion if necessary */ |
| 13528 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13529 | |
| 13530 | if (!phba->sli4_hba.intr_enable) |
| 13531 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13532 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13533 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13534 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13535 | } |
| 13536 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13537 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13538 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13539 | if (rc != MBX_TIMEOUT) |
| 13540 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13541 | if (shdr_status || shdr_add_status || rc) { |
| 13542 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13543 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13544 | "status x%x add_status x%x mbx status x%x\n", |
| 13545 | shdr_status, shdr_add_status, rc); |
| 13546 | rc = -ENXIO; |
| 13547 | } |
| 13548 | return rc; |
| 13549 | } |
| 13550 | |
| 13551 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13552 | * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port. |
| 13553 | * @phba: pointer to lpfc hba data structure. |
| 13554 | * @sblist: pointer to scsi buffer list. |
| 13555 | * @count: number of scsi buffers on the list. |
| 13556 | * |
| 13557 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13558 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13559 | * No Lock is held. |
| 13560 | * |
| 13561 | **/ |
| 13562 | int |
| 13563 | lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist, |
| 13564 | int cnt) |
| 13565 | { |
| 13566 | struct lpfc_scsi_buf *psb = NULL; |
| 13567 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13568 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13569 | void *viraddr; |
| 13570 | LPFC_MBOXQ_t *mbox; |
| 13571 | uint32_t reqlen, alloclen, pg_pairs; |
| 13572 | uint32_t mbox_tmo; |
| 13573 | uint16_t xri_start = 0, scsi_xri_start; |
| 13574 | uint16_t rsrc_range; |
| 13575 | int rc = 0, avail_cnt; |
| 13576 | uint32_t shdr_status, shdr_add_status; |
| 13577 | dma_addr_t pdma_phys_bpl1; |
| 13578 | union lpfc_sli4_cfg_shdr *shdr; |
| 13579 | struct lpfc_rsrc_blks *rsrc_blk; |
| 13580 | uint32_t xri_cnt = 0; |
| 13581 | |
| 13582 | /* Calculate the total requested length of the dma memory */ |
| 13583 | reqlen = cnt * sizeof(struct sgl_page_pairs) + |
| 13584 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
| 13585 | if (reqlen > SLI4_PAGE_SIZE) { |
| 13586 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13587 | "2932 Block sgl registration required DMA " |
| 13588 | "size (%d) great than a page\n", reqlen); |
| 13589 | return -ENOMEM; |
| 13590 | } |
| 13591 | |
| 13592 | /* |
| 13593 | * The use of extents requires the driver to post the sgl headers |
| 13594 | * in multiple postings to meet the contiguous resource assignment. |
| 13595 | */ |
| 13596 | psb = list_prepare_entry(psb, sblist, list); |
| 13597 | scsi_xri_start = phba->sli4_hba.scsi_xri_start; |
| 13598 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, |
| 13599 | list) { |
| 13600 | rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size; |
| 13601 | if (rsrc_range < scsi_xri_start) |
| 13602 | continue; |
| 13603 | else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size) |
| 13604 | continue; |
| 13605 | else |
| 13606 | avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used; |
| 13607 | |
| 13608 | reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) + |
| 13609 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
| 13610 | /* |
| 13611 | * Allocate DMA memory and set up the non-embedded mailbox |
| 13612 | * command. The mbox is used to post an SGL page per loop |
| 13613 | * but the DMA memory has a use-once semantic so the mailbox |
| 13614 | * is used and freed per loop pass. |
| 13615 | */ |
| 13616 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13617 | if (!mbox) { |
| 13618 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13619 | "2933 Failed to allocate mbox cmd " |
| 13620 | "memory\n"); |
| 13621 | return -ENOMEM; |
| 13622 | } |
| 13623 | alloclen = lpfc_sli4_config(phba, mbox, |
| 13624 | LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13625 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13626 | reqlen, |
| 13627 | LPFC_SLI4_MBX_NEMBED); |
| 13628 | if (alloclen < reqlen) { |
| 13629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13630 | "2934 Allocated DMA memory size (%d) " |
| 13631 | "is less than the requested DMA memory " |
| 13632 | "size (%d)\n", alloclen, reqlen); |
| 13633 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13634 | return -ENOMEM; |
| 13635 | } |
| 13636 | |
| 13637 | /* Get the first SGE entry from the non-embedded DMA memory */ |
| 13638 | viraddr = mbox->sge_array->addr[0]; |
| 13639 | |
| 13640 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13641 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13642 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13643 | |
| 13644 | /* pg_pairs tracks posted SGEs per loop iteration. */ |
| 13645 | pg_pairs = 0; |
| 13646 | list_for_each_entry_continue(psb, sblist, list) { |
| 13647 | /* Set up the sge entry */ |
| 13648 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13649 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13650 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13651 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13652 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13653 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
| 13654 | SGL_PAGE_SIZE; |
| 13655 | else |
| 13656 | pdma_phys_bpl1 = 0; |
| 13657 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13658 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13659 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13660 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13661 | /* Keep the first xri for this extent. */ |
| 13662 | if (pg_pairs == 0) |
| 13663 | xri_start = psb->cur_iocbq.sli4_xritag; |
| 13664 | sgl_pg_pairs++; |
| 13665 | pg_pairs++; |
| 13666 | xri_cnt++; |
| 13667 | |
| 13668 | /* |
| 13669 | * Track two exit conditions - the loop has constructed |
| 13670 | * all of the caller's SGE pairs or all available |
| 13671 | * resource IDs in this extent are consumed. |
| 13672 | */ |
| 13673 | if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt)) |
| 13674 | break; |
| 13675 | } |
| 13676 | rsrc_blk->rsrc_used += pg_pairs; |
| 13677 | bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start); |
| 13678 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13679 | |
| 13680 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13681 | "3016 Post SCSI Extent SGL, start %d, cnt %d " |
| 13682 | "blk use %d\n", |
| 13683 | xri_start, pg_pairs, rsrc_blk->rsrc_used); |
| 13684 | /* Perform endian conversion if necessary */ |
| 13685 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13686 | if (!phba->sli4_hba.intr_enable) |
| 13687 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13688 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13689 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13690 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13691 | } |
| 13692 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13693 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13694 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 13695 | &shdr->response); |
| 13696 | if (rc != MBX_TIMEOUT) |
| 13697 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13698 | if (shdr_status || shdr_add_status || rc) { |
| 13699 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13700 | "2935 POST_SGL_BLOCK mailbox command " |
| 13701 | "failed status x%x add_status x%x " |
| 13702 | "mbx status x%x\n", |
| 13703 | shdr_status, shdr_add_status, rc); |
| 13704 | return -ENXIO; |
| 13705 | } |
| 13706 | |
| 13707 | /* Post only what is requested. */ |
| 13708 | if (xri_cnt >= cnt) |
| 13709 | break; |
| 13710 | } |
| 13711 | return rc; |
| 13712 | } |
| 13713 | |
| 13714 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13715 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13716 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13717 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13718 | * |
| 13719 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13720 | * valid type of frame that the LPFC driver will handle. This function will |
| 13721 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13722 | * frame does not pass the check. |
| 13723 | **/ |
| 13724 | static int |
| 13725 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13726 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13727 | /* make rctl_names static to save stack space */ |
| 13728 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13729 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13730 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13731 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13732 | |
| 13733 | switch (fc_hdr->fh_r_ctl) { |
| 13734 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13735 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13736 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13737 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13738 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13739 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13740 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13741 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13742 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13743 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13744 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13745 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13746 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13747 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13748 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13749 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13750 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13751 | case FC_RCTL_BA_PRMT: |
| 13752 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13753 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13754 | case FC_RCTL_P_RJT: /* port reject */ |
| 13755 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13756 | case FC_RCTL_P_BSY: /* port busy */ |
| 13757 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13758 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13759 | case FC_RCTL_LCR: /* link credit reset */ |
| 13760 | case FC_RCTL_END: /* end */ |
| 13761 | break; |
| 13762 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13763 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13764 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13765 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13766 | default: |
| 13767 | goto drop; |
| 13768 | } |
| 13769 | switch (fc_hdr->fh_type) { |
| 13770 | case FC_TYPE_BLS: |
| 13771 | case FC_TYPE_ELS: |
| 13772 | case FC_TYPE_FCP: |
| 13773 | case FC_TYPE_CT: |
| 13774 | break; |
| 13775 | case FC_TYPE_IP: |
| 13776 | case FC_TYPE_ILS: |
| 13777 | default: |
| 13778 | goto drop; |
| 13779 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13780 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13781 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13782 | "2538 Received frame rctl:%s type:%s " |
| 13783 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13784 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13785 | type_names[fc_hdr->fh_type], |
| 13786 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13787 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13788 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13789 | return 0; |
| 13790 | drop: |
| 13791 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13792 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13793 | rctl_names[fc_hdr->fh_r_ctl], |
| 13794 | type_names[fc_hdr->fh_type]); |
| 13795 | return 1; |
| 13796 | } |
| 13797 | |
| 13798 | /** |
| 13799 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13800 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13801 | * |
| 13802 | * This function processes the FC header to retrieve the VFI from the VF |
| 13803 | * header, if one exists. This function will return the VFI if one exists |
| 13804 | * or 0 if no VSAN Header exists. |
| 13805 | **/ |
| 13806 | static uint32_t |
| 13807 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13808 | { |
| 13809 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13810 | |
| 13811 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 13812 | return 0; |
| 13813 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 13814 | } |
| 13815 | |
| 13816 | /** |
| 13817 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 13818 | * @phba: Pointer to the HBA structure to search for the vport on |
| 13819 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13820 | * @fcfi: The FC Fabric ID that the frame came from |
| 13821 | * |
| 13822 | * This function searches the @phba for a vport that matches the content of the |
| 13823 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 13824 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 13825 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 13826 | * vport. |
| 13827 | **/ |
| 13828 | static struct lpfc_vport * |
| 13829 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 13830 | uint16_t fcfi) |
| 13831 | { |
| 13832 | struct lpfc_vport **vports; |
| 13833 | struct lpfc_vport *vport = NULL; |
| 13834 | int i; |
| 13835 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 13836 | fc_hdr->fh_d_id[1] << 8 | |
| 13837 | fc_hdr->fh_d_id[2]); |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 13838 | if (did == Fabric_DID) |
| 13839 | return phba->pport; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13840 | vports = lpfc_create_vport_work_array(phba); |
| 13841 | if (vports != NULL) |
| 13842 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 13843 | if (phba->fcf.fcfi == fcfi && |
| 13844 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 13845 | vports[i]->fc_myDID == did) { |
| 13846 | vport = vports[i]; |
| 13847 | break; |
| 13848 | } |
| 13849 | } |
| 13850 | lpfc_destroy_vport_work_array(phba, vports); |
| 13851 | return vport; |
| 13852 | } |
| 13853 | |
| 13854 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13855 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 13856 | * @vport: The vport to work on. |
| 13857 | * |
| 13858 | * This function updates the receive sequence time stamp for this vport. The |
| 13859 | * receive sequence time stamp indicates the time that the last frame of the |
| 13860 | * the sequence that has been idle for the longest amount of time was received. |
| 13861 | * the driver uses this time stamp to indicate if any received sequences have |
| 13862 | * timed out. |
| 13863 | **/ |
| 13864 | void |
| 13865 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 13866 | { |
| 13867 | struct lpfc_dmabuf *h_buf; |
| 13868 | struct hbq_dmabuf *dmabuf = NULL; |
| 13869 | |
| 13870 | /* get the oldest sequence on the rcv list */ |
| 13871 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 13872 | struct lpfc_dmabuf, list); |
| 13873 | if (!h_buf) |
| 13874 | return; |
| 13875 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13876 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 13877 | } |
| 13878 | |
| 13879 | /** |
| 13880 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 13881 | * @vport: The vport that the received sequences were sent to. |
| 13882 | * |
| 13883 | * This function cleans up all outstanding received sequences. This is called |
| 13884 | * by the driver when a link event or user action invalidates all the received |
| 13885 | * sequences. |
| 13886 | **/ |
| 13887 | void |
| 13888 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 13889 | { |
| 13890 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13891 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13892 | struct hbq_dmabuf *dmabuf = NULL; |
| 13893 | |
| 13894 | /* start with the oldest sequence on the rcv list */ |
| 13895 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13896 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13897 | list_del_init(&dmabuf->hbuf.list); |
| 13898 | list_for_each_entry_safe(d_buf, dnext, |
| 13899 | &dmabuf->dbuf.list, list) { |
| 13900 | list_del_init(&d_buf->list); |
| 13901 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13902 | } |
| 13903 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13904 | } |
| 13905 | } |
| 13906 | |
| 13907 | /** |
| 13908 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 13909 | * @vport: The vport that the received sequences were sent to. |
| 13910 | * |
| 13911 | * This function determines whether any received sequences have timed out by |
| 13912 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 13913 | * indicates that there is at least one timed out sequence this routine will |
| 13914 | * go through the received sequences one at a time from most inactive to most |
| 13915 | * active to determine which ones need to be cleaned up. Once it has determined |
| 13916 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 13917 | * without sending an abort. |
| 13918 | **/ |
| 13919 | void |
| 13920 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 13921 | { |
| 13922 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13923 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13924 | struct hbq_dmabuf *dmabuf = NULL; |
| 13925 | unsigned long timeout; |
| 13926 | int abort_count = 0; |
| 13927 | |
| 13928 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13929 | vport->rcv_buffer_time_stamp); |
| 13930 | if (list_empty(&vport->rcv_buffer_list) || |
| 13931 | time_before(jiffies, timeout)) |
| 13932 | return; |
| 13933 | /* start with the oldest sequence on the rcv list */ |
| 13934 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13935 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13936 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13937 | dmabuf->time_stamp); |
| 13938 | if (time_before(jiffies, timeout)) |
| 13939 | break; |
| 13940 | abort_count++; |
| 13941 | list_del_init(&dmabuf->hbuf.list); |
| 13942 | list_for_each_entry_safe(d_buf, dnext, |
| 13943 | &dmabuf->dbuf.list, list) { |
| 13944 | list_del_init(&d_buf->list); |
| 13945 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13946 | } |
| 13947 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13948 | } |
| 13949 | if (abort_count) |
| 13950 | lpfc_update_rcv_time_stamp(vport); |
| 13951 | } |
| 13952 | |
| 13953 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13954 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 13955 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 13956 | * |
| 13957 | * This function searches through the existing incomplete sequences that have |
| 13958 | * been sent to this @vport. If the frame matches one of the incomplete |
| 13959 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 13960 | * make up that sequence. If no sequence is found that matches this frame then |
| 13961 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 13962 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 13963 | * the frame was linked to. |
| 13964 | **/ |
| 13965 | static struct hbq_dmabuf * |
| 13966 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 13967 | { |
| 13968 | struct fc_frame_header *new_hdr; |
| 13969 | struct fc_frame_header *temp_hdr; |
| 13970 | struct lpfc_dmabuf *d_buf; |
| 13971 | struct lpfc_dmabuf *h_buf; |
| 13972 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13973 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 13974 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13975 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13976 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13977 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13978 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 13979 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13980 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13981 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13982 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13983 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13984 | continue; |
| 13985 | /* found a pending sequence that matches this frame */ |
| 13986 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13987 | break; |
| 13988 | } |
| 13989 | if (!seq_dmabuf) { |
| 13990 | /* |
| 13991 | * This indicates first frame received for this sequence. |
| 13992 | * Queue the buffer on the vport's rcv_buffer_list. |
| 13993 | */ |
| 13994 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13995 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13996 | return dmabuf; |
| 13997 | } |
| 13998 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13999 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 14000 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14001 | list_del_init(&seq_dmabuf->hbuf.list); |
| 14002 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14003 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14004 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14005 | return dmabuf; |
| 14006 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14007 | /* move this sequence to the tail to indicate a young sequence */ |
| 14008 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14009 | seq_dmabuf->time_stamp = jiffies; |
| 14010 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14011 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 14012 | temp_hdr = dmabuf->hbuf.virt; |
| 14013 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 14014 | return seq_dmabuf; |
| 14015 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14016 | /* find the correct place in the sequence to insert this frame */ |
| 14017 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14018 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14019 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14020 | /* |
| 14021 | * If the frame's sequence count is greater than the frame on |
| 14022 | * the list then insert the frame right after this frame |
| 14023 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14024 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14025 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14027 | return seq_dmabuf; |
| 14028 | } |
| 14029 | } |
| 14030 | return NULL; |
| 14031 | } |
| 14032 | |
| 14033 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14034 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14035 | * @vport: pointer to a vitural port |
| 14036 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14037 | * |
| 14038 | * This function tries to abort from the partially assembed sequence, described |
| 14039 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14040 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14041 | * the frames from the partially assembled sequence. |
| 14042 | * |
| 14043 | * Return |
| 14044 | * true -- if there is matching partially assembled sequence present and all |
| 14045 | * the frames freed with the sequence; |
| 14046 | * false -- if there is no matching partially assembled sequence present so |
| 14047 | * nothing got aborted in the lower layer driver |
| 14048 | **/ |
| 14049 | static bool |
| 14050 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14051 | struct hbq_dmabuf *dmabuf) |
| 14052 | { |
| 14053 | struct fc_frame_header *new_hdr; |
| 14054 | struct fc_frame_header *temp_hdr; |
| 14055 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14056 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14057 | |
| 14058 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14059 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14060 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14061 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14062 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14063 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14064 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14065 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14066 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14067 | continue; |
| 14068 | /* found a pending sequence that matches this frame */ |
| 14069 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14070 | break; |
| 14071 | } |
| 14072 | |
| 14073 | /* Free up all the frames from the partially assembled sequence */ |
| 14074 | if (seq_dmabuf) { |
| 14075 | list_for_each_entry_safe(d_buf, n_buf, |
| 14076 | &seq_dmabuf->dbuf.list, list) { |
| 14077 | list_del_init(&d_buf->list); |
| 14078 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14079 | } |
| 14080 | return true; |
| 14081 | } |
| 14082 | return false; |
| 14083 | } |
| 14084 | |
| 14085 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14086 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14087 | * @phba: Pointer to HBA context object. |
| 14088 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14089 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14090 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14091 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14092 | * event. It properly releases the memory allocated to the sequence abort |
| 14093 | * accept iocb. |
| 14094 | **/ |
| 14095 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14096 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14097 | struct lpfc_iocbq *cmd_iocbq, |
| 14098 | struct lpfc_iocbq *rsp_iocbq) |
| 14099 | { |
| 14100 | if (cmd_iocbq) |
| 14101 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14102 | |
| 14103 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14104 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14106 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14107 | rsp_iocbq->iocb.ulpStatus, |
| 14108 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14109 | } |
| 14110 | |
| 14111 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14112 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14113 | * @phba: Pointer to HBA context object. |
| 14114 | * @xri: xri id in transaction. |
| 14115 | * |
| 14116 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14117 | * used by the driver. |
| 14118 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14119 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14120 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14121 | uint16_t xri) |
| 14122 | { |
| 14123 | int i; |
| 14124 | |
| 14125 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14126 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14127 | return i; |
| 14128 | } |
| 14129 | return NO_XRI; |
| 14130 | } |
| 14131 | |
| 14132 | |
| 14133 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14134 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14135 | * @phba: Pointer to HBA context object. |
| 14136 | * @fc_hdr: pointer to a FC frame header. |
| 14137 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14138 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14139 | * event after aborting the sequence handling. |
| 14140 | **/ |
| 14141 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14142 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14143 | struct fc_frame_header *fc_hdr) |
| 14144 | { |
| 14145 | struct lpfc_iocbq *ctiocb = NULL; |
| 14146 | struct lpfc_nodelist *ndlp; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14147 | uint16_t oxid, rxid; |
| 14148 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14149 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14150 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14151 | |
| 14152 | if (!lpfc_is_link_up(phba)) |
| 14153 | return; |
| 14154 | |
| 14155 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14156 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14157 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14158 | |
| 14159 | ndlp = lpfc_findnode_did(phba->pport, sid); |
| 14160 | if (!ndlp) { |
| 14161 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14162 | "1268 Find ndlp returned NULL for oxid:x%x " |
| 14163 | "SID:x%x\n", oxid, sid); |
| 14164 | return; |
| 14165 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14166 | if (lpfc_sli4_xri_inrange(phba, rxid)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 14167 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14168 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14169 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14170 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14171 | if (!ctiocb) |
| 14172 | return; |
| 14173 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14174 | /* Extract the F_CTL field from FC_HDR */ |
| 14175 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14176 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14177 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14178 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14179 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14180 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14181 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14182 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14183 | |
| 14184 | /* Fill in the rest of iocb fields */ |
| 14185 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14186 | icmd->ulpBdeCount = 0; |
| 14187 | icmd->ulpLe = 1; |
| 14188 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14189 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 14190 | ctiocb->context1 = ndlp; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14191 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14192 | ctiocb->iocb_cmpl = NULL; |
| 14193 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14194 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14195 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14196 | ctiocb->sli4_xritag = NO_XRI; |
| 14197 | |
| 14198 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
| 14199 | * send a BLS_RJT. The driver no longer has that exchange. |
| 14200 | * Override the IOCB for a BA_RJT. |
| 14201 | */ |
| 14202 | if (oxid > (phba->sli4_hba.max_cfg_param.max_xri + |
| 14203 | phba->sli4_hba.max_cfg_param.xri_base) || |
| 14204 | oxid > (lpfc_sli4_get_els_iocb_cnt(phba) + |
| 14205 | phba->sli4_hba.max_cfg_param.xri_base)) { |
| 14206 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14207 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14208 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14209 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14210 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14211 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14212 | if (fctl & FC_FC_EX_CTX) { |
| 14213 | /* ABTS sent by responder to CT exchange, construction |
| 14214 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14215 | * field and RX_ID from ABTS for RX_ID field. |
| 14216 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14217 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14218 | } else { |
| 14219 | /* ABTS sent by initiator to CT exchange, construction |
| 14220 | * of BA_ACC will need to allocate a new XRI as for the |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14221 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14222 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14223 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14224 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14225 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14226 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14227 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14228 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14229 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14230 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14231 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
| 14232 | |
| 14233 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14234 | if (rc == IOCB_ERROR) { |
| 14235 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 14236 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14237 | "xri x%x, Data x%x\n", |
| 14238 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14239 | phba->link_state); |
| 14240 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14241 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14242 | } |
| 14243 | |
| 14244 | /** |
| 14245 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14246 | * @vport: Pointer to the vport on which this sequence was received |
| 14247 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14248 | * |
| 14249 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14250 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14251 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14252 | * unsolicited receive sequence has been completely assembled and passed to |
| 14253 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14254 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14255 | * accept to accept the abort. |
| 14256 | **/ |
| 14257 | void |
| 14258 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14259 | struct hbq_dmabuf *dmabuf) |
| 14260 | { |
| 14261 | struct lpfc_hba *phba = vport->phba; |
| 14262 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14263 | uint32_t fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14264 | bool abts_par; |
| 14265 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14266 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14267 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14268 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14269 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14270 | if (fctl & FC_FC_EX_CTX) { |
| 14271 | /* |
| 14272 | * ABTS sent by responder to exchange, just free the buffer |
| 14273 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14274 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14275 | } else { |
| 14276 | /* |
| 14277 | * ABTS sent by initiator to exchange, need to do cleanup |
| 14278 | */ |
| 14279 | /* Try to abort partially assembled seq */ |
| 14280 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14281 | |
| 14282 | /* Send abort to ULP if partially seq abort failed */ |
| 14283 | if (abts_par == false) |
| 14284 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); |
| 14285 | else |
| 14286 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14287 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14288 | /* Send basic accept (BA_ACC) to the abort requester */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14289 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14290 | } |
| 14291 | |
| 14292 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14293 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14294 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14295 | * |
| 14296 | * This function checks the sequence, starting with the frame described by |
| 14297 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14298 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14299 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14300 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14301 | * set. 3) That there are no holes in the sequence count. The function will |
| 14302 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14303 | **/ |
| 14304 | static int |
| 14305 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14306 | { |
| 14307 | struct fc_frame_header *hdr; |
| 14308 | struct lpfc_dmabuf *d_buf; |
| 14309 | struct hbq_dmabuf *seq_dmabuf; |
| 14310 | uint32_t fctl; |
| 14311 | int seq_count = 0; |
| 14312 | |
| 14313 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14314 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14315 | if (hdr->fh_seq_cnt != seq_count) |
| 14316 | return 0; |
| 14317 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14318 | hdr->fh_f_ctl[1] << 8 | |
| 14319 | hdr->fh_f_ctl[2]); |
| 14320 | /* If last frame of sequence we can return success. */ |
| 14321 | if (fctl & FC_FC_END_SEQ) |
| 14322 | return 1; |
| 14323 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14324 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14325 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14326 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14327 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14328 | return 0; |
| 14329 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14330 | hdr->fh_f_ctl[1] << 8 | |
| 14331 | hdr->fh_f_ctl[2]); |
| 14332 | /* If last frame of sequence we can return success. */ |
| 14333 | if (fctl & FC_FC_END_SEQ) |
| 14334 | return 1; |
| 14335 | } |
| 14336 | return 0; |
| 14337 | } |
| 14338 | |
| 14339 | /** |
| 14340 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14341 | * @vport: Pointer to the vport on which this sequence was received |
| 14342 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14343 | * |
| 14344 | * This function takes a sequence, described by a list of frames, and creates |
| 14345 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14346 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14347 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14348 | * to allocate an iocbq then it throw out the received frames that were not |
| 14349 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14350 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14351 | **/ |
| 14352 | static struct lpfc_iocbq * |
| 14353 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14354 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14355 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14356 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14357 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14358 | struct fc_frame_header *fc_hdr; |
| 14359 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14360 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14361 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14362 | |
| 14363 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14364 | /* remove from receive buffer list */ |
| 14365 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14366 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14367 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14368 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14369 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14370 | /* Get an iocbq struct to fill in. */ |
| 14371 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14372 | if (first_iocbq) { |
| 14373 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14374 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14375 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
| 14376 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14377 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14378 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14379 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14380 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14381 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14382 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14383 | /* put the first buffer into the first IOCBq */ |
| 14384 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14385 | first_iocbq->context3 = NULL; |
| 14386 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14387 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14388 | LPFC_DATA_BUF_SIZE; |
| 14389 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14390 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14391 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14392 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14393 | } |
| 14394 | iocbq = first_iocbq; |
| 14395 | /* |
| 14396 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14397 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14398 | */ |
| 14399 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14400 | if (!iocbq) { |
| 14401 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14402 | continue; |
| 14403 | } |
| 14404 | if (!iocbq->context3) { |
| 14405 | iocbq->context3 = d_buf; |
| 14406 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14407 | pbde = (struct ulp_bde64 *) |
| 14408 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14409 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14410 | |
| 14411 | /* We need to get the size out of the right CQE */ |
| 14412 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14413 | len = bf_get(lpfc_rcqe_length, |
| 14414 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14415 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14416 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14417 | } else { |
| 14418 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14419 | if (!iocbq) { |
| 14420 | if (first_iocbq) { |
| 14421 | first_iocbq->iocb.ulpStatus = |
| 14422 | IOSTAT_FCP_RSP_ERROR; |
| 14423 | first_iocbq->iocb.un.ulpWord[4] = |
| 14424 | IOERR_NO_RESOURCES; |
| 14425 | } |
| 14426 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14427 | continue; |
| 14428 | } |
| 14429 | iocbq->context2 = d_buf; |
| 14430 | iocbq->context3 = NULL; |
| 14431 | iocbq->iocb.ulpBdeCount = 1; |
| 14432 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14433 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14434 | |
| 14435 | /* We need to get the size out of the right CQE */ |
| 14436 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14437 | len = bf_get(lpfc_rcqe_length, |
| 14438 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14439 | tot_len += len; |
| 14440 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14441 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14442 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14443 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14444 | } |
| 14445 | } |
| 14446 | return first_iocbq; |
| 14447 | } |
| 14448 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14449 | static void |
| 14450 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14451 | struct hbq_dmabuf *seq_dmabuf) |
| 14452 | { |
| 14453 | struct fc_frame_header *fc_hdr; |
| 14454 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14455 | struct lpfc_hba *phba = vport->phba; |
| 14456 | |
| 14457 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14458 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14459 | if (!iocbq) { |
| 14460 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14461 | "2707 Ring %d handler: Failed to allocate " |
| 14462 | "iocb Rctl x%x Type x%x received\n", |
| 14463 | LPFC_ELS_RING, |
| 14464 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14465 | return; |
| 14466 | } |
| 14467 | if (!lpfc_complete_unsol_iocb(phba, |
| 14468 | &phba->sli.ring[LPFC_ELS_RING], |
| 14469 | iocbq, fc_hdr->fh_r_ctl, |
| 14470 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14471 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14472 | "2540 Ring %d handler: unexpected Rctl " |
| 14473 | "x%x Type x%x received\n", |
| 14474 | LPFC_ELS_RING, |
| 14475 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14476 | |
| 14477 | /* Free iocb created in lpfc_prep_seq */ |
| 14478 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14479 | &iocbq->list, list) { |
| 14480 | list_del_init(&curr_iocb->list); |
| 14481 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14482 | } |
| 14483 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14484 | } |
| 14485 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14486 | /** |
| 14487 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14488 | * @phba: Pointer to HBA context object. |
| 14489 | * |
| 14490 | * This function is called with no lock held. This function processes all |
| 14491 | * the received buffers and gives it to upper layers when a received buffer |
| 14492 | * indicates that it is the final frame in the sequence. The interrupt |
| 14493 | * service routine processes received buffers at interrupt contexts and adds |
| 14494 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14495 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14496 | * appropriate receive function when the final frame in a sequence is received. |
| 14497 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14498 | void |
| 14499 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14500 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14501 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14502 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14503 | struct fc_frame_header *fc_hdr; |
| 14504 | struct lpfc_vport *vport; |
| 14505 | uint32_t fcfi; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14506 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14507 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14508 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14509 | /* check to see if this a valid type of frame */ |
| 14510 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14511 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14512 | return; |
| 14513 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14514 | if ((bf_get(lpfc_cqe_code, |
| 14515 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14516 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14517 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14518 | else |
| 14519 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14520 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14521 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 14522 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14523 | /* throw out the frame */ |
| 14524 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14525 | return; |
| 14526 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14527 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14528 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14529 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14530 | return; |
| 14531 | } |
| 14532 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14533 | /* Link this frame */ |
| 14534 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14535 | if (!seq_dmabuf) { |
| 14536 | /* unable to add frame to vport - throw it out */ |
| 14537 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14538 | return; |
| 14539 | } |
| 14540 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14541 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14542 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14543 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14544 | /* Send the complete sequence to the upper layer protocol */ |
| 14545 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14546 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14547 | |
| 14548 | /** |
| 14549 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14550 | * @phba: pointer to lpfc hba data structure. |
| 14551 | * |
| 14552 | * This routine is invoked to post rpi header templates to the |
| 14553 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14554 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14555 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14556 | * |
| 14557 | * This routine does not require any locks. It's usage is expected |
| 14558 | * to be driver load or reset recovery when the driver is |
| 14559 | * sequential. |
| 14560 | * |
| 14561 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14562 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14563 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14564 | * When this error occurs, the driver is not guaranteed |
| 14565 | * to have any rpi regions posted to the device and |
| 14566 | * must either attempt to repost the regions or take a |
| 14567 | * fatal error. |
| 14568 | **/ |
| 14569 | int |
| 14570 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14571 | { |
| 14572 | struct lpfc_rpi_hdr *rpi_page; |
| 14573 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14574 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14575 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14576 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14577 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14578 | goto exit; |
| 14579 | if (phba->sli4_hba.extents_in_use) |
| 14580 | return -EIO; |
| 14581 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14582 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14583 | /* |
| 14584 | * Assign the rpi headers a physical rpi only if the driver |
| 14585 | * has not initialized those resources. A port reset only |
| 14586 | * needs the headers posted. |
| 14587 | */ |
| 14588 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14589 | LPFC_RPI_RSRC_RDY) |
| 14590 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14591 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14592 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14593 | if (rc != MBX_SUCCESS) { |
| 14594 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14595 | "2008 Error %d posting all rpi " |
| 14596 | "headers\n", rc); |
| 14597 | rc = -EIO; |
| 14598 | break; |
| 14599 | } |
| 14600 | } |
| 14601 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14602 | exit: |
| 14603 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14604 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14605 | return rc; |
| 14606 | } |
| 14607 | |
| 14608 | /** |
| 14609 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14610 | * @phba: pointer to lpfc hba data structure. |
| 14611 | * @rpi_page: pointer to the rpi memory region. |
| 14612 | * |
| 14613 | * This routine is invoked to post a single rpi header to the |
| 14614 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14615 | * maps up to 64 rpi context regions. |
| 14616 | * |
| 14617 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14618 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14619 | * -ENOMEM - No available memory |
| 14620 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14621 | **/ |
| 14622 | int |
| 14623 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14624 | { |
| 14625 | LPFC_MBOXQ_t *mboxq; |
| 14626 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14627 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14628 | uint32_t shdr_status, shdr_add_status; |
| 14629 | union lpfc_sli4_cfg_shdr *shdr; |
| 14630 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14631 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14632 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14633 | return rc; |
| 14634 | if (phba->sli4_hba.extents_in_use) |
| 14635 | return -EIO; |
| 14636 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14637 | /* The port is notified of the header region via a mailbox command. */ |
| 14638 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14639 | if (!mboxq) { |
| 14640 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14641 | "2001 Unable to allocate memory for issuing " |
| 14642 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14643 | return -ENOMEM; |
| 14644 | } |
| 14645 | |
| 14646 | /* Post all rpi memory regions to the port. */ |
| 14647 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14648 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14649 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14650 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14651 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14652 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14653 | |
| 14654 | |
| 14655 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14656 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14657 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14658 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14659 | hdr_tmpl, rpi_page->page_count); |
| 14660 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14661 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14662 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14663 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14664 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14665 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14666 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14667 | if (rc != MBX_TIMEOUT) |
| 14668 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14669 | if (shdr_status || shdr_add_status || rc) { |
| 14670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14671 | "2514 POST_RPI_HDR mailbox failed with " |
| 14672 | "status x%x add_status x%x, mbx status x%x\n", |
| 14673 | shdr_status, shdr_add_status, rc); |
| 14674 | rc = -ENXIO; |
| 14675 | } |
| 14676 | return rc; |
| 14677 | } |
| 14678 | |
| 14679 | /** |
| 14680 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14681 | * @phba: pointer to lpfc hba data structure. |
| 14682 | * |
| 14683 | * This routine is invoked to post rpi header templates to the |
| 14684 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14685 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14686 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14687 | * |
| 14688 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14689 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14690 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14691 | **/ |
| 14692 | int |
| 14693 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14694 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14695 | unsigned long rpi; |
| 14696 | uint16_t max_rpi, rpi_limit; |
| 14697 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14698 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14699 | |
| 14700 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14701 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14702 | |
| 14703 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14704 | * Fetch the next logical rpi. Because this index is logical, |
| 14705 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14706 | */ |
| 14707 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14708 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 14709 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14710 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 14711 | else { |
| 14712 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 14713 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 14714 | phba->sli4_hba.rpi_count++; |
| 14715 | } |
| 14716 | |
| 14717 | /* |
| 14718 | * Don't try to allocate more rpi header regions if the device limit |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14719 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14720 | */ |
| 14721 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 14722 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 14723 | spin_unlock_irq(&phba->hbalock); |
| 14724 | return rpi; |
| 14725 | } |
| 14726 | |
| 14727 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14728 | * RPI header postings are not required for SLI4 ports capable of |
| 14729 | * extents. |
| 14730 | */ |
| 14731 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 14732 | spin_unlock_irq(&phba->hbalock); |
| 14733 | return rpi; |
| 14734 | } |
| 14735 | |
| 14736 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14737 | * If the driver is running low on rpi resources, allocate another |
| 14738 | * page now. Note that the next_rpi value is used because |
| 14739 | * it represents how many are actually in use whereas max_rpi notes |
| 14740 | * how many are supported max by the device. |
| 14741 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14742 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14743 | spin_unlock_irq(&phba->hbalock); |
| 14744 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 14745 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 14746 | if (!rpi_hdr) { |
| 14747 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14748 | "2002 Error Could not grow rpi " |
| 14749 | "count\n"); |
| 14750 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14751 | lrpi = rpi_hdr->start_rpi; |
| 14752 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14753 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 14754 | } |
| 14755 | } |
| 14756 | |
| 14757 | return rpi; |
| 14758 | } |
| 14759 | |
| 14760 | /** |
| 14761 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14762 | * @phba: pointer to lpfc hba data structure. |
| 14763 | * |
| 14764 | * This routine is invoked to release an rpi to the pool of |
| 14765 | * available rpis maintained by the driver. |
| 14766 | **/ |
| 14767 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14768 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14769 | { |
| 14770 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 14771 | phba->sli4_hba.rpi_count--; |
| 14772 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 14773 | } |
| 14774 | } |
| 14775 | |
| 14776 | /** |
| 14777 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14778 | * @phba: pointer to lpfc hba data structure. |
| 14779 | * |
| 14780 | * This routine is invoked to release an rpi to the pool of |
| 14781 | * available rpis maintained by the driver. |
| 14782 | **/ |
| 14783 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14784 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14785 | { |
| 14786 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14787 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14788 | spin_unlock_irq(&phba->hbalock); |
| 14789 | } |
| 14790 | |
| 14791 | /** |
| 14792 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 14793 | * @phba: pointer to lpfc hba data structure. |
| 14794 | * |
| 14795 | * This routine is invoked to remove the memory region that |
| 14796 | * provided rpi via a bitmask. |
| 14797 | **/ |
| 14798 | void |
| 14799 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 14800 | { |
| 14801 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14802 | kfree(phba->sli4_hba.rpi_ids); |
| 14803 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14804 | } |
| 14805 | |
| 14806 | /** |
| 14807 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 14808 | * @phba: pointer to lpfc hba data structure. |
| 14809 | * |
| 14810 | * This routine is invoked to remove the memory region that |
| 14811 | * provided rpi via a bitmask. |
| 14812 | **/ |
| 14813 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14814 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 14815 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14816 | { |
| 14817 | LPFC_MBOXQ_t *mboxq; |
| 14818 | struct lpfc_hba *phba = ndlp->phba; |
| 14819 | int rc; |
| 14820 | |
| 14821 | /* The port is notified of the header region via a mailbox command. */ |
| 14822 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14823 | if (!mboxq) |
| 14824 | return -ENOMEM; |
| 14825 | |
| 14826 | /* Post all rpi memory regions to the port. */ |
| 14827 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14828 | if (cmpl) { |
| 14829 | mboxq->mbox_cmpl = cmpl; |
| 14830 | mboxq->context1 = arg; |
| 14831 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 14832 | } else |
| 14833 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14834 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14835 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14836 | if (rc == MBX_NOT_FINISHED) { |
| 14837 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14838 | "2010 Resume RPI Mailbox failed " |
| 14839 | "status %d, mbxStatus x%x\n", rc, |
| 14840 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 14841 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14842 | return -EIO; |
| 14843 | } |
| 14844 | return 0; |
| 14845 | } |
| 14846 | |
| 14847 | /** |
| 14848 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14849 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14850 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14851 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14852 | * |
| 14853 | * Returns: |
| 14854 | * 0 success |
| 14855 | * -Evalue otherwise |
| 14856 | **/ |
| 14857 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14858 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14859 | { |
| 14860 | LPFC_MBOXQ_t *mboxq; |
| 14861 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14862 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14863 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14864 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14865 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14866 | if (!mboxq) |
| 14867 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14868 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14869 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14870 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14871 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14872 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14873 | "2022 INIT VPI Mailbox failed " |
| 14874 | "status %d, mbxStatus x%x\n", rc, |
| 14875 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14876 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14877 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14878 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14879 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14880 | |
| 14881 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14882 | } |
| 14883 | |
| 14884 | /** |
| 14885 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 14886 | * @phba: pointer to lpfc hba data structure. |
| 14887 | * @mboxq: Pointer to mailbox object. |
| 14888 | * |
| 14889 | * This routine is invoked to manually add a single FCF record. The caller |
| 14890 | * must pass a completely initialized FCF_Record. This routine takes |
| 14891 | * care of the nonembedded mailbox operations. |
| 14892 | **/ |
| 14893 | static void |
| 14894 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 14895 | { |
| 14896 | void *virt_addr; |
| 14897 | union lpfc_sli4_cfg_shdr *shdr; |
| 14898 | uint32_t shdr_status, shdr_add_status; |
| 14899 | |
| 14900 | virt_addr = mboxq->sge_array->addr[0]; |
| 14901 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14902 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 14903 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14904 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14905 | |
| 14906 | if ((shdr_status || shdr_add_status) && |
| 14907 | (shdr_status != STATUS_FCF_IN_USE)) |
| 14908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14909 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 14910 | "status x%x add_status x%x\n", |
| 14911 | shdr_status, shdr_add_status); |
| 14912 | |
| 14913 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14914 | } |
| 14915 | |
| 14916 | /** |
| 14917 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 14918 | * @phba: pointer to lpfc hba data structure. |
| 14919 | * @fcf_record: pointer to the initialized fcf record to add. |
| 14920 | * |
| 14921 | * This routine is invoked to manually add a single FCF record. The caller |
| 14922 | * must pass a completely initialized FCF_Record. This routine takes |
| 14923 | * care of the nonembedded mailbox operations. |
| 14924 | **/ |
| 14925 | int |
| 14926 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 14927 | { |
| 14928 | int rc = 0; |
| 14929 | LPFC_MBOXQ_t *mboxq; |
| 14930 | uint8_t *bytep; |
| 14931 | void *virt_addr; |
| 14932 | dma_addr_t phys_addr; |
| 14933 | struct lpfc_mbx_sge sge; |
| 14934 | uint32_t alloc_len, req_len; |
| 14935 | uint32_t fcfindex; |
| 14936 | |
| 14937 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14938 | if (!mboxq) { |
| 14939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14940 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 14941 | return -ENOMEM; |
| 14942 | } |
| 14943 | |
| 14944 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 14945 | sizeof(uint32_t); |
| 14946 | |
| 14947 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14948 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14949 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 14950 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 14951 | if (alloc_len < req_len) { |
| 14952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14953 | "2523 Allocated DMA memory size (x%x) is " |
| 14954 | "less than the requested DMA memory " |
| 14955 | "size (x%x)\n", alloc_len, req_len); |
| 14956 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14957 | return -ENOMEM; |
| 14958 | } |
| 14959 | |
| 14960 | /* |
| 14961 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 14962 | * routine only uses a single SGE. |
| 14963 | */ |
| 14964 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 14965 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14966 | virt_addr = mboxq->sge_array->addr[0]; |
| 14967 | /* |
| 14968 | * Configure the FCF record for FCFI 0. This is the driver's |
| 14969 | * hardcoded default and gets used in nonFIP mode. |
| 14970 | */ |
| 14971 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 14972 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 14973 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 14974 | |
| 14975 | /* |
| 14976 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 14977 | * the FCoE header plus word10. The data copy needs to be endian |
| 14978 | * correct. |
| 14979 | */ |
| 14980 | bytep += sizeof(uint32_t); |
| 14981 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 14982 | mboxq->vport = phba->pport; |
| 14983 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 14984 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14985 | if (rc == MBX_NOT_FINISHED) { |
| 14986 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14987 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 14988 | "status 0x%x\n", rc); |
| 14989 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14990 | rc = -EIO; |
| 14991 | } else |
| 14992 | rc = 0; |
| 14993 | |
| 14994 | return rc; |
| 14995 | } |
| 14996 | |
| 14997 | /** |
| 14998 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 14999 | * @phba: pointer to lpfc hba data structure. |
| 15000 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15001 | * @fcf_index: FCF table entry index. |
| 15002 | * |
| 15003 | * This routine is invoked to build the driver's default FCF record. The |
| 15004 | * values used are hardcoded. This routine handles memory initialization. |
| 15005 | * |
| 15006 | **/ |
| 15007 | void |
| 15008 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15009 | struct fcf_record *fcf_record, |
| 15010 | uint16_t fcf_index) |
| 15011 | { |
| 15012 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15013 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15014 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15015 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15016 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15017 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15018 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15019 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15020 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15021 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15022 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15023 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15024 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15025 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15026 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15027 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15028 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15029 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15030 | /* Set the VLAN bit map */ |
| 15031 | if (phba->valid_vlan) { |
| 15032 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15033 | = 1 << (phba->vlan_id % 8); |
| 15034 | } |
| 15035 | } |
| 15036 | |
| 15037 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15038 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15039 | * @phba: pointer to lpfc hba data structure. |
| 15040 | * @fcf_index: FCF table entry offset. |
| 15041 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15042 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15043 | * record and processing it one at a time starting from the @fcf_index |
| 15044 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15045 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15046 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15047 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15048 | **/ |
| 15049 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15050 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15051 | { |
| 15052 | int rc = 0, error; |
| 15053 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15054 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15055 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15056 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15057 | if (!mboxq) { |
| 15058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15059 | "2000 Failed to allocate mbox for " |
| 15060 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15061 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15062 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15063 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15064 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15065 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15066 | if (rc) { |
| 15067 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15068 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15069 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15070 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15071 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15072 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15073 | |
| 15074 | spin_lock_irq(&phba->hbalock); |
| 15075 | phba->hba_flag |= FCF_TS_INPROG; |
| 15076 | spin_unlock_irq(&phba->hbalock); |
| 15077 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15078 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15079 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15080 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15081 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15082 | /* Reset eligible FCF count for new scan */ |
| 15083 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15084 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15085 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15086 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15087 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15088 | if (error) { |
| 15089 | if (mboxq) |
| 15090 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15091 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15092 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15093 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15094 | spin_unlock_irq(&phba->hbalock); |
| 15095 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15096 | return error; |
| 15097 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15098 | |
| 15099 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15100 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15101 | * @phba: pointer to lpfc hba data structure. |
| 15102 | * @fcf_index: FCF table entry offset. |
| 15103 | * |
| 15104 | * This routine is invoked to read an FCF record indicated by @fcf_index |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15105 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15106 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15107 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15108 | * otherwise. |
| 15109 | **/ |
| 15110 | int |
| 15111 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15112 | { |
| 15113 | int rc = 0, error; |
| 15114 | LPFC_MBOXQ_t *mboxq; |
| 15115 | |
| 15116 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15117 | if (!mboxq) { |
| 15118 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15119 | "2763 Failed to allocate mbox for " |
| 15120 | "READ_FCF cmd\n"); |
| 15121 | error = -ENOMEM; |
| 15122 | goto fail_fcf_read; |
| 15123 | } |
| 15124 | /* Construct the read FCF record mailbox command */ |
| 15125 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15126 | if (rc) { |
| 15127 | error = -EINVAL; |
| 15128 | goto fail_fcf_read; |
| 15129 | } |
| 15130 | /* Issue the mailbox command asynchronously */ |
| 15131 | mboxq->vport = phba->pport; |
| 15132 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15133 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15134 | if (rc == MBX_NOT_FINISHED) |
| 15135 | error = -EIO; |
| 15136 | else |
| 15137 | error = 0; |
| 15138 | |
| 15139 | fail_fcf_read: |
| 15140 | if (error && mboxq) |
| 15141 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15142 | return error; |
| 15143 | } |
| 15144 | |
| 15145 | /** |
| 15146 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15147 | * @phba: pointer to lpfc hba data structure. |
| 15148 | * @fcf_index: FCF table entry offset. |
| 15149 | * |
| 15150 | * This routine is invoked to read an FCF record indicated by @fcf_index to |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15151 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15152 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15153 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15154 | * otherwise. |
| 15155 | **/ |
| 15156 | int |
| 15157 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15158 | { |
| 15159 | int rc = 0, error; |
| 15160 | LPFC_MBOXQ_t *mboxq; |
| 15161 | |
| 15162 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15163 | if (!mboxq) { |
| 15164 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15165 | "2758 Failed to allocate mbox for " |
| 15166 | "READ_FCF cmd\n"); |
| 15167 | error = -ENOMEM; |
| 15168 | goto fail_fcf_read; |
| 15169 | } |
| 15170 | /* Construct the read FCF record mailbox command */ |
| 15171 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15172 | if (rc) { |
| 15173 | error = -EINVAL; |
| 15174 | goto fail_fcf_read; |
| 15175 | } |
| 15176 | /* Issue the mailbox command asynchronously */ |
| 15177 | mboxq->vport = phba->pport; |
| 15178 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15179 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15180 | if (rc == MBX_NOT_FINISHED) |
| 15181 | error = -EIO; |
| 15182 | else |
| 15183 | error = 0; |
| 15184 | |
| 15185 | fail_fcf_read: |
| 15186 | if (error && mboxq) |
| 15187 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15188 | return error; |
| 15189 | } |
| 15190 | |
| 15191 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15192 | * lpfc_check_next_fcf_pri |
| 15193 | * phba pointer to the lpfc_hba struct for this port. |
| 15194 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15195 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15196 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15197 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15198 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15199 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15200 | * fcf_indexes. |
| 15201 | * returns: |
| 15202 | * 1=success 0=failure |
| 15203 | **/ |
| 15204 | int |
| 15205 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15206 | { |
| 15207 | uint16_t next_fcf_pri; |
| 15208 | uint16_t last_index; |
| 15209 | struct lpfc_fcf_pri *fcf_pri; |
| 15210 | int rc; |
| 15211 | int ret = 0; |
| 15212 | |
| 15213 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15214 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15215 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15216 | "3060 Last IDX %d\n", last_index); |
| 15217 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 15218 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15219 | "3061 Last IDX %d\n", last_index); |
| 15220 | return 0; /* Empty rr list */ |
| 15221 | } |
| 15222 | next_fcf_pri = 0; |
| 15223 | /* |
| 15224 | * Clear the rr_bmask and set all of the bits that are at this |
| 15225 | * priority. |
| 15226 | */ |
| 15227 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15228 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15229 | spin_lock_irq(&phba->hbalock); |
| 15230 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15231 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15232 | continue; |
| 15233 | /* |
| 15234 | * the 1st priority that has not FLOGI failed |
| 15235 | * will be the highest. |
| 15236 | */ |
| 15237 | if (!next_fcf_pri) |
| 15238 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15239 | spin_unlock_irq(&phba->hbalock); |
| 15240 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15241 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15242 | fcf_pri->fcf_rec.fcf_index); |
| 15243 | if (rc) |
| 15244 | return 0; |
| 15245 | } |
| 15246 | spin_lock_irq(&phba->hbalock); |
| 15247 | } |
| 15248 | /* |
| 15249 | * if next_fcf_pri was not set above and the list is not empty then |
| 15250 | * we have failed flogis on all of them. So reset flogi failed |
| 15251 | * and start at the begining. |
| 15252 | */ |
| 15253 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15254 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15255 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15256 | /* |
| 15257 | * the 1st priority that has not FLOGI failed |
| 15258 | * will be the highest. |
| 15259 | */ |
| 15260 | if (!next_fcf_pri) |
| 15261 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15262 | spin_unlock_irq(&phba->hbalock); |
| 15263 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15264 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15265 | fcf_pri->fcf_rec.fcf_index); |
| 15266 | if (rc) |
| 15267 | return 0; |
| 15268 | } |
| 15269 | spin_lock_irq(&phba->hbalock); |
| 15270 | } |
| 15271 | } else |
| 15272 | ret = 1; |
| 15273 | spin_unlock_irq(&phba->hbalock); |
| 15274 | |
| 15275 | return ret; |
| 15276 | } |
| 15277 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15278 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15279 | * @phba: pointer to lpfc hba data structure. |
| 15280 | * |
| 15281 | * This routine is to get the next eligible FCF record index in a round |
| 15282 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15283 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15284 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15285 | * shall be returned. |
| 15286 | **/ |
| 15287 | uint16_t |
| 15288 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15289 | { |
| 15290 | uint16_t next_fcf_index; |
| 15291 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15292 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15293 | next_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15294 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
| 15295 | LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15296 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15297 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15298 | next_fcf_index); |
| 15299 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15300 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15301 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15302 | /* |
| 15303 | * If we have wrapped then we need to clear the bits that |
| 15304 | * have been tested so that we can detect when we should |
| 15305 | * change the priority level. |
| 15306 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15307 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15308 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15309 | } |
| 15310 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15311 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15312 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15313 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15314 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15315 | /* |
| 15316 | * If next fcf index is not found check if there are lower |
| 15317 | * Priority level fcf's in the fcf_priority list. |
| 15318 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15319 | * at that level and continue the selection process. |
| 15320 | */ |
| 15321 | if (lpfc_check_next_fcf_pri_level(phba)) |
| 15322 | goto next_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15323 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15324 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15325 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15326 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15327 | else { |
| 15328 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15329 | "3063 Only FCF available idx %d, flag %x\n", |
| 15330 | next_fcf_index, |
| 15331 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15332 | return next_fcf_index; |
| 15333 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15334 | } |
| 15335 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15336 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15337 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15338 | LPFC_FCF_FLOGI_FAILED) |
| 15339 | goto next_priority; |
| 15340 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15341 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15342 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15343 | next_fcf_index); |
| 15344 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15345 | return next_fcf_index; |
| 15346 | } |
| 15347 | |
| 15348 | /** |
| 15349 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15350 | * @phba: pointer to lpfc hba data structure. |
| 15351 | * |
| 15352 | * This routine sets the FCF record index in to the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15353 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15354 | * does not go beyond the range of the driver allocated bmask dimension |
| 15355 | * before setting the bit. |
| 15356 | * |
| 15357 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15358 | * -EINVAL. |
| 15359 | **/ |
| 15360 | int |
| 15361 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15362 | { |
| 15363 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15364 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15365 | "2610 FCF (x%x) reached driver's book " |
| 15366 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15367 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15368 | return -EINVAL; |
| 15369 | } |
| 15370 | /* Set the eligible FCF record index bmask */ |
| 15371 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15372 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15373 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15374 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15375 | "bmask\n", fcf_index); |
| 15376 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15377 | return 0; |
| 15378 | } |
| 15379 | |
| 15380 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15381 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15382 | * @phba: pointer to lpfc hba data structure. |
| 15383 | * |
| 15384 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15385 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15386 | * does not go beyond the range of the driver allocated bmask dimension |
| 15387 | * before clearing the bit. |
| 15388 | **/ |
| 15389 | void |
| 15390 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15391 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15392 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15393 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15394 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15395 | "2762 FCF (x%x) reached driver's book " |
| 15396 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15397 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15398 | return; |
| 15399 | } |
| 15400 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15401 | spin_lock_irq(&phba->hbalock); |
| 15402 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15403 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15404 | list_del_init(&fcf_pri->list); |
| 15405 | break; |
| 15406 | } |
| 15407 | } |
| 15408 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15409 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15410 | |
| 15411 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15412 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15413 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15414 | } |
| 15415 | |
| 15416 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15417 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15418 | * @phba: pointer to lpfc hba data structure. |
| 15419 | * |
| 15420 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15421 | * command. If the mailbox command returned failure, it will try to stop the |
| 15422 | * FCF rediscover wait timer. |
| 15423 | **/ |
| 15424 | void |
| 15425 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15426 | { |
| 15427 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15428 | uint32_t shdr_status, shdr_add_status; |
| 15429 | |
| 15430 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15431 | |
| 15432 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15433 | &redisc_fcf->header.cfg_shdr.response); |
| 15434 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15435 | &redisc_fcf->header.cfg_shdr.response); |
| 15436 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15437 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15438 | "2746 Requesting for FCF rediscovery failed " |
| 15439 | "status x%x add_status x%x\n", |
| 15440 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15441 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15442 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15443 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15444 | spin_unlock_irq(&phba->hbalock); |
| 15445 | /* |
| 15446 | * CVL event triggered FCF rediscover request failed, |
| 15447 | * last resort to re-try current registered FCF entry. |
| 15448 | */ |
| 15449 | lpfc_retry_pport_discovery(phba); |
| 15450 | } else { |
| 15451 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15452 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15453 | spin_unlock_irq(&phba->hbalock); |
| 15454 | /* |
| 15455 | * DEAD FCF event triggered FCF rediscover request |
| 15456 | * failed, last resort to fail over as a link down |
| 15457 | * to FCF registration. |
| 15458 | */ |
| 15459 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15460 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15461 | } else { |
| 15462 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15463 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15464 | /* |
| 15465 | * Start FCF rediscovery wait timer for pending FCF |
| 15466 | * before rescan FCF record table. |
| 15467 | */ |
| 15468 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15469 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15470 | |
| 15471 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15472 | } |
| 15473 | |
| 15474 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15475 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15476 | * @phba: pointer to lpfc hba data structure. |
| 15477 | * |
| 15478 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15479 | * by the port. |
| 15480 | **/ |
| 15481 | int |
| 15482 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15483 | { |
| 15484 | LPFC_MBOXQ_t *mbox; |
| 15485 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15486 | int rc, length; |
| 15487 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15488 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15489 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15490 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15491 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15492 | if (!mbox) { |
| 15493 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15494 | "2745 Failed to allocate mbox for " |
| 15495 | "requesting FCF rediscover.\n"); |
| 15496 | return -ENOMEM; |
| 15497 | } |
| 15498 | |
| 15499 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15500 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15501 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15502 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15503 | length, LPFC_SLI4_MBX_EMBED); |
| 15504 | |
| 15505 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15506 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15507 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15508 | |
| 15509 | /* Issue the mailbox command asynchronously */ |
| 15510 | mbox->vport = phba->pport; |
| 15511 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15512 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15513 | |
| 15514 | if (rc == MBX_NOT_FINISHED) { |
| 15515 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15516 | return -EIO; |
| 15517 | } |
| 15518 | return 0; |
| 15519 | } |
| 15520 | |
| 15521 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15522 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15523 | * @phba: pointer to lpfc hba data structure. |
| 15524 | * |
| 15525 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15526 | * event when driver failed to perform fast FCF failover. |
| 15527 | **/ |
| 15528 | void |
| 15529 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15530 | { |
| 15531 | uint32_t link_state; |
| 15532 | |
| 15533 | /* |
| 15534 | * Last resort as FCF DEAD event failover will treat this as |
| 15535 | * a link down, but save the link state because we don't want |
| 15536 | * it to be changed to Link Down unless it is already down. |
| 15537 | */ |
| 15538 | link_state = phba->link_state; |
| 15539 | lpfc_linkdown(phba); |
| 15540 | phba->link_state = link_state; |
| 15541 | |
| 15542 | /* Unregister FCF if no devices connected to it */ |
| 15543 | lpfc_unregister_unused_fcf(phba); |
| 15544 | } |
| 15545 | |
| 15546 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15547 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15548 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15549 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15550 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15551 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15552 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15553 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15554 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15555 | static uint32_t |
| 15556 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15557 | { |
| 15558 | LPFC_MBOXQ_t *pmb = NULL; |
| 15559 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15560 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15561 | int rc; |
| 15562 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15563 | if (!rgn23_data) |
| 15564 | return 0; |
| 15565 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15566 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15567 | if (!pmb) { |
| 15568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15569 | "2600 failed to allocate mailbox memory\n"); |
| 15570 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15571 | } |
| 15572 | mb = &pmb->u.mb; |
| 15573 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15574 | do { |
| 15575 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15576 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15577 | |
| 15578 | if (rc != MBX_SUCCESS) { |
| 15579 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15580 | "2601 failed to read config " |
| 15581 | "region 23, rc 0x%x Status 0x%x\n", |
| 15582 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15583 | mb->un.varDmp.word_cnt = 0; |
| 15584 | } |
| 15585 | /* |
| 15586 | * dump mem may return a zero when finished or we got a |
| 15587 | * mailbox error, either way we are done. |
| 15588 | */ |
| 15589 | if (mb->un.varDmp.word_cnt == 0) |
| 15590 | break; |
| 15591 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15592 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15593 | |
| 15594 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15595 | rgn23_data + offset, |
| 15596 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15597 | offset += mb->un.varDmp.word_cnt; |
| 15598 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15599 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15600 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15601 | return offset; |
| 15602 | } |
| 15603 | |
| 15604 | /** |
| 15605 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15606 | * @phba: pointer to lpfc hba data structure. |
| 15607 | * @rgn23_data: pointer to configure region 23 data. |
| 15608 | * |
| 15609 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15610 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15611 | * will be returned, otherwise, 0 will be returned. |
| 15612 | **/ |
| 15613 | static uint32_t |
| 15614 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15615 | { |
| 15616 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15617 | struct lpfc_dmabuf *mp = NULL; |
| 15618 | struct lpfc_mqe *mqe; |
| 15619 | uint32_t data_length = 0; |
| 15620 | int rc; |
| 15621 | |
| 15622 | if (!rgn23_data) |
| 15623 | return 0; |
| 15624 | |
| 15625 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15626 | if (!mboxq) { |
| 15627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15628 | "3105 failed to allocate mailbox memory\n"); |
| 15629 | return 0; |
| 15630 | } |
| 15631 | |
| 15632 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15633 | goto out; |
| 15634 | mqe = &mboxq->u.mqe; |
| 15635 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15636 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15637 | if (rc) |
| 15638 | goto out; |
| 15639 | data_length = mqe->un.mb_words[5]; |
| 15640 | if (data_length == 0) |
| 15641 | goto out; |
| 15642 | if (data_length > DMP_RGN23_SIZE) { |
| 15643 | data_length = 0; |
| 15644 | goto out; |
| 15645 | } |
| 15646 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15647 | out: |
| 15648 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15649 | if (mp) { |
| 15650 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15651 | kfree(mp); |
| 15652 | } |
| 15653 | return data_length; |
| 15654 | } |
| 15655 | |
| 15656 | /** |
| 15657 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15658 | * @phba: pointer to lpfc hba data structure. |
| 15659 | * |
| 15660 | * This function read region 23 and parse TLV for port status to |
| 15661 | * decide if the user disaled the port. If the TLV indicates the |
| 15662 | * port is disabled, the hba_flag is set accordingly. |
| 15663 | **/ |
| 15664 | void |
| 15665 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15666 | { |
| 15667 | uint8_t *rgn23_data = NULL; |
| 15668 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15669 | uint32_t offset = 0; |
| 15670 | |
| 15671 | /* Get adapter Region 23 data */ |
| 15672 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15673 | if (!rgn23_data) |
| 15674 | goto out; |
| 15675 | |
| 15676 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15677 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15678 | else { |
| 15679 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15680 | &phba->sli4_hba.sli_intf); |
| 15681 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15682 | goto out; |
| 15683 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15684 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15685 | |
| 15686 | if (!data_size) |
| 15687 | goto out; |
| 15688 | |
| 15689 | /* Check the region signature first */ |
| 15690 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15691 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15692 | "2619 Config region 23 has bad signature\n"); |
| 15693 | goto out; |
| 15694 | } |
| 15695 | offset += 4; |
| 15696 | |
| 15697 | /* Check the data structure version */ |
| 15698 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 15699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15700 | "2620 Config region 23 has bad version\n"); |
| 15701 | goto out; |
| 15702 | } |
| 15703 | offset += 4; |
| 15704 | |
| 15705 | /* Parse TLV entries in the region */ |
| 15706 | while (offset < data_size) { |
| 15707 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 15708 | break; |
| 15709 | /* |
| 15710 | * If the TLV is not driver specific TLV or driver id is |
| 15711 | * not linux driver id, skip the record. |
| 15712 | */ |
| 15713 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 15714 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 15715 | (rgn23_data[offset + 3] != 0)) { |
| 15716 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15717 | continue; |
| 15718 | } |
| 15719 | |
| 15720 | /* Driver found a driver specific TLV in the config region */ |
| 15721 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 15722 | offset += 4; |
| 15723 | tlv_offset = 0; |
| 15724 | |
| 15725 | /* |
| 15726 | * Search for configured port state sub-TLV. |
| 15727 | */ |
| 15728 | while ((offset < data_size) && |
| 15729 | (tlv_offset < sub_tlv_len)) { |
| 15730 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 15731 | offset += 4; |
| 15732 | tlv_offset += 4; |
| 15733 | break; |
| 15734 | } |
| 15735 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 15736 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15737 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 15738 | continue; |
| 15739 | } |
| 15740 | |
| 15741 | /* This HBA contains PORT_STE configured */ |
| 15742 | if (!rgn23_data[offset + 2]) |
| 15743 | phba->hba_flag |= LINK_DISABLED; |
| 15744 | |
| 15745 | goto out; |
| 15746 | } |
| 15747 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15748 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15749 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15750 | kfree(rgn23_data); |
| 15751 | return; |
| 15752 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15753 | |
| 15754 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15755 | * lpfc_wr_object - write an object to the firmware |
| 15756 | * @phba: HBA structure that indicates port to create a queue on. |
| 15757 | * @dmabuf_list: list of dmabufs to write to the port. |
| 15758 | * @size: the total byte value of the objects to write to the port. |
| 15759 | * @offset: the current offset to be used to start the transfer. |
| 15760 | * |
| 15761 | * This routine will create a wr_object mailbox command to send to the port. |
| 15762 | * the mailbox command will be constructed using the dma buffers described in |
| 15763 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 15764 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 15765 | * used to indicate the starting offset of the transfer and will also return |
| 15766 | * the offset after the write object mailbox has completed. @size is used to |
| 15767 | * determine the end of the object and whether the eof bit should be set. |
| 15768 | * |
| 15769 | * Return 0 is successful and offset will contain the the new offset to use |
| 15770 | * for the next write. |
| 15771 | * Return negative value for error cases. |
| 15772 | **/ |
| 15773 | int |
| 15774 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 15775 | uint32_t size, uint32_t *offset) |
| 15776 | { |
| 15777 | struct lpfc_mbx_wr_object *wr_object; |
| 15778 | LPFC_MBOXQ_t *mbox; |
| 15779 | int rc = 0, i = 0; |
| 15780 | uint32_t shdr_status, shdr_add_status; |
| 15781 | uint32_t mbox_tmo; |
| 15782 | union lpfc_sli4_cfg_shdr *shdr; |
| 15783 | struct lpfc_dmabuf *dmabuf; |
| 15784 | uint32_t written = 0; |
| 15785 | |
| 15786 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15787 | if (!mbox) |
| 15788 | return -ENOMEM; |
| 15789 | |
| 15790 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15791 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 15792 | sizeof(struct lpfc_mbx_wr_object) - |
| 15793 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 15794 | |
| 15795 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 15796 | wr_object->u.request.write_offset = *offset; |
| 15797 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 15798 | wr_object->u.request.object_name[0] = |
| 15799 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 15800 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 15801 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 15802 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 15803 | break; |
| 15804 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 15805 | wr_object->u.request.bde[i].addrHigh = |
| 15806 | putPaddrHigh(dmabuf->phys); |
| 15807 | if (written + SLI4_PAGE_SIZE >= size) { |
| 15808 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15809 | (size - written); |
| 15810 | written += (size - written); |
| 15811 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 15812 | } else { |
| 15813 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15814 | SLI4_PAGE_SIZE; |
| 15815 | written += SLI4_PAGE_SIZE; |
| 15816 | } |
| 15817 | i++; |
| 15818 | } |
| 15819 | wr_object->u.request.bde_count = i; |
| 15820 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 15821 | if (!phba->sli4_hba.intr_enable) |
| 15822 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15823 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15824 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15825 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15826 | } |
| 15827 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15828 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 15829 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15830 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15831 | if (rc != MBX_TIMEOUT) |
| 15832 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15833 | if (shdr_status || shdr_add_status || rc) { |
| 15834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15835 | "3025 Write Object mailbox failed with " |
| 15836 | "status x%x add_status x%x, mbx status x%x\n", |
| 15837 | shdr_status, shdr_add_status, rc); |
| 15838 | rc = -ENXIO; |
| 15839 | } else |
| 15840 | *offset += wr_object->u.response.actual_write_length; |
| 15841 | return rc; |
| 15842 | } |
| 15843 | |
| 15844 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15845 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 15846 | * @vport: pointer to vport data structure. |
| 15847 | * |
| 15848 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 15849 | * and REG_VPI mailbox commands associated with the vport. This function |
| 15850 | * is called when driver want to restart discovery of the vport due to |
| 15851 | * a Clear Virtual Link event. |
| 15852 | **/ |
| 15853 | void |
| 15854 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 15855 | { |
| 15856 | struct lpfc_hba *phba = vport->phba; |
| 15857 | LPFC_MBOXQ_t *mb, *nextmb; |
| 15858 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15859 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15860 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15861 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15862 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15863 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15864 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15865 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15866 | spin_lock_irq(&phba->hbalock); |
| 15867 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 15868 | if (mb->vport != vport) |
| 15869 | continue; |
| 15870 | |
| 15871 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15872 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15873 | continue; |
| 15874 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15875 | list_del(&mb->list); |
| 15876 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 15877 | } |
| 15878 | /* Clean up active mailbox command with the vport */ |
| 15879 | mb = phba->sli.mbox_active; |
| 15880 | if (mb && (mb->vport == vport)) { |
| 15881 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 15882 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 15883 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15884 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15885 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15886 | /* Put reference count for delayed processing */ |
| 15887 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 15888 | /* Unregister the RPI when mailbox complete */ |
| 15889 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15890 | } |
| 15891 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15892 | /* Cleanup any mailbox completions which are not yet processed */ |
| 15893 | do { |
| 15894 | restart_loop = 0; |
| 15895 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 15896 | /* |
| 15897 | * If this mailox is already processed or it is |
| 15898 | * for another vport ignore it. |
| 15899 | */ |
| 15900 | if ((mb->vport != vport) || |
| 15901 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 15902 | continue; |
| 15903 | |
| 15904 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15905 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15906 | continue; |
| 15907 | |
| 15908 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15909 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15910 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15911 | /* Unregister the RPI when mailbox complete */ |
| 15912 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15913 | restart_loop = 1; |
| 15914 | spin_unlock_irq(&phba->hbalock); |
| 15915 | spin_lock(shost->host_lock); |
| 15916 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15917 | spin_unlock(shost->host_lock); |
| 15918 | spin_lock_irq(&phba->hbalock); |
| 15919 | break; |
| 15920 | } |
| 15921 | } |
| 15922 | } while (restart_loop); |
| 15923 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15924 | spin_unlock_irq(&phba->hbalock); |
| 15925 | |
| 15926 | /* Release the cleaned-up mailbox commands */ |
| 15927 | while (!list_empty(&mbox_cmd_list)) { |
| 15928 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15929 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15930 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 15931 | if (mp) { |
| 15932 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15933 | kfree(mp); |
| 15934 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15935 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15936 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15937 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15938 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15939 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15940 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15941 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15942 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15943 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15944 | mempool_free(mb, phba->mbox_mem_pool); |
| 15945 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15946 | |
| 15947 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 15948 | if (act_mbx_ndlp) { |
| 15949 | spin_lock(shost->host_lock); |
| 15950 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15951 | spin_unlock(shost->host_lock); |
| 15952 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15953 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15954 | } |
| 15955 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15956 | /** |
| 15957 | * lpfc_drain_txq - Drain the txq |
| 15958 | * @phba: Pointer to HBA context object. |
| 15959 | * |
| 15960 | * This function attempt to submit IOCBs on the txq |
| 15961 | * to the adapter. For SLI4 adapters, the txq contains |
| 15962 | * ELS IOCBs that have been deferred because the there |
| 15963 | * are no SGLs. This congestion can occur with large |
| 15964 | * vport counts during node discovery. |
| 15965 | **/ |
| 15966 | |
| 15967 | uint32_t |
| 15968 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 15969 | { |
| 15970 | LIST_HEAD(completions); |
| 15971 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 15972 | struct lpfc_iocbq *piocbq = 0; |
| 15973 | unsigned long iflags = 0; |
| 15974 | char *fail_msg = NULL; |
| 15975 | struct lpfc_sglq *sglq; |
| 15976 | union lpfc_wqe wqe; |
| 15977 | |
| 15978 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15979 | if (pring->txq_cnt > pring->txq_max) |
| 15980 | pring->txq_max = pring->txq_cnt; |
| 15981 | |
| 15982 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15983 | |
| 15984 | while (pring->txq_cnt) { |
| 15985 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15986 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 15987 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
| 15988 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15989 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 15990 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15991 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15992 | break; |
| 15993 | } else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15994 | if (!piocbq) { |
| 15995 | /* The txq_cnt out of sync. This should |
| 15996 | * never happen |
| 15997 | */ |
| 15998 | sglq = __lpfc_clear_active_sglq(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15999 | sglq->sli4_lxritag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16000 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16001 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16002 | "2823 txq empty and txq_cnt is %d\n ", |
| 16003 | pring->txq_cnt); |
| 16004 | break; |
| 16005 | } |
| 16006 | } |
| 16007 | |
| 16008 | /* The xri and iocb resources secured, |
| 16009 | * attempt to issue request |
| 16010 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16011 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16012 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16013 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16014 | fail_msg = "to convert bpl to sgl"; |
| 16015 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16016 | fail_msg = "to convert iocb to wqe"; |
| 16017 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16018 | fail_msg = " - Wq is full"; |
| 16019 | else |
| 16020 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16021 | |
| 16022 | if (fail_msg) { |
| 16023 | /* Failed means we can't issue and need to cancel */ |
| 16024 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16025 | "2822 IOCB failed %s iotag 0x%x " |
| 16026 | "xri 0x%x\n", |
| 16027 | fail_msg, |
| 16028 | piocbq->iotag, piocbq->sli4_xritag); |
| 16029 | list_add_tail(&piocbq->list, &completions); |
| 16030 | } |
| 16031 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16032 | } |
| 16033 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16034 | /* Cancel all the IOCBs that cannot be issued */ |
| 16035 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16036 | IOERR_SLI_ABORTED); |
| 16037 | |
| 16038 | return pring->txq_cnt; |
| 16039 | } |