| 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 *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 70 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
| 71 | int); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 72 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 73 | static IOCB_t * |
| 74 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 75 | { |
| 76 | return &iocbq->iocb; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 81 | * @q: The Work Queue to operate on. |
| 82 | * @wqe: The work Queue Entry to put on the Work queue. |
| 83 | * |
| 84 | * This routine will copy the contents of @wqe to the next available entry on |
| 85 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 86 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 87 | * successful. If no entries are available on @q then this function will return |
| 88 | * -ENOMEM. |
| 89 | * The caller is expected to hold the hbalock when calling this routine. |
| 90 | **/ |
| 91 | static uint32_t |
| 92 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 93 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 94 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 95 | struct lpfc_register doorbell; |
| 96 | uint32_t host_index; |
| 97 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 98 | /* sanity check on queue memory */ |
| 99 | if (unlikely(!q)) |
| 100 | return -ENOMEM; |
| 101 | temp_wqe = q->qe[q->host_index].wqe; |
| 102 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 103 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 104 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) { |
| 105 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 106 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 107 | } |
| 108 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 109 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 110 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 111 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 112 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 113 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 114 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 115 | |
| 116 | /* Update the host index before invoking device */ |
| 117 | host_index = q->host_index; |
| 118 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 119 | |
| 120 | /* Ring Doorbell */ |
| 121 | doorbell.word0 = 0; |
| 122 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); |
| 123 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); |
| 124 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); |
| 125 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); |
| 126 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 133 | * @q: The Work Queue to operate on. |
| 134 | * @index: The index to advance the hba index to. |
| 135 | * |
| 136 | * This routine will update the HBA index of a queue to reflect consumption of |
| 137 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 138 | * an entry the host calls this function to update the queue's internal |
| 139 | * pointers. This routine returns the number of entries that were consumed by |
| 140 | * the HBA. |
| 141 | **/ |
| 142 | static uint32_t |
| 143 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 144 | { |
| 145 | uint32_t released = 0; |
| 146 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 147 | /* sanity check on queue memory */ |
| 148 | if (unlikely(!q)) |
| 149 | return 0; |
| 150 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 151 | if (q->hba_index == index) |
| 152 | return 0; |
| 153 | do { |
| 154 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 155 | released++; |
| 156 | } while (q->hba_index != index); |
| 157 | return released; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 162 | * @q: The Mailbox Queue to operate on. |
| 163 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 164 | * |
| 165 | * This routine will copy the contents of @mqe to the next available entry on |
| 166 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 167 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 168 | * successful. If no entries are available on @q then this function will return |
| 169 | * -ENOMEM. |
| 170 | * The caller is expected to hold the hbalock when calling this routine. |
| 171 | **/ |
| 172 | static uint32_t |
| 173 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 174 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 175 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 176 | struct lpfc_register doorbell; |
| 177 | uint32_t host_index; |
| 178 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 179 | /* sanity check on queue memory */ |
| 180 | if (unlikely(!q)) |
| 181 | return -ENOMEM; |
| 182 | temp_mqe = q->qe[q->host_index].mqe; |
| 183 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 184 | /* If the host has not yet processed the next entry then we are done */ |
| 185 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 186 | return -ENOMEM; |
| 187 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 188 | /* Save off the mailbox pointer for completion */ |
| 189 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 190 | |
| 191 | /* Update the host index before invoking device */ |
| 192 | host_index = q->host_index; |
| 193 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 194 | |
| 195 | /* Ring Doorbell */ |
| 196 | doorbell.word0 = 0; |
| 197 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 198 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 199 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
| 200 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 206 | * @q: The Mailbox Queue to operate on. |
| 207 | * |
| 208 | * This routine will update the HBA index of a queue to reflect consumption of |
| 209 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 210 | * an entry the host calls this function to update the queue's internal |
| 211 | * pointers. This routine returns the number of entries that were consumed by |
| 212 | * the HBA. |
| 213 | **/ |
| 214 | static uint32_t |
| 215 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 216 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 217 | /* sanity check on queue memory */ |
| 218 | if (unlikely(!q)) |
| 219 | return 0; |
| 220 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 221 | /* Clear the mailbox pointer for completion */ |
| 222 | q->phba->mbox = NULL; |
| 223 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 224 | return 1; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 229 | * @q: The Event Queue to get the first valid EQE from |
| 230 | * |
| 231 | * This routine will get the first valid Event Queue Entry from @q, update |
| 232 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 233 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 234 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 235 | **/ |
| 236 | static struct lpfc_eqe * |
| 237 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 238 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 239 | struct lpfc_eqe *eqe; |
| 240 | |
| 241 | /* sanity check on queue memory */ |
| 242 | if (unlikely(!q)) |
| 243 | return NULL; |
| 244 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 245 | |
| 246 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 247 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 248 | return NULL; |
| 249 | /* If the host has not yet processed the next entry then we are done */ |
| 250 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 251 | return NULL; |
| 252 | |
| 253 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 254 | return eqe; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 259 | * @q: The Event Queue that the host has completed processing for. |
| 260 | * @arm: Indicates whether the host wants to arms this CQ. |
| 261 | * |
| 262 | * This routine will mark all Event Queue Entries on @q, from the last |
| 263 | * known completed entry to the last entry that was processed, as completed |
| 264 | * by clearing the valid bit for each completion queue entry. Then it will |
| 265 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 266 | * The internal host index in the @q will be updated by this routine to indicate |
| 267 | * that the host has finished processing the entries. The @arm parameter |
| 268 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 269 | * |
| 270 | * This function will return the number of EQEs that were popped. |
| 271 | **/ |
| 272 | uint32_t |
| 273 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 274 | { |
| 275 | uint32_t released = 0; |
| 276 | struct lpfc_eqe *temp_eqe; |
| 277 | struct lpfc_register doorbell; |
| 278 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 279 | /* sanity check on queue memory */ |
| 280 | if (unlikely(!q)) |
| 281 | return 0; |
| 282 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 283 | /* while there are valid entries */ |
| 284 | while (q->hba_index != q->host_index) { |
| 285 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 286 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 287 | released++; |
| 288 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 289 | } |
| 290 | if (unlikely(released == 0 && !arm)) |
| 291 | return 0; |
| 292 | |
| 293 | /* ring doorbell for number popped */ |
| 294 | doorbell.word0 = 0; |
| 295 | if (arm) { |
| 296 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 297 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 298 | } |
| 299 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 300 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 301 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 302 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 303 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 304 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 305 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 306 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 307 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 308 | return released; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 313 | * @q: The Completion Queue to get the first valid CQE from |
| 314 | * |
| 315 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 316 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 317 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 318 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 319 | **/ |
| 320 | static struct lpfc_cqe * |
| 321 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 322 | { |
| 323 | struct lpfc_cqe *cqe; |
| 324 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 325 | /* sanity check on queue memory */ |
| 326 | if (unlikely(!q)) |
| 327 | return NULL; |
| 328 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 329 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 330 | 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] | 331 | return NULL; |
| 332 | /* If the host has not yet processed the next entry then we are done */ |
| 333 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 334 | return NULL; |
| 335 | |
| 336 | cqe = q->qe[q->hba_index].cqe; |
| 337 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 338 | return cqe; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 343 | * @q: The Completion Queue that the host has completed processing for. |
| 344 | * @arm: Indicates whether the host wants to arms this CQ. |
| 345 | * |
| 346 | * This routine will mark all Completion queue entries on @q, from the last |
| 347 | * known completed entry to the last entry that was processed, as completed |
| 348 | * by clearing the valid bit for each completion queue entry. Then it will |
| 349 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 350 | * The internal host index in the @q will be updated by this routine to indicate |
| 351 | * that the host has finished processing the entries. The @arm parameter |
| 352 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 353 | * |
| 354 | * This function will return the number of CQEs that were released. |
| 355 | **/ |
| 356 | uint32_t |
| 357 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 358 | { |
| 359 | uint32_t released = 0; |
| 360 | struct lpfc_cqe *temp_qe; |
| 361 | struct lpfc_register doorbell; |
| 362 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 363 | /* sanity check on queue memory */ |
| 364 | if (unlikely(!q)) |
| 365 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 366 | /* while there are valid entries */ |
| 367 | while (q->hba_index != q->host_index) { |
| 368 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 369 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 370 | released++; |
| 371 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 372 | } |
| 373 | if (unlikely(released == 0 && !arm)) |
| 374 | return 0; |
| 375 | |
| 376 | /* ring doorbell for number popped */ |
| 377 | doorbell.word0 = 0; |
| 378 | if (arm) |
| 379 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 380 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 381 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 382 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 383 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 384 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 385 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 386 | return released; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 391 | * @q: The Header Receive Queue to operate on. |
| 392 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 393 | * |
| 394 | * This routine will copy the contents of @wqe to the next available entry on |
| 395 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 396 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 397 | * index that the rqe was copied to if successful. If no entries are available |
| 398 | * on @q then this function will return -ENOMEM. |
| 399 | * The caller is expected to hold the hbalock when calling this routine. |
| 400 | **/ |
| 401 | static int |
| 402 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 403 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 404 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 405 | struct lpfc_rqe *temp_hrqe; |
| 406 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 407 | struct lpfc_register doorbell; |
| 408 | int put_index = hq->host_index; |
| 409 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 410 | /* sanity check on queue memory */ |
| 411 | if (unlikely(!hq) || unlikely(!dq)) |
| 412 | return -ENOMEM; |
| 413 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 414 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 415 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 416 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 417 | return -EINVAL; |
| 418 | if (hq->host_index != dq->host_index) |
| 419 | return -EINVAL; |
| 420 | /* If the host has not yet processed the next entry then we are done */ |
| 421 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 422 | return -EBUSY; |
| 423 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 424 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 425 | |
| 426 | /* Update the host index to point to the next slot */ |
| 427 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 428 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 429 | |
| 430 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 431 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 432 | doorbell.word0 = 0; |
| 433 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 434 | hq->entry_repost); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 435 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
| 436 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); |
| 437 | } |
| 438 | return put_index; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 443 | * @q: The Header Receive Queue to operate on. |
| 444 | * |
| 445 | * This routine will update the HBA index of a queue to reflect consumption of |
| 446 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 447 | * consumed an entry the host calls this function to update the queue's |
| 448 | * internal pointers. This routine returns the number of entries that were |
| 449 | * consumed by the HBA. |
| 450 | **/ |
| 451 | static uint32_t |
| 452 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 453 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 454 | /* sanity check on queue memory */ |
| 455 | if (unlikely(!hq) || unlikely(!dq)) |
| 456 | return 0; |
| 457 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 458 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 459 | return 0; |
| 460 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 461 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 462 | return 1; |
| 463 | } |
| 464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 466 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 467 | * @phba: Pointer to HBA context object. |
| 468 | * @pring: Pointer to driver SLI ring object. |
| 469 | * |
| 470 | * This function returns pointer to next command iocb entry |
| 471 | * in the command ring. The caller must hold hbalock to prevent |
| 472 | * other threads consume the next command iocb. |
| 473 | * SLI-2/SLI-3 provide different sized iocbs. |
| 474 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 475 | static inline IOCB_t * |
| 476 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 477 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 478 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 479 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 480 | } |
| 481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 482 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 483 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 484 | * @phba: Pointer to HBA context object. |
| 485 | * @pring: Pointer to driver SLI ring object. |
| 486 | * |
| 487 | * This function returns pointer to next response iocb entry |
| 488 | * in the response ring. The caller must hold hbalock to make sure |
| 489 | * that no other thread consume the next response iocb. |
| 490 | * SLI-2/SLI-3 provide different sized iocbs. |
| 491 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 492 | static inline IOCB_t * |
| 493 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 494 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 495 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 496 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 497 | } |
| 498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 500 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 501 | * @phba: Pointer to HBA context object. |
| 502 | * |
| 503 | * This function is called with hbalock held. This function |
| 504 | * allocates a new driver iocb object from the iocb pool. If the |
| 505 | * allocation is successful, it returns pointer to the newly |
| 506 | * allocated iocb object else it returns NULL. |
| 507 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 508 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 509 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 510 | { |
| 511 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 512 | struct lpfc_iocbq * iocbq = NULL; |
| 513 | |
| 514 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 515 | if (iocbq) |
| 516 | phba->iocb_cnt++; |
| 517 | if (phba->iocb_cnt > phba->iocb_max) |
| 518 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 519 | return iocbq; |
| 520 | } |
| 521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 522 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 523 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 524 | * @phba: Pointer to HBA context object. |
| 525 | * @xritag: XRI value. |
| 526 | * |
| 527 | * This function clears the sglq pointer from the array of acive |
| 528 | * sglq's. The xritag that is passed in is used to index into the |
| 529 | * array. Before the xritag can be used it needs to be adjusted |
| 530 | * by subtracting the xribase. |
| 531 | * |
| 532 | * Returns sglq ponter = success, NULL = Failure. |
| 533 | **/ |
| 534 | static struct lpfc_sglq * |
| 535 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 536 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 537 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 538 | |
| 539 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 540 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 541 | return sglq; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 546 | * @phba: Pointer to HBA context object. |
| 547 | * @xritag: XRI value. |
| 548 | * |
| 549 | * This function returns the sglq pointer from the array of acive |
| 550 | * sglq's. The xritag that is passed in is used to index into the |
| 551 | * array. Before the xritag can be used it needs to be adjusted |
| 552 | * by subtracting the xribase. |
| 553 | * |
| 554 | * Returns sglq ponter = success, NULL = Failure. |
| 555 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 556 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 557 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 558 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 559 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 560 | |
| 561 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 562 | return sglq; |
| 563 | } |
| 564 | |
| 565 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 566 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 567 | * @phba: Pointer to HBA context object. |
| 568 | * @xritag: xri used in this exchange. |
| 569 | * @rrq: The RRQ to be cleared. |
| 570 | * |
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 | void |
| 573 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 574 | uint16_t xritag, |
| 575 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 576 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 577 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 578 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 579 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 580 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 581 | |
| 582 | /* The target DID could have been swapped (cable swap) |
| 583 | * we should use the ndlp from the findnode if it is |
| 584 | * available. |
| 585 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 586 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 587 | ndlp = rrq->ndlp; |
| 588 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 589 | if (!ndlp) |
| 590 | goto out; |
| 591 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 592 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 593 | rrq->send_rrq = 0; |
| 594 | rrq->xritag = 0; |
| 595 | rrq->rrq_stop_time = 0; |
| 596 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 597 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 598 | mempool_free(rrq, phba->rrq_pool); |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 603 | * @phba: Pointer to HBA context object. |
| 604 | * |
| 605 | * This function is called with hbalock held. This function |
| 606 | * Checks if stop_time (ratov from setting rrq active) has |
| 607 | * been reached, if it has and the send_rrq flag is set then |
| 608 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 609 | * then it will just call the routine to clear the rrq and |
| 610 | * free the rrq resource. |
| 611 | * The timer is set to the next rrq that is going to expire before |
| 612 | * leaving the routine. |
| 613 | * |
| 614 | **/ |
| 615 | void |
| 616 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 617 | { |
| 618 | struct lpfc_node_rrq *rrq; |
| 619 | struct lpfc_node_rrq *nextrrq; |
| 620 | unsigned long next_time; |
| 621 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 622 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 623 | |
| 624 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 625 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 626 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 627 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 628 | &phba->active_rrq_list, list) { |
| 629 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 630 | list_move(&rrq->list, &send_rrq); |
| 631 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 632 | next_time = rrq->rrq_stop_time; |
| 633 | } |
| 634 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 635 | if (!list_empty(&phba->active_rrq_list)) |
| 636 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 637 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 638 | list_del(&rrq->list); |
| 639 | if (!rrq->send_rrq) |
| 640 | /* this call will free the rrq */ |
| 641 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 642 | else if (lpfc_send_rrq(phba, rrq)) { |
| 643 | /* if we send the rrq then the completion handler |
| 644 | * will clear the bit in the xribitmap. |
| 645 | */ |
| 646 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 647 | rrq); |
| 648 | } |
| 649 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /** |
| 653 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 654 | * @vport: Pointer to vport context object. |
| 655 | * @xri: The xri used in the exchange. |
| 656 | * @did: The targets DID for this exchange. |
| 657 | * |
| 658 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 659 | * rrq = rrq for this xri and target. |
| 660 | **/ |
| 661 | struct lpfc_node_rrq * |
| 662 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 663 | { |
| 664 | struct lpfc_hba *phba = vport->phba; |
| 665 | struct lpfc_node_rrq *rrq; |
| 666 | struct lpfc_node_rrq *nextrrq; |
| 667 | unsigned long iflags; |
| 668 | |
| 669 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 670 | return NULL; |
| 671 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 672 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 673 | if (rrq->vport == vport && rrq->xritag == xri && |
| 674 | rrq->nlp_DID == did){ |
| 675 | list_del(&rrq->list); |
| 676 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 677 | return rrq; |
| 678 | } |
| 679 | } |
| 680 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 686 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 687 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 688 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 689 | * phba->active_rrq_list and clear the rrq. |
| 690 | * 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] | 691 | **/ |
| 692 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 693 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 694 | |
| 695 | { |
| 696 | struct lpfc_hba *phba = vport->phba; |
| 697 | struct lpfc_node_rrq *rrq; |
| 698 | struct lpfc_node_rrq *nextrrq; |
| 699 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 700 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 701 | |
| 702 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 703 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 704 | if (!ndlp) { |
| 705 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 706 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 707 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 708 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 709 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 710 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 711 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 712 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 713 | |
| 714 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 715 | list_del(&rrq->list); |
| 716 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 717 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /** |
| 721 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 722 | * @phba: Pointer to HBA context object. |
| 723 | * |
| 724 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 725 | * calling __lpfc_clr_active_rrq |
| 726 | * |
| 727 | **/ |
| 728 | void |
| 729 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 730 | { |
| 731 | struct lpfc_node_rrq *rrq; |
| 732 | struct lpfc_node_rrq *nextrrq; |
| 733 | unsigned long next_time; |
| 734 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 735 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 736 | |
| 737 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 738 | return; |
| 739 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 740 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 741 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 742 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 743 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 744 | |
| 745 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 746 | list_del(&rrq->list); |
| 747 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 748 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 749 | if (!list_empty(&phba->active_rrq_list)) |
| 750 | mod_timer(&phba->rrq_tmr, next_time); |
| 751 | } |
| 752 | |
| 753 | |
| 754 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 755 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 756 | * @phba: Pointer to HBA context object. |
| 757 | * @ndlp: Targets nodelist pointer for this exchange. |
| 758 | * @xritag the xri in the bitmap to test. |
| 759 | * |
| 760 | * This function is called with hbalock held. This function |
| 761 | * returns 0 = rrq not active for this xri |
| 762 | * 1 = rrq is valid for this xri. |
| 763 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 764 | int |
| 765 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 766 | uint16_t xritag) |
| 767 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 768 | if (!ndlp) |
| 769 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 770 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 771 | return 1; |
| 772 | else |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 778 | * @phba: Pointer to HBA context object. |
| 779 | * @ndlp: nodelist pointer for this target. |
| 780 | * @xritag: xri used in this exchange. |
| 781 | * @rxid: Remote Exchange ID. |
| 782 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 783 | * |
| 784 | * This function takes the hbalock. |
| 785 | * The active bit is always set in the active rrq xri_bitmap even |
| 786 | * if there is no slot avaiable for the other rrq information. |
| 787 | * |
| 788 | * returns 0 rrq actived for this xri |
| 789 | * < 0 No memory or invalid ndlp. |
| 790 | **/ |
| 791 | int |
| 792 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 793 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 794 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 795 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 796 | struct lpfc_node_rrq *rrq; |
| 797 | int empty; |
| 798 | |
| 799 | if (!ndlp) |
| 800 | return -EINVAL; |
| 801 | |
| 802 | if (!phba->cfg_enable_rrq) |
| 803 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 804 | |
| 805 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 806 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 807 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 808 | goto out; |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * set the active bit even if there is no mem available. |
| 813 | */ |
| 814 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 815 | goto out; |
| 816 | |
| 817 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 818 | goto out; |
| 819 | |
| 820 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 821 | goto out; |
| 822 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 823 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 824 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 825 | if (!rrq) { |
| 826 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 827 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 828 | " DID:0x%x Send:%d\n", |
| 829 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | rrq->send_rrq = send_rrq; |
| 833 | rrq->xritag = xritag; |
| 834 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 835 | rrq->ndlp = ndlp; |
| 836 | rrq->nlp_DID = ndlp->nlp_DID; |
| 837 | rrq->vport = ndlp->vport; |
| 838 | rrq->rxid = rxid; |
| 839 | rrq->send_rrq = send_rrq; |
| 840 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 841 | empty = list_empty(&phba->active_rrq_list); |
| 842 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 843 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 844 | if (empty) |
| 845 | lpfc_worker_wake_up(phba); |
| 846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 847 | return 0; |
| 848 | out: |
| 849 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 850 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 851 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 852 | " DID:0x%x Send:%d\n", |
| 853 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 854 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 858 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 859 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 860 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 861 | * |
| 862 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 863 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 864 | * list is not empty then it is successful, it returns pointer to the newly |
| 865 | * allocated sglq object else it returns NULL. |
| 866 | **/ |
| 867 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 869 | { |
| 870 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 871 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 872 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 873 | struct lpfc_scsi_buf *lpfc_cmd; |
| 874 | struct lpfc_nodelist *ndlp; |
| 875 | int found = 0; |
| 876 | |
| 877 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 878 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 879 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 880 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 881 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 882 | ndlp = piocbq->context_un.ndlp; |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 883 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
| 884 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 885 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 886 | else |
| 887 | ndlp = piocbq->context1; |
| 888 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 889 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 890 | start_sglq = sglq; |
| 891 | while (!found) { |
| 892 | if (!sglq) |
| 893 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 894 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 895 | /* This xri has an rrq outstanding for this DID. |
| 896 | * put it back in the list and get another xri. |
| 897 | */ |
| 898 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 899 | sglq = NULL; |
| 900 | list_remove_head(lpfc_sgl_list, sglq, |
| 901 | struct lpfc_sglq, list); |
| 902 | if (sglq == start_sglq) { |
| 903 | sglq = NULL; |
| 904 | break; |
| 905 | } else |
| 906 | continue; |
| 907 | } |
| 908 | sglq->ndlp = ndlp; |
| 909 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 910 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 911 | sglq->state = SGL_ALLOCATED; |
| 912 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 913 | return sglq; |
| 914 | } |
| 915 | |
| 916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 917 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 918 | * @phba: Pointer to HBA context object. |
| 919 | * |
| 920 | * This function is called with no lock held. This function |
| 921 | * allocates a new driver iocb object from the iocb pool. If the |
| 922 | * allocation is successful, it returns pointer to the newly |
| 923 | * allocated iocb object else it returns NULL. |
| 924 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 925 | struct lpfc_iocbq * |
| 926 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 927 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 928 | struct lpfc_iocbq * iocbq = NULL; |
| 929 | unsigned long iflags; |
| 930 | |
| 931 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 932 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 933 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 934 | return iocbq; |
| 935 | } |
| 936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 937 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 938 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 939 | * @phba: Pointer to HBA context object. |
| 940 | * @iocbq: Pointer to driver iocb object. |
| 941 | * |
| 942 | * This function is called with hbalock held to release driver |
| 943 | * iocb object to the iocb pool. The iotag in the iocb object |
| 944 | * does not change for each use of the iocb object. This function |
| 945 | * clears all other fields of the iocb object when it is freed. |
| 946 | * The sqlq structure that holds the xritag and phys and virtual |
| 947 | * mappings for the scatter gather list is retrieved from the |
| 948 | * active array of sglq. The get of the sglq pointer also clears |
| 949 | * the entry in the array. If the status of the IO indiactes that |
| 950 | * this IO was aborted then the sglq entry it put on the |
| 951 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 952 | * IO has good status or fails for any other reason then the sglq |
| 953 | * entry is added to the free list (lpfc_sgl_list). |
| 954 | **/ |
| 955 | static void |
| 956 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 957 | { |
| 958 | struct lpfc_sglq *sglq; |
| 959 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 960 | unsigned long iflag = 0; |
| 961 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 962 | |
| 963 | if (iocbq->sli4_xritag == NO_XRI) |
| 964 | sglq = NULL; |
| 965 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 966 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 967 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 968 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 969 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 970 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 971 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 972 | iflag); |
| 973 | list_add(&sglq->list, |
| 974 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 975 | spin_unlock_irqrestore( |
| 976 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 977 | } else { |
| 978 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 979 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 980 | list_add_tail(&sglq->list, |
| 981 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 982 | |
| 983 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 984 | if (pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 985 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 986 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
| 990 | /* |
| 991 | * Clean all volatile data fields, preserve iotag and node struct. |
| 992 | */ |
| 993 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 994 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 995 | iocbq->sli4_xritag = NO_XRI; |
| 996 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 997 | } |
| 998 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 999 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1000 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1001 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1002 | * @phba: Pointer to HBA context object. |
| 1003 | * @iocbq: Pointer to driver iocb object. |
| 1004 | * |
| 1005 | * This function is called with hbalock held to release driver |
| 1006 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1007 | * does not change for each use of the iocb object. This function |
| 1008 | * clears all other fields of the iocb object when it is freed. |
| 1009 | **/ |
| 1010 | static void |
| 1011 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1012 | { |
| 1013 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1014 | |
| 1015 | /* |
| 1016 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1017 | */ |
| 1018 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1019 | iocbq->sli4_xritag = NO_XRI; |
| 1020 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1021 | } |
| 1022 | |
| 1023 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1024 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1025 | * @phba: Pointer to HBA context object. |
| 1026 | * @iocbq: Pointer to driver iocb object. |
| 1027 | * |
| 1028 | * This function is called with hbalock held to release driver |
| 1029 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1030 | * does not change for each use of the iocb object. This function |
| 1031 | * clears all other fields of the iocb object when it is freed. |
| 1032 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1033 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1034 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1035 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1036 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1037 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1038 | } |
| 1039 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1040 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1041 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1042 | * @phba: Pointer to HBA context object. |
| 1043 | * @iocbq: Pointer to driver iocb object. |
| 1044 | * |
| 1045 | * This function is called with no lock held to release the iocb to |
| 1046 | * iocb pool. |
| 1047 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1048 | void |
| 1049 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1050 | { |
| 1051 | unsigned long iflags; |
| 1052 | |
| 1053 | /* |
| 1054 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1055 | */ |
| 1056 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1057 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1058 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1059 | } |
| 1060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1061 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1062 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1063 | * @phba: Pointer to HBA context object. |
| 1064 | * @iocblist: List of IOCBs. |
| 1065 | * @ulpstatus: ULP status in IOCB command field. |
| 1066 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1067 | * |
| 1068 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1069 | * on the list by invoking the complete callback function associated with the |
| 1070 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1071 | * fields. |
| 1072 | **/ |
| 1073 | void |
| 1074 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1075 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1076 | { |
| 1077 | struct lpfc_iocbq *piocb; |
| 1078 | |
| 1079 | while (!list_empty(iocblist)) { |
| 1080 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 1081 | |
| 1082 | if (!piocb->iocb_cmpl) |
| 1083 | lpfc_sli_release_iocbq(phba, piocb); |
| 1084 | else { |
| 1085 | piocb->iocb.ulpStatus = ulpstatus; |
| 1086 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1087 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1088 | } |
| 1089 | } |
| 1090 | return; |
| 1091 | } |
| 1092 | |
| 1093 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1094 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1095 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1096 | * |
| 1097 | * This function is called by ring event handler function to get the iocb type. |
| 1098 | * This function translates the iocb command to an iocb command type used to |
| 1099 | * decide the final disposition of each completed IOCB. |
| 1100 | * The function returns |
| 1101 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1102 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1103 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1104 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1105 | * |
| 1106 | * The caller is not required to hold any lock. |
| 1107 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1108 | static lpfc_iocb_type |
| 1109 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1110 | { |
| 1111 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1112 | |
| 1113 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1114 | return 0; |
| 1115 | |
| 1116 | switch (iocb_cmnd) { |
| 1117 | case CMD_XMIT_SEQUENCE_CR: |
| 1118 | case CMD_XMIT_SEQUENCE_CX: |
| 1119 | case CMD_XMIT_BCAST_CN: |
| 1120 | case CMD_XMIT_BCAST_CX: |
| 1121 | case CMD_ELS_REQUEST_CR: |
| 1122 | case CMD_ELS_REQUEST_CX: |
| 1123 | case CMD_CREATE_XRI_CR: |
| 1124 | case CMD_CREATE_XRI_CX: |
| 1125 | case CMD_GET_RPI_CN: |
| 1126 | case CMD_XMIT_ELS_RSP_CX: |
| 1127 | case CMD_GET_RPI_CR: |
| 1128 | case CMD_FCP_IWRITE_CR: |
| 1129 | case CMD_FCP_IWRITE_CX: |
| 1130 | case CMD_FCP_IREAD_CR: |
| 1131 | case CMD_FCP_IREAD_CX: |
| 1132 | case CMD_FCP_ICMND_CR: |
| 1133 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1134 | case CMD_FCP_TSEND_CX: |
| 1135 | case CMD_FCP_TRSP_CX: |
| 1136 | case CMD_FCP_TRECEIVE_CX: |
| 1137 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1138 | case CMD_ADAPTER_MSG: |
| 1139 | case CMD_ADAPTER_DUMP: |
| 1140 | case CMD_XMIT_SEQUENCE64_CR: |
| 1141 | case CMD_XMIT_SEQUENCE64_CX: |
| 1142 | case CMD_XMIT_BCAST64_CN: |
| 1143 | case CMD_XMIT_BCAST64_CX: |
| 1144 | case CMD_ELS_REQUEST64_CR: |
| 1145 | case CMD_ELS_REQUEST64_CX: |
| 1146 | case CMD_FCP_IWRITE64_CR: |
| 1147 | case CMD_FCP_IWRITE64_CX: |
| 1148 | case CMD_FCP_IREAD64_CR: |
| 1149 | case CMD_FCP_IREAD64_CX: |
| 1150 | case CMD_FCP_ICMND64_CR: |
| 1151 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1152 | case CMD_FCP_TSEND64_CX: |
| 1153 | case CMD_FCP_TRSP64_CX: |
| 1154 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1155 | case CMD_GEN_REQUEST64_CR: |
| 1156 | case CMD_GEN_REQUEST64_CX: |
| 1157 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1158 | case DSSCMD_IWRITE64_CR: |
| 1159 | case DSSCMD_IWRITE64_CX: |
| 1160 | case DSSCMD_IREAD64_CR: |
| 1161 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | type = LPFC_SOL_IOCB; |
| 1163 | break; |
| 1164 | case CMD_ABORT_XRI_CN: |
| 1165 | case CMD_ABORT_XRI_CX: |
| 1166 | case CMD_CLOSE_XRI_CN: |
| 1167 | case CMD_CLOSE_XRI_CX: |
| 1168 | case CMD_XRI_ABORTED_CX: |
| 1169 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1170 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | type = LPFC_ABORT_IOCB; |
| 1172 | break; |
| 1173 | case CMD_RCV_SEQUENCE_CX: |
| 1174 | case CMD_RCV_ELS_REQ_CX: |
| 1175 | case CMD_RCV_SEQUENCE64_CX: |
| 1176 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1177 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1178 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1179 | case CMD_IOCB_RCV_ELS64_CX: |
| 1180 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1181 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | type = LPFC_UNSOL_IOCB; |
| 1183 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1184 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1185 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1186 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1187 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1188 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1189 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1190 | case CMD_IOCB_RET_HBQE64_CN: |
| 1191 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1192 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1193 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1194 | case CMD_IOCB_LOGENTRY_CN: |
| 1195 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1196 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1197 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1198 | type = LPFC_UNKNOWN_IOCB; |
| 1199 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | default: |
| 1201 | type = LPFC_UNKNOWN_IOCB; |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | return type; |
| 1206 | } |
| 1207 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1208 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1209 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1210 | * @phba: Pointer to HBA context object. |
| 1211 | * |
| 1212 | * This function is called from SLI initialization code |
| 1213 | * to configure every ring of the HBA's SLI interface. The |
| 1214 | * caller is not required to hold any lock. This function issues |
| 1215 | * a config_ring mailbox command for each ring. |
| 1216 | * This function returns zero if successful else returns a negative |
| 1217 | * error code. |
| 1218 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1220 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | { |
| 1222 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1223 | LPFC_MBOXQ_t *pmb; |
| 1224 | MAILBOX_t *pmbox; |
| 1225 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1227 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1228 | if (!pmb) |
| 1229 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1230 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1231 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | lpfc_config_ring(phba, i, pmb); |
| 1234 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1235 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1236 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1237 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1239 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1240 | rc, pmbox->mbxCommand, |
| 1241 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1242 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1243 | ret = -ENXIO; |
| 1244 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1245 | } |
| 1246 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1247 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1248 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | } |
| 1250 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1251 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1252 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1253 | * @phba: Pointer to HBA context object. |
| 1254 | * @pring: Pointer to driver SLI ring object. |
| 1255 | * @piocb: Pointer to the driver iocb object. |
| 1256 | * |
| 1257 | * This function is called with hbalock held. The function adds the |
| 1258 | * new iocb to txcmplq of the given ring. This function always returns |
| 1259 | * 0. If this function is called for ELS ring, this function checks if |
| 1260 | * there is a vport associated with the ELS command. This function also |
| 1261 | * starts els_tmofunc timer if this is an ELS command. |
| 1262 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1264 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1265 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1268 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1270 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
| 1271 | pring->txcmplq_max = pring->txcmplq_cnt; |
| 1272 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1273 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1274 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1275 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1276 | if (!piocb->vport) |
| 1277 | BUG(); |
| 1278 | else |
| 1279 | mod_timer(&piocb->vport->els_tmofunc, |
| 1280 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1281 | } |
| 1282 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1284 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1288 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1289 | * @phba: Pointer to HBA context object. |
| 1290 | * @pring: Pointer to driver SLI ring object. |
| 1291 | * |
| 1292 | * This function is called with hbalock held to get next |
| 1293 | * iocb in txq of the given ring. If there is any iocb in |
| 1294 | * the txq, the function returns first iocb in the list after |
| 1295 | * removing the iocb from the list, else it returns NULL. |
| 1296 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1297 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1298 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | struct lpfc_iocbq *cmd_iocb; |
| 1301 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1302 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 1303 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1305 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | } |
| 1307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1309 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1310 | * @phba: Pointer to HBA context object. |
| 1311 | * @pring: Pointer to driver SLI ring object. |
| 1312 | * |
| 1313 | * This function is called with hbalock held and the caller must post the |
| 1314 | * iocb without releasing the lock. If the caller releases the lock, |
| 1315 | * iocb slot returned by the function is not guaranteed to be available. |
| 1316 | * The function returns pointer to the next available iocb slot if there |
| 1317 | * is available slot in the ring, else it returns NULL. |
| 1318 | * If the get index of the ring is ahead of the put index, the function |
| 1319 | * will post an error attention event to the worker thread to take the |
| 1320 | * HBA to offline state. |
| 1321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1322 | static IOCB_t * |
| 1323 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1324 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1325 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1326 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
| 1327 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1328 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1329 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1331 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1332 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1334 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1336 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1338 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1339 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1340 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1341 | pring->sli.sli3.local_getidx, |
| 1342 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1344 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | /* |
| 1346 | * All error attention handlers are posted to |
| 1347 | * worker thread |
| 1348 | */ |
| 1349 | phba->work_ha |= HA_ERATT; |
| 1350 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1351 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1352 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1353 | |
| 1354 | return NULL; |
| 1355 | } |
| 1356 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1357 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | return NULL; |
| 1359 | } |
| 1360 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1361 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1362 | } |
| 1363 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1364 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1365 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1366 | * @phba: Pointer to HBA context object. |
| 1367 | * @iocbq: Pointer to driver iocb object. |
| 1368 | * |
| 1369 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1370 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1371 | * array and assigns a new iotag. |
| 1372 | * The function returns the allocated iotag if successful, else returns zero. |
| 1373 | * Zero is not a valid iotag. |
| 1374 | * The caller is not required to hold any lock. |
| 1375 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1376 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1379 | struct lpfc_iocbq **new_arr; |
| 1380 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1381 | size_t new_len; |
| 1382 | struct lpfc_sli *psli = &phba->sli; |
| 1383 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1385 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1386 | iotag = psli->last_iotag; |
| 1387 | if(++iotag < psli->iocbq_lookup_len) { |
| 1388 | psli->last_iotag = iotag; |
| 1389 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1390 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1391 | iocbq->iotag = iotag; |
| 1392 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1393 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1394 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1395 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1396 | spin_unlock_irq(&phba->hbalock); |
| 1397 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1398 | GFP_KERNEL); |
| 1399 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1400 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1401 | old_arr = psli->iocbq_lookup; |
| 1402 | if (new_len <= psli->iocbq_lookup_len) { |
| 1403 | /* highly unprobable case */ |
| 1404 | kfree(new_arr); |
| 1405 | iotag = psli->last_iotag; |
| 1406 | if(++iotag < psli->iocbq_lookup_len) { |
| 1407 | psli->last_iotag = iotag; |
| 1408 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1409 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1410 | iocbq->iotag = iotag; |
| 1411 | return iotag; |
| 1412 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1413 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1414 | return 0; |
| 1415 | } |
| 1416 | if (psli->iocbq_lookup) |
| 1417 | memcpy(new_arr, old_arr, |
| 1418 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1419 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1420 | psli->iocbq_lookup = new_arr; |
| 1421 | psli->iocbq_lookup_len = new_len; |
| 1422 | psli->last_iotag = iotag; |
| 1423 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1424 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1425 | iocbq->iotag = iotag; |
| 1426 | kfree(old_arr); |
| 1427 | return iotag; |
| 1428 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1429 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1432 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1433 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1434 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1436 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | } |
| 1438 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1439 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1440 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1441 | * @phba: Pointer to HBA context object. |
| 1442 | * @pring: Pointer to driver SLI ring object. |
| 1443 | * @iocb: Pointer to iocb slot in the ring. |
| 1444 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1445 | * posted to firmware. |
| 1446 | * |
| 1447 | * This function is called with hbalock held to post a new iocb to |
| 1448 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1449 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1450 | * a completion call back for this iocb else the function will free the |
| 1451 | * iocb object. |
| 1452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | static void |
| 1454 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1455 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1456 | { |
| 1457 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1458 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1460 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1462 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1463 | if (pring->ringno == LPFC_ELS_RING) { |
| 1464 | lpfc_debugfs_slow_ring_trc(phba, |
| 1465 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1466 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1467 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1468 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1469 | } |
| 1470 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | /* |
| 1472 | * Issue iocb command to adapter |
| 1473 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1474 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | wmb(); |
| 1476 | pring->stats.iocb_cmd++; |
| 1477 | |
| 1478 | /* |
| 1479 | * If there is no completion routine to call, we can release the |
| 1480 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1481 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1482 | */ |
| 1483 | if (nextiocb->iocb_cmpl) |
| 1484 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1485 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1486 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | |
| 1488 | /* |
| 1489 | * Let the HBA know what IOCB slot will be the next one the |
| 1490 | * driver will put a command into. |
| 1491 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 1492 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1493 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1497 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1498 | * @phba: Pointer to HBA context object. |
| 1499 | * @pring: Pointer to driver SLI ring object. |
| 1500 | * |
| 1501 | * The caller is not required to hold any lock for calling this function. |
| 1502 | * This function updates the chip attention bits for the ring to inform firmware |
| 1503 | * that there are pending work to be done for this ring and requests an |
| 1504 | * interrupt when there is space available in the ring. This function is |
| 1505 | * called when the driver is unable to post more iocbs to the ring due |
| 1506 | * to unavailability of space in the ring. |
| 1507 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1509 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | { |
| 1511 | int ringno = pring->ringno; |
| 1512 | |
| 1513 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1514 | |
| 1515 | wmb(); |
| 1516 | |
| 1517 | /* |
| 1518 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1519 | * The HBA will tell us when an IOCB entry is available. |
| 1520 | */ |
| 1521 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1522 | readl(phba->CAregaddr); /* flush */ |
| 1523 | |
| 1524 | pring->stats.iocb_cmd_full++; |
| 1525 | } |
| 1526 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1527 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1528 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1529 | * @phba: Pointer to HBA context object. |
| 1530 | * @pring: Pointer to driver SLI ring object. |
| 1531 | * |
| 1532 | * This function updates the chip attention register bit for the |
| 1533 | * given ring to inform HBA that there is more work to be done |
| 1534 | * in this ring. The caller is not required to hold any lock. |
| 1535 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1537 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | { |
| 1539 | int ringno = pring->ringno; |
| 1540 | |
| 1541 | /* |
| 1542 | * Tell the HBA that there is work to do in this ring. |
| 1543 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1544 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1545 | wmb(); |
| 1546 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1547 | readl(phba->CAregaddr); /* flush */ |
| 1548 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | } |
| 1550 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1552 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1553 | * @phba: Pointer to HBA context object. |
| 1554 | * @pring: Pointer to driver SLI ring object. |
| 1555 | * |
| 1556 | * This function is called with hbalock held to post pending iocbs |
| 1557 | * in the txq to the firmware. This function is called when driver |
| 1558 | * detects space available in the ring. |
| 1559 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1561 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | { |
| 1563 | IOCB_t *iocb; |
| 1564 | struct lpfc_iocbq *nextiocb; |
| 1565 | |
| 1566 | /* |
| 1567 | * Check to see if: |
| 1568 | * (a) there is anything on the txq to send |
| 1569 | * (b) link is up |
| 1570 | * (c) link attention events can be processed (fcp ring only) |
| 1571 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1572 | */ |
| 1573 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1574 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1576 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1577 | |
| 1578 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1579 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1580 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1581 | |
| 1582 | if (iocb) |
| 1583 | lpfc_sli_update_ring(phba, pring); |
| 1584 | else |
| 1585 | lpfc_sli_update_full_ring(phba, pring); |
| 1586 | } |
| 1587 | |
| 1588 | return; |
| 1589 | } |
| 1590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1591 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1592 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1593 | * @phba: Pointer to HBA context object. |
| 1594 | * @hbqno: HBQ number. |
| 1595 | * |
| 1596 | * This function is called with hbalock held to get the next |
| 1597 | * available slot for the given HBQ. If there is free slot |
| 1598 | * available for the HBQ it will return pointer to the next available |
| 1599 | * HBQ entry else it will return NULL. |
| 1600 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1601 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1602 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1603 | { |
| 1604 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1605 | |
| 1606 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1607 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1608 | hbqp->next_hbqPutIdx = 0; |
| 1609 | |
| 1610 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1611 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1612 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1613 | |
| 1614 | hbqp->local_hbqGetIdx = getidx; |
| 1615 | |
| 1616 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1617 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1618 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1619 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1620 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1621 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1622 | hbqp->entry_count); |
| 1623 | |
| 1624 | phba->link_state = LPFC_HBA_ERROR; |
| 1625 | return NULL; |
| 1626 | } |
| 1627 | |
| 1628 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1629 | return NULL; |
| 1630 | } |
| 1631 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1632 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1633 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1637 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1638 | * @phba: Pointer to HBA context object. |
| 1639 | * |
| 1640 | * This function is called with no lock held to free all the |
| 1641 | * hbq buffers while uninitializing the SLI interface. It also |
| 1642 | * frees the HBQ buffers returned by the firmware but not yet |
| 1643 | * processed by the upper layers. |
| 1644 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1645 | void |
| 1646 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1647 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1648 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1649 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1650 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1651 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1652 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1653 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1654 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1655 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1656 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1657 | for (i = 0; i < hbq_count; ++i) { |
| 1658 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1659 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1660 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1661 | list_del(&hbq_buf->dbuf.list); |
| 1662 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1663 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1664 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1665 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1666 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1667 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1668 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1669 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1670 | list_del(&hbq_buf->dbuf.list); |
| 1671 | if (hbq_buf->tag == -1) { |
| 1672 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1673 | (phba, hbq_buf); |
| 1674 | } else { |
| 1675 | hbqno = hbq_buf->tag >> 16; |
| 1676 | if (hbqno >= LPFC_MAX_HBQS) |
| 1677 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1678 | (phba, hbq_buf); |
| 1679 | else |
| 1680 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1681 | hbq_buf); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | /* Mark the HBQs not in use */ |
| 1686 | phba->hbq_in_use = 0; |
| 1687 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1688 | } |
| 1689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1691 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1692 | * @phba: Pointer to HBA context object. |
| 1693 | * @hbqno: HBQ number. |
| 1694 | * @hbq_buf: Pointer to HBQ buffer. |
| 1695 | * |
| 1696 | * This function is called with the hbalock held to post a |
| 1697 | * hbq buffer to the firmware. If the function finds an empty |
| 1698 | * slot in the HBQ, it will post the buffer. The function will return |
| 1699 | * pointer to the hbq entry if it successfully post the buffer |
| 1700 | * else it will return NULL. |
| 1701 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1702 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1703 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1705 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1706 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1707 | } |
| 1708 | |
| 1709 | /** |
| 1710 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1711 | * @phba: Pointer to HBA context object. |
| 1712 | * @hbqno: HBQ number. |
| 1713 | * @hbq_buf: Pointer to HBQ buffer. |
| 1714 | * |
| 1715 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1716 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1717 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1718 | * it successfully post the buffer else it will return an error. |
| 1719 | **/ |
| 1720 | static int |
| 1721 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1722 | struct hbq_dmabuf *hbq_buf) |
| 1723 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1724 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1725 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1726 | |
| 1727 | /* Get next HBQ entry slot to use */ |
| 1728 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1729 | if (hbqe) { |
| 1730 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1731 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1732 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1733 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1734 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1735 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1736 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1737 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1738 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1739 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1740 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1741 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1742 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1743 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1744 | return 0; |
| 1745 | } else |
| 1746 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1747 | } |
| 1748 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1749 | /** |
| 1750 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1751 | * @phba: Pointer to HBA context object. |
| 1752 | * @hbqno: HBQ number. |
| 1753 | * @hbq_buf: Pointer to HBQ buffer. |
| 1754 | * |
| 1755 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1756 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1757 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1758 | **/ |
| 1759 | static int |
| 1760 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1761 | struct hbq_dmabuf *hbq_buf) |
| 1762 | { |
| 1763 | int rc; |
| 1764 | struct lpfc_rqe hrqe; |
| 1765 | struct lpfc_rqe drqe; |
| 1766 | |
| 1767 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1768 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1769 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1770 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1771 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1772 | &hrqe, &drqe); |
| 1773 | if (rc < 0) |
| 1774 | return rc; |
| 1775 | hbq_buf->tag = rc; |
| 1776 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1780 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1781 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1782 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1783 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1784 | .mask_count = 0, |
| 1785 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1786 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1787 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1788 | .init_count = 40, |
| 1789 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1790 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1792 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1793 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1794 | .rn = 1, |
| 1795 | .entry_count = 200, |
| 1796 | .mask_count = 0, |
| 1797 | .profile = 0, |
| 1798 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1799 | .buffer_count = 0, |
| 1800 | .init_count = 0, |
| 1801 | .add_count = 5, |
| 1802 | }; |
| 1803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1804 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1805 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1806 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1807 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1808 | }; |
| 1809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1811 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1812 | * @phba: Pointer to HBA context object. |
| 1813 | * @hbqno: HBQ number. |
| 1814 | * @count: Number of HBQ buffers to be posted. |
| 1815 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1816 | * This function is called with no lock held to post more hbq buffers to the |
| 1817 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1818 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1819 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1820 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1821 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1822 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1823 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1824 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1825 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1826 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1827 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1828 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1829 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1830 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1831 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1832 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1833 | phba->hbqs[hbqno].buffer_count; |
| 1834 | if (!count) |
| 1835 | return 0; |
| 1836 | /* Allocate HBQ entries */ |
| 1837 | for (i = 0; i < count; i++) { |
| 1838 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1839 | if (!hbq_buffer) |
| 1840 | break; |
| 1841 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1842 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1843 | /* Check whether HBQ is still in use */ |
| 1844 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1845 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1846 | goto err; |
| 1847 | while (!list_empty(&hbq_buf_list)) { |
| 1848 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1849 | dbuf.list); |
| 1850 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1851 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1852 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1853 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1854 | posted++; |
| 1855 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1856 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1858 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1859 | return posted; |
| 1860 | err: |
| 1861 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1862 | while (!list_empty(&hbq_buf_list)) { |
| 1863 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1864 | dbuf.list); |
| 1865 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1866 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1867 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1868 | } |
| 1869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1871 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1872 | * @phba: Pointer to HBA context object. |
| 1873 | * @qno: HBQ number. |
| 1874 | * |
| 1875 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1876 | * is called with no lock held. The function returns the number of HBQ entries |
| 1877 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1878 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1879 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1880 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1881 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1882 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1883 | return 0; |
| 1884 | else |
| 1885 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1886 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1889 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1890 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1891 | * @phba: Pointer to HBA context object. |
| 1892 | * @qno: HBQ queue number. |
| 1893 | * |
| 1894 | * This function is called from SLI initialization code path with |
| 1895 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1896 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1897 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1898 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1899 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1900 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1901 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1902 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1903 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1904 | else |
| 1905 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1906 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1907 | } |
| 1908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1909 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1910 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1911 | * @phba: Pointer to HBA context object. |
| 1912 | * @hbqno: HBQ number. |
| 1913 | * |
| 1914 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1915 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1916 | **/ |
| 1917 | static struct hbq_dmabuf * |
| 1918 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1919 | { |
| 1920 | struct lpfc_dmabuf *d_buf; |
| 1921 | |
| 1922 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1923 | if (!d_buf) |
| 1924 | return NULL; |
| 1925 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1926 | } |
| 1927 | |
| 1928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1929 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1930 | * @phba: Pointer to HBA context object. |
| 1931 | * @tag: Tag of the hbq buffer. |
| 1932 | * |
| 1933 | * This function is called with hbalock held. This function searches |
| 1934 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1935 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1936 | * it returns NULL. |
| 1937 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1938 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1939 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1940 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1941 | struct lpfc_dmabuf *d_buf; |
| 1942 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1943 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1944 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1945 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1946 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1947 | return NULL; |
| 1948 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1949 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1950 | 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] | 1951 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1952 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1953 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1954 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1955 | } |
| 1956 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1957 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1959 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1960 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1961 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1962 | } |
| 1963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1965 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1966 | * @phba: Pointer to HBA context object. |
| 1967 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1968 | * |
| 1969 | * This function is called with hbalock. This function gives back |
| 1970 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1971 | * post the buffer, it will free the buffer. |
| 1972 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1973 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1974 | 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] | 1975 | { |
| 1976 | uint32_t hbqno; |
| 1977 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1978 | if (hbq_buffer) { |
| 1979 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1980 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1981 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1985 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1986 | * 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] | 1987 | * @mbxCommand: mailbox command code. |
| 1988 | * |
| 1989 | * This function is called by the mailbox event handler function to verify |
| 1990 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1991 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1992 | * and the mailbox event handler will take the HBA offline. |
| 1993 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | static int |
| 1995 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1996 | { |
| 1997 | uint8_t ret; |
| 1998 | |
| 1999 | switch (mbxCommand) { |
| 2000 | case MBX_LOAD_SM: |
| 2001 | case MBX_READ_NV: |
| 2002 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2003 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | case MBX_RUN_BIU_DIAG: |
| 2005 | case MBX_INIT_LINK: |
| 2006 | case MBX_DOWN_LINK: |
| 2007 | case MBX_CONFIG_LINK: |
| 2008 | case MBX_CONFIG_RING: |
| 2009 | case MBX_RESET_RING: |
| 2010 | case MBX_READ_CONFIG: |
| 2011 | case MBX_READ_RCONFIG: |
| 2012 | case MBX_READ_SPARM: |
| 2013 | case MBX_READ_STATUS: |
| 2014 | case MBX_READ_RPI: |
| 2015 | case MBX_READ_XRI: |
| 2016 | case MBX_READ_REV: |
| 2017 | case MBX_READ_LNK_STAT: |
| 2018 | case MBX_REG_LOGIN: |
| 2019 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | case MBX_CLEAR_LA: |
| 2021 | case MBX_DUMP_MEMORY: |
| 2022 | case MBX_DUMP_CONTEXT: |
| 2023 | case MBX_RUN_DIAGS: |
| 2024 | case MBX_RESTART: |
| 2025 | case MBX_UPDATE_CFG: |
| 2026 | case MBX_DOWN_LOAD: |
| 2027 | case MBX_DEL_LD_ENTRY: |
| 2028 | case MBX_RUN_PROGRAM: |
| 2029 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2030 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2031 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2032 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2034 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | case MBX_LOAD_AREA: |
| 2036 | case MBX_RUN_BIU_DIAG64: |
| 2037 | case MBX_CONFIG_PORT: |
| 2038 | case MBX_READ_SPARM64: |
| 2039 | case MBX_READ_RPI64: |
| 2040 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2041 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2042 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | case MBX_SET_DEBUG: |
| 2044 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2045 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2046 | case MBX_REG_VPI: |
| 2047 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2048 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2049 | case MBX_PORT_CAPABILITIES: |
| 2050 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2051 | case MBX_SLI4_CONFIG: |
| 2052 | case MBX_SLI4_REQ_FTRS: |
| 2053 | case MBX_REG_FCFI: |
| 2054 | case MBX_UNREG_FCFI: |
| 2055 | case MBX_REG_VFI: |
| 2056 | case MBX_UNREG_VFI: |
| 2057 | case MBX_INIT_VPI: |
| 2058 | case MBX_INIT_VFI: |
| 2059 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2060 | case MBX_READ_EVENT_LOG_STATUS: |
| 2061 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2062 | case MBX_SECURITY_MGMT: |
| 2063 | case MBX_AUTH_PORT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | ret = mbxCommand; |
| 2065 | break; |
| 2066 | default: |
| 2067 | ret = MBX_SHUTDOWN; |
| 2068 | break; |
| 2069 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2070 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2072 | |
| 2073 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2074 | * 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] | 2075 | * @phba: Pointer to HBA context object. |
| 2076 | * @pmboxq: Pointer to mailbox command. |
| 2077 | * |
| 2078 | * This is completion handler function for mailbox commands issued from |
| 2079 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2080 | * mailbox event handler function with no lock held. This function |
| 2081 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2082 | * of the mailbox. |
| 2083 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2084 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2085 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | { |
| 2087 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2088 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | |
| 2090 | /* |
| 2091 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2092 | * continued running. |
| 2093 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2094 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2095 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2097 | if (pdone_q) |
| 2098 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2099 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2100 | return; |
| 2101 | } |
| 2102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2103 | |
| 2104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2105 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2106 | * @phba: Pointer to HBA context object. |
| 2107 | * @pmb: Pointer to mailbox object. |
| 2108 | * |
| 2109 | * This function is the default mailbox completion handler. It |
| 2110 | * frees the memory resources associated with the completed mailbox |
| 2111 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2112 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2113 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2114 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2115 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2117 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2119 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2120 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2121 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2122 | int rc; |
| 2123 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | if (mp) { |
| 2127 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2128 | kfree(mp); |
| 2129 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2130 | |
| 2131 | /* |
| 2132 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2133 | * is in re-discovery driver need to cleanup the RPI. |
| 2134 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2135 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2136 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2137 | !pmb->u.mb.mbxStatus) { |
| 2138 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2139 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2140 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2141 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2142 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2143 | if (rc != MBX_NOT_FINISHED) |
| 2144 | return; |
| 2145 | } |
| 2146 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2147 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2148 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2149 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2150 | shost = lpfc_shost_from_vport(vport); |
| 2151 | spin_lock_irq(shost->host_lock); |
| 2152 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2153 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2154 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2155 | } |
| 2156 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2157 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2158 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2159 | lpfc_nlp_put(ndlp); |
| 2160 | pmb->context2 = NULL; |
| 2161 | } |
| 2162 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2163 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2164 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2165 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2166 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2167 | "2860 SLI authentication is required " |
| 2168 | "for INIT_LINK but has not done yet\n"); |
| 2169 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2170 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2171 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2172 | else |
| 2173 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2177 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2178 | * @phba: Pointer to HBA context object. |
| 2179 | * |
| 2180 | * This function is called with no lock held. This function processes all |
| 2181 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2182 | * service routine processes mailbox completion interrupt and adds completed |
| 2183 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2184 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2185 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2186 | * function returns the mailbox commands to the upper layer by calling the |
| 2187 | * completion handler function of each mailbox. |
| 2188 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2190 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2192 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2194 | int rc; |
| 2195 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | |
| 2197 | phba->sli.slistat.mbox_event++; |
| 2198 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2199 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2200 | spin_lock_irq(&phba->hbalock); |
| 2201 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2202 | spin_unlock_irq(&phba->hbalock); |
| 2203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | do { |
| 2206 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2207 | if (pmb == NULL) |
| 2208 | break; |
| 2209 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2210 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2212 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2213 | if (pmb->vport) { |
| 2214 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2215 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2216 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2217 | (uint32_t)pmbox->mbxCommand, |
| 2218 | pmbox->un.varWords[0], |
| 2219 | pmbox->un.varWords[1]); |
| 2220 | } |
| 2221 | else { |
| 2222 | lpfc_debugfs_disc_trc(phba->pport, |
| 2223 | LPFC_DISC_TRC_MBOX, |
| 2224 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2225 | (uint32_t)pmbox->mbxCommand, |
| 2226 | pmbox->un.varWords[0], |
| 2227 | pmbox->un.varWords[1]); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | /* |
| 2232 | * It is a fatal error if unknown mbox command completion. |
| 2233 | */ |
| 2234 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2235 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2236 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2237 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2238 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2239 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2240 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2241 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2242 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2243 | pmb), |
| 2244 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2245 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | phba->work_hs = HS_FFER3; |
| 2248 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2249 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | } |
| 2251 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | if (pmbox->mbxStatus) { |
| 2253 | phba->sli.slistat.mbox_stat_err++; |
| 2254 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2255 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2256 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2257 | LOG_MBOX | LOG_SLI, |
| 2258 | "(%d):0305 Mbox cmd cmpl " |
| 2259 | "error - RETRYing Data: x%x " |
| 2260 | "(x%x/x%x) x%x x%x x%x\n", |
| 2261 | pmb->vport ? pmb->vport->vpi : 0, |
| 2262 | pmbox->mbxCommand, |
| 2263 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2264 | pmb), |
| 2265 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2266 | pmb), |
| 2267 | pmbox->mbxStatus, |
| 2268 | pmbox->un.varWords[0], |
| 2269 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 | pmbox->mbxStatus = 0; |
| 2271 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2273 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2274 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2279 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2280 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | "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] | 2282 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2284 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2285 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | pmb->mbox_cmpl, |
| 2287 | *((uint32_t *) pmbox), |
| 2288 | pmbox->un.varWords[0], |
| 2289 | pmbox->un.varWords[1], |
| 2290 | pmbox->un.varWords[2], |
| 2291 | pmbox->un.varWords[3], |
| 2292 | pmbox->un.varWords[4], |
| 2293 | pmbox->un.varWords[5], |
| 2294 | pmbox->un.varWords[6], |
| 2295 | pmbox->un.varWords[7]); |
| 2296 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2297 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2299 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2300 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2301 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2302 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2303 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2304 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2305 | * @phba: Pointer to HBA context object. |
| 2306 | * @pring: Pointer to driver SLI ring object. |
| 2307 | * @tag: buffer tag. |
| 2308 | * |
| 2309 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2310 | * is set in the tag the buffer is posted for a particular exchange, |
| 2311 | * the function will return the buffer without replacing the buffer. |
| 2312 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2313 | * returns the buffer and also posts another buffer to the firmware. |
| 2314 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2315 | static struct lpfc_dmabuf * |
| 2316 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2317 | struct lpfc_sli_ring *pring, |
| 2318 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2319 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2320 | struct hbq_dmabuf *hbq_entry; |
| 2321 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2322 | if (tag & QUE_BUFTAG_BIT) |
| 2323 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2324 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2325 | if (!hbq_entry) |
| 2326 | return NULL; |
| 2327 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2328 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2329 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2330 | /** |
| 2331 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2332 | * @phba: Pointer to HBA context object. |
| 2333 | * @pring: Pointer to driver SLI ring object. |
| 2334 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2335 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2336 | * @fch_type: the type for the first frame of the sequence. |
| 2337 | * |
| 2338 | * This function is called with no lock held. This function uses the r_ctl and |
| 2339 | * type of the received sequence to find the correct callback function to call |
| 2340 | * to process the sequence. |
| 2341 | **/ |
| 2342 | static int |
| 2343 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2344 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2345 | uint32_t fch_type) |
| 2346 | { |
| 2347 | int i; |
| 2348 | |
| 2349 | /* unSolicited Responses */ |
| 2350 | if (pring->prt[0].profile) { |
| 2351 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2352 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2353 | saveq); |
| 2354 | return 1; |
| 2355 | } |
| 2356 | /* We must search, based on rctl / type |
| 2357 | for the right routine */ |
| 2358 | for (i = 0; i < pring->num_mask; i++) { |
| 2359 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2360 | (pring->prt[i].type == fch_type)) { |
| 2361 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2362 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2363 | (phba, pring, saveq); |
| 2364 | return 1; |
| 2365 | } |
| 2366 | } |
| 2367 | return 0; |
| 2368 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2369 | |
| 2370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2371 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2372 | * @phba: Pointer to HBA context object. |
| 2373 | * @pring: Pointer to driver SLI ring object. |
| 2374 | * @saveq: Pointer to the unsolicited iocb. |
| 2375 | * |
| 2376 | * This function is called with no lock held by the ring event handler |
| 2377 | * when there is an unsolicited iocb posted to the response ring by the |
| 2378 | * firmware. This function gets the buffer associated with the iocbs |
| 2379 | * and calls the event handler for the ring. This function handles both |
| 2380 | * qring buffers and hbq buffers. |
| 2381 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2382 | * upper layer functions will free the iocb objects. |
| 2383 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | static int |
| 2385 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2386 | struct lpfc_iocbq *saveq) |
| 2387 | { |
| 2388 | IOCB_t * irsp; |
| 2389 | WORD5 * w5p; |
| 2390 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2391 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2392 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2393 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | |
| 2395 | match = 0; |
| 2396 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2397 | |
| 2398 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2399 | if (pring->lpfc_sli_rcv_async_status) |
| 2400 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2401 | else |
| 2402 | lpfc_printf_log(phba, |
| 2403 | KERN_WARNING, |
| 2404 | LOG_SLI, |
| 2405 | "0316 Ring %d handler: unexpected " |
| 2406 | "ASYNC_STATUS iocb received evt_code " |
| 2407 | "0x%x\n", |
| 2408 | pring->ringno, |
| 2409 | irsp->un.asyncstat.evt_code); |
| 2410 | return 1; |
| 2411 | } |
| 2412 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2413 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2414 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2415 | if (irsp->ulpBdeCount > 0) { |
| 2416 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2417 | irsp->un.ulpWord[3]); |
| 2418 | lpfc_in_buf_free(phba, dmzbuf); |
| 2419 | } |
| 2420 | |
| 2421 | if (irsp->ulpBdeCount > 1) { |
| 2422 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2423 | irsp->unsli3.sli3Words[3]); |
| 2424 | lpfc_in_buf_free(phba, dmzbuf); |
| 2425 | } |
| 2426 | |
| 2427 | if (irsp->ulpBdeCount > 2) { |
| 2428 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2429 | irsp->unsli3.sli3Words[7]); |
| 2430 | lpfc_in_buf_free(phba, dmzbuf); |
| 2431 | } |
| 2432 | |
| 2433 | return 1; |
| 2434 | } |
| 2435 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2436 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2437 | if (irsp->ulpBdeCount != 0) { |
| 2438 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2439 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2440 | if (!saveq->context2) |
| 2441 | lpfc_printf_log(phba, |
| 2442 | KERN_ERR, |
| 2443 | LOG_SLI, |
| 2444 | "0341 Ring %d Cannot find buffer for " |
| 2445 | "an unsolicited iocb. tag 0x%x\n", |
| 2446 | pring->ringno, |
| 2447 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2448 | } |
| 2449 | if (irsp->ulpBdeCount == 2) { |
| 2450 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2451 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2452 | if (!saveq->context3) |
| 2453 | lpfc_printf_log(phba, |
| 2454 | KERN_ERR, |
| 2455 | LOG_SLI, |
| 2456 | "0342 Ring %d Cannot find buffer for an" |
| 2457 | " unsolicited iocb. tag 0x%x\n", |
| 2458 | pring->ringno, |
| 2459 | irsp->unsli3.sli3Words[7]); |
| 2460 | } |
| 2461 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2462 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2463 | if (irsp->ulpBdeCount != 0) { |
| 2464 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2465 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2466 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2467 | lpfc_printf_log(phba, |
| 2468 | KERN_ERR, |
| 2469 | LOG_SLI, |
| 2470 | "0343 Ring %d Cannot find " |
| 2471 | "buffer for an unsolicited iocb" |
| 2472 | ". tag 0x%x\n", pring->ringno, |
| 2473 | irsp->un.ulpWord[3]); |
| 2474 | } |
| 2475 | if (irsp->ulpBdeCount == 2) { |
| 2476 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2477 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2478 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2479 | lpfc_printf_log(phba, |
| 2480 | KERN_ERR, |
| 2481 | LOG_SLI, |
| 2482 | "0344 Ring %d Cannot find " |
| 2483 | "buffer for an unsolicited " |
| 2484 | "iocb. tag 0x%x\n", |
| 2485 | pring->ringno, |
| 2486 | irsp->unsli3.sli3Words[7]); |
| 2487 | } |
| 2488 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2489 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2490 | if (irsp->ulpBdeCount != 0 && |
| 2491 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2492 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2493 | int found = 0; |
| 2494 | |
| 2495 | /* search continue save q for same XRI */ |
| 2496 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2497 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2498 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2499 | list_add_tail(&saveq->list, &iocbq->list); |
| 2500 | found = 1; |
| 2501 | break; |
| 2502 | } |
| 2503 | } |
| 2504 | if (!found) |
| 2505 | list_add_tail(&saveq->clist, |
| 2506 | &pring->iocb_continue_saveq); |
| 2507 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2508 | list_del_init(&iocbq->clist); |
| 2509 | saveq = iocbq; |
| 2510 | irsp = &(saveq->iocb); |
| 2511 | } else |
| 2512 | return 0; |
| 2513 | } |
| 2514 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2515 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2516 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2517 | Rctl = FC_RCTL_ELS_REQ; |
| 2518 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2519 | } else { |
| 2520 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2521 | Rctl = w5p->hcsw.Rctl; |
| 2522 | Type = w5p->hcsw.Type; |
| 2523 | |
| 2524 | /* Firmware Workaround */ |
| 2525 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2526 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2527 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2528 | Rctl = FC_RCTL_ELS_REQ; |
| 2529 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2530 | w5p->hcsw.Rctl = Rctl; |
| 2531 | w5p->hcsw.Type = Type; |
| 2532 | } |
| 2533 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2534 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2535 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2536 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2537 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2538 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2539 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2540 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2541 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | } |
| 2543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2544 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2545 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2546 | * @phba: Pointer to HBA context object. |
| 2547 | * @pring: Pointer to driver SLI ring object. |
| 2548 | * @prspiocb: Pointer to response iocb object. |
| 2549 | * |
| 2550 | * This function looks up the iocb_lookup table to get the command iocb |
| 2551 | * corresponding to the given response iocb using the iotag of the |
| 2552 | * response iocb. This function is called with the hbalock held. |
| 2553 | * This function returns the command iocb object if it finds the command |
| 2554 | * iocb else returns NULL. |
| 2555 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2557 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2558 | struct lpfc_sli_ring *pring, |
| 2559 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2562 | uint16_t iotag; |
| 2563 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2564 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2566 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2567 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2568 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2569 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2570 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2571 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2572 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2573 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | } |
| 2575 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2577 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2578 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2579 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2580 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | return NULL; |
| 2582 | } |
| 2583 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2584 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2585 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2586 | * @phba: Pointer to HBA context object. |
| 2587 | * @pring: Pointer to driver SLI ring object. |
| 2588 | * @iotag: IOCB tag. |
| 2589 | * |
| 2590 | * This function looks up the iocb_lookup table to get the command iocb |
| 2591 | * corresponding to the given iotag. This function is called with the |
| 2592 | * hbalock held. |
| 2593 | * This function returns the command iocb object if it finds the command |
| 2594 | * iocb else returns NULL. |
| 2595 | **/ |
| 2596 | static struct lpfc_iocbq * |
| 2597 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2598 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2599 | { |
| 2600 | struct lpfc_iocbq *cmd_iocb; |
| 2601 | |
| 2602 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2603 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2604 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2605 | /* remove from txcmpl queue list */ |
| 2606 | list_del_init(&cmd_iocb->list); |
| 2607 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2608 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2609 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2610 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2611 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2612 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2613 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2614 | iotag, phba->sli.last_iotag); |
| 2615 | return NULL; |
| 2616 | } |
| 2617 | |
| 2618 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2619 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2620 | * @phba: Pointer to HBA context object. |
| 2621 | * @pring: Pointer to driver SLI ring object. |
| 2622 | * @saveq: Pointer to the response iocb to be processed. |
| 2623 | * |
| 2624 | * This function is called by the ring event handler for non-fcp |
| 2625 | * rings when there is a new response iocb in the response ring. |
| 2626 | * The caller is not required to hold any locks. This function |
| 2627 | * gets the command iocb associated with the response iocb and |
| 2628 | * calls the completion handler for the command iocb. If there |
| 2629 | * is no completion handler, the function will free the resources |
| 2630 | * associated with command iocb. If the response iocb is for |
| 2631 | * an already aborted command iocb, the status of the completion |
| 2632 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2633 | * This function always returns 1. |
| 2634 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | struct lpfc_iocbq *saveq) |
| 2638 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2639 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | int rc = 1; |
| 2641 | unsigned long iflag; |
| 2642 | |
| 2643 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2645 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2646 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2647 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | if (cmdiocbp) { |
| 2649 | if (cmdiocbp->iocb_cmpl) { |
| 2650 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2651 | * If an ELS command failed send an event to mgmt |
| 2652 | * application. |
| 2653 | */ |
| 2654 | if (saveq->iocb.ulpStatus && |
| 2655 | (pring->ringno == LPFC_ELS_RING) && |
| 2656 | (cmdiocbp->iocb.ulpCommand == |
| 2657 | CMD_ELS_REQUEST64_CR)) |
| 2658 | lpfc_send_els_failure_event(phba, |
| 2659 | cmdiocbp, saveq); |
| 2660 | |
| 2661 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | * Post all ELS completions to the worker thread. |
| 2663 | * All other are passed to the completion callback. |
| 2664 | */ |
| 2665 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2666 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2667 | (cmdiocbp->iocb_flag & |
| 2668 | LPFC_DRIVER_ABORTED)) { |
| 2669 | spin_lock_irqsave(&phba->hbalock, |
| 2670 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2671 | cmdiocbp->iocb_flag &= |
| 2672 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2673 | spin_unlock_irqrestore(&phba->hbalock, |
| 2674 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2675 | saveq->iocb.ulpStatus = |
| 2676 | IOSTAT_LOCAL_REJECT; |
| 2677 | saveq->iocb.un.ulpWord[4] = |
| 2678 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2679 | |
| 2680 | /* Firmware could still be in progress |
| 2681 | * of DMAing payload, so don't free data |
| 2682 | * buffer till after a hbeat. |
| 2683 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2684 | spin_lock_irqsave(&phba->hbalock, |
| 2685 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2686 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2687 | spin_unlock_irqrestore(&phba->hbalock, |
| 2688 | iflag); |
| 2689 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2690 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2691 | if (saveq->iocb_flag & |
| 2692 | LPFC_EXCHANGE_BUSY) { |
| 2693 | /* Set cmdiocb flag for the |
| 2694 | * exchange busy so sgl (xri) |
| 2695 | * will not be released until |
| 2696 | * the abort xri is received |
| 2697 | * from hba. |
| 2698 | */ |
| 2699 | spin_lock_irqsave( |
| 2700 | &phba->hbalock, iflag); |
| 2701 | cmdiocbp->iocb_flag |= |
| 2702 | LPFC_EXCHANGE_BUSY; |
| 2703 | spin_unlock_irqrestore( |
| 2704 | &phba->hbalock, iflag); |
| 2705 | } |
| 2706 | if (cmdiocbp->iocb_flag & |
| 2707 | LPFC_DRIVER_ABORTED) { |
| 2708 | /* |
| 2709 | * Clear LPFC_DRIVER_ABORTED |
| 2710 | * bit in case it was driver |
| 2711 | * initiated abort. |
| 2712 | */ |
| 2713 | spin_lock_irqsave( |
| 2714 | &phba->hbalock, iflag); |
| 2715 | cmdiocbp->iocb_flag &= |
| 2716 | ~LPFC_DRIVER_ABORTED; |
| 2717 | spin_unlock_irqrestore( |
| 2718 | &phba->hbalock, iflag); |
| 2719 | cmdiocbp->iocb.ulpStatus = |
| 2720 | IOSTAT_LOCAL_REJECT; |
| 2721 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2722 | IOERR_ABORT_REQUESTED; |
| 2723 | /* |
| 2724 | * For SLI4, irsiocb contains |
| 2725 | * NO_XRI in sli_xritag, it |
| 2726 | * shall not affect releasing |
| 2727 | * sgl (xri) process. |
| 2728 | */ |
| 2729 | saveq->iocb.ulpStatus = |
| 2730 | IOSTAT_LOCAL_REJECT; |
| 2731 | saveq->iocb.un.ulpWord[4] = |
| 2732 | IOERR_SLI_ABORTED; |
| 2733 | spin_lock_irqsave( |
| 2734 | &phba->hbalock, iflag); |
| 2735 | saveq->iocb_flag |= |
| 2736 | LPFC_DELAY_MEM_FREE; |
| 2737 | spin_unlock_irqrestore( |
| 2738 | &phba->hbalock, iflag); |
| 2739 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2740 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2743 | } else |
| 2744 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | } else { |
| 2746 | /* |
| 2747 | * Unknown initiating command based on the response iotag. |
| 2748 | * This could be the case on the ELS ring because of |
| 2749 | * lpfc_els_abort(). |
| 2750 | */ |
| 2751 | if (pring->ringno != LPFC_ELS_RING) { |
| 2752 | /* |
| 2753 | * Ring <ringno> handler: unexpected completion IoTag |
| 2754 | * <IoTag> |
| 2755 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2756 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2757 | "0322 Ring %d handler: " |
| 2758 | "unexpected completion IoTag x%x " |
| 2759 | "Data: x%x x%x x%x x%x\n", |
| 2760 | pring->ringno, |
| 2761 | saveq->iocb.ulpIoTag, |
| 2762 | saveq->iocb.ulpStatus, |
| 2763 | saveq->iocb.un.ulpWord[4], |
| 2764 | saveq->iocb.ulpCommand, |
| 2765 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | } |
| 2767 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2768 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | return rc; |
| 2770 | } |
| 2771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2773 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2774 | * @phba: Pointer to HBA context object. |
| 2775 | * @pring: Pointer to driver SLI ring object. |
| 2776 | * |
| 2777 | * This function is called from the iocb ring event handlers when |
| 2778 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2779 | * an error attention condition to the worker thread and the worker |
| 2780 | * thread will transition the HBA to offline state. |
| 2781 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2782 | static void |
| 2783 | 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] | 2784 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2785 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2786 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2787 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2788 | * rsp ring <portRspMax> |
| 2789 | */ |
| 2790 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2791 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2792 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2793 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 2794 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2795 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2796 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2797 | |
| 2798 | /* |
| 2799 | * All error attention handlers are posted to |
| 2800 | * worker thread |
| 2801 | */ |
| 2802 | phba->work_ha |= HA_ERATT; |
| 2803 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2804 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2805 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2806 | |
| 2807 | return; |
| 2808 | } |
| 2809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2811 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2812 | * @ptr: Pointer to address of HBA context object. |
| 2813 | * |
| 2814 | * This function is invoked by the Error Attention polling timer when the |
| 2815 | * timer times out. It will check the SLI Error Attention register for |
| 2816 | * possible attention events. If so, it will post an Error Attention event |
| 2817 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2818 | * Error Attention polling timer for the next poll. |
| 2819 | **/ |
| 2820 | void lpfc_poll_eratt(unsigned long ptr) |
| 2821 | { |
| 2822 | struct lpfc_hba *phba; |
| 2823 | uint32_t eratt = 0; |
| 2824 | |
| 2825 | phba = (struct lpfc_hba *)ptr; |
| 2826 | |
| 2827 | /* Check chip HA register for error event */ |
| 2828 | eratt = lpfc_sli_check_eratt(phba); |
| 2829 | |
| 2830 | if (eratt) |
| 2831 | /* Tell the worker thread there is work to do */ |
| 2832 | lpfc_worker_wake_up(phba); |
| 2833 | else |
| 2834 | /* Restart the timer for next eratt poll */ |
| 2835 | mod_timer(&phba->eratt_poll, jiffies + |
| 2836 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2837 | return; |
| 2838 | } |
| 2839 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2842 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2843 | * @phba: Pointer to HBA context object. |
| 2844 | * @pring: Pointer to driver SLI ring object. |
| 2845 | * @mask: Host attention register mask for this ring. |
| 2846 | * |
| 2847 | * This function is called from the interrupt context when there is a ring |
| 2848 | * event for the fcp ring. The caller does not hold any lock. |
| 2849 | * 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] | 2850 | * 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] | 2851 | * LE bit set. The function will call the completion handler of the command iocb |
| 2852 | * if the response iocb indicates a completion for a command iocb or it is |
| 2853 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2854 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2856 | * to check it explicitly. |
| 2857 | */ |
| 2858 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2859 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2860 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2862 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2864 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2866 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | uint32_t status; |
| 2868 | uint32_t portRspPut, portRspMax; |
| 2869 | int rc = 1; |
| 2870 | lpfc_iocb_type type; |
| 2871 | unsigned long iflag; |
| 2872 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2873 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2874 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | pring->stats.iocb_event++; |
| 2876 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | /* |
| 2878 | * The next available response entry should never exceed the maximum |
| 2879 | * entries. If it does, treat it as an adapter hardware error. |
| 2880 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 2881 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2883 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2884 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2885 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | return 1; |
| 2887 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2888 | if (phba->fcp_ring_in_use) { |
| 2889 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2890 | return 1; |
| 2891 | } else |
| 2892 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | |
| 2894 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 2895 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2896 | /* |
| 2897 | * Fetch an entry off the ring and copy it into a local data |
| 2898 | * structure. The copy involves a byte-swap since the |
| 2899 | * network byte order and pci byte orders are different. |
| 2900 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2901 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2902 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2903 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 2904 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 2905 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2906 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2907 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2908 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2909 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2910 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2911 | irsp = &rspiocbq.iocb; |
| 2912 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2913 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2914 | pring->stats.iocb_rsp++; |
| 2915 | rsp_cmpl++; |
| 2916 | |
| 2917 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2918 | /* |
| 2919 | * If resource errors reported from HBA, reduce |
| 2920 | * queuedepths of the SCSI device. |
| 2921 | */ |
| 2922 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2923 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2924 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2925 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2927 | } |
| 2928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2929 | /* Rsp ring <ringno> error: IOCB */ |
| 2930 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2931 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2932 | "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] | 2933 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2934 | irsp->un.ulpWord[0], |
| 2935 | irsp->un.ulpWord[1], |
| 2936 | irsp->un.ulpWord[2], |
| 2937 | irsp->un.ulpWord[3], |
| 2938 | irsp->un.ulpWord[4], |
| 2939 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2940 | *(uint32_t *)&irsp->un1, |
| 2941 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | switch (type) { |
| 2945 | case LPFC_ABORT_IOCB: |
| 2946 | case LPFC_SOL_IOCB: |
| 2947 | /* |
| 2948 | * Idle exchange closed via ABTS from port. No iocb |
| 2949 | * resources need to be recovered. |
| 2950 | */ |
| 2951 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2952 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2953 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2954 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2956 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | break; |
| 2958 | } |
| 2959 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2960 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2961 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2962 | if (unlikely(!cmdiocbq)) |
| 2963 | break; |
| 2964 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 2965 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 2966 | if (cmdiocbq->iocb_cmpl) { |
| 2967 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2968 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2969 | &rspiocbq); |
| 2970 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2971 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2972 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2973 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2975 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2977 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | default: |
| 2979 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2980 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2981 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2982 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2983 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2984 | dev_warn(&((phba->pcidev)->dev), |
| 2985 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | phba->brd_no, adaptermsg); |
| 2987 | } else { |
| 2988 | /* Unknown IOCB command */ |
| 2989 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2990 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2991 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2992 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2993 | irsp->ulpStatus, |
| 2994 | irsp->ulpIoTag, |
| 2995 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2996 | } |
| 2997 | break; |
| 2998 | } |
| 2999 | |
| 3000 | /* |
| 3001 | * The response IOCB has been processed. Update the ring |
| 3002 | * pointer in SLIM. If the port response put pointer has not |
| 3003 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3004 | * response put pointer. |
| 3005 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3006 | writel(pring->sli.sli3.rspidx, |
| 3007 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3009 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3011 | } |
| 3012 | |
| 3013 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3014 | pring->stats.iocb_rsp_full++; |
| 3015 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3016 | writel(status, phba->CAregaddr); |
| 3017 | readl(phba->CAregaddr); |
| 3018 | } |
| 3019 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3020 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3021 | pring->stats.iocb_cmd_empty++; |
| 3022 | |
| 3023 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3024 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | lpfc_sli_resume_iocb(phba, pring); |
| 3026 | |
| 3027 | if ((pring->lpfc_sli_cmd_available)) |
| 3028 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3029 | |
| 3030 | } |
| 3031 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3032 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3033 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | return rc; |
| 3035 | } |
| 3036 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3037 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3038 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3039 | * @phba: Pointer to HBA context object. |
| 3040 | * @pring: Pointer to driver SLI ring object. |
| 3041 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3042 | * |
| 3043 | * This function is called from the worker thread when there is a slow-path |
| 3044 | * response IOCB to process. This function chains all the response iocbs until |
| 3045 | * seeing the iocb with the LE bit set. The function will call |
| 3046 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3047 | * completion of a command iocb. The function will call the |
| 3048 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3049 | * The function frees the resources or calls the completion handler if this |
| 3050 | * iocb is an abort completion. The function returns NULL when the response |
| 3051 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3052 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3053 | * response iocb passed in. |
| 3054 | **/ |
| 3055 | static struct lpfc_iocbq * |
| 3056 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3057 | struct lpfc_iocbq *rspiocbp) |
| 3058 | { |
| 3059 | struct lpfc_iocbq *saveq; |
| 3060 | struct lpfc_iocbq *cmdiocbp; |
| 3061 | struct lpfc_iocbq *next_iocb; |
| 3062 | IOCB_t *irsp = NULL; |
| 3063 | uint32_t free_saveq; |
| 3064 | uint8_t iocb_cmd_type; |
| 3065 | lpfc_iocb_type type; |
| 3066 | unsigned long iflag; |
| 3067 | int rc; |
| 3068 | |
| 3069 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3070 | /* First add the response iocb to the countinueq list */ |
| 3071 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3072 | pring->iocb_continueq_cnt++; |
| 3073 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3074 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3075 | irsp = &rspiocbp->iocb; |
| 3076 | if (irsp->ulpLe) { |
| 3077 | /* |
| 3078 | * By default, the driver expects to free all resources |
| 3079 | * associated with this iocb completion. |
| 3080 | */ |
| 3081 | free_saveq = 1; |
| 3082 | saveq = list_get_first(&pring->iocb_continueq, |
| 3083 | struct lpfc_iocbq, list); |
| 3084 | irsp = &(saveq->iocb); |
| 3085 | list_del_init(&pring->iocb_continueq); |
| 3086 | pring->iocb_continueq_cnt = 0; |
| 3087 | |
| 3088 | pring->stats.iocb_rsp++; |
| 3089 | |
| 3090 | /* |
| 3091 | * If resource errors reported from HBA, reduce |
| 3092 | * queuedepths of the SCSI device. |
| 3093 | */ |
| 3094 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 3095 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 3096 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3097 | phba->lpfc_rampdown_queue_depth(phba); |
| 3098 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3099 | } |
| 3100 | |
| 3101 | if (irsp->ulpStatus) { |
| 3102 | /* Rsp ring <ringno> error: IOCB */ |
| 3103 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3104 | "0328 Rsp Ring %d error: " |
| 3105 | "IOCB Data: " |
| 3106 | "x%x x%x x%x x%x " |
| 3107 | "x%x x%x x%x x%x " |
| 3108 | "x%x x%x x%x x%x " |
| 3109 | "x%x x%x x%x x%x\n", |
| 3110 | pring->ringno, |
| 3111 | irsp->un.ulpWord[0], |
| 3112 | irsp->un.ulpWord[1], |
| 3113 | irsp->un.ulpWord[2], |
| 3114 | irsp->un.ulpWord[3], |
| 3115 | irsp->un.ulpWord[4], |
| 3116 | irsp->un.ulpWord[5], |
| 3117 | *(((uint32_t *) irsp) + 6), |
| 3118 | *(((uint32_t *) irsp) + 7), |
| 3119 | *(((uint32_t *) irsp) + 8), |
| 3120 | *(((uint32_t *) irsp) + 9), |
| 3121 | *(((uint32_t *) irsp) + 10), |
| 3122 | *(((uint32_t *) irsp) + 11), |
| 3123 | *(((uint32_t *) irsp) + 12), |
| 3124 | *(((uint32_t *) irsp) + 13), |
| 3125 | *(((uint32_t *) irsp) + 14), |
| 3126 | *(((uint32_t *) irsp) + 15)); |
| 3127 | } |
| 3128 | |
| 3129 | /* |
| 3130 | * Fetch the IOCB command type and call the correct completion |
| 3131 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3132 | * get freed back to the lpfc_iocb_list by the discovery |
| 3133 | * kernel thread. |
| 3134 | */ |
| 3135 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3136 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3137 | switch (type) { |
| 3138 | case LPFC_SOL_IOCB: |
| 3139 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3140 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3141 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3142 | break; |
| 3143 | |
| 3144 | case LPFC_UNSOL_IOCB: |
| 3145 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3146 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3147 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3148 | if (!rc) |
| 3149 | free_saveq = 0; |
| 3150 | break; |
| 3151 | |
| 3152 | case LPFC_ABORT_IOCB: |
| 3153 | cmdiocbp = NULL; |
| 3154 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3155 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3156 | saveq); |
| 3157 | if (cmdiocbp) { |
| 3158 | /* Call the specified completion routine */ |
| 3159 | if (cmdiocbp->iocb_cmpl) { |
| 3160 | spin_unlock_irqrestore(&phba->hbalock, |
| 3161 | iflag); |
| 3162 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3163 | saveq); |
| 3164 | spin_lock_irqsave(&phba->hbalock, |
| 3165 | iflag); |
| 3166 | } else |
| 3167 | __lpfc_sli_release_iocbq(phba, |
| 3168 | cmdiocbp); |
| 3169 | } |
| 3170 | break; |
| 3171 | |
| 3172 | case LPFC_UNKNOWN_IOCB: |
| 3173 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3174 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3175 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3176 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3177 | MAX_MSG_DATA); |
| 3178 | dev_warn(&((phba->pcidev)->dev), |
| 3179 | "lpfc%d: %s\n", |
| 3180 | phba->brd_no, adaptermsg); |
| 3181 | } else { |
| 3182 | /* Unknown IOCB command */ |
| 3183 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3184 | "0335 Unknown IOCB " |
| 3185 | "command Data: x%x " |
| 3186 | "x%x x%x x%x\n", |
| 3187 | irsp->ulpCommand, |
| 3188 | irsp->ulpStatus, |
| 3189 | irsp->ulpIoTag, |
| 3190 | irsp->ulpContext); |
| 3191 | } |
| 3192 | break; |
| 3193 | } |
| 3194 | |
| 3195 | if (free_saveq) { |
| 3196 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3197 | &saveq->list, list) { |
| 3198 | list_del(&rspiocbp->list); |
| 3199 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3200 | } |
| 3201 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3202 | } |
| 3203 | rspiocbp = NULL; |
| 3204 | } |
| 3205 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3206 | return rspiocbp; |
| 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * 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] | 3211 | * @phba: Pointer to HBA context object. |
| 3212 | * @pring: Pointer to driver SLI ring object. |
| 3213 | * @mask: Host attention register mask for this ring. |
| 3214 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3215 | * This routine wraps the actual slow_ring event process routine from the |
| 3216 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3217 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3218 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3219 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3220 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3221 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3222 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3223 | } |
| 3224 | |
| 3225 | /** |
| 3226 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3227 | * @phba: Pointer to HBA context object. |
| 3228 | * @pring: Pointer to driver SLI ring object. |
| 3229 | * @mask: Host attention register mask for this ring. |
| 3230 | * |
| 3231 | * This function is called from the worker thread when there is a ring event |
| 3232 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3233 | * remove each response iocb in the response ring and calls the handle |
| 3234 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3235 | **/ |
| 3236 | static void |
| 3237 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3238 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3239 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3240 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | IOCB_t *entry; |
| 3242 | IOCB_t *irsp = NULL; |
| 3243 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3245 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3246 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3248 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | pring->stats.iocb_event++; |
| 3251 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | /* |
| 3253 | * The next available response entry should never exceed the maximum |
| 3254 | * entries. If it does, treat it as an adapter hardware error. |
| 3255 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3256 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3258 | if (portRspPut >= portRspMax) { |
| 3259 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3260 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | * rsp ring <portRspMax> |
| 3262 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3264 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3265 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3266 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3268 | phba->link_state = LPFC_HBA_ERROR; |
| 3269 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | |
| 3271 | phba->work_hs = HS_FFER3; |
| 3272 | lpfc_handle_eratt(phba); |
| 3273 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3274 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3278 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | /* |
| 3280 | * Build a completion list and call the appropriate handler. |
| 3281 | * The process is to get the next available response iocb, get |
| 3282 | * a free iocb from the list, copy the response data into the |
| 3283 | * free iocb, insert to the continuation list, and update the |
| 3284 | * next response index to slim. This process makes response |
| 3285 | * iocb's in the ring available to DMA as fast as possible but |
| 3286 | * pays a penalty for a copy operation. Since the iocb is |
| 3287 | * only 32 bytes, this penalty is considered small relative to |
| 3288 | * the PCI reads for register values and a slim write. When |
| 3289 | * the ulpLe field is set, the entire Command has been |
| 3290 | * received. |
| 3291 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3292 | entry = lpfc_resp_iocb(phba, pring); |
| 3293 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3294 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3295 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | if (rspiocbp == NULL) { |
| 3297 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3298 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3299 | break; |
| 3300 | } |
| 3301 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3302 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3303 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | irsp = &rspiocbp->iocb; |
| 3305 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3306 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3307 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3309 | if (pring->ringno == LPFC_ELS_RING) { |
| 3310 | lpfc_debugfs_slow_ring_trc(phba, |
| 3311 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3312 | *(((uint32_t *) irsp) + 4), |
| 3313 | *(((uint32_t *) irsp) + 6), |
| 3314 | *(((uint32_t *) irsp) + 7)); |
| 3315 | } |
| 3316 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3317 | writel(pring->sli.sli3.rspidx, |
| 3318 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3320 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3321 | /* Handle the response IOCB */ |
| 3322 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3323 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | |
| 3325 | /* |
| 3326 | * If the port response put pointer has not been updated, sync |
| 3327 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3328 | * response put pointer. |
| 3329 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3330 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3332 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3333 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3335 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | /* At least one response entry has been freed */ |
| 3337 | pring->stats.iocb_rsp_full++; |
| 3338 | /* SET RxRE_RSP in Chip Att register */ |
| 3339 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3340 | writel(status, phba->CAregaddr); |
| 3341 | readl(phba->CAregaddr); /* flush */ |
| 3342 | } |
| 3343 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3344 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3345 | pring->stats.iocb_cmd_empty++; |
| 3346 | |
| 3347 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3348 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | lpfc_sli_resume_iocb(phba, pring); |
| 3350 | |
| 3351 | if ((pring->lpfc_sli_cmd_available)) |
| 3352 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3353 | |
| 3354 | } |
| 3355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3357 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | } |
| 3359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3360 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3361 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3362 | * @phba: Pointer to HBA context object. |
| 3363 | * @pring: Pointer to driver SLI ring object. |
| 3364 | * @mask: Host attention register mask for this ring. |
| 3365 | * |
| 3366 | * This function is called from the worker thread when there is a pending |
| 3367 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3368 | * queue. The caller does not hold any lock. The function will remove each |
| 3369 | * response iocb from the response worker queue and calls the handle |
| 3370 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3371 | **/ |
| 3372 | static void |
| 3373 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3374 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3375 | { |
| 3376 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3377 | struct hbq_dmabuf *dmabuf; |
| 3378 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3379 | unsigned long iflag; |
| 3380 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3381 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3382 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3383 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3384 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3385 | /* Get the response iocb from the head of work queue */ |
| 3386 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3387 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3388 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3389 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3390 | |
| 3391 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3392 | case CQE_CODE_COMPL_WQE: |
| 3393 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3394 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3395 | /* Translate ELS WCQE to response IOCBQ */ |
| 3396 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3397 | irspiocbq); |
| 3398 | if (irspiocbq) |
| 3399 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3400 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3401 | break; |
| 3402 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3403 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3404 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3405 | cq_event); |
| 3406 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3407 | break; |
| 3408 | default: |
| 3409 | break; |
| 3410 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | |
| 3414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3415 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3416 | * @phba: Pointer to HBA context object. |
| 3417 | * @pring: Pointer to driver SLI ring object. |
| 3418 | * |
| 3419 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3420 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3421 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3422 | * the return of this function. The caller is not required to hold any locks. |
| 3423 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3424 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3426 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3427 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3430 | if (pring->ringno == LPFC_ELS_RING) { |
| 3431 | lpfc_fabric_abort_hba(phba); |
| 3432 | } |
| 3433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | /* Error everything on txq and txcmplq |
| 3435 | * First do the txq. |
| 3436 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3437 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3438 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | |
| 3441 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3442 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3443 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3444 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3445 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3446 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3447 | /* Cancel all the IOCBs from the completions list */ |
| 3448 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3449 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | } |
| 3451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3452 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3453 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3454 | * @phba: Pointer to HBA context object. |
| 3455 | * |
| 3456 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3457 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3458 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3459 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3460 | * slot has been permanently disabled. |
| 3461 | **/ |
| 3462 | void |
| 3463 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3464 | { |
| 3465 | LIST_HEAD(txq); |
| 3466 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3467 | struct lpfc_sli *psli = &phba->sli; |
| 3468 | struct lpfc_sli_ring *pring; |
| 3469 | |
| 3470 | /* Currently, only one fcp ring */ |
| 3471 | pring = &psli->ring[psli->fcp_ring]; |
| 3472 | |
| 3473 | spin_lock_irq(&phba->hbalock); |
| 3474 | /* Retrieve everything on txq */ |
| 3475 | list_splice_init(&pring->txq, &txq); |
| 3476 | pring->txq_cnt = 0; |
| 3477 | |
| 3478 | /* Retrieve everything on the txcmplq */ |
| 3479 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3480 | pring->txcmplq_cnt = 0; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3481 | |
| 3482 | /* Indicate the I/O queues are flushed */ |
| 3483 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3484 | spin_unlock_irq(&phba->hbalock); |
| 3485 | |
| 3486 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3487 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3488 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3489 | |
| 3490 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3491 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3492 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3496 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3497 | * @phba: Pointer to HBA context object. |
| 3498 | * @mask: Bit mask to be checked. |
| 3499 | * |
| 3500 | * This function reads the host status register and compares |
| 3501 | * with the provided bit mask to check if HBA completed |
| 3502 | * the restart. This function will wait in a loop for the |
| 3503 | * HBA to complete restart. If the HBA does not restart within |
| 3504 | * 15 iterations, the function will reset the HBA again. The |
| 3505 | * function returns 1 when HBA fail to restart otherwise returns |
| 3506 | * zero. |
| 3507 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3508 | static int |
| 3509 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3511 | uint32_t status; |
| 3512 | int i = 0; |
| 3513 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3515 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3516 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3517 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3519 | /* |
| 3520 | * Check status register every 100ms for 5 retries, then every |
| 3521 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3522 | * every 2.5 sec for 4. |
| 3523 | * Break our of the loop if errors occurred during init. |
| 3524 | */ |
| 3525 | while (((status & mask) != mask) && |
| 3526 | !(status & HS_FFERM) && |
| 3527 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3528 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3529 | if (i <= 5) |
| 3530 | msleep(10); |
| 3531 | else if (i <= 10) |
| 3532 | msleep(500); |
| 3533 | else |
| 3534 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3536 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3537 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3538 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3539 | lpfc_sli_brdrestart(phba); |
| 3540 | } |
| 3541 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3542 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3543 | retval = 1; |
| 3544 | break; |
| 3545 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3548 | /* Check to see if any errors occurred during init */ |
| 3549 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3550 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3551 | "2751 Adapter failed to restart, " |
| 3552 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3553 | status, |
| 3554 | readl(phba->MBslimaddr + 0xa8), |
| 3555 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3556 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3557 | retval = 1; |
| 3558 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3560 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | } |
| 3562 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3563 | /** |
| 3564 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3565 | * @phba: Pointer to HBA context object. |
| 3566 | * @mask: Bit mask to be checked. |
| 3567 | * |
| 3568 | * This function checks the host status register to check if HBA is |
| 3569 | * ready. This function will wait in a loop for the HBA to be ready |
| 3570 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3571 | * function again. The function returns 1 when HBA fail to be ready |
| 3572 | * otherwise returns zero. |
| 3573 | **/ |
| 3574 | static int |
| 3575 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3576 | { |
| 3577 | uint32_t status; |
| 3578 | int retval = 0; |
| 3579 | |
| 3580 | /* Read the HBA Host Status Register */ |
| 3581 | status = lpfc_sli4_post_status_check(phba); |
| 3582 | |
| 3583 | if (status) { |
| 3584 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3585 | lpfc_sli_brdrestart(phba); |
| 3586 | status = lpfc_sli4_post_status_check(phba); |
| 3587 | } |
| 3588 | |
| 3589 | /* Check to see if any errors occurred during init */ |
| 3590 | if (status) { |
| 3591 | phba->link_state = LPFC_HBA_ERROR; |
| 3592 | retval = 1; |
| 3593 | } else |
| 3594 | phba->sli4_hba.intr_enable = 0; |
| 3595 | |
| 3596 | return retval; |
| 3597 | } |
| 3598 | |
| 3599 | /** |
| 3600 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3601 | * @phba: Pointer to HBA context object. |
| 3602 | * @mask: Bit mask to be checked. |
| 3603 | * |
| 3604 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3605 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3606 | **/ |
| 3607 | int |
| 3608 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3609 | { |
| 3610 | return phba->lpfc_sli_brdready(phba, mask); |
| 3611 | } |
| 3612 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3613 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3615 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3616 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3617 | * @phba: Pointer to HBA context object. |
| 3618 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3619 | * This function is called before resetting an HBA. This function is called |
| 3620 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3621 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3622 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3623 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3624 | uint32_t __iomem *resp_buf; |
| 3625 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3626 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3627 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3628 | int i; |
| 3629 | uint8_t hdrtype; |
| 3630 | |
| 3631 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3632 | if (hdrtype != 0x80 || |
| 3633 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3634 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3635 | return; |
| 3636 | |
| 3637 | /* |
| 3638 | * Tell the other part of the chip to suspend temporarily all |
| 3639 | * its DMA activity. |
| 3640 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3641 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3642 | |
| 3643 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3644 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3645 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3646 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3647 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3649 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3650 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3651 | return; |
| 3652 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3653 | /* Clear Chip error bit */ |
| 3654 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3655 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | mbox = 0; |
| 3659 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3660 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3661 | |
| 3662 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3663 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3664 | writel(mbox, mbox_buf); |
| 3665 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3666 | for (i = 0; i < 50; i++) { |
| 3667 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3668 | return; |
| 3669 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3670 | mdelay(1); |
| 3671 | else |
| 3672 | break; |
| 3673 | } |
| 3674 | resp_data = 0; |
| 3675 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3676 | return; |
| 3677 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3678 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3679 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3680 | goto restore_hc; |
| 3681 | else |
| 3682 | goto clear_errat; |
| 3683 | } |
| 3684 | |
| 3685 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3686 | resp_data = 0; |
| 3687 | for (i = 0; i < 500; i++) { |
| 3688 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3689 | return; |
| 3690 | if (resp_data != mbox) |
| 3691 | mdelay(1); |
| 3692 | else |
| 3693 | break; |
| 3694 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3695 | |
| 3696 | clear_errat: |
| 3697 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3698 | while (++i < 500) { |
| 3699 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3700 | return; |
| 3701 | if (!(ha_copy & HA_ERATT)) |
| 3702 | mdelay(1); |
| 3703 | else |
| 3704 | break; |
| 3705 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3706 | |
| 3707 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3708 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3709 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3713 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3714 | writel(hc_copy, phba->HCregaddr); |
| 3715 | readl(phba->HCregaddr); /* flush */ |
| 3716 | } |
| 3717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3718 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3719 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3720 | * @phba: Pointer to HBA context object. |
| 3721 | * |
| 3722 | * This function issues a kill_board mailbox command and waits for |
| 3723 | * the error attention interrupt. This function is called for stopping |
| 3724 | * the firmware processing. The caller is not required to hold any |
| 3725 | * locks. This function calls lpfc_hba_down_post function to free |
| 3726 | * any pending commands after the kill. The function will return 1 when it |
| 3727 | * fails to kill the board else will return 0. |
| 3728 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3729 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3730 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3732 | struct lpfc_sli *psli; |
| 3733 | LPFC_MBOXQ_t *pmb; |
| 3734 | uint32_t status; |
| 3735 | uint32_t ha_copy; |
| 3736 | int retval; |
| 3737 | int i = 0; |
| 3738 | |
| 3739 | psli = &phba->sli; |
| 3740 | |
| 3741 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3742 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3743 | "0329 Kill HBA Data: x%x x%x\n", |
| 3744 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3745 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3746 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3747 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3748 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3749 | |
| 3750 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3751 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3752 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3753 | spin_unlock_irq(&phba->hbalock); |
| 3754 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3755 | return 1; |
| 3756 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3757 | status &= ~HC_ERINT_ENA; |
| 3758 | writel(status, phba->HCregaddr); |
| 3759 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3760 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3761 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3762 | |
| 3763 | lpfc_kill_board(phba, pmb); |
| 3764 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3765 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3766 | |
| 3767 | if (retval != MBX_SUCCESS) { |
| 3768 | if (retval != MBX_BUSY) |
| 3769 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3770 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3771 | "2752 KILL_BOARD command failed retval %d\n", |
| 3772 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3773 | spin_lock_irq(&phba->hbalock); |
| 3774 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3775 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3776 | return 1; |
| 3777 | } |
| 3778 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3779 | spin_lock_irq(&phba->hbalock); |
| 3780 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3781 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3782 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3783 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3784 | |
| 3785 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3786 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3787 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3788 | * board is now undefined. |
| 3789 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3790 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3791 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3792 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3793 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3794 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3795 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3799 | if (ha_copy & HA_ERATT) { |
| 3800 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3801 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3802 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3804 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3805 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3807 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3808 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3809 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3811 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3812 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3813 | } |
| 3814 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3815 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3816 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3817 | * @phba: Pointer to HBA context object. |
| 3818 | * |
| 3819 | * This function resets the HBA by writing HC_INITFF to the control |
| 3820 | * register. After the HBA resets, this function resets all the iocb ring |
| 3821 | * indices. This function disables PCI layer parity checking during |
| 3822 | * the reset. |
| 3823 | * This function returns 0 always. |
| 3824 | * The caller is not required to hold any locks. |
| 3825 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3826 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3828 | { |
| 3829 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3831 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3832 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3834 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3836 | /* Reset HBA */ |
| 3837 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3838 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3839 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | |
| 3841 | /* perform board reset */ |
| 3842 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3843 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | phba->pport->fc_myDID = 0; |
| 3845 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3847 | /* Turn off parity checking and serr during the physical reset */ |
| 3848 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3849 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3850 | (cfg_value & |
| 3851 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3852 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3853 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3854 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3855 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3856 | writel(HC_INITFF, phba->HCregaddr); |
| 3857 | mdelay(1); |
| 3858 | readl(phba->HCregaddr); /* flush */ |
| 3859 | writel(0, phba->HCregaddr); |
| 3860 | readl(phba->HCregaddr); /* flush */ |
| 3861 | |
| 3862 | /* Restore PCI cmd register */ |
| 3863 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3864 | |
| 3865 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3866 | for (i = 0; i < psli->num_rings; i++) { |
| 3867 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 3869 | pring->sli.sli3.rspidx = 0; |
| 3870 | pring->sli.sli3.next_cmdidx = 0; |
| 3871 | pring->sli.sli3.local_getidx = 0; |
| 3872 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | pring->missbufcnt = 0; |
| 3874 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3877 | return 0; |
| 3878 | } |
| 3879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3880 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3881 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3882 | * @phba: Pointer to HBA context object. |
| 3883 | * |
| 3884 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3885 | * checking during resets the device. The caller is not required to hold |
| 3886 | * any locks. |
| 3887 | * |
| 3888 | * This function returns 0 always. |
| 3889 | **/ |
| 3890 | int |
| 3891 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3892 | { |
| 3893 | struct lpfc_sli *psli = &phba->sli; |
| 3894 | uint16_t cfg_value; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3895 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3896 | |
| 3897 | /* Reset HBA */ |
| 3898 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3899 | "0295 Reset HBA Data: x%x x%x\n", |
| 3900 | phba->pport->port_state, psli->sli_flag); |
| 3901 | |
| 3902 | /* perform board reset */ |
| 3903 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3904 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3905 | phba->pport->fc_myDID = 0; |
| 3906 | phba->pport->fc_prevDID = 0; |
| 3907 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3908 | spin_lock_irq(&phba->hbalock); |
| 3909 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3910 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3911 | spin_unlock_irq(&phba->hbalock); |
| 3912 | |
| 3913 | /* Now physically reset the device */ |
| 3914 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3915 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3916 | |
| 3917 | /* Turn off parity checking and serr during the physical reset */ |
| 3918 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3919 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3920 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3921 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3922 | /* Perform FCoE PCI function reset */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 3923 | lpfc_sli4_queue_destroy(phba); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3924 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3925 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3926 | /* Restore PCI cmd register */ |
| 3927 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3928 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3929 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | /** |
| 3933 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3934 | * @phba: Pointer to HBA context object. |
| 3935 | * |
| 3936 | * This function is called in the SLI initialization code path to |
| 3937 | * restart the HBA. The caller is not required to hold any lock. |
| 3938 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3939 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3940 | * function to free any pending commands. The function enables |
| 3941 | * POST only during the first initialization. The function returns zero. |
| 3942 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3943 | * command before the return of this function. |
| 3944 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3945 | static int |
| 3946 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3947 | { |
| 3948 | MAILBOX_t *mb; |
| 3949 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3950 | volatile uint32_t word0; |
| 3951 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3952 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3953 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3954 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3955 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3956 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 3957 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 3958 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3959 | psli = &phba->sli; |
| 3960 | |
| 3961 | /* Restart HBA */ |
| 3962 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3963 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3964 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3965 | |
| 3966 | word0 = 0; |
| 3967 | mb = (MAILBOX_t *) &word0; |
| 3968 | mb->mbxCommand = MBX_RESTART; |
| 3969 | mb->mbxHc = 1; |
| 3970 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3971 | lpfc_reset_barrier(phba); |
| 3972 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3973 | to_slim = phba->MBslimaddr; |
| 3974 | writel(*(uint32_t *) mb, to_slim); |
| 3975 | readl(to_slim); /* flush */ |
| 3976 | |
| 3977 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3978 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3979 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3980 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3981 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3982 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3983 | writel(*(uint32_t *) mb, to_slim); |
| 3984 | readl(to_slim); /* flush */ |
| 3985 | |
| 3986 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | phba->pport->stopped = 0; |
| 3988 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3989 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3990 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3991 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 3992 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3993 | psli->stats_start = get_seconds(); |
| 3994 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3995 | /* Give the INITFF and Post time to settle. */ |
| 3996 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3998 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 3999 | if (hba_aer_enabled) |
| 4000 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4001 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4002 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | |
| 4004 | return 0; |
| 4005 | } |
| 4006 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4007 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4008 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4009 | * @phba: Pointer to HBA context object. |
| 4010 | * |
| 4011 | * This function is called in the SLI initialization code path to restart |
| 4012 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4013 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4014 | * free any pending commands. |
| 4015 | **/ |
| 4016 | static int |
| 4017 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4018 | { |
| 4019 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4020 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4021 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4022 | |
| 4023 | /* Restart HBA */ |
| 4024 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4025 | "0296 Restart HBA Data: x%x x%x\n", |
| 4026 | phba->pport->port_state, psli->sli_flag); |
| 4027 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4028 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4029 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4030 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4031 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4032 | |
| 4033 | spin_lock_irq(&phba->hbalock); |
| 4034 | phba->pport->stopped = 0; |
| 4035 | phba->link_state = LPFC_INIT_START; |
| 4036 | phba->hba_flag = 0; |
| 4037 | spin_unlock_irq(&phba->hbalock); |
| 4038 | |
| 4039 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4040 | psli->stats_start = get_seconds(); |
| 4041 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4042 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4043 | if (hba_aer_enabled) |
| 4044 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4045 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4046 | lpfc_hba_down_post(phba); |
| 4047 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4048 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /** |
| 4052 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4053 | * @phba: Pointer to HBA context object. |
| 4054 | * |
| 4055 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4056 | * API jump table function pointer from the lpfc_hba struct. |
| 4057 | **/ |
| 4058 | int |
| 4059 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4060 | { |
| 4061 | return phba->lpfc_sli_brdrestart(phba); |
| 4062 | } |
| 4063 | |
| 4064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4065 | * 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] | 4066 | * @phba: Pointer to HBA context object. |
| 4067 | * |
| 4068 | * This function is called after a HBA restart to wait for successful |
| 4069 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4070 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4071 | * iteration, the function will restart the HBA again. The function returns |
| 4072 | * zero if HBA successfully restarted else returns negative error code. |
| 4073 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | static int |
| 4075 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4076 | { |
| 4077 | uint32_t status, i = 0; |
| 4078 | |
| 4079 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4080 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4081 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | |
| 4083 | /* Check status register to see what current state is */ |
| 4084 | i = 0; |
| 4085 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4086 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4087 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4088 | * retries, then every 1 sec for 50 retires for a total of |
| 4089 | * ~60 seconds before reset the board again and check every |
| 4090 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4091 | * board ready is required by the Falcon FIPS zeroization |
| 4092 | * complete, and any reset the board in between shall cause |
| 4093 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4095 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | /* Adapter failed to init, timeout, status reg |
| 4097 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4099 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4100 | "timeout, status reg x%x, " |
| 4101 | "FW Data: A8 x%x AC x%x\n", status, |
| 4102 | readl(phba->MBslimaddr + 0xa8), |
| 4103 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4104 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | return -ETIMEDOUT; |
| 4106 | } |
| 4107 | |
| 4108 | /* Check to see if any errors occurred during init */ |
| 4109 | if (status & HS_FFERM) { |
| 4110 | /* ERROR: During chipset initialization */ |
| 4111 | /* Adapter failed to init, chipset, status reg |
| 4112 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4114 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4115 | "chipset, status reg x%x, " |
| 4116 | "FW Data: A8 x%x AC x%x\n", status, |
| 4117 | readl(phba->MBslimaddr + 0xa8), |
| 4118 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4119 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | return -EIO; |
| 4121 | } |
| 4122 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4123 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4125 | else if (i <= 100) |
| 4126 | msleep(100); |
| 4127 | else |
| 4128 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4130 | if (i == 150) { |
| 4131 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4132 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4133 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | } |
| 4135 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4136 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4137 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | /* Check to see if any errors occurred during init */ |
| 4141 | if (status & HS_FFERM) { |
| 4142 | /* ERROR: During chipset initialization */ |
| 4143 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4144 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4145 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4146 | "status reg x%x, " |
| 4147 | "FW Data: A8 x%x AC x%x\n", status, |
| 4148 | readl(phba->MBslimaddr + 0xa8), |
| 4149 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4150 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | return -EIO; |
| 4152 | } |
| 4153 | |
| 4154 | /* Clear all interrupt enable conditions */ |
| 4155 | writel(0, phba->HCregaddr); |
| 4156 | readl(phba->HCregaddr); /* flush */ |
| 4157 | |
| 4158 | /* setup host attn register */ |
| 4159 | writel(0xffffffff, phba->HAregaddr); |
| 4160 | readl(phba->HAregaddr); /* flush */ |
| 4161 | return 0; |
| 4162 | } |
| 4163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4165 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4166 | * |
| 4167 | * This function calculates and returns the number of HBQs required to be |
| 4168 | * configured. |
| 4169 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4170 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4171 | lpfc_sli_hbq_count(void) |
| 4172 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4173 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4174 | } |
| 4175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4177 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4178 | * |
| 4179 | * This function adds the number of hbq entries in every HBQ to get |
| 4180 | * the total number of hbq entries required for the HBA and returns |
| 4181 | * the total count. |
| 4182 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4183 | static int |
| 4184 | lpfc_sli_hbq_entry_count(void) |
| 4185 | { |
| 4186 | int hbq_count = lpfc_sli_hbq_count(); |
| 4187 | int count = 0; |
| 4188 | int i; |
| 4189 | |
| 4190 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4191 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4192 | return count; |
| 4193 | } |
| 4194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4196 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4197 | * |
| 4198 | * This function calculates amount of memory required for all hbq entries |
| 4199 | * to be configured and returns the total memory required. |
| 4200 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4201 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4202 | lpfc_sli_hbq_size(void) |
| 4203 | { |
| 4204 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4205 | } |
| 4206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4208 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4209 | * @phba: Pointer to HBA context object. |
| 4210 | * |
| 4211 | * This function is called during the SLI initialization to configure |
| 4212 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4213 | * required to hold any locks. This function will return zero if successful |
| 4214 | * else it will return negative error code. |
| 4215 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4216 | static int |
| 4217 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4218 | { |
| 4219 | int hbq_count = lpfc_sli_hbq_count(); |
| 4220 | LPFC_MBOXQ_t *pmb; |
| 4221 | MAILBOX_t *pmbox; |
| 4222 | uint32_t hbqno; |
| 4223 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4225 | /* Get a Mailbox buffer to setup mailbox |
| 4226 | * commands for HBA initialization |
| 4227 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4228 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4229 | |
| 4230 | if (!pmb) |
| 4231 | return -ENOMEM; |
| 4232 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4233 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4234 | |
| 4235 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4236 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4237 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4238 | |
| 4239 | hbq_entry_index = 0; |
| 4240 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4241 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4242 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4243 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4244 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4245 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4246 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4247 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4248 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4249 | |
| 4250 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4251 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4252 | mbxStatus <status>, ring <num> */ |
| 4253 | |
| 4254 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4255 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4256 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4257 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4258 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4259 | pmbox->mbxStatus, hbqno); |
| 4260 | |
| 4261 | phba->link_state = LPFC_HBA_ERROR; |
| 4262 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4263 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | phba->hbq_count = hbq_count; |
| 4267 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4268 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4269 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4270 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4271 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4272 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4273 | return 0; |
| 4274 | } |
| 4275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4276 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4277 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4278 | * @phba: Pointer to HBA context object. |
| 4279 | * |
| 4280 | * This function is called during the SLI initialization to configure |
| 4281 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4282 | * required to hold any locks. This function will return zero if successful |
| 4283 | * else it will return negative error code. |
| 4284 | **/ |
| 4285 | static int |
| 4286 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4287 | { |
| 4288 | phba->hbq_in_use = 1; |
| 4289 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4290 | phba->hbq_count = 1; |
| 4291 | /* Initially populate or replenish the HBQs */ |
| 4292 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4293 | return 0; |
| 4294 | } |
| 4295 | |
| 4296 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4297 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4298 | * @phba: Pointer to HBA context object. |
| 4299 | * @sli_mode: sli mode - 2/3 |
| 4300 | * |
| 4301 | * This function is called by the sli intialization code path |
| 4302 | * to issue config_port mailbox command. This function restarts the |
| 4303 | * HBA firmware and issues a config_port mailbox command to configure |
| 4304 | * the SLI interface in the sli mode specified by sli_mode |
| 4305 | * variable. The caller is not required to hold any locks. |
| 4306 | * The function returns 0 if successful, else returns negative error |
| 4307 | * code. |
| 4308 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4309 | int |
| 4310 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4311 | { |
| 4312 | LPFC_MBOXQ_t *pmb; |
| 4313 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4314 | |
| 4315 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4316 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4318 | return -ENOMEM; |
| 4319 | } |
| 4320 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4321 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4322 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4323 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4324 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4325 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4326 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4327 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | rc = lpfc_sli_chipset_init(phba); |
| 4329 | if (rc) |
| 4330 | break; |
| 4331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4333 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | resetcount++; |
| 4336 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4337 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4338 | * value of 0 means the call was successful. Any other |
| 4339 | * nonzero value is a failure, but if ERESTART is returned, |
| 4340 | * the driver may reset the HBA and try again. |
| 4341 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4342 | rc = lpfc_config_port_prep(phba); |
| 4343 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4344 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4346 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4348 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4349 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | lpfc_config_port(phba, pmb); |
| 4351 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4352 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4353 | LPFC_SLI3_HBQ_ENABLED | |
| 4354 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4355 | LPFC_SLI3_BG_ENABLED | |
| 4356 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4357 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4359 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4360 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4361 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4363 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | spin_unlock_irq(&phba->hbalock); |
| 4365 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4366 | } else { |
| 4367 | /* Allow asynchronous mailbox command to go through */ |
| 4368 | spin_lock_irq(&phba->hbalock); |
| 4369 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4370 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4371 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4372 | |
| 4373 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4374 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4375 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4376 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4377 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4378 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4379 | if (!done) { |
| 4380 | rc = -EINVAL; |
| 4381 | goto do_prep_failed; |
| 4382 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4383 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4384 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4385 | rc = -ENXIO; |
| 4386 | goto do_prep_failed; |
| 4387 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4388 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4389 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4390 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4391 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4392 | phba->max_vpi : phba->max_vports; |
| 4393 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4394 | } else |
| 4395 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4396 | phba->fips_level = 0; |
| 4397 | phba->fips_spec_rev = 0; |
| 4398 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4399 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4400 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4401 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4402 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4403 | "2850 Security Crypto Active. FIPS x%d " |
| 4404 | "(Spec Rev: x%d)", |
| 4405 | phba->fips_level, phba->fips_spec_rev); |
| 4406 | } |
| 4407 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4409 | "2856 Config Port Security Crypto " |
| 4410 | "Error: x%x ", |
| 4411 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4412 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4413 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4414 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4415 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4416 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4417 | |
| 4418 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4419 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4420 | |
| 4421 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4422 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4423 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4424 | else |
| 4425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4426 | "0443 Adapter did not grant " |
| 4427 | "BlockGuard\n"); |
| 4428 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4429 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4430 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4431 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4432 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4433 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4434 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4435 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4436 | return rc; |
| 4437 | } |
| 4438 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4439 | |
| 4440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4441 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4442 | * @phba: Pointer to HBA context object. |
| 4443 | * |
| 4444 | * This function is the main SLI intialization function. This function |
| 4445 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4446 | * error attention handler code. Caller is not required to hold any |
| 4447 | * locks. This function issues config_port mailbox command to configure |
| 4448 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4449 | * calls the config_port_post function to issue init_link mailbox |
| 4450 | * command and to start the discovery. The function will return zero |
| 4451 | * if successful, else it will return negative error code. |
| 4452 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4453 | int |
| 4454 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4455 | { |
| 4456 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4457 | int mode = 3, i; |
| 4458 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4459 | |
| 4460 | switch (lpfc_sli_mode) { |
| 4461 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4462 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4464 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4465 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4466 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4467 | break; |
| 4468 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4469 | mode = 2; |
| 4470 | break; |
| 4471 | case 0: |
| 4472 | case 3: |
| 4473 | break; |
| 4474 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4476 | "1819 Unrecognized lpfc_sli_mode " |
| 4477 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4478 | |
| 4479 | break; |
| 4480 | } |
| 4481 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4482 | rc = lpfc_sli_config_port(phba, mode); |
| 4483 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4484 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4486 | "1820 Unable to select SLI-3. " |
| 4487 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4488 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4489 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4490 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4491 | goto lpfc_sli_hba_setup_error; |
| 4492 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4493 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4494 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4495 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4496 | if (!rc) { |
| 4497 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4498 | "2709 This device supports " |
| 4499 | "Advanced Error Reporting (AER)\n"); |
| 4500 | spin_lock_irq(&phba->hbalock); |
| 4501 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4502 | spin_unlock_irq(&phba->hbalock); |
| 4503 | } else { |
| 4504 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4505 | "2708 This device does not support " |
| 4506 | "Advanced Error Reporting (AER)\n"); |
| 4507 | phba->cfg_aer_support = 0; |
| 4508 | } |
| 4509 | } |
| 4510 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4511 | if (phba->sli_rev == 3) { |
| 4512 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4513 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4514 | } else { |
| 4515 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4516 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4517 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4521 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4522 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4523 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4524 | |
| 4525 | if (rc) |
| 4526 | goto lpfc_sli_hba_setup_error; |
| 4527 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4528 | /* Initialize VPIs. */ |
| 4529 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4530 | /* |
| 4531 | * The VPI bitmask and physical ID array are allocated |
| 4532 | * and initialized once only - at driver load. A port |
| 4533 | * reset doesn't need to reinitialize this memory. |
| 4534 | */ |
| 4535 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4536 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4537 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4538 | GFP_KERNEL); |
| 4539 | if (!phba->vpi_bmask) { |
| 4540 | rc = -ENOMEM; |
| 4541 | goto lpfc_sli_hba_setup_error; |
| 4542 | } |
| 4543 | |
| 4544 | phba->vpi_ids = kzalloc( |
| 4545 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4546 | GFP_KERNEL); |
| 4547 | if (!phba->vpi_ids) { |
| 4548 | kfree(phba->vpi_bmask); |
| 4549 | rc = -ENOMEM; |
| 4550 | goto lpfc_sli_hba_setup_error; |
| 4551 | } |
| 4552 | for (i = 0; i < phba->max_vpi; i++) |
| 4553 | phba->vpi_ids[i] = i; |
| 4554 | } |
| 4555 | } |
| 4556 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4557 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4558 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4559 | rc = lpfc_sli_hbq_setup(phba); |
| 4560 | if (rc) |
| 4561 | goto lpfc_sli_hba_setup_error; |
| 4562 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4563 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4564 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4565 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4566 | |
| 4567 | rc = lpfc_config_port_post(phba); |
| 4568 | if (rc) |
| 4569 | goto lpfc_sli_hba_setup_error; |
| 4570 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4571 | return rc; |
| 4572 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4573 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4574 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4576 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4577 | return rc; |
| 4578 | } |
| 4579 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4580 | /** |
| 4581 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4582 | * @phba: Pointer to HBA context object. |
| 4583 | * @mboxq: mailbox pointer. |
| 4584 | * This function issue a dump mailbox command to read config region |
| 4585 | * 23 and parse the records in the region and populate driver |
| 4586 | * data structure. |
| 4587 | **/ |
| 4588 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4589 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4590 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4591 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4592 | struct lpfc_dmabuf *mp; |
| 4593 | struct lpfc_mqe *mqe; |
| 4594 | uint32_t data_length; |
| 4595 | int rc; |
| 4596 | |
| 4597 | /* Program the default value of vlan_id and fc_map */ |
| 4598 | phba->valid_vlan = 0; |
| 4599 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4600 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4601 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4602 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4603 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4604 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4605 | return -ENOMEM; |
| 4606 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4607 | mqe = &mboxq->u.mqe; |
| 4608 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4609 | rc = -ENOMEM; |
| 4610 | goto out_free_mboxq; |
| 4611 | } |
| 4612 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4613 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4614 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4615 | |
| 4616 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4617 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4618 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4619 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4620 | "CQ: x%x x%x x%x x%x\n", |
| 4621 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4622 | bf_get(lpfc_mqe_command, mqe), |
| 4623 | bf_get(lpfc_mqe_status, mqe), |
| 4624 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4625 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4626 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4627 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4628 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4629 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4630 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4631 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4632 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4633 | mboxq->mcqe.word0, |
| 4634 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4635 | mboxq->mcqe.trailer); |
| 4636 | |
| 4637 | if (rc) { |
| 4638 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4639 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4640 | rc = -EIO; |
| 4641 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4642 | } |
| 4643 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4644 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4645 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4646 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4647 | rc = -EIO; |
| 4648 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4649 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4650 | |
| 4651 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4652 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4653 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4654 | rc = 0; |
| 4655 | |
| 4656 | out_free_mboxq: |
| 4657 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4658 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | /** |
| 4662 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4663 | * @phba: pointer to lpfc hba data structure. |
| 4664 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4665 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4666 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4667 | * On output, the number of data bytes in @vpd. |
| 4668 | * |
| 4669 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4670 | * addition, this routine gets the port vpd data. |
| 4671 | * |
| 4672 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4673 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4674 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4675 | **/ |
| 4676 | static int |
| 4677 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4678 | uint8_t *vpd, uint32_t *vpd_size) |
| 4679 | { |
| 4680 | int rc = 0; |
| 4681 | uint32_t dma_size; |
| 4682 | struct lpfc_dmabuf *dmabuf; |
| 4683 | struct lpfc_mqe *mqe; |
| 4684 | |
| 4685 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4686 | if (!dmabuf) |
| 4687 | return -ENOMEM; |
| 4688 | |
| 4689 | /* |
| 4690 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4691 | * mailbox command. |
| 4692 | */ |
| 4693 | dma_size = *vpd_size; |
| 4694 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4695 | dma_size, |
| 4696 | &dmabuf->phys, |
| 4697 | GFP_KERNEL); |
| 4698 | if (!dmabuf->virt) { |
| 4699 | kfree(dmabuf); |
| 4700 | return -ENOMEM; |
| 4701 | } |
| 4702 | memset(dmabuf->virt, 0, dma_size); |
| 4703 | |
| 4704 | /* |
| 4705 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4706 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4707 | * in SLI3. This code corrects the conflicts. |
| 4708 | */ |
| 4709 | lpfc_read_rev(phba, mboxq); |
| 4710 | mqe = &mboxq->u.mqe; |
| 4711 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4712 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4713 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4714 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4715 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4716 | |
| 4717 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4718 | if (rc) { |
| 4719 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4720 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4721 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4722 | return -EIO; |
| 4723 | } |
| 4724 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4725 | /* |
| 4726 | * The available vpd length cannot be bigger than the |
| 4727 | * DMA buffer passed to the port. Catch the less than |
| 4728 | * case and update the caller's size. |
| 4729 | */ |
| 4730 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4731 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4732 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4733 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4734 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4735 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4736 | dmabuf->virt, dmabuf->phys); |
| 4737 | kfree(dmabuf); |
| 4738 | return 0; |
| 4739 | } |
| 4740 | |
| 4741 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4742 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4743 | * @phba: pointer to lpfc hba data structure. |
| 4744 | * |
| 4745 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4746 | * is attached to. |
| 4747 | * |
| 4748 | * Return codes |
| 4749 | * 0 - sucessful |
| 4750 | * otherwise - failed to retrieve physical port name |
| 4751 | **/ |
| 4752 | static int |
| 4753 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4754 | { |
| 4755 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4756 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4757 | struct lpfc_controller_attribute *cntl_attr; |
| 4758 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4759 | void *virtaddr = NULL; |
| 4760 | uint32_t alloclen, reqlen; |
| 4761 | uint32_t shdr_status, shdr_add_status; |
| 4762 | union lpfc_sli4_cfg_shdr *shdr; |
| 4763 | char cport_name = 0; |
| 4764 | int rc; |
| 4765 | |
| 4766 | /* We assume nothing at this point */ |
| 4767 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4768 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4769 | |
| 4770 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4771 | if (!mboxq) |
| 4772 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4773 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4774 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4775 | lpfc_sli4_read_config(phba); |
| 4776 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4777 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4778 | |
| 4779 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4780 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4781 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4782 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4783 | LPFC_SLI4_MBX_NEMBED); |
| 4784 | if (alloclen < reqlen) { |
| 4785 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4786 | "3084 Allocated DMA memory size (%d) is " |
| 4787 | "less than the requested DMA memory size " |
| 4788 | "(%d)\n", alloclen, reqlen); |
| 4789 | rc = -ENOMEM; |
| 4790 | goto out_free_mboxq; |
| 4791 | } |
| 4792 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4793 | virtaddr = mboxq->sge_array->addr[0]; |
| 4794 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4795 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4796 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4797 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4798 | if (shdr_status || shdr_add_status || rc) { |
| 4799 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4800 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4801 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4802 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4803 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4804 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4805 | rc, shdr_status, shdr_add_status); |
| 4806 | rc = -ENXIO; |
| 4807 | goto out_free_mboxq; |
| 4808 | } |
| 4809 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4810 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4811 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4812 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4813 | phba->sli4_hba.lnk_info.lnk_no = |
| 4814 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4815 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4816 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4817 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4818 | phba->sli4_hba.lnk_info.lnk_no); |
| 4819 | |
| 4820 | retrieve_ppname: |
| 4821 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4822 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4823 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4824 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4825 | LPFC_SLI4_MBX_EMBED); |
| 4826 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4827 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4828 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4829 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4830 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4831 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4832 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4833 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4834 | if (shdr_status || shdr_add_status || rc) { |
| 4835 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4836 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4837 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4838 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4839 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4840 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4841 | rc, shdr_status, shdr_add_status); |
| 4842 | rc = -ENXIO; |
| 4843 | goto out_free_mboxq; |
| 4844 | } |
| 4845 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4846 | case LPFC_LINK_NUMBER_0: |
| 4847 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4848 | &get_port_name->u.response); |
| 4849 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4850 | break; |
| 4851 | case LPFC_LINK_NUMBER_1: |
| 4852 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4853 | &get_port_name->u.response); |
| 4854 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4855 | break; |
| 4856 | case LPFC_LINK_NUMBER_2: |
| 4857 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4858 | &get_port_name->u.response); |
| 4859 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4860 | break; |
| 4861 | case LPFC_LINK_NUMBER_3: |
| 4862 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4863 | &get_port_name->u.response); |
| 4864 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4865 | break; |
| 4866 | default: |
| 4867 | break; |
| 4868 | } |
| 4869 | |
| 4870 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4871 | phba->Port[0] = cport_name; |
| 4872 | phba->Port[1] = '\0'; |
| 4873 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4874 | "3091 SLI get port name: %s\n", phba->Port); |
| 4875 | } |
| 4876 | |
| 4877 | out_free_mboxq: |
| 4878 | if (rc != MBX_TIMEOUT) { |
| 4879 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4880 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4881 | else |
| 4882 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4883 | } |
| 4884 | return rc; |
| 4885 | } |
| 4886 | |
| 4887 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4888 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4889 | * @phba: pointer to lpfc hba data structure. |
| 4890 | * |
| 4891 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4892 | * event queues |
| 4893 | **/ |
| 4894 | static void |
| 4895 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4896 | { |
| 4897 | uint8_t fcp_eqidx; |
| 4898 | |
| 4899 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4900 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4901 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4902 | if (phba->sli4_hba.fcp_cq) { |
| 4903 | do |
| 4904 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4905 | LPFC_QUEUE_REARM); |
| 4906 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
| 4907 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4908 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4909 | if (phba->sli4_hba.fp_eq) { |
| 4910 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 4911 | fcp_eqidx++) |
| 4912 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], |
| 4913 | LPFC_QUEUE_REARM); |
| 4914 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4918 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4919 | * @phba: Pointer to HBA context object. |
| 4920 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4921 | * @extnt_count: buffer to hold port available extent count. |
| 4922 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4923 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4924 | * This function calls the port and retrievs the number of available |
| 4925 | * extents and their size for a particular extent type. |
| 4926 | * |
| 4927 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4928 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4929 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4930 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 4931 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 4932 | { |
| 4933 | int rc = 0; |
| 4934 | uint32_t length; |
| 4935 | uint32_t mbox_tmo; |
| 4936 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 4937 | LPFC_MBOXQ_t *mbox; |
| 4938 | |
| 4939 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4940 | if (!mbox) |
| 4941 | return -ENOMEM; |
| 4942 | |
| 4943 | /* Find out how many extents are available for this resource type */ |
| 4944 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 4945 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 4946 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4947 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 4948 | length, LPFC_SLI4_MBX_EMBED); |
| 4949 | |
| 4950 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 4951 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 4952 | LPFC_SLI4_MBX_EMBED); |
| 4953 | if (unlikely(rc)) { |
| 4954 | rc = -EIO; |
| 4955 | goto err_exit; |
| 4956 | } |
| 4957 | |
| 4958 | if (!phba->sli4_hba.intr_enable) |
| 4959 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 4960 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 4961 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4962 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 4963 | } |
| 4964 | if (unlikely(rc)) { |
| 4965 | rc = -EIO; |
| 4966 | goto err_exit; |
| 4967 | } |
| 4968 | |
| 4969 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 4970 | if (bf_get(lpfc_mbox_hdr_status, |
| 4971 | &rsrc_info->header.cfg_shdr.response)) { |
| 4972 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 4973 | "2930 Failed to get resource extents " |
| 4974 | "Status 0x%x Add'l Status 0x%x\n", |
| 4975 | bf_get(lpfc_mbox_hdr_status, |
| 4976 | &rsrc_info->header.cfg_shdr.response), |
| 4977 | bf_get(lpfc_mbox_hdr_add_status, |
| 4978 | &rsrc_info->header.cfg_shdr.response)); |
| 4979 | rc = -EIO; |
| 4980 | goto err_exit; |
| 4981 | } |
| 4982 | |
| 4983 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 4984 | &rsrc_info->u.rsp); |
| 4985 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 4986 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4987 | |
| 4988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4989 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 4990 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 4991 | |
| 4992 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4993 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4994 | return rc; |
| 4995 | } |
| 4996 | |
| 4997 | /** |
| 4998 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 4999 | * @phba: Pointer to HBA context object. |
| 5000 | * @type: The extent type to check. |
| 5001 | * |
| 5002 | * This function reads the current available extents from the port and checks |
| 5003 | * if the extent count or extent size has changed since the last access. |
| 5004 | * Callers use this routine post port reset to understand if there is a |
| 5005 | * extent reprovisioning requirement. |
| 5006 | * |
| 5007 | * Returns: |
| 5008 | * -Error: error indicates problem. |
| 5009 | * 1: Extent count or size has changed. |
| 5010 | * 0: No changes. |
| 5011 | **/ |
| 5012 | static int |
| 5013 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5014 | { |
| 5015 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5016 | uint16_t size_diff, rsrc_ext_size; |
| 5017 | int rc = 0; |
| 5018 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5019 | struct list_head *rsrc_blk_list = NULL; |
| 5020 | |
| 5021 | size_diff = 0; |
| 5022 | curr_ext_cnt = 0; |
| 5023 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5024 | &rsrc_ext_cnt, |
| 5025 | &rsrc_ext_size); |
| 5026 | if (unlikely(rc)) |
| 5027 | return -EIO; |
| 5028 | |
| 5029 | switch (type) { |
| 5030 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5031 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5032 | break; |
| 5033 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5034 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5035 | break; |
| 5036 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5037 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5038 | break; |
| 5039 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5040 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5041 | break; |
| 5042 | default: |
| 5043 | break; |
| 5044 | } |
| 5045 | |
| 5046 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5047 | curr_ext_cnt++; |
| 5048 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5049 | size_diff++; |
| 5050 | } |
| 5051 | |
| 5052 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5053 | rc = 1; |
| 5054 | |
| 5055 | return rc; |
| 5056 | } |
| 5057 | |
| 5058 | /** |
| 5059 | * lpfc_sli4_cfg_post_extnts - |
| 5060 | * @phba: Pointer to HBA context object. |
| 5061 | * @extnt_cnt - number of available extents. |
| 5062 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5063 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5064 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5065 | * |
| 5066 | * This function executes the extents allocation request. It also |
| 5067 | * takes care of the amount of memory needed to allocate or get the |
| 5068 | * allocated extents. It is the caller's responsibility to evaluate |
| 5069 | * the response. |
| 5070 | * |
| 5071 | * Returns: |
| 5072 | * -Error: Error value describes the condition found. |
| 5073 | * 0: if successful |
| 5074 | **/ |
| 5075 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5076 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5077 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5078 | { |
| 5079 | int rc = 0; |
| 5080 | uint32_t req_len; |
| 5081 | uint32_t emb_len; |
| 5082 | uint32_t alloc_len, mbox_tmo; |
| 5083 | |
| 5084 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5085 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5086 | |
| 5087 | /* |
| 5088 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5089 | * accounts for extents-specific word. |
| 5090 | */ |
| 5091 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5092 | sizeof(uint32_t); |
| 5093 | |
| 5094 | /* |
| 5095 | * Presume the allocation and response will fit into an embedded |
| 5096 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5097 | */ |
| 5098 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5099 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5100 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5101 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5102 | sizeof(uint32_t); |
| 5103 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5104 | } |
| 5105 | |
| 5106 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5107 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5108 | req_len, *emb); |
| 5109 | if (alloc_len < req_len) { |
| 5110 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5111 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5112 | "less than the requested DMA memory " |
| 5113 | "size (x%x)\n", alloc_len, req_len); |
| 5114 | return -ENOMEM; |
| 5115 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5116 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5117 | if (unlikely(rc)) |
| 5118 | return -EIO; |
| 5119 | |
| 5120 | if (!phba->sli4_hba.intr_enable) |
| 5121 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5122 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5123 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5124 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5125 | } |
| 5126 | |
| 5127 | if (unlikely(rc)) |
| 5128 | rc = -EIO; |
| 5129 | return rc; |
| 5130 | } |
| 5131 | |
| 5132 | /** |
| 5133 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5134 | * @phba: Pointer to HBA context object. |
| 5135 | * @type: The resource extent type to allocate. |
| 5136 | * |
| 5137 | * This function allocates the number of elements for the specified |
| 5138 | * resource type. |
| 5139 | **/ |
| 5140 | static int |
| 5141 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5142 | { |
| 5143 | bool emb = false; |
| 5144 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5145 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5146 | uint16_t *ids; |
| 5147 | int i, rc; |
| 5148 | unsigned long longs; |
| 5149 | unsigned long *bmask; |
| 5150 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5151 | LPFC_MBOXQ_t *mbox; |
| 5152 | uint32_t length; |
| 5153 | struct lpfc_id_range *id_array = NULL; |
| 5154 | void *virtaddr = NULL; |
| 5155 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5156 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5157 | struct list_head *ext_blk_list; |
| 5158 | |
| 5159 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5160 | &rsrc_cnt, |
| 5161 | &rsrc_size); |
| 5162 | if (unlikely(rc)) |
| 5163 | return -EIO; |
| 5164 | |
| 5165 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5166 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5167 | "3009 No available Resource Extents " |
| 5168 | "for resource type 0x%x: Count: 0x%x, " |
| 5169 | "Size 0x%x\n", type, rsrc_cnt, |
| 5170 | rsrc_size); |
| 5171 | return -ENOMEM; |
| 5172 | } |
| 5173 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5174 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5175 | "2903 Post resource extents type-0x%x: " |
| 5176 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5177 | |
| 5178 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5179 | if (!mbox) |
| 5180 | return -ENOMEM; |
| 5181 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5182 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5183 | if (unlikely(rc)) { |
| 5184 | rc = -EIO; |
| 5185 | goto err_exit; |
| 5186 | } |
| 5187 | |
| 5188 | /* |
| 5189 | * Figure out where the response is located. Then get local pointers |
| 5190 | * to the response data. The port does not guarantee to respond to |
| 5191 | * all extents counts request so update the local variable with the |
| 5192 | * allocated count from the port. |
| 5193 | */ |
| 5194 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5195 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5196 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5197 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5198 | } else { |
| 5199 | virtaddr = mbox->sge_array->addr[0]; |
| 5200 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5201 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5202 | id_array = &n_rsrc->id; |
| 5203 | } |
| 5204 | |
| 5205 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5206 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5207 | |
| 5208 | /* |
| 5209 | * Based on the resource size and count, correct the base and max |
| 5210 | * resource values. |
| 5211 | */ |
| 5212 | length = sizeof(struct lpfc_rsrc_blks); |
| 5213 | switch (type) { |
| 5214 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5215 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5216 | sizeof(unsigned long), |
| 5217 | GFP_KERNEL); |
| 5218 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5219 | rc = -ENOMEM; |
| 5220 | goto err_exit; |
| 5221 | } |
| 5222 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5223 | sizeof(uint16_t), |
| 5224 | GFP_KERNEL); |
| 5225 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5226 | kfree(phba->sli4_hba.rpi_bmask); |
| 5227 | rc = -ENOMEM; |
| 5228 | goto err_exit; |
| 5229 | } |
| 5230 | |
| 5231 | /* |
| 5232 | * The next_rpi was initialized with the maximum available |
| 5233 | * count but the port may allocate a smaller number. Catch |
| 5234 | * that case and update the next_rpi. |
| 5235 | */ |
| 5236 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5237 | |
| 5238 | /* Initialize local ptrs for common extent processing later. */ |
| 5239 | bmask = phba->sli4_hba.rpi_bmask; |
| 5240 | ids = phba->sli4_hba.rpi_ids; |
| 5241 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5242 | break; |
| 5243 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5244 | phba->vpi_bmask = kzalloc(longs * |
| 5245 | sizeof(unsigned long), |
| 5246 | GFP_KERNEL); |
| 5247 | if (unlikely(!phba->vpi_bmask)) { |
| 5248 | rc = -ENOMEM; |
| 5249 | goto err_exit; |
| 5250 | } |
| 5251 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5252 | sizeof(uint16_t), |
| 5253 | GFP_KERNEL); |
| 5254 | if (unlikely(!phba->vpi_ids)) { |
| 5255 | kfree(phba->vpi_bmask); |
| 5256 | rc = -ENOMEM; |
| 5257 | goto err_exit; |
| 5258 | } |
| 5259 | |
| 5260 | /* Initialize local ptrs for common extent processing later. */ |
| 5261 | bmask = phba->vpi_bmask; |
| 5262 | ids = phba->vpi_ids; |
| 5263 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5264 | break; |
| 5265 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5266 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5267 | sizeof(unsigned long), |
| 5268 | GFP_KERNEL); |
| 5269 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5270 | rc = -ENOMEM; |
| 5271 | goto err_exit; |
| 5272 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5273 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5274 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5275 | sizeof(uint16_t), |
| 5276 | GFP_KERNEL); |
| 5277 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5278 | kfree(phba->sli4_hba.xri_bmask); |
| 5279 | rc = -ENOMEM; |
| 5280 | goto err_exit; |
| 5281 | } |
| 5282 | |
| 5283 | /* Initialize local ptrs for common extent processing later. */ |
| 5284 | bmask = phba->sli4_hba.xri_bmask; |
| 5285 | ids = phba->sli4_hba.xri_ids; |
| 5286 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5287 | break; |
| 5288 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5289 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5290 | sizeof(unsigned long), |
| 5291 | GFP_KERNEL); |
| 5292 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5293 | rc = -ENOMEM; |
| 5294 | goto err_exit; |
| 5295 | } |
| 5296 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5297 | sizeof(uint16_t), |
| 5298 | GFP_KERNEL); |
| 5299 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5300 | kfree(phba->sli4_hba.vfi_bmask); |
| 5301 | rc = -ENOMEM; |
| 5302 | goto err_exit; |
| 5303 | } |
| 5304 | |
| 5305 | /* Initialize local ptrs for common extent processing later. */ |
| 5306 | bmask = phba->sli4_hba.vfi_bmask; |
| 5307 | ids = phba->sli4_hba.vfi_ids; |
| 5308 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5309 | break; |
| 5310 | default: |
| 5311 | /* Unsupported Opcode. Fail call. */ |
| 5312 | id_array = NULL; |
| 5313 | bmask = NULL; |
| 5314 | ids = NULL; |
| 5315 | ext_blk_list = NULL; |
| 5316 | goto err_exit; |
| 5317 | } |
| 5318 | |
| 5319 | /* |
| 5320 | * Complete initializing the extent configuration with the |
| 5321 | * allocated ids assigned to this function. The bitmask serves |
| 5322 | * as an index into the array and manages the available ids. The |
| 5323 | * array just stores the ids communicated to the port via the wqes. |
| 5324 | */ |
| 5325 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5326 | if ((i % 2) == 0) |
| 5327 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5328 | &id_array[k]); |
| 5329 | else |
| 5330 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5331 | &id_array[k]); |
| 5332 | |
| 5333 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5334 | if (unlikely(!rsrc_blks)) { |
| 5335 | rc = -ENOMEM; |
| 5336 | kfree(bmask); |
| 5337 | kfree(ids); |
| 5338 | goto err_exit; |
| 5339 | } |
| 5340 | rsrc_blks->rsrc_start = rsrc_id; |
| 5341 | rsrc_blks->rsrc_size = rsrc_size; |
| 5342 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5343 | rsrc_start = rsrc_id; |
| 5344 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5345 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5346 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5347 | |
| 5348 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5349 | ids[j] = rsrc_id; |
| 5350 | rsrc_id++; |
| 5351 | j++; |
| 5352 | } |
| 5353 | /* Entire word processed. Get next word.*/ |
| 5354 | if ((i % 2) == 1) |
| 5355 | k++; |
| 5356 | } |
| 5357 | err_exit: |
| 5358 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5359 | return rc; |
| 5360 | } |
| 5361 | |
| 5362 | /** |
| 5363 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5364 | * @phba: Pointer to HBA context object. |
| 5365 | * @type: the extent's type. |
| 5366 | * |
| 5367 | * This function deallocates all extents of a particular resource type. |
| 5368 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5369 | * is the caller's responsibility to release all kernel memory resources. |
| 5370 | **/ |
| 5371 | static int |
| 5372 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5373 | { |
| 5374 | int rc; |
| 5375 | uint32_t length, mbox_tmo = 0; |
| 5376 | LPFC_MBOXQ_t *mbox; |
| 5377 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5378 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5379 | |
| 5380 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5381 | if (!mbox) |
| 5382 | return -ENOMEM; |
| 5383 | |
| 5384 | /* |
| 5385 | * This function sends an embedded mailbox because it only sends the |
| 5386 | * the resource type. All extents of this type are released by the |
| 5387 | * port. |
| 5388 | */ |
| 5389 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5390 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5391 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5392 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5393 | length, LPFC_SLI4_MBX_EMBED); |
| 5394 | |
| 5395 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5396 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5397 | LPFC_SLI4_MBX_EMBED); |
| 5398 | if (unlikely(rc)) { |
| 5399 | rc = -EIO; |
| 5400 | goto out_free_mbox; |
| 5401 | } |
| 5402 | if (!phba->sli4_hba.intr_enable) |
| 5403 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5404 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5405 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5406 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5407 | } |
| 5408 | if (unlikely(rc)) { |
| 5409 | rc = -EIO; |
| 5410 | goto out_free_mbox; |
| 5411 | } |
| 5412 | |
| 5413 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5414 | if (bf_get(lpfc_mbox_hdr_status, |
| 5415 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5416 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5417 | "2919 Failed to release resource extents " |
| 5418 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5419 | "Resource memory not released.\n", |
| 5420 | type, |
| 5421 | bf_get(lpfc_mbox_hdr_status, |
| 5422 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5423 | bf_get(lpfc_mbox_hdr_add_status, |
| 5424 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5425 | rc = -EIO; |
| 5426 | goto out_free_mbox; |
| 5427 | } |
| 5428 | |
| 5429 | /* Release kernel memory resources for the specific type. */ |
| 5430 | switch (type) { |
| 5431 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5432 | kfree(phba->vpi_bmask); |
| 5433 | kfree(phba->vpi_ids); |
| 5434 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5435 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5436 | &phba->lpfc_vpi_blk_list, list) { |
| 5437 | list_del_init(&rsrc_blk->list); |
| 5438 | kfree(rsrc_blk); |
| 5439 | } |
| 5440 | break; |
| 5441 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5442 | kfree(phba->sli4_hba.xri_bmask); |
| 5443 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5444 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5445 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5446 | list_del_init(&rsrc_blk->list); |
| 5447 | kfree(rsrc_blk); |
| 5448 | } |
| 5449 | break; |
| 5450 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5451 | kfree(phba->sli4_hba.vfi_bmask); |
| 5452 | kfree(phba->sli4_hba.vfi_ids); |
| 5453 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5454 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5455 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5456 | list_del_init(&rsrc_blk->list); |
| 5457 | kfree(rsrc_blk); |
| 5458 | } |
| 5459 | break; |
| 5460 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5461 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5462 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5463 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5464 | list_del_init(&rsrc_blk->list); |
| 5465 | kfree(rsrc_blk); |
| 5466 | } |
| 5467 | break; |
| 5468 | default: |
| 5469 | break; |
| 5470 | } |
| 5471 | |
| 5472 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5473 | |
| 5474 | out_free_mbox: |
| 5475 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5476 | return rc; |
| 5477 | } |
| 5478 | |
| 5479 | /** |
| 5480 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5481 | * @phba: Pointer to HBA context object. |
| 5482 | * |
| 5483 | * This function allocates all SLI4 resource identifiers. |
| 5484 | **/ |
| 5485 | int |
| 5486 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5487 | { |
| 5488 | int i, rc, error = 0; |
| 5489 | uint16_t count, base; |
| 5490 | unsigned long longs; |
| 5491 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5492 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5493 | 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] | 5494 | if (phba->sli4_hba.extents_in_use) { |
| 5495 | /* |
| 5496 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5497 | * resource extent count must be read and allocated before |
| 5498 | * provisioning the resource id arrays. |
| 5499 | */ |
| 5500 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5501 | LPFC_IDX_RSRC_RDY) { |
| 5502 | /* |
| 5503 | * Extent-based resources are set - the driver could |
| 5504 | * be in a port reset. Figure out if any corrective |
| 5505 | * actions need to be taken. |
| 5506 | */ |
| 5507 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5508 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5509 | if (rc != 0) |
| 5510 | error++; |
| 5511 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5512 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5513 | if (rc != 0) |
| 5514 | error++; |
| 5515 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5516 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5517 | if (rc != 0) |
| 5518 | error++; |
| 5519 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5520 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5521 | if (rc != 0) |
| 5522 | error++; |
| 5523 | |
| 5524 | /* |
| 5525 | * It's possible that the number of resources |
| 5526 | * provided to this port instance changed between |
| 5527 | * resets. Detect this condition and reallocate |
| 5528 | * resources. Otherwise, there is no action. |
| 5529 | */ |
| 5530 | if (error) { |
| 5531 | lpfc_printf_log(phba, KERN_INFO, |
| 5532 | LOG_MBOX | LOG_INIT, |
| 5533 | "2931 Detected extent resource " |
| 5534 | "change. Reallocating all " |
| 5535 | "extents.\n"); |
| 5536 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5537 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5538 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5539 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5540 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5541 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5542 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5543 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5544 | } else |
| 5545 | return 0; |
| 5546 | } |
| 5547 | |
| 5548 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5549 | if (unlikely(rc)) |
| 5550 | goto err_exit; |
| 5551 | |
| 5552 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5553 | if (unlikely(rc)) |
| 5554 | goto err_exit; |
| 5555 | |
| 5556 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5557 | if (unlikely(rc)) |
| 5558 | goto err_exit; |
| 5559 | |
| 5560 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5561 | if (unlikely(rc)) |
| 5562 | goto err_exit; |
| 5563 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5564 | LPFC_IDX_RSRC_RDY); |
| 5565 | return rc; |
| 5566 | } else { |
| 5567 | /* |
| 5568 | * The port does not support resource extents. The XRI, VPI, |
| 5569 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5570 | * Just allocate the bitmasks and provision the resource id |
| 5571 | * arrays. If a port reset is active, the resources don't |
| 5572 | * need any action - just exit. |
| 5573 | */ |
| 5574 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5575 | LPFC_IDX_RSRC_RDY) { |
| 5576 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5577 | lpfc_sli4_remove_rpis(phba); |
| 5578 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5579 | /* RPIs. */ |
| 5580 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
| 5581 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5582 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5583 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5584 | sizeof(unsigned long), |
| 5585 | GFP_KERNEL); |
| 5586 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5587 | rc = -ENOMEM; |
| 5588 | goto err_exit; |
| 5589 | } |
| 5590 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5591 | sizeof(uint16_t), |
| 5592 | GFP_KERNEL); |
| 5593 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5594 | rc = -ENOMEM; |
| 5595 | goto free_rpi_bmask; |
| 5596 | } |
| 5597 | |
| 5598 | for (i = 0; i < count; i++) |
| 5599 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5600 | |
| 5601 | /* VPIs. */ |
| 5602 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
| 5603 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5604 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5605 | phba->vpi_bmask = kzalloc(longs * |
| 5606 | sizeof(unsigned long), |
| 5607 | GFP_KERNEL); |
| 5608 | if (unlikely(!phba->vpi_bmask)) { |
| 5609 | rc = -ENOMEM; |
| 5610 | goto free_rpi_ids; |
| 5611 | } |
| 5612 | phba->vpi_ids = kzalloc(count * |
| 5613 | sizeof(uint16_t), |
| 5614 | GFP_KERNEL); |
| 5615 | if (unlikely(!phba->vpi_ids)) { |
| 5616 | rc = -ENOMEM; |
| 5617 | goto free_vpi_bmask; |
| 5618 | } |
| 5619 | |
| 5620 | for (i = 0; i < count; i++) |
| 5621 | phba->vpi_ids[i] = base + i; |
| 5622 | |
| 5623 | /* XRIs. */ |
| 5624 | count = phba->sli4_hba.max_cfg_param.max_xri; |
| 5625 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5626 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5627 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5628 | sizeof(unsigned long), |
| 5629 | GFP_KERNEL); |
| 5630 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5631 | rc = -ENOMEM; |
| 5632 | goto free_vpi_ids; |
| 5633 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5634 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5635 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5636 | sizeof(uint16_t), |
| 5637 | GFP_KERNEL); |
| 5638 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5639 | rc = -ENOMEM; |
| 5640 | goto free_xri_bmask; |
| 5641 | } |
| 5642 | |
| 5643 | for (i = 0; i < count; i++) |
| 5644 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5645 | |
| 5646 | /* VFIs. */ |
| 5647 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
| 5648 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5649 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5650 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5651 | sizeof(unsigned long), |
| 5652 | GFP_KERNEL); |
| 5653 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5654 | rc = -ENOMEM; |
| 5655 | goto free_xri_ids; |
| 5656 | } |
| 5657 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5658 | sizeof(uint16_t), |
| 5659 | GFP_KERNEL); |
| 5660 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5661 | rc = -ENOMEM; |
| 5662 | goto free_vfi_bmask; |
| 5663 | } |
| 5664 | |
| 5665 | for (i = 0; i < count; i++) |
| 5666 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5667 | |
| 5668 | /* |
| 5669 | * Mark all resources ready. An HBA reset doesn't need |
| 5670 | * to reset the initialization. |
| 5671 | */ |
| 5672 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5673 | LPFC_IDX_RSRC_RDY); |
| 5674 | return 0; |
| 5675 | } |
| 5676 | |
| 5677 | free_vfi_bmask: |
| 5678 | kfree(phba->sli4_hba.vfi_bmask); |
| 5679 | free_xri_ids: |
| 5680 | kfree(phba->sli4_hba.xri_ids); |
| 5681 | free_xri_bmask: |
| 5682 | kfree(phba->sli4_hba.xri_bmask); |
| 5683 | free_vpi_ids: |
| 5684 | kfree(phba->vpi_ids); |
| 5685 | free_vpi_bmask: |
| 5686 | kfree(phba->vpi_bmask); |
| 5687 | free_rpi_ids: |
| 5688 | kfree(phba->sli4_hba.rpi_ids); |
| 5689 | free_rpi_bmask: |
| 5690 | kfree(phba->sli4_hba.rpi_bmask); |
| 5691 | err_exit: |
| 5692 | return rc; |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5697 | * @phba: Pointer to HBA context object. |
| 5698 | * |
| 5699 | * This function allocates the number of elements for the specified |
| 5700 | * resource type. |
| 5701 | **/ |
| 5702 | int |
| 5703 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5704 | { |
| 5705 | if (phba->sli4_hba.extents_in_use) { |
| 5706 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5707 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5708 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5709 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5710 | } else { |
| 5711 | kfree(phba->vpi_bmask); |
| 5712 | kfree(phba->vpi_ids); |
| 5713 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5714 | kfree(phba->sli4_hba.xri_bmask); |
| 5715 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5716 | kfree(phba->sli4_hba.vfi_bmask); |
| 5717 | kfree(phba->sli4_hba.vfi_ids); |
| 5718 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5719 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5720 | } |
| 5721 | |
| 5722 | return 0; |
| 5723 | } |
| 5724 | |
| 5725 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5726 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5727 | * @phba: Pointer to HBA context object. |
| 5728 | * @type: The resource extent type. |
| 5729 | * @extnt_count: buffer to hold port extent count response |
| 5730 | * @extnt_size: buffer to hold port extent size response. |
| 5731 | * |
| 5732 | * This function calls the port to read the host allocated extents |
| 5733 | * for a particular type. |
| 5734 | **/ |
| 5735 | int |
| 5736 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5737 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5738 | { |
| 5739 | bool emb; |
| 5740 | int rc = 0; |
| 5741 | uint16_t curr_blks = 0; |
| 5742 | uint32_t req_len, emb_len; |
| 5743 | uint32_t alloc_len, mbox_tmo; |
| 5744 | struct list_head *blk_list_head; |
| 5745 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5746 | LPFC_MBOXQ_t *mbox; |
| 5747 | void *virtaddr = NULL; |
| 5748 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5749 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5750 | union lpfc_sli4_cfg_shdr *shdr; |
| 5751 | |
| 5752 | switch (type) { |
| 5753 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5754 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5755 | break; |
| 5756 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5757 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5758 | break; |
| 5759 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5760 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5761 | break; |
| 5762 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5763 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5764 | break; |
| 5765 | default: |
| 5766 | return -EIO; |
| 5767 | } |
| 5768 | |
| 5769 | /* Count the number of extents currently allocatd for this type. */ |
| 5770 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5771 | if (curr_blks == 0) { |
| 5772 | /* |
| 5773 | * The GET_ALLOCATED mailbox does not return the size, |
| 5774 | * just the count. The size should be just the size |
| 5775 | * stored in the current allocated block and all sizes |
| 5776 | * for an extent type are the same so set the return |
| 5777 | * value now. |
| 5778 | */ |
| 5779 | *extnt_size = rsrc_blk->rsrc_size; |
| 5780 | } |
| 5781 | curr_blks++; |
| 5782 | } |
| 5783 | |
| 5784 | /* Calculate the total requested length of the dma memory. */ |
| 5785 | req_len = curr_blks * sizeof(uint16_t); |
| 5786 | |
| 5787 | /* |
| 5788 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5789 | * accounts for extents-specific word. |
| 5790 | */ |
| 5791 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5792 | sizeof(uint32_t); |
| 5793 | |
| 5794 | /* |
| 5795 | * Presume the allocation and response will fit into an embedded |
| 5796 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5797 | */ |
| 5798 | emb = LPFC_SLI4_MBX_EMBED; |
| 5799 | req_len = emb_len; |
| 5800 | if (req_len > emb_len) { |
| 5801 | req_len = curr_blks * sizeof(uint16_t) + |
| 5802 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5803 | sizeof(uint32_t); |
| 5804 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5805 | } |
| 5806 | |
| 5807 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5808 | if (!mbox) |
| 5809 | return -ENOMEM; |
| 5810 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5811 | |
| 5812 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5813 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5814 | req_len, emb); |
| 5815 | if (alloc_len < req_len) { |
| 5816 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5817 | "2983 Allocated DMA memory size (x%x) is " |
| 5818 | "less than the requested DMA memory " |
| 5819 | "size (x%x)\n", alloc_len, req_len); |
| 5820 | rc = -ENOMEM; |
| 5821 | goto err_exit; |
| 5822 | } |
| 5823 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5824 | if (unlikely(rc)) { |
| 5825 | rc = -EIO; |
| 5826 | goto err_exit; |
| 5827 | } |
| 5828 | |
| 5829 | if (!phba->sli4_hba.intr_enable) |
| 5830 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5831 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5832 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5833 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5834 | } |
| 5835 | |
| 5836 | if (unlikely(rc)) { |
| 5837 | rc = -EIO; |
| 5838 | goto err_exit; |
| 5839 | } |
| 5840 | |
| 5841 | /* |
| 5842 | * Figure out where the response is located. Then get local pointers |
| 5843 | * to the response data. The port does not guarantee to respond to |
| 5844 | * all extents counts request so update the local variable with the |
| 5845 | * allocated count from the port. |
| 5846 | */ |
| 5847 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5848 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5849 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5850 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5851 | } else { |
| 5852 | virtaddr = mbox->sge_array->addr[0]; |
| 5853 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5854 | shdr = &n_rsrc->cfg_shdr; |
| 5855 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5856 | } |
| 5857 | |
| 5858 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5859 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5860 | "2984 Failed to read allocated resources " |
| 5861 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5862 | type, |
| 5863 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5864 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5865 | rc = -EIO; |
| 5866 | goto err_exit; |
| 5867 | } |
| 5868 | err_exit: |
| 5869 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5870 | return rc; |
| 5871 | } |
| 5872 | |
| 5873 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5874 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5875 | * @phba: pointer to lpfc hba data structure. |
| 5876 | * |
| 5877 | * This routine walks the list of els buffers that have been allocated and |
| 5878 | * repost them to the port by using SGL block post. This is needed after a |
| 5879 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5880 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5881 | * SGL block post mailbox commands to post them to the port. For single els |
| 5882 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5883 | * mailbox command for posting. |
| 5884 | * |
| 5885 | * Returns: 0 = success, non-zero failure. |
| 5886 | **/ |
| 5887 | static int |
| 5888 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5889 | { |
| 5890 | struct lpfc_sglq *sglq_entry = NULL; |
| 5891 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5892 | struct lpfc_sglq *sglq_entry_first = NULL; |
| 5893 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; |
| 5894 | int last_xritag = NO_XRI; |
| 5895 | LIST_HEAD(prep_sgl_list); |
| 5896 | LIST_HEAD(blck_sgl_list); |
| 5897 | LIST_HEAD(allc_sgl_list); |
| 5898 | LIST_HEAD(post_sgl_list); |
| 5899 | LIST_HEAD(free_sgl_list); |
| 5900 | |
| 5901 | spin_lock(&phba->hbalock); |
| 5902 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
| 5903 | spin_unlock(&phba->hbalock); |
| 5904 | |
| 5905 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 5906 | &allc_sgl_list, list) { |
| 5907 | list_del_init(&sglq_entry->list); |
| 5908 | block_cnt++; |
| 5909 | if ((last_xritag != NO_XRI) && |
| 5910 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 5911 | /* a hole in xri block, form a sgl posting block */ |
| 5912 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 5913 | post_cnt = block_cnt - 1; |
| 5914 | /* prepare list for next posting block */ |
| 5915 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5916 | block_cnt = 1; |
| 5917 | } else { |
| 5918 | /* prepare list for next posting block */ |
| 5919 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5920 | /* enough sgls for non-embed sgl mbox command */ |
| 5921 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 5922 | list_splice_init(&prep_sgl_list, |
| 5923 | &blck_sgl_list); |
| 5924 | post_cnt = block_cnt; |
| 5925 | block_cnt = 0; |
| 5926 | } |
| 5927 | } |
| 5928 | num_posted++; |
| 5929 | |
| 5930 | /* keep track of last sgl's xritag */ |
| 5931 | last_xritag = sglq_entry->sli4_xritag; |
| 5932 | |
| 5933 | /* end of repost sgl list condition for els buffers */ |
| 5934 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 5935 | if (post_cnt == 0) { |
| 5936 | list_splice_init(&prep_sgl_list, |
| 5937 | &blck_sgl_list); |
| 5938 | post_cnt = block_cnt; |
| 5939 | } else if (block_cnt == 1) { |
| 5940 | status = lpfc_sli4_post_sgl(phba, |
| 5941 | sglq_entry->phys, 0, |
| 5942 | sglq_entry->sli4_xritag); |
| 5943 | if (!status) { |
| 5944 | /* successful, put sgl to posted list */ |
| 5945 | list_add_tail(&sglq_entry->list, |
| 5946 | &post_sgl_list); |
| 5947 | } else { |
| 5948 | /* Failure, put sgl to free list */ |
| 5949 | lpfc_printf_log(phba, KERN_WARNING, |
| 5950 | LOG_SLI, |
| 5951 | "3159 Failed to post els " |
| 5952 | "sgl, xritag:x%x\n", |
| 5953 | sglq_entry->sli4_xritag); |
| 5954 | list_add_tail(&sglq_entry->list, |
| 5955 | &free_sgl_list); |
| 5956 | spin_lock_irq(&phba->hbalock); |
| 5957 | phba->sli4_hba.els_xri_cnt--; |
| 5958 | spin_unlock_irq(&phba->hbalock); |
| 5959 | } |
| 5960 | } |
| 5961 | } |
| 5962 | |
| 5963 | /* continue until a nembed page worth of sgls */ |
| 5964 | if (post_cnt == 0) |
| 5965 | continue; |
| 5966 | |
| 5967 | /* post the els buffer list sgls as a block */ |
| 5968 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 5969 | post_cnt); |
| 5970 | |
| 5971 | if (!status) { |
| 5972 | /* success, put sgl list to posted sgl list */ |
| 5973 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 5974 | } else { |
| 5975 | /* Failure, put sgl list to free sgl list */ |
| 5976 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 5977 | struct lpfc_sglq, |
| 5978 | list); |
| 5979 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5980 | "3160 Failed to post els sgl-list, " |
| 5981 | "xritag:x%x-x%x\n", |
| 5982 | sglq_entry_first->sli4_xritag, |
| 5983 | (sglq_entry_first->sli4_xritag + |
| 5984 | post_cnt - 1)); |
| 5985 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
| 5986 | spin_lock_irq(&phba->hbalock); |
| 5987 | phba->sli4_hba.els_xri_cnt -= post_cnt; |
| 5988 | spin_unlock_irq(&phba->hbalock); |
| 5989 | } |
| 5990 | |
| 5991 | /* don't reset xirtag due to hole in xri block */ |
| 5992 | if (block_cnt == 0) |
| 5993 | last_xritag = NO_XRI; |
| 5994 | |
| 5995 | /* reset els sgl post count for next round of posting */ |
| 5996 | post_cnt = 0; |
| 5997 | } |
| 5998 | |
| 5999 | /* free the els sgls failed to post */ |
| 6000 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6001 | |
| 6002 | /* push els sgls posted to the availble list */ |
| 6003 | if (!list_empty(&post_sgl_list)) { |
| 6004 | spin_lock(&phba->hbalock); |
| 6005 | list_splice_init(&post_sgl_list, |
| 6006 | &phba->sli4_hba.lpfc_sgl_list); |
| 6007 | spin_unlock(&phba->hbalock); |
| 6008 | } else { |
| 6009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6010 | "3161 Failure to post els sgl to port.\n"); |
| 6011 | return -EIO; |
| 6012 | } |
| 6013 | return 0; |
| 6014 | } |
| 6015 | |
| 6016 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6017 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6018 | * @phba: Pointer to HBA context object. |
| 6019 | * |
| 6020 | * This function is the main SLI4 device intialization PCI function. This |
| 6021 | * function is called by the HBA intialization code, HBA reset code and |
| 6022 | * HBA error attention handler code. Caller is not required to hold any |
| 6023 | * locks. |
| 6024 | **/ |
| 6025 | int |
| 6026 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6027 | { |
| 6028 | int rc; |
| 6029 | LPFC_MBOXQ_t *mboxq; |
| 6030 | struct lpfc_mqe *mqe; |
| 6031 | uint8_t *vpd; |
| 6032 | uint32_t vpd_size; |
| 6033 | uint32_t ftr_rsp = 0; |
| 6034 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6035 | struct lpfc_vport *vport = phba->pport; |
| 6036 | struct lpfc_dmabuf *mp; |
| 6037 | |
| 6038 | /* Perform a PCI function reset to start from clean */ |
| 6039 | rc = lpfc_pci_function_reset(phba); |
| 6040 | if (unlikely(rc)) |
| 6041 | return -ENODEV; |
| 6042 | |
| 6043 | /* Check the HBA Host Status Register for readyness */ |
| 6044 | rc = lpfc_sli4_post_status_check(phba); |
| 6045 | if (unlikely(rc)) |
| 6046 | return -ENODEV; |
| 6047 | else { |
| 6048 | spin_lock_irq(&phba->hbalock); |
| 6049 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6050 | spin_unlock_irq(&phba->hbalock); |
| 6051 | } |
| 6052 | |
| 6053 | /* |
| 6054 | * Allocate a single mailbox container for initializing the |
| 6055 | * port. |
| 6056 | */ |
| 6057 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6058 | if (!mboxq) |
| 6059 | return -ENOMEM; |
| 6060 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6061 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6062 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6063 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6064 | if (!vpd) { |
| 6065 | rc = -ENOMEM; |
| 6066 | goto out_free_mbox; |
| 6067 | } |
| 6068 | |
| 6069 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6070 | if (unlikely(rc)) { |
| 6071 | kfree(vpd); |
| 6072 | goto out_free_mbox; |
| 6073 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6074 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6075 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6076 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6077 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6078 | else |
| 6079 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6080 | |
| 6081 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6082 | LPFC_DCBX_CEE_MODE) |
| 6083 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6084 | else |
| 6085 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6086 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6087 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6088 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6089 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6090 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6091 | "0376 READ_REV Error. SLI Level %d " |
| 6092 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6093 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6094 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6095 | kfree(vpd); |
| 6096 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6097 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6098 | |
| 6099 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6100 | * Continue initialization with default values even if driver failed |
| 6101 | * to read FCoE param config regions, only read parameters if the |
| 6102 | * board is FCoE |
| 6103 | */ |
| 6104 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6105 | lpfc_sli4_read_fcoe_params(phba)) |
| 6106 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6107 | "2570 Failed to read FCoE parameters\n"); |
| 6108 | |
| 6109 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6110 | * Retrieve sli4 device physical port name, failure of doing it |
| 6111 | * is considered as non-fatal. |
| 6112 | */ |
| 6113 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6114 | if (!rc) |
| 6115 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6116 | "3080 Successful retrieving SLI4 device " |
| 6117 | "physical port name: %s.\n", phba->Port); |
| 6118 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6119 | /* |
| 6120 | * Evaluate the read rev and vpd data. Populate the driver |
| 6121 | * state with the results. If this routine fails, the failure |
| 6122 | * is not fatal as the driver will use generic values. |
| 6123 | */ |
| 6124 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6125 | if (unlikely(!rc)) { |
| 6126 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6127 | "0377 Error %d parsing vpd. " |
| 6128 | "Using defaults.\n", rc); |
| 6129 | rc = 0; |
| 6130 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6131 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6132 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6133 | /* Save information as VPD data */ |
| 6134 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6135 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6136 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6137 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6138 | &mqe->un.read_rev); |
| 6139 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6140 | &mqe->un.read_rev); |
| 6141 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6142 | &mqe->un.read_rev); |
| 6143 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6144 | &mqe->un.read_rev); |
| 6145 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6146 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6147 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6148 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6149 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6150 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6151 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6152 | "(%d):0380 READ_REV Status x%x " |
| 6153 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6154 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6155 | bf_get(lpfc_mqe_status, mqe), |
| 6156 | phba->vpd.rev.opFwName, |
| 6157 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6158 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6159 | |
| 6160 | /* |
| 6161 | * Discover the port's supported feature set and match it against the |
| 6162 | * hosts requests. |
| 6163 | */ |
| 6164 | lpfc_request_features(phba, mboxq); |
| 6165 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6166 | if (unlikely(rc)) { |
| 6167 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6168 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | /* |
| 6172 | * The port must support FCP initiator mode as this is the |
| 6173 | * only mode running in the host. |
| 6174 | */ |
| 6175 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6176 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6177 | "0378 No support for fcpi mode.\n"); |
| 6178 | ftr_rsp++; |
| 6179 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6180 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6181 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6182 | else |
| 6183 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6184 | /* |
| 6185 | * If the port cannot support the host's requested features |
| 6186 | * then turn off the global config parameters to disable the |
| 6187 | * feature in the driver. This is not a fatal error. |
| 6188 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6189 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6190 | if (phba->cfg_enable_bg) { |
| 6191 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6192 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6193 | else |
| 6194 | ftr_rsp++; |
| 6195 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6196 | |
| 6197 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6198 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6199 | ftr_rsp++; |
| 6200 | |
| 6201 | if (ftr_rsp) { |
| 6202 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6203 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6204 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6205 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6206 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6207 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6208 | phba->cfg_enable_bg = 0; |
| 6209 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6210 | phba->cfg_enable_npiv = 0; |
| 6211 | } |
| 6212 | |
| 6213 | /* These SLI3 features are assumed in SLI4 */ |
| 6214 | spin_lock_irq(&phba->hbalock); |
| 6215 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6216 | spin_unlock_irq(&phba->hbalock); |
| 6217 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6218 | /* |
| 6219 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6220 | * calls depends on these resources to complete port setup. |
| 6221 | */ |
| 6222 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6223 | if (rc) { |
| 6224 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6225 | "2920 Failed to alloc Resource IDs " |
| 6226 | "rc = x%x\n", rc); |
| 6227 | goto out_free_mbox; |
| 6228 | } |
| 6229 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6230 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6231 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6232 | if (rc) { |
| 6233 | phba->link_state = LPFC_HBA_ERROR; |
| 6234 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6235 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6236 | } |
| 6237 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6238 | mboxq->vport = vport; |
| 6239 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6240 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6241 | if (rc == MBX_SUCCESS) { |
| 6242 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6243 | rc = 0; |
| 6244 | } |
| 6245 | |
| 6246 | /* |
| 6247 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6248 | * it to the mbuf pool. |
| 6249 | */ |
| 6250 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6251 | kfree(mp); |
| 6252 | mboxq->context1 = NULL; |
| 6253 | if (unlikely(rc)) { |
| 6254 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6255 | "0382 READ_SPARAM command failed " |
| 6256 | "status %d, mbxStatus x%x\n", |
| 6257 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6258 | phba->link_state = LPFC_HBA_ERROR; |
| 6259 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6260 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6261 | } |
| 6262 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6263 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6264 | |
| 6265 | /* Update the fc_host data structures with new wwn. */ |
| 6266 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6267 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6268 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6269 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6270 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6271 | if (unlikely(rc)) { |
| 6272 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6273 | "1400 Failed to update xri-sgl size and " |
| 6274 | "mapping: %d\n", rc); |
| 6275 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6276 | } |
| 6277 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6278 | /* register the els sgl pool to the port */ |
| 6279 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6280 | if (unlikely(rc)) { |
| 6281 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6282 | "0582 Error %d during els sgl post " |
| 6283 | "operation\n", rc); |
| 6284 | rc = -ENODEV; |
| 6285 | goto out_free_mbox; |
| 6286 | } |
| 6287 | |
| 6288 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6289 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6290 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6291 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6292 | "0383 Error %d during scsi sgl post " |
| 6293 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6294 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6295 | /* A pci function reset will repost them */ |
| 6296 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6297 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | /* Post the rpi header region to the device. */ |
| 6301 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6302 | if (unlikely(rc)) { |
| 6303 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6304 | "0393 Error %d during rpi post operation\n", |
| 6305 | rc); |
| 6306 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6307 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6308 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6309 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6310 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6311 | /* Create all the SLI4 queues */ |
| 6312 | rc = lpfc_sli4_queue_create(phba); |
| 6313 | if (rc) { |
| 6314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6315 | "3089 Failed to allocate queues\n"); |
| 6316 | rc = -ENODEV; |
| 6317 | goto out_stop_timers; |
| 6318 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6319 | /* Set up all the queues to the device */ |
| 6320 | rc = lpfc_sli4_queue_setup(phba); |
| 6321 | if (unlikely(rc)) { |
| 6322 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6323 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6324 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | /* Arm the CQs and then EQs on device */ |
| 6328 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6329 | |
| 6330 | /* Indicate device interrupt mode */ |
| 6331 | phba->sli4_hba.intr_enable = 1; |
| 6332 | |
| 6333 | /* Allow asynchronous mailbox command to go through */ |
| 6334 | spin_lock_irq(&phba->hbalock); |
| 6335 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6336 | spin_unlock_irq(&phba->hbalock); |
| 6337 | |
| 6338 | /* Post receive buffers to the device */ |
| 6339 | lpfc_sli4_rb_setup(phba); |
| 6340 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6341 | /* Reset HBA FCF states after HBA reset */ |
| 6342 | phba->fcf.fcf_flag = 0; |
| 6343 | phba->fcf.current_rec.flag = 0; |
| 6344 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6345 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6346 | mod_timer(&vport->els_tmofunc, |
| 6347 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6348 | |
| 6349 | /* Start heart beat timer */ |
| 6350 | mod_timer(&phba->hb_tmofunc, |
| 6351 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6352 | phba->hb_outstanding = 0; |
| 6353 | phba->last_completion_time = jiffies; |
| 6354 | |
| 6355 | /* Start error attention (ERATT) polling timer */ |
| 6356 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6357 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6358 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6359 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6360 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6361 | if (!rc) { |
| 6362 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6363 | "2829 This device supports " |
| 6364 | "Advanced Error Reporting (AER)\n"); |
| 6365 | spin_lock_irq(&phba->hbalock); |
| 6366 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6367 | spin_unlock_irq(&phba->hbalock); |
| 6368 | } else { |
| 6369 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6370 | "2830 This device does not support " |
| 6371 | "Advanced Error Reporting (AER)\n"); |
| 6372 | phba->cfg_aer_support = 0; |
| 6373 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6374 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6375 | } |
| 6376 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6377 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6378 | /* |
| 6379 | * The FC Port needs to register FCFI (index 0) |
| 6380 | */ |
| 6381 | lpfc_reg_fcfi(phba, mboxq); |
| 6382 | mboxq->vport = phba->pport; |
| 6383 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6384 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6385 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6386 | rc = 0; |
| 6387 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6388 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6389 | |
| 6390 | /* Check if the port is configured to be disabled */ |
| 6391 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6392 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6393 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6394 | /* |
| 6395 | * The port is ready, set the host's link state to LINK_DOWN |
| 6396 | * in preparation for link interrupts. |
| 6397 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6398 | spin_lock_irq(&phba->hbalock); |
| 6399 | phba->link_state = LPFC_LINK_DOWN; |
| 6400 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6401 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6402 | (phba->hba_flag & LINK_DISABLED)) { |
| 6403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6404 | "3103 Adapter Link is disabled.\n"); |
| 6405 | lpfc_down_link(phba, mboxq); |
| 6406 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6407 | if (rc != MBX_SUCCESS) { |
| 6408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6409 | "3104 Adapter failed to issue " |
| 6410 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6411 | goto out_unset_queue; |
| 6412 | } |
| 6413 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6414 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6415 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6416 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6417 | if (rc) |
| 6418 | goto out_unset_queue; |
| 6419 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6420 | } |
| 6421 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6422 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6423 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6424 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6425 | lpfc_sli4_queue_unset(phba); |
| 6426 | out_destroy_queue: |
| 6427 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6428 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6429 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6430 | out_free_mbox: |
| 6431 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6432 | return rc; |
| 6433 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6434 | |
| 6435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6436 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6437 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6438 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6439 | * This is the callback function for mailbox timer. The mailbox |
| 6440 | * timer is armed when a new mailbox command is issued and the timer |
| 6441 | * is deleted when the mailbox complete. The function is called by |
| 6442 | * the kernel timer code when a mailbox does not complete within |
| 6443 | * expected time. This function wakes up the worker thread to |
| 6444 | * process the mailbox timeout and returns. All the processing is |
| 6445 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6446 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6447 | void |
| 6448 | lpfc_mbox_timeout(unsigned long ptr) |
| 6449 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6450 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6451 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6452 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6453 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6454 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6455 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6456 | if (!tmo_posted) |
| 6457 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6458 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6459 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6460 | if (!tmo_posted) |
| 6461 | lpfc_worker_wake_up(phba); |
| 6462 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6463 | } |
| 6464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6465 | |
| 6466 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6467 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6468 | * @phba: Pointer to HBA context object. |
| 6469 | * |
| 6470 | * This function is called from worker thread when a mailbox command times out. |
| 6471 | * The caller is not required to hold any locks. This function will reset the |
| 6472 | * HBA and recover all the pending commands. |
| 6473 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6474 | void |
| 6475 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6476 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6477 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6478 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6479 | struct lpfc_sli *psli = &phba->sli; |
| 6480 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6481 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6482 | /* Check the pmbox pointer first. There is a race condition |
| 6483 | * between the mbox timeout handler getting executed in the |
| 6484 | * worklist and the mailbox actually completing. When this |
| 6485 | * race condition occurs, the mbox_active will be NULL. |
| 6486 | */ |
| 6487 | spin_lock_irq(&phba->hbalock); |
| 6488 | if (pmbox == NULL) { |
| 6489 | lpfc_printf_log(phba, KERN_WARNING, |
| 6490 | LOG_MBOX | LOG_SLI, |
| 6491 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6492 | "exiting\n"); |
| 6493 | spin_unlock_irq(&phba->hbalock); |
| 6494 | return; |
| 6495 | } |
| 6496 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6497 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6498 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6499 | "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] | 6500 | mb->mbxCommand, |
| 6501 | phba->pport->port_state, |
| 6502 | phba->sli.sli_flag, |
| 6503 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6504 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6505 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6506 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6507 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6508 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6509 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6510 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6511 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6512 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6513 | spin_lock_irq(&phba->hbalock); |
| 6514 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6515 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6516 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6517 | |
| 6518 | pring = &psli->ring[psli->fcp_ring]; |
| 6519 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6520 | |
| 6521 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6522 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6523 | |
| 6524 | /* Reset the HBA device */ |
| 6525 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6526 | } |
| 6527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6528 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6529 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6530 | * @phba: Pointer to HBA context object. |
| 6531 | * @pmbox: Pointer to mailbox object. |
| 6532 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6533 | * |
| 6534 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6535 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6536 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6537 | * The mailbox command can be submitted in polling mode, in which case |
| 6538 | * this function will wait in a polling loop for the completion of the |
| 6539 | * mailbox. |
| 6540 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6541 | * function will submit the command and returns immediately without waiting |
| 6542 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6543 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6544 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6545 | * mailbox is issued in polling mode and there is already a mailbox |
| 6546 | * pending, then the function will return an error. If the mailbox is issued |
| 6547 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6548 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6549 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6550 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6551 | * return codes the caller owns the mailbox command after the return of |
| 6552 | * the function. |
| 6553 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6554 | static int |
| 6555 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6556 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6557 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6558 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6559 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6560 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6561 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6562 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6563 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6564 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6565 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6566 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6567 | int processing_queue = 0; |
| 6568 | |
| 6569 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6570 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6571 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6572 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6573 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6574 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6575 | return MBX_SUCCESS; |
| 6576 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6577 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6578 | pmbox = lpfc_mbox_get(phba); |
| 6579 | if (!pmbox) { |
| 6580 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6581 | return MBX_SUCCESS; |
| 6582 | } |
| 6583 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6584 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6585 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6586 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6587 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6588 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6589 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6590 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6591 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6592 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6593 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6594 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6595 | } |
| 6596 | } |
| 6597 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6598 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6599 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6600 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6601 | goto out_not_finished; |
| 6602 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6603 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6604 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6605 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6606 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6607 | goto out_not_finished; |
| 6608 | } |
| 6609 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6610 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6611 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6612 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6613 | status = MBX_SUCCESS; |
| 6614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6615 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6616 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6617 | |
| 6618 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6619 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6620 | "(%d):0311 Mailbox command x%x cannot " |
| 6621 | "issue Data: x%x x%x\n", |
| 6622 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6623 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6624 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6625 | } |
| 6626 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6627 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
| 6628 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6629 | !(hc_copy & HC_MBINT_ENA)) { |
| 6630 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6631 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6632 | "(%d):2528 Mailbox command x%x cannot " |
| 6633 | "issue Data: x%x x%x\n", |
| 6634 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6635 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6636 | goto out_not_finished; |
| 6637 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6638 | } |
| 6639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6640 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6641 | /* Polling for a mbox command when another one is already active |
| 6642 | * is not allowed in SLI. Also, the driver must have established |
| 6643 | * SLI2 mode to queue and process multiple mbox commands. |
| 6644 | */ |
| 6645 | |
| 6646 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6647 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6648 | |
| 6649 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6650 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6651 | "(%d):2529 Mailbox command x%x " |
| 6652 | "cannot issue Data: x%x x%x\n", |
| 6653 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6654 | pmbox->u.mb.mbxCommand, |
| 6655 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6656 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6657 | } |
| 6658 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6659 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6660 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6661 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6662 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6663 | "(%d):2530 Mailbox command x%x " |
| 6664 | "cannot issue Data: x%x x%x\n", |
| 6665 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6666 | pmbox->u.mb.mbxCommand, |
| 6667 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6668 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6669 | } |
| 6670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6671 | /* Another mailbox command is still being processed, queue this |
| 6672 | * command to be processed later. |
| 6673 | */ |
| 6674 | lpfc_mbox_put(phba, pmbox); |
| 6675 | |
| 6676 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6677 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6678 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6679 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6680 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 6681 | mb->mbxCommand, phba->pport->port_state, |
| 6682 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6683 | |
| 6684 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6685 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6686 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6687 | if (pmbox->vport) { |
| 6688 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6689 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6690 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 6691 | (uint32_t)mb->mbxCommand, |
| 6692 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6693 | } |
| 6694 | else { |
| 6695 | lpfc_debugfs_disc_trc(phba->pport, |
| 6696 | LPFC_DISC_TRC_MBOX, |
| 6697 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 6698 | (uint32_t)mb->mbxCommand, |
| 6699 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6700 | } |
| 6701 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6702 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6703 | } |
| 6704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6705 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6706 | |
| 6707 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6708 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6709 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6710 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6711 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6712 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6713 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6714 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6715 | "(%d):2531 Mailbox command x%x " |
| 6716 | "cannot issue Data: x%x x%x\n", |
| 6717 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6718 | pmbox->u.mb.mbxCommand, |
| 6719 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6720 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6721 | } |
| 6722 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6723 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6724 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6725 | } |
| 6726 | |
| 6727 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6728 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6729 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6730 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6731 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6732 | mb->mbxCommand, phba->pport->port_state, |
| 6733 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6735 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 6736 | if (pmbox->vport) { |
| 6737 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6738 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6739 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 6740 | (uint32_t)mb->mbxCommand, |
| 6741 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6742 | } |
| 6743 | else { |
| 6744 | lpfc_debugfs_disc_trc(phba->pport, |
| 6745 | LPFC_DISC_TRC_MBOX, |
| 6746 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 6747 | (uint32_t)mb->mbxCommand, |
| 6748 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6749 | } |
| 6750 | } |
| 6751 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6752 | psli->slistat.mbox_cmd++; |
| 6753 | evtctr = psli->slistat.mbox_event; |
| 6754 | |
| 6755 | /* next set own bit for the adapter and copy over command word */ |
| 6756 | mb->mbxOwner = OWN_CHIP; |
| 6757 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6758 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6759 | /* Populate mbox extension offset word. */ |
| 6760 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
| 6761 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6762 | = (uint8_t *)phba->mbox_ext |
| 6763 | - (uint8_t *)phba->mbox; |
| 6764 | } |
| 6765 | |
| 6766 | /* Copy the mailbox extension data */ |
| 6767 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6768 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6769 | (uint8_t *)phba->mbox_ext, |
| 6770 | pmbox->in_ext_byte_len); |
| 6771 | } |
| 6772 | /* Copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6773 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6774 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6775 | /* Populate mbox extension offset word. */ |
| 6776 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
| 6777 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6778 | = MAILBOX_HBA_EXT_OFFSET; |
| 6779 | |
| 6780 | /* Copy the mailbox extension data */ |
| 6781 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6782 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6783 | MAILBOX_HBA_EXT_OFFSET, |
| 6784 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6785 | |
| 6786 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6787 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6788 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6789 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6790 | } |
| 6791 | |
| 6792 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6793 | word */ |
| 6794 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 6795 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 6796 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6797 | |
| 6798 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6799 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6800 | to_slim = phba->MBslimaddr; |
| 6801 | writel(ldata, to_slim); |
| 6802 | readl(to_slim); /* flush */ |
| 6803 | |
| 6804 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6805 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6806 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6811 | |
| 6812 | switch (flag) { |
| 6813 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6814 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6815 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6816 | /* Interrupt board to do it */ |
| 6817 | writel(CA_MBATT, phba->CAregaddr); |
| 6818 | readl(phba->CAregaddr); /* flush */ |
| 6819 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6820 | break; |
| 6821 | |
| 6822 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6823 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6824 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6825 | /* Interrupt board to do it */ |
| 6826 | writel(CA_MBATT, phba->CAregaddr); |
| 6827 | readl(phba->CAregaddr); /* flush */ |
| 6828 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6829 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6830 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6831 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6832 | word0 = le32_to_cpu(word0); |
| 6833 | } else { |
| 6834 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6835 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6836 | spin_unlock_irqrestore(&phba->hbalock, |
| 6837 | drvr_flag); |
| 6838 | goto out_not_finished; |
| 6839 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6840 | } |
| 6841 | |
| 6842 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6843 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6844 | spin_unlock_irqrestore(&phba->hbalock, |
| 6845 | drvr_flag); |
| 6846 | goto out_not_finished; |
| 6847 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6848 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6849 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6850 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6851 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6852 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6853 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6854 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6855 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6856 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6857 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6858 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6859 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | /* Check if we took a mbox interrupt while we were |
| 6863 | polling */ |
| 6864 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6865 | && (evtctr != psli->slistat.mbox_event)) |
| 6866 | break; |
| 6867 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6868 | if (i++ > 10) { |
| 6869 | spin_unlock_irqrestore(&phba->hbalock, |
| 6870 | drvr_flag); |
| 6871 | msleep(1); |
| 6872 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6873 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6874 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6875 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6876 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6877 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6878 | word0 = le32_to_cpu(word0); |
| 6879 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6880 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6881 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6882 | /* Check real SLIM for any errors */ |
| 6883 | slimword0 = readl(phba->MBslimaddr); |
| 6884 | slimmb = (MAILBOX_t *) & slimword0; |
| 6885 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6886 | && slimmb->mbxStatus) { |
| 6887 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6888 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6889 | word0 = slimword0; |
| 6890 | } |
| 6891 | } |
| 6892 | } else { |
| 6893 | /* First copy command data */ |
| 6894 | word0 = readl(phba->MBslimaddr); |
| 6895 | } |
| 6896 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6897 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6898 | spin_unlock_irqrestore(&phba->hbalock, |
| 6899 | drvr_flag); |
| 6900 | goto out_not_finished; |
| 6901 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6902 | } |
| 6903 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6904 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6905 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6906 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6907 | /* Copy the mailbox extension data */ |
| 6908 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6909 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 6910 | pmbox->context2, |
| 6911 | pmbox->out_ext_byte_len); |
| 6912 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6913 | } else { |
| 6914 | /* First copy command data */ |
| 6915 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 6916 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6917 | /* Copy the mailbox extension data */ |
| 6918 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6919 | lpfc_memcpy_from_slim(pmbox->context2, |
| 6920 | phba->MBslimaddr + |
| 6921 | MAILBOX_HBA_EXT_OFFSET, |
| 6922 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6923 | } |
| 6924 | } |
| 6925 | |
| 6926 | writel(HA_MBATT, phba->HAregaddr); |
| 6927 | readl(phba->HAregaddr); /* flush */ |
| 6928 | |
| 6929 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 6930 | status = mb->mbxStatus; |
| 6931 | } |
| 6932 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6933 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6934 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6935 | |
| 6936 | out_not_finished: |
| 6937 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6938 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6939 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 6940 | } |
| 6941 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6942 | } |
| 6943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6944 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6945 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 6946 | * @phba: Pointer to HBA context object. |
| 6947 | * |
| 6948 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 6949 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 6950 | * possible outstanding mailbox command before return. |
| 6951 | * |
| 6952 | * Returns: |
| 6953 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 6954 | * the outstanding mailbox command timed out. |
| 6955 | **/ |
| 6956 | static int |
| 6957 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 6958 | { |
| 6959 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6960 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6961 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6962 | |
| 6963 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 6964 | spin_lock_irq(&phba->hbalock); |
| 6965 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6966 | /* Determine how long we might wait for the active mailbox |
| 6967 | * command to be gracefully completed by firmware. |
| 6968 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6969 | if (phba->sli.mbox_active) |
| 6970 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 6971 | phba->sli.mbox_active) * |
| 6972 | 1000) + jiffies; |
| 6973 | spin_unlock_irq(&phba->hbalock); |
| 6974 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6975 | /* Wait for the outstnading mailbox command to complete */ |
| 6976 | while (phba->sli.mbox_active) { |
| 6977 | /* Check active mailbox complete status every 2ms */ |
| 6978 | msleep(2); |
| 6979 | if (time_after(jiffies, timeout)) { |
| 6980 | /* Timeout, marked the outstanding cmd not complete */ |
| 6981 | rc = 1; |
| 6982 | break; |
| 6983 | } |
| 6984 | } |
| 6985 | |
| 6986 | /* Can not cleanly block async mailbox command, fails it */ |
| 6987 | if (rc) { |
| 6988 | spin_lock_irq(&phba->hbalock); |
| 6989 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6990 | spin_unlock_irq(&phba->hbalock); |
| 6991 | } |
| 6992 | return rc; |
| 6993 | } |
| 6994 | |
| 6995 | /** |
| 6996 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 6997 | * @phba: Pointer to HBA context object. |
| 6998 | * |
| 6999 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7000 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7001 | * that there is no outstanding mailbox command before resuming posting |
| 7002 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7003 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7004 | * mailbox command posting. |
| 7005 | **/ |
| 7006 | static void |
| 7007 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7008 | { |
| 7009 | struct lpfc_sli *psli = &phba->sli; |
| 7010 | |
| 7011 | spin_lock_irq(&phba->hbalock); |
| 7012 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7013 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7014 | spin_unlock_irq(&phba->hbalock); |
| 7015 | return; |
| 7016 | } |
| 7017 | |
| 7018 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7019 | * successful or timeout, after timing-out the outstanding mailbox |
| 7020 | * command shall always be removed, so just unblock posting async |
| 7021 | * mailbox command and resume |
| 7022 | */ |
| 7023 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7024 | spin_unlock_irq(&phba->hbalock); |
| 7025 | |
| 7026 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7027 | lpfc_worker_wake_up(phba); |
| 7028 | } |
| 7029 | |
| 7030 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7031 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7032 | * @phba: Pointer to HBA context object. |
| 7033 | * @mboxq: Pointer to mailbox object. |
| 7034 | * |
| 7035 | * The function posts a mailbox to the port. The mailbox is expected |
| 7036 | * to be comletely filled in and ready for the port to operate on it. |
| 7037 | * This routine executes a synchronous completion operation on the |
| 7038 | * mailbox by polling for its completion. |
| 7039 | * |
| 7040 | * The caller must not be holding any locks when calling this routine. |
| 7041 | * |
| 7042 | * Returns: |
| 7043 | * MBX_SUCCESS - mailbox posted successfully |
| 7044 | * Any of the MBX error values. |
| 7045 | **/ |
| 7046 | static int |
| 7047 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7048 | { |
| 7049 | int rc = MBX_SUCCESS; |
| 7050 | unsigned long iflag; |
| 7051 | uint32_t db_ready; |
| 7052 | uint32_t mcqe_status; |
| 7053 | uint32_t mbx_cmnd; |
| 7054 | unsigned long timeout; |
| 7055 | struct lpfc_sli *psli = &phba->sli; |
| 7056 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7057 | struct lpfc_bmbx_create *mbox_rgn; |
| 7058 | struct dma_address *dma_address; |
| 7059 | struct lpfc_register bmbx_reg; |
| 7060 | |
| 7061 | /* |
| 7062 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7063 | * at a time and there is no queueing provided. |
| 7064 | */ |
| 7065 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7066 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7067 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7068 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7069 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7070 | "cannot issue Data: x%x x%x\n", |
| 7071 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7072 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7073 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7074 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7075 | psli->sli_flag, MBX_POLL); |
| 7076 | return MBXERR_ERROR; |
| 7077 | } |
| 7078 | /* The server grabs the token and owns it until release */ |
| 7079 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7080 | phba->sli.mbox_active = mboxq; |
| 7081 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7082 | |
| 7083 | /* |
| 7084 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7085 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7086 | * the bmbx mailbox region. |
| 7087 | */ |
| 7088 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7089 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7090 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7091 | sizeof(struct lpfc_mqe)); |
| 7092 | |
| 7093 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7094 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7095 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7096 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7097 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7098 | * 1000) + jiffies; |
| 7099 | do { |
| 7100 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7101 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7102 | if (!db_ready) |
| 7103 | msleep(2); |
| 7104 | |
| 7105 | if (time_after(jiffies, timeout)) { |
| 7106 | rc = MBXERR_ERROR; |
| 7107 | goto exit; |
| 7108 | } |
| 7109 | } while (!db_ready); |
| 7110 | |
| 7111 | /* Post the low mailbox dma address to the port. */ |
| 7112 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7113 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7114 | * 1000) + jiffies; |
| 7115 | do { |
| 7116 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7117 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7118 | if (!db_ready) |
| 7119 | msleep(2); |
| 7120 | |
| 7121 | if (time_after(jiffies, timeout)) { |
| 7122 | rc = MBXERR_ERROR; |
| 7123 | goto exit; |
| 7124 | } |
| 7125 | } while (!db_ready); |
| 7126 | |
| 7127 | /* |
| 7128 | * Read the CQ to ensure the mailbox has completed. |
| 7129 | * If so, update the mailbox status so that the upper layers |
| 7130 | * can complete the request normally. |
| 7131 | */ |
| 7132 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7133 | sizeof(struct lpfc_mqe)); |
| 7134 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7135 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7136 | sizeof(struct lpfc_mcqe)); |
| 7137 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7138 | /* |
| 7139 | * When the CQE status indicates a failure and the mailbox status |
| 7140 | * indicates success then copy the CQE status into the mailbox status |
| 7141 | * (and prefix it with x4000). |
| 7142 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7143 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7144 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7145 | bf_set(lpfc_mqe_status, mb, |
| 7146 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7147 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7148 | } else |
| 7149 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | |
| 7151 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7152 | "(%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] | 7153 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7154 | " 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] | 7155 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7156 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7157 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7158 | bf_get(lpfc_mqe_status, mb), |
| 7159 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7160 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7161 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7162 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7163 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7164 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7165 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7166 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7167 | mboxq->mcqe.trailer); |
| 7168 | exit: |
| 7169 | /* We are holding the token, no needed for lock when release */ |
| 7170 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7171 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7172 | phba->sli.mbox_active = NULL; |
| 7173 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7174 | return rc; |
| 7175 | } |
| 7176 | |
| 7177 | /** |
| 7178 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7179 | * @phba: Pointer to HBA context object. |
| 7180 | * @pmbox: Pointer to mailbox object. |
| 7181 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7182 | * |
| 7183 | * This function is called by discovery code and HBA management code to submit |
| 7184 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7185 | * |
| 7186 | * Return codes the caller owns the mailbox command after the return of the |
| 7187 | * function. |
| 7188 | **/ |
| 7189 | static int |
| 7190 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7191 | uint32_t flag) |
| 7192 | { |
| 7193 | struct lpfc_sli *psli = &phba->sli; |
| 7194 | unsigned long iflags; |
| 7195 | int rc; |
| 7196 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7197 | /* dump from issue mailbox command if setup */ |
| 7198 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7199 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7200 | rc = lpfc_mbox_dev_check(phba); |
| 7201 | if (unlikely(rc)) { |
| 7202 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7203 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7204 | "cannot issue Data: x%x x%x\n", |
| 7205 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7206 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7207 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7208 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7209 | psli->sli_flag, flag); |
| 7210 | goto out_not_finished; |
| 7211 | } |
| 7212 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7213 | /* Detect polling mode and jump to a handler */ |
| 7214 | if (!phba->sli4_hba.intr_enable) { |
| 7215 | if (flag == MBX_POLL) |
| 7216 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7217 | else |
| 7218 | rc = -EIO; |
| 7219 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7220 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7221 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7222 | "(x%x/x%x) failure: " |
| 7223 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7224 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7225 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7226 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7227 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7228 | mboxq), |
| 7229 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7230 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7231 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7232 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7233 | bf_get(lpfc_mcqe_ext_status, |
| 7234 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7235 | psli->sli_flag, flag); |
| 7236 | return rc; |
| 7237 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7238 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7239 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7240 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7241 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7242 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7243 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7244 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7245 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7247 | /* Try to block the asynchronous mailbox posting */ |
| 7248 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7249 | if (!rc) { |
| 7250 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7251 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7252 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7253 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7254 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7255 | "(%d):2597 Sync Mailbox command " |
| 7256 | "x%x (x%x/x%x) failure: " |
| 7257 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7258 | "Data: x%x x%x\n,", |
| 7259 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7260 | mboxq->u.mb.mbxCommand, |
| 7261 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7262 | mboxq), |
| 7263 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7264 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7265 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7266 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7267 | bf_get(lpfc_mcqe_ext_status, |
| 7268 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7269 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7270 | /* Unblock the async mailbox posting afterward */ |
| 7271 | lpfc_sli4_async_mbox_unblock(phba); |
| 7272 | } |
| 7273 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7277 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7278 | if (rc) { |
| 7279 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7280 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7281 | "cannot issue Data: x%x x%x\n", |
| 7282 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7283 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7284 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7285 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7286 | psli->sli_flag, flag); |
| 7287 | goto out_not_finished; |
| 7288 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7289 | |
| 7290 | /* Put the mailbox command to the driver internal FIFO */ |
| 7291 | psli->slistat.mbox_busy++; |
| 7292 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7293 | lpfc_mbox_put(phba, mboxq); |
| 7294 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7295 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7296 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7297 | "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] | 7298 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7299 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7300 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7301 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7302 | phba->pport->port_state, |
| 7303 | psli->sli_flag, MBX_NOWAIT); |
| 7304 | /* Wake up worker thread to transport mailbox command from head */ |
| 7305 | lpfc_worker_wake_up(phba); |
| 7306 | |
| 7307 | return MBX_BUSY; |
| 7308 | |
| 7309 | out_not_finished: |
| 7310 | return MBX_NOT_FINISHED; |
| 7311 | } |
| 7312 | |
| 7313 | /** |
| 7314 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7315 | * @phba: Pointer to HBA context object. |
| 7316 | * |
| 7317 | * This function is called by worker thread to send a mailbox command to |
| 7318 | * SLI4 HBA firmware. |
| 7319 | * |
| 7320 | **/ |
| 7321 | int |
| 7322 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7323 | { |
| 7324 | struct lpfc_sli *psli = &phba->sli; |
| 7325 | LPFC_MBOXQ_t *mboxq; |
| 7326 | int rc = MBX_SUCCESS; |
| 7327 | unsigned long iflags; |
| 7328 | struct lpfc_mqe *mqe; |
| 7329 | uint32_t mbx_cmnd; |
| 7330 | |
| 7331 | /* Check interrupt mode before post async mailbox command */ |
| 7332 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7333 | return MBX_NOT_FINISHED; |
| 7334 | |
| 7335 | /* Check for mailbox command service token */ |
| 7336 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7337 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7338 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7339 | return MBX_NOT_FINISHED; |
| 7340 | } |
| 7341 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7342 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7343 | return MBX_NOT_FINISHED; |
| 7344 | } |
| 7345 | if (unlikely(phba->sli.mbox_active)) { |
| 7346 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7347 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7348 | "0384 There is pending active mailbox cmd\n"); |
| 7349 | return MBX_NOT_FINISHED; |
| 7350 | } |
| 7351 | /* Take the mailbox command service token */ |
| 7352 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7353 | |
| 7354 | /* Get the next mailbox command from head of queue */ |
| 7355 | mboxq = lpfc_mbox_get(phba); |
| 7356 | |
| 7357 | /* If no more mailbox command waiting for post, we're done */ |
| 7358 | if (!mboxq) { |
| 7359 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7360 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7361 | return MBX_SUCCESS; |
| 7362 | } |
| 7363 | phba->sli.mbox_active = mboxq; |
| 7364 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7365 | |
| 7366 | /* Check device readiness for posting mailbox command */ |
| 7367 | rc = lpfc_mbox_dev_check(phba); |
| 7368 | if (unlikely(rc)) |
| 7369 | /* Driver clean routine will clean up pending mailbox */ |
| 7370 | goto out_not_finished; |
| 7371 | |
| 7372 | /* Prepare the mbox command to be posted */ |
| 7373 | mqe = &mboxq->u.mqe; |
| 7374 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7375 | |
| 7376 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7377 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7378 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7379 | |
| 7380 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7381 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7382 | "x%x x%x\n", |
| 7383 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7384 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7385 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7386 | phba->pport->port_state, psli->sli_flag); |
| 7387 | |
| 7388 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7389 | if (mboxq->vport) { |
| 7390 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7391 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7392 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7393 | mbx_cmnd, mqe->un.mb_words[0], |
| 7394 | mqe->un.mb_words[1]); |
| 7395 | } else { |
| 7396 | lpfc_debugfs_disc_trc(phba->pport, |
| 7397 | LPFC_DISC_TRC_MBOX, |
| 7398 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7399 | mbx_cmnd, mqe->un.mb_words[0], |
| 7400 | mqe->un.mb_words[1]); |
| 7401 | } |
| 7402 | } |
| 7403 | psli->slistat.mbox_cmd++; |
| 7404 | |
| 7405 | /* Post the mailbox command to the port */ |
| 7406 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7407 | if (rc != MBX_SUCCESS) { |
| 7408 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7409 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7410 | "cannot issue Data: x%x x%x\n", |
| 7411 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7412 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7413 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7414 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7415 | psli->sli_flag, MBX_NOWAIT); |
| 7416 | goto out_not_finished; |
| 7417 | } |
| 7418 | |
| 7419 | return rc; |
| 7420 | |
| 7421 | out_not_finished: |
| 7422 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7423 | if (phba->sli.mbox_active) { |
| 7424 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7425 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7426 | /* Release the token */ |
| 7427 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7428 | phba->sli.mbox_active = NULL; |
| 7429 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7430 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7431 | |
| 7432 | return MBX_NOT_FINISHED; |
| 7433 | } |
| 7434 | |
| 7435 | /** |
| 7436 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7437 | * @phba: Pointer to HBA context object. |
| 7438 | * @pmbox: Pointer to mailbox object. |
| 7439 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7440 | * |
| 7441 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7442 | * the API jump table function pointer from the lpfc_hba struct. |
| 7443 | * |
| 7444 | * Return codes the caller owns the mailbox command after the return of the |
| 7445 | * function. |
| 7446 | **/ |
| 7447 | int |
| 7448 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7449 | { |
| 7450 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7451 | } |
| 7452 | |
| 7453 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7454 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7455 | * @phba: The hba struct for which this call is being executed. |
| 7456 | * @dev_grp: The HBA PCI-Device group number. |
| 7457 | * |
| 7458 | * This routine sets up the mbox interface API function jump table in @phba |
| 7459 | * struct. |
| 7460 | * Returns: 0 - success, -ENODEV - failure. |
| 7461 | **/ |
| 7462 | int |
| 7463 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7464 | { |
| 7465 | |
| 7466 | switch (dev_grp) { |
| 7467 | case LPFC_PCI_DEV_LP: |
| 7468 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7469 | phba->lpfc_sli_handle_slow_ring_event = |
| 7470 | lpfc_sli_handle_slow_ring_event_s3; |
| 7471 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7472 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7473 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7474 | break; |
| 7475 | case LPFC_PCI_DEV_OC: |
| 7476 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7477 | phba->lpfc_sli_handle_slow_ring_event = |
| 7478 | lpfc_sli_handle_slow_ring_event_s4; |
| 7479 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7480 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7481 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7482 | break; |
| 7483 | default: |
| 7484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7485 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7486 | dev_grp); |
| 7487 | return -ENODEV; |
| 7488 | break; |
| 7489 | } |
| 7490 | return 0; |
| 7491 | } |
| 7492 | |
| 7493 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7494 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7495 | * @phba: Pointer to HBA context object. |
| 7496 | * @pring: Pointer to driver SLI ring object. |
| 7497 | * @piocb: Pointer to address of newly added command iocb. |
| 7498 | * |
| 7499 | * This function is called with hbalock held to add a command |
| 7500 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7501 | * to the ring. |
| 7502 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7503 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7504 | __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] | 7505 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7506 | { |
| 7507 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7508 | list_add_tail(&piocb->list, &pring->txq); |
| 7509 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7510 | } |
| 7511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7513 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7514 | * @phba: Pointer to HBA context object. |
| 7515 | * @pring: Pointer to driver SLI ring object. |
| 7516 | * @piocb: Pointer to address of newly added command iocb. |
| 7517 | * |
| 7518 | * This function is called with hbalock held before a new |
| 7519 | * iocb is submitted to the firmware. This function checks |
| 7520 | * txq to flush the iocbs in txq to Firmware before |
| 7521 | * submitting new iocbs to the Firmware. |
| 7522 | * If there are iocbs in the txq which need to be submitted |
| 7523 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7524 | * of the txq after dequeuing it from txq. |
| 7525 | * If there is no iocb in the txq then the function will return |
| 7526 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7527 | * *piocb to find if there are more commands in the txq. |
| 7528 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7529 | static struct lpfc_iocbq * |
| 7530 | 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] | 7531 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7532 | { |
| 7533 | struct lpfc_iocbq * nextiocb; |
| 7534 | |
| 7535 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7536 | if (!nextiocb) { |
| 7537 | nextiocb = *piocb; |
| 7538 | *piocb = NULL; |
| 7539 | } |
| 7540 | |
| 7541 | return nextiocb; |
| 7542 | } |
| 7543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7544 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7545 | * __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] | 7546 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7547 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7548 | * @piocb: Pointer to command iocb. |
| 7549 | * @flag: Flag indicating if this command can be put into txq. |
| 7550 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7551 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7552 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7553 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7554 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7555 | * this function allows only iocbs for posting buffers. This function finds |
| 7556 | * next available slot in the command ring and posts the command to the |
| 7557 | * available slot and writes the port attention register to request HBA start |
| 7558 | * processing new iocb. If there is no slot available in the ring and |
| 7559 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7560 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7561 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7562 | * This function is called with hbalock held. The function will return success |
| 7563 | * after it successfully submit the iocb to firmware or after adding to the |
| 7564 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7565 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7566 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7567 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7568 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7569 | { |
| 7570 | struct lpfc_iocbq *nextiocb; |
| 7571 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7572 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7573 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7574 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7575 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7576 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7577 | lpfc_printf_log(phba, KERN_ERR, |
| 7578 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7579 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7580 | piocb->iocb.ulpCommand); |
| 7581 | dump_stack(); |
| 7582 | return IOCB_ERROR; |
| 7583 | } |
| 7584 | |
| 7585 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7586 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7587 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7588 | return IOCB_ERROR; |
| 7589 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7590 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7591 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7592 | return IOCB_ERROR; |
| 7593 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7594 | /* |
| 7595 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7596 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7597 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7598 | return IOCB_ERROR; |
| 7599 | |
| 7600 | /* |
| 7601 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7602 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7603 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7604 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7605 | goto iocb_busy; |
| 7606 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7607 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7608 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7609 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7610 | * can be issued if the link is not up. |
| 7611 | */ |
| 7612 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7613 | case CMD_GEN_REQUEST64_CR: |
| 7614 | case CMD_GEN_REQUEST64_CX: |
| 7615 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7616 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7617 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7618 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7619 | MENLO_TRANSPORT_TYPE)) |
| 7620 | |
| 7621 | goto iocb_busy; |
| 7622 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7623 | case CMD_QUE_RING_BUF_CN: |
| 7624 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7625 | /* |
| 7626 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7627 | * completion, iocb_cmpl MUST be 0. |
| 7628 | */ |
| 7629 | if (piocb->iocb_cmpl) |
| 7630 | piocb->iocb_cmpl = NULL; |
| 7631 | /*FALLTHROUGH*/ |
| 7632 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7633 | case CMD_CLOSE_XRI_CN: |
| 7634 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7635 | break; |
| 7636 | default: |
| 7637 | goto iocb_busy; |
| 7638 | } |
| 7639 | |
| 7640 | /* |
| 7641 | * For FCP commands, we must be in a state where we can process link |
| 7642 | * attention events. |
| 7643 | */ |
| 7644 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7645 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7646 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7647 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7649 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7650 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7651 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7652 | |
| 7653 | if (iocb) |
| 7654 | lpfc_sli_update_ring(phba, pring); |
| 7655 | else |
| 7656 | lpfc_sli_update_full_ring(phba, pring); |
| 7657 | |
| 7658 | if (!piocb) |
| 7659 | return IOCB_SUCCESS; |
| 7660 | |
| 7661 | goto out_busy; |
| 7662 | |
| 7663 | iocb_busy: |
| 7664 | pring->stats.iocb_cmd_delay++; |
| 7665 | |
| 7666 | out_busy: |
| 7667 | |
| 7668 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7669 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7670 | return IOCB_SUCCESS; |
| 7671 | } |
| 7672 | |
| 7673 | return IOCB_BUSY; |
| 7674 | } |
| 7675 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7676 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7677 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7678 | * @phba: Pointer to HBA context object. |
| 7679 | * @piocb: Pointer to command iocb. |
| 7680 | * @sglq: Pointer to the scatter gather queue object. |
| 7681 | * |
| 7682 | * This routine converts the bpl or bde that is in the IOCB |
| 7683 | * to a sgl list for the sli4 hardware. The physical address |
| 7684 | * of the bpl/bde is converted back to a virtual address. |
| 7685 | * If the IOCB contains a BPL then the list of BDE's is |
| 7686 | * converted to sli4_sge's. If the IOCB contains a single |
| 7687 | * BDE then it is converted to a single sli_sge. |
| 7688 | * The IOCB is still in cpu endianess so the contents of |
| 7689 | * the bpl can be used without byte swapping. |
| 7690 | * |
| 7691 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7692 | **/ |
| 7693 | static uint16_t |
| 7694 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7695 | struct lpfc_sglq *sglq) |
| 7696 | { |
| 7697 | uint16_t xritag = NO_XRI; |
| 7698 | struct ulp_bde64 *bpl = NULL; |
| 7699 | struct ulp_bde64 bde; |
| 7700 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7701 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7702 | IOCB_t *icmd; |
| 7703 | int numBdes = 0; |
| 7704 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7705 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7706 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7707 | |
| 7708 | if (!piocbq || !sglq) |
| 7709 | return xritag; |
| 7710 | |
| 7711 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7712 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7713 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7714 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7715 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7716 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7717 | sizeof(struct ulp_bde64); |
| 7718 | /* The addrHigh and addrLow fields within the IOCB |
| 7719 | * have not been byteswapped yet so there is no |
| 7720 | * need to swap them back. |
| 7721 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7722 | if (piocbq->context3) |
| 7723 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7724 | else |
| 7725 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7726 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7727 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7728 | if (!bpl) |
| 7729 | return xritag; |
| 7730 | |
| 7731 | for (i = 0; i < numBdes; i++) { |
| 7732 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7733 | sgl->addr_hi = bpl->addrHigh; |
| 7734 | sgl->addr_lo = bpl->addrLow; |
| 7735 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7736 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7737 | if ((i+1) == numBdes) |
| 7738 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7739 | else |
| 7740 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7741 | /* swap the size field back to the cpu so we |
| 7742 | * can assign it to the sgl. |
| 7743 | */ |
| 7744 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7745 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7746 | /* The offsets in the sgl need to be accumulated |
| 7747 | * separately for the request and reply lists. |
| 7748 | * The request is always first, the reply follows. |
| 7749 | */ |
| 7750 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7751 | /* add up the reply sg entries */ |
| 7752 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7753 | inbound++; |
| 7754 | /* first inbound? reset the offset */ |
| 7755 | if (inbound == 1) |
| 7756 | offset = 0; |
| 7757 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7758 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7759 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7760 | offset += bde.tus.f.bdeSize; |
| 7761 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7762 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7763 | bpl++; |
| 7764 | sgl++; |
| 7765 | } |
| 7766 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7767 | /* The addrHigh and addrLow fields of the BDE have not |
| 7768 | * been byteswapped yet so they need to be swapped |
| 7769 | * before putting them in the sgl. |
| 7770 | */ |
| 7771 | sgl->addr_hi = |
| 7772 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7773 | sgl->addr_lo = |
| 7774 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7775 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7776 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7777 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7778 | sgl->sge_len = |
| 7779 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7780 | } |
| 7781 | return sglq->sli4_xritag; |
| 7782 | } |
| 7783 | |
| 7784 | /** |
| 7785 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7786 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7787 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7788 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7789 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7790 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7791 | * |
| 7792 | * Return: index into SLI4 fast-path FCP queue index. |
| 7793 | **/ |
| 7794 | static uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7795 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7796 | { |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7797 | ++phba->fcp_qidx; |
| 7798 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) |
| 7799 | phba->fcp_qidx = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7800 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7801 | return phba->fcp_qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7802 | } |
| 7803 | |
| 7804 | /** |
| 7805 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7806 | * @phba: Pointer to HBA context object. |
| 7807 | * @piocb: Pointer to command iocb. |
| 7808 | * @wqe: Pointer to the work queue entry. |
| 7809 | * |
| 7810 | * This routine converts the iocb command to its Work Queue Entry |
| 7811 | * equivalent. The wqe pointer should not have any fields set when |
| 7812 | * this routine is called because it will memcpy over them. |
| 7813 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7814 | * wqe. |
| 7815 | * |
| 7816 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7817 | **/ |
| 7818 | static int |
| 7819 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7820 | union lpfc_wqe *wqe) |
| 7821 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7822 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7823 | uint8_t ct = 0; |
| 7824 | uint32_t fip; |
| 7825 | uint32_t abort_tag; |
| 7826 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7827 | uint8_t cmnd; |
| 7828 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7829 | uint16_t abrt_iotag; |
| 7830 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7831 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7832 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7833 | int numBdes, i; |
| 7834 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7835 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7836 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7837 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7838 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7839 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7840 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7841 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7842 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7843 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7844 | command_type = ELS_COMMAND_FIP; |
| 7845 | else |
| 7846 | command_type = ELS_COMMAND_NON_FIP; |
| 7847 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7848 | /* Some of the fields are in the right position already */ |
| 7849 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7850 | abort_tag = (uint32_t) iocbq->iotag; |
| 7851 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7852 | 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] | 7853 | /* words0-2 bpl convert bde */ |
| 7854 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7855 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7856 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7857 | bpl = (struct ulp_bde64 *) |
| 7858 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7859 | if (!bpl) |
| 7860 | return IOCB_ERROR; |
| 7861 | |
| 7862 | /* Should already be byte swapped. */ |
| 7863 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7864 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7865 | /* swap the size field back to the cpu so we |
| 7866 | * can assign it to the sgl. |
| 7867 | */ |
| 7868 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7869 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7870 | total_len = 0; |
| 7871 | for (i = 0; i < numBdes; i++) { |
| 7872 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7873 | total_len += bde.tus.f.bdeSize; |
| 7874 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7875 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7876 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7877 | |
| 7878 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 7879 | cmnd = iocbq->iocb.ulpCommand; |
| 7880 | |
| 7881 | switch (iocbq->iocb.ulpCommand) { |
| 7882 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 7883 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 7884 | ndlp = iocbq->context_un.ndlp; |
| 7885 | else |
| 7886 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7887 | if (!iocbq->iocb.ulpLe) { |
| 7888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7889 | "2007 Only Limited Edition cmd Format" |
| 7890 | " supported 0x%x\n", |
| 7891 | iocbq->iocb.ulpCommand); |
| 7892 | return IOCB_ERROR; |
| 7893 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7894 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7895 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7896 | /* Els_reguest64 has a TMO */ |
| 7897 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 7898 | iocbq->iocb.ulpTimeout); |
| 7899 | /* Need a VF for word 4 set the vf bit*/ |
| 7900 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 7901 | /* And a VFID for word 12 */ |
| 7902 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7903 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7904 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7905 | iocbq->iocb.ulpContext); |
| 7906 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 7907 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7908 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7909 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7910 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 7911 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7912 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7913 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7914 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7915 | &phba->sli4_hba.sli_intf); |
| 7916 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7917 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 7918 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7919 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 7920 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7921 | *pcmd == ELS_CMD_PLOGI)) { |
| 7922 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7923 | bf_set(els_req64_sid, &wqe->els_req, |
| 7924 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7925 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 7926 | !(phba->fc_topology == |
| 7927 | LPFC_TOPOLOGY_LOOP)) |
| 7928 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7929 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7930 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 7931 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 7932 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7933 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 7934 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7935 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 7936 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7937 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7938 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 7939 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7940 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 7941 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 7942 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 7943 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 7944 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 7945 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7946 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7947 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7948 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 7949 | iocbq->iocb.un.ulpWord[3]); |
| 7950 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7951 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7952 | /* The entire sequence is transmitted for this IOCB */ |
| 7953 | xmit_len = total_len; |
| 7954 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7955 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 7956 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7957 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7958 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 7959 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7960 | /* word4 relative_offset memcpy */ |
| 7961 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7962 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 7963 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 7964 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 7965 | LPFC_WQE_IOD_WRITE); |
| 7966 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 7967 | LPFC_WQE_LENLOC_WORD12); |
| 7968 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7969 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 7970 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7971 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7972 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7973 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 7974 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7975 | /* word4 iocb=rsvd wqe=rsvd */ |
| 7976 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 7977 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7978 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7979 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7980 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 7981 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7982 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 7983 | LPFC_WQE_LENLOC_WORD3); |
| 7984 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7985 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7986 | case CMD_FCP_IWRITE64_CR: |
| 7987 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7988 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7989 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7990 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7991 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7992 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 7993 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 7994 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 7995 | iocbq->iocb.ulpFCP2Rcvy); |
| 7996 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 7997 | /* Always open the exchange */ |
| 7998 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7999 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8000 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8001 | LPFC_WQE_LENLOC_WORD4); |
| 8002 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8003 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8004 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 8005 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 8006 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 8007 | } |
| 8008 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8009 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8010 | case CMD_FCP_IREAD64_CR: |
| 8011 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8012 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8013 | wqe->fcp_iread.payload_offset_len = |
| 8014 | xmit_len + sizeof(struct fcp_rsp); |
| 8015 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8016 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8017 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8018 | iocbq->iocb.ulpFCP2Rcvy); |
| 8019 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8020 | /* Always open the exchange */ |
| 8021 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8022 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8023 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8024 | LPFC_WQE_LENLOC_WORD4); |
| 8025 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8026 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8027 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 8028 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 8029 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 8030 | } |
| 8031 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8032 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8033 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8034 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 8035 | wqe->fcp_icmd.rsrvd3 = 0; |
| 8036 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8037 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8038 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8039 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8040 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8041 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8042 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8043 | LPFC_WQE_LENLOC_NONE); |
| 8044 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
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 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8047 | /* For this command calculate the xmit length of the |
| 8048 | * request bde. |
| 8049 | */ |
| 8050 | xmit_len = 0; |
| 8051 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8052 | sizeof(struct ulp_bde64); |
| 8053 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8054 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8055 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8056 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8057 | xmit_len += bde.tus.f.bdeSize; |
| 8058 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8059 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8060 | wqe->gen_req.request_payload_len = xmit_len; |
| 8061 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8062 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8063 | /* word6 context tag copied in memcpy */ |
| 8064 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8065 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8066 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8067 | "2015 Invalid CT %x command 0x%x\n", |
| 8068 | ct, iocbq->iocb.ulpCommand); |
| 8069 | return IOCB_ERROR; |
| 8070 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8071 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8072 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8073 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8074 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8075 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8076 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8077 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8078 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8079 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8080 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8081 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8082 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8083 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8084 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8085 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8086 | /* word4 */ |
| 8087 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8088 | /* word5 iocb=rsvd wge=did */ |
| 8089 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8090 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8091 | |
| 8092 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8093 | &phba->sli4_hba.sli_intf); |
| 8094 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8095 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8096 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8097 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8098 | iocbq->vport->fc_myDID); |
| 8099 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8100 | bf_set(wqe_els_did, |
| 8101 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8102 | } |
| 8103 | } |
| 8104 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8105 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8106 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8107 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8108 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8109 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8110 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8111 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8112 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8113 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8114 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8115 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8116 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8117 | LPFC_WQE_LENLOC_WORD3); |
| 8118 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8119 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8120 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8121 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8122 | iocbq->context2)->virt); |
| 8123 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8124 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8125 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8126 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8127 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8128 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8129 | phba->vpi_ids[phba->pport->vpi]); |
| 8130 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8131 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8132 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8133 | case CMD_CLOSE_XRI_CN: |
| 8134 | case CMD_ABORT_XRI_CN: |
| 8135 | case CMD_ABORT_XRI_CX: |
| 8136 | /* words 0-2 memcpy should be 0 rserved */ |
| 8137 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8138 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8139 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8140 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8141 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8142 | } else |
| 8143 | fip = 0; |
| 8144 | |
| 8145 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8146 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8147 | * The link is down, or the command was ELS_FIP |
| 8148 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8149 | * on the wire. |
| 8150 | */ |
| 8151 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8152 | else |
| 8153 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8154 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8155 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8156 | wqe->abort_cmd.rsrvd5 = 0; |
| 8157 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8158 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8159 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8160 | /* |
| 8161 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8162 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8163 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8164 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8165 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8166 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8167 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8168 | cmnd = CMD_ABORT_XRI_CX; |
| 8169 | command_type = OTHER_COMMAND; |
| 8170 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8171 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8172 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8173 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8174 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8175 | * we re-construct this WQE here based on information in |
| 8176 | * iocbq from scratch. |
| 8177 | */ |
| 8178 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8179 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8180 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8181 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8182 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8183 | LPFC_ABTS_UNSOL_INT) { |
| 8184 | /* ABTS sent by initiator to CT exchange, the |
| 8185 | * RX_ID field will be filled with the newly |
| 8186 | * allocated responder XRI. |
| 8187 | */ |
| 8188 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8189 | iocbq->sli4_xritag); |
| 8190 | } else { |
| 8191 | /* ABTS sent by responder to CT exchange, the |
| 8192 | * RX_ID field will be filled with the responder |
| 8193 | * RX_ID from ABTS. |
| 8194 | */ |
| 8195 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8196 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8197 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8198 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8199 | 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] | 8200 | |
| 8201 | /* Use CT=VPI */ |
| 8202 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8203 | ndlp->nlp_DID); |
| 8204 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8205 | iocbq->iocb.ulpContext); |
| 8206 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8207 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8208 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8209 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8210 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8211 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8212 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8213 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8214 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8215 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8216 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8217 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8218 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8219 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8220 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8221 | } |
| 8222 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8223 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8224 | case CMD_XRI_ABORTED_CX: |
| 8225 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8226 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8227 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8228 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8229 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8230 | default: |
| 8231 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8232 | "2014 Invalid command 0x%x\n", |
| 8233 | iocbq->iocb.ulpCommand); |
| 8234 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8235 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8236 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8237 | |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8238 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8239 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8240 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8241 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8242 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8243 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8244 | 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] | 8245 | return 0; |
| 8246 | } |
| 8247 | |
| 8248 | /** |
| 8249 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8250 | * @phba: Pointer to HBA context object. |
| 8251 | * @ring_number: SLI ring number to issue iocb on. |
| 8252 | * @piocb: Pointer to command iocb. |
| 8253 | * @flag: Flag indicating if this command can be put into txq. |
| 8254 | * |
| 8255 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8256 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8257 | * |
| 8258 | * This function is called with hbalock held. The function will return success |
| 8259 | * after it successfully submit the iocb to firmware or after adding to the |
| 8260 | * txq. |
| 8261 | **/ |
| 8262 | static int |
| 8263 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8264 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8265 | { |
| 8266 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8267 | union lpfc_wqe wqe; |
| 8268 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8269 | |
| 8270 | if (piocb->sli4_xritag == NO_XRI) { |
| 8271 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8272 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8273 | sglq = NULL; |
| 8274 | else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8275 | if (pring->txq_cnt) { |
| 8276 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8277 | __lpfc_sli_ringtx_put(phba, |
| 8278 | pring, piocb); |
| 8279 | return IOCB_SUCCESS; |
| 8280 | } else { |
| 8281 | return IOCB_BUSY; |
| 8282 | } |
| 8283 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8284 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8285 | if (!sglq) { |
| 8286 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8287 | __lpfc_sli_ringtx_put(phba, |
| 8288 | pring, |
| 8289 | piocb); |
| 8290 | return IOCB_SUCCESS; |
| 8291 | } else |
| 8292 | return IOCB_BUSY; |
| 8293 | } |
| 8294 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8295 | } |
| 8296 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8297 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8298 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8299 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8300 | /* |
| 8301 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8302 | * sglq is on the active list |
| 8303 | */ |
| 8304 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); |
| 8305 | if (!sglq) |
| 8306 | return IOCB_ERROR; |
| 8307 | } |
| 8308 | |
| 8309 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8310 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8311 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8312 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8313 | return IOCB_ERROR; |
| 8314 | } |
| 8315 | |
| 8316 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8317 | return IOCB_ERROR; |
| 8318 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8319 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8320 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8321 | /* |
| 8322 | * For FCP command IOCB, get a new WQ index to distribute |
| 8323 | * WQE across the WQsr. On the other hand, for abort IOCB, |
| 8324 | * it carries the same WQ index to the original command |
| 8325 | * IOCB. |
| 8326 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8327 | if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8328 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8329 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8330 | return IOCB_ERROR; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8331 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8332 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8333 | return IOCB_ERROR; |
| 8334 | } else { |
| 8335 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8336 | return IOCB_ERROR; |
| 8337 | } |
| 8338 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8339 | |
| 8340 | return 0; |
| 8341 | } |
| 8342 | |
| 8343 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8344 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8345 | * |
| 8346 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8347 | * pointer from the lpfc_hba struct. |
| 8348 | * |
| 8349 | * Return codes: |
| 8350 | * IOCB_ERROR - Error |
| 8351 | * IOCB_SUCCESS - Success |
| 8352 | * IOCB_BUSY - Busy |
| 8353 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8354 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8355 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8356 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8357 | { |
| 8358 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8359 | } |
| 8360 | |
| 8361 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8362 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8363 | * @phba: The hba struct for which this call is being executed. |
| 8364 | * @dev_grp: The HBA PCI-Device group number. |
| 8365 | * |
| 8366 | * This routine sets up the SLI interface API function jump table in @phba |
| 8367 | * struct. |
| 8368 | * Returns: 0 - success, -ENODEV - failure. |
| 8369 | **/ |
| 8370 | int |
| 8371 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8372 | { |
| 8373 | |
| 8374 | switch (dev_grp) { |
| 8375 | case LPFC_PCI_DEV_LP: |
| 8376 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8377 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8378 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8379 | case LPFC_PCI_DEV_OC: |
| 8380 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8381 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8382 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8383 | default: |
| 8384 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8385 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8386 | dev_grp); |
| 8387 | return -ENODEV; |
| 8388 | break; |
| 8389 | } |
| 8390 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8391 | return 0; |
| 8392 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8393 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8395 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8396 | * @phba: Pointer to HBA context object. |
| 8397 | * @pring: Pointer to driver SLI ring object. |
| 8398 | * @piocb: Pointer to command iocb. |
| 8399 | * @flag: Flag indicating if this command can be put into txq. |
| 8400 | * |
| 8401 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8402 | * function. This function gets the hbalock and calls |
| 8403 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8404 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8405 | * functions which do not hold hbalock. |
| 8406 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8407 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8408 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8409 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8410 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8411 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8412 | unsigned long iflags; |
| 8413 | int rc; |
| 8414 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8415 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 8416 | pring = &phba->sli.ring[ring_number]; |
| 8417 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8418 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8419 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8420 | } else { |
| 8421 | /* For now, SLI2/3 will still use hbalock */ |
| 8422 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8423 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8424 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8425 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8426 | return rc; |
| 8427 | } |
| 8428 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8429 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8430 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8431 | * @phba: Pointer to HBA context object. |
| 8432 | * |
| 8433 | * This function is called while driver attaches with the |
| 8434 | * HBA to setup the extra ring. The extra ring is used |
| 8435 | * only when driver needs to support target mode functionality |
| 8436 | * or IP over FC functionalities. |
| 8437 | * |
| 8438 | * This function is called with no lock held. |
| 8439 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8440 | static int |
| 8441 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8442 | { |
| 8443 | struct lpfc_sli *psli; |
| 8444 | struct lpfc_sli_ring *pring; |
| 8445 | |
| 8446 | psli = &phba->sli; |
| 8447 | |
| 8448 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8449 | |
| 8450 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8451 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8452 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8453 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8454 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8455 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8456 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8457 | /* and give them to the extra ring */ |
| 8458 | pring = &psli->ring[psli->extra_ring]; |
| 8459 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8460 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8461 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8462 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8463 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8464 | |
| 8465 | /* Setup default profile for this ring */ |
| 8466 | pring->iotag_max = 4096; |
| 8467 | pring->num_mask = 1; |
| 8468 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8469 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8470 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8471 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8472 | return 0; |
| 8473 | } |
| 8474 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8475 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
| 8476 | * @vport: pointer to virtual port object. |
| 8477 | * @ndlp: nodelist pointer for the impacted rport. |
| 8478 | * |
| 8479 | * The driver calls this routine in response to a XRI ABORT CQE |
| 8480 | * event from the port. In this event, the driver is required to |
| 8481 | * recover its login to the rport even though its login may be valid |
| 8482 | * from the driver's perspective. The failed ABTS notice from the |
| 8483 | * port indicates the rport is not responding. |
| 8484 | */ |
| 8485 | static void |
| 8486 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8487 | struct lpfc_nodelist *ndlp) |
| 8488 | { |
| 8489 | struct Scsi_Host *shost; |
| 8490 | struct lpfc_hba *phba; |
| 8491 | unsigned long flags = 0; |
| 8492 | |
| 8493 | shost = lpfc_shost_from_vport(vport); |
| 8494 | phba = vport->phba; |
| 8495 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8496 | lpfc_printf_log(phba, KERN_INFO, |
| 8497 | LOG_SLI, "3093 No rport recovery needed. " |
| 8498 | "rport in state 0x%x\n", |
| 8499 | ndlp->nlp_state); |
| 8500 | return; |
| 8501 | } |
| 8502 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8503 | "3094 Start rport recovery on shost id 0x%x " |
| 8504 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8505 | "flags 0x%x\n", |
| 8506 | shost->host_no, ndlp->nlp_DID, |
| 8507 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8508 | ndlp->nlp_flag); |
| 8509 | /* |
| 8510 | * The rport is not responding. Don't attempt ADISC recovery. |
| 8511 | * Remove the FCP-2 flag to force a PLOGI. |
| 8512 | */ |
| 8513 | spin_lock_irqsave(shost->host_lock, flags); |
| 8514 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8515 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8516 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8517 | NLP_EVT_DEVICE_RECOVERY); |
| 8518 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 8519 | spin_lock_irqsave(shost->host_lock, flags); |
| 8520 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 8521 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8522 | lpfc_disc_start(vport); |
| 8523 | } |
| 8524 | |
| 8525 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8526 | * @phba: Pointer to HBA context object. |
| 8527 | * @iocbq: Pointer to iocb object. |
| 8528 | * |
| 8529 | * The async_event handler calls this routine when it receives |
| 8530 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8531 | * this event when an Abort Sequence request to an rport fails |
| 8532 | * twice in succession. The abort could be originated by the |
| 8533 | * driver or by the port. The ABTS could have been for an ELS |
| 8534 | * or FCP IO. The port only generates this event when an ABTS |
| 8535 | * fails to complete after one retry. |
| 8536 | */ |
| 8537 | static void |
| 8538 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8539 | struct lpfc_iocbq *iocbq) |
| 8540 | { |
| 8541 | struct lpfc_nodelist *ndlp = NULL; |
| 8542 | uint16_t rpi = 0, vpi = 0; |
| 8543 | struct lpfc_vport *vport = NULL; |
| 8544 | |
| 8545 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8546 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8547 | rpi = iocbq->iocb.ulpContext; |
| 8548 | |
| 8549 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8550 | "3092 Port generated ABTS async event " |
| 8551 | "on vpi %d rpi %d status 0x%x\n", |
| 8552 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8553 | |
| 8554 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8555 | if (!vport) |
| 8556 | goto err_exit; |
| 8557 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8558 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8559 | goto err_exit; |
| 8560 | |
| 8561 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8562 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8563 | return; |
| 8564 | |
| 8565 | err_exit: |
| 8566 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8567 | "3095 Event Context not found, no " |
| 8568 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8569 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8570 | vpi, rpi); |
| 8571 | } |
| 8572 | |
| 8573 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8574 | * @phba: pointer to HBA context object. |
| 8575 | * @ndlp: nodelist pointer for the impacted rport. |
| 8576 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8577 | * |
| 8578 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8579 | * port. The port generates this event when an abort exchange request to an |
| 8580 | * rport fails twice in succession with no reply. The abort could be originated |
| 8581 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8582 | */ |
| 8583 | void |
| 8584 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8585 | struct lpfc_nodelist *ndlp, |
| 8586 | struct sli4_wcqe_xri_aborted *axri) |
| 8587 | { |
| 8588 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8589 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8590 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8591 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8592 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8593 | "3115 Node Context not found, driver " |
| 8594 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8595 | return; |
| 8596 | } |
| 8597 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8598 | vport = ndlp->vport; |
| 8599 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8600 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8601 | "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] | 8602 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8603 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8604 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8605 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8606 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8607 | /* |
| 8608 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8609 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8610 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8611 | */ |
| 8612 | ext_status = axri->parameter & WCQE_PARAM_MASK; |
| 8613 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8614 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8615 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8616 | } |
| 8617 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8618 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8619 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8620 | * @phba: Pointer to HBA context object. |
| 8621 | * @pring: Pointer to driver SLI ring object. |
| 8622 | * @iocbq: Pointer to iocb object. |
| 8623 | * |
| 8624 | * This function is called by the slow ring event handler |
| 8625 | * function when there is an ASYNC event iocb in the ring. |
| 8626 | * This function is called with no lock held. |
| 8627 | * Currently this function handles only temperature related |
| 8628 | * ASYNC events. The function decodes the temperature sensor |
| 8629 | * event message and posts events for the management applications. |
| 8630 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8631 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8632 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8633 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8634 | { |
| 8635 | IOCB_t *icmd; |
| 8636 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8637 | struct temp_event temp_event_data; |
| 8638 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8639 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8640 | |
| 8641 | icmd = &iocbq->iocb; |
| 8642 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8643 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8644 | switch (evt_code) { |
| 8645 | case ASYNC_TEMP_WARN: |
| 8646 | case ASYNC_TEMP_SAFE: |
| 8647 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8648 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8649 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8650 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8651 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8652 | "0347 Adapter is very hot, please take " |
| 8653 | "corrective action. temperature : %d Celsius\n", |
| 8654 | (uint32_t) icmd->ulpContext); |
| 8655 | } else { |
| 8656 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8657 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8658 | "0340 Adapter temperature is OK now. " |
| 8659 | "temperature : %d Celsius\n", |
| 8660 | (uint32_t) icmd->ulpContext); |
| 8661 | } |
| 8662 | |
| 8663 | /* Send temperature change event to applications */ |
| 8664 | shost = lpfc_shost_from_vport(phba->pport); |
| 8665 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8666 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8667 | LPFC_NL_VENDOR_ID); |
| 8668 | break; |
| 8669 | case ASYNC_STATUS_CN: |
| 8670 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8671 | break; |
| 8672 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8673 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8674 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8675 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8676 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8677 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8678 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8679 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8680 | "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] | 8681 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8682 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8683 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8684 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8685 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8686 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8687 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8688 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8689 | } |
| 8690 | |
| 8691 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8692 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8693 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8694 | * @phba: Pointer to HBA context object. |
| 8695 | * |
| 8696 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8697 | * number of iocbs per ring and iotags. This function is |
| 8698 | * called while driver attach to the HBA and before the |
| 8699 | * interrupts are enabled. So there is no need for locking. |
| 8700 | * |
| 8701 | * This function always returns 0. |
| 8702 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8703 | int |
| 8704 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8705 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8706 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8707 | struct lpfc_sli *psli = &phba->sli; |
| 8708 | struct lpfc_sli_ring *pring; |
| 8709 | |
| 8710 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 8711 | psli->sli_flag = 0; |
| 8712 | psli->fcp_ring = LPFC_FCP_RING; |
| 8713 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8714 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8715 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8716 | psli->iocbq_lookup = NULL; |
| 8717 | psli->iocbq_lookup_len = 0; |
| 8718 | psli->last_iotag = 0; |
| 8719 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8720 | for (i = 0; i < psli->num_rings; i++) { |
| 8721 | pring = &psli->ring[i]; |
| 8722 | switch (i) { |
| 8723 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8724 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8725 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8726 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8727 | pring->sli.sli3.numCiocb += |
| 8728 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8729 | pring->sli.sli3.numRiocb += |
| 8730 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8731 | pring->sli.sli3.numCiocb += |
| 8732 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8733 | pring->sli.sli3.numRiocb += |
| 8734 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8735 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8736 | SLI3_IOCB_CMD_SIZE : |
| 8737 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8738 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8739 | SLI3_IOCB_RSP_SIZE : |
| 8740 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8741 | pring->iotag_ctr = 0; |
| 8742 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8743 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8744 | pring->fast_iotag = pring->iotag_max; |
| 8745 | pring->num_mask = 0; |
| 8746 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8747 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8748 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8749 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8750 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 8751 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8752 | SLI3_IOCB_CMD_SIZE : |
| 8753 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8754 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8755 | SLI3_IOCB_RSP_SIZE : |
| 8756 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8757 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8758 | pring->num_mask = 0; |
| 8759 | break; |
| 8760 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8761 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8762 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8763 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 8764 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8765 | SLI3_IOCB_CMD_SIZE : |
| 8766 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8767 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8768 | SLI3_IOCB_RSP_SIZE : |
| 8769 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8770 | pring->fast_iotag = 0; |
| 8771 | pring->iotag_ctr = 0; |
| 8772 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8773 | pring->lpfc_sli_rcv_async_status = |
| 8774 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8775 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8776 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8777 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8778 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8779 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8780 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8781 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8782 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8783 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8784 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8785 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8786 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8787 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8788 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8789 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8790 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8791 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8792 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8793 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8794 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8795 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8796 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8797 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8798 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8799 | lpfc_ct_unsol_event; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8800 | /* abort unsolicited sequence */ |
| 8801 | pring->prt[4].profile = 0; /* Mask 4 */ |
| 8802 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; |
| 8803 | pring->prt[4].type = FC_TYPE_BLS; |
| 8804 | pring->prt[4].lpfc_sli_rcv_unsol_event = |
| 8805 | lpfc_sli4_ct_abort_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8806 | break; |
| 8807 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8808 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 8809 | pring->sli.sli3.sizeCiocb) + |
| 8810 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8811 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8812 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8813 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8814 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8815 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8816 | phba->brd_no, totiocbsize, |
| 8817 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8818 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8819 | if (phba->cfg_multi_ring_support == 2) |
| 8820 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8821 | |
| 8822 | return 0; |
| 8823 | } |
| 8824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8826 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8827 | * @phba: Pointer to HBA context object. |
| 8828 | * |
| 8829 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8830 | * ring. This function also initializes ring indices of each ring. |
| 8831 | * This function is called during the initialization of the SLI |
| 8832 | * interface of an HBA. |
| 8833 | * This function is called with no lock held and always returns |
| 8834 | * 1. |
| 8835 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8836 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8837 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8838 | { |
| 8839 | struct lpfc_sli *psli; |
| 8840 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8841 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8842 | |
| 8843 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8844 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8845 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8846 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8847 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8848 | for (i = 0; i < psli->num_rings; i++) { |
| 8849 | pring = &psli->ring[i]; |
| 8850 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8851 | pring->sli.sli3.next_cmdidx = 0; |
| 8852 | pring->sli.sli3.local_getidx = 0; |
| 8853 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8854 | INIT_LIST_HEAD(&pring->txq); |
| 8855 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8856 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8857 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8858 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 8859 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8860 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8861 | spin_unlock_irq(&phba->hbalock); |
| 8862 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8863 | } |
| 8864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8865 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8866 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8867 | * @phba: Pointer to HBA context object. |
| 8868 | * |
| 8869 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8870 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8871 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8872 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8873 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8874 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8875 | * pending mailbox command queue from the various clients must be stopped; |
| 8876 | * either the HBA is in a state that it will never works on the outstanding |
| 8877 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8878 | * mailbox command has been completed. |
| 8879 | **/ |
| 8880 | static void |
| 8881 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8882 | { |
| 8883 | LIST_HEAD(completions); |
| 8884 | struct lpfc_sli *psli = &phba->sli; |
| 8885 | LPFC_MBOXQ_t *pmb; |
| 8886 | unsigned long iflag; |
| 8887 | |
| 8888 | /* Flush all the mailbox commands in the mbox system */ |
| 8889 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8890 | /* The pending mailbox command queue */ |
| 8891 | list_splice_init(&phba->sli.mboxq, &completions); |
| 8892 | /* The outstanding active mailbox command */ |
| 8893 | if (psli->mbox_active) { |
| 8894 | list_add_tail(&psli->mbox_active->list, &completions); |
| 8895 | psli->mbox_active = NULL; |
| 8896 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8897 | } |
| 8898 | /* The completed mailbox command queue */ |
| 8899 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 8900 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8901 | |
| 8902 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 8903 | while (!list_empty(&completions)) { |
| 8904 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 8905 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8906 | if (pmb->mbox_cmpl) |
| 8907 | pmb->mbox_cmpl(phba, pmb); |
| 8908 | } |
| 8909 | } |
| 8910 | |
| 8911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8912 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8913 | * @vport: Pointer to virtual port object. |
| 8914 | * |
| 8915 | * lpfc_sli_host_down is called to clean up the resources |
| 8916 | * associated with a vport before destroying virtual |
| 8917 | * port data structures. |
| 8918 | * This function does following operations: |
| 8919 | * - Free discovery resources associated with this virtual |
| 8920 | * port. |
| 8921 | * - Free iocbs associated with this virtual port in |
| 8922 | * the txq. |
| 8923 | * - Send abort for all iocb commands associated with this |
| 8924 | * vport in txcmplq. |
| 8925 | * |
| 8926 | * This function is called with no lock held and always returns 1. |
| 8927 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8928 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8929 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 8930 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8931 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8932 | struct lpfc_hba *phba = vport->phba; |
| 8933 | struct lpfc_sli *psli = &phba->sli; |
| 8934 | struct lpfc_sli_ring *pring; |
| 8935 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8936 | int i; |
| 8937 | unsigned long flags = 0; |
| 8938 | uint16_t prev_pring_flag; |
| 8939 | |
| 8940 | lpfc_cleanup_discovery_resources(vport); |
| 8941 | |
| 8942 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8943 | for (i = 0; i < psli->num_rings; i++) { |
| 8944 | pring = &psli->ring[i]; |
| 8945 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8946 | /* Only slow rings */ |
| 8947 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8948 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8949 | /* Set the lpfc data pending flag */ |
| 8950 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8951 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8952 | /* |
| 8953 | * Error everything on the txq since these iocbs have not been |
| 8954 | * given to the FW yet. |
| 8955 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8956 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 8957 | if (iocb->vport != vport) |
| 8958 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8959 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8960 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8961 | } |
| 8962 | |
| 8963 | /* Next issue ABTS for everything on the txcmplq */ |
| 8964 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 8965 | list) { |
| 8966 | if (iocb->vport != vport) |
| 8967 | continue; |
| 8968 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 8969 | } |
| 8970 | |
| 8971 | pring->flag = prev_pring_flag; |
| 8972 | } |
| 8973 | |
| 8974 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 8975 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8976 | /* Cancel all the IOCBs from the completions list */ |
| 8977 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8978 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8979 | return 1; |
| 8980 | } |
| 8981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8983 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8984 | * @phba: Pointer to HBA context object. |
| 8985 | * |
| 8986 | * This function cleans up all iocb, buffers, mailbox commands |
| 8987 | * while shutting down the HBA. This function is called with no |
| 8988 | * lock held and always returns 1. |
| 8989 | * This function does the following to cleanup driver resources: |
| 8990 | * - Free discovery resources for each virtual port |
| 8991 | * - Cleanup any pending fabric iocbs |
| 8992 | * - Iterate through the iocb txq and free each entry |
| 8993 | * in the list. |
| 8994 | * - Free up any buffer posted to the HBA |
| 8995 | * - Free mailbox commands in the mailbox queue. |
| 8996 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8997 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8998 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8999 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9000 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9001 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9002 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9003 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9004 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9005 | int i; |
| 9006 | |
| 9007 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9008 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9010 | lpfc_hba_down_prep(phba); |
| 9011 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9012 | lpfc_fabric_abort_hba(phba); |
| 9013 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9014 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9015 | for (i = 0; i < psli->num_rings; i++) { |
| 9016 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9017 | /* Only slow rings */ |
| 9018 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9019 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9020 | /* Set the lpfc data pending flag */ |
| 9021 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9022 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9023 | |
| 9024 | /* |
| 9025 | * Error everything on the txq since these iocbs have not been |
| 9026 | * given to the FW yet. |
| 9027 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9028 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9029 | pring->txq_cnt = 0; |
| 9030 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9031 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9032 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9033 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9034 | /* Cancel all the IOCBs from the completions list */ |
| 9035 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9036 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9037 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9038 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9039 | list_splice_init(&phba->elsbuf, &completions); |
| 9040 | phba->elsbuf_cnt = 0; |
| 9041 | phba->elsbuf_prev_cnt = 0; |
| 9042 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9043 | |
| 9044 | while (!list_empty(&completions)) { |
| 9045 | list_remove_head(&completions, buf_ptr, |
| 9046 | struct lpfc_dmabuf, list); |
| 9047 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9048 | kfree(buf_ptr); |
| 9049 | } |
| 9050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9051 | /* Return any active mbox cmds */ |
| 9052 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9053 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9054 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9055 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9056 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9057 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9058 | return 1; |
| 9059 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9060 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9061 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9062 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9063 | * @srcp: Source memory pointer. |
| 9064 | * @destp: Destination memory pointer. |
| 9065 | * @cnt: Number of words required to be copied. |
| 9066 | * |
| 9067 | * This function is used for copying data between driver memory |
| 9068 | * and the SLI memory. This function also changes the endianness |
| 9069 | * of each word if native endianness is different from SLI |
| 9070 | * endianness. This function can be called with or without |
| 9071 | * lock. |
| 9072 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9073 | void |
| 9074 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9075 | { |
| 9076 | uint32_t *src = srcp; |
| 9077 | uint32_t *dest = destp; |
| 9078 | uint32_t ldata; |
| 9079 | int i; |
| 9080 | |
| 9081 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9082 | ldata = *src; |
| 9083 | ldata = le32_to_cpu(ldata); |
| 9084 | *dest = ldata; |
| 9085 | src++; |
| 9086 | dest++; |
| 9087 | } |
| 9088 | } |
| 9089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9090 | |
| 9091 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9092 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9093 | * @srcp: Source memory pointer. |
| 9094 | * @destp: Destination memory pointer. |
| 9095 | * @cnt: Number of words required to be copied. |
| 9096 | * |
| 9097 | * This function is used for copying data between a data structure |
| 9098 | * with big endian representation to local endianness. |
| 9099 | * This function can be called with or without lock. |
| 9100 | **/ |
| 9101 | void |
| 9102 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9103 | { |
| 9104 | uint32_t *src = srcp; |
| 9105 | uint32_t *dest = destp; |
| 9106 | uint32_t ldata; |
| 9107 | int i; |
| 9108 | |
| 9109 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9110 | ldata = *src; |
| 9111 | ldata = be32_to_cpu(ldata); |
| 9112 | *dest = ldata; |
| 9113 | src++; |
| 9114 | dest++; |
| 9115 | } |
| 9116 | } |
| 9117 | |
| 9118 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9119 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9120 | * @phba: Pointer to HBA context object. |
| 9121 | * @pring: Pointer to driver SLI ring object. |
| 9122 | * @mp: Pointer to driver buffer object. |
| 9123 | * |
| 9124 | * This function is called with no lock held. |
| 9125 | * It always return zero after adding the buffer to the postbufq |
| 9126 | * buffer list. |
| 9127 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9128 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9129 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9130 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9131 | { |
| 9132 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9133 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9134 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9135 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9136 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9137 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9138 | return 0; |
| 9139 | } |
| 9140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9141 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9142 | * 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] | 9143 | * @phba: Pointer to HBA context object. |
| 9144 | * |
| 9145 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9146 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9147 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9148 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9149 | * The function returns the allocated tag. The function is called with |
| 9150 | * no locks held. |
| 9151 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9152 | uint32_t |
| 9153 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9154 | { |
| 9155 | spin_lock_irq(&phba->hbalock); |
| 9156 | phba->buffer_tag_count++; |
| 9157 | /* |
| 9158 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9159 | * a tag assigned by HBQ. |
| 9160 | */ |
| 9161 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9162 | spin_unlock_irq(&phba->hbalock); |
| 9163 | return phba->buffer_tag_count; |
| 9164 | } |
| 9165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9167 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9168 | * @phba: Pointer to HBA context object. |
| 9169 | * @pring: Pointer to driver SLI ring object. |
| 9170 | * @tag: Buffer tag. |
| 9171 | * |
| 9172 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9173 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9174 | * iocb is posted to the response ring with the tag of the buffer. |
| 9175 | * This function searches the pring->postbufq list using the tag |
| 9176 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9177 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9178 | * buffer is returned to the caller else NULL is returned. |
| 9179 | * This function is called with no lock held. |
| 9180 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9181 | struct lpfc_dmabuf * |
| 9182 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9183 | uint32_t tag) |
| 9184 | { |
| 9185 | struct lpfc_dmabuf *mp, *next_mp; |
| 9186 | struct list_head *slp = &pring->postbufq; |
| 9187 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9188 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9189 | spin_lock_irq(&phba->hbalock); |
| 9190 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9191 | if (mp->buffer_tag == tag) { |
| 9192 | list_del_init(&mp->list); |
| 9193 | pring->postbufq_cnt--; |
| 9194 | spin_unlock_irq(&phba->hbalock); |
| 9195 | return mp; |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | spin_unlock_irq(&phba->hbalock); |
| 9200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9201 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9202 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9203 | pring->ringno, (unsigned long) tag, |
| 9204 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9205 | |
| 9206 | return NULL; |
| 9207 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9208 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9209 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9210 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9211 | * @phba: Pointer to HBA context object. |
| 9212 | * @pring: Pointer to driver SLI ring object. |
| 9213 | * @phys: DMA address of the buffer. |
| 9214 | * |
| 9215 | * This function searches the buffer list using the dma_address |
| 9216 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9217 | * corresponding to the dma_address. The function returns the |
| 9218 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9219 | * This function is called by the ct and els unsolicited event |
| 9220 | * handlers to get the buffer associated with the unsolicited |
| 9221 | * event. |
| 9222 | * |
| 9223 | * This function is called with no lock held. |
| 9224 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9225 | struct lpfc_dmabuf * |
| 9226 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9227 | dma_addr_t phys) |
| 9228 | { |
| 9229 | struct lpfc_dmabuf *mp, *next_mp; |
| 9230 | struct list_head *slp = &pring->postbufq; |
| 9231 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9232 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9233 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9234 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9235 | if (mp->phys == phys) { |
| 9236 | list_del_init(&mp->list); |
| 9237 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9238 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9239 | return mp; |
| 9240 | } |
| 9241 | } |
| 9242 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9243 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9245 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9246 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9247 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9248 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9249 | return NULL; |
| 9250 | } |
| 9251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9253 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9254 | * @phba: Pointer to HBA context object. |
| 9255 | * @cmdiocb: Pointer to driver command iocb object. |
| 9256 | * @rspiocb: Pointer to driver response iocb object. |
| 9257 | * |
| 9258 | * This function is the completion handler for the abort iocbs for |
| 9259 | * ELS commands. This function is called from the ELS ring event |
| 9260 | * handler with no lock held. This function frees memory resources |
| 9261 | * associated with the abort iocb. |
| 9262 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9263 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9264 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9265 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9266 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9267 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9268 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9269 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9270 | |
| 9271 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9272 | |
| 9273 | /* |
| 9274 | * Assume that the port already completed and returned, or |
| 9275 | * will return the iocb. Just Log the message. |
| 9276 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9277 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9278 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9279 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9280 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9281 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9282 | if (abort_iotag != 0 && |
| 9283 | abort_iotag <= phba->sli.last_iotag) |
| 9284 | abort_iocb = |
| 9285 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9286 | } else |
| 9287 | /* For sli4 the abort_tag is the XRI, |
| 9288 | * so the abort routine puts the iotag of the iocb |
| 9289 | * being aborted in the context field of the abort |
| 9290 | * IOCB. |
| 9291 | */ |
| 9292 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9293 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9294 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9295 | "0327 Cannot abort els iocb %p " |
| 9296 | "with tag %x context %x, abort status %x, " |
| 9297 | "abort code %x\n", |
| 9298 | abort_iocb, abort_iotag, abort_context, |
| 9299 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9300 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9301 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9302 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9303 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9304 | return; |
| 9305 | } |
| 9306 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9307 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9308 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9309 | * @phba: Pointer to HBA context object. |
| 9310 | * @cmdiocb: Pointer to driver command iocb object. |
| 9311 | * @rspiocb: Pointer to driver response iocb object. |
| 9312 | * |
| 9313 | * The function is called from SLI ring event handler with no |
| 9314 | * lock held. This function is the completion handler for ELS commands |
| 9315 | * which are aborted. The function frees memory resources used for |
| 9316 | * the aborted ELS commands. |
| 9317 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9318 | static void |
| 9319 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9320 | struct lpfc_iocbq *rspiocb) |
| 9321 | { |
| 9322 | IOCB_t *irsp = &rspiocb->iocb; |
| 9323 | |
| 9324 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9325 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9326 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9327 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9328 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9329 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9330 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9331 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9332 | else |
| 9333 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9334 | return; |
| 9335 | } |
| 9336 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9337 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9338 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9339 | * @phba: Pointer to HBA context object. |
| 9340 | * @pring: Pointer to driver SLI ring object. |
| 9341 | * @cmdiocb: Pointer to driver command iocb object. |
| 9342 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9343 | * This function issues an abort iocb for the provided command iocb down to |
| 9344 | * the port. Other than the case the outstanding command iocb is an abort |
| 9345 | * request, this function issues abort out unconditionally. This function is |
| 9346 | * called with hbalock held. The function returns 0 when it fails due to |
| 9347 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9348 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9349 | static int |
| 9350 | 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] | 9351 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9352 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9353 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9354 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9355 | IOCB_t *icmd = NULL; |
| 9356 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9357 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 9358 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9360 | /* |
| 9361 | * There are certain command types we don't want to abort. And we |
| 9362 | * don't want to abort commands that are already in the process of |
| 9363 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9364 | */ |
| 9365 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9366 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9367 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9368 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9369 | return 0; |
| 9370 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9371 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9372 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9373 | if (abtsiocbp == NULL) |
| 9374 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9375 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9376 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9377 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9378 | */ |
| 9379 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9381 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9382 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9383 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9384 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9385 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9386 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9387 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9388 | else |
| 9389 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9390 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9391 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9392 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9393 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9394 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9395 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9396 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9397 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9398 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9399 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9400 | else |
| 9401 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9402 | |
| 9403 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9404 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9405 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9406 | "0339 Abort xri x%x, original iotag x%x, " |
| 9407 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9408 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9409 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9410 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 9411 | |
| 9412 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9413 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9414 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9415 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9416 | abtsiocbp, 0); |
| 9417 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9418 | } else { |
| 9419 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9420 | abtsiocbp, 0); |
| 9421 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9422 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9423 | if (retval) |
| 9424 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9425 | |
| 9426 | /* |
| 9427 | * Caller to this routine should check for IOCB_ERROR |
| 9428 | * and handle it properly. This routine no longer removes |
| 9429 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9430 | */ |
| 9431 | return retval; |
| 9432 | } |
| 9433 | |
| 9434 | /** |
| 9435 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9436 | * @phba: Pointer to HBA context object. |
| 9437 | * @pring: Pointer to driver SLI ring object. |
| 9438 | * @cmdiocb: Pointer to driver command iocb object. |
| 9439 | * |
| 9440 | * This function issues an abort iocb for the provided command iocb. In case |
| 9441 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9442 | * ring. Instead, the callback function shall be changed to those commands |
| 9443 | * so that nothing happens when them finishes. This function is called with |
| 9444 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9445 | * request. |
| 9446 | **/ |
| 9447 | int |
| 9448 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9449 | struct lpfc_iocbq *cmdiocb) |
| 9450 | { |
| 9451 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9452 | int retval = IOCB_ERROR; |
| 9453 | IOCB_t *icmd = NULL; |
| 9454 | |
| 9455 | /* |
| 9456 | * There are certain command types we don't want to abort. And we |
| 9457 | * don't want to abort commands that are already in the process of |
| 9458 | * being aborted. |
| 9459 | */ |
| 9460 | icmd = &cmdiocb->iocb; |
| 9461 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9462 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9463 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9464 | return 0; |
| 9465 | |
| 9466 | /* |
| 9467 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9468 | * the callback so that nothing happens when it finishes. |
| 9469 | */ |
| 9470 | if ((vport->load_flag & FC_UNLOADING) && |
| 9471 | (pring->ringno == LPFC_ELS_RING)) { |
| 9472 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9473 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9474 | else |
| 9475 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9476 | goto abort_iotag_exit; |
| 9477 | } |
| 9478 | |
| 9479 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9480 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9481 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9482 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9483 | /* |
| 9484 | * Caller to this routine should check for IOCB_ERROR |
| 9485 | * and handle it properly. This routine no longer removes |
| 9486 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9487 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9488 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9489 | } |
| 9490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9491 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9492 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9493 | * @phba: Pointer to HBA context object. |
| 9494 | * @pring: Pointer to driver SLI ring object. |
| 9495 | * |
| 9496 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9497 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9498 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9499 | * to complete before the return of this function. The caller is not required |
| 9500 | * to hold any locks. |
| 9501 | **/ |
| 9502 | static void |
| 9503 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9504 | { |
| 9505 | LIST_HEAD(completions); |
| 9506 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9507 | |
| 9508 | if (pring->ringno == LPFC_ELS_RING) |
| 9509 | lpfc_fabric_abort_hba(phba); |
| 9510 | |
| 9511 | spin_lock_irq(&phba->hbalock); |
| 9512 | |
| 9513 | /* Take off all the iocbs on txq for cancelling */ |
| 9514 | list_splice_init(&pring->txq, &completions); |
| 9515 | pring->txq_cnt = 0; |
| 9516 | |
| 9517 | /* Next issue ABTS for everything on the txcmplq */ |
| 9518 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9519 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9520 | |
| 9521 | spin_unlock_irq(&phba->hbalock); |
| 9522 | |
| 9523 | /* Cancel all the IOCBs from the completions list */ |
| 9524 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9525 | IOERR_SLI_ABORTED); |
| 9526 | } |
| 9527 | |
| 9528 | /** |
| 9529 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9530 | * @phba: pointer to lpfc HBA data structure. |
| 9531 | * |
| 9532 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9533 | **/ |
| 9534 | void |
| 9535 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9536 | { |
| 9537 | struct lpfc_sli *psli = &phba->sli; |
| 9538 | struct lpfc_sli_ring *pring; |
| 9539 | int i; |
| 9540 | |
| 9541 | for (i = 0; i < psli->num_rings; i++) { |
| 9542 | pring = &psli->ring[i]; |
| 9543 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9544 | } |
| 9545 | } |
| 9546 | |
| 9547 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9548 | * 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] | 9549 | * @iocbq: Pointer to driver iocb object. |
| 9550 | * @vport: Pointer to driver virtual port object. |
| 9551 | * @tgt_id: SCSI ID of the target. |
| 9552 | * @lun_id: LUN ID of the scsi device. |
| 9553 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9554 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9555 | * 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] | 9556 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9557 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9558 | * 1 if the filtering criteria is not met. |
| 9559 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9560 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9561 | * lun_id parameter. |
| 9562 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9563 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9564 | * parameters. |
| 9565 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9566 | * given iocb is for the SCSI host associated with the given vport. |
| 9567 | * This function is called with no locks held. |
| 9568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9569 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9570 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9571 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9572 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9573 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9574 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9575 | int rc = 1; |
| 9576 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9577 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9578 | return rc; |
| 9579 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9580 | if (iocbq->vport != vport) |
| 9581 | return rc; |
| 9582 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9583 | 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] | 9584 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9585 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9586 | return rc; |
| 9587 | |
| 9588 | switch (ctx_cmd) { |
| 9589 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9590 | if ((lpfc_cmd->rdata->pnode) && |
| 9591 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9592 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9593 | rc = 0; |
| 9594 | break; |
| 9595 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9596 | if ((lpfc_cmd->rdata->pnode) && |
| 9597 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9598 | rc = 0; |
| 9599 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9600 | case LPFC_CTX_HOST: |
| 9601 | rc = 0; |
| 9602 | break; |
| 9603 | default: |
| 9604 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9605 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9606 | break; |
| 9607 | } |
| 9608 | |
| 9609 | return rc; |
| 9610 | } |
| 9611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9613 | * 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] | 9614 | * @vport: Pointer to virtual port. |
| 9615 | * @tgt_id: SCSI ID of the target. |
| 9616 | * @lun_id: LUN ID of the scsi device. |
| 9617 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9618 | * |
| 9619 | * This function returns number of FCP commands pending for the vport. |
| 9620 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9621 | * commands pending on the vport associated with SCSI device specified |
| 9622 | * by tgt_id and lun_id parameters. |
| 9623 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9624 | * commands pending on the vport associated with SCSI target specified |
| 9625 | * by tgt_id parameter. |
| 9626 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9627 | * commands pending on the vport. |
| 9628 | * This function returns the number of iocbs which satisfy the filter. |
| 9629 | * This function is called without any lock held. |
| 9630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9631 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9632 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9633 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9634 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9635 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9636 | struct lpfc_iocbq *iocbq; |
| 9637 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9638 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9639 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9640 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9641 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9642 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9643 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9644 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9645 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9646 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9647 | return sum; |
| 9648 | } |
| 9649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9651 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9652 | * @phba: Pointer to HBA context object |
| 9653 | * @cmdiocb: Pointer to command iocb object. |
| 9654 | * @rspiocb: Pointer to response iocb object. |
| 9655 | * |
| 9656 | * This function is called when an aborted FCP iocb completes. This |
| 9657 | * function is called by the ring event handler with no lock held. |
| 9658 | * This function frees the iocb. |
| 9659 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9660 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9661 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9662 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9663 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9664 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9665 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9666 | "original iotag x%x, abort cmd iotag x%x " |
| 9667 | "status 0x%x, reason 0x%x\n", |
| 9668 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9669 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9670 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9671 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9672 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9673 | return; |
| 9674 | } |
| 9675 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9676 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9677 | * 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] | 9678 | * @vport: Pointer to virtual port. |
| 9679 | * @pring: Pointer to driver SLI ring object. |
| 9680 | * @tgt_id: SCSI ID of the target. |
| 9681 | * @lun_id: LUN ID of the scsi device. |
| 9682 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9683 | * |
| 9684 | * This function sends an abort command for every SCSI command |
| 9685 | * associated with the given virtual port pending on the ring |
| 9686 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9687 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9688 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9689 | * parameters |
| 9690 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9691 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9692 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9693 | * FCP iocbs associated with virtual port. |
| 9694 | * This function returns number of iocbs it failed to abort. |
| 9695 | * This function is called with no locks held. |
| 9696 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9697 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9698 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9699 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9700 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9701 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9702 | struct lpfc_iocbq *iocbq; |
| 9703 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9704 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9705 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9706 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9707 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9708 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9709 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9710 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9711 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9712 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9713 | continue; |
| 9714 | |
| 9715 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9716 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9717 | if (abtsiocb == NULL) { |
| 9718 | errcnt++; |
| 9719 | continue; |
| 9720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9721 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9722 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9723 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9724 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9725 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9726 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9727 | else |
| 9728 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9729 | abtsiocb->iocb.ulpLe = 1; |
| 9730 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9731 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9732 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9733 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9734 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9735 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9736 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9738 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9739 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9740 | else |
| 9741 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9742 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9743 | /* Setup callback routine and issue the command. */ |
| 9744 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9745 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9746 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9747 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9748 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9749 | errcnt++; |
| 9750 | continue; |
| 9751 | } |
| 9752 | } |
| 9753 | |
| 9754 | return errcnt; |
| 9755 | } |
| 9756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9757 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9758 | * 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] | 9759 | * @phba: Pointer to HBA context object. |
| 9760 | * @cmdiocbq: Pointer to command iocb. |
| 9761 | * @rspiocbq: Pointer to response iocb. |
| 9762 | * |
| 9763 | * This function is the completion handler for iocbs issued using |
| 9764 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9765 | * ring event handler function without any lock held. This function |
| 9766 | * can be called from both worker thread context and interrupt |
| 9767 | * context. This function also can be called from other thread which |
| 9768 | * cleans up the SLI layer objects. |
| 9769 | * This function copy the contents of the response iocb to the |
| 9770 | * response iocb memory object provided by the caller of |
| 9771 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9772 | * sleeps for the iocb completion. |
| 9773 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9774 | static void |
| 9775 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9776 | struct lpfc_iocbq *cmdiocbq, |
| 9777 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9778 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9779 | wait_queue_head_t *pdone_q; |
| 9780 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9781 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9782 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9783 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9784 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9785 | if (cmdiocbq->context2 && rspiocbq) |
| 9786 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9787 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9788 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9789 | /* Set the exchange busy flag for task management commands */ |
| 9790 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9791 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9792 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9793 | cur_iocbq); |
| 9794 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9795 | } |
| 9796 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9797 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9798 | if (pdone_q) |
| 9799 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9800 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9801 | return; |
| 9802 | } |
| 9803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9804 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9805 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9806 | * @phba: Pointer to HBA context object.. |
| 9807 | * @piocbq: Pointer to command iocb. |
| 9808 | * @flag: Flag to test. |
| 9809 | * |
| 9810 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9811 | * see if the passed in flag is set. |
| 9812 | * Returns: |
| 9813 | * 1 if flag is set. |
| 9814 | * 0 if flag is not set. |
| 9815 | **/ |
| 9816 | static int |
| 9817 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9818 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9819 | { |
| 9820 | unsigned long iflags; |
| 9821 | int ret; |
| 9822 | |
| 9823 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9824 | ret = piocbq->iocb_flag & flag; |
| 9825 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9826 | return ret; |
| 9827 | |
| 9828 | } |
| 9829 | |
| 9830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9831 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9832 | * @phba: Pointer to HBA context object.. |
| 9833 | * @pring: Pointer to sli ring. |
| 9834 | * @piocb: Pointer to command iocb. |
| 9835 | * @prspiocbq: Pointer to response iocb. |
| 9836 | * @timeout: Timeout in number of seconds. |
| 9837 | * |
| 9838 | * This function issues the iocb to firmware and waits for the |
| 9839 | * iocb to complete. If the iocb command is not |
| 9840 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9841 | * Caller should not free the iocb resources if this function |
| 9842 | * returns IOCB_TIMEDOUT. |
| 9843 | * The function waits for the iocb completion using an |
| 9844 | * non-interruptible wait. |
| 9845 | * This function will sleep while waiting for iocb completion. |
| 9846 | * So, this function should not be called from any context which |
| 9847 | * does not allow sleeping. Due to the same reason, this function |
| 9848 | * cannot be called with interrupt disabled. |
| 9849 | * This function assumes that the iocb completions occur while |
| 9850 | * this function sleep. So, this function cannot be called from |
| 9851 | * the thread which process iocb completion for this ring. |
| 9852 | * This function clears the iocb_flag of the iocb object before |
| 9853 | * issuing the iocb and the iocb completion handler sets this |
| 9854 | * flag and wakes this thread when the iocb completes. |
| 9855 | * The contents of the response iocb will be copied to prspiocbq |
| 9856 | * by the completion handler when the command completes. |
| 9857 | * This function returns IOCB_SUCCESS when success. |
| 9858 | * This function is called with no lock held. |
| 9859 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9860 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9861 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9862 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9863 | struct lpfc_iocbq *piocb, |
| 9864 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9865 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9866 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9867 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9868 | long timeleft, timeout_req = 0; |
| 9869 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9870 | uint32_t creg_val; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9871 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9872 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9873 | * If the caller has provided a response iocbq buffer, then context2 |
| 9874 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9875 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9876 | if (prspiocbq) { |
| 9877 | if (piocb->context2) |
| 9878 | return IOCB_ERROR; |
| 9879 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9880 | } |
| 9881 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9882 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9883 | piocb->context_un.wait_queue = &done_q; |
| 9884 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9885 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9886 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9887 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9888 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9889 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9890 | writel(creg_val, phba->HCregaddr); |
| 9891 | readl(phba->HCregaddr); /* flush */ |
| 9892 | } |
| 9893 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9894 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 9895 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9896 | if (retval == IOCB_SUCCESS) { |
| 9897 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9898 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9899 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9900 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9901 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9902 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 9903 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9904 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9905 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9906 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9907 | "0338 IOCB wait timeout error - no " |
| 9908 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9909 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9910 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9911 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9912 | "0330 IOCB wake NOT set, " |
| 9913 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9914 | timeout, (timeleft / jiffies)); |
| 9915 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9916 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9917 | } else if (retval == IOCB_BUSY) { |
| 9918 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9919 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 9920 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); |
| 9921 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9922 | } else { |
| 9923 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9924 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9925 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9926 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9927 | } |
| 9928 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9929 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9930 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9931 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9932 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 9933 | writel(creg_val, phba->HCregaddr); |
| 9934 | readl(phba->HCregaddr); /* flush */ |
| 9935 | } |
| 9936 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9937 | if (prspiocbq) |
| 9938 | piocb->context2 = NULL; |
| 9939 | |
| 9940 | piocb->context_un.wait_queue = NULL; |
| 9941 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9942 | return retval; |
| 9943 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9945 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9946 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9947 | * @phba: Pointer to HBA context object. |
| 9948 | * @pmboxq: Pointer to driver mailbox object. |
| 9949 | * @timeout: Timeout in number of seconds. |
| 9950 | * |
| 9951 | * This function issues the mailbox to firmware and waits for the |
| 9952 | * mailbox command to complete. If the mailbox command is not |
| 9953 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 9954 | * The function waits for the mailbox completion using an |
| 9955 | * interruptible wait. If the thread is woken up due to a |
| 9956 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 9957 | * should not free the mailbox resources, if this function returns |
| 9958 | * MBX_TIMEOUT. |
| 9959 | * This function will sleep while waiting for mailbox completion. |
| 9960 | * So, this function should not be called from any context which |
| 9961 | * does not allow sleeping. Due to the same reason, this function |
| 9962 | * cannot be called with interrupt disabled. |
| 9963 | * This function assumes that the mailbox completion occurs while |
| 9964 | * this function sleep. So, this function cannot be called from |
| 9965 | * the worker thread which processes mailbox completion. |
| 9966 | * This function is called in the context of HBA management |
| 9967 | * applications. |
| 9968 | * This function returns MBX_SUCCESS when successful. |
| 9969 | * This function is called with no lock held. |
| 9970 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9971 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9972 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9973 | uint32_t timeout) |
| 9974 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9975 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9976 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9977 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9978 | |
| 9979 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9980 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9981 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9982 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9983 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9984 | /* setup wake call as IOCB callback */ |
| 9985 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 9986 | /* setup context field to pass wait_queue pointer to wake function */ |
| 9987 | pmboxq->context1 = &done_q; |
| 9988 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9989 | /* now issue the command */ |
| 9990 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9991 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9992 | wait_event_interruptible_timeout(done_q, |
| 9993 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 9994 | timeout * HZ); |
| 9995 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9996 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9997 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9998 | /* |
| 9999 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10000 | * else do not free the resources. |
| 10001 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10002 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10003 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10004 | lpfc_sli4_swap_str(phba, pmboxq); |
| 10005 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10006 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10007 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10008 | } |
| 10009 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10010 | } |
| 10011 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10012 | return retval; |
| 10013 | } |
| 10014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10015 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10016 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10017 | * @phba: Pointer to HBA context. |
| 10018 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10019 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10020 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10021 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10022 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10023 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10024 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10025 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10026 | * as with offline or HBA function reset), this routine will wait for the |
| 10027 | * outstanding mailbox command to complete before invoking the mailbox |
| 10028 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10029 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10030 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10031 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10032 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10033 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10034 | unsigned long timeout; |
| 10035 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10036 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10037 | /* delay 100ms for port state */ |
| 10038 | msleep(100); |
| 10039 | lpfc_sli_mbox_sys_flush(phba); |
| 10040 | return; |
| 10041 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10042 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10043 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10044 | spin_lock_irq(&phba->hbalock); |
| 10045 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10046 | |
| 10047 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10048 | /* Determine how long we might wait for the active mailbox |
| 10049 | * command to be gracefully completed by firmware. |
| 10050 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10051 | if (phba->sli.mbox_active) |
| 10052 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10053 | phba->sli.mbox_active) * |
| 10054 | 1000) + jiffies; |
| 10055 | spin_unlock_irq(&phba->hbalock); |
| 10056 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10057 | while (phba->sli.mbox_active) { |
| 10058 | /* Check active mailbox complete status every 2ms */ |
| 10059 | msleep(2); |
| 10060 | if (time_after(jiffies, timeout)) |
| 10061 | /* Timeout, let the mailbox flush routine to |
| 10062 | * forcefully release active mailbox command |
| 10063 | */ |
| 10064 | break; |
| 10065 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10066 | } else |
| 10067 | spin_unlock_irq(&phba->hbalock); |
| 10068 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10069 | lpfc_sli_mbox_sys_flush(phba); |
| 10070 | } |
| 10071 | |
| 10072 | /** |
| 10073 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10074 | * @phba: Pointer to HBA context. |
| 10075 | * |
| 10076 | * This function is called to read the SLI3 device error attention registers |
| 10077 | * for possible error attention events. The caller must hold the hostlock |
| 10078 | * with spin_lock_irq(). |
| 10079 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10080 | * 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] | 10081 | * Register and returns 0 otherwise. |
| 10082 | **/ |
| 10083 | static int |
| 10084 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10085 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10086 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10087 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10088 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10089 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10090 | goto unplug_err; |
| 10091 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10092 | if (ha_copy & HA_ERATT) { |
| 10093 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10094 | if (lpfc_sli_read_hs(phba)) |
| 10095 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10096 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10097 | /* Check if there is a deferred error condition is active */ |
| 10098 | if ((HS_FFER1 & phba->work_hs) && |
| 10099 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10100 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10101 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10102 | /* Clear all interrupt enable conditions */ |
| 10103 | writel(0, phba->HCregaddr); |
| 10104 | readl(phba->HCregaddr); |
| 10105 | } |
| 10106 | |
| 10107 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10108 | phba->work_ha |= HA_ERATT; |
| 10109 | /* Indicate polling handles this ERATT */ |
| 10110 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10111 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10112 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10113 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10114 | |
| 10115 | unplug_err: |
| 10116 | /* Set the driver HS work bitmap */ |
| 10117 | phba->work_hs |= UNPLUG_ERR; |
| 10118 | /* Set the driver HA work bitmap */ |
| 10119 | phba->work_ha |= HA_ERATT; |
| 10120 | /* Indicate polling handles this ERATT */ |
| 10121 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10122 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10123 | } |
| 10124 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10125 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10126 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10127 | * @phba: Pointer to HBA context. |
| 10128 | * |
| 10129 | * This function is called to read the SLI4 device error attention registers |
| 10130 | * for possible error attention events. The caller must hold the hostlock |
| 10131 | * with spin_lock_irq(). |
| 10132 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10133 | * 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] | 10134 | * Register and returns 0 otherwise. |
| 10135 | **/ |
| 10136 | static int |
| 10137 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10138 | { |
| 10139 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10140 | uint32_t if_type, portsmphr; |
| 10141 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10142 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10143 | /* |
| 10144 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10145 | * registers for error attention. This can be changed later. |
| 10146 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10147 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10148 | switch (if_type) { |
| 10149 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10150 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10151 | &uerr_sta_lo) || |
| 10152 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10153 | &uerr_sta_hi)) { |
| 10154 | phba->work_hs |= UNPLUG_ERR; |
| 10155 | phba->work_ha |= HA_ERATT; |
| 10156 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10157 | return 1; |
| 10158 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10159 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10160 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10162 | "1423 HBA Unrecoverable error: " |
| 10163 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10164 | "ue_mask_lo_reg=0x%x, " |
| 10165 | "ue_mask_hi_reg=0x%x\n", |
| 10166 | uerr_sta_lo, uerr_sta_hi, |
| 10167 | phba->sli4_hba.ue_mask_lo, |
| 10168 | phba->sli4_hba.ue_mask_hi); |
| 10169 | phba->work_status[0] = uerr_sta_lo; |
| 10170 | phba->work_status[1] = uerr_sta_hi; |
| 10171 | phba->work_ha |= HA_ERATT; |
| 10172 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10173 | return 1; |
| 10174 | } |
| 10175 | break; |
| 10176 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10177 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10178 | &portstat_reg.word0) || |
| 10179 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10180 | &portsmphr)){ |
| 10181 | phba->work_hs |= UNPLUG_ERR; |
| 10182 | phba->work_ha |= HA_ERATT; |
| 10183 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10184 | return 1; |
| 10185 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10186 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10187 | phba->work_status[0] = |
| 10188 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10189 | phba->work_status[1] = |
| 10190 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10192 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10193 | "port status reg 0x%x, " |
| 10194 | "port smphr reg 0x%x, " |
| 10195 | "error 1=0x%x, error 2=0x%x\n", |
| 10196 | portstat_reg.word0, |
| 10197 | portsmphr, |
| 10198 | phba->work_status[0], |
| 10199 | phba->work_status[1]); |
| 10200 | phba->work_ha |= HA_ERATT; |
| 10201 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10202 | return 1; |
| 10203 | } |
| 10204 | break; |
| 10205 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10206 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10207 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10208 | "2886 HBA Error Attention on unsupported " |
| 10209 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10210 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10211 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10212 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10213 | return 0; |
| 10214 | } |
| 10215 | |
| 10216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10217 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10218 | * @phba: Pointer to HBA context. |
| 10219 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10220 | * 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] | 10221 | * error attention register bit for error attention events. |
| 10222 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10223 | * 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] | 10224 | * Register and returns 0 otherwise. |
| 10225 | **/ |
| 10226 | int |
| 10227 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10228 | { |
| 10229 | uint32_t ha_copy; |
| 10230 | |
| 10231 | /* If somebody is waiting to handle an eratt, don't process it |
| 10232 | * here. The brdkill function will do this. |
| 10233 | */ |
| 10234 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10235 | return 0; |
| 10236 | |
| 10237 | /* Check if interrupt handler handles this ERATT */ |
| 10238 | spin_lock_irq(&phba->hbalock); |
| 10239 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10240 | /* Interrupt handler has handled ERATT */ |
| 10241 | spin_unlock_irq(&phba->hbalock); |
| 10242 | return 0; |
| 10243 | } |
| 10244 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10245 | /* |
| 10246 | * If there is deferred error attention, do not check for error |
| 10247 | * attention |
| 10248 | */ |
| 10249 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10250 | spin_unlock_irq(&phba->hbalock); |
| 10251 | return 0; |
| 10252 | } |
| 10253 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10254 | /* If PCI channel is offline, don't process it */ |
| 10255 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10256 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10257 | return 0; |
| 10258 | } |
| 10259 | |
| 10260 | switch (phba->sli_rev) { |
| 10261 | case LPFC_SLI_REV2: |
| 10262 | case LPFC_SLI_REV3: |
| 10263 | /* Read chip Host Attention (HA) register */ |
| 10264 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10265 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10266 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10267 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10268 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10269 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10270 | default: |
| 10271 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10272 | "0299 Invalid SLI revision (%d)\n", |
| 10273 | phba->sli_rev); |
| 10274 | ha_copy = 0; |
| 10275 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10276 | } |
| 10277 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10278 | |
| 10279 | return ha_copy; |
| 10280 | } |
| 10281 | |
| 10282 | /** |
| 10283 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10284 | * @phba: Pointer to HBA context. |
| 10285 | * |
| 10286 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10287 | * that the interrupt should be handled. |
| 10288 | * |
| 10289 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10290 | * interrupt should be handled, otherwise -EIO. |
| 10291 | */ |
| 10292 | static inline int |
| 10293 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10294 | { |
| 10295 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10296 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10297 | return -EIO; |
| 10298 | |
| 10299 | /* Update device level interrupt statistics */ |
| 10300 | phba->sli.slistat.sli_intr++; |
| 10301 | |
| 10302 | /* Ignore all interrupts during initialization. */ |
| 10303 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10304 | return -EIO; |
| 10305 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10306 | return 0; |
| 10307 | } |
| 10308 | |
| 10309 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10310 | * 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] | 10311 | * @irq: Interrupt number. |
| 10312 | * @dev_id: The device context pointer. |
| 10313 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10314 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10315 | * service routine when device with SLI-3 interface spec is enabled with |
| 10316 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10317 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10318 | * interrupt mode, this function is called as part of the device-level |
| 10319 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10320 | * is undergoing initialization, the interrupt handler will not process |
| 10321 | * the interrupt. The link attention and ELS ring attention events are |
| 10322 | * handled by the worker thread. The interrupt handler signals the worker |
| 10323 | * thread and returns for these events. This function is called without |
| 10324 | * 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] | 10325 | * structures. |
| 10326 | * |
| 10327 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10328 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10329 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10330 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10331 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10332 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10333 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10334 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10335 | uint32_t work_ha_copy; |
| 10336 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10337 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10338 | uint32_t control; |
| 10339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10340 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10341 | struct lpfc_vport *vport; |
| 10342 | struct lpfc_nodelist *ndlp; |
| 10343 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10344 | LPFC_MBOXQ_t *pmb; |
| 10345 | int rc; |
| 10346 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10347 | /* |
| 10348 | * Get the driver's phba structure from the dev_id and |
| 10349 | * assume the HBA is not interrupting. |
| 10350 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10351 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10352 | |
| 10353 | if (unlikely(!phba)) |
| 10354 | return IRQ_NONE; |
| 10355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10356 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10357 | * Stuff needs to be attented to when this function is invoked as an |
| 10358 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10359 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10360 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10361 | /* Check device state for handling interrupt */ |
| 10362 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10363 | return IRQ_NONE; |
| 10364 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10365 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10366 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10367 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10368 | /* If somebody is waiting to handle an eratt don't process it |
| 10369 | * here. The brdkill function will do this. |
| 10370 | */ |
| 10371 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10372 | ha_copy &= ~HA_ERATT; |
| 10373 | /* Check the need for handling ERATT in interrupt handler */ |
| 10374 | if (ha_copy & HA_ERATT) { |
| 10375 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10376 | /* ERATT polling has handled ERATT */ |
| 10377 | ha_copy &= ~HA_ERATT; |
| 10378 | else |
| 10379 | /* Indicate interrupt handler handles ERATT */ |
| 10380 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10381 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10382 | |
| 10383 | /* |
| 10384 | * If there is deferred error attention, do not check for any |
| 10385 | * interrupt. |
| 10386 | */ |
| 10387 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10388 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10389 | return IRQ_NONE; |
| 10390 | } |
| 10391 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10392 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10393 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10394 | goto unplug_error; |
| 10395 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10396 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10397 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10398 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10399 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10400 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10401 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10402 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10403 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10404 | } else |
| 10405 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10406 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10407 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10408 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10409 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10410 | if (work_ha_copy & HA_LATT) { |
| 10411 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10412 | /* |
| 10413 | * Turn off Link Attention interrupts |
| 10414 | * until CLEAR_LA done |
| 10415 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10416 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10417 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10418 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10419 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10420 | control &= ~HC_LAINT_ENA; |
| 10421 | writel(control, phba->HCregaddr); |
| 10422 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10423 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10424 | } |
| 10425 | else |
| 10426 | work_ha_copy &= ~HA_LATT; |
| 10427 | } |
| 10428 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10429 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10430 | /* |
| 10431 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10432 | * the only slow ring. |
| 10433 | */ |
| 10434 | status = (work_ha_copy & |
| 10435 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10436 | status >>= (4*LPFC_ELS_RING); |
| 10437 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10438 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10439 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10440 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10441 | |
| 10442 | lpfc_debugfs_slow_ring_trc(phba, |
| 10443 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10444 | control, status, |
| 10445 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10446 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10447 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10448 | lpfc_debugfs_slow_ring_trc(phba, |
| 10449 | "ISR Disable ring:" |
| 10450 | "pwork:x%x hawork:x%x wait:x%x", |
| 10451 | phba->work_ha, work_ha_copy, |
| 10452 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10453 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10454 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10455 | control &= |
| 10456 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10457 | writel(control, phba->HCregaddr); |
| 10458 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10459 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10460 | else { |
| 10461 | lpfc_debugfs_slow_ring_trc(phba, |
| 10462 | "ISR slow ring: pwork:" |
| 10463 | "x%x hawork:x%x wait:x%x", |
| 10464 | phba->work_ha, work_ha_copy, |
| 10465 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10466 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10467 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10468 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10469 | } |
| 10470 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10471 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10472 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10473 | if (lpfc_sli_read_hs(phba)) |
| 10474 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10475 | /* |
| 10476 | * Check if there is a deferred error condition |
| 10477 | * is active |
| 10478 | */ |
| 10479 | if ((HS_FFER1 & phba->work_hs) && |
| 10480 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10481 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10482 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10483 | phba->hba_flag |= DEFER_ERATT; |
| 10484 | /* Clear all interrupt enable conditions */ |
| 10485 | writel(0, phba->HCregaddr); |
| 10486 | readl(phba->HCregaddr); |
| 10487 | } |
| 10488 | } |
| 10489 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10490 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10491 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10492 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10493 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10494 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10495 | |
| 10496 | /* First check out the status word */ |
| 10497 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10498 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10499 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10500 | /* |
| 10501 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10502 | * mbxStatus <status> |
| 10503 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10504 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10505 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10506 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10507 | "Interrupt mbxCommand x%x " |
| 10508 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10509 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10510 | pmbox->mbxCommand, |
| 10511 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10512 | /* clear mailbox attention bit */ |
| 10513 | work_ha_copy &= ~HA_MBATT; |
| 10514 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10515 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10516 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10517 | phba->last_completion_time = jiffies; |
| 10518 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10519 | if (pmb->mbox_cmpl) { |
| 10520 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10521 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10522 | if (pmb->out_ext_byte_len && |
| 10523 | pmb->context2) |
| 10524 | lpfc_sli_pcimem_bcopy( |
| 10525 | phba->mbox_ext, |
| 10526 | pmb->context2, |
| 10527 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10528 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10529 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10530 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10531 | |
| 10532 | lpfc_debugfs_disc_trc(vport, |
| 10533 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10534 | "MBOX dflt rpi: : " |
| 10535 | "status:x%x rpi:x%x", |
| 10536 | (uint32_t)pmbox->mbxStatus, |
| 10537 | pmbox->un.varWords[0], 0); |
| 10538 | |
| 10539 | if (!pmbox->mbxStatus) { |
| 10540 | mp = (struct lpfc_dmabuf *) |
| 10541 | (pmb->context1); |
| 10542 | ndlp = (struct lpfc_nodelist *) |
| 10543 | pmb->context2; |
| 10544 | |
| 10545 | /* Reg_LOGIN of dflt RPI was |
| 10546 | * successful. new lets get |
| 10547 | * rid of the RPI using the |
| 10548 | * same mbox buffer. |
| 10549 | */ |
| 10550 | lpfc_unreg_login(phba, |
| 10551 | vport->vpi, |
| 10552 | pmbox->un.varWords[0], |
| 10553 | pmb); |
| 10554 | pmb->mbox_cmpl = |
| 10555 | lpfc_mbx_cmpl_dflt_rpi; |
| 10556 | pmb->context1 = mp; |
| 10557 | pmb->context2 = ndlp; |
| 10558 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10559 | rc = lpfc_sli_issue_mbox(phba, |
| 10560 | pmb, |
| 10561 | MBX_NOWAIT); |
| 10562 | if (rc != MBX_BUSY) |
| 10563 | lpfc_printf_log(phba, |
| 10564 | KERN_ERR, |
| 10565 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10566 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10567 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10568 | if (rc != MBX_NOT_FINISHED) |
| 10569 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10570 | } |
| 10571 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10572 | spin_lock_irqsave( |
| 10573 | &phba->pport->work_port_lock, |
| 10574 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10575 | phba->pport->work_port_events &= |
| 10576 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10577 | spin_unlock_irqrestore( |
| 10578 | &phba->pport->work_port_lock, |
| 10579 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10580 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10581 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10582 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10583 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10584 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10585 | if ((work_ha_copy & HA_MBATT) && |
| 10586 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10587 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10588 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10589 | do { |
| 10590 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10591 | MBX_NOWAIT); |
| 10592 | } while (rc == MBX_NOT_FINISHED); |
| 10593 | if (rc != MBX_SUCCESS) |
| 10594 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10595 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10596 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10597 | } |
| 10598 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10599 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10600 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10601 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10602 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10603 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10604 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10605 | unplug_error: |
| 10606 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10607 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10608 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10609 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10610 | |
| 10611 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10612 | * 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] | 10613 | * @irq: Interrupt number. |
| 10614 | * @dev_id: The device context pointer. |
| 10615 | * |
| 10616 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10617 | * service routine when device with SLI-3 interface spec is enabled with |
| 10618 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10619 | * ring event in the HBA. However, when the device is enabled with either |
| 10620 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10621 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10622 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10623 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10624 | * the intrrupt context. This function is called without any lock held. |
| 10625 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10626 | * |
| 10627 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10628 | * returns IRQ_NONE. |
| 10629 | **/ |
| 10630 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10631 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10632 | { |
| 10633 | struct lpfc_hba *phba; |
| 10634 | uint32_t ha_copy; |
| 10635 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10636 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10637 | |
| 10638 | /* Get the driver's phba structure from the dev_id and |
| 10639 | * assume the HBA is not interrupting. |
| 10640 | */ |
| 10641 | phba = (struct lpfc_hba *) dev_id; |
| 10642 | |
| 10643 | if (unlikely(!phba)) |
| 10644 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10645 | |
| 10646 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10647 | * Stuff needs to be attented to when this function is invoked as an |
| 10648 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10649 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10650 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10651 | /* Check device state for handling interrupt */ |
| 10652 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10653 | return IRQ_NONE; |
| 10654 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10655 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10656 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10657 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10658 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10659 | /* |
| 10660 | * If there is deferred error attention, do not check for |
| 10661 | * any interrupt. |
| 10662 | */ |
| 10663 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10664 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10665 | return IRQ_NONE; |
| 10666 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10667 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10668 | phba->HAregaddr); |
| 10669 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10670 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10671 | } else |
| 10672 | ha_copy = phba->ha_copy; |
| 10673 | |
| 10674 | /* |
| 10675 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10676 | */ |
| 10677 | ha_copy &= ~(phba->work_ha_mask); |
| 10678 | |
| 10679 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10680 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10681 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10682 | lpfc_sli_handle_fast_ring_event(phba, |
| 10683 | &phba->sli.ring[LPFC_FCP_RING], |
| 10684 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10685 | |
| 10686 | if (phba->cfg_multi_ring_support == 2) { |
| 10687 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10688 | * Process all events on extra ring. Take the optimized path |
| 10689 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10690 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10691 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10692 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10693 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10694 | lpfc_sli_handle_fast_ring_event(phba, |
| 10695 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10696 | status); |
| 10697 | } |
| 10698 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10699 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10700 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10701 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10702 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10703 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10704 | * @irq: Interrupt number. |
| 10705 | * @dev_id: The device context pointer. |
| 10706 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10707 | * This function is the HBA device-level interrupt handler to device with |
| 10708 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10709 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10710 | * requires driver attention. This function invokes the slow-path interrupt |
| 10711 | * attention handling function and fast-path interrupt attention handling |
| 10712 | * function in turn to process the relevant HBA attention events. This |
| 10713 | * function is called without any lock held. It gets the hbalock to access |
| 10714 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10715 | * |
| 10716 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10717 | * returns IRQ_NONE. |
| 10718 | **/ |
| 10719 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10720 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10721 | { |
| 10722 | struct lpfc_hba *phba; |
| 10723 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10724 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10725 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10726 | |
| 10727 | /* |
| 10728 | * Get the driver's phba structure from the dev_id and |
| 10729 | * assume the HBA is not interrupting. |
| 10730 | */ |
| 10731 | phba = (struct lpfc_hba *) dev_id; |
| 10732 | |
| 10733 | if (unlikely(!phba)) |
| 10734 | return IRQ_NONE; |
| 10735 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10736 | /* Check device state for handling interrupt */ |
| 10737 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10738 | return IRQ_NONE; |
| 10739 | |
| 10740 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10741 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10742 | spin_unlock(&phba->hbalock); |
| 10743 | return IRQ_HANDLED; |
| 10744 | } |
| 10745 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10746 | if (unlikely(!phba->ha_copy)) { |
| 10747 | spin_unlock(&phba->hbalock); |
| 10748 | return IRQ_NONE; |
| 10749 | } else if (phba->ha_copy & HA_ERATT) { |
| 10750 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10751 | /* ERATT polling has handled ERATT */ |
| 10752 | phba->ha_copy &= ~HA_ERATT; |
| 10753 | else |
| 10754 | /* Indicate interrupt handler handles ERATT */ |
| 10755 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10756 | } |
| 10757 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10758 | /* |
| 10759 | * If there is deferred error attention, do not check for any interrupt. |
| 10760 | */ |
| 10761 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10762 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10763 | return IRQ_NONE; |
| 10764 | } |
| 10765 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10766 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10767 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10768 | spin_unlock(&phba->hbalock); |
| 10769 | return IRQ_HANDLED; |
| 10770 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10771 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10772 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10773 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10774 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10775 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10776 | readl(phba->HAregaddr); /* flush */ |
| 10777 | spin_unlock(&phba->hbalock); |
| 10778 | |
| 10779 | /* |
| 10780 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10781 | */ |
| 10782 | |
| 10783 | /* status of events with mailbox and link attention */ |
| 10784 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10785 | |
| 10786 | /* status of events with ELS ring */ |
| 10787 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10788 | status2 >>= (4*LPFC_ELS_RING); |
| 10789 | |
| 10790 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10791 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10792 | else |
| 10793 | sp_irq_rc = IRQ_NONE; |
| 10794 | |
| 10795 | /* |
| 10796 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10797 | */ |
| 10798 | |
| 10799 | /* status of events with FCP ring */ |
| 10800 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10801 | status1 >>= (4*LPFC_FCP_RING); |
| 10802 | |
| 10803 | /* status of events with extra ring */ |
| 10804 | if (phba->cfg_multi_ring_support == 2) { |
| 10805 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10806 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10807 | } else |
| 10808 | status2 = 0; |
| 10809 | |
| 10810 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10811 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10812 | else |
| 10813 | fp_irq_rc = IRQ_NONE; |
| 10814 | |
| 10815 | /* Return device-level interrupt handling status */ |
| 10816 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10817 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10818 | |
| 10819 | /** |
| 10820 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10821 | * @phba: pointer to lpfc hba data structure. |
| 10822 | * |
| 10823 | * This routine is invoked by the worker thread to process all the pending |
| 10824 | * SLI4 FCP abort XRI events. |
| 10825 | **/ |
| 10826 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10827 | { |
| 10828 | struct lpfc_cq_event *cq_event; |
| 10829 | |
| 10830 | /* First, declare the fcp xri abort event has been handled */ |
| 10831 | spin_lock_irq(&phba->hbalock); |
| 10832 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10833 | spin_unlock_irq(&phba->hbalock); |
| 10834 | /* Now, handle all the fcp xri abort events */ |
| 10835 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10836 | /* Get the first event from the head of the event queue */ |
| 10837 | spin_lock_irq(&phba->hbalock); |
| 10838 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10839 | cq_event, struct lpfc_cq_event, list); |
| 10840 | spin_unlock_irq(&phba->hbalock); |
| 10841 | /* Notify aborted XRI for FCP work queue */ |
| 10842 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10843 | /* Free the event processed back to the free pool */ |
| 10844 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10845 | } |
| 10846 | } |
| 10847 | |
| 10848 | /** |
| 10849 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10850 | * @phba: pointer to lpfc hba data structure. |
| 10851 | * |
| 10852 | * This routine is invoked by the worker thread to process all the pending |
| 10853 | * SLI4 els abort xri events. |
| 10854 | **/ |
| 10855 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10856 | { |
| 10857 | struct lpfc_cq_event *cq_event; |
| 10858 | |
| 10859 | /* First, declare the els xri abort event has been handled */ |
| 10860 | spin_lock_irq(&phba->hbalock); |
| 10861 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10862 | spin_unlock_irq(&phba->hbalock); |
| 10863 | /* Now, handle all the els xri abort events */ |
| 10864 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10865 | /* Get the first event from the head of the event queue */ |
| 10866 | spin_lock_irq(&phba->hbalock); |
| 10867 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10868 | cq_event, struct lpfc_cq_event, list); |
| 10869 | spin_unlock_irq(&phba->hbalock); |
| 10870 | /* Notify aborted XRI for ELS work queue */ |
| 10871 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10872 | /* Free the event processed back to the free pool */ |
| 10873 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10874 | } |
| 10875 | } |
| 10876 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10877 | /** |
| 10878 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10879 | * @phba: pointer to lpfc hba data structure |
| 10880 | * @pIocbIn: pointer to the rspiocbq |
| 10881 | * @pIocbOut: pointer to the cmdiocbq |
| 10882 | * @wcqe: pointer to the complete wcqe |
| 10883 | * |
| 10884 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 10885 | * by copying all the IOCB fields from command iocbq and transferring the |
| 10886 | * completion status information from the complete wcqe. |
| 10887 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10888 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10889 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 10890 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10891 | struct lpfc_iocbq *pIocbOut, |
| 10892 | struct lpfc_wcqe_complete *wcqe) |
| 10893 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10894 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10895 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10896 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 10897 | |
| 10898 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 10899 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10900 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10901 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 10902 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10903 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 10904 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 10905 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 10906 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 10907 | wcqe->total_data_placed; |
| 10908 | else |
| 10909 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10910 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10911 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10912 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 10913 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10914 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10915 | /* Convert BG errors for completion status */ |
| 10916 | if (status == CQE_STATUS_DI_ERROR) { |
| 10917 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 10918 | |
| 10919 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 10920 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 10921 | else |
| 10922 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 10923 | |
| 10924 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 10925 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 10926 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10927 | BGS_GUARD_ERR_MASK; |
| 10928 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 10929 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10930 | BGS_APPTAG_ERR_MASK; |
| 10931 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 10932 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10933 | BGS_REFTAG_ERR_MASK; |
| 10934 | |
| 10935 | /* Check to see if there was any good data before the error */ |
| 10936 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 10937 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10938 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 10939 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 10940 | wcqe->total_data_placed; |
| 10941 | } |
| 10942 | |
| 10943 | /* |
| 10944 | * Set ALL the error bits to indicate we don't know what |
| 10945 | * type of error it is. |
| 10946 | */ |
| 10947 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 10948 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10949 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 10950 | BGS_GUARD_ERR_MASK); |
| 10951 | } |
| 10952 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10953 | /* Pick up HBA exchange busy condition */ |
| 10954 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 10955 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10956 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 10957 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10958 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10959 | } |
| 10960 | |
| 10961 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10962 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 10963 | * @phba: Pointer to HBA context object. |
| 10964 | * @wcqe: Pointer to work-queue completion queue entry. |
| 10965 | * |
| 10966 | * This routine handles an ELS work-queue completion event and construct |
| 10967 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 10968 | * discovery engine to handle. |
| 10969 | * |
| 10970 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 10971 | **/ |
| 10972 | static struct lpfc_iocbq * |
| 10973 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 10974 | struct lpfc_iocbq *irspiocbq) |
| 10975 | { |
| 10976 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 10977 | struct lpfc_iocbq *cmdiocbq; |
| 10978 | struct lpfc_wcqe_complete *wcqe; |
| 10979 | unsigned long iflags; |
| 10980 | |
| 10981 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 10982 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10983 | pring->stats.iocb_event++; |
| 10984 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 10985 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 10986 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 10987 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10988 | |
| 10989 | if (unlikely(!cmdiocbq)) { |
| 10990 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10991 | "0386 ELS complete with no corresponding " |
| 10992 | "cmdiocb: iotag (%d)\n", |
| 10993 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10994 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 10995 | return NULL; |
| 10996 | } |
| 10997 | |
| 10998 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10999 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11000 | |
| 11001 | return irspiocbq; |
| 11002 | } |
| 11003 | |
| 11004 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11005 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11006 | * @phba: Pointer to HBA context object. |
| 11007 | * @cqe: Pointer to mailbox completion queue entry. |
| 11008 | * |
| 11009 | * This routine process a mailbox completion queue entry with asynchrous |
| 11010 | * event. |
| 11011 | * |
| 11012 | * Return: true if work posted to worker thread, otherwise false. |
| 11013 | **/ |
| 11014 | static bool |
| 11015 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11016 | { |
| 11017 | struct lpfc_cq_event *cq_event; |
| 11018 | unsigned long iflags; |
| 11019 | |
| 11020 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11021 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11022 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11023 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11024 | |
| 11025 | /* Allocate a new internal CQ_EVENT entry */ |
| 11026 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11027 | if (!cq_event) { |
| 11028 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11029 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11030 | return false; |
| 11031 | } |
| 11032 | |
| 11033 | /* Move the CQE into an asynchronous event entry */ |
| 11034 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11035 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11036 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11037 | /* Set the async event flag */ |
| 11038 | phba->hba_flag |= ASYNC_EVENT; |
| 11039 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11040 | |
| 11041 | return true; |
| 11042 | } |
| 11043 | |
| 11044 | /** |
| 11045 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11046 | * @phba: Pointer to HBA context object. |
| 11047 | * @cqe: Pointer to mailbox completion queue entry. |
| 11048 | * |
| 11049 | * This routine process a mailbox completion queue entry with mailbox |
| 11050 | * completion event. |
| 11051 | * |
| 11052 | * Return: true if work posted to worker thread, otherwise false. |
| 11053 | **/ |
| 11054 | static bool |
| 11055 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11056 | { |
| 11057 | uint32_t mcqe_status; |
| 11058 | MAILBOX_t *mbox, *pmbox; |
| 11059 | struct lpfc_mqe *mqe; |
| 11060 | struct lpfc_vport *vport; |
| 11061 | struct lpfc_nodelist *ndlp; |
| 11062 | struct lpfc_dmabuf *mp; |
| 11063 | unsigned long iflags; |
| 11064 | LPFC_MBOXQ_t *pmb; |
| 11065 | bool workposted = false; |
| 11066 | int rc; |
| 11067 | |
| 11068 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11069 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11070 | goto out_no_mqe_complete; |
| 11071 | |
| 11072 | /* Get the reference to the active mbox command */ |
| 11073 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11074 | pmb = phba->sli.mbox_active; |
| 11075 | if (unlikely(!pmb)) { |
| 11076 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11077 | "1832 No pending MBOX command to handle\n"); |
| 11078 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11079 | goto out_no_mqe_complete; |
| 11080 | } |
| 11081 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11082 | mqe = &pmb->u.mqe; |
| 11083 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11084 | mbox = phba->mbox; |
| 11085 | vport = pmb->vport; |
| 11086 | |
| 11087 | /* Reset heartbeat timer */ |
| 11088 | phba->last_completion_time = jiffies; |
| 11089 | del_timer(&phba->sli.mbox_tmo); |
| 11090 | |
| 11091 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11092 | if (pmb->mbox_cmpl && mbox) |
| 11093 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11094 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11095 | /* |
| 11096 | * For mcqe errors, conditionally move a modified error code to |
| 11097 | * the mbox so that the error will not be missed. |
| 11098 | */ |
| 11099 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11100 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11101 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11102 | bf_set(lpfc_mqe_status, mqe, |
| 11103 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11104 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11105 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11106 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11107 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11108 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11109 | mcqe_status, |
| 11110 | pmbox->un.varWords[0], 0); |
| 11111 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11112 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11113 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11114 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11115 | * RID of the PPI using the same mbox buffer. |
| 11116 | */ |
| 11117 | lpfc_unreg_login(phba, vport->vpi, |
| 11118 | pmbox->un.varWords[0], pmb); |
| 11119 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11120 | pmb->context1 = mp; |
| 11121 | pmb->context2 = ndlp; |
| 11122 | pmb->vport = vport; |
| 11123 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11124 | if (rc != MBX_BUSY) |
| 11125 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11126 | LOG_SLI, "0385 rc should " |
| 11127 | "have been MBX_BUSY\n"); |
| 11128 | if (rc != MBX_NOT_FINISHED) |
| 11129 | goto send_current_mbox; |
| 11130 | } |
| 11131 | } |
| 11132 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11133 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11134 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11135 | |
| 11136 | /* There is mailbox completion work to do */ |
| 11137 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11138 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11139 | phba->work_ha |= HA_MBATT; |
| 11140 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11141 | workposted = true; |
| 11142 | |
| 11143 | send_current_mbox: |
| 11144 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11145 | /* Release the mailbox command posting token */ |
| 11146 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11147 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11148 | phba->sli.mbox_active = NULL; |
| 11149 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11150 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11151 | lpfc_worker_wake_up(phba); |
| 11152 | out_no_mqe_complete: |
| 11153 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11154 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11155 | return workposted; |
| 11156 | } |
| 11157 | |
| 11158 | /** |
| 11159 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11160 | * @phba: Pointer to HBA context object. |
| 11161 | * @cqe: Pointer to mailbox completion queue entry. |
| 11162 | * |
| 11163 | * This routine process a mailbox completion queue entry, it invokes the |
| 11164 | * proper mailbox complete handling or asynchrous event handling routine |
| 11165 | * according to the MCQE's async bit. |
| 11166 | * |
| 11167 | * Return: true if work posted to worker thread, otherwise false. |
| 11168 | **/ |
| 11169 | static bool |
| 11170 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11171 | { |
| 11172 | struct lpfc_mcqe mcqe; |
| 11173 | bool workposted; |
| 11174 | |
| 11175 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11176 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11177 | |
| 11178 | /* Invoke the proper event handling routine */ |
| 11179 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11180 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11181 | else |
| 11182 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11183 | return workposted; |
| 11184 | } |
| 11185 | |
| 11186 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11187 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11188 | * @phba: Pointer to HBA context object. |
| 11189 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11190 | * |
| 11191 | * This routine handles an ELS work-queue completion event. |
| 11192 | * |
| 11193 | * Return: true if work posted to worker thread, otherwise false. |
| 11194 | **/ |
| 11195 | static bool |
| 11196 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, |
| 11197 | struct lpfc_wcqe_complete *wcqe) |
| 11198 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11199 | struct lpfc_iocbq *irspiocbq; |
| 11200 | unsigned long iflags; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 11201 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11202 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11203 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11204 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11205 | if (!irspiocbq) { |
| 11206 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11207 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11208 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
| 11209 | pring->txq_cnt, phba->iocb_cnt, |
| 11210 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, |
| 11211 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11212 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11213 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11214 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11215 | /* Save off the slow-path queue event for work thread to process */ |
| 11216 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11217 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11218 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11219 | &phba->sli4_hba.sp_queue_event); |
| 11220 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11221 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11222 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11223 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11224 | } |
| 11225 | |
| 11226 | /** |
| 11227 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11228 | * @phba: Pointer to HBA context object. |
| 11229 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11230 | * |
| 11231 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11232 | * proper WQ release routine to the slow-path WQ. |
| 11233 | **/ |
| 11234 | static void |
| 11235 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11236 | struct lpfc_wcqe_release *wcqe) |
| 11237 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11238 | /* sanity check on queue memory */ |
| 11239 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11240 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11241 | /* Check for the slow-path ELS work queue */ |
| 11242 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11243 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11244 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11245 | else |
| 11246 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11247 | "2579 Slow-path wqe consume event carries " |
| 11248 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11249 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11250 | phba->sli4_hba.els_wq->queue_id); |
| 11251 | } |
| 11252 | |
| 11253 | /** |
| 11254 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11255 | * @phba: Pointer to HBA context object. |
| 11256 | * @cq: Pointer to a WQ completion queue. |
| 11257 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11258 | * |
| 11259 | * This routine handles an XRI abort event. |
| 11260 | * |
| 11261 | * Return: true if work posted to worker thread, otherwise false. |
| 11262 | **/ |
| 11263 | static bool |
| 11264 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11265 | struct lpfc_queue *cq, |
| 11266 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11267 | { |
| 11268 | bool workposted = false; |
| 11269 | struct lpfc_cq_event *cq_event; |
| 11270 | unsigned long iflags; |
| 11271 | |
| 11272 | /* Allocate a new internal CQ_EVENT entry */ |
| 11273 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11274 | if (!cq_event) { |
| 11275 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11276 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11277 | return false; |
| 11278 | } |
| 11279 | |
| 11280 | /* Move the CQE into the proper xri abort event list */ |
| 11281 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11282 | switch (cq->subtype) { |
| 11283 | case LPFC_FCP: |
| 11284 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11285 | list_add_tail(&cq_event->list, |
| 11286 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11287 | /* Set the fcp xri abort event flag */ |
| 11288 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11289 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11290 | workposted = true; |
| 11291 | break; |
| 11292 | case LPFC_ELS: |
| 11293 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11294 | list_add_tail(&cq_event->list, |
| 11295 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11296 | /* Set the els xri abort event flag */ |
| 11297 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11298 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11299 | workposted = true; |
| 11300 | break; |
| 11301 | default: |
| 11302 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11303 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11304 | cq->subtype); |
| 11305 | workposted = false; |
| 11306 | break; |
| 11307 | } |
| 11308 | return workposted; |
| 11309 | } |
| 11310 | |
| 11311 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11312 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11313 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11314 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11315 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11316 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11317 | * |
| 11318 | * Return: true if work posted to worker thread, otherwise false. |
| 11319 | **/ |
| 11320 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11321 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11322 | { |
| 11323 | bool workposted = false; |
| 11324 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11325 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11326 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11327 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11328 | unsigned long iflags; |
| 11329 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11330 | /* sanity check on queue memory */ |
| 11331 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11332 | return workposted; |
| 11333 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11334 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11335 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11336 | else |
| 11337 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11338 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11339 | goto out; |
| 11340 | |
| 11341 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11342 | switch (status) { |
| 11343 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11344 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11345 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11346 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11347 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11348 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11349 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11350 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11351 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11352 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11353 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11354 | goto out; |
| 11355 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11356 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11357 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11358 | /* save off the frame for the word thread to process */ |
| 11359 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11360 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11361 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11362 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11363 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11364 | workposted = true; |
| 11365 | break; |
| 11366 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11367 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11368 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11369 | /* Post more buffers if possible */ |
| 11370 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11371 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11372 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11373 | workposted = true; |
| 11374 | break; |
| 11375 | } |
| 11376 | out: |
| 11377 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11378 | } |
| 11379 | |
| 11380 | /** |
| 11381 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11382 | * @phba: Pointer to HBA context object. |
| 11383 | * @cq: Pointer to the completion queue. |
| 11384 | * @wcqe: Pointer to a completion queue entry. |
| 11385 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11386 | * 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] | 11387 | * entry. |
| 11388 | * |
| 11389 | * Return: true if work posted to worker thread, otherwise false. |
| 11390 | **/ |
| 11391 | static bool |
| 11392 | 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] | 11393 | struct lpfc_cqe *cqe) |
| 11394 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11395 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11396 | bool workposted = false; |
| 11397 | |
| 11398 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11399 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11400 | |
| 11401 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11402 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11403 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11404 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11405 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11406 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11407 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11408 | break; |
| 11409 | case CQE_CODE_RELEASE_WQE: |
| 11410 | /* Process the WQ release event */ |
| 11411 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11412 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11413 | break; |
| 11414 | case CQE_CODE_XRI_ABORTED: |
| 11415 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11416 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11417 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11418 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11419 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11420 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11421 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11422 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11423 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11424 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11425 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11426 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11427 | default: |
| 11428 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11429 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11430 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11431 | break; |
| 11432 | } |
| 11433 | return workposted; |
| 11434 | } |
| 11435 | |
| 11436 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11437 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11438 | * @phba: Pointer to HBA context object. |
| 11439 | * @eqe: Pointer to fast-path event queue entry. |
| 11440 | * |
| 11441 | * This routine process a event queue entry from the slow-path event queue. |
| 11442 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11443 | * completion event on a completion queue, if not, an error shall be logged |
| 11444 | * and just return. Otherwise, it will get to the corresponding completion |
| 11445 | * queue and process all the entries on that completion queue, rearm the |
| 11446 | * completion queue, and then return. |
| 11447 | * |
| 11448 | **/ |
| 11449 | static void |
| 11450 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 11451 | { |
| 11452 | struct lpfc_queue *cq = NULL, *childq, *speq; |
| 11453 | struct lpfc_cqe *cqe; |
| 11454 | bool workposted = false; |
| 11455 | int ecount = 0; |
| 11456 | uint16_t cqid; |
| 11457 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11458 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11459 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11460 | "0359 Not a valid slow-path completion " |
| 11461 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11462 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11463 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11464 | return; |
| 11465 | } |
| 11466 | |
| 11467 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11468 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11469 | |
| 11470 | /* Search for completion queue pointer matching this cqid */ |
| 11471 | speq = phba->sli4_hba.sp_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11472 | /* sanity check on queue memory */ |
| 11473 | if (unlikely(!speq)) |
| 11474 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11475 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11476 | if (childq->queue_id == cqid) { |
| 11477 | cq = childq; |
| 11478 | break; |
| 11479 | } |
| 11480 | } |
| 11481 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11482 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11483 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11484 | "0365 Slow-path CQ identifier " |
| 11485 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11486 | return; |
| 11487 | } |
| 11488 | |
| 11489 | /* Process all the entries to the CQ */ |
| 11490 | switch (cq->type) { |
| 11491 | case LPFC_MCQ: |
| 11492 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11493 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11494 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11495 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11496 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11497 | } |
| 11498 | break; |
| 11499 | case LPFC_WCQ: |
| 11500 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11501 | if (cq->subtype == LPFC_FCP) |
| 11502 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11503 | cqe); |
| 11504 | else |
| 11505 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11506 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11507 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11508 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11509 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11510 | |
| 11511 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11512 | if (ecount > cq->CQ_max_cqe) |
| 11513 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11514 | break; |
| 11515 | default: |
| 11516 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11517 | "0370 Invalid completion queue type (%d)\n", |
| 11518 | cq->type); |
| 11519 | return; |
| 11520 | } |
| 11521 | |
| 11522 | /* Catch the no cq entry condition, log an error */ |
| 11523 | if (unlikely(ecount == 0)) |
| 11524 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11525 | "0371 No entry from the CQ: identifier " |
| 11526 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11527 | |
| 11528 | /* In any case, flash and re-arm the RCQ */ |
| 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 | /** |
| 11537 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry |
| 11538 | * @eqe: Pointer to fast-path completion queue entry. |
| 11539 | * |
| 11540 | * This routine process a fast-path work queue completion entry from fast-path |
| 11541 | * event queue for FCP command response completion. |
| 11542 | **/ |
| 11543 | static void |
| 11544 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, |
| 11545 | struct lpfc_wcqe_complete *wcqe) |
| 11546 | { |
| 11547 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
| 11548 | struct lpfc_iocbq *cmdiocbq; |
| 11549 | struct lpfc_iocbq irspiocbq; |
| 11550 | unsigned long iflags; |
| 11551 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11552 | /* Check for response status */ |
| 11553 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11554 | /* If resource errors reported from HBA, reduce queue |
| 11555 | * depth of the SCSI device. |
| 11556 | */ |
| 11557 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11558 | IOSTAT_LOCAL_REJECT) && |
| 11559 | (wcqe->parameter == IOERR_NO_RESOURCES)) { |
| 11560 | phba->lpfc_rampdown_queue_depth(phba); |
| 11561 | } |
| 11562 | /* Log the error status */ |
| 11563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11564 | "0373 FCP complete error: status=x%x, " |
| 11565 | "hw_status=x%x, total_data_specified=%d, " |
| 11566 | "parameter=x%x, word3=x%x\n", |
| 11567 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11568 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11569 | wcqe->total_data_placed, wcqe->parameter, |
| 11570 | wcqe->word3); |
| 11571 | } |
| 11572 | |
| 11573 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 11574 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11575 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11576 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11577 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame^] | 11578 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11579 | if (unlikely(!cmdiocbq)) { |
| 11580 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11581 | "0374 FCP complete with no corresponding " |
| 11582 | "cmdiocb: iotag (%d)\n", |
| 11583 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11584 | return; |
| 11585 | } |
| 11586 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11587 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11588 | "0375 FCP cmdiocb not callback function " |
| 11589 | "iotag: (%d)\n", |
| 11590 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11591 | return; |
| 11592 | } |
| 11593 | |
| 11594 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11595 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11596 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11597 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11598 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11599 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11600 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11601 | } |
| 11602 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11603 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11604 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11605 | } |
| 11606 | |
| 11607 | /** |
| 11608 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11609 | * @phba: Pointer to HBA context object. |
| 11610 | * @cq: Pointer to completion queue. |
| 11611 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11612 | * |
| 11613 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11614 | * proper WQ release routine to the slow-path WQ. |
| 11615 | **/ |
| 11616 | static void |
| 11617 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11618 | struct lpfc_wcqe_release *wcqe) |
| 11619 | { |
| 11620 | struct lpfc_queue *childwq; |
| 11621 | bool wqid_matched = false; |
| 11622 | uint16_t fcp_wqid; |
| 11623 | |
| 11624 | /* Check for fast-path FCP work queue release */ |
| 11625 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11626 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11627 | if (childwq->queue_id == fcp_wqid) { |
| 11628 | lpfc_sli4_wq_release(childwq, |
| 11629 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11630 | wqid_matched = true; |
| 11631 | break; |
| 11632 | } |
| 11633 | } |
| 11634 | /* Report warning log message if no match found */ |
| 11635 | if (wqid_matched != true) |
| 11636 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11637 | "2580 Fast-path wqe consume event carries " |
| 11638 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11639 | } |
| 11640 | |
| 11641 | /** |
| 11642 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11643 | * @cq: Pointer to the completion queue. |
| 11644 | * @eqe: Pointer to fast-path completion queue entry. |
| 11645 | * |
| 11646 | * This routine process a fast-path work queue completion entry from fast-path |
| 11647 | * event queue for FCP command response completion. |
| 11648 | **/ |
| 11649 | static int |
| 11650 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11651 | struct lpfc_cqe *cqe) |
| 11652 | { |
| 11653 | struct lpfc_wcqe_release wcqe; |
| 11654 | bool workposted = false; |
| 11655 | |
| 11656 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11657 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11658 | |
| 11659 | /* Check and process for different type of WCQE and dispatch */ |
| 11660 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11661 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11662 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11663 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11664 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11665 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
| 11666 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11667 | break; |
| 11668 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11669 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11670 | /* Process the WQ release event */ |
| 11671 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11672 | (struct lpfc_wcqe_release *)&wcqe); |
| 11673 | break; |
| 11674 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11675 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11676 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11677 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11678 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11679 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11680 | break; |
| 11681 | default: |
| 11682 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11683 | "0144 Not a valid WCQE code: x%x\n", |
| 11684 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11685 | break; |
| 11686 | } |
| 11687 | return workposted; |
| 11688 | } |
| 11689 | |
| 11690 | /** |
| 11691 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry |
| 11692 | * @phba: Pointer to HBA context object. |
| 11693 | * @eqe: Pointer to fast-path event queue entry. |
| 11694 | * |
| 11695 | * This routine process a event queue entry from the fast-path event queue. |
| 11696 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11697 | * completion event on a completion queue, if not, an error shall be logged |
| 11698 | * and just return. Otherwise, it will get to the corresponding completion |
| 11699 | * queue and process all the entries on the completion queue, rearm the |
| 11700 | * completion queue, and then return. |
| 11701 | **/ |
| 11702 | static void |
| 11703 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11704 | uint32_t fcp_cqidx) |
| 11705 | { |
| 11706 | struct lpfc_queue *cq; |
| 11707 | struct lpfc_cqe *cqe; |
| 11708 | bool workposted = false; |
| 11709 | uint16_t cqid; |
| 11710 | int ecount = 0; |
| 11711 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11712 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11714 | "0366 Not a valid fast-path completion " |
| 11715 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11716 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11717 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11718 | return; |
| 11719 | } |
| 11720 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11721 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11722 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11723 | "3146 Fast-path completion queues " |
| 11724 | "does not exist\n"); |
| 11725 | return; |
| 11726 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11727 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; |
| 11728 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11729 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11730 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11731 | "0367 Fast-path completion queue " |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11732 | "(%d) does not exist\n", fcp_cqidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11733 | return; |
| 11734 | } |
| 11735 | |
| 11736 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11737 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11738 | if (unlikely(cqid != cq->queue_id)) { |
| 11739 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11740 | "0368 Miss-matched fast-path completion " |
| 11741 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11742 | cqid, cq->queue_id); |
| 11743 | return; |
| 11744 | } |
| 11745 | |
| 11746 | /* Process all the entries to the CQ */ |
| 11747 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11748 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11749 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11750 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11751 | } |
| 11752 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11753 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11754 | if (ecount > cq->CQ_max_cqe) |
| 11755 | cq->CQ_max_cqe = ecount; |
| 11756 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11757 | /* Catch the no cq entry condition */ |
| 11758 | if (unlikely(ecount == 0)) |
| 11759 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11760 | "0369 No entry from fast-path completion " |
| 11761 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11762 | |
| 11763 | /* In any case, flash and re-arm the CQ */ |
| 11764 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11765 | |
| 11766 | /* wake up worker thread if there are works to be done */ |
| 11767 | if (workposted) |
| 11768 | lpfc_worker_wake_up(phba); |
| 11769 | } |
| 11770 | |
| 11771 | static void |
| 11772 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11773 | { |
| 11774 | struct lpfc_eqe *eqe; |
| 11775 | |
| 11776 | /* walk all the EQ entries and drop on the floor */ |
| 11777 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11778 | ; |
| 11779 | |
| 11780 | /* Clear and re-arm the EQ */ |
| 11781 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11782 | } |
| 11783 | |
| 11784 | /** |
| 11785 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device |
| 11786 | * @irq: Interrupt number. |
| 11787 | * @dev_id: The device context pointer. |
| 11788 | * |
| 11789 | * This function is directly called from the PCI layer as an interrupt |
| 11790 | * service routine when device with SLI-4 interface spec is enabled with |
| 11791 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11792 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11793 | * interrupt mode, this function is called as part of the device-level |
| 11794 | * interrupt handler. When the PCI slot is in error recovery or the HBA is |
| 11795 | * undergoing initialization, the interrupt handler will not process the |
| 11796 | * interrupt. The link attention and ELS ring attention events are handled |
| 11797 | * by the worker thread. The interrupt handler signals the worker thread |
| 11798 | * and returns for these events. This function is called without any lock |
| 11799 | * held. It gets the hbalock to access and update SLI data structures. |
| 11800 | * |
| 11801 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11802 | * returns IRQ_NONE. |
| 11803 | **/ |
| 11804 | irqreturn_t |
| 11805 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) |
| 11806 | { |
| 11807 | struct lpfc_hba *phba; |
| 11808 | struct lpfc_queue *speq; |
| 11809 | struct lpfc_eqe *eqe; |
| 11810 | unsigned long iflag; |
| 11811 | int ecount = 0; |
| 11812 | |
| 11813 | /* |
| 11814 | * Get the driver's phba structure from the dev_id |
| 11815 | */ |
| 11816 | phba = (struct lpfc_hba *)dev_id; |
| 11817 | |
| 11818 | if (unlikely(!phba)) |
| 11819 | return IRQ_NONE; |
| 11820 | |
| 11821 | /* Get to the EQ struct associated with this vector */ |
| 11822 | speq = phba->sli4_hba.sp_eq; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11823 | if (unlikely(!speq)) |
| 11824 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11825 | |
| 11826 | /* Check device state for handling interrupt */ |
| 11827 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11828 | speq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11829 | /* Check again for link_state with lock held */ |
| 11830 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11831 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11832 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11833 | lpfc_sli4_eq_flush(phba, speq); |
| 11834 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11835 | return IRQ_NONE; |
| 11836 | } |
| 11837 | |
| 11838 | /* |
| 11839 | * Process all the event on FCP slow-path EQ |
| 11840 | */ |
| 11841 | while ((eqe = lpfc_sli4_eq_get(speq))) { |
| 11842 | lpfc_sli4_sp_handle_eqe(phba, eqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11843 | if (!(++ecount % speq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11844 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11845 | speq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11846 | } |
| 11847 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11848 | /* Track the max number of EQEs processed in 1 intr */ |
| 11849 | if (ecount > speq->EQ_max_eqe) |
| 11850 | speq->EQ_max_eqe = ecount; |
| 11851 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11852 | /* Always clear and re-arm the slow-path EQ */ |
| 11853 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); |
| 11854 | |
| 11855 | /* Catch the no cq entry condition */ |
| 11856 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11857 | speq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11858 | if (phba->intr_type == MSIX) |
| 11859 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11860 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11861 | "0357 MSI-X interrupt with no EQE\n"); |
| 11862 | else |
| 11863 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11864 | return IRQ_NONE; |
| 11865 | } |
| 11866 | |
| 11867 | return IRQ_HANDLED; |
| 11868 | } /* lpfc_sli4_sp_intr_handler */ |
| 11869 | |
| 11870 | /** |
| 11871 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device |
| 11872 | * @irq: Interrupt number. |
| 11873 | * @dev_id: The device context pointer. |
| 11874 | * |
| 11875 | * This function is directly called from the PCI layer as an interrupt |
| 11876 | * service routine when device with SLI-4 interface spec is enabled with |
| 11877 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11878 | * ring event in the HBA. However, when the device is enabled with either |
| 11879 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11880 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11881 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11882 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11883 | * the intrrupt context. This function is called without any lock held. |
| 11884 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11885 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11886 | * equal to that of FCP CQ index. |
| 11887 | * |
| 11888 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11889 | * returns IRQ_NONE. |
| 11890 | **/ |
| 11891 | irqreturn_t |
| 11892 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) |
| 11893 | { |
| 11894 | struct lpfc_hba *phba; |
| 11895 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11896 | struct lpfc_queue *fpeq; |
| 11897 | struct lpfc_eqe *eqe; |
| 11898 | unsigned long iflag; |
| 11899 | int ecount = 0; |
| 11900 | uint32_t fcp_eqidx; |
| 11901 | |
| 11902 | /* Get the driver's phba structure from the dev_id */ |
| 11903 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11904 | phba = fcp_eq_hdl->phba; |
| 11905 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11906 | |
| 11907 | if (unlikely(!phba)) |
| 11908 | return IRQ_NONE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11909 | if (unlikely(!phba->sli4_hba.fp_eq)) |
| 11910 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11911 | |
| 11912 | /* Get to the EQ struct associated with this vector */ |
| 11913 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11914 | if (unlikely(!fpeq)) |
| 11915 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11916 | |
| 11917 | /* Check device state for handling interrupt */ |
| 11918 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11919 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11920 | /* Check again for link_state with lock held */ |
| 11921 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11922 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11923 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11924 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11925 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11926 | return IRQ_NONE; |
| 11927 | } |
| 11928 | |
| 11929 | /* |
| 11930 | * Process all the event on FCP fast-path EQ |
| 11931 | */ |
| 11932 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 11933 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11934 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11935 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11936 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11937 | } |
| 11938 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11939 | /* Track the max number of EQEs processed in 1 intr */ |
| 11940 | if (ecount > fpeq->EQ_max_eqe) |
| 11941 | fpeq->EQ_max_eqe = ecount; |
| 11942 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11943 | /* Always clear and re-arm the fast-path EQ */ |
| 11944 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11945 | |
| 11946 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11947 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11948 | if (phba->intr_type == MSIX) |
| 11949 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11950 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11951 | "0358 MSI-X interrupt with no EQE\n"); |
| 11952 | else |
| 11953 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11954 | return IRQ_NONE; |
| 11955 | } |
| 11956 | |
| 11957 | return IRQ_HANDLED; |
| 11958 | } /* lpfc_sli4_fp_intr_handler */ |
| 11959 | |
| 11960 | /** |
| 11961 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 11962 | * @irq: Interrupt number. |
| 11963 | * @dev_id: The device context pointer. |
| 11964 | * |
| 11965 | * This function is the device-level interrupt handler to device with SLI-4 |
| 11966 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 11967 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 11968 | * driver attention. This function invokes the slow-path interrupt attention |
| 11969 | * handling function and fast-path interrupt attention handling function in |
| 11970 | * turn to process the relevant HBA attention events. This function is called |
| 11971 | * without any lock held. It gets the hbalock to access and update SLI data |
| 11972 | * structures. |
| 11973 | * |
| 11974 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11975 | * returns IRQ_NONE. |
| 11976 | **/ |
| 11977 | irqreturn_t |
| 11978 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 11979 | { |
| 11980 | struct lpfc_hba *phba; |
| 11981 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11982 | bool fp_handled = false; |
| 11983 | uint32_t fcp_eqidx; |
| 11984 | |
| 11985 | /* Get the driver's phba structure from the dev_id */ |
| 11986 | phba = (struct lpfc_hba *)dev_id; |
| 11987 | |
| 11988 | if (unlikely(!phba)) |
| 11989 | return IRQ_NONE; |
| 11990 | |
| 11991 | /* |
| 11992 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11993 | */ |
| 11994 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); |
| 11995 | |
| 11996 | /* |
| 11997 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11998 | */ |
| 11999 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 12000 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, |
| 12001 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
| 12002 | if (fp_irq_rc == IRQ_HANDLED) |
| 12003 | fp_handled |= true; |
| 12004 | } |
| 12005 | |
| 12006 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; |
| 12007 | } /* lpfc_sli4_intr_handler */ |
| 12008 | |
| 12009 | /** |
| 12010 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12011 | * @queue: The queue structure to free. |
| 12012 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12013 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12014 | * the host resident queue. This function must be called after destroying the |
| 12015 | * queue on the HBA. |
| 12016 | **/ |
| 12017 | void |
| 12018 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12019 | { |
| 12020 | struct lpfc_dmabuf *dmabuf; |
| 12021 | |
| 12022 | if (!queue) |
| 12023 | return; |
| 12024 | |
| 12025 | while (!list_empty(&queue->page_list)) { |
| 12026 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12027 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12028 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12029 | dmabuf->virt, dmabuf->phys); |
| 12030 | kfree(dmabuf); |
| 12031 | } |
| 12032 | kfree(queue); |
| 12033 | return; |
| 12034 | } |
| 12035 | |
| 12036 | /** |
| 12037 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12038 | * @phba: The HBA that this queue is being created on. |
| 12039 | * @entry_size: The size of each queue entry for this queue. |
| 12040 | * @entry count: The number of entries that this queue will handle. |
| 12041 | * |
| 12042 | * This function allocates a queue structure and the DMAable memory used for |
| 12043 | * the host resident queue. This function must be called before creating the |
| 12044 | * queue on the HBA. |
| 12045 | **/ |
| 12046 | struct lpfc_queue * |
| 12047 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12048 | uint32_t entry_count) |
| 12049 | { |
| 12050 | struct lpfc_queue *queue; |
| 12051 | struct lpfc_dmabuf *dmabuf; |
| 12052 | int x, total_qe_count; |
| 12053 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12054 | 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] | 12055 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12056 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12057 | hw_page_size = SLI4_PAGE_SIZE; |
| 12058 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12059 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12060 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12061 | if (!queue) |
| 12062 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12063 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12064 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12065 | INIT_LIST_HEAD(&queue->list); |
| 12066 | INIT_LIST_HEAD(&queue->page_list); |
| 12067 | INIT_LIST_HEAD(&queue->child_list); |
| 12068 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12069 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12070 | if (!dmabuf) |
| 12071 | goto out_fail; |
| 12072 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12073 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12074 | GFP_KERNEL); |
| 12075 | if (!dmabuf->virt) { |
| 12076 | kfree(dmabuf); |
| 12077 | goto out_fail; |
| 12078 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12079 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12080 | dmabuf->buffer_tag = x; |
| 12081 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12082 | /* initialize queue's entry array */ |
| 12083 | dma_pointer = dmabuf->virt; |
| 12084 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12085 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12086 | total_qe_count++, dma_pointer += entry_size) { |
| 12087 | queue->qe[total_qe_count].address = dma_pointer; |
| 12088 | } |
| 12089 | } |
| 12090 | queue->entry_size = entry_size; |
| 12091 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12092 | |
| 12093 | /* |
| 12094 | * entry_repost is calculated based on the number of entries in the |
| 12095 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12096 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12097 | */ |
| 12098 | queue->entry_repost = (entry_count >> 3); |
| 12099 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12100 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12101 | queue->phba = phba; |
| 12102 | |
| 12103 | return queue; |
| 12104 | out_fail: |
| 12105 | lpfc_sli4_queue_free(queue); |
| 12106 | return NULL; |
| 12107 | } |
| 12108 | |
| 12109 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12110 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12111 | * @phba: HBA structure that indicates port to create a queue on. |
| 12112 | * @startq: The starting FCP EQ to modify |
| 12113 | * |
| 12114 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12115 | * |
| 12116 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12117 | * is used to get the starting FCP EQ to change. |
| 12118 | * This function is asynchronous and will wait for the mailbox |
| 12119 | * command to finish before continuing. |
| 12120 | * |
| 12121 | * On success this function will return a zero. If unable to allocate enough |
| 12122 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12123 | * fails this function will return -ENXIO. |
| 12124 | **/ |
| 12125 | uint32_t |
| 12126 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12127 | { |
| 12128 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12129 | LPFC_MBOXQ_t *mbox; |
| 12130 | struct lpfc_queue *eq; |
| 12131 | int cnt, rc, length, status = 0; |
| 12132 | uint32_t shdr_status, shdr_add_status; |
| 12133 | int fcp_eqidx; |
| 12134 | union lpfc_sli4_cfg_shdr *shdr; |
| 12135 | uint16_t dmult; |
| 12136 | |
| 12137 | if (startq >= phba->cfg_fcp_eq_count) |
| 12138 | return 0; |
| 12139 | |
| 12140 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12141 | if (!mbox) |
| 12142 | return -ENOMEM; |
| 12143 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12144 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12145 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12146 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12147 | length, LPFC_SLI4_MBX_EMBED); |
| 12148 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12149 | |
| 12150 | /* Calculate delay multiper from maximum interrupt per second */ |
| 12151 | dmult = LPFC_DMULT_CONST/phba->cfg_fcp_imax - 1; |
| 12152 | |
| 12153 | cnt = 0; |
| 12154 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 12155 | fcp_eqidx++) { |
| 12156 | eq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
| 12157 | if (!eq) |
| 12158 | continue; |
| 12159 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12160 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12161 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12162 | cnt++; |
| 12163 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12164 | break; |
| 12165 | } |
| 12166 | eq_delay->u.request.num_eq = cnt; |
| 12167 | |
| 12168 | mbox->vport = phba->pport; |
| 12169 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12170 | mbox->context1 = NULL; |
| 12171 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12172 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12173 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12174 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12175 | if (shdr_status || shdr_add_status || rc) { |
| 12176 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12177 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12178 | "status x%x add_status x%x, mbx status x%x\n", |
| 12179 | shdr_status, shdr_add_status, rc); |
| 12180 | status = -ENXIO; |
| 12181 | } |
| 12182 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12183 | return status; |
| 12184 | } |
| 12185 | |
| 12186 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12187 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12188 | * @phba: HBA structure that indicates port to create a queue on. |
| 12189 | * @eq: The queue structure to use to create the event queue. |
| 12190 | * @imax: The maximum interrupt per second limit. |
| 12191 | * |
| 12192 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12193 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12194 | * |
| 12195 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12196 | * is used to get the entry count and entry size that are necessary to |
| 12197 | * determine the number of pages to allocate and use for this queue. This |
| 12198 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12199 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12200 | * command to finish before continuing. |
| 12201 | * |
| 12202 | * 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] | 12203 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12204 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12205 | **/ |
| 12206 | uint32_t |
| 12207 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) |
| 12208 | { |
| 12209 | struct lpfc_mbx_eq_create *eq_create; |
| 12210 | LPFC_MBOXQ_t *mbox; |
| 12211 | int rc, length, status = 0; |
| 12212 | struct lpfc_dmabuf *dmabuf; |
| 12213 | uint32_t shdr_status, shdr_add_status; |
| 12214 | union lpfc_sli4_cfg_shdr *shdr; |
| 12215 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12216 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12217 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12218 | /* sanity check on queue memory */ |
| 12219 | if (!eq) |
| 12220 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12221 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12222 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12223 | |
| 12224 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12225 | if (!mbox) |
| 12226 | return -ENOMEM; |
| 12227 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12228 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12229 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12230 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12231 | length, LPFC_SLI4_MBX_EMBED); |
| 12232 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12233 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12234 | eq->page_count); |
| 12235 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12236 | LPFC_EQE_SIZE); |
| 12237 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12238 | /* Calculate delay multiper from maximum interrupt per second */ |
| 12239 | dmult = LPFC_DMULT_CONST/imax - 1; |
| 12240 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12241 | dmult); |
| 12242 | switch (eq->entry_count) { |
| 12243 | default: |
| 12244 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12245 | "0360 Unsupported EQ count. (%d)\n", |
| 12246 | eq->entry_count); |
| 12247 | if (eq->entry_count < 256) |
| 12248 | return -EINVAL; |
| 12249 | /* otherwise default to smallest count (drop through) */ |
| 12250 | case 256: |
| 12251 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12252 | LPFC_EQ_CNT_256); |
| 12253 | break; |
| 12254 | case 512: |
| 12255 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12256 | LPFC_EQ_CNT_512); |
| 12257 | break; |
| 12258 | case 1024: |
| 12259 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12260 | LPFC_EQ_CNT_1024); |
| 12261 | break; |
| 12262 | case 2048: |
| 12263 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12264 | LPFC_EQ_CNT_2048); |
| 12265 | break; |
| 12266 | case 4096: |
| 12267 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12268 | LPFC_EQ_CNT_4096); |
| 12269 | break; |
| 12270 | } |
| 12271 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12272 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12273 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12274 | putPaddrLow(dmabuf->phys); |
| 12275 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12276 | putPaddrHigh(dmabuf->phys); |
| 12277 | } |
| 12278 | mbox->vport = phba->pport; |
| 12279 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12280 | mbox->context1 = NULL; |
| 12281 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12282 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12283 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12284 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12285 | if (shdr_status || shdr_add_status || rc) { |
| 12286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12287 | "2500 EQ_CREATE mailbox failed with " |
| 12288 | "status x%x add_status x%x, mbx status x%x\n", |
| 12289 | shdr_status, shdr_add_status, rc); |
| 12290 | status = -ENXIO; |
| 12291 | } |
| 12292 | eq->type = LPFC_EQ; |
| 12293 | eq->subtype = LPFC_NONE; |
| 12294 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12295 | if (eq->queue_id == 0xFFFF) |
| 12296 | status = -ENXIO; |
| 12297 | eq->host_index = 0; |
| 12298 | eq->hba_index = 0; |
| 12299 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12300 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12301 | return status; |
| 12302 | } |
| 12303 | |
| 12304 | /** |
| 12305 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12306 | * @phba: HBA structure that indicates port to create a queue on. |
| 12307 | * @cq: The queue structure to use to create the completion queue. |
| 12308 | * @eq: The event queue to bind this completion queue to. |
| 12309 | * |
| 12310 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12311 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12312 | * |
| 12313 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12314 | * is used to get the entry count and entry size that are necessary to |
| 12315 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12316 | * is used to indicate which event queue to bind this completion queue to. This |
| 12317 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12318 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12319 | * command to finish before continuing. |
| 12320 | * |
| 12321 | * 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] | 12322 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12323 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12324 | **/ |
| 12325 | uint32_t |
| 12326 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12327 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12328 | { |
| 12329 | struct lpfc_mbx_cq_create *cq_create; |
| 12330 | struct lpfc_dmabuf *dmabuf; |
| 12331 | LPFC_MBOXQ_t *mbox; |
| 12332 | int rc, length, status = 0; |
| 12333 | uint32_t shdr_status, shdr_add_status; |
| 12334 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12335 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12336 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12337 | /* sanity check on queue memory */ |
| 12338 | if (!cq || !eq) |
| 12339 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12340 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12341 | hw_page_size = SLI4_PAGE_SIZE; |
| 12342 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12343 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12344 | if (!mbox) |
| 12345 | return -ENOMEM; |
| 12346 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12347 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12348 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12349 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12350 | length, LPFC_SLI4_MBX_EMBED); |
| 12351 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12352 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12353 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12354 | cq->page_count); |
| 12355 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12356 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12357 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12358 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12359 | 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] | 12360 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12361 | 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] | 12362 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12363 | eq->queue_id); |
| 12364 | } else { |
| 12365 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12366 | eq->queue_id); |
| 12367 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12368 | switch (cq->entry_count) { |
| 12369 | default: |
| 12370 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12371 | "0361 Unsupported CQ count. (%d)\n", |
| 12372 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12373 | if (cq->entry_count < 256) { |
| 12374 | status = -EINVAL; |
| 12375 | goto out; |
| 12376 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12377 | /* otherwise default to smallest count (drop through) */ |
| 12378 | case 256: |
| 12379 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12380 | LPFC_CQ_CNT_256); |
| 12381 | break; |
| 12382 | case 512: |
| 12383 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12384 | LPFC_CQ_CNT_512); |
| 12385 | break; |
| 12386 | case 1024: |
| 12387 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12388 | LPFC_CQ_CNT_1024); |
| 12389 | break; |
| 12390 | } |
| 12391 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12392 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12393 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12394 | putPaddrLow(dmabuf->phys); |
| 12395 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12396 | putPaddrHigh(dmabuf->phys); |
| 12397 | } |
| 12398 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12399 | |
| 12400 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12401 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12402 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12403 | if (shdr_status || shdr_add_status || rc) { |
| 12404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12405 | "2501 CQ_CREATE mailbox failed with " |
| 12406 | "status x%x add_status x%x, mbx status x%x\n", |
| 12407 | shdr_status, shdr_add_status, rc); |
| 12408 | status = -ENXIO; |
| 12409 | goto out; |
| 12410 | } |
| 12411 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12412 | if (cq->queue_id == 0xFFFF) { |
| 12413 | status = -ENXIO; |
| 12414 | goto out; |
| 12415 | } |
| 12416 | /* link the cq onto the parent eq child list */ |
| 12417 | list_add_tail(&cq->list, &eq->child_list); |
| 12418 | /* Set up completion queue's type and subtype */ |
| 12419 | cq->type = type; |
| 12420 | cq->subtype = subtype; |
| 12421 | 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] | 12422 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12423 | cq->host_index = 0; |
| 12424 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12425 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12426 | out: |
| 12427 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12428 | return status; |
| 12429 | } |
| 12430 | |
| 12431 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12432 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12433 | * @phba: HBA structure that indicates port to create a queue on. |
| 12434 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12435 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12436 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12437 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12438 | * This function provides failback (fb) functionality when the |
| 12439 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12440 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12441 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12442 | * This routine cannot fail as all attributes were previously accessed and |
| 12443 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12444 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12445 | static void |
| 12446 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12447 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12448 | { |
| 12449 | struct lpfc_mbx_mq_create *mq_create; |
| 12450 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12451 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12452 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12453 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12454 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12455 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12456 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12457 | length, LPFC_SLI4_MBX_EMBED); |
| 12458 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12459 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12460 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12461 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12462 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12463 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12464 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12465 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12466 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12467 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12468 | break; |
| 12469 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12470 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12471 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12472 | break; |
| 12473 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12474 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12475 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12476 | break; |
| 12477 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12478 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12479 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12480 | break; |
| 12481 | } |
| 12482 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12483 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12484 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12485 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12486 | putPaddrHigh(dmabuf->phys); |
| 12487 | } |
| 12488 | } |
| 12489 | |
| 12490 | /** |
| 12491 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12492 | * @phba: HBA structure that indicates port to create a queue on. |
| 12493 | * @mq: The queue structure to use to create the mailbox queue. |
| 12494 | * @cq: The completion queue to associate with this cq. |
| 12495 | * @subtype: The queue's subtype. |
| 12496 | * |
| 12497 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12498 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12499 | * |
| 12500 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12501 | * is used to get the entry count and entry size that are necessary to |
| 12502 | * determine the number of pages to allocate and use for this queue. This |
| 12503 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12504 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12505 | * command to finish before continuing. |
| 12506 | * |
| 12507 | * 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] | 12508 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12509 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12510 | **/ |
| 12511 | int32_t |
| 12512 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12513 | struct lpfc_queue *cq, uint32_t subtype) |
| 12514 | { |
| 12515 | struct lpfc_mbx_mq_create *mq_create; |
| 12516 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12517 | struct lpfc_dmabuf *dmabuf; |
| 12518 | LPFC_MBOXQ_t *mbox; |
| 12519 | int rc, length, status = 0; |
| 12520 | uint32_t shdr_status, shdr_add_status; |
| 12521 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12522 | 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] | 12523 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12524 | /* sanity check on queue memory */ |
| 12525 | if (!mq || !cq) |
| 12526 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12527 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12528 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12529 | |
| 12530 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12531 | if (!mbox) |
| 12532 | return -ENOMEM; |
| 12533 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12534 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12535 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12536 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12537 | length, LPFC_SLI4_MBX_EMBED); |
| 12538 | |
| 12539 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12540 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12541 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12542 | &mq_create_ext->u.request, mq->page_count); |
| 12543 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12544 | &mq_create_ext->u.request, 1); |
| 12545 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12546 | &mq_create_ext->u.request, 1); |
| 12547 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12548 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12549 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12550 | &mq_create_ext->u.request, 1); |
| 12551 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12552 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12553 | 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] | 12554 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12555 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12556 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12557 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12558 | cq->queue_id); |
| 12559 | else |
| 12560 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12561 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12562 | switch (mq->entry_count) { |
| 12563 | default: |
| 12564 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12565 | "0362 Unsupported MQ count. (%d)\n", |
| 12566 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12567 | if (mq->entry_count < 16) { |
| 12568 | status = -EINVAL; |
| 12569 | goto out; |
| 12570 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12571 | /* otherwise default to smallest count (drop through) */ |
| 12572 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12573 | bf_set(lpfc_mq_context_ring_size, |
| 12574 | &mq_create_ext->u.request.context, |
| 12575 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12576 | break; |
| 12577 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12578 | bf_set(lpfc_mq_context_ring_size, |
| 12579 | &mq_create_ext->u.request.context, |
| 12580 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12581 | break; |
| 12582 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12583 | bf_set(lpfc_mq_context_ring_size, |
| 12584 | &mq_create_ext->u.request.context, |
| 12585 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12586 | break; |
| 12587 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12588 | bf_set(lpfc_mq_context_ring_size, |
| 12589 | &mq_create_ext->u.request.context, |
| 12590 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12591 | break; |
| 12592 | } |
| 12593 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12594 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12595 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12596 | putPaddrLow(dmabuf->phys); |
| 12597 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12598 | putPaddrHigh(dmabuf->phys); |
| 12599 | } |
| 12600 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12601 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12602 | &mq_create_ext->u.response); |
| 12603 | if (rc != MBX_SUCCESS) { |
| 12604 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12605 | "2795 MQ_CREATE_EXT failed with " |
| 12606 | "status x%x. Failback to MQ_CREATE.\n", |
| 12607 | rc); |
| 12608 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12609 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12610 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12611 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12612 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12613 | &mq_create->u.response); |
| 12614 | } |
| 12615 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12616 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12617 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12618 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12619 | if (shdr_status || shdr_add_status || rc) { |
| 12620 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12621 | "2502 MQ_CREATE mailbox failed with " |
| 12622 | "status x%x add_status x%x, mbx status x%x\n", |
| 12623 | shdr_status, shdr_add_status, rc); |
| 12624 | status = -ENXIO; |
| 12625 | goto out; |
| 12626 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12627 | if (mq->queue_id == 0xFFFF) { |
| 12628 | status = -ENXIO; |
| 12629 | goto out; |
| 12630 | } |
| 12631 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12632 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12633 | mq->subtype = subtype; |
| 12634 | mq->host_index = 0; |
| 12635 | mq->hba_index = 0; |
| 12636 | |
| 12637 | /* link the mq onto the parent cq child list */ |
| 12638 | list_add_tail(&mq->list, &cq->child_list); |
| 12639 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12640 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12641 | return status; |
| 12642 | } |
| 12643 | |
| 12644 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12645 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12646 | * @phba: HBA structure that indicates port to create a queue on. |
| 12647 | * @wq: The queue structure to use to create the work queue. |
| 12648 | * @cq: The completion queue to bind this work queue to. |
| 12649 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12650 | * |
| 12651 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12652 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12653 | * |
| 12654 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12655 | * is used to get the entry count and entry size that are necessary to |
| 12656 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12657 | * is used to indicate which completion queue to bind this work queue to. This |
| 12658 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12659 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12660 | * command to finish before continuing. |
| 12661 | * |
| 12662 | * 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] | 12663 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12664 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12665 | **/ |
| 12666 | uint32_t |
| 12667 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12668 | struct lpfc_queue *cq, uint32_t subtype) |
| 12669 | { |
| 12670 | struct lpfc_mbx_wq_create *wq_create; |
| 12671 | struct lpfc_dmabuf *dmabuf; |
| 12672 | LPFC_MBOXQ_t *mbox; |
| 12673 | int rc, length, status = 0; |
| 12674 | uint32_t shdr_status, shdr_add_status; |
| 12675 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12676 | 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] | 12677 | struct dma_address *page; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12678 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12679 | /* sanity check on queue memory */ |
| 12680 | if (!wq || !cq) |
| 12681 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12682 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12683 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12684 | |
| 12685 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12686 | if (!mbox) |
| 12687 | return -ENOMEM; |
| 12688 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12689 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12690 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12691 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12692 | length, LPFC_SLI4_MBX_EMBED); |
| 12693 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12694 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12695 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12696 | wq->page_count); |
| 12697 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12698 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12699 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12700 | phba->sli4_hba.pc_sli4_params.wqv); |
| 12701 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12702 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12703 | wq->entry_count); |
| 12704 | switch (wq->entry_size) { |
| 12705 | default: |
| 12706 | case 64: |
| 12707 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12708 | &wq_create->u.request_1, |
| 12709 | LPFC_WQ_WQE_SIZE_64); |
| 12710 | break; |
| 12711 | case 128: |
| 12712 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12713 | &wq_create->u.request_1, |
| 12714 | LPFC_WQ_WQE_SIZE_128); |
| 12715 | break; |
| 12716 | } |
| 12717 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12718 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12719 | page = wq_create->u.request_1.page; |
| 12720 | } else { |
| 12721 | page = wq_create->u.request.page; |
| 12722 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12723 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12724 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12725 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12726 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12727 | } |
| 12728 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12729 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12730 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12731 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12732 | if (shdr_status || shdr_add_status || rc) { |
| 12733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12734 | "2503 WQ_CREATE mailbox failed with " |
| 12735 | "status x%x add_status x%x, mbx status x%x\n", |
| 12736 | shdr_status, shdr_add_status, rc); |
| 12737 | status = -ENXIO; |
| 12738 | goto out; |
| 12739 | } |
| 12740 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12741 | if (wq->queue_id == 0xFFFF) { |
| 12742 | status = -ENXIO; |
| 12743 | goto out; |
| 12744 | } |
| 12745 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12746 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12747 | wq->subtype = subtype; |
| 12748 | wq->host_index = 0; |
| 12749 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12750 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12751 | |
| 12752 | /* link the wq onto the parent cq child list */ |
| 12753 | list_add_tail(&wq->list, &cq->child_list); |
| 12754 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12755 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12756 | return status; |
| 12757 | } |
| 12758 | |
| 12759 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12760 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12761 | * @phba: HBA structure that indicates port to create a queue on. |
| 12762 | * @rq: The queue structure to use for the receive queue. |
| 12763 | * @qno: The associated HBQ number |
| 12764 | * |
| 12765 | * |
| 12766 | * For SLI4 we need to adjust the RQ repost value based on |
| 12767 | * the number of buffers that are initially posted to the RQ. |
| 12768 | */ |
| 12769 | void |
| 12770 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12771 | { |
| 12772 | uint32_t cnt; |
| 12773 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12774 | /* sanity check on queue memory */ |
| 12775 | if (!rq) |
| 12776 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12777 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12778 | |
| 12779 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12780 | cnt = (cnt >> 3); |
| 12781 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12782 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12783 | |
| 12784 | rq->entry_repost = cnt; |
| 12785 | } |
| 12786 | |
| 12787 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12788 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12789 | * @phba: HBA structure that indicates port to create a queue on. |
| 12790 | * @hrq: The queue structure to use to create the header receive queue. |
| 12791 | * @drq: The queue structure to use to create the data receive queue. |
| 12792 | * @cq: The completion queue to bind this work queue to. |
| 12793 | * |
| 12794 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12795 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12796 | * to the HBA. |
| 12797 | * |
| 12798 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12799 | * struct is used to get the entry count that is necessary to determine the |
| 12800 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12801 | * completion queue to bind received buffers that are posted to these queues to. |
| 12802 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12803 | * receive queue pair. This function is asynchronous and will wait for the |
| 12804 | * mailbox command to finish before continuing. |
| 12805 | * |
| 12806 | * 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] | 12807 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12808 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12809 | **/ |
| 12810 | uint32_t |
| 12811 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12812 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12813 | { |
| 12814 | struct lpfc_mbx_rq_create *rq_create; |
| 12815 | struct lpfc_dmabuf *dmabuf; |
| 12816 | LPFC_MBOXQ_t *mbox; |
| 12817 | int rc, length, status = 0; |
| 12818 | uint32_t shdr_status, shdr_add_status; |
| 12819 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12820 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12821 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12822 | /* sanity check on queue memory */ |
| 12823 | if (!hrq || !drq || !cq) |
| 12824 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12825 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12826 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12827 | |
| 12828 | if (hrq->entry_count != drq->entry_count) |
| 12829 | return -EINVAL; |
| 12830 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12831 | if (!mbox) |
| 12832 | return -ENOMEM; |
| 12833 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12834 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12835 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12836 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12837 | length, LPFC_SLI4_MBX_EMBED); |
| 12838 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12839 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12840 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12841 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12842 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12843 | bf_set(lpfc_rq_context_rqe_count_1, |
| 12844 | &rq_create->u.request.context, |
| 12845 | hrq->entry_count); |
| 12846 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12847 | bf_set(lpfc_rq_context_rqe_size, |
| 12848 | &rq_create->u.request.context, |
| 12849 | LPFC_RQE_SIZE_8); |
| 12850 | bf_set(lpfc_rq_context_page_size, |
| 12851 | &rq_create->u.request.context, |
| 12852 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12853 | } else { |
| 12854 | switch (hrq->entry_count) { |
| 12855 | default: |
| 12856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12857 | "2535 Unsupported RQ count. (%d)\n", |
| 12858 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12859 | if (hrq->entry_count < 512) { |
| 12860 | status = -EINVAL; |
| 12861 | goto out; |
| 12862 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12863 | /* otherwise default to smallest count (drop through) */ |
| 12864 | case 512: |
| 12865 | bf_set(lpfc_rq_context_rqe_count, |
| 12866 | &rq_create->u.request.context, |
| 12867 | LPFC_RQ_RING_SIZE_512); |
| 12868 | break; |
| 12869 | case 1024: |
| 12870 | bf_set(lpfc_rq_context_rqe_count, |
| 12871 | &rq_create->u.request.context, |
| 12872 | LPFC_RQ_RING_SIZE_1024); |
| 12873 | break; |
| 12874 | case 2048: |
| 12875 | bf_set(lpfc_rq_context_rqe_count, |
| 12876 | &rq_create->u.request.context, |
| 12877 | LPFC_RQ_RING_SIZE_2048); |
| 12878 | break; |
| 12879 | case 4096: |
| 12880 | bf_set(lpfc_rq_context_rqe_count, |
| 12881 | &rq_create->u.request.context, |
| 12882 | LPFC_RQ_RING_SIZE_4096); |
| 12883 | break; |
| 12884 | } |
| 12885 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12886 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12887 | } |
| 12888 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12889 | cq->queue_id); |
| 12890 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12891 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12892 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12893 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12894 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12895 | putPaddrLow(dmabuf->phys); |
| 12896 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12897 | putPaddrHigh(dmabuf->phys); |
| 12898 | } |
| 12899 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12900 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12901 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12902 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12903 | if (shdr_status || shdr_add_status || rc) { |
| 12904 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12905 | "2504 RQ_CREATE mailbox failed with " |
| 12906 | "status x%x add_status x%x, mbx status x%x\n", |
| 12907 | shdr_status, shdr_add_status, rc); |
| 12908 | status = -ENXIO; |
| 12909 | goto out; |
| 12910 | } |
| 12911 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12912 | if (hrq->queue_id == 0xFFFF) { |
| 12913 | status = -ENXIO; |
| 12914 | goto out; |
| 12915 | } |
| 12916 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12917 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12918 | hrq->subtype = subtype; |
| 12919 | hrq->host_index = 0; |
| 12920 | hrq->hba_index = 0; |
| 12921 | |
| 12922 | /* now create the data queue */ |
| 12923 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12924 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12925 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12926 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12927 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12928 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12929 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12930 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12931 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12932 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 12933 | LPFC_RQE_SIZE_8); |
| 12934 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 12935 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12936 | } else { |
| 12937 | switch (drq->entry_count) { |
| 12938 | default: |
| 12939 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12940 | "2536 Unsupported RQ count. (%d)\n", |
| 12941 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12942 | if (drq->entry_count < 512) { |
| 12943 | status = -EINVAL; |
| 12944 | goto out; |
| 12945 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12946 | /* otherwise default to smallest count (drop through) */ |
| 12947 | case 512: |
| 12948 | bf_set(lpfc_rq_context_rqe_count, |
| 12949 | &rq_create->u.request.context, |
| 12950 | LPFC_RQ_RING_SIZE_512); |
| 12951 | break; |
| 12952 | case 1024: |
| 12953 | bf_set(lpfc_rq_context_rqe_count, |
| 12954 | &rq_create->u.request.context, |
| 12955 | LPFC_RQ_RING_SIZE_1024); |
| 12956 | break; |
| 12957 | case 2048: |
| 12958 | bf_set(lpfc_rq_context_rqe_count, |
| 12959 | &rq_create->u.request.context, |
| 12960 | LPFC_RQ_RING_SIZE_2048); |
| 12961 | break; |
| 12962 | case 4096: |
| 12963 | bf_set(lpfc_rq_context_rqe_count, |
| 12964 | &rq_create->u.request.context, |
| 12965 | LPFC_RQ_RING_SIZE_4096); |
| 12966 | break; |
| 12967 | } |
| 12968 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12969 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12970 | } |
| 12971 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12972 | cq->queue_id); |
| 12973 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12974 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12975 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 12976 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12977 | putPaddrLow(dmabuf->phys); |
| 12978 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12979 | putPaddrHigh(dmabuf->phys); |
| 12980 | } |
| 12981 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12982 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12983 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12984 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12985 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12986 | if (shdr_status || shdr_add_status || rc) { |
| 12987 | status = -ENXIO; |
| 12988 | goto out; |
| 12989 | } |
| 12990 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12991 | if (drq->queue_id == 0xFFFF) { |
| 12992 | status = -ENXIO; |
| 12993 | goto out; |
| 12994 | } |
| 12995 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12996 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12997 | drq->subtype = subtype; |
| 12998 | drq->host_index = 0; |
| 12999 | drq->hba_index = 0; |
| 13000 | |
| 13001 | /* link the header and data RQs onto the parent cq child list */ |
| 13002 | list_add_tail(&hrq->list, &cq->child_list); |
| 13003 | list_add_tail(&drq->list, &cq->child_list); |
| 13004 | |
| 13005 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13006 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13007 | return status; |
| 13008 | } |
| 13009 | |
| 13010 | /** |
| 13011 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13012 | * @eq: The queue structure associated with the queue to destroy. |
| 13013 | * |
| 13014 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13015 | * command, specific to the type of queue, to the HBA. |
| 13016 | * |
| 13017 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13018 | * |
| 13019 | * 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] | 13020 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13021 | **/ |
| 13022 | uint32_t |
| 13023 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13024 | { |
| 13025 | LPFC_MBOXQ_t *mbox; |
| 13026 | int rc, length, status = 0; |
| 13027 | uint32_t shdr_status, shdr_add_status; |
| 13028 | union lpfc_sli4_cfg_shdr *shdr; |
| 13029 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13030 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13031 | if (!eq) |
| 13032 | return -ENODEV; |
| 13033 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13034 | if (!mbox) |
| 13035 | return -ENOMEM; |
| 13036 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13037 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13038 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13039 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13040 | length, LPFC_SLI4_MBX_EMBED); |
| 13041 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13042 | eq->queue_id); |
| 13043 | mbox->vport = eq->phba->pport; |
| 13044 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13045 | |
| 13046 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13047 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13048 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13049 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13050 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13051 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13052 | if (shdr_status || shdr_add_status || rc) { |
| 13053 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13054 | "2505 EQ_DESTROY mailbox failed with " |
| 13055 | "status x%x add_status x%x, mbx status x%x\n", |
| 13056 | shdr_status, shdr_add_status, rc); |
| 13057 | status = -ENXIO; |
| 13058 | } |
| 13059 | |
| 13060 | /* Remove eq from any list */ |
| 13061 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13062 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13063 | return status; |
| 13064 | } |
| 13065 | |
| 13066 | /** |
| 13067 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13068 | * @cq: The queue structure associated with the queue to destroy. |
| 13069 | * |
| 13070 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13071 | * command, specific to the type of queue, to the HBA. |
| 13072 | * |
| 13073 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13074 | * |
| 13075 | * 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] | 13076 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13077 | **/ |
| 13078 | uint32_t |
| 13079 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13080 | { |
| 13081 | LPFC_MBOXQ_t *mbox; |
| 13082 | int rc, length, status = 0; |
| 13083 | uint32_t shdr_status, shdr_add_status; |
| 13084 | union lpfc_sli4_cfg_shdr *shdr; |
| 13085 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13086 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13087 | if (!cq) |
| 13088 | return -ENODEV; |
| 13089 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13090 | if (!mbox) |
| 13091 | return -ENOMEM; |
| 13092 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13093 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13094 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13095 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13096 | length, LPFC_SLI4_MBX_EMBED); |
| 13097 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13098 | cq->queue_id); |
| 13099 | mbox->vport = cq->phba->pport; |
| 13100 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13101 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13102 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13103 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13104 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13105 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13106 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13107 | if (shdr_status || shdr_add_status || rc) { |
| 13108 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13109 | "2506 CQ_DESTROY mailbox failed with " |
| 13110 | "status x%x add_status x%x, mbx status x%x\n", |
| 13111 | shdr_status, shdr_add_status, rc); |
| 13112 | status = -ENXIO; |
| 13113 | } |
| 13114 | /* Remove cq from any list */ |
| 13115 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13116 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13117 | return status; |
| 13118 | } |
| 13119 | |
| 13120 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13121 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13122 | * @qm: The queue structure associated with the queue to destroy. |
| 13123 | * |
| 13124 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13125 | * command, specific to the type of queue, to the HBA. |
| 13126 | * |
| 13127 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13128 | * |
| 13129 | * 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] | 13130 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13131 | **/ |
| 13132 | uint32_t |
| 13133 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13134 | { |
| 13135 | LPFC_MBOXQ_t *mbox; |
| 13136 | int rc, length, status = 0; |
| 13137 | uint32_t shdr_status, shdr_add_status; |
| 13138 | union lpfc_sli4_cfg_shdr *shdr; |
| 13139 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13140 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13141 | if (!mq) |
| 13142 | return -ENODEV; |
| 13143 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13144 | if (!mbox) |
| 13145 | return -ENOMEM; |
| 13146 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13147 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13148 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13149 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13150 | length, LPFC_SLI4_MBX_EMBED); |
| 13151 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13152 | mq->queue_id); |
| 13153 | mbox->vport = mq->phba->pport; |
| 13154 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13155 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13156 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13157 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13158 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13159 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13160 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13161 | if (shdr_status || shdr_add_status || rc) { |
| 13162 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13163 | "2507 MQ_DESTROY mailbox failed with " |
| 13164 | "status x%x add_status x%x, mbx status x%x\n", |
| 13165 | shdr_status, shdr_add_status, rc); |
| 13166 | status = -ENXIO; |
| 13167 | } |
| 13168 | /* Remove mq from any list */ |
| 13169 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13170 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13171 | return status; |
| 13172 | } |
| 13173 | |
| 13174 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13175 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13176 | * @wq: The queue structure associated with the queue to destroy. |
| 13177 | * |
| 13178 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13179 | * command, specific to the type of queue, to the HBA. |
| 13180 | * |
| 13181 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13182 | * |
| 13183 | * 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] | 13184 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13185 | **/ |
| 13186 | uint32_t |
| 13187 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13188 | { |
| 13189 | LPFC_MBOXQ_t *mbox; |
| 13190 | int rc, length, status = 0; |
| 13191 | uint32_t shdr_status, shdr_add_status; |
| 13192 | union lpfc_sli4_cfg_shdr *shdr; |
| 13193 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13194 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13195 | if (!wq) |
| 13196 | return -ENODEV; |
| 13197 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13198 | if (!mbox) |
| 13199 | return -ENOMEM; |
| 13200 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13201 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13202 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13203 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13204 | length, LPFC_SLI4_MBX_EMBED); |
| 13205 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13206 | wq->queue_id); |
| 13207 | mbox->vport = wq->phba->pport; |
| 13208 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13209 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13210 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13211 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13212 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13213 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13214 | if (shdr_status || shdr_add_status || rc) { |
| 13215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13216 | "2508 WQ_DESTROY mailbox failed with " |
| 13217 | "status x%x add_status x%x, mbx status x%x\n", |
| 13218 | shdr_status, shdr_add_status, rc); |
| 13219 | status = -ENXIO; |
| 13220 | } |
| 13221 | /* Remove wq from any list */ |
| 13222 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13223 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13224 | return status; |
| 13225 | } |
| 13226 | |
| 13227 | /** |
| 13228 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13229 | * @rq: The queue structure associated with the queue to destroy. |
| 13230 | * |
| 13231 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13232 | * command, specific to the type of queue, to the HBA. |
| 13233 | * |
| 13234 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13235 | * |
| 13236 | * 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] | 13237 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13238 | **/ |
| 13239 | uint32_t |
| 13240 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13241 | struct lpfc_queue *drq) |
| 13242 | { |
| 13243 | LPFC_MBOXQ_t *mbox; |
| 13244 | int rc, length, status = 0; |
| 13245 | uint32_t shdr_status, shdr_add_status; |
| 13246 | union lpfc_sli4_cfg_shdr *shdr; |
| 13247 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13248 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13249 | if (!hrq || !drq) |
| 13250 | return -ENODEV; |
| 13251 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13252 | if (!mbox) |
| 13253 | return -ENOMEM; |
| 13254 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13255 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13256 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13257 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13258 | length, LPFC_SLI4_MBX_EMBED); |
| 13259 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13260 | hrq->queue_id); |
| 13261 | mbox->vport = hrq->phba->pport; |
| 13262 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13263 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13264 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13265 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13266 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13267 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13268 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13269 | if (shdr_status || shdr_add_status || rc) { |
| 13270 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13271 | "2509 RQ_DESTROY mailbox failed with " |
| 13272 | "status x%x add_status x%x, mbx status x%x\n", |
| 13273 | shdr_status, shdr_add_status, rc); |
| 13274 | if (rc != MBX_TIMEOUT) |
| 13275 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13276 | return -ENXIO; |
| 13277 | } |
| 13278 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13279 | drq->queue_id); |
| 13280 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13281 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13282 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13283 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13284 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13285 | if (shdr_status || shdr_add_status || rc) { |
| 13286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13287 | "2510 RQ_DESTROY mailbox failed with " |
| 13288 | "status x%x add_status x%x, mbx status x%x\n", |
| 13289 | shdr_status, shdr_add_status, rc); |
| 13290 | status = -ENXIO; |
| 13291 | } |
| 13292 | list_del_init(&hrq->list); |
| 13293 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13294 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13295 | return status; |
| 13296 | } |
| 13297 | |
| 13298 | /** |
| 13299 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13300 | * @phba: The virtual port for which this call being executed. |
| 13301 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13302 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13303 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13304 | * |
| 13305 | * This routine will post the sgl pages for the IO that has the xritag |
| 13306 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13307 | * creation and persists for as long as the driver is loaded. |
| 13308 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13309 | * pdma_phys_addr1 should be 0. |
| 13310 | * If the caller needs to map more than 256 scatter gather segment then |
| 13311 | * pdma_phys_addr1 should be a valid physical address. |
| 13312 | * physical address for SGLs must be 64 byte aligned. |
| 13313 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13314 | * the second sgl can have between 1 and 256 entries. |
| 13315 | * |
| 13316 | * Return codes: |
| 13317 | * 0 - Success |
| 13318 | * -ENXIO, -ENOMEM - Failure |
| 13319 | **/ |
| 13320 | int |
| 13321 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13322 | dma_addr_t pdma_phys_addr0, |
| 13323 | dma_addr_t pdma_phys_addr1, |
| 13324 | uint16_t xritag) |
| 13325 | { |
| 13326 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13327 | LPFC_MBOXQ_t *mbox; |
| 13328 | int rc; |
| 13329 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13330 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13331 | union lpfc_sli4_cfg_shdr *shdr; |
| 13332 | |
| 13333 | if (xritag == NO_XRI) { |
| 13334 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13335 | "0364 Invalid param:\n"); |
| 13336 | return -EINVAL; |
| 13337 | } |
| 13338 | |
| 13339 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13340 | if (!mbox) |
| 13341 | return -ENOMEM; |
| 13342 | |
| 13343 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13344 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13345 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13346 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13347 | |
| 13348 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13349 | &mbox->u.mqe.un.post_sgl_pages; |
| 13350 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13351 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13352 | |
| 13353 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13354 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13355 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13356 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13357 | |
| 13358 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13359 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13360 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13361 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13362 | if (!phba->sli4_hba.intr_enable) |
| 13363 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13364 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13365 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13366 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13367 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13368 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13369 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13370 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13371 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13372 | if (rc != MBX_TIMEOUT) |
| 13373 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13374 | if (shdr_status || shdr_add_status || rc) { |
| 13375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13376 | "2511 POST_SGL mailbox failed with " |
| 13377 | "status x%x add_status x%x, mbx status x%x\n", |
| 13378 | shdr_status, shdr_add_status, rc); |
| 13379 | rc = -ENXIO; |
| 13380 | } |
| 13381 | return 0; |
| 13382 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13383 | |
| 13384 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13385 | * 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] | 13386 | * @phba: pointer to lpfc hba data structure. |
| 13387 | * |
| 13388 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13389 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13390 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13391 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13392 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13393 | * Returns |
| 13394 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13395 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13396 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13397 | uint16_t |
| 13398 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13399 | { |
| 13400 | unsigned long xri; |
| 13401 | |
| 13402 | /* |
| 13403 | * Fetch the next logical xri. Because this index is logical, |
| 13404 | * the driver starts at 0 each time. |
| 13405 | */ |
| 13406 | spin_lock_irq(&phba->hbalock); |
| 13407 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13408 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13409 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13410 | spin_unlock_irq(&phba->hbalock); |
| 13411 | return NO_XRI; |
| 13412 | } else { |
| 13413 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13414 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13415 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13416 | spin_unlock_irq(&phba->hbalock); |
| 13417 | return xri; |
| 13418 | } |
| 13419 | |
| 13420 | /** |
| 13421 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13422 | * @phba: pointer to lpfc hba data structure. |
| 13423 | * |
| 13424 | * This routine is invoked to release an xri to the pool of |
| 13425 | * available rpis maintained by the driver. |
| 13426 | **/ |
| 13427 | void |
| 13428 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13429 | { |
| 13430 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13431 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13432 | } |
| 13433 | } |
| 13434 | |
| 13435 | /** |
| 13436 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13437 | * @phba: pointer to lpfc hba data structure. |
| 13438 | * |
| 13439 | * This routine is invoked to release an xri to the pool of |
| 13440 | * available rpis maintained by the driver. |
| 13441 | **/ |
| 13442 | void |
| 13443 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13444 | { |
| 13445 | spin_lock_irq(&phba->hbalock); |
| 13446 | __lpfc_sli4_free_xri(phba, xri); |
| 13447 | spin_unlock_irq(&phba->hbalock); |
| 13448 | } |
| 13449 | |
| 13450 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13451 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13452 | * @phba: Pointer to HBA context object. |
| 13453 | * |
| 13454 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13455 | * it will return 0xffff. |
| 13456 | * The function returns the allocated xritag if successful, else returns zero. |
| 13457 | * Zero is not a valid xritag. |
| 13458 | * The caller is not required to hold any lock. |
| 13459 | **/ |
| 13460 | uint16_t |
| 13461 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13462 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13463 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13464 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13465 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13466 | if (xri_index == NO_XRI) |
| 13467 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13468 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13469 | " Max XRI is %d, Used XRI is %d\n", |
| 13470 | xri_index, |
| 13471 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13472 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13473 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13474 | } |
| 13475 | |
| 13476 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13477 | * 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] | 13478 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13479 | * @post_sgl_list: pointer to els sgl entry list. |
| 13480 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13481 | * |
| 13482 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13483 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13484 | * is only called when the driver is loading and after all IO has been |
| 13485 | * stopped. |
| 13486 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13487 | static int |
| 13488 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13489 | struct list_head *post_sgl_list, |
| 13490 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13491 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13492 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13493 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13494 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13495 | void *viraddr; |
| 13496 | LPFC_MBOXQ_t *mbox; |
| 13497 | uint32_t reqlen, alloclen, pg_pairs; |
| 13498 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13499 | uint16_t xritag_start = 0; |
| 13500 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13501 | uint32_t shdr_status, shdr_add_status; |
| 13502 | union lpfc_sli4_cfg_shdr *shdr; |
| 13503 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13504 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13505 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13506 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13507 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13508 | "2559 Block sgl registration required DMA " |
| 13509 | "size (%d) great than a page\n", reqlen); |
| 13510 | return -ENOMEM; |
| 13511 | } |
| 13512 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13513 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13514 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13515 | |
| 13516 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13517 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13518 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13519 | LPFC_SLI4_MBX_NEMBED); |
| 13520 | |
| 13521 | if (alloclen < reqlen) { |
| 13522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13523 | "0285 Allocated DMA memory size (%d) is " |
| 13524 | "less than the requested DMA memory " |
| 13525 | "size (%d)\n", alloclen, reqlen); |
| 13526 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13527 | return -ENOMEM; |
| 13528 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13529 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13530 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13531 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13532 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13533 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13534 | pg_pairs = 0; |
| 13535 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13536 | /* Set up the sge entry */ |
| 13537 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13538 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13539 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13540 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13541 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13542 | cpu_to_le32(putPaddrLow(0)); |
| 13543 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13544 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13545 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13546 | /* Keep the first xritag on the list */ |
| 13547 | if (pg_pairs == 0) |
| 13548 | xritag_start = sglq_entry->sli4_xritag; |
| 13549 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13550 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13551 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13552 | |
| 13553 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13554 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13555 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13556 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13557 | if (!phba->sli4_hba.intr_enable) |
| 13558 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13559 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13560 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13561 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13562 | } |
| 13563 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13564 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13565 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13566 | if (rc != MBX_TIMEOUT) |
| 13567 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13568 | if (shdr_status || shdr_add_status || rc) { |
| 13569 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13570 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13571 | "status x%x add_status x%x mbx status x%x\n", |
| 13572 | shdr_status, shdr_add_status, rc); |
| 13573 | rc = -ENXIO; |
| 13574 | } |
| 13575 | return rc; |
| 13576 | } |
| 13577 | |
| 13578 | /** |
| 13579 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13580 | * @phba: pointer to lpfc hba data structure. |
| 13581 | * @sblist: pointer to scsi buffer list. |
| 13582 | * @count: number of scsi buffers on the list. |
| 13583 | * |
| 13584 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13585 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13586 | * No Lock is held. |
| 13587 | * |
| 13588 | **/ |
| 13589 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13590 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 13591 | struct list_head *sblist, |
| 13592 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13593 | { |
| 13594 | struct lpfc_scsi_buf *psb; |
| 13595 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13596 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13597 | void *viraddr; |
| 13598 | LPFC_MBOXQ_t *mbox; |
| 13599 | uint32_t reqlen, alloclen, pg_pairs; |
| 13600 | uint32_t mbox_tmo; |
| 13601 | uint16_t xritag_start = 0; |
| 13602 | int rc = 0; |
| 13603 | uint32_t shdr_status, shdr_add_status; |
| 13604 | dma_addr_t pdma_phys_bpl1; |
| 13605 | union lpfc_sli4_cfg_shdr *shdr; |
| 13606 | |
| 13607 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13608 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13609 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13610 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13611 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13612 | "0217 Block sgl registration required DMA " |
| 13613 | "size (%d) great than a page\n", reqlen); |
| 13614 | return -ENOMEM; |
| 13615 | } |
| 13616 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13617 | if (!mbox) { |
| 13618 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13619 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13620 | return -ENOMEM; |
| 13621 | } |
| 13622 | |
| 13623 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13624 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13625 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13626 | LPFC_SLI4_MBX_NEMBED); |
| 13627 | |
| 13628 | if (alloclen < reqlen) { |
| 13629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13630 | "2561 Allocated DMA memory size (%d) is " |
| 13631 | "less than the requested DMA memory " |
| 13632 | "size (%d)\n", alloclen, reqlen); |
| 13633 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13634 | return -ENOMEM; |
| 13635 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13636 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13637 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 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 = 0; |
| 13645 | list_for_each_entry(psb, sblist, list) { |
| 13646 | /* Set up the sge entry */ |
| 13647 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13648 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13649 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13650 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13651 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13652 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13653 | else |
| 13654 | pdma_phys_bpl1 = 0; |
| 13655 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13656 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13657 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13658 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13659 | /* Keep the first xritag on the list */ |
| 13660 | if (pg_pairs == 0) |
| 13661 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13662 | sgl_pg_pairs++; |
| 13663 | pg_pairs++; |
| 13664 | } |
| 13665 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13666 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13667 | /* Perform endian conversion if necessary */ |
| 13668 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13669 | |
| 13670 | if (!phba->sli4_hba.intr_enable) |
| 13671 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13672 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13673 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13674 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13675 | } |
| 13676 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13677 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13678 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13679 | if (rc != MBX_TIMEOUT) |
| 13680 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13681 | if (shdr_status || shdr_add_status || rc) { |
| 13682 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13683 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13684 | "status x%x add_status x%x mbx status x%x\n", |
| 13685 | shdr_status, shdr_add_status, rc); |
| 13686 | rc = -ENXIO; |
| 13687 | } |
| 13688 | return rc; |
| 13689 | } |
| 13690 | |
| 13691 | /** |
| 13692 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13693 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13694 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13695 | * |
| 13696 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13697 | * valid type of frame that the LPFC driver will handle. This function will |
| 13698 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13699 | * frame does not pass the check. |
| 13700 | **/ |
| 13701 | static int |
| 13702 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13703 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13704 | /* make rctl_names static to save stack space */ |
| 13705 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13706 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13707 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13708 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13709 | |
| 13710 | switch (fc_hdr->fh_r_ctl) { |
| 13711 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13712 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13713 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13714 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13715 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13716 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13717 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13718 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13719 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13720 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13721 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13722 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13723 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13724 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13725 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13726 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13727 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13728 | case FC_RCTL_BA_PRMT: |
| 13729 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13730 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13731 | case FC_RCTL_P_RJT: /* port reject */ |
| 13732 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13733 | case FC_RCTL_P_BSY: /* port busy */ |
| 13734 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13735 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13736 | case FC_RCTL_LCR: /* link credit reset */ |
| 13737 | case FC_RCTL_END: /* end */ |
| 13738 | break; |
| 13739 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13740 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13741 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13742 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13743 | default: |
| 13744 | goto drop; |
| 13745 | } |
| 13746 | switch (fc_hdr->fh_type) { |
| 13747 | case FC_TYPE_BLS: |
| 13748 | case FC_TYPE_ELS: |
| 13749 | case FC_TYPE_FCP: |
| 13750 | case FC_TYPE_CT: |
| 13751 | break; |
| 13752 | case FC_TYPE_IP: |
| 13753 | case FC_TYPE_ILS: |
| 13754 | default: |
| 13755 | goto drop; |
| 13756 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13757 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13758 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13759 | "2538 Received frame rctl:%s type:%s " |
| 13760 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13761 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13762 | type_names[fc_hdr->fh_type], |
| 13763 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13764 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13765 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13766 | return 0; |
| 13767 | drop: |
| 13768 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13769 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13770 | rctl_names[fc_hdr->fh_r_ctl], |
| 13771 | type_names[fc_hdr->fh_type]); |
| 13772 | return 1; |
| 13773 | } |
| 13774 | |
| 13775 | /** |
| 13776 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13777 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13778 | * |
| 13779 | * This function processes the FC header to retrieve the VFI from the VF |
| 13780 | * header, if one exists. This function will return the VFI if one exists |
| 13781 | * or 0 if no VSAN Header exists. |
| 13782 | **/ |
| 13783 | static uint32_t |
| 13784 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13785 | { |
| 13786 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13787 | |
| 13788 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 13789 | return 0; |
| 13790 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 13791 | } |
| 13792 | |
| 13793 | /** |
| 13794 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 13795 | * @phba: Pointer to the HBA structure to search for the vport on |
| 13796 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13797 | * @fcfi: The FC Fabric ID that the frame came from |
| 13798 | * |
| 13799 | * This function searches the @phba for a vport that matches the content of the |
| 13800 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 13801 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 13802 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 13803 | * vport. |
| 13804 | **/ |
| 13805 | static struct lpfc_vport * |
| 13806 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 13807 | uint16_t fcfi) |
| 13808 | { |
| 13809 | struct lpfc_vport **vports; |
| 13810 | struct lpfc_vport *vport = NULL; |
| 13811 | int i; |
| 13812 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 13813 | fc_hdr->fh_d_id[1] << 8 | |
| 13814 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13815 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 13816 | if (did == Fabric_DID) |
| 13817 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13818 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 13819 | !(phba->link_state == LPFC_HBA_READY)) |
| 13820 | return phba->pport; |
| 13821 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13822 | vports = lpfc_create_vport_work_array(phba); |
| 13823 | if (vports != NULL) |
| 13824 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 13825 | if (phba->fcf.fcfi == fcfi && |
| 13826 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 13827 | vports[i]->fc_myDID == did) { |
| 13828 | vport = vports[i]; |
| 13829 | break; |
| 13830 | } |
| 13831 | } |
| 13832 | lpfc_destroy_vport_work_array(phba, vports); |
| 13833 | return vport; |
| 13834 | } |
| 13835 | |
| 13836 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13837 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 13838 | * @vport: The vport to work on. |
| 13839 | * |
| 13840 | * This function updates the receive sequence time stamp for this vport. The |
| 13841 | * receive sequence time stamp indicates the time that the last frame of the |
| 13842 | * the sequence that has been idle for the longest amount of time was received. |
| 13843 | * the driver uses this time stamp to indicate if any received sequences have |
| 13844 | * timed out. |
| 13845 | **/ |
| 13846 | void |
| 13847 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 13848 | { |
| 13849 | struct lpfc_dmabuf *h_buf; |
| 13850 | struct hbq_dmabuf *dmabuf = NULL; |
| 13851 | |
| 13852 | /* get the oldest sequence on the rcv list */ |
| 13853 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 13854 | struct lpfc_dmabuf, list); |
| 13855 | if (!h_buf) |
| 13856 | return; |
| 13857 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13858 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 13859 | } |
| 13860 | |
| 13861 | /** |
| 13862 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 13863 | * @vport: The vport that the received sequences were sent to. |
| 13864 | * |
| 13865 | * This function cleans up all outstanding received sequences. This is called |
| 13866 | * by the driver when a link event or user action invalidates all the received |
| 13867 | * sequences. |
| 13868 | **/ |
| 13869 | void |
| 13870 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 13871 | { |
| 13872 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13873 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13874 | struct hbq_dmabuf *dmabuf = NULL; |
| 13875 | |
| 13876 | /* start with the oldest sequence on the rcv list */ |
| 13877 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13878 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13879 | list_del_init(&dmabuf->hbuf.list); |
| 13880 | list_for_each_entry_safe(d_buf, dnext, |
| 13881 | &dmabuf->dbuf.list, list) { |
| 13882 | list_del_init(&d_buf->list); |
| 13883 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13884 | } |
| 13885 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13886 | } |
| 13887 | } |
| 13888 | |
| 13889 | /** |
| 13890 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 13891 | * @vport: The vport that the received sequences were sent to. |
| 13892 | * |
| 13893 | * This function determines whether any received sequences have timed out by |
| 13894 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 13895 | * indicates that there is at least one timed out sequence this routine will |
| 13896 | * go through the received sequences one at a time from most inactive to most |
| 13897 | * active to determine which ones need to be cleaned up. Once it has determined |
| 13898 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 13899 | * without sending an abort. |
| 13900 | **/ |
| 13901 | void |
| 13902 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 13903 | { |
| 13904 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13905 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13906 | struct hbq_dmabuf *dmabuf = NULL; |
| 13907 | unsigned long timeout; |
| 13908 | int abort_count = 0; |
| 13909 | |
| 13910 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13911 | vport->rcv_buffer_time_stamp); |
| 13912 | if (list_empty(&vport->rcv_buffer_list) || |
| 13913 | time_before(jiffies, timeout)) |
| 13914 | return; |
| 13915 | /* start with the oldest sequence on the rcv list */ |
| 13916 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13917 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13918 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13919 | dmabuf->time_stamp); |
| 13920 | if (time_before(jiffies, timeout)) |
| 13921 | break; |
| 13922 | abort_count++; |
| 13923 | list_del_init(&dmabuf->hbuf.list); |
| 13924 | list_for_each_entry_safe(d_buf, dnext, |
| 13925 | &dmabuf->dbuf.list, list) { |
| 13926 | list_del_init(&d_buf->list); |
| 13927 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13928 | } |
| 13929 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13930 | } |
| 13931 | if (abort_count) |
| 13932 | lpfc_update_rcv_time_stamp(vport); |
| 13933 | } |
| 13934 | |
| 13935 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13936 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 13937 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 13938 | * |
| 13939 | * This function searches through the existing incomplete sequences that have |
| 13940 | * been sent to this @vport. If the frame matches one of the incomplete |
| 13941 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 13942 | * make up that sequence. If no sequence is found that matches this frame then |
| 13943 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 13944 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 13945 | * the frame was linked to. |
| 13946 | **/ |
| 13947 | static struct hbq_dmabuf * |
| 13948 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 13949 | { |
| 13950 | struct fc_frame_header *new_hdr; |
| 13951 | struct fc_frame_header *temp_hdr; |
| 13952 | struct lpfc_dmabuf *d_buf; |
| 13953 | struct lpfc_dmabuf *h_buf; |
| 13954 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13955 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 13956 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13957 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13958 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13959 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13960 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 13961 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13962 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13963 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13964 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13965 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13966 | continue; |
| 13967 | /* found a pending sequence that matches this frame */ |
| 13968 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13969 | break; |
| 13970 | } |
| 13971 | if (!seq_dmabuf) { |
| 13972 | /* |
| 13973 | * This indicates first frame received for this sequence. |
| 13974 | * Queue the buffer on the vport's rcv_buffer_list. |
| 13975 | */ |
| 13976 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13977 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13978 | return dmabuf; |
| 13979 | } |
| 13980 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13981 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 13982 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13983 | list_del_init(&seq_dmabuf->hbuf.list); |
| 13984 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13985 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13986 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13987 | return dmabuf; |
| 13988 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13989 | /* move this sequence to the tail to indicate a young sequence */ |
| 13990 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13991 | seq_dmabuf->time_stamp = jiffies; |
| 13992 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13993 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 13994 | temp_hdr = dmabuf->hbuf.virt; |
| 13995 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 13996 | return seq_dmabuf; |
| 13997 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13998 | /* find the correct place in the sequence to insert this frame */ |
| 13999 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14000 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14001 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14002 | /* |
| 14003 | * If the frame's sequence count is greater than the frame on |
| 14004 | * the list then insert the frame right after this frame |
| 14005 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14006 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14007 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14008 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14009 | return seq_dmabuf; |
| 14010 | } |
| 14011 | } |
| 14012 | return NULL; |
| 14013 | } |
| 14014 | |
| 14015 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14016 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14017 | * @vport: pointer to a vitural port |
| 14018 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14019 | * |
| 14020 | * This function tries to abort from the partially assembed sequence, described |
| 14021 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14022 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14023 | * the frames from the partially assembled sequence. |
| 14024 | * |
| 14025 | * Return |
| 14026 | * true -- if there is matching partially assembled sequence present and all |
| 14027 | * the frames freed with the sequence; |
| 14028 | * false -- if there is no matching partially assembled sequence present so |
| 14029 | * nothing got aborted in the lower layer driver |
| 14030 | **/ |
| 14031 | static bool |
| 14032 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14033 | struct hbq_dmabuf *dmabuf) |
| 14034 | { |
| 14035 | struct fc_frame_header *new_hdr; |
| 14036 | struct fc_frame_header *temp_hdr; |
| 14037 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14038 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14039 | |
| 14040 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14041 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14042 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14043 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14044 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14045 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14046 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14047 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14048 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14049 | continue; |
| 14050 | /* found a pending sequence that matches this frame */ |
| 14051 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14052 | break; |
| 14053 | } |
| 14054 | |
| 14055 | /* Free up all the frames from the partially assembled sequence */ |
| 14056 | if (seq_dmabuf) { |
| 14057 | list_for_each_entry_safe(d_buf, n_buf, |
| 14058 | &seq_dmabuf->dbuf.list, list) { |
| 14059 | list_del_init(&d_buf->list); |
| 14060 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14061 | } |
| 14062 | return true; |
| 14063 | } |
| 14064 | return false; |
| 14065 | } |
| 14066 | |
| 14067 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14068 | * 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] | 14069 | * @phba: Pointer to HBA context object. |
| 14070 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14071 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14072 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14073 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14074 | * event. It properly releases the memory allocated to the sequence abort |
| 14075 | * accept iocb. |
| 14076 | **/ |
| 14077 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14078 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14079 | struct lpfc_iocbq *cmd_iocbq, |
| 14080 | struct lpfc_iocbq *rsp_iocbq) |
| 14081 | { |
| 14082 | if (cmd_iocbq) |
| 14083 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14084 | |
| 14085 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14086 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14087 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14088 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14089 | rsp_iocbq->iocb.ulpStatus, |
| 14090 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14091 | } |
| 14092 | |
| 14093 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14094 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14095 | * @phba: Pointer to HBA context object. |
| 14096 | * @xri: xri id in transaction. |
| 14097 | * |
| 14098 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14099 | * used by the driver. |
| 14100 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14101 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14102 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14103 | uint16_t xri) |
| 14104 | { |
| 14105 | int i; |
| 14106 | |
| 14107 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14108 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14109 | return i; |
| 14110 | } |
| 14111 | return NO_XRI; |
| 14112 | } |
| 14113 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14114 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14115 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14116 | * @phba: Pointer to HBA context object. |
| 14117 | * @fc_hdr: pointer to a FC frame header. |
| 14118 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14119 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14120 | * event after aborting the sequence handling. |
| 14121 | **/ |
| 14122 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14123 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14124 | struct fc_frame_header *fc_hdr) |
| 14125 | { |
| 14126 | struct lpfc_iocbq *ctiocb = NULL; |
| 14127 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14128 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14129 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14130 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14131 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14132 | |
| 14133 | if (!lpfc_is_link_up(phba)) |
| 14134 | return; |
| 14135 | |
| 14136 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14137 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14138 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14139 | |
| 14140 | ndlp = lpfc_findnode_did(phba->pport, sid); |
| 14141 | if (!ndlp) { |
| 14142 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14143 | "1268 Find ndlp returned NULL for oxid:x%x " |
| 14144 | "SID:x%x\n", oxid, sid); |
| 14145 | return; |
| 14146 | } |
| 14147 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14148 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14149 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14150 | if (!ctiocb) |
| 14151 | return; |
| 14152 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14153 | /* Extract the F_CTL field from FC_HDR */ |
| 14154 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14155 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14156 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14157 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14158 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14159 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14160 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14161 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14162 | |
| 14163 | /* Fill in the rest of iocb fields */ |
| 14164 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14165 | icmd->ulpBdeCount = 0; |
| 14166 | icmd->ulpLe = 1; |
| 14167 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14168 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 14169 | ctiocb->context1 = ndlp; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14170 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14171 | ctiocb->iocb_cmpl = NULL; |
| 14172 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14173 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14174 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14175 | ctiocb->sli4_xritag = NO_XRI; |
| 14176 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14177 | if (fctl & FC_FC_EX_CTX) |
| 14178 | /* Exchange responder sent the abort so we |
| 14179 | * own the oxid. |
| 14180 | */ |
| 14181 | xri = oxid; |
| 14182 | else |
| 14183 | xri = rxid; |
| 14184 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14185 | if (lxri != NO_XRI) |
| 14186 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14187 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14188 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
| 14189 | * send a BLS_RJT. The driver no longer has that exchange. |
| 14190 | * Override the IOCB for a BA_RJT. |
| 14191 | */ |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14192 | if (xri > (phba->sli4_hba.max_cfg_param.max_xri + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14193 | phba->sli4_hba.max_cfg_param.xri_base) || |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14194 | xri > (lpfc_sli4_get_els_iocb_cnt(phba) + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14195 | phba->sli4_hba.max_cfg_param.xri_base)) { |
| 14196 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14197 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14198 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14199 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14200 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14201 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14202 | if (fctl & FC_FC_EX_CTX) { |
| 14203 | /* ABTS sent by responder to CT exchange, construction |
| 14204 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14205 | * field and RX_ID from ABTS for RX_ID field. |
| 14206 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14207 | 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] | 14208 | } else { |
| 14209 | /* ABTS sent by initiator to CT exchange, construction |
| 14210 | * 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] | 14211 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14212 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14213 | 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] | 14214 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14215 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14216 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14217 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14218 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14219 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14220 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14221 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
| 14222 | |
| 14223 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14224 | if (rc == IOCB_ERROR) { |
| 14225 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 14226 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14227 | "xri x%x, Data x%x\n", |
| 14228 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14229 | phba->link_state); |
| 14230 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14231 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14232 | } |
| 14233 | |
| 14234 | /** |
| 14235 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14236 | * @vport: Pointer to the vport on which this sequence was received |
| 14237 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14238 | * |
| 14239 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14240 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14241 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14242 | * unsolicited receive sequence has been completely assembled and passed to |
| 14243 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14244 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14245 | * accept to accept the abort. |
| 14246 | **/ |
| 14247 | void |
| 14248 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14249 | struct hbq_dmabuf *dmabuf) |
| 14250 | { |
| 14251 | struct lpfc_hba *phba = vport->phba; |
| 14252 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14253 | uint32_t fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14254 | bool abts_par; |
| 14255 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14256 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14257 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14258 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14259 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14260 | if (fctl & FC_FC_EX_CTX) { |
| 14261 | /* |
| 14262 | * ABTS sent by responder to exchange, just free the buffer |
| 14263 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14264 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14265 | } else { |
| 14266 | /* |
| 14267 | * ABTS sent by initiator to exchange, need to do cleanup |
| 14268 | */ |
| 14269 | /* Try to abort partially assembled seq */ |
| 14270 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14271 | |
| 14272 | /* Send abort to ULP if partially seq abort failed */ |
| 14273 | if (abts_par == false) |
| 14274 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); |
| 14275 | else |
| 14276 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14277 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14278 | /* Send basic accept (BA_ACC) to the abort requester */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14279 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14280 | } |
| 14281 | |
| 14282 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14283 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14284 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14285 | * |
| 14286 | * This function checks the sequence, starting with the frame described by |
| 14287 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14288 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14289 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14290 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14291 | * set. 3) That there are no holes in the sequence count. The function will |
| 14292 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14293 | **/ |
| 14294 | static int |
| 14295 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14296 | { |
| 14297 | struct fc_frame_header *hdr; |
| 14298 | struct lpfc_dmabuf *d_buf; |
| 14299 | struct hbq_dmabuf *seq_dmabuf; |
| 14300 | uint32_t fctl; |
| 14301 | int seq_count = 0; |
| 14302 | |
| 14303 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14304 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14305 | if (hdr->fh_seq_cnt != seq_count) |
| 14306 | return 0; |
| 14307 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14308 | hdr->fh_f_ctl[1] << 8 | |
| 14309 | hdr->fh_f_ctl[2]); |
| 14310 | /* If last frame of sequence we can return success. */ |
| 14311 | if (fctl & FC_FC_END_SEQ) |
| 14312 | return 1; |
| 14313 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14314 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14315 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14316 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14317 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14318 | return 0; |
| 14319 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14320 | hdr->fh_f_ctl[1] << 8 | |
| 14321 | hdr->fh_f_ctl[2]); |
| 14322 | /* If last frame of sequence we can return success. */ |
| 14323 | if (fctl & FC_FC_END_SEQ) |
| 14324 | return 1; |
| 14325 | } |
| 14326 | return 0; |
| 14327 | } |
| 14328 | |
| 14329 | /** |
| 14330 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14331 | * @vport: Pointer to the vport on which this sequence was received |
| 14332 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14333 | * |
| 14334 | * This function takes a sequence, described by a list of frames, and creates |
| 14335 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14336 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14337 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14338 | * to allocate an iocbq then it throw out the received frames that were not |
| 14339 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14340 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14341 | **/ |
| 14342 | static struct lpfc_iocbq * |
| 14343 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14344 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14345 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14346 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14347 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14348 | struct fc_frame_header *fc_hdr; |
| 14349 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14350 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14351 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14352 | |
| 14353 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14354 | /* remove from receive buffer list */ |
| 14355 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14356 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14357 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14358 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14359 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14360 | /* Get an iocbq struct to fill in. */ |
| 14361 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14362 | if (first_iocbq) { |
| 14363 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14364 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14365 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14366 | |
| 14367 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14368 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14369 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14370 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14371 | sli4_did_from_fc_hdr(fc_hdr); |
| 14372 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14373 | } else |
| 14374 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14375 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14376 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14377 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14378 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14379 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14380 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14381 | /* put the first buffer into the first IOCBq */ |
| 14382 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14383 | first_iocbq->context3 = NULL; |
| 14384 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14385 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14386 | LPFC_DATA_BUF_SIZE; |
| 14387 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14388 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14389 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14390 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14391 | } |
| 14392 | iocbq = first_iocbq; |
| 14393 | /* |
| 14394 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14395 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14396 | */ |
| 14397 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14398 | if (!iocbq) { |
| 14399 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14400 | continue; |
| 14401 | } |
| 14402 | if (!iocbq->context3) { |
| 14403 | iocbq->context3 = d_buf; |
| 14404 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14405 | pbde = (struct ulp_bde64 *) |
| 14406 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14407 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14408 | |
| 14409 | /* We need to get the size out of the right CQE */ |
| 14410 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14411 | len = bf_get(lpfc_rcqe_length, |
| 14412 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14413 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14414 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14415 | } else { |
| 14416 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14417 | if (!iocbq) { |
| 14418 | if (first_iocbq) { |
| 14419 | first_iocbq->iocb.ulpStatus = |
| 14420 | IOSTAT_FCP_RSP_ERROR; |
| 14421 | first_iocbq->iocb.un.ulpWord[4] = |
| 14422 | IOERR_NO_RESOURCES; |
| 14423 | } |
| 14424 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14425 | continue; |
| 14426 | } |
| 14427 | iocbq->context2 = d_buf; |
| 14428 | iocbq->context3 = NULL; |
| 14429 | iocbq->iocb.ulpBdeCount = 1; |
| 14430 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14431 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14432 | |
| 14433 | /* We need to get the size out of the right CQE */ |
| 14434 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14435 | len = bf_get(lpfc_rcqe_length, |
| 14436 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14437 | tot_len += len; |
| 14438 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14439 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14440 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14441 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14442 | } |
| 14443 | } |
| 14444 | return first_iocbq; |
| 14445 | } |
| 14446 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14447 | static void |
| 14448 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14449 | struct hbq_dmabuf *seq_dmabuf) |
| 14450 | { |
| 14451 | struct fc_frame_header *fc_hdr; |
| 14452 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14453 | struct lpfc_hba *phba = vport->phba; |
| 14454 | |
| 14455 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14456 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14457 | if (!iocbq) { |
| 14458 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14459 | "2707 Ring %d handler: Failed to allocate " |
| 14460 | "iocb Rctl x%x Type x%x received\n", |
| 14461 | LPFC_ELS_RING, |
| 14462 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14463 | return; |
| 14464 | } |
| 14465 | if (!lpfc_complete_unsol_iocb(phba, |
| 14466 | &phba->sli.ring[LPFC_ELS_RING], |
| 14467 | iocbq, fc_hdr->fh_r_ctl, |
| 14468 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14469 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14470 | "2540 Ring %d handler: unexpected Rctl " |
| 14471 | "x%x Type x%x received\n", |
| 14472 | LPFC_ELS_RING, |
| 14473 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14474 | |
| 14475 | /* Free iocb created in lpfc_prep_seq */ |
| 14476 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14477 | &iocbq->list, list) { |
| 14478 | list_del_init(&curr_iocb->list); |
| 14479 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14480 | } |
| 14481 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14482 | } |
| 14483 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14484 | /** |
| 14485 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14486 | * @phba: Pointer to HBA context object. |
| 14487 | * |
| 14488 | * This function is called with no lock held. This function processes all |
| 14489 | * the received buffers and gives it to upper layers when a received buffer |
| 14490 | * indicates that it is the final frame in the sequence. The interrupt |
| 14491 | * service routine processes received buffers at interrupt contexts and adds |
| 14492 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14493 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14494 | * appropriate receive function when the final frame in a sequence is received. |
| 14495 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14496 | void |
| 14497 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14498 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14499 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14500 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14501 | struct fc_frame_header *fc_hdr; |
| 14502 | struct lpfc_vport *vport; |
| 14503 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14504 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14505 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14506 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14507 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14508 | /* check to see if this a valid type of frame */ |
| 14509 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14510 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14511 | return; |
| 14512 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14513 | if ((bf_get(lpfc_cqe_code, |
| 14514 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14515 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14516 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14517 | else |
| 14518 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14519 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14520 | |
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 | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14522 | if (!vport) { |
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 | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14527 | |
| 14528 | /* d_id this frame is directed to */ |
| 14529 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 14530 | |
| 14531 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 14532 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 14533 | (did != Fabric_DID)) { |
| 14534 | /* |
| 14535 | * Throw out the frame if we are not pt2pt. |
| 14536 | * The pt2pt protocol allows for discovery frames |
| 14537 | * to be received without a registered VPI. |
| 14538 | */ |
| 14539 | if (!(vport->fc_flag & FC_PT2PT) || |
| 14540 | (phba->link_state == LPFC_HBA_READY)) { |
| 14541 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14542 | return; |
| 14543 | } |
| 14544 | } |
| 14545 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14546 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14547 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14548 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14549 | return; |
| 14550 | } |
| 14551 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14552 | /* Link this frame */ |
| 14553 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14554 | if (!seq_dmabuf) { |
| 14555 | /* unable to add frame to vport - throw it out */ |
| 14556 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14557 | return; |
| 14558 | } |
| 14559 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14560 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14561 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14562 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14563 | /* Send the complete sequence to the upper layer protocol */ |
| 14564 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14565 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14566 | |
| 14567 | /** |
| 14568 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14569 | * @phba: pointer to lpfc hba data structure. |
| 14570 | * |
| 14571 | * This routine is invoked to post rpi header templates to the |
| 14572 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14573 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14574 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14575 | * |
| 14576 | * This routine does not require any locks. It's usage is expected |
| 14577 | * to be driver load or reset recovery when the driver is |
| 14578 | * sequential. |
| 14579 | * |
| 14580 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14581 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14582 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14583 | * When this error occurs, the driver is not guaranteed |
| 14584 | * to have any rpi regions posted to the device and |
| 14585 | * must either attempt to repost the regions or take a |
| 14586 | * fatal error. |
| 14587 | **/ |
| 14588 | int |
| 14589 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14590 | { |
| 14591 | struct lpfc_rpi_hdr *rpi_page; |
| 14592 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14593 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14594 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14595 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14596 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14597 | goto exit; |
| 14598 | if (phba->sli4_hba.extents_in_use) |
| 14599 | return -EIO; |
| 14600 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14601 | 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] | 14602 | /* |
| 14603 | * Assign the rpi headers a physical rpi only if the driver |
| 14604 | * has not initialized those resources. A port reset only |
| 14605 | * needs the headers posted. |
| 14606 | */ |
| 14607 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14608 | LPFC_RPI_RSRC_RDY) |
| 14609 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14610 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14611 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14612 | if (rc != MBX_SUCCESS) { |
| 14613 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14614 | "2008 Error %d posting all rpi " |
| 14615 | "headers\n", rc); |
| 14616 | rc = -EIO; |
| 14617 | break; |
| 14618 | } |
| 14619 | } |
| 14620 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14621 | exit: |
| 14622 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14623 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14624 | return rc; |
| 14625 | } |
| 14626 | |
| 14627 | /** |
| 14628 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14629 | * @phba: pointer to lpfc hba data structure. |
| 14630 | * @rpi_page: pointer to the rpi memory region. |
| 14631 | * |
| 14632 | * This routine is invoked to post a single rpi header to the |
| 14633 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14634 | * maps up to 64 rpi context regions. |
| 14635 | * |
| 14636 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14637 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14638 | * -ENOMEM - No available memory |
| 14639 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14640 | **/ |
| 14641 | int |
| 14642 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14643 | { |
| 14644 | LPFC_MBOXQ_t *mboxq; |
| 14645 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14646 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14647 | uint32_t shdr_status, shdr_add_status; |
| 14648 | union lpfc_sli4_cfg_shdr *shdr; |
| 14649 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14650 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14651 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14652 | return rc; |
| 14653 | if (phba->sli4_hba.extents_in_use) |
| 14654 | return -EIO; |
| 14655 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14656 | /* The port is notified of the header region via a mailbox command. */ |
| 14657 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14658 | if (!mboxq) { |
| 14659 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14660 | "2001 Unable to allocate memory for issuing " |
| 14661 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14662 | return -ENOMEM; |
| 14663 | } |
| 14664 | |
| 14665 | /* Post all rpi memory regions to the port. */ |
| 14666 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14667 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14668 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14669 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14670 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14671 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14672 | |
| 14673 | |
| 14674 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14675 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14676 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14677 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14678 | hdr_tmpl, rpi_page->page_count); |
| 14679 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14680 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14681 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14682 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14683 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14684 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14685 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14686 | if (rc != MBX_TIMEOUT) |
| 14687 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14688 | if (shdr_status || shdr_add_status || rc) { |
| 14689 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14690 | "2514 POST_RPI_HDR mailbox failed with " |
| 14691 | "status x%x add_status x%x, mbx status x%x\n", |
| 14692 | shdr_status, shdr_add_status, rc); |
| 14693 | rc = -ENXIO; |
| 14694 | } |
| 14695 | return rc; |
| 14696 | } |
| 14697 | |
| 14698 | /** |
| 14699 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14700 | * @phba: pointer to lpfc hba data structure. |
| 14701 | * |
| 14702 | * This routine is invoked to post rpi header templates to the |
| 14703 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14704 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14705 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14706 | * |
| 14707 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14708 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14709 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14710 | **/ |
| 14711 | int |
| 14712 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14713 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14714 | unsigned long rpi; |
| 14715 | uint16_t max_rpi, rpi_limit; |
| 14716 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14717 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14718 | |
| 14719 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14720 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14721 | |
| 14722 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14723 | * Fetch the next logical rpi. Because this index is logical, |
| 14724 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14725 | */ |
| 14726 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14727 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 14728 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14729 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 14730 | else { |
| 14731 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 14732 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 14733 | phba->sli4_hba.rpi_count++; |
| 14734 | } |
| 14735 | |
| 14736 | /* |
| 14737 | * 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] | 14738 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14739 | */ |
| 14740 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 14741 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 14742 | spin_unlock_irq(&phba->hbalock); |
| 14743 | return rpi; |
| 14744 | } |
| 14745 | |
| 14746 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14747 | * RPI header postings are not required for SLI4 ports capable of |
| 14748 | * extents. |
| 14749 | */ |
| 14750 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 14751 | spin_unlock_irq(&phba->hbalock); |
| 14752 | return rpi; |
| 14753 | } |
| 14754 | |
| 14755 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14756 | * If the driver is running low on rpi resources, allocate another |
| 14757 | * page now. Note that the next_rpi value is used because |
| 14758 | * it represents how many are actually in use whereas max_rpi notes |
| 14759 | * how many are supported max by the device. |
| 14760 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14761 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14762 | spin_unlock_irq(&phba->hbalock); |
| 14763 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 14764 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 14765 | if (!rpi_hdr) { |
| 14766 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14767 | "2002 Error Could not grow rpi " |
| 14768 | "count\n"); |
| 14769 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14770 | lrpi = rpi_hdr->start_rpi; |
| 14771 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14772 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 14773 | } |
| 14774 | } |
| 14775 | |
| 14776 | return rpi; |
| 14777 | } |
| 14778 | |
| 14779 | /** |
| 14780 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14781 | * @phba: pointer to lpfc hba data structure. |
| 14782 | * |
| 14783 | * This routine is invoked to release an rpi to the pool of |
| 14784 | * available rpis maintained by the driver. |
| 14785 | **/ |
| 14786 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14787 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14788 | { |
| 14789 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 14790 | phba->sli4_hba.rpi_count--; |
| 14791 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 14792 | } |
| 14793 | } |
| 14794 | |
| 14795 | /** |
| 14796 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14797 | * @phba: pointer to lpfc hba data structure. |
| 14798 | * |
| 14799 | * This routine is invoked to release an rpi to the pool of |
| 14800 | * available rpis maintained by the driver. |
| 14801 | **/ |
| 14802 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14803 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14804 | { |
| 14805 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14806 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14807 | spin_unlock_irq(&phba->hbalock); |
| 14808 | } |
| 14809 | |
| 14810 | /** |
| 14811 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 14812 | * @phba: pointer to lpfc hba data structure. |
| 14813 | * |
| 14814 | * This routine is invoked to remove the memory region that |
| 14815 | * provided rpi via a bitmask. |
| 14816 | **/ |
| 14817 | void |
| 14818 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 14819 | { |
| 14820 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14821 | kfree(phba->sli4_hba.rpi_ids); |
| 14822 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14823 | } |
| 14824 | |
| 14825 | /** |
| 14826 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 14827 | * @phba: pointer to lpfc hba data structure. |
| 14828 | * |
| 14829 | * This routine is invoked to remove the memory region that |
| 14830 | * provided rpi via a bitmask. |
| 14831 | **/ |
| 14832 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14833 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 14834 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14835 | { |
| 14836 | LPFC_MBOXQ_t *mboxq; |
| 14837 | struct lpfc_hba *phba = ndlp->phba; |
| 14838 | int rc; |
| 14839 | |
| 14840 | /* The port is notified of the header region via a mailbox command. */ |
| 14841 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14842 | if (!mboxq) |
| 14843 | return -ENOMEM; |
| 14844 | |
| 14845 | /* Post all rpi memory regions to the port. */ |
| 14846 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14847 | if (cmpl) { |
| 14848 | mboxq->mbox_cmpl = cmpl; |
| 14849 | mboxq->context1 = arg; |
| 14850 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 14851 | } else |
| 14852 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14853 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14854 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14855 | if (rc == MBX_NOT_FINISHED) { |
| 14856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14857 | "2010 Resume RPI Mailbox failed " |
| 14858 | "status %d, mbxStatus x%x\n", rc, |
| 14859 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 14860 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14861 | return -EIO; |
| 14862 | } |
| 14863 | return 0; |
| 14864 | } |
| 14865 | |
| 14866 | /** |
| 14867 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14868 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14869 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14870 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14871 | * |
| 14872 | * Returns: |
| 14873 | * 0 success |
| 14874 | * -Evalue otherwise |
| 14875 | **/ |
| 14876 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14877 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14878 | { |
| 14879 | LPFC_MBOXQ_t *mboxq; |
| 14880 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14881 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14882 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14883 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14884 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14885 | if (!mboxq) |
| 14886 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14887 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14888 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14889 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14890 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14891 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14892 | "2022 INIT VPI Mailbox failed " |
| 14893 | "status %d, mbxStatus x%x\n", rc, |
| 14894 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14895 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14896 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14897 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14898 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14899 | |
| 14900 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14901 | } |
| 14902 | |
| 14903 | /** |
| 14904 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 14905 | * @phba: pointer to lpfc hba data structure. |
| 14906 | * @mboxq: Pointer to mailbox object. |
| 14907 | * |
| 14908 | * This routine is invoked to manually add a single FCF record. The caller |
| 14909 | * must pass a completely initialized FCF_Record. This routine takes |
| 14910 | * care of the nonembedded mailbox operations. |
| 14911 | **/ |
| 14912 | static void |
| 14913 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 14914 | { |
| 14915 | void *virt_addr; |
| 14916 | union lpfc_sli4_cfg_shdr *shdr; |
| 14917 | uint32_t shdr_status, shdr_add_status; |
| 14918 | |
| 14919 | virt_addr = mboxq->sge_array->addr[0]; |
| 14920 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14921 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 14922 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14923 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14924 | |
| 14925 | if ((shdr_status || shdr_add_status) && |
| 14926 | (shdr_status != STATUS_FCF_IN_USE)) |
| 14927 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14928 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 14929 | "status x%x add_status x%x\n", |
| 14930 | shdr_status, shdr_add_status); |
| 14931 | |
| 14932 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14933 | } |
| 14934 | |
| 14935 | /** |
| 14936 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 14937 | * @phba: pointer to lpfc hba data structure. |
| 14938 | * @fcf_record: pointer to the initialized fcf record to add. |
| 14939 | * |
| 14940 | * This routine is invoked to manually add a single FCF record. The caller |
| 14941 | * must pass a completely initialized FCF_Record. This routine takes |
| 14942 | * care of the nonembedded mailbox operations. |
| 14943 | **/ |
| 14944 | int |
| 14945 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 14946 | { |
| 14947 | int rc = 0; |
| 14948 | LPFC_MBOXQ_t *mboxq; |
| 14949 | uint8_t *bytep; |
| 14950 | void *virt_addr; |
| 14951 | dma_addr_t phys_addr; |
| 14952 | struct lpfc_mbx_sge sge; |
| 14953 | uint32_t alloc_len, req_len; |
| 14954 | uint32_t fcfindex; |
| 14955 | |
| 14956 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14957 | if (!mboxq) { |
| 14958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14959 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 14960 | return -ENOMEM; |
| 14961 | } |
| 14962 | |
| 14963 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 14964 | sizeof(uint32_t); |
| 14965 | |
| 14966 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14967 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14968 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 14969 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 14970 | if (alloc_len < req_len) { |
| 14971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14972 | "2523 Allocated DMA memory size (x%x) is " |
| 14973 | "less than the requested DMA memory " |
| 14974 | "size (x%x)\n", alloc_len, req_len); |
| 14975 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14976 | return -ENOMEM; |
| 14977 | } |
| 14978 | |
| 14979 | /* |
| 14980 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 14981 | * routine only uses a single SGE. |
| 14982 | */ |
| 14983 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 14984 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14985 | virt_addr = mboxq->sge_array->addr[0]; |
| 14986 | /* |
| 14987 | * Configure the FCF record for FCFI 0. This is the driver's |
| 14988 | * hardcoded default and gets used in nonFIP mode. |
| 14989 | */ |
| 14990 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 14991 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 14992 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 14993 | |
| 14994 | /* |
| 14995 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 14996 | * the FCoE header plus word10. The data copy needs to be endian |
| 14997 | * correct. |
| 14998 | */ |
| 14999 | bytep += sizeof(uint32_t); |
| 15000 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15001 | mboxq->vport = phba->pport; |
| 15002 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15003 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15004 | if (rc == MBX_NOT_FINISHED) { |
| 15005 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15006 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15007 | "status 0x%x\n", rc); |
| 15008 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15009 | rc = -EIO; |
| 15010 | } else |
| 15011 | rc = 0; |
| 15012 | |
| 15013 | return rc; |
| 15014 | } |
| 15015 | |
| 15016 | /** |
| 15017 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15018 | * @phba: pointer to lpfc hba data structure. |
| 15019 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15020 | * @fcf_index: FCF table entry index. |
| 15021 | * |
| 15022 | * This routine is invoked to build the driver's default FCF record. The |
| 15023 | * values used are hardcoded. This routine handles memory initialization. |
| 15024 | * |
| 15025 | **/ |
| 15026 | void |
| 15027 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15028 | struct fcf_record *fcf_record, |
| 15029 | uint16_t fcf_index) |
| 15030 | { |
| 15031 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15032 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15033 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15034 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15035 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15036 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15037 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15038 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15039 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15040 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15041 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15042 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15043 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15044 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15045 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15046 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15047 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15048 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15049 | /* Set the VLAN bit map */ |
| 15050 | if (phba->valid_vlan) { |
| 15051 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15052 | = 1 << (phba->vlan_id % 8); |
| 15053 | } |
| 15054 | } |
| 15055 | |
| 15056 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15057 | * 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] | 15058 | * @phba: pointer to lpfc hba data structure. |
| 15059 | * @fcf_index: FCF table entry offset. |
| 15060 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15061 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15062 | * record and processing it one at a time starting from the @fcf_index |
| 15063 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15064 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15065 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15066 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15067 | **/ |
| 15068 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15069 | 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] | 15070 | { |
| 15071 | int rc = 0, error; |
| 15072 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15073 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15074 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15075 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15076 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15077 | if (!mboxq) { |
| 15078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15079 | "2000 Failed to allocate mbox for " |
| 15080 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15081 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15082 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15083 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15084 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15085 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15086 | if (rc) { |
| 15087 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15088 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15089 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15090 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15091 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15092 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15093 | |
| 15094 | spin_lock_irq(&phba->hbalock); |
| 15095 | phba->hba_flag |= FCF_TS_INPROG; |
| 15096 | spin_unlock_irq(&phba->hbalock); |
| 15097 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15098 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15099 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15100 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15101 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15102 | /* Reset eligible FCF count for new scan */ |
| 15103 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15104 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15105 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15106 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15107 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15108 | if (error) { |
| 15109 | if (mboxq) |
| 15110 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15111 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15112 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15113 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15114 | spin_unlock_irq(&phba->hbalock); |
| 15115 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15116 | return error; |
| 15117 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15118 | |
| 15119 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15120 | * 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] | 15121 | * @phba: pointer to lpfc hba data structure. |
| 15122 | * @fcf_index: FCF table entry offset. |
| 15123 | * |
| 15124 | * 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] | 15125 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15126 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15127 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15128 | * otherwise. |
| 15129 | **/ |
| 15130 | int |
| 15131 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15132 | { |
| 15133 | int rc = 0, error; |
| 15134 | LPFC_MBOXQ_t *mboxq; |
| 15135 | |
| 15136 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15137 | if (!mboxq) { |
| 15138 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15139 | "2763 Failed to allocate mbox for " |
| 15140 | "READ_FCF cmd\n"); |
| 15141 | error = -ENOMEM; |
| 15142 | goto fail_fcf_read; |
| 15143 | } |
| 15144 | /* Construct the read FCF record mailbox command */ |
| 15145 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15146 | if (rc) { |
| 15147 | error = -EINVAL; |
| 15148 | goto fail_fcf_read; |
| 15149 | } |
| 15150 | /* Issue the mailbox command asynchronously */ |
| 15151 | mboxq->vport = phba->pport; |
| 15152 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15153 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15154 | if (rc == MBX_NOT_FINISHED) |
| 15155 | error = -EIO; |
| 15156 | else |
| 15157 | error = 0; |
| 15158 | |
| 15159 | fail_fcf_read: |
| 15160 | if (error && mboxq) |
| 15161 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15162 | return error; |
| 15163 | } |
| 15164 | |
| 15165 | /** |
| 15166 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15167 | * @phba: pointer to lpfc hba data structure. |
| 15168 | * @fcf_index: FCF table entry offset. |
| 15169 | * |
| 15170 | * 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] | 15171 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15172 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15173 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15174 | * otherwise. |
| 15175 | **/ |
| 15176 | int |
| 15177 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15178 | { |
| 15179 | int rc = 0, error; |
| 15180 | LPFC_MBOXQ_t *mboxq; |
| 15181 | |
| 15182 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15183 | if (!mboxq) { |
| 15184 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15185 | "2758 Failed to allocate mbox for " |
| 15186 | "READ_FCF cmd\n"); |
| 15187 | error = -ENOMEM; |
| 15188 | goto fail_fcf_read; |
| 15189 | } |
| 15190 | /* Construct the read FCF record mailbox command */ |
| 15191 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15192 | if (rc) { |
| 15193 | error = -EINVAL; |
| 15194 | goto fail_fcf_read; |
| 15195 | } |
| 15196 | /* Issue the mailbox command asynchronously */ |
| 15197 | mboxq->vport = phba->pport; |
| 15198 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15199 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15200 | if (rc == MBX_NOT_FINISHED) |
| 15201 | error = -EIO; |
| 15202 | else |
| 15203 | error = 0; |
| 15204 | |
| 15205 | fail_fcf_read: |
| 15206 | if (error && mboxq) |
| 15207 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15208 | return error; |
| 15209 | } |
| 15210 | |
| 15211 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15212 | * lpfc_check_next_fcf_pri |
| 15213 | * phba pointer to the lpfc_hba struct for this port. |
| 15214 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15215 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15216 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15217 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15218 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15219 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15220 | * fcf_indexes. |
| 15221 | * returns: |
| 15222 | * 1=success 0=failure |
| 15223 | **/ |
| 15224 | int |
| 15225 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15226 | { |
| 15227 | uint16_t next_fcf_pri; |
| 15228 | uint16_t last_index; |
| 15229 | struct lpfc_fcf_pri *fcf_pri; |
| 15230 | int rc; |
| 15231 | int ret = 0; |
| 15232 | |
| 15233 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15234 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15235 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15236 | "3060 Last IDX %d\n", last_index); |
| 15237 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 15238 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15239 | "3061 Last IDX %d\n", last_index); |
| 15240 | return 0; /* Empty rr list */ |
| 15241 | } |
| 15242 | next_fcf_pri = 0; |
| 15243 | /* |
| 15244 | * Clear the rr_bmask and set all of the bits that are at this |
| 15245 | * priority. |
| 15246 | */ |
| 15247 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15248 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15249 | spin_lock_irq(&phba->hbalock); |
| 15250 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15251 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15252 | continue; |
| 15253 | /* |
| 15254 | * the 1st priority that has not FLOGI failed |
| 15255 | * will be the highest. |
| 15256 | */ |
| 15257 | if (!next_fcf_pri) |
| 15258 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15259 | spin_unlock_irq(&phba->hbalock); |
| 15260 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15261 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15262 | fcf_pri->fcf_rec.fcf_index); |
| 15263 | if (rc) |
| 15264 | return 0; |
| 15265 | } |
| 15266 | spin_lock_irq(&phba->hbalock); |
| 15267 | } |
| 15268 | /* |
| 15269 | * if next_fcf_pri was not set above and the list is not empty then |
| 15270 | * we have failed flogis on all of them. So reset flogi failed |
| 15271 | * and start at the begining. |
| 15272 | */ |
| 15273 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15274 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15275 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15276 | /* |
| 15277 | * the 1st priority that has not FLOGI failed |
| 15278 | * will be the highest. |
| 15279 | */ |
| 15280 | if (!next_fcf_pri) |
| 15281 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15282 | spin_unlock_irq(&phba->hbalock); |
| 15283 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15284 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15285 | fcf_pri->fcf_rec.fcf_index); |
| 15286 | if (rc) |
| 15287 | return 0; |
| 15288 | } |
| 15289 | spin_lock_irq(&phba->hbalock); |
| 15290 | } |
| 15291 | } else |
| 15292 | ret = 1; |
| 15293 | spin_unlock_irq(&phba->hbalock); |
| 15294 | |
| 15295 | return ret; |
| 15296 | } |
| 15297 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15298 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15299 | * @phba: pointer to lpfc hba data structure. |
| 15300 | * |
| 15301 | * This routine is to get the next eligible FCF record index in a round |
| 15302 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15303 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15304 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15305 | * shall be returned. |
| 15306 | **/ |
| 15307 | uint16_t |
| 15308 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15309 | { |
| 15310 | uint16_t next_fcf_index; |
| 15311 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15312 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15313 | next_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15314 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
| 15315 | LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15316 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15317 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15318 | next_fcf_index); |
| 15319 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15320 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15321 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15322 | /* |
| 15323 | * If we have wrapped then we need to clear the bits that |
| 15324 | * have been tested so that we can detect when we should |
| 15325 | * change the priority level. |
| 15326 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15327 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15328 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15329 | } |
| 15330 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15331 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15332 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15333 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15334 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15335 | /* |
| 15336 | * If next fcf index is not found check if there are lower |
| 15337 | * Priority level fcf's in the fcf_priority list. |
| 15338 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15339 | * at that level and continue the selection process. |
| 15340 | */ |
| 15341 | if (lpfc_check_next_fcf_pri_level(phba)) |
| 15342 | goto next_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15343 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15344 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15345 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15346 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15347 | else { |
| 15348 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15349 | "3063 Only FCF available idx %d, flag %x\n", |
| 15350 | next_fcf_index, |
| 15351 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15352 | return next_fcf_index; |
| 15353 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15354 | } |
| 15355 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15356 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15357 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15358 | LPFC_FCF_FLOGI_FAILED) |
| 15359 | goto next_priority; |
| 15360 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15361 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15362 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15363 | next_fcf_index); |
| 15364 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15365 | return next_fcf_index; |
| 15366 | } |
| 15367 | |
| 15368 | /** |
| 15369 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15370 | * @phba: pointer to lpfc hba data structure. |
| 15371 | * |
| 15372 | * 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] | 15373 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15374 | * does not go beyond the range of the driver allocated bmask dimension |
| 15375 | * before setting the bit. |
| 15376 | * |
| 15377 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15378 | * -EINVAL. |
| 15379 | **/ |
| 15380 | int |
| 15381 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15382 | { |
| 15383 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15384 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15385 | "2610 FCF (x%x) reached driver's book " |
| 15386 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15387 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15388 | return -EINVAL; |
| 15389 | } |
| 15390 | /* Set the eligible FCF record index bmask */ |
| 15391 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15392 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15393 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15394 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15395 | "bmask\n", fcf_index); |
| 15396 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15397 | return 0; |
| 15398 | } |
| 15399 | |
| 15400 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15401 | * 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] | 15402 | * @phba: pointer to lpfc hba data structure. |
| 15403 | * |
| 15404 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15405 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15406 | * does not go beyond the range of the driver allocated bmask dimension |
| 15407 | * before clearing the bit. |
| 15408 | **/ |
| 15409 | void |
| 15410 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15411 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15412 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15413 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15414 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15415 | "2762 FCF (x%x) reached driver's book " |
| 15416 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15417 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15418 | return; |
| 15419 | } |
| 15420 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15421 | spin_lock_irq(&phba->hbalock); |
| 15422 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15423 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15424 | list_del_init(&fcf_pri->list); |
| 15425 | break; |
| 15426 | } |
| 15427 | } |
| 15428 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15429 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15430 | |
| 15431 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15432 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15433 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15434 | } |
| 15435 | |
| 15436 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15437 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15438 | * @phba: pointer to lpfc hba data structure. |
| 15439 | * |
| 15440 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15441 | * command. If the mailbox command returned failure, it will try to stop the |
| 15442 | * FCF rediscover wait timer. |
| 15443 | **/ |
| 15444 | void |
| 15445 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15446 | { |
| 15447 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15448 | uint32_t shdr_status, shdr_add_status; |
| 15449 | |
| 15450 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15451 | |
| 15452 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15453 | &redisc_fcf->header.cfg_shdr.response); |
| 15454 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15455 | &redisc_fcf->header.cfg_shdr.response); |
| 15456 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15457 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15458 | "2746 Requesting for FCF rediscovery failed " |
| 15459 | "status x%x add_status x%x\n", |
| 15460 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15461 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15462 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15463 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15464 | spin_unlock_irq(&phba->hbalock); |
| 15465 | /* |
| 15466 | * CVL event triggered FCF rediscover request failed, |
| 15467 | * last resort to re-try current registered FCF entry. |
| 15468 | */ |
| 15469 | lpfc_retry_pport_discovery(phba); |
| 15470 | } else { |
| 15471 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15472 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15473 | spin_unlock_irq(&phba->hbalock); |
| 15474 | /* |
| 15475 | * DEAD FCF event triggered FCF rediscover request |
| 15476 | * failed, last resort to fail over as a link down |
| 15477 | * to FCF registration. |
| 15478 | */ |
| 15479 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15480 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15481 | } else { |
| 15482 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15483 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15484 | /* |
| 15485 | * Start FCF rediscovery wait timer for pending FCF |
| 15486 | * before rescan FCF record table. |
| 15487 | */ |
| 15488 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15489 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15490 | |
| 15491 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15492 | } |
| 15493 | |
| 15494 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15495 | * 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] | 15496 | * @phba: pointer to lpfc hba data structure. |
| 15497 | * |
| 15498 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15499 | * by the port. |
| 15500 | **/ |
| 15501 | int |
| 15502 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15503 | { |
| 15504 | LPFC_MBOXQ_t *mbox; |
| 15505 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15506 | int rc, length; |
| 15507 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15508 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15509 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15510 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15511 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15512 | if (!mbox) { |
| 15513 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15514 | "2745 Failed to allocate mbox for " |
| 15515 | "requesting FCF rediscover.\n"); |
| 15516 | return -ENOMEM; |
| 15517 | } |
| 15518 | |
| 15519 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15520 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15521 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15522 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15523 | length, LPFC_SLI4_MBX_EMBED); |
| 15524 | |
| 15525 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15526 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15527 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15528 | |
| 15529 | /* Issue the mailbox command asynchronously */ |
| 15530 | mbox->vport = phba->pport; |
| 15531 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15532 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15533 | |
| 15534 | if (rc == MBX_NOT_FINISHED) { |
| 15535 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15536 | return -EIO; |
| 15537 | } |
| 15538 | return 0; |
| 15539 | } |
| 15540 | |
| 15541 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15542 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15543 | * @phba: pointer to lpfc hba data structure. |
| 15544 | * |
| 15545 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15546 | * event when driver failed to perform fast FCF failover. |
| 15547 | **/ |
| 15548 | void |
| 15549 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15550 | { |
| 15551 | uint32_t link_state; |
| 15552 | |
| 15553 | /* |
| 15554 | * Last resort as FCF DEAD event failover will treat this as |
| 15555 | * a link down, but save the link state because we don't want |
| 15556 | * it to be changed to Link Down unless it is already down. |
| 15557 | */ |
| 15558 | link_state = phba->link_state; |
| 15559 | lpfc_linkdown(phba); |
| 15560 | phba->link_state = link_state; |
| 15561 | |
| 15562 | /* Unregister FCF if no devices connected to it */ |
| 15563 | lpfc_unregister_unused_fcf(phba); |
| 15564 | } |
| 15565 | |
| 15566 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15567 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15568 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15569 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15570 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15571 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15572 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15573 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15574 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15575 | static uint32_t |
| 15576 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15577 | { |
| 15578 | LPFC_MBOXQ_t *pmb = NULL; |
| 15579 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15580 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15581 | int rc; |
| 15582 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15583 | if (!rgn23_data) |
| 15584 | return 0; |
| 15585 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15586 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15587 | if (!pmb) { |
| 15588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15589 | "2600 failed to allocate mailbox memory\n"); |
| 15590 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15591 | } |
| 15592 | mb = &pmb->u.mb; |
| 15593 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15594 | do { |
| 15595 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15596 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15597 | |
| 15598 | if (rc != MBX_SUCCESS) { |
| 15599 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15600 | "2601 failed to read config " |
| 15601 | "region 23, rc 0x%x Status 0x%x\n", |
| 15602 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15603 | mb->un.varDmp.word_cnt = 0; |
| 15604 | } |
| 15605 | /* |
| 15606 | * dump mem may return a zero when finished or we got a |
| 15607 | * mailbox error, either way we are done. |
| 15608 | */ |
| 15609 | if (mb->un.varDmp.word_cnt == 0) |
| 15610 | break; |
| 15611 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15612 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15613 | |
| 15614 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15615 | rgn23_data + offset, |
| 15616 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15617 | offset += mb->un.varDmp.word_cnt; |
| 15618 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15619 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15620 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15621 | return offset; |
| 15622 | } |
| 15623 | |
| 15624 | /** |
| 15625 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15626 | * @phba: pointer to lpfc hba data structure. |
| 15627 | * @rgn23_data: pointer to configure region 23 data. |
| 15628 | * |
| 15629 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15630 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15631 | * will be returned, otherwise, 0 will be returned. |
| 15632 | **/ |
| 15633 | static uint32_t |
| 15634 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15635 | { |
| 15636 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15637 | struct lpfc_dmabuf *mp = NULL; |
| 15638 | struct lpfc_mqe *mqe; |
| 15639 | uint32_t data_length = 0; |
| 15640 | int rc; |
| 15641 | |
| 15642 | if (!rgn23_data) |
| 15643 | return 0; |
| 15644 | |
| 15645 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15646 | if (!mboxq) { |
| 15647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15648 | "3105 failed to allocate mailbox memory\n"); |
| 15649 | return 0; |
| 15650 | } |
| 15651 | |
| 15652 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15653 | goto out; |
| 15654 | mqe = &mboxq->u.mqe; |
| 15655 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15656 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15657 | if (rc) |
| 15658 | goto out; |
| 15659 | data_length = mqe->un.mb_words[5]; |
| 15660 | if (data_length == 0) |
| 15661 | goto out; |
| 15662 | if (data_length > DMP_RGN23_SIZE) { |
| 15663 | data_length = 0; |
| 15664 | goto out; |
| 15665 | } |
| 15666 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15667 | out: |
| 15668 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15669 | if (mp) { |
| 15670 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15671 | kfree(mp); |
| 15672 | } |
| 15673 | return data_length; |
| 15674 | } |
| 15675 | |
| 15676 | /** |
| 15677 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15678 | * @phba: pointer to lpfc hba data structure. |
| 15679 | * |
| 15680 | * This function read region 23 and parse TLV for port status to |
| 15681 | * decide if the user disaled the port. If the TLV indicates the |
| 15682 | * port is disabled, the hba_flag is set accordingly. |
| 15683 | **/ |
| 15684 | void |
| 15685 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15686 | { |
| 15687 | uint8_t *rgn23_data = NULL; |
| 15688 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15689 | uint32_t offset = 0; |
| 15690 | |
| 15691 | /* Get adapter Region 23 data */ |
| 15692 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15693 | if (!rgn23_data) |
| 15694 | goto out; |
| 15695 | |
| 15696 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15697 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15698 | else { |
| 15699 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15700 | &phba->sli4_hba.sli_intf); |
| 15701 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15702 | goto out; |
| 15703 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15704 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15705 | |
| 15706 | if (!data_size) |
| 15707 | goto out; |
| 15708 | |
| 15709 | /* Check the region signature first */ |
| 15710 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15711 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15712 | "2619 Config region 23 has bad signature\n"); |
| 15713 | goto out; |
| 15714 | } |
| 15715 | offset += 4; |
| 15716 | |
| 15717 | /* Check the data structure version */ |
| 15718 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 15719 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15720 | "2620 Config region 23 has bad version\n"); |
| 15721 | goto out; |
| 15722 | } |
| 15723 | offset += 4; |
| 15724 | |
| 15725 | /* Parse TLV entries in the region */ |
| 15726 | while (offset < data_size) { |
| 15727 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 15728 | break; |
| 15729 | /* |
| 15730 | * If the TLV is not driver specific TLV or driver id is |
| 15731 | * not linux driver id, skip the record. |
| 15732 | */ |
| 15733 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 15734 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 15735 | (rgn23_data[offset + 3] != 0)) { |
| 15736 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15737 | continue; |
| 15738 | } |
| 15739 | |
| 15740 | /* Driver found a driver specific TLV in the config region */ |
| 15741 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 15742 | offset += 4; |
| 15743 | tlv_offset = 0; |
| 15744 | |
| 15745 | /* |
| 15746 | * Search for configured port state sub-TLV. |
| 15747 | */ |
| 15748 | while ((offset < data_size) && |
| 15749 | (tlv_offset < sub_tlv_len)) { |
| 15750 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 15751 | offset += 4; |
| 15752 | tlv_offset += 4; |
| 15753 | break; |
| 15754 | } |
| 15755 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 15756 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15757 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 15758 | continue; |
| 15759 | } |
| 15760 | |
| 15761 | /* This HBA contains PORT_STE configured */ |
| 15762 | if (!rgn23_data[offset + 2]) |
| 15763 | phba->hba_flag |= LINK_DISABLED; |
| 15764 | |
| 15765 | goto out; |
| 15766 | } |
| 15767 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15768 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15769 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15770 | kfree(rgn23_data); |
| 15771 | return; |
| 15772 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15773 | |
| 15774 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15775 | * lpfc_wr_object - write an object to the firmware |
| 15776 | * @phba: HBA structure that indicates port to create a queue on. |
| 15777 | * @dmabuf_list: list of dmabufs to write to the port. |
| 15778 | * @size: the total byte value of the objects to write to the port. |
| 15779 | * @offset: the current offset to be used to start the transfer. |
| 15780 | * |
| 15781 | * This routine will create a wr_object mailbox command to send to the port. |
| 15782 | * the mailbox command will be constructed using the dma buffers described in |
| 15783 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 15784 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 15785 | * used to indicate the starting offset of the transfer and will also return |
| 15786 | * the offset after the write object mailbox has completed. @size is used to |
| 15787 | * determine the end of the object and whether the eof bit should be set. |
| 15788 | * |
| 15789 | * Return 0 is successful and offset will contain the the new offset to use |
| 15790 | * for the next write. |
| 15791 | * Return negative value for error cases. |
| 15792 | **/ |
| 15793 | int |
| 15794 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 15795 | uint32_t size, uint32_t *offset) |
| 15796 | { |
| 15797 | struct lpfc_mbx_wr_object *wr_object; |
| 15798 | LPFC_MBOXQ_t *mbox; |
| 15799 | int rc = 0, i = 0; |
| 15800 | uint32_t shdr_status, shdr_add_status; |
| 15801 | uint32_t mbox_tmo; |
| 15802 | union lpfc_sli4_cfg_shdr *shdr; |
| 15803 | struct lpfc_dmabuf *dmabuf; |
| 15804 | uint32_t written = 0; |
| 15805 | |
| 15806 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15807 | if (!mbox) |
| 15808 | return -ENOMEM; |
| 15809 | |
| 15810 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15811 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 15812 | sizeof(struct lpfc_mbx_wr_object) - |
| 15813 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 15814 | |
| 15815 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 15816 | wr_object->u.request.write_offset = *offset; |
| 15817 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 15818 | wr_object->u.request.object_name[0] = |
| 15819 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 15820 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 15821 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 15822 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 15823 | break; |
| 15824 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 15825 | wr_object->u.request.bde[i].addrHigh = |
| 15826 | putPaddrHigh(dmabuf->phys); |
| 15827 | if (written + SLI4_PAGE_SIZE >= size) { |
| 15828 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15829 | (size - written); |
| 15830 | written += (size - written); |
| 15831 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 15832 | } else { |
| 15833 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15834 | SLI4_PAGE_SIZE; |
| 15835 | written += SLI4_PAGE_SIZE; |
| 15836 | } |
| 15837 | i++; |
| 15838 | } |
| 15839 | wr_object->u.request.bde_count = i; |
| 15840 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 15841 | if (!phba->sli4_hba.intr_enable) |
| 15842 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15843 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15844 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15845 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15846 | } |
| 15847 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15848 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 15849 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15850 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15851 | if (rc != MBX_TIMEOUT) |
| 15852 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15853 | if (shdr_status || shdr_add_status || rc) { |
| 15854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15855 | "3025 Write Object mailbox failed with " |
| 15856 | "status x%x add_status x%x, mbx status x%x\n", |
| 15857 | shdr_status, shdr_add_status, rc); |
| 15858 | rc = -ENXIO; |
| 15859 | } else |
| 15860 | *offset += wr_object->u.response.actual_write_length; |
| 15861 | return rc; |
| 15862 | } |
| 15863 | |
| 15864 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15865 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 15866 | * @vport: pointer to vport data structure. |
| 15867 | * |
| 15868 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 15869 | * and REG_VPI mailbox commands associated with the vport. This function |
| 15870 | * is called when driver want to restart discovery of the vport due to |
| 15871 | * a Clear Virtual Link event. |
| 15872 | **/ |
| 15873 | void |
| 15874 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 15875 | { |
| 15876 | struct lpfc_hba *phba = vport->phba; |
| 15877 | LPFC_MBOXQ_t *mb, *nextmb; |
| 15878 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15879 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15880 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15881 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15882 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15883 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15884 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15885 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15886 | spin_lock_irq(&phba->hbalock); |
| 15887 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 15888 | if (mb->vport != vport) |
| 15889 | continue; |
| 15890 | |
| 15891 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15892 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15893 | continue; |
| 15894 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15895 | list_del(&mb->list); |
| 15896 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 15897 | } |
| 15898 | /* Clean up active mailbox command with the vport */ |
| 15899 | mb = phba->sli.mbox_active; |
| 15900 | if (mb && (mb->vport == vport)) { |
| 15901 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 15902 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 15903 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15904 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15905 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15906 | /* Put reference count for delayed processing */ |
| 15907 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 15908 | /* Unregister the RPI when mailbox complete */ |
| 15909 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15910 | } |
| 15911 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15912 | /* Cleanup any mailbox completions which are not yet processed */ |
| 15913 | do { |
| 15914 | restart_loop = 0; |
| 15915 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 15916 | /* |
| 15917 | * If this mailox is already processed or it is |
| 15918 | * for another vport ignore it. |
| 15919 | */ |
| 15920 | if ((mb->vport != vport) || |
| 15921 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 15922 | continue; |
| 15923 | |
| 15924 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15925 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15926 | continue; |
| 15927 | |
| 15928 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15929 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15930 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15931 | /* Unregister the RPI when mailbox complete */ |
| 15932 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15933 | restart_loop = 1; |
| 15934 | spin_unlock_irq(&phba->hbalock); |
| 15935 | spin_lock(shost->host_lock); |
| 15936 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15937 | spin_unlock(shost->host_lock); |
| 15938 | spin_lock_irq(&phba->hbalock); |
| 15939 | break; |
| 15940 | } |
| 15941 | } |
| 15942 | } while (restart_loop); |
| 15943 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15944 | spin_unlock_irq(&phba->hbalock); |
| 15945 | |
| 15946 | /* Release the cleaned-up mailbox commands */ |
| 15947 | while (!list_empty(&mbox_cmd_list)) { |
| 15948 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15949 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15950 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 15951 | if (mp) { |
| 15952 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15953 | kfree(mp); |
| 15954 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15955 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15956 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15957 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15958 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15959 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15960 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15961 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15962 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15963 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15964 | mempool_free(mb, phba->mbox_mem_pool); |
| 15965 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15966 | |
| 15967 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 15968 | if (act_mbx_ndlp) { |
| 15969 | spin_lock(shost->host_lock); |
| 15970 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15971 | spin_unlock(shost->host_lock); |
| 15972 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15973 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15974 | } |
| 15975 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15976 | /** |
| 15977 | * lpfc_drain_txq - Drain the txq |
| 15978 | * @phba: Pointer to HBA context object. |
| 15979 | * |
| 15980 | * This function attempt to submit IOCBs on the txq |
| 15981 | * to the adapter. For SLI4 adapters, the txq contains |
| 15982 | * ELS IOCBs that have been deferred because the there |
| 15983 | * are no SGLs. This congestion can occur with large |
| 15984 | * vport counts during node discovery. |
| 15985 | **/ |
| 15986 | |
| 15987 | uint32_t |
| 15988 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 15989 | { |
| 15990 | LIST_HEAD(completions); |
| 15991 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 15992 | struct lpfc_iocbq *piocbq = 0; |
| 15993 | unsigned long iflags = 0; |
| 15994 | char *fail_msg = NULL; |
| 15995 | struct lpfc_sglq *sglq; |
| 15996 | union lpfc_wqe wqe; |
| 15997 | |
| 15998 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15999 | if (pring->txq_cnt > pring->txq_max) |
| 16000 | pring->txq_max = pring->txq_cnt; |
| 16001 | |
| 16002 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16003 | |
| 16004 | while (pring->txq_cnt) { |
| 16005 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16006 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16007 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16008 | if (!piocbq) { |
| 16009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16010 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16011 | "2823 txq empty and txq_cnt is %d\n ", |
| 16012 | pring->txq_cnt); |
| 16013 | break; |
| 16014 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16015 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16016 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16017 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16018 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16019 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16020 | } |
| 16021 | |
| 16022 | /* The xri and iocb resources secured, |
| 16023 | * attempt to issue request |
| 16024 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16025 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16026 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16027 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16028 | fail_msg = "to convert bpl to sgl"; |
| 16029 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16030 | fail_msg = "to convert iocb to wqe"; |
| 16031 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16032 | fail_msg = " - Wq is full"; |
| 16033 | else |
| 16034 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16035 | |
| 16036 | if (fail_msg) { |
| 16037 | /* Failed means we can't issue and need to cancel */ |
| 16038 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16039 | "2822 IOCB failed %s iotag 0x%x " |
| 16040 | "xri 0x%x\n", |
| 16041 | fail_msg, |
| 16042 | piocbq->iotag, piocbq->sli4_xritag); |
| 16043 | list_add_tail(&piocbq->list, &completions); |
| 16044 | } |
| 16045 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16046 | } |
| 16047 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16048 | /* Cancel all the IOCBs that cannot be issued */ |
| 16049 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16050 | IOERR_SLI_ABORTED); |
| 16051 | |
| 16052 | return pring->txq_cnt; |
| 16053 | } |