| 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 */ |
| 104 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 105 | return -ENOMEM; |
| 106 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 107 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 108 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 109 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 110 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 111 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 112 | |
| 113 | /* Update the host index before invoking device */ |
| 114 | host_index = q->host_index; |
| 115 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 116 | |
| 117 | /* Ring Doorbell */ |
| 118 | doorbell.word0 = 0; |
| 119 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); |
| 120 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); |
| 121 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); |
| 122 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); |
| 123 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 130 | * @q: The Work Queue to operate on. |
| 131 | * @index: The index to advance the hba index to. |
| 132 | * |
| 133 | * This routine will update the HBA index of a queue to reflect consumption of |
| 134 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 135 | * an entry the host calls this function to update the queue's internal |
| 136 | * pointers. This routine returns the number of entries that were consumed by |
| 137 | * the HBA. |
| 138 | **/ |
| 139 | static uint32_t |
| 140 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 141 | { |
| 142 | uint32_t released = 0; |
| 143 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 144 | /* sanity check on queue memory */ |
| 145 | if (unlikely(!q)) |
| 146 | return 0; |
| 147 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 148 | if (q->hba_index == index) |
| 149 | return 0; |
| 150 | do { |
| 151 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 152 | released++; |
| 153 | } while (q->hba_index != index); |
| 154 | return released; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 159 | * @q: The Mailbox Queue to operate on. |
| 160 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 161 | * |
| 162 | * This routine will copy the contents of @mqe to the next available entry on |
| 163 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 164 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 165 | * successful. If no entries are available on @q then this function will return |
| 166 | * -ENOMEM. |
| 167 | * The caller is expected to hold the hbalock when calling this routine. |
| 168 | **/ |
| 169 | static uint32_t |
| 170 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 171 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 172 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 173 | struct lpfc_register doorbell; |
| 174 | uint32_t host_index; |
| 175 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 176 | /* sanity check on queue memory */ |
| 177 | if (unlikely(!q)) |
| 178 | return -ENOMEM; |
| 179 | temp_mqe = q->qe[q->host_index].mqe; |
| 180 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 181 | /* If the host has not yet processed the next entry then we are done */ |
| 182 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 183 | return -ENOMEM; |
| 184 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 185 | /* Save off the mailbox pointer for completion */ |
| 186 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 187 | |
| 188 | /* Update the host index before invoking device */ |
| 189 | host_index = q->host_index; |
| 190 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 191 | |
| 192 | /* Ring Doorbell */ |
| 193 | doorbell.word0 = 0; |
| 194 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 195 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 196 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
| 197 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 203 | * @q: The Mailbox Queue to operate on. |
| 204 | * |
| 205 | * This routine will update the HBA index of a queue to reflect consumption of |
| 206 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 207 | * an entry the host calls this function to update the queue's internal |
| 208 | * pointers. This routine returns the number of entries that were consumed by |
| 209 | * the HBA. |
| 210 | **/ |
| 211 | static uint32_t |
| 212 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 213 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 214 | /* sanity check on queue memory */ |
| 215 | if (unlikely(!q)) |
| 216 | return 0; |
| 217 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 218 | /* Clear the mailbox pointer for completion */ |
| 219 | q->phba->mbox = NULL; |
| 220 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 221 | return 1; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 226 | * @q: The Event Queue to get the first valid EQE from |
| 227 | * |
| 228 | * This routine will get the first valid Event Queue Entry from @q, update |
| 229 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 230 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 231 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 232 | **/ |
| 233 | static struct lpfc_eqe * |
| 234 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 235 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 236 | struct lpfc_eqe *eqe; |
| 237 | |
| 238 | /* sanity check on queue memory */ |
| 239 | if (unlikely(!q)) |
| 240 | return NULL; |
| 241 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 242 | |
| 243 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 244 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 245 | return NULL; |
| 246 | /* If the host has not yet processed the next entry then we are done */ |
| 247 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 248 | return NULL; |
| 249 | |
| 250 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 251 | return eqe; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 256 | * @q: The Event Queue that the host has completed processing for. |
| 257 | * @arm: Indicates whether the host wants to arms this CQ. |
| 258 | * |
| 259 | * This routine will mark all Event Queue Entries on @q, from the last |
| 260 | * known completed entry to the last entry that was processed, as completed |
| 261 | * by clearing the valid bit for each completion queue entry. Then it will |
| 262 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 263 | * The internal host index in the @q will be updated by this routine to indicate |
| 264 | * that the host has finished processing the entries. The @arm parameter |
| 265 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 266 | * |
| 267 | * This function will return the number of EQEs that were popped. |
| 268 | **/ |
| 269 | uint32_t |
| 270 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 271 | { |
| 272 | uint32_t released = 0; |
| 273 | struct lpfc_eqe *temp_eqe; |
| 274 | struct lpfc_register doorbell; |
| 275 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 276 | /* sanity check on queue memory */ |
| 277 | if (unlikely(!q)) |
| 278 | return 0; |
| 279 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 280 | /* while there are valid entries */ |
| 281 | while (q->hba_index != q->host_index) { |
| 282 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 283 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 284 | released++; |
| 285 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 286 | } |
| 287 | if (unlikely(released == 0 && !arm)) |
| 288 | return 0; |
| 289 | |
| 290 | /* ring doorbell for number popped */ |
| 291 | doorbell.word0 = 0; |
| 292 | if (arm) { |
| 293 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 294 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 295 | } |
| 296 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 297 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 298 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 299 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 300 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 301 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 302 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 303 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 304 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 305 | return released; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 310 | * @q: The Completion Queue to get the first valid CQE from |
| 311 | * |
| 312 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 313 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 314 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 315 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 316 | **/ |
| 317 | static struct lpfc_cqe * |
| 318 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 319 | { |
| 320 | struct lpfc_cqe *cqe; |
| 321 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 322 | /* sanity check on queue memory */ |
| 323 | if (unlikely(!q)) |
| 324 | return NULL; |
| 325 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 326 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 327 | 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] | 328 | return NULL; |
| 329 | /* If the host has not yet processed the next entry then we are done */ |
| 330 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) |
| 331 | return NULL; |
| 332 | |
| 333 | cqe = q->qe[q->hba_index].cqe; |
| 334 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 335 | return cqe; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 340 | * @q: The Completion Queue that the host has completed processing for. |
| 341 | * @arm: Indicates whether the host wants to arms this CQ. |
| 342 | * |
| 343 | * This routine will mark all Completion queue entries on @q, from the last |
| 344 | * known completed entry to the last entry that was processed, as completed |
| 345 | * by clearing the valid bit for each completion queue entry. Then it will |
| 346 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 347 | * The internal host index in the @q will be updated by this routine to indicate |
| 348 | * that the host has finished processing the entries. The @arm parameter |
| 349 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 350 | * |
| 351 | * This function will return the number of CQEs that were released. |
| 352 | **/ |
| 353 | uint32_t |
| 354 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 355 | { |
| 356 | uint32_t released = 0; |
| 357 | struct lpfc_cqe *temp_qe; |
| 358 | struct lpfc_register doorbell; |
| 359 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 360 | /* sanity check on queue memory */ |
| 361 | if (unlikely(!q)) |
| 362 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 363 | /* while there are valid entries */ |
| 364 | while (q->hba_index != q->host_index) { |
| 365 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 366 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 367 | released++; |
| 368 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 369 | } |
| 370 | if (unlikely(released == 0 && !arm)) |
| 371 | return 0; |
| 372 | |
| 373 | /* ring doorbell for number popped */ |
| 374 | doorbell.word0 = 0; |
| 375 | if (arm) |
| 376 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 377 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 378 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 379 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 380 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 381 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 382 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 383 | return released; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 388 | * @q: The Header Receive Queue to operate on. |
| 389 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 390 | * |
| 391 | * This routine will copy the contents of @wqe to the next available entry on |
| 392 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 393 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 394 | * index that the rqe was copied to if successful. If no entries are available |
| 395 | * on @q then this function will return -ENOMEM. |
| 396 | * The caller is expected to hold the hbalock when calling this routine. |
| 397 | **/ |
| 398 | static int |
| 399 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 400 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 401 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 402 | struct lpfc_rqe *temp_hrqe; |
| 403 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 404 | struct lpfc_register doorbell; |
| 405 | int put_index = hq->host_index; |
| 406 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 407 | /* sanity check on queue memory */ |
| 408 | if (unlikely(!hq) || unlikely(!dq)) |
| 409 | return -ENOMEM; |
| 410 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 411 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 412 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 413 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 414 | return -EINVAL; |
| 415 | if (hq->host_index != dq->host_index) |
| 416 | return -EINVAL; |
| 417 | /* If the host has not yet processed the next entry then we are done */ |
| 418 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 419 | return -EBUSY; |
| 420 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 421 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 422 | |
| 423 | /* Update the host index to point to the next slot */ |
| 424 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 425 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 426 | |
| 427 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 428 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 429 | doorbell.word0 = 0; |
| 430 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 431 | hq->entry_repost); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 432 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
| 433 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); |
| 434 | } |
| 435 | return put_index; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 440 | * @q: The Header Receive Queue to operate on. |
| 441 | * |
| 442 | * This routine will update the HBA index of a queue to reflect consumption of |
| 443 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 444 | * consumed an entry the host calls this function to update the queue's |
| 445 | * internal pointers. This routine returns the number of entries that were |
| 446 | * consumed by the HBA. |
| 447 | **/ |
| 448 | static uint32_t |
| 449 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 450 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 451 | /* sanity check on queue memory */ |
| 452 | if (unlikely(!hq) || unlikely(!dq)) |
| 453 | return 0; |
| 454 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 455 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 456 | return 0; |
| 457 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 458 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 459 | return 1; |
| 460 | } |
| 461 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 462 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 463 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 464 | * @phba: Pointer to HBA context object. |
| 465 | * @pring: Pointer to driver SLI ring object. |
| 466 | * |
| 467 | * This function returns pointer to next command iocb entry |
| 468 | * in the command ring. The caller must hold hbalock to prevent |
| 469 | * other threads consume the next command iocb. |
| 470 | * SLI-2/SLI-3 provide different sized iocbs. |
| 471 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 472 | static inline IOCB_t * |
| 473 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 474 | { |
| 475 | return (IOCB_t *) (((char *) pring->cmdringaddr) + |
| 476 | pring->cmdidx * phba->iocb_cmd_size); |
| 477 | } |
| 478 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 479 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 480 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 481 | * @phba: Pointer to HBA context object. |
| 482 | * @pring: Pointer to driver SLI ring object. |
| 483 | * |
| 484 | * This function returns pointer to next response iocb entry |
| 485 | * in the response ring. The caller must hold hbalock to make sure |
| 486 | * that no other thread consume the next response iocb. |
| 487 | * SLI-2/SLI-3 provide different sized iocbs. |
| 488 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 489 | static inline IOCB_t * |
| 490 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 491 | { |
| 492 | return (IOCB_t *) (((char *) pring->rspringaddr) + |
| 493 | pring->rspidx * phba->iocb_rsp_size); |
| 494 | } |
| 495 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 496 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 497 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 498 | * @phba: Pointer to HBA context object. |
| 499 | * |
| 500 | * This function is called with hbalock held. This function |
| 501 | * allocates a new driver iocb object from the iocb pool. If the |
| 502 | * allocation is successful, it returns pointer to the newly |
| 503 | * allocated iocb object else it returns NULL. |
| 504 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 505 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 507 | { |
| 508 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 509 | struct lpfc_iocbq * iocbq = NULL; |
| 510 | |
| 511 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 512 | if (iocbq) |
| 513 | phba->iocb_cnt++; |
| 514 | if (phba->iocb_cnt > phba->iocb_max) |
| 515 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 516 | return iocbq; |
| 517 | } |
| 518 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 519 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 520 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 521 | * @phba: Pointer to HBA context object. |
| 522 | * @xritag: XRI value. |
| 523 | * |
| 524 | * This function clears the sglq pointer from the array of acive |
| 525 | * sglq's. The xritag that is passed in is used to index into the |
| 526 | * array. Before the xritag can be used it needs to be adjusted |
| 527 | * by subtracting the xribase. |
| 528 | * |
| 529 | * Returns sglq ponter = success, NULL = Failure. |
| 530 | **/ |
| 531 | static struct lpfc_sglq * |
| 532 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 533 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 534 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 535 | |
| 536 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 537 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 538 | return sglq; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 543 | * @phba: Pointer to HBA context object. |
| 544 | * @xritag: XRI value. |
| 545 | * |
| 546 | * This function returns the sglq pointer from the array of acive |
| 547 | * sglq's. The xritag that is passed in is used to index into the |
| 548 | * array. Before the xritag can be used it needs to be adjusted |
| 549 | * by subtracting the xribase. |
| 550 | * |
| 551 | * Returns sglq ponter = success, NULL = Failure. |
| 552 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 553 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 554 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 555 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 556 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 557 | |
| 558 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 559 | return sglq; |
| 560 | } |
| 561 | |
| 562 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 563 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 564 | * @phba: Pointer to HBA context object. |
| 565 | * @xritag: xri used in this exchange. |
| 566 | * @rrq: The RRQ to be cleared. |
| 567 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 568 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 569 | void |
| 570 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 571 | uint16_t xritag, |
| 572 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 573 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 574 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 575 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 576 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 577 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 578 | |
| 579 | /* The target DID could have been swapped (cable swap) |
| 580 | * we should use the ndlp from the findnode if it is |
| 581 | * available. |
| 582 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 583 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 584 | ndlp = rrq->ndlp; |
| 585 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 586 | if (!ndlp) |
| 587 | goto out; |
| 588 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 589 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 590 | rrq->send_rrq = 0; |
| 591 | rrq->xritag = 0; |
| 592 | rrq->rrq_stop_time = 0; |
| 593 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 594 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 595 | mempool_free(rrq, phba->rrq_pool); |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 600 | * @phba: Pointer to HBA context object. |
| 601 | * |
| 602 | * This function is called with hbalock held. This function |
| 603 | * Checks if stop_time (ratov from setting rrq active) has |
| 604 | * been reached, if it has and the send_rrq flag is set then |
| 605 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 606 | * then it will just call the routine to clear the rrq and |
| 607 | * free the rrq resource. |
| 608 | * The timer is set to the next rrq that is going to expire before |
| 609 | * leaving the routine. |
| 610 | * |
| 611 | **/ |
| 612 | void |
| 613 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 614 | { |
| 615 | struct lpfc_node_rrq *rrq; |
| 616 | struct lpfc_node_rrq *nextrrq; |
| 617 | unsigned long next_time; |
| 618 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 619 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 620 | |
| 621 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 622 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 623 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 624 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 625 | &phba->active_rrq_list, list) { |
| 626 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 627 | list_move(&rrq->list, &send_rrq); |
| 628 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 629 | next_time = rrq->rrq_stop_time; |
| 630 | } |
| 631 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 632 | if (!list_empty(&phba->active_rrq_list)) |
| 633 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 634 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 635 | list_del(&rrq->list); |
| 636 | if (!rrq->send_rrq) |
| 637 | /* this call will free the rrq */ |
| 638 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 639 | else if (lpfc_send_rrq(phba, rrq)) { |
| 640 | /* if we send the rrq then the completion handler |
| 641 | * will clear the bit in the xribitmap. |
| 642 | */ |
| 643 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 644 | rrq); |
| 645 | } |
| 646 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /** |
| 650 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 651 | * @vport: Pointer to vport context object. |
| 652 | * @xri: The xri used in the exchange. |
| 653 | * @did: The targets DID for this exchange. |
| 654 | * |
| 655 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 656 | * rrq = rrq for this xri and target. |
| 657 | **/ |
| 658 | struct lpfc_node_rrq * |
| 659 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 660 | { |
| 661 | struct lpfc_hba *phba = vport->phba; |
| 662 | struct lpfc_node_rrq *rrq; |
| 663 | struct lpfc_node_rrq *nextrrq; |
| 664 | unsigned long iflags; |
| 665 | |
| 666 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 667 | return NULL; |
| 668 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 669 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 670 | if (rrq->vport == vport && rrq->xritag == xri && |
| 671 | rrq->nlp_DID == did){ |
| 672 | list_del(&rrq->list); |
| 673 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 674 | return rrq; |
| 675 | } |
| 676 | } |
| 677 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 678 | return NULL; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 683 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 684 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 685 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 686 | * phba->active_rrq_list and clear the rrq. |
| 687 | * 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] | 688 | **/ |
| 689 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 690 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 691 | |
| 692 | { |
| 693 | struct lpfc_hba *phba = vport->phba; |
| 694 | struct lpfc_node_rrq *rrq; |
| 695 | struct lpfc_node_rrq *nextrrq; |
| 696 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 697 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 698 | |
| 699 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 700 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 701 | if (!ndlp) { |
| 702 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 703 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 704 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 705 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 706 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 707 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 708 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 709 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 710 | |
| 711 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 712 | list_del(&rrq->list); |
| 713 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 714 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /** |
| 718 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 719 | * @phba: Pointer to HBA context object. |
| 720 | * |
| 721 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 722 | * calling __lpfc_clr_active_rrq |
| 723 | * |
| 724 | **/ |
| 725 | void |
| 726 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 727 | { |
| 728 | struct lpfc_node_rrq *rrq; |
| 729 | struct lpfc_node_rrq *nextrrq; |
| 730 | unsigned long next_time; |
| 731 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 732 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 733 | |
| 734 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 735 | return; |
| 736 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 737 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 738 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 739 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 740 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 741 | |
| 742 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 743 | list_del(&rrq->list); |
| 744 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 745 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 746 | if (!list_empty(&phba->active_rrq_list)) |
| 747 | mod_timer(&phba->rrq_tmr, next_time); |
| 748 | } |
| 749 | |
| 750 | |
| 751 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 752 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 753 | * @phba: Pointer to HBA context object. |
| 754 | * @ndlp: Targets nodelist pointer for this exchange. |
| 755 | * @xritag the xri in the bitmap to test. |
| 756 | * |
| 757 | * This function is called with hbalock held. This function |
| 758 | * returns 0 = rrq not active for this xri |
| 759 | * 1 = rrq is valid for this xri. |
| 760 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 761 | int |
| 762 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 763 | uint16_t xritag) |
| 764 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 765 | if (!ndlp) |
| 766 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 767 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 768 | return 1; |
| 769 | else |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 775 | * @phba: Pointer to HBA context object. |
| 776 | * @ndlp: nodelist pointer for this target. |
| 777 | * @xritag: xri used in this exchange. |
| 778 | * @rxid: Remote Exchange ID. |
| 779 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 780 | * |
| 781 | * This function takes the hbalock. |
| 782 | * The active bit is always set in the active rrq xri_bitmap even |
| 783 | * if there is no slot avaiable for the other rrq information. |
| 784 | * |
| 785 | * returns 0 rrq actived for this xri |
| 786 | * < 0 No memory or invalid ndlp. |
| 787 | **/ |
| 788 | int |
| 789 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 790 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 791 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 792 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 793 | struct lpfc_node_rrq *rrq; |
| 794 | int empty; |
| 795 | |
| 796 | if (!ndlp) |
| 797 | return -EINVAL; |
| 798 | |
| 799 | if (!phba->cfg_enable_rrq) |
| 800 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 801 | |
| 802 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 803 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 804 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 805 | goto out; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * set the active bit even if there is no mem available. |
| 810 | */ |
| 811 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 812 | goto out; |
| 813 | |
| 814 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 815 | goto out; |
| 816 | |
| 817 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 818 | goto out; |
| 819 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 820 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 821 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 822 | if (!rrq) { |
| 823 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 824 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 825 | " DID:0x%x Send:%d\n", |
| 826 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 827 | return -EINVAL; |
| 828 | } |
| 829 | rrq->send_rrq = send_rrq; |
| 830 | rrq->xritag = xritag; |
| 831 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 832 | rrq->ndlp = ndlp; |
| 833 | rrq->nlp_DID = ndlp->nlp_DID; |
| 834 | rrq->vport = ndlp->vport; |
| 835 | rrq->rxid = rxid; |
| 836 | rrq->send_rrq = send_rrq; |
| 837 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 838 | empty = list_empty(&phba->active_rrq_list); |
| 839 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 840 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 841 | if (empty) |
| 842 | lpfc_worker_wake_up(phba); |
| 843 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 844 | return 0; |
| 845 | out: |
| 846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 847 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 848 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 849 | " DID:0x%x Send:%d\n", |
| 850 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 851 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 855 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 856 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 857 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 858 | * |
| 859 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 860 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 861 | * list is not empty then it is successful, it returns pointer to the newly |
| 862 | * allocated sglq object else it returns NULL. |
| 863 | **/ |
| 864 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 866 | { |
| 867 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 868 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 869 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 870 | struct lpfc_scsi_buf *lpfc_cmd; |
| 871 | struct lpfc_nodelist *ndlp; |
| 872 | int found = 0; |
| 873 | |
| 874 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 875 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 876 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 877 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 878 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 879 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 880 | else |
| 881 | ndlp = piocbq->context1; |
| 882 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 883 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 884 | start_sglq = sglq; |
| 885 | while (!found) { |
| 886 | if (!sglq) |
| 887 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame^] | 888 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 889 | /* This xri has an rrq outstanding for this DID. |
| 890 | * put it back in the list and get another xri. |
| 891 | */ |
| 892 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 893 | sglq = NULL; |
| 894 | list_remove_head(lpfc_sgl_list, sglq, |
| 895 | struct lpfc_sglq, list); |
| 896 | if (sglq == start_sglq) { |
| 897 | sglq = NULL; |
| 898 | break; |
| 899 | } else |
| 900 | continue; |
| 901 | } |
| 902 | sglq->ndlp = ndlp; |
| 903 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 904 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 905 | sglq->state = SGL_ALLOCATED; |
| 906 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 907 | return sglq; |
| 908 | } |
| 909 | |
| 910 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 911 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 912 | * @phba: Pointer to HBA context object. |
| 913 | * |
| 914 | * This function is called with no lock held. This function |
| 915 | * allocates a new driver iocb object from the iocb pool. If the |
| 916 | * allocation is successful, it returns pointer to the newly |
| 917 | * allocated iocb object else it returns NULL. |
| 918 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 919 | struct lpfc_iocbq * |
| 920 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 921 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 922 | struct lpfc_iocbq * iocbq = NULL; |
| 923 | unsigned long iflags; |
| 924 | |
| 925 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 926 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 927 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 928 | return iocbq; |
| 929 | } |
| 930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 931 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 932 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 933 | * @phba: Pointer to HBA context object. |
| 934 | * @iocbq: Pointer to driver iocb object. |
| 935 | * |
| 936 | * This function is called with hbalock held to release driver |
| 937 | * iocb object to the iocb pool. The iotag in the iocb object |
| 938 | * does not change for each use of the iocb object. This function |
| 939 | * clears all other fields of the iocb object when it is freed. |
| 940 | * The sqlq structure that holds the xritag and phys and virtual |
| 941 | * mappings for the scatter gather list is retrieved from the |
| 942 | * active array of sglq. The get of the sglq pointer also clears |
| 943 | * the entry in the array. If the status of the IO indiactes that |
| 944 | * this IO was aborted then the sglq entry it put on the |
| 945 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 946 | * IO has good status or fails for any other reason then the sglq |
| 947 | * entry is added to the free list (lpfc_sgl_list). |
| 948 | **/ |
| 949 | static void |
| 950 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 951 | { |
| 952 | struct lpfc_sglq *sglq; |
| 953 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 954 | unsigned long iflag = 0; |
| 955 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 956 | |
| 957 | if (iocbq->sli4_xritag == NO_XRI) |
| 958 | sglq = NULL; |
| 959 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 960 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 961 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 962 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 963 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 964 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 965 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 966 | iflag); |
| 967 | list_add(&sglq->list, |
| 968 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 969 | spin_unlock_irqrestore( |
| 970 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 971 | } else { |
| 972 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 973 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 974 | list_add_tail(&sglq->list, |
| 975 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 976 | |
| 977 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 978 | if (pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 979 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 980 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | |
| 984 | /* |
| 985 | * Clean all volatile data fields, preserve iotag and node struct. |
| 986 | */ |
| 987 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 988 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 989 | iocbq->sli4_xritag = NO_XRI; |
| 990 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 991 | } |
| 992 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 993 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 994 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 995 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 996 | * @phba: Pointer to HBA context object. |
| 997 | * @iocbq: Pointer to driver iocb object. |
| 998 | * |
| 999 | * This function is called with hbalock held to release driver |
| 1000 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1001 | * does not change for each use of the iocb object. This function |
| 1002 | * clears all other fields of the iocb object when it is freed. |
| 1003 | **/ |
| 1004 | static void |
| 1005 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1006 | { |
| 1007 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1008 | |
| 1009 | /* |
| 1010 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1011 | */ |
| 1012 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1013 | iocbq->sli4_xritag = NO_XRI; |
| 1014 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1018 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1019 | * @phba: Pointer to HBA context object. |
| 1020 | * @iocbq: Pointer to driver iocb object. |
| 1021 | * |
| 1022 | * This function is called with hbalock held to release driver |
| 1023 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1024 | * does not change for each use of the iocb object. This function |
| 1025 | * clears all other fields of the iocb object when it is freed. |
| 1026 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1027 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1029 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1030 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1031 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1034 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1035 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1036 | * @phba: Pointer to HBA context object. |
| 1037 | * @iocbq: Pointer to driver iocb object. |
| 1038 | * |
| 1039 | * This function is called with no lock held to release the iocb to |
| 1040 | * iocb pool. |
| 1041 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1042 | void |
| 1043 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1044 | { |
| 1045 | unsigned long iflags; |
| 1046 | |
| 1047 | /* |
| 1048 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1049 | */ |
| 1050 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1051 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1052 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1053 | } |
| 1054 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1055 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1056 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1057 | * @phba: Pointer to HBA context object. |
| 1058 | * @iocblist: List of IOCBs. |
| 1059 | * @ulpstatus: ULP status in IOCB command field. |
| 1060 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1061 | * |
| 1062 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1063 | * on the list by invoking the complete callback function associated with the |
| 1064 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1065 | * fields. |
| 1066 | **/ |
| 1067 | void |
| 1068 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1069 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1070 | { |
| 1071 | struct lpfc_iocbq *piocb; |
| 1072 | |
| 1073 | while (!list_empty(iocblist)) { |
| 1074 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 1075 | |
| 1076 | if (!piocb->iocb_cmpl) |
| 1077 | lpfc_sli_release_iocbq(phba, piocb); |
| 1078 | else { |
| 1079 | piocb->iocb.ulpStatus = ulpstatus; |
| 1080 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1081 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1082 | } |
| 1083 | } |
| 1084 | return; |
| 1085 | } |
| 1086 | |
| 1087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1088 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1089 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1090 | * |
| 1091 | * This function is called by ring event handler function to get the iocb type. |
| 1092 | * This function translates the iocb command to an iocb command type used to |
| 1093 | * decide the final disposition of each completed IOCB. |
| 1094 | * The function returns |
| 1095 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1096 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1097 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1098 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1099 | * |
| 1100 | * The caller is not required to hold any lock. |
| 1101 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1102 | static lpfc_iocb_type |
| 1103 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1104 | { |
| 1105 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1106 | |
| 1107 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1108 | return 0; |
| 1109 | |
| 1110 | switch (iocb_cmnd) { |
| 1111 | case CMD_XMIT_SEQUENCE_CR: |
| 1112 | case CMD_XMIT_SEQUENCE_CX: |
| 1113 | case CMD_XMIT_BCAST_CN: |
| 1114 | case CMD_XMIT_BCAST_CX: |
| 1115 | case CMD_ELS_REQUEST_CR: |
| 1116 | case CMD_ELS_REQUEST_CX: |
| 1117 | case CMD_CREATE_XRI_CR: |
| 1118 | case CMD_CREATE_XRI_CX: |
| 1119 | case CMD_GET_RPI_CN: |
| 1120 | case CMD_XMIT_ELS_RSP_CX: |
| 1121 | case CMD_GET_RPI_CR: |
| 1122 | case CMD_FCP_IWRITE_CR: |
| 1123 | case CMD_FCP_IWRITE_CX: |
| 1124 | case CMD_FCP_IREAD_CR: |
| 1125 | case CMD_FCP_IREAD_CX: |
| 1126 | case CMD_FCP_ICMND_CR: |
| 1127 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1128 | case CMD_FCP_TSEND_CX: |
| 1129 | case CMD_FCP_TRSP_CX: |
| 1130 | case CMD_FCP_TRECEIVE_CX: |
| 1131 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | case CMD_ADAPTER_MSG: |
| 1133 | case CMD_ADAPTER_DUMP: |
| 1134 | case CMD_XMIT_SEQUENCE64_CR: |
| 1135 | case CMD_XMIT_SEQUENCE64_CX: |
| 1136 | case CMD_XMIT_BCAST64_CN: |
| 1137 | case CMD_XMIT_BCAST64_CX: |
| 1138 | case CMD_ELS_REQUEST64_CR: |
| 1139 | case CMD_ELS_REQUEST64_CX: |
| 1140 | case CMD_FCP_IWRITE64_CR: |
| 1141 | case CMD_FCP_IWRITE64_CX: |
| 1142 | case CMD_FCP_IREAD64_CR: |
| 1143 | case CMD_FCP_IREAD64_CX: |
| 1144 | case CMD_FCP_ICMND64_CR: |
| 1145 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1146 | case CMD_FCP_TSEND64_CX: |
| 1147 | case CMD_FCP_TRSP64_CX: |
| 1148 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1149 | case CMD_GEN_REQUEST64_CR: |
| 1150 | case CMD_GEN_REQUEST64_CX: |
| 1151 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1152 | case DSSCMD_IWRITE64_CR: |
| 1153 | case DSSCMD_IWRITE64_CX: |
| 1154 | case DSSCMD_IREAD64_CR: |
| 1155 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 | type = LPFC_SOL_IOCB; |
| 1157 | break; |
| 1158 | case CMD_ABORT_XRI_CN: |
| 1159 | case CMD_ABORT_XRI_CX: |
| 1160 | case CMD_CLOSE_XRI_CN: |
| 1161 | case CMD_CLOSE_XRI_CX: |
| 1162 | case CMD_XRI_ABORTED_CX: |
| 1163 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1164 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | type = LPFC_ABORT_IOCB; |
| 1166 | break; |
| 1167 | case CMD_RCV_SEQUENCE_CX: |
| 1168 | case CMD_RCV_ELS_REQ_CX: |
| 1169 | case CMD_RCV_SEQUENCE64_CX: |
| 1170 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1171 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1172 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1173 | case CMD_IOCB_RCV_ELS64_CX: |
| 1174 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1175 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | type = LPFC_UNSOL_IOCB; |
| 1177 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1178 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1179 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1180 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1181 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1182 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1183 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1184 | case CMD_IOCB_RET_HBQE64_CN: |
| 1185 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1186 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1187 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1188 | case CMD_IOCB_LOGENTRY_CN: |
| 1189 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1190 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1191 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1192 | type = LPFC_UNKNOWN_IOCB; |
| 1193 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1194 | default: |
| 1195 | type = LPFC_UNKNOWN_IOCB; |
| 1196 | break; |
| 1197 | } |
| 1198 | |
| 1199 | return type; |
| 1200 | } |
| 1201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1203 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1204 | * @phba: Pointer to HBA context object. |
| 1205 | * |
| 1206 | * This function is called from SLI initialization code |
| 1207 | * to configure every ring of the HBA's SLI interface. The |
| 1208 | * caller is not required to hold any lock. This function issues |
| 1209 | * a config_ring mailbox command for each ring. |
| 1210 | * This function returns zero if successful else returns a negative |
| 1211 | * error code. |
| 1212 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1214 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | { |
| 1216 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1217 | LPFC_MBOXQ_t *pmb; |
| 1218 | MAILBOX_t *pmbox; |
| 1219 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1221 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1222 | if (!pmb) |
| 1223 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1224 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1225 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | lpfc_config_ring(phba, i, pmb); |
| 1228 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1229 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1231 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1233 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1234 | rc, pmbox->mbxCommand, |
| 1235 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1236 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1237 | ret = -ENXIO; |
| 1238 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | } |
| 1240 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1241 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1242 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | } |
| 1244 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1245 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1246 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1247 | * @phba: Pointer to HBA context object. |
| 1248 | * @pring: Pointer to driver SLI ring object. |
| 1249 | * @piocb: Pointer to the driver iocb object. |
| 1250 | * |
| 1251 | * This function is called with hbalock held. The function adds the |
| 1252 | * new iocb to txcmplq of the given ring. This function always returns |
| 1253 | * 0. If this function is called for ELS ring, this function checks if |
| 1254 | * there is a vport associated with the ELS command. This function also |
| 1255 | * starts els_tmofunc timer if this is an ELS command. |
| 1256 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1258 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1259 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1262 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1264 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
| 1265 | pring->txcmplq_max = pring->txcmplq_cnt; |
| 1266 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1267 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1268 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1269 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1270 | if (!piocb->vport) |
| 1271 | BUG(); |
| 1272 | else |
| 1273 | mod_timer(&piocb->vport->els_tmofunc, |
| 1274 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1275 | } |
| 1276 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1278 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | } |
| 1280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1281 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1282 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1283 | * @phba: Pointer to HBA context object. |
| 1284 | * @pring: Pointer to driver SLI ring object. |
| 1285 | * |
| 1286 | * This function is called with hbalock held to get next |
| 1287 | * iocb in txq of the given ring. If there is any iocb in |
| 1288 | * the txq, the function returns first iocb in the list after |
| 1289 | * removing the iocb from the list, else it returns NULL. |
| 1290 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1291 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1292 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | struct lpfc_iocbq *cmd_iocb; |
| 1295 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1296 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 1297 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1298 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1299 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | } |
| 1301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1302 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1303 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1304 | * @phba: Pointer to HBA context object. |
| 1305 | * @pring: Pointer to driver SLI ring object. |
| 1306 | * |
| 1307 | * This function is called with hbalock held and the caller must post the |
| 1308 | * iocb without releasing the lock. If the caller releases the lock, |
| 1309 | * iocb slot returned by the function is not guaranteed to be available. |
| 1310 | * The function returns pointer to the next available iocb slot if there |
| 1311 | * is available slot in the ring, else it returns NULL. |
| 1312 | * If the get index of the ring is ahead of the put index, the function |
| 1313 | * will post an error attention event to the worker thread to take the |
| 1314 | * HBA to offline state. |
| 1315 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | static IOCB_t * |
| 1317 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1318 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1319 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | uint32_t max_cmd_idx = pring->numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | if ((pring->next_cmdidx == pring->cmdidx) && |
| 1322 | (++pring->next_cmdidx >= max_cmd_idx)) |
| 1323 | pring->next_cmdidx = 0; |
| 1324 | |
| 1325 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { |
| 1326 | |
| 1327 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 1328 | |
| 1329 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { |
| 1330 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1331 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1332 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1333 | pring->ringno, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | pring->local_getidx, max_cmd_idx); |
| 1335 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1336 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | /* |
| 1338 | * All error attention handlers are posted to |
| 1339 | * worker thread |
| 1340 | */ |
| 1341 | phba->work_ha |= HA_ERATT; |
| 1342 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1343 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1344 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | |
| 1346 | return NULL; |
| 1347 | } |
| 1348 | |
| 1349 | if (pring->local_getidx == pring->next_cmdidx) |
| 1350 | return NULL; |
| 1351 | } |
| 1352 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1353 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1354 | } |
| 1355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1356 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1357 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1358 | * @phba: Pointer to HBA context object. |
| 1359 | * @iocbq: Pointer to driver iocb object. |
| 1360 | * |
| 1361 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1362 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1363 | * array and assigns a new iotag. |
| 1364 | * The function returns the allocated iotag if successful, else returns zero. |
| 1365 | * Zero is not a valid iotag. |
| 1366 | * The caller is not required to hold any lock. |
| 1367 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1368 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1369 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1371 | struct lpfc_iocbq **new_arr; |
| 1372 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1373 | size_t new_len; |
| 1374 | struct lpfc_sli *psli = &phba->sli; |
| 1375 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1377 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1378 | iotag = psli->last_iotag; |
| 1379 | if(++iotag < psli->iocbq_lookup_len) { |
| 1380 | psli->last_iotag = iotag; |
| 1381 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1382 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1383 | iocbq->iotag = iotag; |
| 1384 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1385 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1386 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1387 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1388 | spin_unlock_irq(&phba->hbalock); |
| 1389 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1390 | GFP_KERNEL); |
| 1391 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1392 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1393 | old_arr = psli->iocbq_lookup; |
| 1394 | if (new_len <= psli->iocbq_lookup_len) { |
| 1395 | /* highly unprobable case */ |
| 1396 | kfree(new_arr); |
| 1397 | iotag = psli->last_iotag; |
| 1398 | if(++iotag < psli->iocbq_lookup_len) { |
| 1399 | psli->last_iotag = iotag; |
| 1400 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1402 | iocbq->iotag = iotag; |
| 1403 | return iotag; |
| 1404 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1406 | return 0; |
| 1407 | } |
| 1408 | if (psli->iocbq_lookup) |
| 1409 | memcpy(new_arr, old_arr, |
| 1410 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1411 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1412 | psli->iocbq_lookup = new_arr; |
| 1413 | psli->iocbq_lookup_len = new_len; |
| 1414 | psli->last_iotag = iotag; |
| 1415 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1416 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1417 | iocbq->iotag = iotag; |
| 1418 | kfree(old_arr); |
| 1419 | return iotag; |
| 1420 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1421 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1422 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1424 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1425 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1426 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1428 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | } |
| 1430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1432 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1433 | * @phba: Pointer to HBA context object. |
| 1434 | * @pring: Pointer to driver SLI ring object. |
| 1435 | * @iocb: Pointer to iocb slot in the ring. |
| 1436 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1437 | * posted to firmware. |
| 1438 | * |
| 1439 | * This function is called with hbalock held to post a new iocb to |
| 1440 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1441 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1442 | * a completion call back for this iocb else the function will free the |
| 1443 | * iocb object. |
| 1444 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | static void |
| 1446 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1447 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1448 | { |
| 1449 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1450 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1452 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1454 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1455 | if (pring->ringno == LPFC_ELS_RING) { |
| 1456 | lpfc_debugfs_slow_ring_trc(phba, |
| 1457 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1458 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1459 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1460 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1461 | } |
| 1462 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | /* |
| 1464 | * Issue iocb command to adapter |
| 1465 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1466 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | wmb(); |
| 1468 | pring->stats.iocb_cmd++; |
| 1469 | |
| 1470 | /* |
| 1471 | * If there is no completion routine to call, we can release the |
| 1472 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1473 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1474 | */ |
| 1475 | if (nextiocb->iocb_cmpl) |
| 1476 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1477 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1478 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1479 | |
| 1480 | /* |
| 1481 | * Let the HBA know what IOCB slot will be the next one the |
| 1482 | * driver will put a command into. |
| 1483 | */ |
| 1484 | pring->cmdidx = pring->next_cmdidx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1485 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | } |
| 1487 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1489 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1490 | * @phba: Pointer to HBA context object. |
| 1491 | * @pring: Pointer to driver SLI ring object. |
| 1492 | * |
| 1493 | * The caller is not required to hold any lock for calling this function. |
| 1494 | * This function updates the chip attention bits for the ring to inform firmware |
| 1495 | * that there are pending work to be done for this ring and requests an |
| 1496 | * interrupt when there is space available in the ring. This function is |
| 1497 | * called when the driver is unable to post more iocbs to the ring due |
| 1498 | * to unavailability of space in the ring. |
| 1499 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1501 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | { |
| 1503 | int ringno = pring->ringno; |
| 1504 | |
| 1505 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1506 | |
| 1507 | wmb(); |
| 1508 | |
| 1509 | /* |
| 1510 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1511 | * The HBA will tell us when an IOCB entry is available. |
| 1512 | */ |
| 1513 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1514 | readl(phba->CAregaddr); /* flush */ |
| 1515 | |
| 1516 | pring->stats.iocb_cmd_full++; |
| 1517 | } |
| 1518 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1519 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1520 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1521 | * @phba: Pointer to HBA context object. |
| 1522 | * @pring: Pointer to driver SLI ring object. |
| 1523 | * |
| 1524 | * This function updates the chip attention register bit for the |
| 1525 | * given ring to inform HBA that there is more work to be done |
| 1526 | * in this ring. The caller is not required to hold any lock. |
| 1527 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1529 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | { |
| 1531 | int ringno = pring->ringno; |
| 1532 | |
| 1533 | /* |
| 1534 | * Tell the HBA that there is work to do in this ring. |
| 1535 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1536 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1537 | wmb(); |
| 1538 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1539 | readl(phba->CAregaddr); /* flush */ |
| 1540 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | } |
| 1542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1543 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1544 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1545 | * @phba: Pointer to HBA context object. |
| 1546 | * @pring: Pointer to driver SLI ring object. |
| 1547 | * |
| 1548 | * This function is called with hbalock held to post pending iocbs |
| 1549 | * in the txq to the firmware. This function is called when driver |
| 1550 | * detects space available in the ring. |
| 1551 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | { |
| 1555 | IOCB_t *iocb; |
| 1556 | struct lpfc_iocbq *nextiocb; |
| 1557 | |
| 1558 | /* |
| 1559 | * Check to see if: |
| 1560 | * (a) there is anything on the txq to send |
| 1561 | * (b) link is up |
| 1562 | * (c) link attention events can be processed (fcp ring only) |
| 1563 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1564 | */ |
| 1565 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1566 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1568 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | |
| 1570 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1571 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1572 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1573 | |
| 1574 | if (iocb) |
| 1575 | lpfc_sli_update_ring(phba, pring); |
| 1576 | else |
| 1577 | lpfc_sli_update_full_ring(phba, pring); |
| 1578 | } |
| 1579 | |
| 1580 | return; |
| 1581 | } |
| 1582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1583 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1584 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1585 | * @phba: Pointer to HBA context object. |
| 1586 | * @hbqno: HBQ number. |
| 1587 | * |
| 1588 | * This function is called with hbalock held to get the next |
| 1589 | * available slot for the given HBQ. If there is free slot |
| 1590 | * available for the HBQ it will return pointer to the next available |
| 1591 | * HBQ entry else it will return NULL. |
| 1592 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1593 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1594 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1595 | { |
| 1596 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1597 | |
| 1598 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1599 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1600 | hbqp->next_hbqPutIdx = 0; |
| 1601 | |
| 1602 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1603 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1604 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1605 | |
| 1606 | hbqp->local_hbqGetIdx = getidx; |
| 1607 | |
| 1608 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1609 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1610 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1611 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1612 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1613 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1614 | hbqp->entry_count); |
| 1615 | |
| 1616 | phba->link_state = LPFC_HBA_ERROR; |
| 1617 | return NULL; |
| 1618 | } |
| 1619 | |
| 1620 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1621 | return NULL; |
| 1622 | } |
| 1623 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1624 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1625 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1626 | } |
| 1627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1629 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1630 | * @phba: Pointer to HBA context object. |
| 1631 | * |
| 1632 | * This function is called with no lock held to free all the |
| 1633 | * hbq buffers while uninitializing the SLI interface. It also |
| 1634 | * frees the HBQ buffers returned by the firmware but not yet |
| 1635 | * processed by the upper layers. |
| 1636 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1637 | void |
| 1638 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1639 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1640 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1641 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1642 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1643 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1644 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1645 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1646 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1647 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1648 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1649 | for (i = 0; i < hbq_count; ++i) { |
| 1650 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1651 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1652 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1653 | list_del(&hbq_buf->dbuf.list); |
| 1654 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1655 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1656 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1657 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1658 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1659 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1660 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1661 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1662 | list_del(&hbq_buf->dbuf.list); |
| 1663 | if (hbq_buf->tag == -1) { |
| 1664 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1665 | (phba, hbq_buf); |
| 1666 | } else { |
| 1667 | hbqno = hbq_buf->tag >> 16; |
| 1668 | if (hbqno >= LPFC_MAX_HBQS) |
| 1669 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1670 | (phba, hbq_buf); |
| 1671 | else |
| 1672 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1673 | hbq_buf); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | /* Mark the HBQs not in use */ |
| 1678 | phba->hbq_in_use = 0; |
| 1679 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1680 | } |
| 1681 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1682 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1683 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1684 | * @phba: Pointer to HBA context object. |
| 1685 | * @hbqno: HBQ number. |
| 1686 | * @hbq_buf: Pointer to HBQ buffer. |
| 1687 | * |
| 1688 | * This function is called with the hbalock held to post a |
| 1689 | * hbq buffer to the firmware. If the function finds an empty |
| 1690 | * slot in the HBQ, it will post the buffer. The function will return |
| 1691 | * pointer to the hbq entry if it successfully post the buffer |
| 1692 | * else it will return NULL. |
| 1693 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1694 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1695 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1696 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1697 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1698 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1699 | } |
| 1700 | |
| 1701 | /** |
| 1702 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1703 | * @phba: Pointer to HBA context object. |
| 1704 | * @hbqno: HBQ number. |
| 1705 | * @hbq_buf: Pointer to HBQ buffer. |
| 1706 | * |
| 1707 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1708 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1709 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1710 | * it successfully post the buffer else it will return an error. |
| 1711 | **/ |
| 1712 | static int |
| 1713 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1714 | struct hbq_dmabuf *hbq_buf) |
| 1715 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1716 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1717 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1718 | |
| 1719 | /* Get next HBQ entry slot to use */ |
| 1720 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1721 | if (hbqe) { |
| 1722 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1723 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1724 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1725 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1726 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1727 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1728 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1729 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1730 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1731 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1732 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1733 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1734 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1735 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1736 | return 0; |
| 1737 | } else |
| 1738 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1739 | } |
| 1740 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1741 | /** |
| 1742 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1743 | * @phba: Pointer to HBA context object. |
| 1744 | * @hbqno: HBQ number. |
| 1745 | * @hbq_buf: Pointer to HBQ buffer. |
| 1746 | * |
| 1747 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1748 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1749 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1750 | **/ |
| 1751 | static int |
| 1752 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1753 | struct hbq_dmabuf *hbq_buf) |
| 1754 | { |
| 1755 | int rc; |
| 1756 | struct lpfc_rqe hrqe; |
| 1757 | struct lpfc_rqe drqe; |
| 1758 | |
| 1759 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1760 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1761 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1762 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1763 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1764 | &hrqe, &drqe); |
| 1765 | if (rc < 0) |
| 1766 | return rc; |
| 1767 | hbq_buf->tag = rc; |
| 1768 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1772 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1773 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1774 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1775 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1776 | .mask_count = 0, |
| 1777 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1778 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1779 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1780 | .init_count = 40, |
| 1781 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1782 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1784 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1785 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1786 | .rn = 1, |
| 1787 | .entry_count = 200, |
| 1788 | .mask_count = 0, |
| 1789 | .profile = 0, |
| 1790 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1791 | .buffer_count = 0, |
| 1792 | .init_count = 0, |
| 1793 | .add_count = 5, |
| 1794 | }; |
| 1795 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1796 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1797 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1798 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1799 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1800 | }; |
| 1801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1803 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1804 | * @phba: Pointer to HBA context object. |
| 1805 | * @hbqno: HBQ number. |
| 1806 | * @count: Number of HBQ buffers to be posted. |
| 1807 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1808 | * This function is called with no lock held to post more hbq buffers to the |
| 1809 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1810 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1811 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1812 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1813 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1814 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1815 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1816 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1817 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1818 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1819 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1820 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1821 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1822 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1823 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1824 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1825 | phba->hbqs[hbqno].buffer_count; |
| 1826 | if (!count) |
| 1827 | return 0; |
| 1828 | /* Allocate HBQ entries */ |
| 1829 | for (i = 0; i < count; i++) { |
| 1830 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1831 | if (!hbq_buffer) |
| 1832 | break; |
| 1833 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1834 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1835 | /* Check whether HBQ is still in use */ |
| 1836 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1837 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1838 | goto err; |
| 1839 | while (!list_empty(&hbq_buf_list)) { |
| 1840 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1841 | dbuf.list); |
| 1842 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1843 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1844 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1845 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1846 | posted++; |
| 1847 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1848 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1849 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1850 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1851 | return posted; |
| 1852 | err: |
| 1853 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1854 | while (!list_empty(&hbq_buf_list)) { |
| 1855 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1856 | dbuf.list); |
| 1857 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1858 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1859 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1860 | } |
| 1861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1863 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1864 | * @phba: Pointer to HBA context object. |
| 1865 | * @qno: HBQ number. |
| 1866 | * |
| 1867 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1868 | * is called with no lock held. The function returns the number of HBQ entries |
| 1869 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1871 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1872 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1873 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1874 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1875 | return 0; |
| 1876 | else |
| 1877 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1878 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1879 | } |
| 1880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1882 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | * @phba: Pointer to HBA context object. |
| 1884 | * @qno: HBQ queue number. |
| 1885 | * |
| 1886 | * This function is called from SLI initialization code path with |
| 1887 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1888 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1889 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1890 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1891 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1892 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1893 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1894 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1895 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1896 | else |
| 1897 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1898 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1899 | } |
| 1900 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1901 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1902 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1903 | * @phba: Pointer to HBA context object. |
| 1904 | * @hbqno: HBQ number. |
| 1905 | * |
| 1906 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1907 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1908 | **/ |
| 1909 | static struct hbq_dmabuf * |
| 1910 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1911 | { |
| 1912 | struct lpfc_dmabuf *d_buf; |
| 1913 | |
| 1914 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1915 | if (!d_buf) |
| 1916 | return NULL; |
| 1917 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1918 | } |
| 1919 | |
| 1920 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1921 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1922 | * @phba: Pointer to HBA context object. |
| 1923 | * @tag: Tag of the hbq buffer. |
| 1924 | * |
| 1925 | * This function is called with hbalock held. This function searches |
| 1926 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1927 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1928 | * it returns NULL. |
| 1929 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1930 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1931 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1932 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1933 | struct lpfc_dmabuf *d_buf; |
| 1934 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1935 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1936 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1937 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1938 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1939 | return NULL; |
| 1940 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1941 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1942 | 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] | 1943 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1944 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1945 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1946 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1947 | } |
| 1948 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1949 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1951 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1952 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1954 | } |
| 1955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1957 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1958 | * @phba: Pointer to HBA context object. |
| 1959 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1960 | * |
| 1961 | * This function is called with hbalock. This function gives back |
| 1962 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1963 | * post the buffer, it will free the buffer. |
| 1964 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1965 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1966 | 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] | 1967 | { |
| 1968 | uint32_t hbqno; |
| 1969 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1970 | if (hbq_buffer) { |
| 1971 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1972 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1973 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1977 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1978 | * 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] | 1979 | * @mbxCommand: mailbox command code. |
| 1980 | * |
| 1981 | * This function is called by the mailbox event handler function to verify |
| 1982 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1983 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1984 | * and the mailbox event handler will take the HBA offline. |
| 1985 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | static int |
| 1987 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 1988 | { |
| 1989 | uint8_t ret; |
| 1990 | |
| 1991 | switch (mbxCommand) { |
| 1992 | case MBX_LOAD_SM: |
| 1993 | case MBX_READ_NV: |
| 1994 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1995 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | case MBX_RUN_BIU_DIAG: |
| 1997 | case MBX_INIT_LINK: |
| 1998 | case MBX_DOWN_LINK: |
| 1999 | case MBX_CONFIG_LINK: |
| 2000 | case MBX_CONFIG_RING: |
| 2001 | case MBX_RESET_RING: |
| 2002 | case MBX_READ_CONFIG: |
| 2003 | case MBX_READ_RCONFIG: |
| 2004 | case MBX_READ_SPARM: |
| 2005 | case MBX_READ_STATUS: |
| 2006 | case MBX_READ_RPI: |
| 2007 | case MBX_READ_XRI: |
| 2008 | case MBX_READ_REV: |
| 2009 | case MBX_READ_LNK_STAT: |
| 2010 | case MBX_REG_LOGIN: |
| 2011 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | case MBX_CLEAR_LA: |
| 2013 | case MBX_DUMP_MEMORY: |
| 2014 | case MBX_DUMP_CONTEXT: |
| 2015 | case MBX_RUN_DIAGS: |
| 2016 | case MBX_RESTART: |
| 2017 | case MBX_UPDATE_CFG: |
| 2018 | case MBX_DOWN_LOAD: |
| 2019 | case MBX_DEL_LD_ENTRY: |
| 2020 | case MBX_RUN_PROGRAM: |
| 2021 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2022 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2024 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2026 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | case MBX_LOAD_AREA: |
| 2028 | case MBX_RUN_BIU_DIAG64: |
| 2029 | case MBX_CONFIG_PORT: |
| 2030 | case MBX_READ_SPARM64: |
| 2031 | case MBX_READ_RPI64: |
| 2032 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2033 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2034 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | case MBX_SET_DEBUG: |
| 2036 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2037 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2038 | case MBX_REG_VPI: |
| 2039 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2040 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2041 | case MBX_PORT_CAPABILITIES: |
| 2042 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2043 | case MBX_SLI4_CONFIG: |
| 2044 | case MBX_SLI4_REQ_FTRS: |
| 2045 | case MBX_REG_FCFI: |
| 2046 | case MBX_UNREG_FCFI: |
| 2047 | case MBX_REG_VFI: |
| 2048 | case MBX_UNREG_VFI: |
| 2049 | case MBX_INIT_VPI: |
| 2050 | case MBX_INIT_VFI: |
| 2051 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2052 | case MBX_READ_EVENT_LOG_STATUS: |
| 2053 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2054 | case MBX_SECURITY_MGMT: |
| 2055 | case MBX_AUTH_PORT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | ret = mbxCommand; |
| 2057 | break; |
| 2058 | default: |
| 2059 | ret = MBX_SHUTDOWN; |
| 2060 | break; |
| 2061 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2062 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2064 | |
| 2065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2066 | * 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] | 2067 | * @phba: Pointer to HBA context object. |
| 2068 | * @pmboxq: Pointer to mailbox command. |
| 2069 | * |
| 2070 | * This is completion handler function for mailbox commands issued from |
| 2071 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2072 | * mailbox event handler function with no lock held. This function |
| 2073 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2074 | * of the mailbox. |
| 2075 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2076 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | { |
| 2079 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2080 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | |
| 2082 | /* |
| 2083 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2084 | * continued running. |
| 2085 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2086 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2087 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2089 | if (pdone_q) |
| 2090 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2091 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | return; |
| 2093 | } |
| 2094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2095 | |
| 2096 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2097 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2098 | * @phba: Pointer to HBA context object. |
| 2099 | * @pmb: Pointer to mailbox object. |
| 2100 | * |
| 2101 | * This function is the default mailbox completion handler. It |
| 2102 | * frees the memory resources associated with the completed mailbox |
| 2103 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2104 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2105 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2109 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2111 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2112 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2113 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2114 | int rc; |
| 2115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2117 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | if (mp) { |
| 2119 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2120 | kfree(mp); |
| 2121 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2122 | |
| 2123 | /* |
| 2124 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2125 | * is in re-discovery driver need to cleanup the RPI. |
| 2126 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2127 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2128 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2129 | !pmb->u.mb.mbxStatus) { |
| 2130 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2131 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2132 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2134 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2135 | if (rc != MBX_NOT_FINISHED) |
| 2136 | return; |
| 2137 | } |
| 2138 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2139 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2140 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2141 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2142 | shost = lpfc_shost_from_vport(vport); |
| 2143 | spin_lock_irq(shost->host_lock); |
| 2144 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2145 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2146 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2147 | } |
| 2148 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2149 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2150 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2151 | lpfc_nlp_put(ndlp); |
| 2152 | pmb->context2 = NULL; |
| 2153 | } |
| 2154 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2155 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2156 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2157 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2158 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2159 | "2860 SLI authentication is required " |
| 2160 | "for INIT_LINK but has not done yet\n"); |
| 2161 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2162 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2163 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2164 | else |
| 2165 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2168 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2169 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2170 | * @phba: Pointer to HBA context object. |
| 2171 | * |
| 2172 | * This function is called with no lock held. This function processes all |
| 2173 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2174 | * service routine processes mailbox completion interrupt and adds completed |
| 2175 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2176 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2177 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2178 | * function returns the mailbox commands to the upper layer by calling the |
| 2179 | * completion handler function of each mailbox. |
| 2180 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2184 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2185 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2186 | int rc; |
| 2187 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | |
| 2189 | phba->sli.slistat.mbox_event++; |
| 2190 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2191 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2192 | spin_lock_irq(&phba->hbalock); |
| 2193 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2194 | spin_unlock_irq(&phba->hbalock); |
| 2195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | do { |
| 2198 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2199 | if (pmb == NULL) |
| 2200 | break; |
| 2201 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2202 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2204 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2205 | if (pmb->vport) { |
| 2206 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2207 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2208 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2209 | (uint32_t)pmbox->mbxCommand, |
| 2210 | pmbox->un.varWords[0], |
| 2211 | pmbox->un.varWords[1]); |
| 2212 | } |
| 2213 | else { |
| 2214 | lpfc_debugfs_disc_trc(phba->pport, |
| 2215 | LPFC_DISC_TRC_MBOX, |
| 2216 | "MBOX cmpl: 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 | } |
| 2222 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | /* |
| 2224 | * It is a fatal error if unknown mbox command completion. |
| 2225 | */ |
| 2226 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2227 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2228 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2229 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2230 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2231 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2232 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2233 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2234 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2235 | pmb), |
| 2236 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2237 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | phba->work_hs = HS_FFER3; |
| 2240 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2241 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | } |
| 2243 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | if (pmbox->mbxStatus) { |
| 2245 | phba->sli.slistat.mbox_stat_err++; |
| 2246 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2247 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2248 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2249 | LOG_MBOX | LOG_SLI, |
| 2250 | "(%d):0305 Mbox cmd cmpl " |
| 2251 | "error - RETRYing Data: x%x " |
| 2252 | "(x%x/x%x) x%x x%x x%x\n", |
| 2253 | pmb->vport ? pmb->vport->vpi : 0, |
| 2254 | pmbox->mbxCommand, |
| 2255 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2256 | pmb), |
| 2257 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2258 | pmb), |
| 2259 | pmbox->mbxStatus, |
| 2260 | pmbox->un.varWords[0], |
| 2261 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | pmbox->mbxStatus = 0; |
| 2263 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2265 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2266 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2271 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2272 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | "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] | 2274 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2276 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2277 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | pmb->mbox_cmpl, |
| 2279 | *((uint32_t *) pmbox), |
| 2280 | pmbox->un.varWords[0], |
| 2281 | pmbox->un.varWords[1], |
| 2282 | pmbox->un.varWords[2], |
| 2283 | pmbox->un.varWords[3], |
| 2284 | pmbox->un.varWords[4], |
| 2285 | pmbox->un.varWords[5], |
| 2286 | pmbox->un.varWords[6], |
| 2287 | pmbox->un.varWords[7]); |
| 2288 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2291 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2292 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2296 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2297 | * @phba: Pointer to HBA context object. |
| 2298 | * @pring: Pointer to driver SLI ring object. |
| 2299 | * @tag: buffer tag. |
| 2300 | * |
| 2301 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2302 | * is set in the tag the buffer is posted for a particular exchange, |
| 2303 | * the function will return the buffer without replacing the buffer. |
| 2304 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2305 | * returns the buffer and also posts another buffer to the firmware. |
| 2306 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2307 | static struct lpfc_dmabuf * |
| 2308 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2309 | struct lpfc_sli_ring *pring, |
| 2310 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2311 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2312 | struct hbq_dmabuf *hbq_entry; |
| 2313 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2314 | if (tag & QUE_BUFTAG_BIT) |
| 2315 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2316 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2317 | if (!hbq_entry) |
| 2318 | return NULL; |
| 2319 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2320 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2321 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2322 | /** |
| 2323 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2324 | * @phba: Pointer to HBA context object. |
| 2325 | * @pring: Pointer to driver SLI ring object. |
| 2326 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2327 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2328 | * @fch_type: the type for the first frame of the sequence. |
| 2329 | * |
| 2330 | * This function is called with no lock held. This function uses the r_ctl and |
| 2331 | * type of the received sequence to find the correct callback function to call |
| 2332 | * to process the sequence. |
| 2333 | **/ |
| 2334 | static int |
| 2335 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2336 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2337 | uint32_t fch_type) |
| 2338 | { |
| 2339 | int i; |
| 2340 | |
| 2341 | /* unSolicited Responses */ |
| 2342 | if (pring->prt[0].profile) { |
| 2343 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2344 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2345 | saveq); |
| 2346 | return 1; |
| 2347 | } |
| 2348 | /* We must search, based on rctl / type |
| 2349 | for the right routine */ |
| 2350 | for (i = 0; i < pring->num_mask; i++) { |
| 2351 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2352 | (pring->prt[i].type == fch_type)) { |
| 2353 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2354 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2355 | (phba, pring, saveq); |
| 2356 | return 1; |
| 2357 | } |
| 2358 | } |
| 2359 | return 0; |
| 2360 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2361 | |
| 2362 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2363 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2364 | * @phba: Pointer to HBA context object. |
| 2365 | * @pring: Pointer to driver SLI ring object. |
| 2366 | * @saveq: Pointer to the unsolicited iocb. |
| 2367 | * |
| 2368 | * This function is called with no lock held by the ring event handler |
| 2369 | * when there is an unsolicited iocb posted to the response ring by the |
| 2370 | * firmware. This function gets the buffer associated with the iocbs |
| 2371 | * and calls the event handler for the ring. This function handles both |
| 2372 | * qring buffers and hbq buffers. |
| 2373 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2374 | * upper layer functions will free the iocb objects. |
| 2375 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | static int |
| 2377 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2378 | struct lpfc_iocbq *saveq) |
| 2379 | { |
| 2380 | IOCB_t * irsp; |
| 2381 | WORD5 * w5p; |
| 2382 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2383 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2384 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2385 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | |
| 2387 | match = 0; |
| 2388 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2389 | |
| 2390 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2391 | if (pring->lpfc_sli_rcv_async_status) |
| 2392 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2393 | else |
| 2394 | lpfc_printf_log(phba, |
| 2395 | KERN_WARNING, |
| 2396 | LOG_SLI, |
| 2397 | "0316 Ring %d handler: unexpected " |
| 2398 | "ASYNC_STATUS iocb received evt_code " |
| 2399 | "0x%x\n", |
| 2400 | pring->ringno, |
| 2401 | irsp->un.asyncstat.evt_code); |
| 2402 | return 1; |
| 2403 | } |
| 2404 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2405 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2406 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2407 | if (irsp->ulpBdeCount > 0) { |
| 2408 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2409 | irsp->un.ulpWord[3]); |
| 2410 | lpfc_in_buf_free(phba, dmzbuf); |
| 2411 | } |
| 2412 | |
| 2413 | if (irsp->ulpBdeCount > 1) { |
| 2414 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2415 | irsp->unsli3.sli3Words[3]); |
| 2416 | lpfc_in_buf_free(phba, dmzbuf); |
| 2417 | } |
| 2418 | |
| 2419 | if (irsp->ulpBdeCount > 2) { |
| 2420 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2421 | irsp->unsli3.sli3Words[7]); |
| 2422 | lpfc_in_buf_free(phba, dmzbuf); |
| 2423 | } |
| 2424 | |
| 2425 | return 1; |
| 2426 | } |
| 2427 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2428 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2429 | if (irsp->ulpBdeCount != 0) { |
| 2430 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2431 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2432 | if (!saveq->context2) |
| 2433 | lpfc_printf_log(phba, |
| 2434 | KERN_ERR, |
| 2435 | LOG_SLI, |
| 2436 | "0341 Ring %d Cannot find buffer for " |
| 2437 | "an unsolicited iocb. tag 0x%x\n", |
| 2438 | pring->ringno, |
| 2439 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2440 | } |
| 2441 | if (irsp->ulpBdeCount == 2) { |
| 2442 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2443 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2444 | if (!saveq->context3) |
| 2445 | lpfc_printf_log(phba, |
| 2446 | KERN_ERR, |
| 2447 | LOG_SLI, |
| 2448 | "0342 Ring %d Cannot find buffer for an" |
| 2449 | " unsolicited iocb. tag 0x%x\n", |
| 2450 | pring->ringno, |
| 2451 | irsp->unsli3.sli3Words[7]); |
| 2452 | } |
| 2453 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2454 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2455 | if (irsp->ulpBdeCount != 0) { |
| 2456 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2457 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2458 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2459 | lpfc_printf_log(phba, |
| 2460 | KERN_ERR, |
| 2461 | LOG_SLI, |
| 2462 | "0343 Ring %d Cannot find " |
| 2463 | "buffer for an unsolicited iocb" |
| 2464 | ". tag 0x%x\n", pring->ringno, |
| 2465 | irsp->un.ulpWord[3]); |
| 2466 | } |
| 2467 | if (irsp->ulpBdeCount == 2) { |
| 2468 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2469 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2470 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2471 | lpfc_printf_log(phba, |
| 2472 | KERN_ERR, |
| 2473 | LOG_SLI, |
| 2474 | "0344 Ring %d Cannot find " |
| 2475 | "buffer for an unsolicited " |
| 2476 | "iocb. tag 0x%x\n", |
| 2477 | pring->ringno, |
| 2478 | irsp->unsli3.sli3Words[7]); |
| 2479 | } |
| 2480 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2481 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2482 | if (irsp->ulpBdeCount != 0 && |
| 2483 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2484 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2485 | int found = 0; |
| 2486 | |
| 2487 | /* search continue save q for same XRI */ |
| 2488 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2489 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2490 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2491 | list_add_tail(&saveq->list, &iocbq->list); |
| 2492 | found = 1; |
| 2493 | break; |
| 2494 | } |
| 2495 | } |
| 2496 | if (!found) |
| 2497 | list_add_tail(&saveq->clist, |
| 2498 | &pring->iocb_continue_saveq); |
| 2499 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2500 | list_del_init(&iocbq->clist); |
| 2501 | saveq = iocbq; |
| 2502 | irsp = &(saveq->iocb); |
| 2503 | } else |
| 2504 | return 0; |
| 2505 | } |
| 2506 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2507 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2508 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2509 | Rctl = FC_RCTL_ELS_REQ; |
| 2510 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2511 | } else { |
| 2512 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2513 | Rctl = w5p->hcsw.Rctl; |
| 2514 | Type = w5p->hcsw.Type; |
| 2515 | |
| 2516 | /* Firmware Workaround */ |
| 2517 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2518 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2519 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2520 | Rctl = FC_RCTL_ELS_REQ; |
| 2521 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2522 | w5p->hcsw.Rctl = Rctl; |
| 2523 | w5p->hcsw.Type = Type; |
| 2524 | } |
| 2525 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2526 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2527 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2528 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2529 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2530 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2531 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2533 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | } |
| 2535 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2536 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2537 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2538 | * @phba: Pointer to HBA context object. |
| 2539 | * @pring: Pointer to driver SLI ring object. |
| 2540 | * @prspiocb: Pointer to response iocb object. |
| 2541 | * |
| 2542 | * This function looks up the iocb_lookup table to get the command iocb |
| 2543 | * corresponding to the given response iocb using the iotag of the |
| 2544 | * response iocb. This function is called with the hbalock held. |
| 2545 | * This function returns the command iocb object if it finds the command |
| 2546 | * iocb else returns NULL. |
| 2547 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2549 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2550 | struct lpfc_sli_ring *pring, |
| 2551 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2554 | uint16_t iotag; |
| 2555 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2556 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2557 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2558 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2559 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2560 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2561 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2562 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2563 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2564 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2565 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | } |
| 2567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2568 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2569 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2570 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2571 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2572 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2573 | return NULL; |
| 2574 | } |
| 2575 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2576 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2577 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2578 | * @phba: Pointer to HBA context object. |
| 2579 | * @pring: Pointer to driver SLI ring object. |
| 2580 | * @iotag: IOCB tag. |
| 2581 | * |
| 2582 | * This function looks up the iocb_lookup table to get the command iocb |
| 2583 | * corresponding to the given iotag. This function is called with the |
| 2584 | * hbalock held. |
| 2585 | * This function returns the command iocb object if it finds the command |
| 2586 | * iocb else returns NULL. |
| 2587 | **/ |
| 2588 | static struct lpfc_iocbq * |
| 2589 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2590 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2591 | { |
| 2592 | struct lpfc_iocbq *cmd_iocb; |
| 2593 | |
| 2594 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2595 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2596 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2597 | /* remove from txcmpl queue list */ |
| 2598 | list_del_init(&cmd_iocb->list); |
| 2599 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2600 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2601 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2602 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2603 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2604 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2605 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2606 | iotag, phba->sli.last_iotag); |
| 2607 | return NULL; |
| 2608 | } |
| 2609 | |
| 2610 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2611 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2612 | * @phba: Pointer to HBA context object. |
| 2613 | * @pring: Pointer to driver SLI ring object. |
| 2614 | * @saveq: Pointer to the response iocb to be processed. |
| 2615 | * |
| 2616 | * This function is called by the ring event handler for non-fcp |
| 2617 | * rings when there is a new response iocb in the response ring. |
| 2618 | * The caller is not required to hold any locks. This function |
| 2619 | * gets the command iocb associated with the response iocb and |
| 2620 | * calls the completion handler for the command iocb. If there |
| 2621 | * is no completion handler, the function will free the resources |
| 2622 | * associated with command iocb. If the response iocb is for |
| 2623 | * an already aborted command iocb, the status of the completion |
| 2624 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2625 | * This function always returns 1. |
| 2626 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | struct lpfc_iocbq *saveq) |
| 2630 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | int rc = 1; |
| 2633 | unsigned long iflag; |
| 2634 | |
| 2635 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2637 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | if (cmdiocbp) { |
| 2641 | if (cmdiocbp->iocb_cmpl) { |
| 2642 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2643 | * If an ELS command failed send an event to mgmt |
| 2644 | * application. |
| 2645 | */ |
| 2646 | if (saveq->iocb.ulpStatus && |
| 2647 | (pring->ringno == LPFC_ELS_RING) && |
| 2648 | (cmdiocbp->iocb.ulpCommand == |
| 2649 | CMD_ELS_REQUEST64_CR)) |
| 2650 | lpfc_send_els_failure_event(phba, |
| 2651 | cmdiocbp, saveq); |
| 2652 | |
| 2653 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | * Post all ELS completions to the worker thread. |
| 2655 | * All other are passed to the completion callback. |
| 2656 | */ |
| 2657 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2658 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2659 | (cmdiocbp->iocb_flag & |
| 2660 | LPFC_DRIVER_ABORTED)) { |
| 2661 | spin_lock_irqsave(&phba->hbalock, |
| 2662 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2663 | cmdiocbp->iocb_flag &= |
| 2664 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2665 | spin_unlock_irqrestore(&phba->hbalock, |
| 2666 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2667 | saveq->iocb.ulpStatus = |
| 2668 | IOSTAT_LOCAL_REJECT; |
| 2669 | saveq->iocb.un.ulpWord[4] = |
| 2670 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2671 | |
| 2672 | /* Firmware could still be in progress |
| 2673 | * of DMAing payload, so don't free data |
| 2674 | * buffer till after a hbeat. |
| 2675 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2676 | spin_lock_irqsave(&phba->hbalock, |
| 2677 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2678 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2679 | spin_unlock_irqrestore(&phba->hbalock, |
| 2680 | iflag); |
| 2681 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2682 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2683 | if (saveq->iocb_flag & |
| 2684 | LPFC_EXCHANGE_BUSY) { |
| 2685 | /* Set cmdiocb flag for the |
| 2686 | * exchange busy so sgl (xri) |
| 2687 | * will not be released until |
| 2688 | * the abort xri is received |
| 2689 | * from hba. |
| 2690 | */ |
| 2691 | spin_lock_irqsave( |
| 2692 | &phba->hbalock, iflag); |
| 2693 | cmdiocbp->iocb_flag |= |
| 2694 | LPFC_EXCHANGE_BUSY; |
| 2695 | spin_unlock_irqrestore( |
| 2696 | &phba->hbalock, iflag); |
| 2697 | } |
| 2698 | if (cmdiocbp->iocb_flag & |
| 2699 | LPFC_DRIVER_ABORTED) { |
| 2700 | /* |
| 2701 | * Clear LPFC_DRIVER_ABORTED |
| 2702 | * bit in case it was driver |
| 2703 | * initiated abort. |
| 2704 | */ |
| 2705 | spin_lock_irqsave( |
| 2706 | &phba->hbalock, iflag); |
| 2707 | cmdiocbp->iocb_flag &= |
| 2708 | ~LPFC_DRIVER_ABORTED; |
| 2709 | spin_unlock_irqrestore( |
| 2710 | &phba->hbalock, iflag); |
| 2711 | cmdiocbp->iocb.ulpStatus = |
| 2712 | IOSTAT_LOCAL_REJECT; |
| 2713 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2714 | IOERR_ABORT_REQUESTED; |
| 2715 | /* |
| 2716 | * For SLI4, irsiocb contains |
| 2717 | * NO_XRI in sli_xritag, it |
| 2718 | * shall not affect releasing |
| 2719 | * sgl (xri) process. |
| 2720 | */ |
| 2721 | saveq->iocb.ulpStatus = |
| 2722 | IOSTAT_LOCAL_REJECT; |
| 2723 | saveq->iocb.un.ulpWord[4] = |
| 2724 | IOERR_SLI_ABORTED; |
| 2725 | spin_lock_irqsave( |
| 2726 | &phba->hbalock, iflag); |
| 2727 | saveq->iocb_flag |= |
| 2728 | LPFC_DELAY_MEM_FREE; |
| 2729 | spin_unlock_irqrestore( |
| 2730 | &phba->hbalock, iflag); |
| 2731 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2732 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2734 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2735 | } else |
| 2736 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | } else { |
| 2738 | /* |
| 2739 | * Unknown initiating command based on the response iotag. |
| 2740 | * This could be the case on the ELS ring because of |
| 2741 | * lpfc_els_abort(). |
| 2742 | */ |
| 2743 | if (pring->ringno != LPFC_ELS_RING) { |
| 2744 | /* |
| 2745 | * Ring <ringno> handler: unexpected completion IoTag |
| 2746 | * <IoTag> |
| 2747 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2748 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2749 | "0322 Ring %d handler: " |
| 2750 | "unexpected completion IoTag x%x " |
| 2751 | "Data: x%x x%x x%x x%x\n", |
| 2752 | pring->ringno, |
| 2753 | saveq->iocb.ulpIoTag, |
| 2754 | saveq->iocb.ulpStatus, |
| 2755 | saveq->iocb.un.ulpWord[4], |
| 2756 | saveq->iocb.ulpCommand, |
| 2757 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | } |
| 2759 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2760 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | return rc; |
| 2762 | } |
| 2763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2765 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2766 | * @phba: Pointer to HBA context object. |
| 2767 | * @pring: Pointer to driver SLI ring object. |
| 2768 | * |
| 2769 | * This function is called from the iocb ring event handlers when |
| 2770 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2771 | * an error attention condition to the worker thread and the worker |
| 2772 | * thread will transition the HBA to offline state. |
| 2773 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2774 | static void |
| 2775 | 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] | 2776 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2777 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2778 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2779 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2780 | * rsp ring <portRspMax> |
| 2781 | */ |
| 2782 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2783 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2784 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2785 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2786 | pring->numRiocb); |
| 2787 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2788 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2789 | |
| 2790 | /* |
| 2791 | * All error attention handlers are posted to |
| 2792 | * worker thread |
| 2793 | */ |
| 2794 | phba->work_ha |= HA_ERATT; |
| 2795 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2796 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2797 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2798 | |
| 2799 | return; |
| 2800 | } |
| 2801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2803 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2804 | * @ptr: Pointer to address of HBA context object. |
| 2805 | * |
| 2806 | * This function is invoked by the Error Attention polling timer when the |
| 2807 | * timer times out. It will check the SLI Error Attention register for |
| 2808 | * possible attention events. If so, it will post an Error Attention event |
| 2809 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2810 | * Error Attention polling timer for the next poll. |
| 2811 | **/ |
| 2812 | void lpfc_poll_eratt(unsigned long ptr) |
| 2813 | { |
| 2814 | struct lpfc_hba *phba; |
| 2815 | uint32_t eratt = 0; |
| 2816 | |
| 2817 | phba = (struct lpfc_hba *)ptr; |
| 2818 | |
| 2819 | /* Check chip HA register for error event */ |
| 2820 | eratt = lpfc_sli_check_eratt(phba); |
| 2821 | |
| 2822 | if (eratt) |
| 2823 | /* Tell the worker thread there is work to do */ |
| 2824 | lpfc_worker_wake_up(phba); |
| 2825 | else |
| 2826 | /* Restart the timer for next eratt poll */ |
| 2827 | mod_timer(&phba->eratt_poll, jiffies + |
| 2828 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2829 | return; |
| 2830 | } |
| 2831 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2832 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2833 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2834 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2835 | * @phba: Pointer to HBA context object. |
| 2836 | * @pring: Pointer to driver SLI ring object. |
| 2837 | * @mask: Host attention register mask for this ring. |
| 2838 | * |
| 2839 | * This function is called from the interrupt context when there is a ring |
| 2840 | * event for the fcp ring. The caller does not hold any lock. |
| 2841 | * 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] | 2842 | * 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] | 2843 | * LE bit set. The function will call the completion handler of the command iocb |
| 2844 | * if the response iocb indicates a completion for a command iocb or it is |
| 2845 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2846 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2847 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2848 | * to check it explicitly. |
| 2849 | */ |
| 2850 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2851 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2852 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2853 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2854 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2856 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2858 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | uint32_t status; |
| 2860 | uint32_t portRspPut, portRspMax; |
| 2861 | int rc = 1; |
| 2862 | lpfc_iocb_type type; |
| 2863 | unsigned long iflag; |
| 2864 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | pring->stats.iocb_event++; |
| 2868 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | /* |
| 2870 | * The next available response entry should never exceed the maximum |
| 2871 | * entries. If it does, treat it as an adapter hardware error. |
| 2872 | */ |
| 2873 | portRspMax = pring->numRiocb; |
| 2874 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2875 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2876 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | return 1; |
| 2879 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2880 | if (phba->fcp_ring_in_use) { |
| 2881 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2882 | return 1; |
| 2883 | } else |
| 2884 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | |
| 2886 | rmb(); |
| 2887 | while (pring->rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2888 | /* |
| 2889 | * Fetch an entry off the ring and copy it into a local data |
| 2890 | * structure. The copy involves a byte-swap since the |
| 2891 | * network byte order and pci byte orders are different. |
| 2892 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2893 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2894 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2895 | |
| 2896 | if (++pring->rspidx >= portRspMax) |
| 2897 | pring->rspidx = 0; |
| 2898 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2899 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2900 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2901 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2902 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2903 | irsp = &rspiocbq.iocb; |
| 2904 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2905 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2906 | pring->stats.iocb_rsp++; |
| 2907 | rsp_cmpl++; |
| 2908 | |
| 2909 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2910 | /* |
| 2911 | * If resource errors reported from HBA, reduce |
| 2912 | * queuedepths of the SCSI device. |
| 2913 | */ |
| 2914 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2915 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2916 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2917 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2918 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2919 | } |
| 2920 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | /* Rsp ring <ringno> error: IOCB */ |
| 2922 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2923 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | "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] | 2925 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | irsp->un.ulpWord[0], |
| 2927 | irsp->un.ulpWord[1], |
| 2928 | irsp->un.ulpWord[2], |
| 2929 | irsp->un.ulpWord[3], |
| 2930 | irsp->un.ulpWord[4], |
| 2931 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2932 | *(uint32_t *)&irsp->un1, |
| 2933 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | switch (type) { |
| 2937 | case LPFC_ABORT_IOCB: |
| 2938 | case LPFC_SOL_IOCB: |
| 2939 | /* |
| 2940 | * Idle exchange closed via ABTS from port. No iocb |
| 2941 | * resources need to be recovered. |
| 2942 | */ |
| 2943 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2944 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2945 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2946 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2947 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2948 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | break; |
| 2950 | } |
| 2951 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2952 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2953 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2954 | if (unlikely(!cmdiocbq)) |
| 2955 | break; |
| 2956 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 2957 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 2958 | if (cmdiocbq->iocb_cmpl) { |
| 2959 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2960 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2961 | &rspiocbq); |
| 2962 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2963 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2965 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2966 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2967 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2968 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2969 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | default: |
| 2971 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2972 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2973 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2974 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2975 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2976 | dev_warn(&((phba->pcidev)->dev), |
| 2977 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | phba->brd_no, adaptermsg); |
| 2979 | } else { |
| 2980 | /* Unknown IOCB command */ |
| 2981 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2982 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2984 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2985 | irsp->ulpStatus, |
| 2986 | irsp->ulpIoTag, |
| 2987 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | } |
| 2989 | break; |
| 2990 | } |
| 2991 | |
| 2992 | /* |
| 2993 | * The response IOCB has been processed. Update the ring |
| 2994 | * pointer in SLIM. If the port response put pointer has not |
| 2995 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 2996 | * response put pointer. |
| 2997 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2998 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | |
| 3000 | if (pring->rspidx == portRspPut) |
| 3001 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3002 | } |
| 3003 | |
| 3004 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3005 | pring->stats.iocb_rsp_full++; |
| 3006 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3007 | writel(status, phba->CAregaddr); |
| 3008 | readl(phba->CAregaddr); |
| 3009 | } |
| 3010 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3011 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3012 | pring->stats.iocb_cmd_empty++; |
| 3013 | |
| 3014 | /* Force update of the local copy of cmdGetInx */ |
| 3015 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 3016 | lpfc_sli_resume_iocb(phba, pring); |
| 3017 | |
| 3018 | if ((pring->lpfc_sli_cmd_available)) |
| 3019 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3020 | |
| 3021 | } |
| 3022 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3023 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3024 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | return rc; |
| 3026 | } |
| 3027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3028 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3029 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3030 | * @phba: Pointer to HBA context object. |
| 3031 | * @pring: Pointer to driver SLI ring object. |
| 3032 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3033 | * |
| 3034 | * This function is called from the worker thread when there is a slow-path |
| 3035 | * response IOCB to process. This function chains all the response iocbs until |
| 3036 | * seeing the iocb with the LE bit set. The function will call |
| 3037 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3038 | * completion of a command iocb. The function will call the |
| 3039 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3040 | * The function frees the resources or calls the completion handler if this |
| 3041 | * iocb is an abort completion. The function returns NULL when the response |
| 3042 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3043 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3044 | * response iocb passed in. |
| 3045 | **/ |
| 3046 | static struct lpfc_iocbq * |
| 3047 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3048 | struct lpfc_iocbq *rspiocbp) |
| 3049 | { |
| 3050 | struct lpfc_iocbq *saveq; |
| 3051 | struct lpfc_iocbq *cmdiocbp; |
| 3052 | struct lpfc_iocbq *next_iocb; |
| 3053 | IOCB_t *irsp = NULL; |
| 3054 | uint32_t free_saveq; |
| 3055 | uint8_t iocb_cmd_type; |
| 3056 | lpfc_iocb_type type; |
| 3057 | unsigned long iflag; |
| 3058 | int rc; |
| 3059 | |
| 3060 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3061 | /* First add the response iocb to the countinueq list */ |
| 3062 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3063 | pring->iocb_continueq_cnt++; |
| 3064 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3065 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3066 | irsp = &rspiocbp->iocb; |
| 3067 | if (irsp->ulpLe) { |
| 3068 | /* |
| 3069 | * By default, the driver expects to free all resources |
| 3070 | * associated with this iocb completion. |
| 3071 | */ |
| 3072 | free_saveq = 1; |
| 3073 | saveq = list_get_first(&pring->iocb_continueq, |
| 3074 | struct lpfc_iocbq, list); |
| 3075 | irsp = &(saveq->iocb); |
| 3076 | list_del_init(&pring->iocb_continueq); |
| 3077 | pring->iocb_continueq_cnt = 0; |
| 3078 | |
| 3079 | pring->stats.iocb_rsp++; |
| 3080 | |
| 3081 | /* |
| 3082 | * If resource errors reported from HBA, reduce |
| 3083 | * queuedepths of the SCSI device. |
| 3084 | */ |
| 3085 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 3086 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 3087 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3088 | phba->lpfc_rampdown_queue_depth(phba); |
| 3089 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3090 | } |
| 3091 | |
| 3092 | if (irsp->ulpStatus) { |
| 3093 | /* Rsp ring <ringno> error: IOCB */ |
| 3094 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3095 | "0328 Rsp Ring %d error: " |
| 3096 | "IOCB Data: " |
| 3097 | "x%x x%x x%x x%x " |
| 3098 | "x%x x%x x%x x%x " |
| 3099 | "x%x x%x x%x x%x " |
| 3100 | "x%x x%x x%x x%x\n", |
| 3101 | pring->ringno, |
| 3102 | irsp->un.ulpWord[0], |
| 3103 | irsp->un.ulpWord[1], |
| 3104 | irsp->un.ulpWord[2], |
| 3105 | irsp->un.ulpWord[3], |
| 3106 | irsp->un.ulpWord[4], |
| 3107 | irsp->un.ulpWord[5], |
| 3108 | *(((uint32_t *) irsp) + 6), |
| 3109 | *(((uint32_t *) irsp) + 7), |
| 3110 | *(((uint32_t *) irsp) + 8), |
| 3111 | *(((uint32_t *) irsp) + 9), |
| 3112 | *(((uint32_t *) irsp) + 10), |
| 3113 | *(((uint32_t *) irsp) + 11), |
| 3114 | *(((uint32_t *) irsp) + 12), |
| 3115 | *(((uint32_t *) irsp) + 13), |
| 3116 | *(((uint32_t *) irsp) + 14), |
| 3117 | *(((uint32_t *) irsp) + 15)); |
| 3118 | } |
| 3119 | |
| 3120 | /* |
| 3121 | * Fetch the IOCB command type and call the correct completion |
| 3122 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3123 | * get freed back to the lpfc_iocb_list by the discovery |
| 3124 | * kernel thread. |
| 3125 | */ |
| 3126 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3127 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3128 | switch (type) { |
| 3129 | case LPFC_SOL_IOCB: |
| 3130 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3131 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3132 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3133 | break; |
| 3134 | |
| 3135 | case LPFC_UNSOL_IOCB: |
| 3136 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3137 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3138 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3139 | if (!rc) |
| 3140 | free_saveq = 0; |
| 3141 | break; |
| 3142 | |
| 3143 | case LPFC_ABORT_IOCB: |
| 3144 | cmdiocbp = NULL; |
| 3145 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3146 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3147 | saveq); |
| 3148 | if (cmdiocbp) { |
| 3149 | /* Call the specified completion routine */ |
| 3150 | if (cmdiocbp->iocb_cmpl) { |
| 3151 | spin_unlock_irqrestore(&phba->hbalock, |
| 3152 | iflag); |
| 3153 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3154 | saveq); |
| 3155 | spin_lock_irqsave(&phba->hbalock, |
| 3156 | iflag); |
| 3157 | } else |
| 3158 | __lpfc_sli_release_iocbq(phba, |
| 3159 | cmdiocbp); |
| 3160 | } |
| 3161 | break; |
| 3162 | |
| 3163 | case LPFC_UNKNOWN_IOCB: |
| 3164 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3165 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3166 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3167 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3168 | MAX_MSG_DATA); |
| 3169 | dev_warn(&((phba->pcidev)->dev), |
| 3170 | "lpfc%d: %s\n", |
| 3171 | phba->brd_no, adaptermsg); |
| 3172 | } else { |
| 3173 | /* Unknown IOCB command */ |
| 3174 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3175 | "0335 Unknown IOCB " |
| 3176 | "command Data: x%x " |
| 3177 | "x%x x%x x%x\n", |
| 3178 | irsp->ulpCommand, |
| 3179 | irsp->ulpStatus, |
| 3180 | irsp->ulpIoTag, |
| 3181 | irsp->ulpContext); |
| 3182 | } |
| 3183 | break; |
| 3184 | } |
| 3185 | |
| 3186 | if (free_saveq) { |
| 3187 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3188 | &saveq->list, list) { |
| 3189 | list_del(&rspiocbp->list); |
| 3190 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3191 | } |
| 3192 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3193 | } |
| 3194 | rspiocbp = NULL; |
| 3195 | } |
| 3196 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3197 | return rspiocbp; |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * 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] | 3202 | * @phba: Pointer to HBA context object. |
| 3203 | * @pring: Pointer to driver SLI ring object. |
| 3204 | * @mask: Host attention register mask for this ring. |
| 3205 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3206 | * This routine wraps the actual slow_ring event process routine from the |
| 3207 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3208 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3209 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3211 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3213 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3214 | } |
| 3215 | |
| 3216 | /** |
| 3217 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3218 | * @phba: Pointer to HBA context object. |
| 3219 | * @pring: Pointer to driver SLI ring object. |
| 3220 | * @mask: Host attention register mask for this ring. |
| 3221 | * |
| 3222 | * This function is called from the worker thread when there is a ring event |
| 3223 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3224 | * remove each response iocb in the response ring and calls the handle |
| 3225 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3226 | **/ |
| 3227 | static void |
| 3228 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3229 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3230 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3231 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3232 | IOCB_t *entry; |
| 3233 | IOCB_t *irsp = NULL; |
| 3234 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3237 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3238 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3239 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | pring->stats.iocb_event++; |
| 3242 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | /* |
| 3244 | * The next available response entry should never exceed the maximum |
| 3245 | * entries. If it does, treat it as an adapter hardware error. |
| 3246 | */ |
| 3247 | portRspMax = pring->numRiocb; |
| 3248 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3249 | if (portRspPut >= portRspMax) { |
| 3250 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3251 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | * rsp ring <portRspMax> |
| 3253 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3254 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3255 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3256 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3257 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | phba->link_state = LPFC_HBA_ERROR; |
| 3260 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | |
| 3262 | phba->work_hs = HS_FFER3; |
| 3263 | lpfc_handle_eratt(phba); |
| 3264 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3265 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | rmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3269 | while (pring->rspidx != portRspPut) { |
| 3270 | /* |
| 3271 | * Build a completion list and call the appropriate handler. |
| 3272 | * The process is to get the next available response iocb, get |
| 3273 | * a free iocb from the list, copy the response data into the |
| 3274 | * free iocb, insert to the continuation list, and update the |
| 3275 | * next response index to slim. This process makes response |
| 3276 | * iocb's in the ring available to DMA as fast as possible but |
| 3277 | * pays a penalty for a copy operation. Since the iocb is |
| 3278 | * only 32 bytes, this penalty is considered small relative to |
| 3279 | * the PCI reads for register values and a slim write. When |
| 3280 | * the ulpLe field is set, the entire Command has been |
| 3281 | * received. |
| 3282 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3283 | entry = lpfc_resp_iocb(phba, pring); |
| 3284 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3285 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3286 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3287 | if (rspiocbp == NULL) { |
| 3288 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3289 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | break; |
| 3291 | } |
| 3292 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3293 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3294 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | irsp = &rspiocbp->iocb; |
| 3296 | |
| 3297 | if (++pring->rspidx >= portRspMax) |
| 3298 | pring->rspidx = 0; |
| 3299 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3300 | if (pring->ringno == LPFC_ELS_RING) { |
| 3301 | lpfc_debugfs_slow_ring_trc(phba, |
| 3302 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3303 | *(((uint32_t *) irsp) + 4), |
| 3304 | *(((uint32_t *) irsp) + 6), |
| 3305 | *(((uint32_t *) irsp) + 7)); |
| 3306 | } |
| 3307 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3308 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3310 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3311 | /* Handle the response IOCB */ |
| 3312 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3313 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | |
| 3315 | /* |
| 3316 | * If the port response put pointer has not been updated, sync |
| 3317 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3318 | * response put pointer. |
| 3319 | */ |
| 3320 | if (pring->rspidx == portRspPut) { |
| 3321 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3322 | } |
| 3323 | } /* while (pring->rspidx != portRspPut) */ |
| 3324 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3325 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3326 | /* At least one response entry has been freed */ |
| 3327 | pring->stats.iocb_rsp_full++; |
| 3328 | /* SET RxRE_RSP in Chip Att register */ |
| 3329 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3330 | writel(status, phba->CAregaddr); |
| 3331 | readl(phba->CAregaddr); /* flush */ |
| 3332 | } |
| 3333 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3334 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3335 | pring->stats.iocb_cmd_empty++; |
| 3336 | |
| 3337 | /* Force update of the local copy of cmdGetInx */ |
| 3338 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| 3339 | lpfc_sli_resume_iocb(phba, pring); |
| 3340 | |
| 3341 | if ((pring->lpfc_sli_cmd_available)) |
| 3342 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3343 | |
| 3344 | } |
| 3345 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3346 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3347 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | } |
| 3349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3350 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3351 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3352 | * @phba: Pointer to HBA context object. |
| 3353 | * @pring: Pointer to driver SLI ring object. |
| 3354 | * @mask: Host attention register mask for this ring. |
| 3355 | * |
| 3356 | * This function is called from the worker thread when there is a pending |
| 3357 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3358 | * queue. The caller does not hold any lock. The function will remove each |
| 3359 | * response iocb from the response worker queue and calls the handle |
| 3360 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3361 | **/ |
| 3362 | static void |
| 3363 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3364 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3365 | { |
| 3366 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3367 | struct hbq_dmabuf *dmabuf; |
| 3368 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3369 | unsigned long iflag; |
| 3370 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3371 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3372 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3373 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3374 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3375 | /* Get the response iocb from the head of work queue */ |
| 3376 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3377 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3378 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3379 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3380 | |
| 3381 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3382 | case CQE_CODE_COMPL_WQE: |
| 3383 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3384 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3385 | /* Translate ELS WCQE to response IOCBQ */ |
| 3386 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3387 | irspiocbq); |
| 3388 | if (irspiocbq) |
| 3389 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3390 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3391 | break; |
| 3392 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3393 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3394 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3395 | cq_event); |
| 3396 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3397 | break; |
| 3398 | default: |
| 3399 | break; |
| 3400 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3405 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3406 | * @phba: Pointer to HBA context object. |
| 3407 | * @pring: Pointer to driver SLI ring object. |
| 3408 | * |
| 3409 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3410 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3411 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3412 | * the return of this function. The caller is not required to hold any locks. |
| 3413 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3414 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3416 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3417 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3419 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3420 | if (pring->ringno == LPFC_ELS_RING) { |
| 3421 | lpfc_fabric_abort_hba(phba); |
| 3422 | } |
| 3423 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | /* Error everything on txq and txcmplq |
| 3425 | * First do the txq. |
| 3426 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3427 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3428 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | |
| 3431 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3432 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3433 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3434 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3435 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3436 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3437 | /* Cancel all the IOCBs from the completions list */ |
| 3438 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3439 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | } |
| 3441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3443 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3444 | * @phba: Pointer to HBA context object. |
| 3445 | * |
| 3446 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3447 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3448 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3449 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3450 | * slot has been permanently disabled. |
| 3451 | **/ |
| 3452 | void |
| 3453 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3454 | { |
| 3455 | LIST_HEAD(txq); |
| 3456 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3457 | struct lpfc_sli *psli = &phba->sli; |
| 3458 | struct lpfc_sli_ring *pring; |
| 3459 | |
| 3460 | /* Currently, only one fcp ring */ |
| 3461 | pring = &psli->ring[psli->fcp_ring]; |
| 3462 | |
| 3463 | spin_lock_irq(&phba->hbalock); |
| 3464 | /* Retrieve everything on txq */ |
| 3465 | list_splice_init(&pring->txq, &txq); |
| 3466 | pring->txq_cnt = 0; |
| 3467 | |
| 3468 | /* Retrieve everything on the txcmplq */ |
| 3469 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3470 | pring->txcmplq_cnt = 0; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3471 | |
| 3472 | /* Indicate the I/O queues are flushed */ |
| 3473 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3474 | spin_unlock_irq(&phba->hbalock); |
| 3475 | |
| 3476 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3477 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3478 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3479 | |
| 3480 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3481 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3482 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3486 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3487 | * @phba: Pointer to HBA context object. |
| 3488 | * @mask: Bit mask to be checked. |
| 3489 | * |
| 3490 | * This function reads the host status register and compares |
| 3491 | * with the provided bit mask to check if HBA completed |
| 3492 | * the restart. This function will wait in a loop for the |
| 3493 | * HBA to complete restart. If the HBA does not restart within |
| 3494 | * 15 iterations, the function will reset the HBA again. The |
| 3495 | * function returns 1 when HBA fail to restart otherwise returns |
| 3496 | * zero. |
| 3497 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3498 | static int |
| 3499 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3501 | uint32_t status; |
| 3502 | int i = 0; |
| 3503 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3505 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3506 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3507 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3509 | /* |
| 3510 | * Check status register every 100ms for 5 retries, then every |
| 3511 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3512 | * every 2.5 sec for 4. |
| 3513 | * Break our of the loop if errors occurred during init. |
| 3514 | */ |
| 3515 | while (((status & mask) != mask) && |
| 3516 | !(status & HS_FFERM) && |
| 3517 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3519 | if (i <= 5) |
| 3520 | msleep(10); |
| 3521 | else if (i <= 10) |
| 3522 | msleep(500); |
| 3523 | else |
| 3524 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3525 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3526 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3527 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3529 | lpfc_sli_brdrestart(phba); |
| 3530 | } |
| 3531 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3532 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3533 | retval = 1; |
| 3534 | break; |
| 3535 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3536 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3538 | /* Check to see if any errors occurred during init */ |
| 3539 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3540 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3541 | "2751 Adapter failed to restart, " |
| 3542 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3543 | status, |
| 3544 | readl(phba->MBslimaddr + 0xa8), |
| 3545 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3546 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3547 | retval = 1; |
| 3548 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3550 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | } |
| 3552 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3553 | /** |
| 3554 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3555 | * @phba: Pointer to HBA context object. |
| 3556 | * @mask: Bit mask to be checked. |
| 3557 | * |
| 3558 | * This function checks the host status register to check if HBA is |
| 3559 | * ready. This function will wait in a loop for the HBA to be ready |
| 3560 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3561 | * function again. The function returns 1 when HBA fail to be ready |
| 3562 | * otherwise returns zero. |
| 3563 | **/ |
| 3564 | static int |
| 3565 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3566 | { |
| 3567 | uint32_t status; |
| 3568 | int retval = 0; |
| 3569 | |
| 3570 | /* Read the HBA Host Status Register */ |
| 3571 | status = lpfc_sli4_post_status_check(phba); |
| 3572 | |
| 3573 | if (status) { |
| 3574 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3575 | lpfc_sli_brdrestart(phba); |
| 3576 | status = lpfc_sli4_post_status_check(phba); |
| 3577 | } |
| 3578 | |
| 3579 | /* Check to see if any errors occurred during init */ |
| 3580 | if (status) { |
| 3581 | phba->link_state = LPFC_HBA_ERROR; |
| 3582 | retval = 1; |
| 3583 | } else |
| 3584 | phba->sli4_hba.intr_enable = 0; |
| 3585 | |
| 3586 | return retval; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3591 | * @phba: Pointer to HBA context object. |
| 3592 | * @mask: Bit mask to be checked. |
| 3593 | * |
| 3594 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3595 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3596 | **/ |
| 3597 | int |
| 3598 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3599 | { |
| 3600 | return phba->lpfc_sli_brdready(phba, mask); |
| 3601 | } |
| 3602 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3603 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3605 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3606 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3607 | * @phba: Pointer to HBA context object. |
| 3608 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3609 | * This function is called before resetting an HBA. This function is called |
| 3610 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3611 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3612 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3613 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3614 | uint32_t __iomem *resp_buf; |
| 3615 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3616 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3617 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3618 | int i; |
| 3619 | uint8_t hdrtype; |
| 3620 | |
| 3621 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3622 | if (hdrtype != 0x80 || |
| 3623 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3624 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3625 | return; |
| 3626 | |
| 3627 | /* |
| 3628 | * Tell the other part of the chip to suspend temporarily all |
| 3629 | * its DMA activity. |
| 3630 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3631 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3632 | |
| 3633 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3634 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3635 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3636 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3637 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3638 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3639 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3640 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3641 | return; |
| 3642 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3643 | /* Clear Chip error bit */ |
| 3644 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3645 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | mbox = 0; |
| 3649 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3650 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3651 | |
| 3652 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3653 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3654 | writel(mbox, mbox_buf); |
| 3655 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3656 | for (i = 0; i < 50; i++) { |
| 3657 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3658 | return; |
| 3659 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3660 | mdelay(1); |
| 3661 | else |
| 3662 | break; |
| 3663 | } |
| 3664 | resp_data = 0; |
| 3665 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3666 | return; |
| 3667 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3668 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3669 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3670 | goto restore_hc; |
| 3671 | else |
| 3672 | goto clear_errat; |
| 3673 | } |
| 3674 | |
| 3675 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3676 | resp_data = 0; |
| 3677 | for (i = 0; i < 500; i++) { |
| 3678 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3679 | return; |
| 3680 | if (resp_data != mbox) |
| 3681 | mdelay(1); |
| 3682 | else |
| 3683 | break; |
| 3684 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3685 | |
| 3686 | clear_errat: |
| 3687 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3688 | while (++i < 500) { |
| 3689 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3690 | return; |
| 3691 | if (!(ha_copy & HA_ERATT)) |
| 3692 | mdelay(1); |
| 3693 | else |
| 3694 | break; |
| 3695 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3696 | |
| 3697 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3698 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3699 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3703 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3704 | writel(hc_copy, phba->HCregaddr); |
| 3705 | readl(phba->HCregaddr); /* flush */ |
| 3706 | } |
| 3707 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3708 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3709 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3710 | * @phba: Pointer to HBA context object. |
| 3711 | * |
| 3712 | * This function issues a kill_board mailbox command and waits for |
| 3713 | * the error attention interrupt. This function is called for stopping |
| 3714 | * the firmware processing. The caller is not required to hold any |
| 3715 | * locks. This function calls lpfc_hba_down_post function to free |
| 3716 | * any pending commands after the kill. The function will return 1 when it |
| 3717 | * fails to kill the board else will return 0. |
| 3718 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3719 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3720 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3721 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3722 | struct lpfc_sli *psli; |
| 3723 | LPFC_MBOXQ_t *pmb; |
| 3724 | uint32_t status; |
| 3725 | uint32_t ha_copy; |
| 3726 | int retval; |
| 3727 | int i = 0; |
| 3728 | |
| 3729 | psli = &phba->sli; |
| 3730 | |
| 3731 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3732 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3733 | "0329 Kill HBA Data: x%x x%x\n", |
| 3734 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3735 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3736 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3737 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3738 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3739 | |
| 3740 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3742 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3743 | spin_unlock_irq(&phba->hbalock); |
| 3744 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3745 | return 1; |
| 3746 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3747 | status &= ~HC_ERINT_ENA; |
| 3748 | writel(status, phba->HCregaddr); |
| 3749 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3750 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3751 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3752 | |
| 3753 | lpfc_kill_board(phba, pmb); |
| 3754 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3755 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3756 | |
| 3757 | if (retval != MBX_SUCCESS) { |
| 3758 | if (retval != MBX_BUSY) |
| 3759 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3761 | "2752 KILL_BOARD command failed retval %d\n", |
| 3762 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3763 | spin_lock_irq(&phba->hbalock); |
| 3764 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3765 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3766 | return 1; |
| 3767 | } |
| 3768 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3769 | spin_lock_irq(&phba->hbalock); |
| 3770 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3771 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3772 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3773 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3774 | |
| 3775 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3776 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3777 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3778 | * board is now undefined. |
| 3779 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3780 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3781 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3782 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3783 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3784 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3785 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3789 | if (ha_copy & HA_ERATT) { |
| 3790 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3791 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3792 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3793 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3794 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3795 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3797 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3798 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3799 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3800 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3801 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3802 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3803 | } |
| 3804 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3805 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3806 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3807 | * @phba: Pointer to HBA context object. |
| 3808 | * |
| 3809 | * This function resets the HBA by writing HC_INITFF to the control |
| 3810 | * register. After the HBA resets, this function resets all the iocb ring |
| 3811 | * indices. This function disables PCI layer parity checking during |
| 3812 | * the reset. |
| 3813 | * This function returns 0 always. |
| 3814 | * The caller is not required to hold any locks. |
| 3815 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3816 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3817 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3818 | { |
| 3819 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3821 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3824 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3826 | /* Reset HBA */ |
| 3827 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3828 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3829 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | |
| 3831 | /* perform board reset */ |
| 3832 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3833 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3834 | phba->pport->fc_myDID = 0; |
| 3835 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3836 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3837 | /* Turn off parity checking and serr during the physical reset */ |
| 3838 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3839 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3840 | (cfg_value & |
| 3841 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3842 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3843 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3844 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3845 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3846 | writel(HC_INITFF, phba->HCregaddr); |
| 3847 | mdelay(1); |
| 3848 | readl(phba->HCregaddr); /* flush */ |
| 3849 | writel(0, phba->HCregaddr); |
| 3850 | readl(phba->HCregaddr); /* flush */ |
| 3851 | |
| 3852 | /* Restore PCI cmd register */ |
| 3853 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | |
| 3855 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3856 | for (i = 0; i < psli->num_rings; i++) { |
| 3857 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3858 | pring->flag = 0; |
| 3859 | pring->rspidx = 0; |
| 3860 | pring->next_cmdidx = 0; |
| 3861 | pring->local_getidx = 0; |
| 3862 | pring->cmdidx = 0; |
| 3863 | pring->missbufcnt = 0; |
| 3864 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3867 | return 0; |
| 3868 | } |
| 3869 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3870 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3871 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3872 | * @phba: Pointer to HBA context object. |
| 3873 | * |
| 3874 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3875 | * checking during resets the device. The caller is not required to hold |
| 3876 | * any locks. |
| 3877 | * |
| 3878 | * This function returns 0 always. |
| 3879 | **/ |
| 3880 | int |
| 3881 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3882 | { |
| 3883 | struct lpfc_sli *psli = &phba->sli; |
| 3884 | uint16_t cfg_value; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3885 | |
| 3886 | /* Reset HBA */ |
| 3887 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3888 | "0295 Reset HBA Data: x%x x%x\n", |
| 3889 | phba->pport->port_state, psli->sli_flag); |
| 3890 | |
| 3891 | /* perform board reset */ |
| 3892 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3893 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3894 | phba->pport->fc_myDID = 0; |
| 3895 | phba->pport->fc_prevDID = 0; |
| 3896 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3897 | spin_lock_irq(&phba->hbalock); |
| 3898 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3899 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3900 | spin_unlock_irq(&phba->hbalock); |
| 3901 | |
| 3902 | /* Now physically reset the device */ |
| 3903 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3904 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3905 | |
| 3906 | /* Turn off parity checking and serr during the physical reset */ |
| 3907 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3908 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3909 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3910 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3911 | /* Perform FCoE PCI function reset */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 3912 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3913 | lpfc_pci_function_reset(phba); |
| 3914 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3915 | /* Restore PCI cmd register */ |
| 3916 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3917 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3918 | return 0; |
| 3919 | } |
| 3920 | |
| 3921 | /** |
| 3922 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3923 | * @phba: Pointer to HBA context object. |
| 3924 | * |
| 3925 | * This function is called in the SLI initialization code path to |
| 3926 | * restart the HBA. The caller is not required to hold any lock. |
| 3927 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3928 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3929 | * function to free any pending commands. The function enables |
| 3930 | * POST only during the first initialization. The function returns zero. |
| 3931 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3932 | * command before the return of this function. |
| 3933 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3934 | static int |
| 3935 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3936 | { |
| 3937 | MAILBOX_t *mb; |
| 3938 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3939 | volatile uint32_t word0; |
| 3940 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3941 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3942 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3943 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3944 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3945 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 3946 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 3947 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3948 | psli = &phba->sli; |
| 3949 | |
| 3950 | /* Restart HBA */ |
| 3951 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3952 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3953 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3954 | |
| 3955 | word0 = 0; |
| 3956 | mb = (MAILBOX_t *) &word0; |
| 3957 | mb->mbxCommand = MBX_RESTART; |
| 3958 | mb->mbxHc = 1; |
| 3959 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3960 | lpfc_reset_barrier(phba); |
| 3961 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3962 | to_slim = phba->MBslimaddr; |
| 3963 | writel(*(uint32_t *) mb, to_slim); |
| 3964 | readl(to_slim); /* flush */ |
| 3965 | |
| 3966 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3967 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3968 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3969 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3970 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3971 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3972 | writel(*(uint32_t *) mb, to_slim); |
| 3973 | readl(to_slim); /* flush */ |
| 3974 | |
| 3975 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | phba->pport->stopped = 0; |
| 3977 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3978 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3979 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3980 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 3981 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3982 | psli->stats_start = get_seconds(); |
| 3983 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3984 | /* Give the INITFF and Post time to settle. */ |
| 3985 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3987 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 3988 | if (hba_aer_enabled) |
| 3989 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 3990 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3991 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | |
| 3993 | return 0; |
| 3994 | } |
| 3995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3996 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3997 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 3998 | * @phba: Pointer to HBA context object. |
| 3999 | * |
| 4000 | * This function is called in the SLI initialization code path to restart |
| 4001 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4002 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4003 | * free any pending commands. |
| 4004 | **/ |
| 4005 | static int |
| 4006 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4007 | { |
| 4008 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4009 | uint32_t hba_aer_enabled; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4010 | |
| 4011 | /* Restart HBA */ |
| 4012 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4013 | "0296 Restart HBA Data: x%x x%x\n", |
| 4014 | phba->pport->port_state, psli->sli_flag); |
| 4015 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4016 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4017 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4018 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4019 | lpfc_sli4_brdreset(phba); |
| 4020 | |
| 4021 | spin_lock_irq(&phba->hbalock); |
| 4022 | phba->pport->stopped = 0; |
| 4023 | phba->link_state = LPFC_INIT_START; |
| 4024 | phba->hba_flag = 0; |
| 4025 | spin_unlock_irq(&phba->hbalock); |
| 4026 | |
| 4027 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4028 | psli->stats_start = get_seconds(); |
| 4029 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4030 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4031 | if (hba_aer_enabled) |
| 4032 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4033 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4034 | lpfc_hba_down_post(phba); |
| 4035 | |
| 4036 | return 0; |
| 4037 | } |
| 4038 | |
| 4039 | /** |
| 4040 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4041 | * @phba: Pointer to HBA context object. |
| 4042 | * |
| 4043 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4044 | * API jump table function pointer from the lpfc_hba struct. |
| 4045 | **/ |
| 4046 | int |
| 4047 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4048 | { |
| 4049 | return phba->lpfc_sli_brdrestart(phba); |
| 4050 | } |
| 4051 | |
| 4052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4053 | * 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] | 4054 | * @phba: Pointer to HBA context object. |
| 4055 | * |
| 4056 | * This function is called after a HBA restart to wait for successful |
| 4057 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4058 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4059 | * iteration, the function will restart the HBA again. The function returns |
| 4060 | * zero if HBA successfully restarted else returns negative error code. |
| 4061 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4062 | static int |
| 4063 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4064 | { |
| 4065 | uint32_t status, i = 0; |
| 4066 | |
| 4067 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4068 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4069 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4070 | |
| 4071 | /* Check status register to see what current state is */ |
| 4072 | i = 0; |
| 4073 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4074 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4075 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4076 | * retries, then every 1 sec for 50 retires for a total of |
| 4077 | * ~60 seconds before reset the board again and check every |
| 4078 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4079 | * board ready is required by the Falcon FIPS zeroization |
| 4080 | * complete, and any reset the board in between shall cause |
| 4081 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4083 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | /* Adapter failed to init, timeout, status reg |
| 4085 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4087 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4088 | "timeout, status reg x%x, " |
| 4089 | "FW Data: A8 x%x AC x%x\n", status, |
| 4090 | readl(phba->MBslimaddr + 0xa8), |
| 4091 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4092 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | return -ETIMEDOUT; |
| 4094 | } |
| 4095 | |
| 4096 | /* Check to see if any errors occurred during init */ |
| 4097 | if (status & HS_FFERM) { |
| 4098 | /* ERROR: During chipset initialization */ |
| 4099 | /* Adapter failed to init, chipset, status reg |
| 4100 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4101 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4102 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4103 | "chipset, status reg x%x, " |
| 4104 | "FW Data: A8 x%x AC x%x\n", status, |
| 4105 | readl(phba->MBslimaddr + 0xa8), |
| 4106 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4107 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | return -EIO; |
| 4109 | } |
| 4110 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4111 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4113 | else if (i <= 100) |
| 4114 | msleep(100); |
| 4115 | else |
| 4116 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4118 | if (i == 150) { |
| 4119 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4120 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4121 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4122 | } |
| 4123 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4124 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4125 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | /* Check to see if any errors occurred during init */ |
| 4129 | if (status & HS_FFERM) { |
| 4130 | /* ERROR: During chipset initialization */ |
| 4131 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4133 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4134 | "status reg x%x, " |
| 4135 | "FW Data: A8 x%x AC x%x\n", status, |
| 4136 | readl(phba->MBslimaddr + 0xa8), |
| 4137 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4138 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | return -EIO; |
| 4140 | } |
| 4141 | |
| 4142 | /* Clear all interrupt enable conditions */ |
| 4143 | writel(0, phba->HCregaddr); |
| 4144 | readl(phba->HCregaddr); /* flush */ |
| 4145 | |
| 4146 | /* setup host attn register */ |
| 4147 | writel(0xffffffff, phba->HAregaddr); |
| 4148 | readl(phba->HAregaddr); /* flush */ |
| 4149 | return 0; |
| 4150 | } |
| 4151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4153 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4154 | * |
| 4155 | * This function calculates and returns the number of HBQs required to be |
| 4156 | * configured. |
| 4157 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4158 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4159 | lpfc_sli_hbq_count(void) |
| 4160 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4161 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 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_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4166 | * |
| 4167 | * This function adds the number of hbq entries in every HBQ to get |
| 4168 | * the total number of hbq entries required for the HBA and returns |
| 4169 | * the total count. |
| 4170 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4171 | static int |
| 4172 | lpfc_sli_hbq_entry_count(void) |
| 4173 | { |
| 4174 | int hbq_count = lpfc_sli_hbq_count(); |
| 4175 | int count = 0; |
| 4176 | int i; |
| 4177 | |
| 4178 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4179 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4180 | return count; |
| 4181 | } |
| 4182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4183 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4184 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4185 | * |
| 4186 | * This function calculates amount of memory required for all hbq entries |
| 4187 | * to be configured and returns the total memory required. |
| 4188 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4190 | lpfc_sli_hbq_size(void) |
| 4191 | { |
| 4192 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 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_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4197 | * @phba: Pointer to HBA context object. |
| 4198 | * |
| 4199 | * This function is called during the SLI initialization to configure |
| 4200 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4201 | * required to hold any locks. This function will return zero if successful |
| 4202 | * else it will return negative error code. |
| 4203 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4204 | static int |
| 4205 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4206 | { |
| 4207 | int hbq_count = lpfc_sli_hbq_count(); |
| 4208 | LPFC_MBOXQ_t *pmb; |
| 4209 | MAILBOX_t *pmbox; |
| 4210 | uint32_t hbqno; |
| 4211 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4212 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4213 | /* Get a Mailbox buffer to setup mailbox |
| 4214 | * commands for HBA initialization |
| 4215 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4216 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4217 | |
| 4218 | if (!pmb) |
| 4219 | return -ENOMEM; |
| 4220 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4221 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4222 | |
| 4223 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4224 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4225 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4226 | |
| 4227 | hbq_entry_index = 0; |
| 4228 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4229 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4230 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4231 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4232 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4233 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4234 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4235 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4236 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4237 | |
| 4238 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4239 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4240 | mbxStatus <status>, ring <num> */ |
| 4241 | |
| 4242 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4243 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4244 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4245 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4246 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4247 | pmbox->mbxStatus, hbqno); |
| 4248 | |
| 4249 | phba->link_state = LPFC_HBA_ERROR; |
| 4250 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4251 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4252 | } |
| 4253 | } |
| 4254 | phba->hbq_count = hbq_count; |
| 4255 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4256 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4257 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4258 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4259 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4260 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4261 | return 0; |
| 4262 | } |
| 4263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4265 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4266 | * @phba: Pointer to HBA context object. |
| 4267 | * |
| 4268 | * This function is called during the SLI initialization to configure |
| 4269 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4270 | * required to hold any locks. This function will return zero if successful |
| 4271 | * else it will return negative error code. |
| 4272 | **/ |
| 4273 | static int |
| 4274 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4275 | { |
| 4276 | phba->hbq_in_use = 1; |
| 4277 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4278 | phba->hbq_count = 1; |
| 4279 | /* Initially populate or replenish the HBQs */ |
| 4280 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4281 | return 0; |
| 4282 | } |
| 4283 | |
| 4284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4285 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4286 | * @phba: Pointer to HBA context object. |
| 4287 | * @sli_mode: sli mode - 2/3 |
| 4288 | * |
| 4289 | * This function is called by the sli intialization code path |
| 4290 | * to issue config_port mailbox command. This function restarts the |
| 4291 | * HBA firmware and issues a config_port mailbox command to configure |
| 4292 | * the SLI interface in the sli mode specified by sli_mode |
| 4293 | * variable. The caller is not required to hold any locks. |
| 4294 | * The function returns 0 if successful, else returns negative error |
| 4295 | * code. |
| 4296 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4297 | int |
| 4298 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | { |
| 4300 | LPFC_MBOXQ_t *pmb; |
| 4301 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4302 | |
| 4303 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4304 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | return -ENOMEM; |
| 4307 | } |
| 4308 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4309 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4311 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4312 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4314 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4315 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | rc = lpfc_sli_chipset_init(phba); |
| 4317 | if (rc) |
| 4318 | break; |
| 4319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4321 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | resetcount++; |
| 4324 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4325 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4326 | * value of 0 means the call was successful. Any other |
| 4327 | * nonzero value is a failure, but if ERESTART is returned, |
| 4328 | * the driver may reset the HBA and try again. |
| 4329 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | rc = lpfc_config_port_prep(phba); |
| 4331 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4332 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4334 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4336 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | lpfc_config_port(phba, pmb); |
| 4339 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4340 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4341 | LPFC_SLI3_HBQ_ENABLED | |
| 4342 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4343 | LPFC_SLI3_BG_ENABLED | |
| 4344 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4345 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4347 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4348 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4349 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4350 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4351 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | spin_unlock_irq(&phba->hbalock); |
| 4353 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4354 | } else { |
| 4355 | /* Allow asynchronous mailbox command to go through */ |
| 4356 | spin_lock_irq(&phba->hbalock); |
| 4357 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4358 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4359 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4360 | |
| 4361 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4362 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4363 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4364 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4365 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4366 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4367 | if (!done) { |
| 4368 | rc = -EINVAL; |
| 4369 | goto do_prep_failed; |
| 4370 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4371 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4372 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4373 | rc = -ENXIO; |
| 4374 | goto do_prep_failed; |
| 4375 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4376 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4377 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4378 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4379 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4380 | phba->max_vpi : phba->max_vports; |
| 4381 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4382 | } else |
| 4383 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4384 | phba->fips_level = 0; |
| 4385 | phba->fips_spec_rev = 0; |
| 4386 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4387 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4388 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4389 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4390 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4391 | "2850 Security Crypto Active. FIPS x%d " |
| 4392 | "(Spec Rev: x%d)", |
| 4393 | phba->fips_level, phba->fips_spec_rev); |
| 4394 | } |
| 4395 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4397 | "2856 Config Port Security Crypto " |
| 4398 | "Error: x%x ", |
| 4399 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4400 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4401 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4402 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4403 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4404 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4405 | |
| 4406 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4407 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4408 | |
| 4409 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4410 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4411 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4412 | else |
| 4413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4414 | "0443 Adapter did not grant " |
| 4415 | "BlockGuard\n"); |
| 4416 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4417 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4418 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4419 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4420 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4421 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4422 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4423 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4424 | return rc; |
| 4425 | } |
| 4426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4427 | |
| 4428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4429 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4430 | * @phba: Pointer to HBA context object. |
| 4431 | * |
| 4432 | * This function is the main SLI intialization function. This function |
| 4433 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4434 | * error attention handler code. Caller is not required to hold any |
| 4435 | * locks. This function issues config_port mailbox command to configure |
| 4436 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4437 | * calls the config_port_post function to issue init_link mailbox |
| 4438 | * command and to start the discovery. The function will return zero |
| 4439 | * if successful, else it will return negative error code. |
| 4440 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4441 | int |
| 4442 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4443 | { |
| 4444 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4445 | int mode = 3, i; |
| 4446 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4447 | |
| 4448 | switch (lpfc_sli_mode) { |
| 4449 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4450 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4452 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4453 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4454 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4455 | break; |
| 4456 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4457 | mode = 2; |
| 4458 | break; |
| 4459 | case 0: |
| 4460 | case 3: |
| 4461 | break; |
| 4462 | default: |
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 | "1819 Unrecognized lpfc_sli_mode " |
| 4465 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4466 | |
| 4467 | break; |
| 4468 | } |
| 4469 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4470 | rc = lpfc_sli_config_port(phba, mode); |
| 4471 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4472 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4473 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4474 | "1820 Unable to select SLI-3. " |
| 4475 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4476 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4477 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4478 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | goto lpfc_sli_hba_setup_error; |
| 4480 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4481 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4482 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4483 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4484 | if (!rc) { |
| 4485 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4486 | "2709 This device supports " |
| 4487 | "Advanced Error Reporting (AER)\n"); |
| 4488 | spin_lock_irq(&phba->hbalock); |
| 4489 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4490 | spin_unlock_irq(&phba->hbalock); |
| 4491 | } else { |
| 4492 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4493 | "2708 This device does not support " |
| 4494 | "Advanced Error Reporting (AER)\n"); |
| 4495 | phba->cfg_aer_support = 0; |
| 4496 | } |
| 4497 | } |
| 4498 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4499 | if (phba->sli_rev == 3) { |
| 4500 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4501 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4502 | } else { |
| 4503 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4504 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4505 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4509 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4510 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4511 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4512 | |
| 4513 | if (rc) |
| 4514 | goto lpfc_sli_hba_setup_error; |
| 4515 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4516 | /* Initialize VPIs. */ |
| 4517 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4518 | /* |
| 4519 | * The VPI bitmask and physical ID array are allocated |
| 4520 | * and initialized once only - at driver load. A port |
| 4521 | * reset doesn't need to reinitialize this memory. |
| 4522 | */ |
| 4523 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4524 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4525 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4526 | GFP_KERNEL); |
| 4527 | if (!phba->vpi_bmask) { |
| 4528 | rc = -ENOMEM; |
| 4529 | goto lpfc_sli_hba_setup_error; |
| 4530 | } |
| 4531 | |
| 4532 | phba->vpi_ids = kzalloc( |
| 4533 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4534 | GFP_KERNEL); |
| 4535 | if (!phba->vpi_ids) { |
| 4536 | kfree(phba->vpi_bmask); |
| 4537 | rc = -ENOMEM; |
| 4538 | goto lpfc_sli_hba_setup_error; |
| 4539 | } |
| 4540 | for (i = 0; i < phba->max_vpi; i++) |
| 4541 | phba->vpi_ids[i] = i; |
| 4542 | } |
| 4543 | } |
| 4544 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4545 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4546 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4547 | rc = lpfc_sli_hbq_setup(phba); |
| 4548 | if (rc) |
| 4549 | goto lpfc_sli_hba_setup_error; |
| 4550 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4551 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4553 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4554 | |
| 4555 | rc = lpfc_config_port_post(phba); |
| 4556 | if (rc) |
| 4557 | goto lpfc_sli_hba_setup_error; |
| 4558 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4559 | return rc; |
| 4560 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4561 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4563 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4564 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4565 | return rc; |
| 4566 | } |
| 4567 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4568 | /** |
| 4569 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4570 | * @phba: Pointer to HBA context object. |
| 4571 | * @mboxq: mailbox pointer. |
| 4572 | * This function issue a dump mailbox command to read config region |
| 4573 | * 23 and parse the records in the region and populate driver |
| 4574 | * data structure. |
| 4575 | **/ |
| 4576 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4577 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4578 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4579 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4580 | struct lpfc_dmabuf *mp; |
| 4581 | struct lpfc_mqe *mqe; |
| 4582 | uint32_t data_length; |
| 4583 | int rc; |
| 4584 | |
| 4585 | /* Program the default value of vlan_id and fc_map */ |
| 4586 | phba->valid_vlan = 0; |
| 4587 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4588 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4589 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4590 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4591 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4592 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4593 | return -ENOMEM; |
| 4594 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4595 | mqe = &mboxq->u.mqe; |
| 4596 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4597 | rc = -ENOMEM; |
| 4598 | goto out_free_mboxq; |
| 4599 | } |
| 4600 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4601 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4602 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4603 | |
| 4604 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4605 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4606 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4607 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4608 | "CQ: x%x x%x x%x x%x\n", |
| 4609 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4610 | bf_get(lpfc_mqe_command, mqe), |
| 4611 | bf_get(lpfc_mqe_status, mqe), |
| 4612 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4613 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4614 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4615 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4616 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4617 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4618 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4619 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4620 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4621 | mboxq->mcqe.word0, |
| 4622 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4623 | mboxq->mcqe.trailer); |
| 4624 | |
| 4625 | if (rc) { |
| 4626 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4627 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4628 | rc = -EIO; |
| 4629 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4630 | } |
| 4631 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4632 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4633 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4634 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4635 | rc = -EIO; |
| 4636 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4637 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4638 | |
| 4639 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4640 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4641 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4642 | rc = 0; |
| 4643 | |
| 4644 | out_free_mboxq: |
| 4645 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4646 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4651 | * @phba: pointer to lpfc hba data structure. |
| 4652 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4653 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4654 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4655 | * On output, the number of data bytes in @vpd. |
| 4656 | * |
| 4657 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4658 | * addition, this routine gets the port vpd data. |
| 4659 | * |
| 4660 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4661 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4662 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4663 | **/ |
| 4664 | static int |
| 4665 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4666 | uint8_t *vpd, uint32_t *vpd_size) |
| 4667 | { |
| 4668 | int rc = 0; |
| 4669 | uint32_t dma_size; |
| 4670 | struct lpfc_dmabuf *dmabuf; |
| 4671 | struct lpfc_mqe *mqe; |
| 4672 | |
| 4673 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4674 | if (!dmabuf) |
| 4675 | return -ENOMEM; |
| 4676 | |
| 4677 | /* |
| 4678 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4679 | * mailbox command. |
| 4680 | */ |
| 4681 | dma_size = *vpd_size; |
| 4682 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4683 | dma_size, |
| 4684 | &dmabuf->phys, |
| 4685 | GFP_KERNEL); |
| 4686 | if (!dmabuf->virt) { |
| 4687 | kfree(dmabuf); |
| 4688 | return -ENOMEM; |
| 4689 | } |
| 4690 | memset(dmabuf->virt, 0, dma_size); |
| 4691 | |
| 4692 | /* |
| 4693 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4694 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4695 | * in SLI3. This code corrects the conflicts. |
| 4696 | */ |
| 4697 | lpfc_read_rev(phba, mboxq); |
| 4698 | mqe = &mboxq->u.mqe; |
| 4699 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4700 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4701 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4702 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4703 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4704 | |
| 4705 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4706 | if (rc) { |
| 4707 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4708 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4709 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4710 | return -EIO; |
| 4711 | } |
| 4712 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4713 | /* |
| 4714 | * The available vpd length cannot be bigger than the |
| 4715 | * DMA buffer passed to the port. Catch the less than |
| 4716 | * case and update the caller's size. |
| 4717 | */ |
| 4718 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4719 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4720 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4721 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4722 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4723 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4724 | dmabuf->virt, dmabuf->phys); |
| 4725 | kfree(dmabuf); |
| 4726 | return 0; |
| 4727 | } |
| 4728 | |
| 4729 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4730 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4731 | * @phba: pointer to lpfc hba data structure. |
| 4732 | * |
| 4733 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4734 | * is attached to. |
| 4735 | * |
| 4736 | * Return codes |
| 4737 | * 0 - sucessful |
| 4738 | * otherwise - failed to retrieve physical port name |
| 4739 | **/ |
| 4740 | static int |
| 4741 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4742 | { |
| 4743 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4744 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4745 | struct lpfc_controller_attribute *cntl_attr; |
| 4746 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4747 | void *virtaddr = NULL; |
| 4748 | uint32_t alloclen, reqlen; |
| 4749 | uint32_t shdr_status, shdr_add_status; |
| 4750 | union lpfc_sli4_cfg_shdr *shdr; |
| 4751 | char cport_name = 0; |
| 4752 | int rc; |
| 4753 | |
| 4754 | /* We assume nothing at this point */ |
| 4755 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4756 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4757 | |
| 4758 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4759 | if (!mboxq) |
| 4760 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4761 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4762 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4763 | lpfc_sli4_read_config(phba); |
| 4764 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4765 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4766 | |
| 4767 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4768 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4769 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4770 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4771 | LPFC_SLI4_MBX_NEMBED); |
| 4772 | if (alloclen < reqlen) { |
| 4773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4774 | "3084 Allocated DMA memory size (%d) is " |
| 4775 | "less than the requested DMA memory size " |
| 4776 | "(%d)\n", alloclen, reqlen); |
| 4777 | rc = -ENOMEM; |
| 4778 | goto out_free_mboxq; |
| 4779 | } |
| 4780 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4781 | virtaddr = mboxq->sge_array->addr[0]; |
| 4782 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4783 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4784 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4785 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4786 | if (shdr_status || shdr_add_status || rc) { |
| 4787 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4788 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4789 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4790 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4791 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4792 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4793 | rc, shdr_status, shdr_add_status); |
| 4794 | rc = -ENXIO; |
| 4795 | goto out_free_mboxq; |
| 4796 | } |
| 4797 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4798 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4799 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4800 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4801 | phba->sli4_hba.lnk_info.lnk_no = |
| 4802 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4803 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4804 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4805 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4806 | phba->sli4_hba.lnk_info.lnk_no); |
| 4807 | |
| 4808 | retrieve_ppname: |
| 4809 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4810 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4811 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4812 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4813 | LPFC_SLI4_MBX_EMBED); |
| 4814 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4815 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4816 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4817 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4818 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4819 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4820 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4821 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4822 | if (shdr_status || shdr_add_status || rc) { |
| 4823 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4824 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4825 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4826 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4827 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4828 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4829 | rc, shdr_status, shdr_add_status); |
| 4830 | rc = -ENXIO; |
| 4831 | goto out_free_mboxq; |
| 4832 | } |
| 4833 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4834 | case LPFC_LINK_NUMBER_0: |
| 4835 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4836 | &get_port_name->u.response); |
| 4837 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4838 | break; |
| 4839 | case LPFC_LINK_NUMBER_1: |
| 4840 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4841 | &get_port_name->u.response); |
| 4842 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4843 | break; |
| 4844 | case LPFC_LINK_NUMBER_2: |
| 4845 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4846 | &get_port_name->u.response); |
| 4847 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4848 | break; |
| 4849 | case LPFC_LINK_NUMBER_3: |
| 4850 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4851 | &get_port_name->u.response); |
| 4852 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4853 | break; |
| 4854 | default: |
| 4855 | break; |
| 4856 | } |
| 4857 | |
| 4858 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4859 | phba->Port[0] = cport_name; |
| 4860 | phba->Port[1] = '\0'; |
| 4861 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4862 | "3091 SLI get port name: %s\n", phba->Port); |
| 4863 | } |
| 4864 | |
| 4865 | out_free_mboxq: |
| 4866 | if (rc != MBX_TIMEOUT) { |
| 4867 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4868 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4869 | else |
| 4870 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4871 | } |
| 4872 | return rc; |
| 4873 | } |
| 4874 | |
| 4875 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4876 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4877 | * @phba: pointer to lpfc hba data structure. |
| 4878 | * |
| 4879 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4880 | * event queues |
| 4881 | **/ |
| 4882 | static void |
| 4883 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4884 | { |
| 4885 | uint8_t fcp_eqidx; |
| 4886 | |
| 4887 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4888 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4889 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4890 | if (phba->sli4_hba.fcp_cq) { |
| 4891 | do |
| 4892 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4893 | LPFC_QUEUE_REARM); |
| 4894 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
| 4895 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4896 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4897 | if (phba->sli4_hba.fp_eq) { |
| 4898 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 4899 | fcp_eqidx++) |
| 4900 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], |
| 4901 | LPFC_QUEUE_REARM); |
| 4902 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4906 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4907 | * @phba: Pointer to HBA context object. |
| 4908 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4909 | * @extnt_count: buffer to hold port available extent count. |
| 4910 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4911 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4912 | * This function calls the port and retrievs the number of available |
| 4913 | * extents and their size for a particular extent type. |
| 4914 | * |
| 4915 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4916 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4917 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4918 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 4919 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 4920 | { |
| 4921 | int rc = 0; |
| 4922 | uint32_t length; |
| 4923 | uint32_t mbox_tmo; |
| 4924 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 4925 | LPFC_MBOXQ_t *mbox; |
| 4926 | |
| 4927 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4928 | if (!mbox) |
| 4929 | return -ENOMEM; |
| 4930 | |
| 4931 | /* Find out how many extents are available for this resource type */ |
| 4932 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 4933 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 4934 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4935 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 4936 | length, LPFC_SLI4_MBX_EMBED); |
| 4937 | |
| 4938 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 4939 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 4940 | LPFC_SLI4_MBX_EMBED); |
| 4941 | if (unlikely(rc)) { |
| 4942 | rc = -EIO; |
| 4943 | goto err_exit; |
| 4944 | } |
| 4945 | |
| 4946 | if (!phba->sli4_hba.intr_enable) |
| 4947 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 4948 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 4949 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4950 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 4951 | } |
| 4952 | if (unlikely(rc)) { |
| 4953 | rc = -EIO; |
| 4954 | goto err_exit; |
| 4955 | } |
| 4956 | |
| 4957 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 4958 | if (bf_get(lpfc_mbox_hdr_status, |
| 4959 | &rsrc_info->header.cfg_shdr.response)) { |
| 4960 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 4961 | "2930 Failed to get resource extents " |
| 4962 | "Status 0x%x Add'l Status 0x%x\n", |
| 4963 | bf_get(lpfc_mbox_hdr_status, |
| 4964 | &rsrc_info->header.cfg_shdr.response), |
| 4965 | bf_get(lpfc_mbox_hdr_add_status, |
| 4966 | &rsrc_info->header.cfg_shdr.response)); |
| 4967 | rc = -EIO; |
| 4968 | goto err_exit; |
| 4969 | } |
| 4970 | |
| 4971 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 4972 | &rsrc_info->u.rsp); |
| 4973 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 4974 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4975 | |
| 4976 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4977 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 4978 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 4979 | |
| 4980 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4981 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4982 | return rc; |
| 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 4987 | * @phba: Pointer to HBA context object. |
| 4988 | * @type: The extent type to check. |
| 4989 | * |
| 4990 | * This function reads the current available extents from the port and checks |
| 4991 | * if the extent count or extent size has changed since the last access. |
| 4992 | * Callers use this routine post port reset to understand if there is a |
| 4993 | * extent reprovisioning requirement. |
| 4994 | * |
| 4995 | * Returns: |
| 4996 | * -Error: error indicates problem. |
| 4997 | * 1: Extent count or size has changed. |
| 4998 | * 0: No changes. |
| 4999 | **/ |
| 5000 | static int |
| 5001 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5002 | { |
| 5003 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5004 | uint16_t size_diff, rsrc_ext_size; |
| 5005 | int rc = 0; |
| 5006 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5007 | struct list_head *rsrc_blk_list = NULL; |
| 5008 | |
| 5009 | size_diff = 0; |
| 5010 | curr_ext_cnt = 0; |
| 5011 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5012 | &rsrc_ext_cnt, |
| 5013 | &rsrc_ext_size); |
| 5014 | if (unlikely(rc)) |
| 5015 | return -EIO; |
| 5016 | |
| 5017 | switch (type) { |
| 5018 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5019 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5020 | break; |
| 5021 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5022 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5023 | break; |
| 5024 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5025 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5026 | break; |
| 5027 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5028 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5029 | break; |
| 5030 | default: |
| 5031 | break; |
| 5032 | } |
| 5033 | |
| 5034 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5035 | curr_ext_cnt++; |
| 5036 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5037 | size_diff++; |
| 5038 | } |
| 5039 | |
| 5040 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5041 | rc = 1; |
| 5042 | |
| 5043 | return rc; |
| 5044 | } |
| 5045 | |
| 5046 | /** |
| 5047 | * lpfc_sli4_cfg_post_extnts - |
| 5048 | * @phba: Pointer to HBA context object. |
| 5049 | * @extnt_cnt - number of available extents. |
| 5050 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5051 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5052 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5053 | * |
| 5054 | * This function executes the extents allocation request. It also |
| 5055 | * takes care of the amount of memory needed to allocate or get the |
| 5056 | * allocated extents. It is the caller's responsibility to evaluate |
| 5057 | * the response. |
| 5058 | * |
| 5059 | * Returns: |
| 5060 | * -Error: Error value describes the condition found. |
| 5061 | * 0: if successful |
| 5062 | **/ |
| 5063 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5064 | 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] | 5065 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5066 | { |
| 5067 | int rc = 0; |
| 5068 | uint32_t req_len; |
| 5069 | uint32_t emb_len; |
| 5070 | uint32_t alloc_len, mbox_tmo; |
| 5071 | |
| 5072 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5073 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5074 | |
| 5075 | /* |
| 5076 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5077 | * accounts for extents-specific word. |
| 5078 | */ |
| 5079 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5080 | sizeof(uint32_t); |
| 5081 | |
| 5082 | /* |
| 5083 | * Presume the allocation and response will fit into an embedded |
| 5084 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5085 | */ |
| 5086 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5087 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5088 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5089 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5090 | sizeof(uint32_t); |
| 5091 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5092 | } |
| 5093 | |
| 5094 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5095 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5096 | req_len, *emb); |
| 5097 | if (alloc_len < req_len) { |
| 5098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5099 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5100 | "less than the requested DMA memory " |
| 5101 | "size (x%x)\n", alloc_len, req_len); |
| 5102 | return -ENOMEM; |
| 5103 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5104 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5105 | if (unlikely(rc)) |
| 5106 | return -EIO; |
| 5107 | |
| 5108 | if (!phba->sli4_hba.intr_enable) |
| 5109 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5110 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5111 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5112 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5113 | } |
| 5114 | |
| 5115 | if (unlikely(rc)) |
| 5116 | rc = -EIO; |
| 5117 | return rc; |
| 5118 | } |
| 5119 | |
| 5120 | /** |
| 5121 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5122 | * @phba: Pointer to HBA context object. |
| 5123 | * @type: The resource extent type to allocate. |
| 5124 | * |
| 5125 | * This function allocates the number of elements for the specified |
| 5126 | * resource type. |
| 5127 | **/ |
| 5128 | static int |
| 5129 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5130 | { |
| 5131 | bool emb = false; |
| 5132 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5133 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5134 | uint16_t *ids; |
| 5135 | int i, rc; |
| 5136 | unsigned long longs; |
| 5137 | unsigned long *bmask; |
| 5138 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5139 | LPFC_MBOXQ_t *mbox; |
| 5140 | uint32_t length; |
| 5141 | struct lpfc_id_range *id_array = NULL; |
| 5142 | void *virtaddr = NULL; |
| 5143 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5144 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5145 | struct list_head *ext_blk_list; |
| 5146 | |
| 5147 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5148 | &rsrc_cnt, |
| 5149 | &rsrc_size); |
| 5150 | if (unlikely(rc)) |
| 5151 | return -EIO; |
| 5152 | |
| 5153 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5154 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5155 | "3009 No available Resource Extents " |
| 5156 | "for resource type 0x%x: Count: 0x%x, " |
| 5157 | "Size 0x%x\n", type, rsrc_cnt, |
| 5158 | rsrc_size); |
| 5159 | return -ENOMEM; |
| 5160 | } |
| 5161 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5162 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5163 | "2903 Post resource extents type-0x%x: " |
| 5164 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5165 | |
| 5166 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5167 | if (!mbox) |
| 5168 | return -ENOMEM; |
| 5169 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5170 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5171 | if (unlikely(rc)) { |
| 5172 | rc = -EIO; |
| 5173 | goto err_exit; |
| 5174 | } |
| 5175 | |
| 5176 | /* |
| 5177 | * Figure out where the response is located. Then get local pointers |
| 5178 | * to the response data. The port does not guarantee to respond to |
| 5179 | * all extents counts request so update the local variable with the |
| 5180 | * allocated count from the port. |
| 5181 | */ |
| 5182 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5183 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5184 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5185 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5186 | } else { |
| 5187 | virtaddr = mbox->sge_array->addr[0]; |
| 5188 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5189 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5190 | id_array = &n_rsrc->id; |
| 5191 | } |
| 5192 | |
| 5193 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5194 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5195 | |
| 5196 | /* |
| 5197 | * Based on the resource size and count, correct the base and max |
| 5198 | * resource values. |
| 5199 | */ |
| 5200 | length = sizeof(struct lpfc_rsrc_blks); |
| 5201 | switch (type) { |
| 5202 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5203 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5204 | sizeof(unsigned long), |
| 5205 | GFP_KERNEL); |
| 5206 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5207 | rc = -ENOMEM; |
| 5208 | goto err_exit; |
| 5209 | } |
| 5210 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5211 | sizeof(uint16_t), |
| 5212 | GFP_KERNEL); |
| 5213 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5214 | kfree(phba->sli4_hba.rpi_bmask); |
| 5215 | rc = -ENOMEM; |
| 5216 | goto err_exit; |
| 5217 | } |
| 5218 | |
| 5219 | /* |
| 5220 | * The next_rpi was initialized with the maximum available |
| 5221 | * count but the port may allocate a smaller number. Catch |
| 5222 | * that case and update the next_rpi. |
| 5223 | */ |
| 5224 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5225 | |
| 5226 | /* Initialize local ptrs for common extent processing later. */ |
| 5227 | bmask = phba->sli4_hba.rpi_bmask; |
| 5228 | ids = phba->sli4_hba.rpi_ids; |
| 5229 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5230 | break; |
| 5231 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5232 | phba->vpi_bmask = kzalloc(longs * |
| 5233 | sizeof(unsigned long), |
| 5234 | GFP_KERNEL); |
| 5235 | if (unlikely(!phba->vpi_bmask)) { |
| 5236 | rc = -ENOMEM; |
| 5237 | goto err_exit; |
| 5238 | } |
| 5239 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5240 | sizeof(uint16_t), |
| 5241 | GFP_KERNEL); |
| 5242 | if (unlikely(!phba->vpi_ids)) { |
| 5243 | kfree(phba->vpi_bmask); |
| 5244 | rc = -ENOMEM; |
| 5245 | goto err_exit; |
| 5246 | } |
| 5247 | |
| 5248 | /* Initialize local ptrs for common extent processing later. */ |
| 5249 | bmask = phba->vpi_bmask; |
| 5250 | ids = phba->vpi_ids; |
| 5251 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5252 | break; |
| 5253 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5254 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5255 | sizeof(unsigned long), |
| 5256 | GFP_KERNEL); |
| 5257 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5258 | rc = -ENOMEM; |
| 5259 | goto err_exit; |
| 5260 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5261 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5262 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5263 | sizeof(uint16_t), |
| 5264 | GFP_KERNEL); |
| 5265 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5266 | kfree(phba->sli4_hba.xri_bmask); |
| 5267 | rc = -ENOMEM; |
| 5268 | goto err_exit; |
| 5269 | } |
| 5270 | |
| 5271 | /* Initialize local ptrs for common extent processing later. */ |
| 5272 | bmask = phba->sli4_hba.xri_bmask; |
| 5273 | ids = phba->sli4_hba.xri_ids; |
| 5274 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5275 | break; |
| 5276 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5277 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5278 | sizeof(unsigned long), |
| 5279 | GFP_KERNEL); |
| 5280 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5281 | rc = -ENOMEM; |
| 5282 | goto err_exit; |
| 5283 | } |
| 5284 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5285 | sizeof(uint16_t), |
| 5286 | GFP_KERNEL); |
| 5287 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5288 | kfree(phba->sli4_hba.vfi_bmask); |
| 5289 | rc = -ENOMEM; |
| 5290 | goto err_exit; |
| 5291 | } |
| 5292 | |
| 5293 | /* Initialize local ptrs for common extent processing later. */ |
| 5294 | bmask = phba->sli4_hba.vfi_bmask; |
| 5295 | ids = phba->sli4_hba.vfi_ids; |
| 5296 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5297 | break; |
| 5298 | default: |
| 5299 | /* Unsupported Opcode. Fail call. */ |
| 5300 | id_array = NULL; |
| 5301 | bmask = NULL; |
| 5302 | ids = NULL; |
| 5303 | ext_blk_list = NULL; |
| 5304 | goto err_exit; |
| 5305 | } |
| 5306 | |
| 5307 | /* |
| 5308 | * Complete initializing the extent configuration with the |
| 5309 | * allocated ids assigned to this function. The bitmask serves |
| 5310 | * as an index into the array and manages the available ids. The |
| 5311 | * array just stores the ids communicated to the port via the wqes. |
| 5312 | */ |
| 5313 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5314 | if ((i % 2) == 0) |
| 5315 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5316 | &id_array[k]); |
| 5317 | else |
| 5318 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5319 | &id_array[k]); |
| 5320 | |
| 5321 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5322 | if (unlikely(!rsrc_blks)) { |
| 5323 | rc = -ENOMEM; |
| 5324 | kfree(bmask); |
| 5325 | kfree(ids); |
| 5326 | goto err_exit; |
| 5327 | } |
| 5328 | rsrc_blks->rsrc_start = rsrc_id; |
| 5329 | rsrc_blks->rsrc_size = rsrc_size; |
| 5330 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5331 | rsrc_start = rsrc_id; |
| 5332 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5333 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5334 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5335 | |
| 5336 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5337 | ids[j] = rsrc_id; |
| 5338 | rsrc_id++; |
| 5339 | j++; |
| 5340 | } |
| 5341 | /* Entire word processed. Get next word.*/ |
| 5342 | if ((i % 2) == 1) |
| 5343 | k++; |
| 5344 | } |
| 5345 | err_exit: |
| 5346 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5347 | return rc; |
| 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5352 | * @phba: Pointer to HBA context object. |
| 5353 | * @type: the extent's type. |
| 5354 | * |
| 5355 | * This function deallocates all extents of a particular resource type. |
| 5356 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5357 | * is the caller's responsibility to release all kernel memory resources. |
| 5358 | **/ |
| 5359 | static int |
| 5360 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5361 | { |
| 5362 | int rc; |
| 5363 | uint32_t length, mbox_tmo = 0; |
| 5364 | LPFC_MBOXQ_t *mbox; |
| 5365 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5366 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5367 | |
| 5368 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5369 | if (!mbox) |
| 5370 | return -ENOMEM; |
| 5371 | |
| 5372 | /* |
| 5373 | * This function sends an embedded mailbox because it only sends the |
| 5374 | * the resource type. All extents of this type are released by the |
| 5375 | * port. |
| 5376 | */ |
| 5377 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5378 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5379 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5380 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5381 | length, LPFC_SLI4_MBX_EMBED); |
| 5382 | |
| 5383 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5384 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5385 | LPFC_SLI4_MBX_EMBED); |
| 5386 | if (unlikely(rc)) { |
| 5387 | rc = -EIO; |
| 5388 | goto out_free_mbox; |
| 5389 | } |
| 5390 | if (!phba->sli4_hba.intr_enable) |
| 5391 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5392 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5393 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5394 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5395 | } |
| 5396 | if (unlikely(rc)) { |
| 5397 | rc = -EIO; |
| 5398 | goto out_free_mbox; |
| 5399 | } |
| 5400 | |
| 5401 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5402 | if (bf_get(lpfc_mbox_hdr_status, |
| 5403 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5404 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5405 | "2919 Failed to release resource extents " |
| 5406 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5407 | "Resource memory not released.\n", |
| 5408 | type, |
| 5409 | bf_get(lpfc_mbox_hdr_status, |
| 5410 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5411 | bf_get(lpfc_mbox_hdr_add_status, |
| 5412 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5413 | rc = -EIO; |
| 5414 | goto out_free_mbox; |
| 5415 | } |
| 5416 | |
| 5417 | /* Release kernel memory resources for the specific type. */ |
| 5418 | switch (type) { |
| 5419 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5420 | kfree(phba->vpi_bmask); |
| 5421 | kfree(phba->vpi_ids); |
| 5422 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5423 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5424 | &phba->lpfc_vpi_blk_list, list) { |
| 5425 | list_del_init(&rsrc_blk->list); |
| 5426 | kfree(rsrc_blk); |
| 5427 | } |
| 5428 | break; |
| 5429 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5430 | kfree(phba->sli4_hba.xri_bmask); |
| 5431 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5432 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5433 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5434 | list_del_init(&rsrc_blk->list); |
| 5435 | kfree(rsrc_blk); |
| 5436 | } |
| 5437 | break; |
| 5438 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5439 | kfree(phba->sli4_hba.vfi_bmask); |
| 5440 | kfree(phba->sli4_hba.vfi_ids); |
| 5441 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5442 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5443 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5444 | list_del_init(&rsrc_blk->list); |
| 5445 | kfree(rsrc_blk); |
| 5446 | } |
| 5447 | break; |
| 5448 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5449 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5450 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5451 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5452 | list_del_init(&rsrc_blk->list); |
| 5453 | kfree(rsrc_blk); |
| 5454 | } |
| 5455 | break; |
| 5456 | default: |
| 5457 | break; |
| 5458 | } |
| 5459 | |
| 5460 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5461 | |
| 5462 | out_free_mbox: |
| 5463 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5464 | return rc; |
| 5465 | } |
| 5466 | |
| 5467 | /** |
| 5468 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5469 | * @phba: Pointer to HBA context object. |
| 5470 | * |
| 5471 | * This function allocates all SLI4 resource identifiers. |
| 5472 | **/ |
| 5473 | int |
| 5474 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5475 | { |
| 5476 | int i, rc, error = 0; |
| 5477 | uint16_t count, base; |
| 5478 | unsigned long longs; |
| 5479 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5480 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5481 | 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] | 5482 | if (phba->sli4_hba.extents_in_use) { |
| 5483 | /* |
| 5484 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5485 | * resource extent count must be read and allocated before |
| 5486 | * provisioning the resource id arrays. |
| 5487 | */ |
| 5488 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5489 | LPFC_IDX_RSRC_RDY) { |
| 5490 | /* |
| 5491 | * Extent-based resources are set - the driver could |
| 5492 | * be in a port reset. Figure out if any corrective |
| 5493 | * actions need to be taken. |
| 5494 | */ |
| 5495 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5496 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5497 | if (rc != 0) |
| 5498 | error++; |
| 5499 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5500 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5501 | if (rc != 0) |
| 5502 | error++; |
| 5503 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5504 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5505 | if (rc != 0) |
| 5506 | error++; |
| 5507 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5508 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5509 | if (rc != 0) |
| 5510 | error++; |
| 5511 | |
| 5512 | /* |
| 5513 | * It's possible that the number of resources |
| 5514 | * provided to this port instance changed between |
| 5515 | * resets. Detect this condition and reallocate |
| 5516 | * resources. Otherwise, there is no action. |
| 5517 | */ |
| 5518 | if (error) { |
| 5519 | lpfc_printf_log(phba, KERN_INFO, |
| 5520 | LOG_MBOX | LOG_INIT, |
| 5521 | "2931 Detected extent resource " |
| 5522 | "change. Reallocating all " |
| 5523 | "extents.\n"); |
| 5524 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5525 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5526 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5527 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5528 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5529 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5530 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5531 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5532 | } else |
| 5533 | return 0; |
| 5534 | } |
| 5535 | |
| 5536 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5537 | if (unlikely(rc)) |
| 5538 | goto err_exit; |
| 5539 | |
| 5540 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5541 | if (unlikely(rc)) |
| 5542 | goto err_exit; |
| 5543 | |
| 5544 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5545 | if (unlikely(rc)) |
| 5546 | goto err_exit; |
| 5547 | |
| 5548 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5549 | if (unlikely(rc)) |
| 5550 | goto err_exit; |
| 5551 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5552 | LPFC_IDX_RSRC_RDY); |
| 5553 | return rc; |
| 5554 | } else { |
| 5555 | /* |
| 5556 | * The port does not support resource extents. The XRI, VPI, |
| 5557 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5558 | * Just allocate the bitmasks and provision the resource id |
| 5559 | * arrays. If a port reset is active, the resources don't |
| 5560 | * need any action - just exit. |
| 5561 | */ |
| 5562 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5563 | LPFC_IDX_RSRC_RDY) { |
| 5564 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5565 | lpfc_sli4_remove_rpis(phba); |
| 5566 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5567 | /* RPIs. */ |
| 5568 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
| 5569 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5570 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5571 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5572 | sizeof(unsigned long), |
| 5573 | GFP_KERNEL); |
| 5574 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5575 | rc = -ENOMEM; |
| 5576 | goto err_exit; |
| 5577 | } |
| 5578 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5579 | sizeof(uint16_t), |
| 5580 | GFP_KERNEL); |
| 5581 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5582 | rc = -ENOMEM; |
| 5583 | goto free_rpi_bmask; |
| 5584 | } |
| 5585 | |
| 5586 | for (i = 0; i < count; i++) |
| 5587 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5588 | |
| 5589 | /* VPIs. */ |
| 5590 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
| 5591 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5592 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5593 | phba->vpi_bmask = kzalloc(longs * |
| 5594 | sizeof(unsigned long), |
| 5595 | GFP_KERNEL); |
| 5596 | if (unlikely(!phba->vpi_bmask)) { |
| 5597 | rc = -ENOMEM; |
| 5598 | goto free_rpi_ids; |
| 5599 | } |
| 5600 | phba->vpi_ids = kzalloc(count * |
| 5601 | sizeof(uint16_t), |
| 5602 | GFP_KERNEL); |
| 5603 | if (unlikely(!phba->vpi_ids)) { |
| 5604 | rc = -ENOMEM; |
| 5605 | goto free_vpi_bmask; |
| 5606 | } |
| 5607 | |
| 5608 | for (i = 0; i < count; i++) |
| 5609 | phba->vpi_ids[i] = base + i; |
| 5610 | |
| 5611 | /* XRIs. */ |
| 5612 | count = phba->sli4_hba.max_cfg_param.max_xri; |
| 5613 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5614 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5615 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5616 | sizeof(unsigned long), |
| 5617 | GFP_KERNEL); |
| 5618 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5619 | rc = -ENOMEM; |
| 5620 | goto free_vpi_ids; |
| 5621 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5622 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5623 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5624 | sizeof(uint16_t), |
| 5625 | GFP_KERNEL); |
| 5626 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5627 | rc = -ENOMEM; |
| 5628 | goto free_xri_bmask; |
| 5629 | } |
| 5630 | |
| 5631 | for (i = 0; i < count; i++) |
| 5632 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5633 | |
| 5634 | /* VFIs. */ |
| 5635 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
| 5636 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5637 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5638 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5639 | sizeof(unsigned long), |
| 5640 | GFP_KERNEL); |
| 5641 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5642 | rc = -ENOMEM; |
| 5643 | goto free_xri_ids; |
| 5644 | } |
| 5645 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5646 | sizeof(uint16_t), |
| 5647 | GFP_KERNEL); |
| 5648 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5649 | rc = -ENOMEM; |
| 5650 | goto free_vfi_bmask; |
| 5651 | } |
| 5652 | |
| 5653 | for (i = 0; i < count; i++) |
| 5654 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5655 | |
| 5656 | /* |
| 5657 | * Mark all resources ready. An HBA reset doesn't need |
| 5658 | * to reset the initialization. |
| 5659 | */ |
| 5660 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5661 | LPFC_IDX_RSRC_RDY); |
| 5662 | return 0; |
| 5663 | } |
| 5664 | |
| 5665 | free_vfi_bmask: |
| 5666 | kfree(phba->sli4_hba.vfi_bmask); |
| 5667 | free_xri_ids: |
| 5668 | kfree(phba->sli4_hba.xri_ids); |
| 5669 | free_xri_bmask: |
| 5670 | kfree(phba->sli4_hba.xri_bmask); |
| 5671 | free_vpi_ids: |
| 5672 | kfree(phba->vpi_ids); |
| 5673 | free_vpi_bmask: |
| 5674 | kfree(phba->vpi_bmask); |
| 5675 | free_rpi_ids: |
| 5676 | kfree(phba->sli4_hba.rpi_ids); |
| 5677 | free_rpi_bmask: |
| 5678 | kfree(phba->sli4_hba.rpi_bmask); |
| 5679 | err_exit: |
| 5680 | return rc; |
| 5681 | } |
| 5682 | |
| 5683 | /** |
| 5684 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5685 | * @phba: Pointer to HBA context object. |
| 5686 | * |
| 5687 | * This function allocates the number of elements for the specified |
| 5688 | * resource type. |
| 5689 | **/ |
| 5690 | int |
| 5691 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5692 | { |
| 5693 | if (phba->sli4_hba.extents_in_use) { |
| 5694 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5695 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5696 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5697 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5698 | } else { |
| 5699 | kfree(phba->vpi_bmask); |
| 5700 | kfree(phba->vpi_ids); |
| 5701 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5702 | kfree(phba->sli4_hba.xri_bmask); |
| 5703 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5704 | kfree(phba->sli4_hba.vfi_bmask); |
| 5705 | kfree(phba->sli4_hba.vfi_ids); |
| 5706 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5707 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5708 | } |
| 5709 | |
| 5710 | return 0; |
| 5711 | } |
| 5712 | |
| 5713 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5714 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5715 | * @phba: Pointer to HBA context object. |
| 5716 | * @type: The resource extent type. |
| 5717 | * @extnt_count: buffer to hold port extent count response |
| 5718 | * @extnt_size: buffer to hold port extent size response. |
| 5719 | * |
| 5720 | * This function calls the port to read the host allocated extents |
| 5721 | * for a particular type. |
| 5722 | **/ |
| 5723 | int |
| 5724 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5725 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5726 | { |
| 5727 | bool emb; |
| 5728 | int rc = 0; |
| 5729 | uint16_t curr_blks = 0; |
| 5730 | uint32_t req_len, emb_len; |
| 5731 | uint32_t alloc_len, mbox_tmo; |
| 5732 | struct list_head *blk_list_head; |
| 5733 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5734 | LPFC_MBOXQ_t *mbox; |
| 5735 | void *virtaddr = NULL; |
| 5736 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5737 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5738 | union lpfc_sli4_cfg_shdr *shdr; |
| 5739 | |
| 5740 | switch (type) { |
| 5741 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5742 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5743 | break; |
| 5744 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5745 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5746 | break; |
| 5747 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5748 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5749 | break; |
| 5750 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5751 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5752 | break; |
| 5753 | default: |
| 5754 | return -EIO; |
| 5755 | } |
| 5756 | |
| 5757 | /* Count the number of extents currently allocatd for this type. */ |
| 5758 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5759 | if (curr_blks == 0) { |
| 5760 | /* |
| 5761 | * The GET_ALLOCATED mailbox does not return the size, |
| 5762 | * just the count. The size should be just the size |
| 5763 | * stored in the current allocated block and all sizes |
| 5764 | * for an extent type are the same so set the return |
| 5765 | * value now. |
| 5766 | */ |
| 5767 | *extnt_size = rsrc_blk->rsrc_size; |
| 5768 | } |
| 5769 | curr_blks++; |
| 5770 | } |
| 5771 | |
| 5772 | /* Calculate the total requested length of the dma memory. */ |
| 5773 | req_len = curr_blks * sizeof(uint16_t); |
| 5774 | |
| 5775 | /* |
| 5776 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5777 | * accounts for extents-specific word. |
| 5778 | */ |
| 5779 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5780 | sizeof(uint32_t); |
| 5781 | |
| 5782 | /* |
| 5783 | * Presume the allocation and response will fit into an embedded |
| 5784 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5785 | */ |
| 5786 | emb = LPFC_SLI4_MBX_EMBED; |
| 5787 | req_len = emb_len; |
| 5788 | if (req_len > emb_len) { |
| 5789 | req_len = curr_blks * sizeof(uint16_t) + |
| 5790 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5791 | sizeof(uint32_t); |
| 5792 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5793 | } |
| 5794 | |
| 5795 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5796 | if (!mbox) |
| 5797 | return -ENOMEM; |
| 5798 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5799 | |
| 5800 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5801 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5802 | req_len, emb); |
| 5803 | if (alloc_len < req_len) { |
| 5804 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5805 | "2983 Allocated DMA memory size (x%x) is " |
| 5806 | "less than the requested DMA memory " |
| 5807 | "size (x%x)\n", alloc_len, req_len); |
| 5808 | rc = -ENOMEM; |
| 5809 | goto err_exit; |
| 5810 | } |
| 5811 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5812 | if (unlikely(rc)) { |
| 5813 | rc = -EIO; |
| 5814 | goto err_exit; |
| 5815 | } |
| 5816 | |
| 5817 | if (!phba->sli4_hba.intr_enable) |
| 5818 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5819 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5820 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5821 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5822 | } |
| 5823 | |
| 5824 | if (unlikely(rc)) { |
| 5825 | rc = -EIO; |
| 5826 | goto err_exit; |
| 5827 | } |
| 5828 | |
| 5829 | /* |
| 5830 | * Figure out where the response is located. Then get local pointers |
| 5831 | * to the response data. The port does not guarantee to respond to |
| 5832 | * all extents counts request so update the local variable with the |
| 5833 | * allocated count from the port. |
| 5834 | */ |
| 5835 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5836 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5837 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5838 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5839 | } else { |
| 5840 | virtaddr = mbox->sge_array->addr[0]; |
| 5841 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5842 | shdr = &n_rsrc->cfg_shdr; |
| 5843 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5844 | } |
| 5845 | |
| 5846 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5847 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5848 | "2984 Failed to read allocated resources " |
| 5849 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5850 | type, |
| 5851 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5852 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5853 | rc = -EIO; |
| 5854 | goto err_exit; |
| 5855 | } |
| 5856 | err_exit: |
| 5857 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5858 | return rc; |
| 5859 | } |
| 5860 | |
| 5861 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5862 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5863 | * @phba: pointer to lpfc hba data structure. |
| 5864 | * |
| 5865 | * This routine walks the list of els buffers that have been allocated and |
| 5866 | * repost them to the port by using SGL block post. This is needed after a |
| 5867 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5868 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5869 | * SGL block post mailbox commands to post them to the port. For single els |
| 5870 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5871 | * mailbox command for posting. |
| 5872 | * |
| 5873 | * Returns: 0 = success, non-zero failure. |
| 5874 | **/ |
| 5875 | static int |
| 5876 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5877 | { |
| 5878 | struct lpfc_sglq *sglq_entry = NULL; |
| 5879 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5880 | struct lpfc_sglq *sglq_entry_first = NULL; |
| 5881 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; |
| 5882 | int last_xritag = NO_XRI; |
| 5883 | LIST_HEAD(prep_sgl_list); |
| 5884 | LIST_HEAD(blck_sgl_list); |
| 5885 | LIST_HEAD(allc_sgl_list); |
| 5886 | LIST_HEAD(post_sgl_list); |
| 5887 | LIST_HEAD(free_sgl_list); |
| 5888 | |
| 5889 | spin_lock(&phba->hbalock); |
| 5890 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
| 5891 | spin_unlock(&phba->hbalock); |
| 5892 | |
| 5893 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 5894 | &allc_sgl_list, list) { |
| 5895 | list_del_init(&sglq_entry->list); |
| 5896 | block_cnt++; |
| 5897 | if ((last_xritag != NO_XRI) && |
| 5898 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 5899 | /* a hole in xri block, form a sgl posting block */ |
| 5900 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 5901 | post_cnt = block_cnt - 1; |
| 5902 | /* prepare list for next posting block */ |
| 5903 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5904 | block_cnt = 1; |
| 5905 | } else { |
| 5906 | /* prepare list for next posting block */ |
| 5907 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5908 | /* enough sgls for non-embed sgl mbox command */ |
| 5909 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 5910 | list_splice_init(&prep_sgl_list, |
| 5911 | &blck_sgl_list); |
| 5912 | post_cnt = block_cnt; |
| 5913 | block_cnt = 0; |
| 5914 | } |
| 5915 | } |
| 5916 | num_posted++; |
| 5917 | |
| 5918 | /* keep track of last sgl's xritag */ |
| 5919 | last_xritag = sglq_entry->sli4_xritag; |
| 5920 | |
| 5921 | /* end of repost sgl list condition for els buffers */ |
| 5922 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 5923 | if (post_cnt == 0) { |
| 5924 | list_splice_init(&prep_sgl_list, |
| 5925 | &blck_sgl_list); |
| 5926 | post_cnt = block_cnt; |
| 5927 | } else if (block_cnt == 1) { |
| 5928 | status = lpfc_sli4_post_sgl(phba, |
| 5929 | sglq_entry->phys, 0, |
| 5930 | sglq_entry->sli4_xritag); |
| 5931 | if (!status) { |
| 5932 | /* successful, put sgl to posted list */ |
| 5933 | list_add_tail(&sglq_entry->list, |
| 5934 | &post_sgl_list); |
| 5935 | } else { |
| 5936 | /* Failure, put sgl to free list */ |
| 5937 | lpfc_printf_log(phba, KERN_WARNING, |
| 5938 | LOG_SLI, |
| 5939 | "3159 Failed to post els " |
| 5940 | "sgl, xritag:x%x\n", |
| 5941 | sglq_entry->sli4_xritag); |
| 5942 | list_add_tail(&sglq_entry->list, |
| 5943 | &free_sgl_list); |
| 5944 | spin_lock_irq(&phba->hbalock); |
| 5945 | phba->sli4_hba.els_xri_cnt--; |
| 5946 | spin_unlock_irq(&phba->hbalock); |
| 5947 | } |
| 5948 | } |
| 5949 | } |
| 5950 | |
| 5951 | /* continue until a nembed page worth of sgls */ |
| 5952 | if (post_cnt == 0) |
| 5953 | continue; |
| 5954 | |
| 5955 | /* post the els buffer list sgls as a block */ |
| 5956 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 5957 | post_cnt); |
| 5958 | |
| 5959 | if (!status) { |
| 5960 | /* success, put sgl list to posted sgl list */ |
| 5961 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 5962 | } else { |
| 5963 | /* Failure, put sgl list to free sgl list */ |
| 5964 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 5965 | struct lpfc_sglq, |
| 5966 | list); |
| 5967 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5968 | "3160 Failed to post els sgl-list, " |
| 5969 | "xritag:x%x-x%x\n", |
| 5970 | sglq_entry_first->sli4_xritag, |
| 5971 | (sglq_entry_first->sli4_xritag + |
| 5972 | post_cnt - 1)); |
| 5973 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
| 5974 | spin_lock_irq(&phba->hbalock); |
| 5975 | phba->sli4_hba.els_xri_cnt -= post_cnt; |
| 5976 | spin_unlock_irq(&phba->hbalock); |
| 5977 | } |
| 5978 | |
| 5979 | /* don't reset xirtag due to hole in xri block */ |
| 5980 | if (block_cnt == 0) |
| 5981 | last_xritag = NO_XRI; |
| 5982 | |
| 5983 | /* reset els sgl post count for next round of posting */ |
| 5984 | post_cnt = 0; |
| 5985 | } |
| 5986 | |
| 5987 | /* free the els sgls failed to post */ |
| 5988 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 5989 | |
| 5990 | /* push els sgls posted to the availble list */ |
| 5991 | if (!list_empty(&post_sgl_list)) { |
| 5992 | spin_lock(&phba->hbalock); |
| 5993 | list_splice_init(&post_sgl_list, |
| 5994 | &phba->sli4_hba.lpfc_sgl_list); |
| 5995 | spin_unlock(&phba->hbalock); |
| 5996 | } else { |
| 5997 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5998 | "3161 Failure to post els sgl to port.\n"); |
| 5999 | return -EIO; |
| 6000 | } |
| 6001 | return 0; |
| 6002 | } |
| 6003 | |
| 6004 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6005 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6006 | * @phba: Pointer to HBA context object. |
| 6007 | * |
| 6008 | * This function is the main SLI4 device intialization PCI function. This |
| 6009 | * function is called by the HBA intialization code, HBA reset code and |
| 6010 | * HBA error attention handler code. Caller is not required to hold any |
| 6011 | * locks. |
| 6012 | **/ |
| 6013 | int |
| 6014 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6015 | { |
| 6016 | int rc; |
| 6017 | LPFC_MBOXQ_t *mboxq; |
| 6018 | struct lpfc_mqe *mqe; |
| 6019 | uint8_t *vpd; |
| 6020 | uint32_t vpd_size; |
| 6021 | uint32_t ftr_rsp = 0; |
| 6022 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6023 | struct lpfc_vport *vport = phba->pport; |
| 6024 | struct lpfc_dmabuf *mp; |
| 6025 | |
| 6026 | /* Perform a PCI function reset to start from clean */ |
| 6027 | rc = lpfc_pci_function_reset(phba); |
| 6028 | if (unlikely(rc)) |
| 6029 | return -ENODEV; |
| 6030 | |
| 6031 | /* Check the HBA Host Status Register for readyness */ |
| 6032 | rc = lpfc_sli4_post_status_check(phba); |
| 6033 | if (unlikely(rc)) |
| 6034 | return -ENODEV; |
| 6035 | else { |
| 6036 | spin_lock_irq(&phba->hbalock); |
| 6037 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6038 | spin_unlock_irq(&phba->hbalock); |
| 6039 | } |
| 6040 | |
| 6041 | /* |
| 6042 | * Allocate a single mailbox container for initializing the |
| 6043 | * port. |
| 6044 | */ |
| 6045 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6046 | if (!mboxq) |
| 6047 | return -ENOMEM; |
| 6048 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6049 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6050 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6051 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6052 | if (!vpd) { |
| 6053 | rc = -ENOMEM; |
| 6054 | goto out_free_mbox; |
| 6055 | } |
| 6056 | |
| 6057 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6058 | if (unlikely(rc)) { |
| 6059 | kfree(vpd); |
| 6060 | goto out_free_mbox; |
| 6061 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6062 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6063 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6064 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6065 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6066 | else |
| 6067 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6068 | |
| 6069 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6070 | LPFC_DCBX_CEE_MODE) |
| 6071 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6072 | else |
| 6073 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6074 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6075 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6076 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6077 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6078 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6079 | "0376 READ_REV Error. SLI Level %d " |
| 6080 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6081 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6082 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6083 | kfree(vpd); |
| 6084 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6085 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6086 | |
| 6087 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6088 | * Continue initialization with default values even if driver failed |
| 6089 | * to read FCoE param config regions, only read parameters if the |
| 6090 | * board is FCoE |
| 6091 | */ |
| 6092 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6093 | lpfc_sli4_read_fcoe_params(phba)) |
| 6094 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6095 | "2570 Failed to read FCoE parameters\n"); |
| 6096 | |
| 6097 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6098 | * Retrieve sli4 device physical port name, failure of doing it |
| 6099 | * is considered as non-fatal. |
| 6100 | */ |
| 6101 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6102 | if (!rc) |
| 6103 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6104 | "3080 Successful retrieving SLI4 device " |
| 6105 | "physical port name: %s.\n", phba->Port); |
| 6106 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6107 | /* |
| 6108 | * Evaluate the read rev and vpd data. Populate the driver |
| 6109 | * state with the results. If this routine fails, the failure |
| 6110 | * is not fatal as the driver will use generic values. |
| 6111 | */ |
| 6112 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6113 | if (unlikely(!rc)) { |
| 6114 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6115 | "0377 Error %d parsing vpd. " |
| 6116 | "Using defaults.\n", rc); |
| 6117 | rc = 0; |
| 6118 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6119 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6120 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6121 | /* Save information as VPD data */ |
| 6122 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6123 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6124 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6125 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6126 | &mqe->un.read_rev); |
| 6127 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6128 | &mqe->un.read_rev); |
| 6129 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6130 | &mqe->un.read_rev); |
| 6131 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6132 | &mqe->un.read_rev); |
| 6133 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6134 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6135 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6136 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6137 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6138 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6139 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6140 | "(%d):0380 READ_REV Status x%x " |
| 6141 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6142 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6143 | bf_get(lpfc_mqe_status, mqe), |
| 6144 | phba->vpd.rev.opFwName, |
| 6145 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6146 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6147 | |
| 6148 | /* |
| 6149 | * Discover the port's supported feature set and match it against the |
| 6150 | * hosts requests. |
| 6151 | */ |
| 6152 | lpfc_request_features(phba, mboxq); |
| 6153 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6154 | if (unlikely(rc)) { |
| 6155 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6156 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | /* |
| 6160 | * The port must support FCP initiator mode as this is the |
| 6161 | * only mode running in the host. |
| 6162 | */ |
| 6163 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6164 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6165 | "0378 No support for fcpi mode.\n"); |
| 6166 | ftr_rsp++; |
| 6167 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6168 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6169 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6170 | else |
| 6171 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6172 | /* |
| 6173 | * If the port cannot support the host's requested features |
| 6174 | * then turn off the global config parameters to disable the |
| 6175 | * feature in the driver. This is not a fatal error. |
| 6176 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6177 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6178 | if (phba->cfg_enable_bg) { |
| 6179 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6180 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6181 | else |
| 6182 | ftr_rsp++; |
| 6183 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6184 | |
| 6185 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6186 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6187 | ftr_rsp++; |
| 6188 | |
| 6189 | if (ftr_rsp) { |
| 6190 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6191 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6192 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6193 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6194 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6195 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6196 | phba->cfg_enable_bg = 0; |
| 6197 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6198 | phba->cfg_enable_npiv = 0; |
| 6199 | } |
| 6200 | |
| 6201 | /* These SLI3 features are assumed in SLI4 */ |
| 6202 | spin_lock_irq(&phba->hbalock); |
| 6203 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6204 | spin_unlock_irq(&phba->hbalock); |
| 6205 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6206 | /* |
| 6207 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6208 | * calls depends on these resources to complete port setup. |
| 6209 | */ |
| 6210 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6211 | if (rc) { |
| 6212 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6213 | "2920 Failed to alloc Resource IDs " |
| 6214 | "rc = x%x\n", rc); |
| 6215 | goto out_free_mbox; |
| 6216 | } |
| 6217 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6218 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6219 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6220 | if (rc) { |
| 6221 | phba->link_state = LPFC_HBA_ERROR; |
| 6222 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6223 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6224 | } |
| 6225 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6226 | mboxq->vport = vport; |
| 6227 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6228 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6229 | if (rc == MBX_SUCCESS) { |
| 6230 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6231 | rc = 0; |
| 6232 | } |
| 6233 | |
| 6234 | /* |
| 6235 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6236 | * it to the mbuf pool. |
| 6237 | */ |
| 6238 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6239 | kfree(mp); |
| 6240 | mboxq->context1 = NULL; |
| 6241 | if (unlikely(rc)) { |
| 6242 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6243 | "0382 READ_SPARAM command failed " |
| 6244 | "status %d, mbxStatus x%x\n", |
| 6245 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6246 | phba->link_state = LPFC_HBA_ERROR; |
| 6247 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6248 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6249 | } |
| 6250 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6251 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6252 | |
| 6253 | /* Update the fc_host data structures with new wwn. */ |
| 6254 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6255 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6256 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6257 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6258 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6259 | if (unlikely(rc)) { |
| 6260 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6261 | "1400 Failed to update xri-sgl size and " |
| 6262 | "mapping: %d\n", rc); |
| 6263 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6264 | } |
| 6265 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6266 | /* register the els sgl pool to the port */ |
| 6267 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6268 | if (unlikely(rc)) { |
| 6269 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6270 | "0582 Error %d during els sgl post " |
| 6271 | "operation\n", rc); |
| 6272 | rc = -ENODEV; |
| 6273 | goto out_free_mbox; |
| 6274 | } |
| 6275 | |
| 6276 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6277 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6278 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6279 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6280 | "0383 Error %d during scsi sgl post " |
| 6281 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6282 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6283 | /* A pci function reset will repost them */ |
| 6284 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6285 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | /* Post the rpi header region to the device. */ |
| 6289 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6290 | if (unlikely(rc)) { |
| 6291 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6292 | "0393 Error %d during rpi post operation\n", |
| 6293 | rc); |
| 6294 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6295 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6296 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6297 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6298 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6299 | /* Create all the SLI4 queues */ |
| 6300 | rc = lpfc_sli4_queue_create(phba); |
| 6301 | if (rc) { |
| 6302 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6303 | "3089 Failed to allocate queues\n"); |
| 6304 | rc = -ENODEV; |
| 6305 | goto out_stop_timers; |
| 6306 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6307 | /* Set up all the queues to the device */ |
| 6308 | rc = lpfc_sli4_queue_setup(phba); |
| 6309 | if (unlikely(rc)) { |
| 6310 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6311 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6312 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | /* Arm the CQs and then EQs on device */ |
| 6316 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6317 | |
| 6318 | /* Indicate device interrupt mode */ |
| 6319 | phba->sli4_hba.intr_enable = 1; |
| 6320 | |
| 6321 | /* Allow asynchronous mailbox command to go through */ |
| 6322 | spin_lock_irq(&phba->hbalock); |
| 6323 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6324 | spin_unlock_irq(&phba->hbalock); |
| 6325 | |
| 6326 | /* Post receive buffers to the device */ |
| 6327 | lpfc_sli4_rb_setup(phba); |
| 6328 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6329 | /* Reset HBA FCF states after HBA reset */ |
| 6330 | phba->fcf.fcf_flag = 0; |
| 6331 | phba->fcf.current_rec.flag = 0; |
| 6332 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6333 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6334 | mod_timer(&vport->els_tmofunc, |
| 6335 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6336 | |
| 6337 | /* Start heart beat timer */ |
| 6338 | mod_timer(&phba->hb_tmofunc, |
| 6339 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6340 | phba->hb_outstanding = 0; |
| 6341 | phba->last_completion_time = jiffies; |
| 6342 | |
| 6343 | /* Start error attention (ERATT) polling timer */ |
| 6344 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6345 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6346 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6347 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6348 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6349 | if (!rc) { |
| 6350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6351 | "2829 This device supports " |
| 6352 | "Advanced Error Reporting (AER)\n"); |
| 6353 | spin_lock_irq(&phba->hbalock); |
| 6354 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6355 | spin_unlock_irq(&phba->hbalock); |
| 6356 | } else { |
| 6357 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6358 | "2830 This device does not support " |
| 6359 | "Advanced Error Reporting (AER)\n"); |
| 6360 | phba->cfg_aer_support = 0; |
| 6361 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6362 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6363 | } |
| 6364 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6365 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6366 | /* |
| 6367 | * The FC Port needs to register FCFI (index 0) |
| 6368 | */ |
| 6369 | lpfc_reg_fcfi(phba, mboxq); |
| 6370 | mboxq->vport = phba->pport; |
| 6371 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6372 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6373 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6374 | rc = 0; |
| 6375 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6376 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6377 | |
| 6378 | /* Check if the port is configured to be disabled */ |
| 6379 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6380 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6381 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6382 | /* |
| 6383 | * The port is ready, set the host's link state to LINK_DOWN |
| 6384 | * in preparation for link interrupts. |
| 6385 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6386 | spin_lock_irq(&phba->hbalock); |
| 6387 | phba->link_state = LPFC_LINK_DOWN; |
| 6388 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6389 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6390 | (phba->hba_flag & LINK_DISABLED)) { |
| 6391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6392 | "3103 Adapter Link is disabled.\n"); |
| 6393 | lpfc_down_link(phba, mboxq); |
| 6394 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6395 | if (rc != MBX_SUCCESS) { |
| 6396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6397 | "3104 Adapter failed to issue " |
| 6398 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6399 | goto out_unset_queue; |
| 6400 | } |
| 6401 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6402 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6403 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6404 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6405 | if (rc) |
| 6406 | goto out_unset_queue; |
| 6407 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6408 | } |
| 6409 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6410 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6411 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6412 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6413 | lpfc_sli4_queue_unset(phba); |
| 6414 | out_destroy_queue: |
| 6415 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6416 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6417 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6418 | out_free_mbox: |
| 6419 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6420 | return rc; |
| 6421 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6422 | |
| 6423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6424 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6425 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6426 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6427 | * This is the callback function for mailbox timer. The mailbox |
| 6428 | * timer is armed when a new mailbox command is issued and the timer |
| 6429 | * is deleted when the mailbox complete. The function is called by |
| 6430 | * the kernel timer code when a mailbox does not complete within |
| 6431 | * expected time. This function wakes up the worker thread to |
| 6432 | * process the mailbox timeout and returns. All the processing is |
| 6433 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6434 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6435 | void |
| 6436 | lpfc_mbox_timeout(unsigned long ptr) |
| 6437 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6438 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6439 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6440 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6441 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6442 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6443 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6444 | if (!tmo_posted) |
| 6445 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6446 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6447 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6448 | if (!tmo_posted) |
| 6449 | lpfc_worker_wake_up(phba); |
| 6450 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6451 | } |
| 6452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6453 | |
| 6454 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6455 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6456 | * @phba: Pointer to HBA context object. |
| 6457 | * |
| 6458 | * This function is called from worker thread when a mailbox command times out. |
| 6459 | * The caller is not required to hold any locks. This function will reset the |
| 6460 | * HBA and recover all the pending commands. |
| 6461 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6462 | void |
| 6463 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6464 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6465 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6466 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6467 | struct lpfc_sli *psli = &phba->sli; |
| 6468 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6469 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6470 | /* Check the pmbox pointer first. There is a race condition |
| 6471 | * between the mbox timeout handler getting executed in the |
| 6472 | * worklist and the mailbox actually completing. When this |
| 6473 | * race condition occurs, the mbox_active will be NULL. |
| 6474 | */ |
| 6475 | spin_lock_irq(&phba->hbalock); |
| 6476 | if (pmbox == NULL) { |
| 6477 | lpfc_printf_log(phba, KERN_WARNING, |
| 6478 | LOG_MBOX | LOG_SLI, |
| 6479 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6480 | "exiting\n"); |
| 6481 | spin_unlock_irq(&phba->hbalock); |
| 6482 | return; |
| 6483 | } |
| 6484 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6485 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6487 | "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] | 6488 | mb->mbxCommand, |
| 6489 | phba->pport->port_state, |
| 6490 | phba->sli.sli_flag, |
| 6491 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6492 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6493 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6494 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6495 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6496 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6497 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6498 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6499 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6500 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6501 | spin_lock_irq(&phba->hbalock); |
| 6502 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6503 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6504 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6505 | |
| 6506 | pring = &psli->ring[psli->fcp_ring]; |
| 6507 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6508 | |
| 6509 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6510 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6511 | |
| 6512 | /* Reset the HBA device */ |
| 6513 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6514 | } |
| 6515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6516 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6517 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6518 | * @phba: Pointer to HBA context object. |
| 6519 | * @pmbox: Pointer to mailbox object. |
| 6520 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6521 | * |
| 6522 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6523 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6524 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6525 | * The mailbox command can be submitted in polling mode, in which case |
| 6526 | * this function will wait in a polling loop for the completion of the |
| 6527 | * mailbox. |
| 6528 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6529 | * function will submit the command and returns immediately without waiting |
| 6530 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6531 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6532 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6533 | * mailbox is issued in polling mode and there is already a mailbox |
| 6534 | * pending, then the function will return an error. If the mailbox is issued |
| 6535 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6536 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6537 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6538 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6539 | * return codes the caller owns the mailbox command after the return of |
| 6540 | * the function. |
| 6541 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6542 | static int |
| 6543 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6544 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6545 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6546 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6547 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6548 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6549 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6550 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6551 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6552 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6553 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6554 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6555 | int processing_queue = 0; |
| 6556 | |
| 6557 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6558 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6559 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6560 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6561 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6562 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6563 | return MBX_SUCCESS; |
| 6564 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6565 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6566 | pmbox = lpfc_mbox_get(phba); |
| 6567 | if (!pmbox) { |
| 6568 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6569 | return MBX_SUCCESS; |
| 6570 | } |
| 6571 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6572 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6573 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6574 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6575 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6576 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6577 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6578 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6579 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6580 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6581 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6582 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6583 | } |
| 6584 | } |
| 6585 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6586 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6587 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6588 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6589 | goto out_not_finished; |
| 6590 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6591 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6592 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6593 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6594 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6595 | goto out_not_finished; |
| 6596 | } |
| 6597 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6598 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6599 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6600 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6601 | status = MBX_SUCCESS; |
| 6602 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6603 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6604 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6605 | |
| 6606 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6607 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6608 | "(%d):0311 Mailbox command x%x cannot " |
| 6609 | "issue Data: x%x x%x\n", |
| 6610 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6611 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6612 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6613 | } |
| 6614 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6615 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
| 6616 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6617 | !(hc_copy & HC_MBINT_ENA)) { |
| 6618 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6619 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6620 | "(%d):2528 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 | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6624 | goto out_not_finished; |
| 6625 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6626 | } |
| 6627 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6628 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6629 | /* Polling for a mbox command when another one is already active |
| 6630 | * is not allowed in SLI. Also, the driver must have established |
| 6631 | * SLI2 mode to queue and process multiple mbox commands. |
| 6632 | */ |
| 6633 | |
| 6634 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6635 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6636 | |
| 6637 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6638 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6639 | "(%d):2529 Mailbox command x%x " |
| 6640 | "cannot issue Data: x%x x%x\n", |
| 6641 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6642 | pmbox->u.mb.mbxCommand, |
| 6643 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6644 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6645 | } |
| 6646 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6647 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6648 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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):2530 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 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6659 | /* Another mailbox command is still being processed, queue this |
| 6660 | * command to be processed later. |
| 6661 | */ |
| 6662 | lpfc_mbox_put(phba, pmbox); |
| 6663 | |
| 6664 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6665 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6666 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6667 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6668 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 6669 | mb->mbxCommand, phba->pport->port_state, |
| 6670 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6671 | |
| 6672 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6673 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6674 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6675 | if (pmbox->vport) { |
| 6676 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6677 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6678 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 6679 | (uint32_t)mb->mbxCommand, |
| 6680 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6681 | } |
| 6682 | else { |
| 6683 | lpfc_debugfs_disc_trc(phba->pport, |
| 6684 | LPFC_DISC_TRC_MBOX, |
| 6685 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 6686 | (uint32_t)mb->mbxCommand, |
| 6687 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6688 | } |
| 6689 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6690 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6691 | } |
| 6692 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6693 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6694 | |
| 6695 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6696 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6697 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6698 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6699 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6700 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6701 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6702 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6703 | "(%d):2531 Mailbox command x%x " |
| 6704 | "cannot issue Data: x%x x%x\n", |
| 6705 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6706 | pmbox->u.mb.mbxCommand, |
| 6707 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6708 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6709 | } |
| 6710 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6711 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6712 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6716 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6717 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6718 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6719 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6720 | mb->mbxCommand, phba->pport->port_state, |
| 6721 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6722 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6723 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 6724 | if (pmbox->vport) { |
| 6725 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6726 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6727 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 6728 | (uint32_t)mb->mbxCommand, |
| 6729 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6730 | } |
| 6731 | else { |
| 6732 | lpfc_debugfs_disc_trc(phba->pport, |
| 6733 | LPFC_DISC_TRC_MBOX, |
| 6734 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 6735 | (uint32_t)mb->mbxCommand, |
| 6736 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6737 | } |
| 6738 | } |
| 6739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6740 | psli->slistat.mbox_cmd++; |
| 6741 | evtctr = psli->slistat.mbox_event; |
| 6742 | |
| 6743 | /* next set own bit for the adapter and copy over command word */ |
| 6744 | mb->mbxOwner = OWN_CHIP; |
| 6745 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6746 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6747 | /* Populate mbox extension offset word. */ |
| 6748 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
| 6749 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6750 | = (uint8_t *)phba->mbox_ext |
| 6751 | - (uint8_t *)phba->mbox; |
| 6752 | } |
| 6753 | |
| 6754 | /* Copy the mailbox extension data */ |
| 6755 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6756 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6757 | (uint8_t *)phba->mbox_ext, |
| 6758 | pmbox->in_ext_byte_len); |
| 6759 | } |
| 6760 | /* Copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6761 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6762 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6763 | /* Populate mbox extension offset word. */ |
| 6764 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
| 6765 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6766 | = MAILBOX_HBA_EXT_OFFSET; |
| 6767 | |
| 6768 | /* Copy the mailbox extension data */ |
| 6769 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6770 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6771 | MAILBOX_HBA_EXT_OFFSET, |
| 6772 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6773 | |
| 6774 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6775 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6776 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6777 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6781 | word */ |
| 6782 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 6783 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 6784 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6785 | |
| 6786 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6787 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6788 | to_slim = phba->MBslimaddr; |
| 6789 | writel(ldata, to_slim); |
| 6790 | readl(to_slim); /* flush */ |
| 6791 | |
| 6792 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6793 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6794 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6795 | } |
| 6796 | } |
| 6797 | |
| 6798 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6799 | |
| 6800 | switch (flag) { |
| 6801 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6802 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6803 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6804 | /* Interrupt board to do it */ |
| 6805 | writel(CA_MBATT, phba->CAregaddr); |
| 6806 | readl(phba->CAregaddr); /* flush */ |
| 6807 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6808 | break; |
| 6809 | |
| 6810 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6811 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6812 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6813 | /* Interrupt board to do it */ |
| 6814 | writel(CA_MBATT, phba->CAregaddr); |
| 6815 | readl(phba->CAregaddr); /* flush */ |
| 6816 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6817 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6818 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6819 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6820 | word0 = le32_to_cpu(word0); |
| 6821 | } else { |
| 6822 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6823 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6824 | spin_unlock_irqrestore(&phba->hbalock, |
| 6825 | drvr_flag); |
| 6826 | goto out_not_finished; |
| 6827 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6831 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6832 | spin_unlock_irqrestore(&phba->hbalock, |
| 6833 | drvr_flag); |
| 6834 | goto out_not_finished; |
| 6835 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6836 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6837 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6838 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6839 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6840 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6841 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6842 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6843 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6844 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6845 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6846 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6847 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | /* Check if we took a mbox interrupt while we were |
| 6851 | polling */ |
| 6852 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6853 | && (evtctr != psli->slistat.mbox_event)) |
| 6854 | break; |
| 6855 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6856 | if (i++ > 10) { |
| 6857 | spin_unlock_irqrestore(&phba->hbalock, |
| 6858 | drvr_flag); |
| 6859 | msleep(1); |
| 6860 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6862 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6863 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6864 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6865 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6866 | word0 = le32_to_cpu(word0); |
| 6867 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6868 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6869 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6870 | /* Check real SLIM for any errors */ |
| 6871 | slimword0 = readl(phba->MBslimaddr); |
| 6872 | slimmb = (MAILBOX_t *) & slimword0; |
| 6873 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6874 | && slimmb->mbxStatus) { |
| 6875 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6876 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6877 | word0 = slimword0; |
| 6878 | } |
| 6879 | } |
| 6880 | } else { |
| 6881 | /* First copy command data */ |
| 6882 | word0 = readl(phba->MBslimaddr); |
| 6883 | } |
| 6884 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6885 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6886 | spin_unlock_irqrestore(&phba->hbalock, |
| 6887 | drvr_flag); |
| 6888 | goto out_not_finished; |
| 6889 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6890 | } |
| 6891 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6892 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6893 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6894 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6895 | /* Copy the mailbox extension data */ |
| 6896 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6897 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 6898 | pmbox->context2, |
| 6899 | pmbox->out_ext_byte_len); |
| 6900 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6901 | } else { |
| 6902 | /* First copy command data */ |
| 6903 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 6904 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6905 | /* Copy the mailbox extension data */ |
| 6906 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6907 | lpfc_memcpy_from_slim(pmbox->context2, |
| 6908 | phba->MBslimaddr + |
| 6909 | MAILBOX_HBA_EXT_OFFSET, |
| 6910 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6911 | } |
| 6912 | } |
| 6913 | |
| 6914 | writel(HA_MBATT, phba->HAregaddr); |
| 6915 | readl(phba->HAregaddr); /* flush */ |
| 6916 | |
| 6917 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 6918 | status = mb->mbxStatus; |
| 6919 | } |
| 6920 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6921 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6922 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6923 | |
| 6924 | out_not_finished: |
| 6925 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6926 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6927 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 6928 | } |
| 6929 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6930 | } |
| 6931 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6932 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6933 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 6934 | * @phba: Pointer to HBA context object. |
| 6935 | * |
| 6936 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 6937 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 6938 | * possible outstanding mailbox command before return. |
| 6939 | * |
| 6940 | * Returns: |
| 6941 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 6942 | * the outstanding mailbox command timed out. |
| 6943 | **/ |
| 6944 | static int |
| 6945 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 6946 | { |
| 6947 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6948 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6949 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6950 | |
| 6951 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 6952 | spin_lock_irq(&phba->hbalock); |
| 6953 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6954 | /* Determine how long we might wait for the active mailbox |
| 6955 | * command to be gracefully completed by firmware. |
| 6956 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6957 | if (phba->sli.mbox_active) |
| 6958 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 6959 | phba->sli.mbox_active) * |
| 6960 | 1000) + jiffies; |
| 6961 | spin_unlock_irq(&phba->hbalock); |
| 6962 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6963 | /* Wait for the outstnading mailbox command to complete */ |
| 6964 | while (phba->sli.mbox_active) { |
| 6965 | /* Check active mailbox complete status every 2ms */ |
| 6966 | msleep(2); |
| 6967 | if (time_after(jiffies, timeout)) { |
| 6968 | /* Timeout, marked the outstanding cmd not complete */ |
| 6969 | rc = 1; |
| 6970 | break; |
| 6971 | } |
| 6972 | } |
| 6973 | |
| 6974 | /* Can not cleanly block async mailbox command, fails it */ |
| 6975 | if (rc) { |
| 6976 | spin_lock_irq(&phba->hbalock); |
| 6977 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6978 | spin_unlock_irq(&phba->hbalock); |
| 6979 | } |
| 6980 | return rc; |
| 6981 | } |
| 6982 | |
| 6983 | /** |
| 6984 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 6985 | * @phba: Pointer to HBA context object. |
| 6986 | * |
| 6987 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 6988 | * commands from the driver internal pending mailbox queue. It makes sure |
| 6989 | * that there is no outstanding mailbox command before resuming posting |
| 6990 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 6991 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 6992 | * mailbox command posting. |
| 6993 | **/ |
| 6994 | static void |
| 6995 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 6996 | { |
| 6997 | struct lpfc_sli *psli = &phba->sli; |
| 6998 | |
| 6999 | spin_lock_irq(&phba->hbalock); |
| 7000 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7001 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7002 | spin_unlock_irq(&phba->hbalock); |
| 7003 | return; |
| 7004 | } |
| 7005 | |
| 7006 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7007 | * successful or timeout, after timing-out the outstanding mailbox |
| 7008 | * command shall always be removed, so just unblock posting async |
| 7009 | * mailbox command and resume |
| 7010 | */ |
| 7011 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7012 | spin_unlock_irq(&phba->hbalock); |
| 7013 | |
| 7014 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7015 | lpfc_worker_wake_up(phba); |
| 7016 | } |
| 7017 | |
| 7018 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7019 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7020 | * @phba: Pointer to HBA context object. |
| 7021 | * @mboxq: Pointer to mailbox object. |
| 7022 | * |
| 7023 | * The function posts a mailbox to the port. The mailbox is expected |
| 7024 | * to be comletely filled in and ready for the port to operate on it. |
| 7025 | * This routine executes a synchronous completion operation on the |
| 7026 | * mailbox by polling for its completion. |
| 7027 | * |
| 7028 | * The caller must not be holding any locks when calling this routine. |
| 7029 | * |
| 7030 | * Returns: |
| 7031 | * MBX_SUCCESS - mailbox posted successfully |
| 7032 | * Any of the MBX error values. |
| 7033 | **/ |
| 7034 | static int |
| 7035 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7036 | { |
| 7037 | int rc = MBX_SUCCESS; |
| 7038 | unsigned long iflag; |
| 7039 | uint32_t db_ready; |
| 7040 | uint32_t mcqe_status; |
| 7041 | uint32_t mbx_cmnd; |
| 7042 | unsigned long timeout; |
| 7043 | struct lpfc_sli *psli = &phba->sli; |
| 7044 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7045 | struct lpfc_bmbx_create *mbox_rgn; |
| 7046 | struct dma_address *dma_address; |
| 7047 | struct lpfc_register bmbx_reg; |
| 7048 | |
| 7049 | /* |
| 7050 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7051 | * at a time and there is no queueing provided. |
| 7052 | */ |
| 7053 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7054 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7055 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7056 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7057 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7058 | "cannot issue Data: x%x x%x\n", |
| 7059 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7060 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7061 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7062 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | psli->sli_flag, MBX_POLL); |
| 7064 | return MBXERR_ERROR; |
| 7065 | } |
| 7066 | /* The server grabs the token and owns it until release */ |
| 7067 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7068 | phba->sli.mbox_active = mboxq; |
| 7069 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7070 | |
| 7071 | /* |
| 7072 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7073 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7074 | * the bmbx mailbox region. |
| 7075 | */ |
| 7076 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7077 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7078 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7079 | sizeof(struct lpfc_mqe)); |
| 7080 | |
| 7081 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7082 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7083 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7084 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7085 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7086 | * 1000) + jiffies; |
| 7087 | do { |
| 7088 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7089 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7090 | if (!db_ready) |
| 7091 | msleep(2); |
| 7092 | |
| 7093 | if (time_after(jiffies, timeout)) { |
| 7094 | rc = MBXERR_ERROR; |
| 7095 | goto exit; |
| 7096 | } |
| 7097 | } while (!db_ready); |
| 7098 | |
| 7099 | /* Post the low mailbox dma address to the port. */ |
| 7100 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7101 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7102 | * 1000) + jiffies; |
| 7103 | do { |
| 7104 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7105 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7106 | if (!db_ready) |
| 7107 | msleep(2); |
| 7108 | |
| 7109 | if (time_after(jiffies, timeout)) { |
| 7110 | rc = MBXERR_ERROR; |
| 7111 | goto exit; |
| 7112 | } |
| 7113 | } while (!db_ready); |
| 7114 | |
| 7115 | /* |
| 7116 | * Read the CQ to ensure the mailbox has completed. |
| 7117 | * If so, update the mailbox status so that the upper layers |
| 7118 | * can complete the request normally. |
| 7119 | */ |
| 7120 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7121 | sizeof(struct lpfc_mqe)); |
| 7122 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7123 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7124 | sizeof(struct lpfc_mcqe)); |
| 7125 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7126 | /* |
| 7127 | * When the CQE status indicates a failure and the mailbox status |
| 7128 | * indicates success then copy the CQE status into the mailbox status |
| 7129 | * (and prefix it with x4000). |
| 7130 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7131 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7132 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7133 | bf_set(lpfc_mqe_status, mb, |
| 7134 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7135 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7136 | } else |
| 7137 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7138 | |
| 7139 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7140 | "(%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] | 7141 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7142 | " 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] | 7143 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7144 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7145 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7146 | bf_get(lpfc_mqe_status, mb), |
| 7147 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7148 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7149 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7150 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7151 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7152 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7153 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7154 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7155 | mboxq->mcqe.trailer); |
| 7156 | exit: |
| 7157 | /* We are holding the token, no needed for lock when release */ |
| 7158 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7159 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7160 | phba->sli.mbox_active = NULL; |
| 7161 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7162 | return rc; |
| 7163 | } |
| 7164 | |
| 7165 | /** |
| 7166 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7167 | * @phba: Pointer to HBA context object. |
| 7168 | * @pmbox: Pointer to mailbox object. |
| 7169 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7170 | * |
| 7171 | * This function is called by discovery code and HBA management code to submit |
| 7172 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7173 | * |
| 7174 | * Return codes the caller owns the mailbox command after the return of the |
| 7175 | * function. |
| 7176 | **/ |
| 7177 | static int |
| 7178 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7179 | uint32_t flag) |
| 7180 | { |
| 7181 | struct lpfc_sli *psli = &phba->sli; |
| 7182 | unsigned long iflags; |
| 7183 | int rc; |
| 7184 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7185 | /* dump from issue mailbox command if setup */ |
| 7186 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7187 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7188 | rc = lpfc_mbox_dev_check(phba); |
| 7189 | if (unlikely(rc)) { |
| 7190 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7191 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7192 | "cannot issue Data: x%x x%x\n", |
| 7193 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7194 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7195 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7196 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7197 | psli->sli_flag, flag); |
| 7198 | goto out_not_finished; |
| 7199 | } |
| 7200 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7201 | /* Detect polling mode and jump to a handler */ |
| 7202 | if (!phba->sli4_hba.intr_enable) { |
| 7203 | if (flag == MBX_POLL) |
| 7204 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7205 | else |
| 7206 | rc = -EIO; |
| 7207 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7208 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7209 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7210 | "(x%x/x%x) failure: " |
| 7211 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7212 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7213 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7214 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7215 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7216 | mboxq), |
| 7217 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7218 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7219 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7220 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7221 | bf_get(lpfc_mcqe_ext_status, |
| 7222 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7223 | psli->sli_flag, flag); |
| 7224 | return rc; |
| 7225 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7226 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7227 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7228 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7229 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7230 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7231 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7232 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7233 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7234 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7235 | /* Try to block the asynchronous mailbox posting */ |
| 7236 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7237 | if (!rc) { |
| 7238 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7239 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7240 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7241 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7242 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7243 | "(%d):2597 Sync Mailbox command " |
| 7244 | "x%x (x%x/x%x) failure: " |
| 7245 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7246 | "Data: x%x x%x\n,", |
| 7247 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7248 | mboxq->u.mb.mbxCommand, |
| 7249 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7250 | mboxq), |
| 7251 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7252 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7253 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7254 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7255 | bf_get(lpfc_mcqe_ext_status, |
| 7256 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7257 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7258 | /* Unblock the async mailbox posting afterward */ |
| 7259 | lpfc_sli4_async_mbox_unblock(phba); |
| 7260 | } |
| 7261 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7265 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7266 | if (rc) { |
| 7267 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7268 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7269 | "cannot issue Data: x%x x%x\n", |
| 7270 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7271 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7272 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7273 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7274 | psli->sli_flag, flag); |
| 7275 | goto out_not_finished; |
| 7276 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7277 | |
| 7278 | /* Put the mailbox command to the driver internal FIFO */ |
| 7279 | psli->slistat.mbox_busy++; |
| 7280 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7281 | lpfc_mbox_put(phba, mboxq); |
| 7282 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7283 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7284 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7285 | "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] | 7286 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7287 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7288 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7289 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7290 | phba->pport->port_state, |
| 7291 | psli->sli_flag, MBX_NOWAIT); |
| 7292 | /* Wake up worker thread to transport mailbox command from head */ |
| 7293 | lpfc_worker_wake_up(phba); |
| 7294 | |
| 7295 | return MBX_BUSY; |
| 7296 | |
| 7297 | out_not_finished: |
| 7298 | return MBX_NOT_FINISHED; |
| 7299 | } |
| 7300 | |
| 7301 | /** |
| 7302 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7303 | * @phba: Pointer to HBA context object. |
| 7304 | * |
| 7305 | * This function is called by worker thread to send a mailbox command to |
| 7306 | * SLI4 HBA firmware. |
| 7307 | * |
| 7308 | **/ |
| 7309 | int |
| 7310 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7311 | { |
| 7312 | struct lpfc_sli *psli = &phba->sli; |
| 7313 | LPFC_MBOXQ_t *mboxq; |
| 7314 | int rc = MBX_SUCCESS; |
| 7315 | unsigned long iflags; |
| 7316 | struct lpfc_mqe *mqe; |
| 7317 | uint32_t mbx_cmnd; |
| 7318 | |
| 7319 | /* Check interrupt mode before post async mailbox command */ |
| 7320 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7321 | return MBX_NOT_FINISHED; |
| 7322 | |
| 7323 | /* Check for mailbox command service token */ |
| 7324 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7325 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7326 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7327 | return MBX_NOT_FINISHED; |
| 7328 | } |
| 7329 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7330 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7331 | return MBX_NOT_FINISHED; |
| 7332 | } |
| 7333 | if (unlikely(phba->sli.mbox_active)) { |
| 7334 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7335 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7336 | "0384 There is pending active mailbox cmd\n"); |
| 7337 | return MBX_NOT_FINISHED; |
| 7338 | } |
| 7339 | /* Take the mailbox command service token */ |
| 7340 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7341 | |
| 7342 | /* Get the next mailbox command from head of queue */ |
| 7343 | mboxq = lpfc_mbox_get(phba); |
| 7344 | |
| 7345 | /* If no more mailbox command waiting for post, we're done */ |
| 7346 | if (!mboxq) { |
| 7347 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7348 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7349 | return MBX_SUCCESS; |
| 7350 | } |
| 7351 | phba->sli.mbox_active = mboxq; |
| 7352 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7353 | |
| 7354 | /* Check device readiness for posting mailbox command */ |
| 7355 | rc = lpfc_mbox_dev_check(phba); |
| 7356 | if (unlikely(rc)) |
| 7357 | /* Driver clean routine will clean up pending mailbox */ |
| 7358 | goto out_not_finished; |
| 7359 | |
| 7360 | /* Prepare the mbox command to be posted */ |
| 7361 | mqe = &mboxq->u.mqe; |
| 7362 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7363 | |
| 7364 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7365 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7366 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7367 | |
| 7368 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7369 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7370 | "x%x x%x\n", |
| 7371 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7372 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7373 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7374 | phba->pport->port_state, psli->sli_flag); |
| 7375 | |
| 7376 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7377 | if (mboxq->vport) { |
| 7378 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7379 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7380 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7381 | mbx_cmnd, mqe->un.mb_words[0], |
| 7382 | mqe->un.mb_words[1]); |
| 7383 | } else { |
| 7384 | lpfc_debugfs_disc_trc(phba->pport, |
| 7385 | LPFC_DISC_TRC_MBOX, |
| 7386 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7387 | mbx_cmnd, mqe->un.mb_words[0], |
| 7388 | mqe->un.mb_words[1]); |
| 7389 | } |
| 7390 | } |
| 7391 | psli->slistat.mbox_cmd++; |
| 7392 | |
| 7393 | /* Post the mailbox command to the port */ |
| 7394 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7395 | if (rc != MBX_SUCCESS) { |
| 7396 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7397 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7398 | "cannot issue Data: x%x x%x\n", |
| 7399 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7400 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7401 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7402 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7403 | psli->sli_flag, MBX_NOWAIT); |
| 7404 | goto out_not_finished; |
| 7405 | } |
| 7406 | |
| 7407 | return rc; |
| 7408 | |
| 7409 | out_not_finished: |
| 7410 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7411 | if (phba->sli.mbox_active) { |
| 7412 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7413 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7414 | /* Release the token */ |
| 7415 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7416 | phba->sli.mbox_active = NULL; |
| 7417 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7418 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7419 | |
| 7420 | return MBX_NOT_FINISHED; |
| 7421 | } |
| 7422 | |
| 7423 | /** |
| 7424 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7425 | * @phba: Pointer to HBA context object. |
| 7426 | * @pmbox: Pointer to mailbox object. |
| 7427 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7428 | * |
| 7429 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7430 | * the API jump table function pointer from the lpfc_hba struct. |
| 7431 | * |
| 7432 | * Return codes the caller owns the mailbox command after the return of the |
| 7433 | * function. |
| 7434 | **/ |
| 7435 | int |
| 7436 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7437 | { |
| 7438 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7439 | } |
| 7440 | |
| 7441 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7442 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7443 | * @phba: The hba struct for which this call is being executed. |
| 7444 | * @dev_grp: The HBA PCI-Device group number. |
| 7445 | * |
| 7446 | * This routine sets up the mbox interface API function jump table in @phba |
| 7447 | * struct. |
| 7448 | * Returns: 0 - success, -ENODEV - failure. |
| 7449 | **/ |
| 7450 | int |
| 7451 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7452 | { |
| 7453 | |
| 7454 | switch (dev_grp) { |
| 7455 | case LPFC_PCI_DEV_LP: |
| 7456 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7457 | phba->lpfc_sli_handle_slow_ring_event = |
| 7458 | lpfc_sli_handle_slow_ring_event_s3; |
| 7459 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7460 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7461 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7462 | break; |
| 7463 | case LPFC_PCI_DEV_OC: |
| 7464 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7465 | phba->lpfc_sli_handle_slow_ring_event = |
| 7466 | lpfc_sli_handle_slow_ring_event_s4; |
| 7467 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7468 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7469 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7470 | break; |
| 7471 | default: |
| 7472 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7473 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7474 | dev_grp); |
| 7475 | return -ENODEV; |
| 7476 | break; |
| 7477 | } |
| 7478 | return 0; |
| 7479 | } |
| 7480 | |
| 7481 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7482 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7483 | * @phba: Pointer to HBA context object. |
| 7484 | * @pring: Pointer to driver SLI ring object. |
| 7485 | * @piocb: Pointer to address of newly added command iocb. |
| 7486 | * |
| 7487 | * This function is called with hbalock held to add a command |
| 7488 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7489 | * to the ring. |
| 7490 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7491 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7492 | __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] | 7493 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7494 | { |
| 7495 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7496 | list_add_tail(&piocb->list, &pring->txq); |
| 7497 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7498 | } |
| 7499 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7500 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7501 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7502 | * @phba: Pointer to HBA context object. |
| 7503 | * @pring: Pointer to driver SLI ring object. |
| 7504 | * @piocb: Pointer to address of newly added command iocb. |
| 7505 | * |
| 7506 | * This function is called with hbalock held before a new |
| 7507 | * iocb is submitted to the firmware. This function checks |
| 7508 | * txq to flush the iocbs in txq to Firmware before |
| 7509 | * submitting new iocbs to the Firmware. |
| 7510 | * If there are iocbs in the txq which need to be submitted |
| 7511 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7512 | * of the txq after dequeuing it from txq. |
| 7513 | * If there is no iocb in the txq then the function will return |
| 7514 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7515 | * *piocb to find if there are more commands in the txq. |
| 7516 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7517 | static struct lpfc_iocbq * |
| 7518 | 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] | 7519 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7520 | { |
| 7521 | struct lpfc_iocbq * nextiocb; |
| 7522 | |
| 7523 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7524 | if (!nextiocb) { |
| 7525 | nextiocb = *piocb; |
| 7526 | *piocb = NULL; |
| 7527 | } |
| 7528 | |
| 7529 | return nextiocb; |
| 7530 | } |
| 7531 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7532 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7533 | * __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] | 7534 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7535 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7536 | * @piocb: Pointer to command iocb. |
| 7537 | * @flag: Flag indicating if this command can be put into txq. |
| 7538 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7539 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7540 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7541 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7542 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7543 | * this function allows only iocbs for posting buffers. This function finds |
| 7544 | * next available slot in the command ring and posts the command to the |
| 7545 | * available slot and writes the port attention register to request HBA start |
| 7546 | * processing new iocb. If there is no slot available in the ring and |
| 7547 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7548 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7549 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7550 | * This function is called with hbalock held. The function will return success |
| 7551 | * after it successfully submit the iocb to firmware or after adding to the |
| 7552 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7553 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7554 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7555 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7556 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7557 | { |
| 7558 | struct lpfc_iocbq *nextiocb; |
| 7559 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7560 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7561 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7562 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7563 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7564 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7565 | lpfc_printf_log(phba, KERN_ERR, |
| 7566 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7567 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7568 | piocb->iocb.ulpCommand); |
| 7569 | dump_stack(); |
| 7570 | return IOCB_ERROR; |
| 7571 | } |
| 7572 | |
| 7573 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7574 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7575 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7576 | return IOCB_ERROR; |
| 7577 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7578 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7579 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7580 | return IOCB_ERROR; |
| 7581 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7582 | /* |
| 7583 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7584 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7585 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7586 | return IOCB_ERROR; |
| 7587 | |
| 7588 | /* |
| 7589 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7590 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7591 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7592 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7593 | goto iocb_busy; |
| 7594 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7595 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7596 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7597 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7598 | * can be issued if the link is not up. |
| 7599 | */ |
| 7600 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7601 | case CMD_GEN_REQUEST64_CR: |
| 7602 | case CMD_GEN_REQUEST64_CX: |
| 7603 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7604 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7605 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7606 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7607 | MENLO_TRANSPORT_TYPE)) |
| 7608 | |
| 7609 | goto iocb_busy; |
| 7610 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7611 | case CMD_QUE_RING_BUF_CN: |
| 7612 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7613 | /* |
| 7614 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7615 | * completion, iocb_cmpl MUST be 0. |
| 7616 | */ |
| 7617 | if (piocb->iocb_cmpl) |
| 7618 | piocb->iocb_cmpl = NULL; |
| 7619 | /*FALLTHROUGH*/ |
| 7620 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7621 | case CMD_CLOSE_XRI_CN: |
| 7622 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7623 | break; |
| 7624 | default: |
| 7625 | goto iocb_busy; |
| 7626 | } |
| 7627 | |
| 7628 | /* |
| 7629 | * For FCP commands, we must be in a state where we can process link |
| 7630 | * attention events. |
| 7631 | */ |
| 7632 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7633 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7634 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7635 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7636 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7637 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7638 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7639 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7640 | |
| 7641 | if (iocb) |
| 7642 | lpfc_sli_update_ring(phba, pring); |
| 7643 | else |
| 7644 | lpfc_sli_update_full_ring(phba, pring); |
| 7645 | |
| 7646 | if (!piocb) |
| 7647 | return IOCB_SUCCESS; |
| 7648 | |
| 7649 | goto out_busy; |
| 7650 | |
| 7651 | iocb_busy: |
| 7652 | pring->stats.iocb_cmd_delay++; |
| 7653 | |
| 7654 | out_busy: |
| 7655 | |
| 7656 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7657 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7658 | return IOCB_SUCCESS; |
| 7659 | } |
| 7660 | |
| 7661 | return IOCB_BUSY; |
| 7662 | } |
| 7663 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7664 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7665 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7666 | * @phba: Pointer to HBA context object. |
| 7667 | * @piocb: Pointer to command iocb. |
| 7668 | * @sglq: Pointer to the scatter gather queue object. |
| 7669 | * |
| 7670 | * This routine converts the bpl or bde that is in the IOCB |
| 7671 | * to a sgl list for the sli4 hardware. The physical address |
| 7672 | * of the bpl/bde is converted back to a virtual address. |
| 7673 | * If the IOCB contains a BPL then the list of BDE's is |
| 7674 | * converted to sli4_sge's. If the IOCB contains a single |
| 7675 | * BDE then it is converted to a single sli_sge. |
| 7676 | * The IOCB is still in cpu endianess so the contents of |
| 7677 | * the bpl can be used without byte swapping. |
| 7678 | * |
| 7679 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7680 | **/ |
| 7681 | static uint16_t |
| 7682 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7683 | struct lpfc_sglq *sglq) |
| 7684 | { |
| 7685 | uint16_t xritag = NO_XRI; |
| 7686 | struct ulp_bde64 *bpl = NULL; |
| 7687 | struct ulp_bde64 bde; |
| 7688 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7689 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7690 | IOCB_t *icmd; |
| 7691 | int numBdes = 0; |
| 7692 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7693 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7694 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7695 | |
| 7696 | if (!piocbq || !sglq) |
| 7697 | return xritag; |
| 7698 | |
| 7699 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7700 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7701 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7702 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7703 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7704 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7705 | sizeof(struct ulp_bde64); |
| 7706 | /* The addrHigh and addrLow fields within the IOCB |
| 7707 | * have not been byteswapped yet so there is no |
| 7708 | * need to swap them back. |
| 7709 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7710 | if (piocbq->context3) |
| 7711 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7712 | else |
| 7713 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7714 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7715 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7716 | if (!bpl) |
| 7717 | return xritag; |
| 7718 | |
| 7719 | for (i = 0; i < numBdes; i++) { |
| 7720 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7721 | sgl->addr_hi = bpl->addrHigh; |
| 7722 | sgl->addr_lo = bpl->addrLow; |
| 7723 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7724 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7725 | if ((i+1) == numBdes) |
| 7726 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7727 | else |
| 7728 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7729 | /* swap the size field back to the cpu so we |
| 7730 | * can assign it to the sgl. |
| 7731 | */ |
| 7732 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7733 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7734 | /* The offsets in the sgl need to be accumulated |
| 7735 | * separately for the request and reply lists. |
| 7736 | * The request is always first, the reply follows. |
| 7737 | */ |
| 7738 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7739 | /* add up the reply sg entries */ |
| 7740 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7741 | inbound++; |
| 7742 | /* first inbound? reset the offset */ |
| 7743 | if (inbound == 1) |
| 7744 | offset = 0; |
| 7745 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7746 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7747 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7748 | offset += bde.tus.f.bdeSize; |
| 7749 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7750 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7751 | bpl++; |
| 7752 | sgl++; |
| 7753 | } |
| 7754 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7755 | /* The addrHigh and addrLow fields of the BDE have not |
| 7756 | * been byteswapped yet so they need to be swapped |
| 7757 | * before putting them in the sgl. |
| 7758 | */ |
| 7759 | sgl->addr_hi = |
| 7760 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7761 | sgl->addr_lo = |
| 7762 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7763 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7764 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7765 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7766 | sgl->sge_len = |
| 7767 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7768 | } |
| 7769 | return sglq->sli4_xritag; |
| 7770 | } |
| 7771 | |
| 7772 | /** |
| 7773 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7774 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7775 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7776 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7777 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7778 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7779 | * |
| 7780 | * Return: index into SLI4 fast-path FCP queue index. |
| 7781 | **/ |
| 7782 | static uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7783 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7784 | { |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7785 | ++phba->fcp_qidx; |
| 7786 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) |
| 7787 | phba->fcp_qidx = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7788 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7789 | return phba->fcp_qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7790 | } |
| 7791 | |
| 7792 | /** |
| 7793 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7794 | * @phba: Pointer to HBA context object. |
| 7795 | * @piocb: Pointer to command iocb. |
| 7796 | * @wqe: Pointer to the work queue entry. |
| 7797 | * |
| 7798 | * This routine converts the iocb command to its Work Queue Entry |
| 7799 | * equivalent. The wqe pointer should not have any fields set when |
| 7800 | * this routine is called because it will memcpy over them. |
| 7801 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7802 | * wqe. |
| 7803 | * |
| 7804 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7805 | **/ |
| 7806 | static int |
| 7807 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7808 | union lpfc_wqe *wqe) |
| 7809 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7810 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7811 | uint8_t ct = 0; |
| 7812 | uint32_t fip; |
| 7813 | uint32_t abort_tag; |
| 7814 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7815 | uint8_t cmnd; |
| 7816 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7817 | uint16_t abrt_iotag; |
| 7818 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7819 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7820 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7821 | int numBdes, i; |
| 7822 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7823 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7824 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7825 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7826 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7827 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7828 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7829 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7830 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7831 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7832 | command_type = ELS_COMMAND_FIP; |
| 7833 | else |
| 7834 | command_type = ELS_COMMAND_NON_FIP; |
| 7835 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7836 | /* Some of the fields are in the right position already */ |
| 7837 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7838 | abort_tag = (uint32_t) iocbq->iotag; |
| 7839 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7840 | 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] | 7841 | /* words0-2 bpl convert bde */ |
| 7842 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7843 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7844 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7845 | bpl = (struct ulp_bde64 *) |
| 7846 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7847 | if (!bpl) |
| 7848 | return IOCB_ERROR; |
| 7849 | |
| 7850 | /* Should already be byte swapped. */ |
| 7851 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7852 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7853 | /* swap the size field back to the cpu so we |
| 7854 | * can assign it to the sgl. |
| 7855 | */ |
| 7856 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7857 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7858 | total_len = 0; |
| 7859 | for (i = 0; i < numBdes; i++) { |
| 7860 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7861 | total_len += bde.tus.f.bdeSize; |
| 7862 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7863 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7864 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7865 | |
| 7866 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 7867 | cmnd = iocbq->iocb.ulpCommand; |
| 7868 | |
| 7869 | switch (iocbq->iocb.ulpCommand) { |
| 7870 | case CMD_ELS_REQUEST64_CR: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7871 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7872 | if (!iocbq->iocb.ulpLe) { |
| 7873 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7874 | "2007 Only Limited Edition cmd Format" |
| 7875 | " supported 0x%x\n", |
| 7876 | iocbq->iocb.ulpCommand); |
| 7877 | return IOCB_ERROR; |
| 7878 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7879 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7880 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7881 | /* Els_reguest64 has a TMO */ |
| 7882 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 7883 | iocbq->iocb.ulpTimeout); |
| 7884 | /* Need a VF for word 4 set the vf bit*/ |
| 7885 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 7886 | /* And a VFID for word 12 */ |
| 7887 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7888 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7889 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7890 | iocbq->iocb.ulpContext); |
| 7891 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 7892 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7893 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7894 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7895 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 7896 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7897 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7898 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7899 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7900 | &phba->sli4_hba.sli_intf); |
| 7901 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7902 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 7903 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7904 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 7905 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7906 | *pcmd == ELS_CMD_PLOGI)) { |
| 7907 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7908 | bf_set(els_req64_sid, &wqe->els_req, |
| 7909 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7910 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 7911 | !(phba->fc_topology == |
| 7912 | LPFC_TOPOLOGY_LOOP)) |
| 7913 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7914 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7915 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 7916 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 7917 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7918 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 7919 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7920 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 7921 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7922 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7923 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 7924 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7925 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 7926 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 7927 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 7928 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 7929 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 7930 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7931 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7932 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7933 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 7934 | iocbq->iocb.un.ulpWord[3]); |
| 7935 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7936 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7937 | /* The entire sequence is transmitted for this IOCB */ |
| 7938 | xmit_len = total_len; |
| 7939 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7940 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 7941 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7942 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7943 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 7944 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7945 | /* word4 relative_offset memcpy */ |
| 7946 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7947 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 7948 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 7949 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 7950 | LPFC_WQE_IOD_WRITE); |
| 7951 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 7952 | LPFC_WQE_LENLOC_WORD12); |
| 7953 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7954 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 7955 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7956 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7957 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7958 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 7959 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7960 | /* word4 iocb=rsvd wqe=rsvd */ |
| 7961 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 7962 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7963 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7964 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7965 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 7966 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7967 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 7968 | LPFC_WQE_LENLOC_WORD3); |
| 7969 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7970 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7971 | case CMD_FCP_IWRITE64_CR: |
| 7972 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7973 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7974 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7975 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7976 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7977 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 7978 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 7979 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 7980 | iocbq->iocb.ulpFCP2Rcvy); |
| 7981 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 7982 | /* Always open the exchange */ |
| 7983 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7984 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7985 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 7986 | LPFC_WQE_LENLOC_WORD4); |
| 7987 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 7988 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 7989 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 7990 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 7991 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 7992 | } |
| 7993 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7994 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7995 | case CMD_FCP_IREAD64_CR: |
| 7996 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7997 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7998 | wqe->fcp_iread.payload_offset_len = |
| 7999 | xmit_len + sizeof(struct fcp_rsp); |
| 8000 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8001 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8002 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8003 | iocbq->iocb.ulpFCP2Rcvy); |
| 8004 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8005 | /* Always open the exchange */ |
| 8006 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8007 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8008 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8009 | LPFC_WQE_LENLOC_WORD4); |
| 8010 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8011 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8012 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 8013 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 8014 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 8015 | } |
| 8016 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8017 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8018 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8019 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 8020 | wqe->fcp_icmd.rsrvd3 = 0; |
| 8021 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8022 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8023 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8024 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8025 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8026 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8027 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8028 | LPFC_WQE_LENLOC_NONE); |
| 8029 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8030 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8031 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8032 | /* For this command calculate the xmit length of the |
| 8033 | * request bde. |
| 8034 | */ |
| 8035 | xmit_len = 0; |
| 8036 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8037 | sizeof(struct ulp_bde64); |
| 8038 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8039 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8040 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8041 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8042 | xmit_len += bde.tus.f.bdeSize; |
| 8043 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8044 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8045 | wqe->gen_req.request_payload_len = xmit_len; |
| 8046 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8047 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8048 | /* word6 context tag copied in memcpy */ |
| 8049 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8050 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8051 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8052 | "2015 Invalid CT %x command 0x%x\n", |
| 8053 | ct, iocbq->iocb.ulpCommand); |
| 8054 | return IOCB_ERROR; |
| 8055 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8056 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8057 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8058 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8059 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8060 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8061 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8062 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8063 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8064 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8065 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8066 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8067 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8068 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8069 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8070 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8071 | /* word4 */ |
| 8072 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8073 | /* word5 iocb=rsvd wge=did */ |
| 8074 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8075 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8076 | |
| 8077 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8078 | &phba->sli4_hba.sli_intf); |
| 8079 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8080 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8081 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8082 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8083 | iocbq->vport->fc_myDID); |
| 8084 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8085 | bf_set(wqe_els_did, |
| 8086 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8087 | } |
| 8088 | } |
| 8089 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8090 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8091 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8092 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8093 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8094 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8095 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8096 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8097 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8098 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8099 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8100 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8101 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8102 | LPFC_WQE_LENLOC_WORD3); |
| 8103 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8104 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8105 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8106 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8107 | iocbq->context2)->virt); |
| 8108 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8109 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8110 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8111 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8112 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8113 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8114 | phba->vpi_ids[phba->pport->vpi]); |
| 8115 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8116 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8117 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8118 | case CMD_CLOSE_XRI_CN: |
| 8119 | case CMD_ABORT_XRI_CN: |
| 8120 | case CMD_ABORT_XRI_CX: |
| 8121 | /* words 0-2 memcpy should be 0 rserved */ |
| 8122 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8123 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8124 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8125 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8126 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8127 | } else |
| 8128 | fip = 0; |
| 8129 | |
| 8130 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8131 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8132 | * The link is down, or the command was ELS_FIP |
| 8133 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8134 | * on the wire. |
| 8135 | */ |
| 8136 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8137 | else |
| 8138 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8139 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8140 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8141 | wqe->abort_cmd.rsrvd5 = 0; |
| 8142 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8143 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8144 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8145 | /* |
| 8146 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8147 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8148 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8149 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8150 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8151 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8152 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8153 | cmnd = CMD_ABORT_XRI_CX; |
| 8154 | command_type = OTHER_COMMAND; |
| 8155 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8156 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8157 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8158 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8159 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8160 | * we re-construct this WQE here based on information in |
| 8161 | * iocbq from scratch. |
| 8162 | */ |
| 8163 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8164 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8165 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8166 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8167 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8168 | LPFC_ABTS_UNSOL_INT) { |
| 8169 | /* ABTS sent by initiator to CT exchange, the |
| 8170 | * RX_ID field will be filled with the newly |
| 8171 | * allocated responder XRI. |
| 8172 | */ |
| 8173 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8174 | iocbq->sli4_xritag); |
| 8175 | } else { |
| 8176 | /* ABTS sent by responder to CT exchange, the |
| 8177 | * RX_ID field will be filled with the responder |
| 8178 | * RX_ID from ABTS. |
| 8179 | */ |
| 8180 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8181 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8182 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8183 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8184 | 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] | 8185 | |
| 8186 | /* Use CT=VPI */ |
| 8187 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8188 | ndlp->nlp_DID); |
| 8189 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8190 | iocbq->iocb.ulpContext); |
| 8191 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8192 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8193 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8194 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8195 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8196 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8197 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8198 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8199 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8200 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8201 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8202 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8203 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8204 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8205 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8206 | } |
| 8207 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8208 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8209 | case CMD_XRI_ABORTED_CX: |
| 8210 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8211 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8212 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8213 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8214 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8215 | default: |
| 8216 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8217 | "2014 Invalid command 0x%x\n", |
| 8218 | iocbq->iocb.ulpCommand); |
| 8219 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8220 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8221 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8222 | |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8223 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8224 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8225 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8226 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8227 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8228 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8229 | 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] | 8230 | return 0; |
| 8231 | } |
| 8232 | |
| 8233 | /** |
| 8234 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8235 | * @phba: Pointer to HBA context object. |
| 8236 | * @ring_number: SLI ring number to issue iocb on. |
| 8237 | * @piocb: Pointer to command iocb. |
| 8238 | * @flag: Flag indicating if this command can be put into txq. |
| 8239 | * |
| 8240 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8241 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8242 | * |
| 8243 | * This function is called with hbalock held. The function will return success |
| 8244 | * after it successfully submit the iocb to firmware or after adding to the |
| 8245 | * txq. |
| 8246 | **/ |
| 8247 | static int |
| 8248 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8249 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8250 | { |
| 8251 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8252 | union lpfc_wqe wqe; |
| 8253 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8254 | |
| 8255 | if (piocb->sli4_xritag == NO_XRI) { |
| 8256 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8257 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8258 | sglq = NULL; |
| 8259 | else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8260 | if (pring->txq_cnt) { |
| 8261 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8262 | __lpfc_sli_ringtx_put(phba, |
| 8263 | pring, piocb); |
| 8264 | return IOCB_SUCCESS; |
| 8265 | } else { |
| 8266 | return IOCB_BUSY; |
| 8267 | } |
| 8268 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8269 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8270 | if (!sglq) { |
| 8271 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8272 | __lpfc_sli_ringtx_put(phba, |
| 8273 | pring, |
| 8274 | piocb); |
| 8275 | return IOCB_SUCCESS; |
| 8276 | } else |
| 8277 | return IOCB_BUSY; |
| 8278 | } |
| 8279 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8280 | } |
| 8281 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8282 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8283 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8284 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8285 | /* |
| 8286 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8287 | * sglq is on the active list |
| 8288 | */ |
| 8289 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); |
| 8290 | if (!sglq) |
| 8291 | return IOCB_ERROR; |
| 8292 | } |
| 8293 | |
| 8294 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8295 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8296 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8297 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8298 | return IOCB_ERROR; |
| 8299 | } |
| 8300 | |
| 8301 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8302 | return IOCB_ERROR; |
| 8303 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8304 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8305 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8306 | /* |
| 8307 | * For FCP command IOCB, get a new WQ index to distribute |
| 8308 | * WQE across the WQsr. On the other hand, for abort IOCB, |
| 8309 | * it carries the same WQ index to the original command |
| 8310 | * IOCB. |
| 8311 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8312 | if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8313 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8314 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8315 | return IOCB_ERROR; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8316 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8317 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8318 | return IOCB_ERROR; |
| 8319 | } else { |
| 8320 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8321 | return IOCB_ERROR; |
| 8322 | } |
| 8323 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8324 | |
| 8325 | return 0; |
| 8326 | } |
| 8327 | |
| 8328 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8329 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8330 | * |
| 8331 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8332 | * pointer from the lpfc_hba struct. |
| 8333 | * |
| 8334 | * Return codes: |
| 8335 | * IOCB_ERROR - Error |
| 8336 | * IOCB_SUCCESS - Success |
| 8337 | * IOCB_BUSY - Busy |
| 8338 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8339 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8340 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8341 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8342 | { |
| 8343 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8344 | } |
| 8345 | |
| 8346 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8347 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8348 | * @phba: The hba struct for which this call is being executed. |
| 8349 | * @dev_grp: The HBA PCI-Device group number. |
| 8350 | * |
| 8351 | * This routine sets up the SLI interface API function jump table in @phba |
| 8352 | * struct. |
| 8353 | * Returns: 0 - success, -ENODEV - failure. |
| 8354 | **/ |
| 8355 | int |
| 8356 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8357 | { |
| 8358 | |
| 8359 | switch (dev_grp) { |
| 8360 | case LPFC_PCI_DEV_LP: |
| 8361 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8362 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8363 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8364 | case LPFC_PCI_DEV_OC: |
| 8365 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8366 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8367 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8368 | default: |
| 8369 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8370 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8371 | dev_grp); |
| 8372 | return -ENODEV; |
| 8373 | break; |
| 8374 | } |
| 8375 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8376 | return 0; |
| 8377 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8378 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8379 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8380 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8381 | * @phba: Pointer to HBA context object. |
| 8382 | * @pring: Pointer to driver SLI ring object. |
| 8383 | * @piocb: Pointer to command iocb. |
| 8384 | * @flag: Flag indicating if this command can be put into txq. |
| 8385 | * |
| 8386 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8387 | * function. This function gets the hbalock and calls |
| 8388 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8389 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8390 | * functions which do not hold hbalock. |
| 8391 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8392 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8393 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8394 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8395 | { |
| 8396 | unsigned long iflags; |
| 8397 | int rc; |
| 8398 | |
| 8399 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8400 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8401 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8402 | |
| 8403 | return rc; |
| 8404 | } |
| 8405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8407 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8408 | * @phba: Pointer to HBA context object. |
| 8409 | * |
| 8410 | * This function is called while driver attaches with the |
| 8411 | * HBA to setup the extra ring. The extra ring is used |
| 8412 | * only when driver needs to support target mode functionality |
| 8413 | * or IP over FC functionalities. |
| 8414 | * |
| 8415 | * This function is called with no lock held. |
| 8416 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8417 | static int |
| 8418 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8419 | { |
| 8420 | struct lpfc_sli *psli; |
| 8421 | struct lpfc_sli_ring *pring; |
| 8422 | |
| 8423 | psli = &phba->sli; |
| 8424 | |
| 8425 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8426 | |
| 8427 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8428 | pring = &psli->ring[psli->fcp_ring]; |
| 8429 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8430 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8431 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8432 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8433 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8434 | /* and give them to the extra ring */ |
| 8435 | pring = &psli->ring[psli->extra_ring]; |
| 8436 | |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8437 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8438 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8439 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8440 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8441 | |
| 8442 | /* Setup default profile for this ring */ |
| 8443 | pring->iotag_max = 4096; |
| 8444 | pring->num_mask = 1; |
| 8445 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8446 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8447 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8448 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8449 | return 0; |
| 8450 | } |
| 8451 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8452 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
| 8453 | * @vport: pointer to virtual port object. |
| 8454 | * @ndlp: nodelist pointer for the impacted rport. |
| 8455 | * |
| 8456 | * The driver calls this routine in response to a XRI ABORT CQE |
| 8457 | * event from the port. In this event, the driver is required to |
| 8458 | * recover its login to the rport even though its login may be valid |
| 8459 | * from the driver's perspective. The failed ABTS notice from the |
| 8460 | * port indicates the rport is not responding. |
| 8461 | */ |
| 8462 | static void |
| 8463 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8464 | struct lpfc_nodelist *ndlp) |
| 8465 | { |
| 8466 | struct Scsi_Host *shost; |
| 8467 | struct lpfc_hba *phba; |
| 8468 | unsigned long flags = 0; |
| 8469 | |
| 8470 | shost = lpfc_shost_from_vport(vport); |
| 8471 | phba = vport->phba; |
| 8472 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8473 | lpfc_printf_log(phba, KERN_INFO, |
| 8474 | LOG_SLI, "3093 No rport recovery needed. " |
| 8475 | "rport in state 0x%x\n", |
| 8476 | ndlp->nlp_state); |
| 8477 | return; |
| 8478 | } |
| 8479 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8480 | "3094 Start rport recovery on shost id 0x%x " |
| 8481 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8482 | "flags 0x%x\n", |
| 8483 | shost->host_no, ndlp->nlp_DID, |
| 8484 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8485 | ndlp->nlp_flag); |
| 8486 | /* |
| 8487 | * The rport is not responding. Don't attempt ADISC recovery. |
| 8488 | * Remove the FCP-2 flag to force a PLOGI. |
| 8489 | */ |
| 8490 | spin_lock_irqsave(shost->host_lock, flags); |
| 8491 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8492 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8493 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8494 | NLP_EVT_DEVICE_RECOVERY); |
| 8495 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 8496 | spin_lock_irqsave(shost->host_lock, flags); |
| 8497 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 8498 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8499 | lpfc_disc_start(vport); |
| 8500 | } |
| 8501 | |
| 8502 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8503 | * @phba: Pointer to HBA context object. |
| 8504 | * @iocbq: Pointer to iocb object. |
| 8505 | * |
| 8506 | * The async_event handler calls this routine when it receives |
| 8507 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8508 | * this event when an Abort Sequence request to an rport fails |
| 8509 | * twice in succession. The abort could be originated by the |
| 8510 | * driver or by the port. The ABTS could have been for an ELS |
| 8511 | * or FCP IO. The port only generates this event when an ABTS |
| 8512 | * fails to complete after one retry. |
| 8513 | */ |
| 8514 | static void |
| 8515 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8516 | struct lpfc_iocbq *iocbq) |
| 8517 | { |
| 8518 | struct lpfc_nodelist *ndlp = NULL; |
| 8519 | uint16_t rpi = 0, vpi = 0; |
| 8520 | struct lpfc_vport *vport = NULL; |
| 8521 | |
| 8522 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8523 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8524 | rpi = iocbq->iocb.ulpContext; |
| 8525 | |
| 8526 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8527 | "3092 Port generated ABTS async event " |
| 8528 | "on vpi %d rpi %d status 0x%x\n", |
| 8529 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8530 | |
| 8531 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8532 | if (!vport) |
| 8533 | goto err_exit; |
| 8534 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8535 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8536 | goto err_exit; |
| 8537 | |
| 8538 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8539 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8540 | return; |
| 8541 | |
| 8542 | err_exit: |
| 8543 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8544 | "3095 Event Context not found, no " |
| 8545 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8546 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8547 | vpi, rpi); |
| 8548 | } |
| 8549 | |
| 8550 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8551 | * @phba: pointer to HBA context object. |
| 8552 | * @ndlp: nodelist pointer for the impacted rport. |
| 8553 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8554 | * |
| 8555 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8556 | * port. The port generates this event when an abort exchange request to an |
| 8557 | * rport fails twice in succession with no reply. The abort could be originated |
| 8558 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8559 | */ |
| 8560 | void |
| 8561 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8562 | struct lpfc_nodelist *ndlp, |
| 8563 | struct sli4_wcqe_xri_aborted *axri) |
| 8564 | { |
| 8565 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8566 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8567 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8568 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8569 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8570 | "3115 Node Context not found, driver " |
| 8571 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8572 | return; |
| 8573 | } |
| 8574 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8575 | vport = ndlp->vport; |
| 8576 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8577 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8578 | "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] | 8579 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8580 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8581 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8582 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8583 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8584 | /* |
| 8585 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8586 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8587 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8588 | */ |
| 8589 | ext_status = axri->parameter & WCQE_PARAM_MASK; |
| 8590 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8591 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8592 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8593 | } |
| 8594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8595 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8596 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8597 | * @phba: Pointer to HBA context object. |
| 8598 | * @pring: Pointer to driver SLI ring object. |
| 8599 | * @iocbq: Pointer to iocb object. |
| 8600 | * |
| 8601 | * This function is called by the slow ring event handler |
| 8602 | * function when there is an ASYNC event iocb in the ring. |
| 8603 | * This function is called with no lock held. |
| 8604 | * Currently this function handles only temperature related |
| 8605 | * ASYNC events. The function decodes the temperature sensor |
| 8606 | * event message and posts events for the management applications. |
| 8607 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8608 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8609 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8610 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8611 | { |
| 8612 | IOCB_t *icmd; |
| 8613 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8614 | struct temp_event temp_event_data; |
| 8615 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8616 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8617 | |
| 8618 | icmd = &iocbq->iocb; |
| 8619 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8620 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8621 | switch (evt_code) { |
| 8622 | case ASYNC_TEMP_WARN: |
| 8623 | case ASYNC_TEMP_SAFE: |
| 8624 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8625 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8626 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8627 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8628 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8629 | "0347 Adapter is very hot, please take " |
| 8630 | "corrective action. temperature : %d Celsius\n", |
| 8631 | (uint32_t) icmd->ulpContext); |
| 8632 | } else { |
| 8633 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8634 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8635 | "0340 Adapter temperature is OK now. " |
| 8636 | "temperature : %d Celsius\n", |
| 8637 | (uint32_t) icmd->ulpContext); |
| 8638 | } |
| 8639 | |
| 8640 | /* Send temperature change event to applications */ |
| 8641 | shost = lpfc_shost_from_vport(phba->pport); |
| 8642 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8643 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8644 | LPFC_NL_VENDOR_ID); |
| 8645 | break; |
| 8646 | case ASYNC_STATUS_CN: |
| 8647 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8648 | break; |
| 8649 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8650 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8651 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8652 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8653 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8654 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8655 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8656 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8657 | "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] | 8658 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8659 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8660 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8661 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8662 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8663 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8664 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8665 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8666 | } |
| 8667 | |
| 8668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8670 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8671 | * @phba: Pointer to HBA context object. |
| 8672 | * |
| 8673 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8674 | * number of iocbs per ring and iotags. This function is |
| 8675 | * called while driver attach to the HBA and before the |
| 8676 | * interrupts are enabled. So there is no need for locking. |
| 8677 | * |
| 8678 | * This function always returns 0. |
| 8679 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8680 | int |
| 8681 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8682 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8683 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8684 | struct lpfc_sli *psli = &phba->sli; |
| 8685 | struct lpfc_sli_ring *pring; |
| 8686 | |
| 8687 | psli->num_rings = MAX_CONFIGURED_RINGS; |
| 8688 | psli->sli_flag = 0; |
| 8689 | psli->fcp_ring = LPFC_FCP_RING; |
| 8690 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8691 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8692 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8693 | psli->iocbq_lookup = NULL; |
| 8694 | psli->iocbq_lookup_len = 0; |
| 8695 | psli->last_iotag = 0; |
| 8696 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8697 | for (i = 0; i < psli->num_rings; i++) { |
| 8698 | pring = &psli->ring[i]; |
| 8699 | switch (i) { |
| 8700 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8701 | /* numCiocb and numRiocb are used in config_port */ |
| 8702 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8703 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8704 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8705 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8706 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8707 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8708 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8709 | SLI3_IOCB_CMD_SIZE : |
| 8710 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8711 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8712 | SLI3_IOCB_RSP_SIZE : |
| 8713 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8714 | pring->iotag_ctr = 0; |
| 8715 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8716 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8717 | pring->fast_iotag = pring->iotag_max; |
| 8718 | pring->num_mask = 0; |
| 8719 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8720 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8721 | /* numCiocb and numRiocb are used in config_port */ |
| 8722 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8723 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8724 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8725 | SLI3_IOCB_CMD_SIZE : |
| 8726 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8727 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8728 | SLI3_IOCB_RSP_SIZE : |
| 8729 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8730 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8731 | pring->num_mask = 0; |
| 8732 | break; |
| 8733 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8734 | /* numCiocb and numRiocb are used in config_port */ |
| 8735 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8736 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8737 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8738 | SLI3_IOCB_CMD_SIZE : |
| 8739 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8740 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8741 | SLI3_IOCB_RSP_SIZE : |
| 8742 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8743 | pring->fast_iotag = 0; |
| 8744 | pring->iotag_ctr = 0; |
| 8745 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8746 | pring->lpfc_sli_rcv_async_status = |
| 8747 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8748 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8749 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8750 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8751 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8752 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8753 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8754 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8755 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8756 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8757 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8758 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8759 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8760 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8761 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8762 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8763 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8764 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8765 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8766 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8767 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8768 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8769 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8770 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8771 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8772 | lpfc_ct_unsol_event; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8773 | /* abort unsolicited sequence */ |
| 8774 | pring->prt[4].profile = 0; /* Mask 4 */ |
| 8775 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; |
| 8776 | pring->prt[4].type = FC_TYPE_BLS; |
| 8777 | pring->prt[4].lpfc_sli_rcv_unsol_event = |
| 8778 | lpfc_sli4_ct_abort_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8779 | break; |
| 8780 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8781 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8782 | (pring->numRiocb * pring->sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8783 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8784 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8785 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8786 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8787 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8788 | phba->brd_no, totiocbsize, |
| 8789 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8790 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8791 | if (phba->cfg_multi_ring_support == 2) |
| 8792 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8793 | |
| 8794 | return 0; |
| 8795 | } |
| 8796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8798 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8799 | * @phba: Pointer to HBA context object. |
| 8800 | * |
| 8801 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8802 | * ring. This function also initializes ring indices of each ring. |
| 8803 | * This function is called during the initialization of the SLI |
| 8804 | * interface of an HBA. |
| 8805 | * This function is called with no lock held and always returns |
| 8806 | * 1. |
| 8807 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8808 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8809 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8810 | { |
| 8811 | struct lpfc_sli *psli; |
| 8812 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8813 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8814 | |
| 8815 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8816 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8817 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8818 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8819 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8820 | for (i = 0; i < psli->num_rings; i++) { |
| 8821 | pring = &psli->ring[i]; |
| 8822 | pring->ringno = i; |
| 8823 | pring->next_cmdidx = 0; |
| 8824 | pring->local_getidx = 0; |
| 8825 | pring->cmdidx = 0; |
| 8826 | INIT_LIST_HEAD(&pring->txq); |
| 8827 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8828 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8829 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8830 | INIT_LIST_HEAD(&pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8831 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8832 | spin_unlock_irq(&phba->hbalock); |
| 8833 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8834 | } |
| 8835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8836 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8837 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8838 | * @phba: Pointer to HBA context object. |
| 8839 | * |
| 8840 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8841 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8842 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8843 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8844 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8845 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8846 | * pending mailbox command queue from the various clients must be stopped; |
| 8847 | * either the HBA is in a state that it will never works on the outstanding |
| 8848 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8849 | * mailbox command has been completed. |
| 8850 | **/ |
| 8851 | static void |
| 8852 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8853 | { |
| 8854 | LIST_HEAD(completions); |
| 8855 | struct lpfc_sli *psli = &phba->sli; |
| 8856 | LPFC_MBOXQ_t *pmb; |
| 8857 | unsigned long iflag; |
| 8858 | |
| 8859 | /* Flush all the mailbox commands in the mbox system */ |
| 8860 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8861 | /* The pending mailbox command queue */ |
| 8862 | list_splice_init(&phba->sli.mboxq, &completions); |
| 8863 | /* The outstanding active mailbox command */ |
| 8864 | if (psli->mbox_active) { |
| 8865 | list_add_tail(&psli->mbox_active->list, &completions); |
| 8866 | psli->mbox_active = NULL; |
| 8867 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8868 | } |
| 8869 | /* The completed mailbox command queue */ |
| 8870 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 8871 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8872 | |
| 8873 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 8874 | while (!list_empty(&completions)) { |
| 8875 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 8876 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8877 | if (pmb->mbox_cmpl) |
| 8878 | pmb->mbox_cmpl(phba, pmb); |
| 8879 | } |
| 8880 | } |
| 8881 | |
| 8882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8883 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8884 | * @vport: Pointer to virtual port object. |
| 8885 | * |
| 8886 | * lpfc_sli_host_down is called to clean up the resources |
| 8887 | * associated with a vport before destroying virtual |
| 8888 | * port data structures. |
| 8889 | * This function does following operations: |
| 8890 | * - Free discovery resources associated with this virtual |
| 8891 | * port. |
| 8892 | * - Free iocbs associated with this virtual port in |
| 8893 | * the txq. |
| 8894 | * - Send abort for all iocb commands associated with this |
| 8895 | * vport in txcmplq. |
| 8896 | * |
| 8897 | * This function is called with no lock held and always returns 1. |
| 8898 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8899 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8900 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 8901 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8902 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8903 | struct lpfc_hba *phba = vport->phba; |
| 8904 | struct lpfc_sli *psli = &phba->sli; |
| 8905 | struct lpfc_sli_ring *pring; |
| 8906 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8907 | int i; |
| 8908 | unsigned long flags = 0; |
| 8909 | uint16_t prev_pring_flag; |
| 8910 | |
| 8911 | lpfc_cleanup_discovery_resources(vport); |
| 8912 | |
| 8913 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8914 | for (i = 0; i < psli->num_rings; i++) { |
| 8915 | pring = &psli->ring[i]; |
| 8916 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8917 | /* Only slow rings */ |
| 8918 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8919 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8920 | /* Set the lpfc data pending flag */ |
| 8921 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8922 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8923 | /* |
| 8924 | * Error everything on the txq since these iocbs have not been |
| 8925 | * given to the FW yet. |
| 8926 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8927 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 8928 | if (iocb->vport != vport) |
| 8929 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8930 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8931 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | /* Next issue ABTS for everything on the txcmplq */ |
| 8935 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 8936 | list) { |
| 8937 | if (iocb->vport != vport) |
| 8938 | continue; |
| 8939 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 8940 | } |
| 8941 | |
| 8942 | pring->flag = prev_pring_flag; |
| 8943 | } |
| 8944 | |
| 8945 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 8946 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8947 | /* Cancel all the IOCBs from the completions list */ |
| 8948 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8949 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8950 | return 1; |
| 8951 | } |
| 8952 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8953 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8954 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8955 | * @phba: Pointer to HBA context object. |
| 8956 | * |
| 8957 | * This function cleans up all iocb, buffers, mailbox commands |
| 8958 | * while shutting down the HBA. This function is called with no |
| 8959 | * lock held and always returns 1. |
| 8960 | * This function does the following to cleanup driver resources: |
| 8961 | * - Free discovery resources for each virtual port |
| 8962 | * - Cleanup any pending fabric iocbs |
| 8963 | * - Iterate through the iocb txq and free each entry |
| 8964 | * in the list. |
| 8965 | * - Free up any buffer posted to the HBA |
| 8966 | * - Free mailbox commands in the mailbox queue. |
| 8967 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8968 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8969 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8970 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8971 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8972 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8973 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 8974 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8975 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8976 | int i; |
| 8977 | |
| 8978 | /* Shutdown the mailbox command sub-system */ |
| 8979 | lpfc_sli_mbox_sys_shutdown(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8981 | lpfc_hba_down_prep(phba); |
| 8982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8983 | lpfc_fabric_abort_hba(phba); |
| 8984 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8985 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8986 | for (i = 0; i < psli->num_rings; i++) { |
| 8987 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8988 | /* Only slow rings */ |
| 8989 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8990 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8991 | /* Set the lpfc data pending flag */ |
| 8992 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8993 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8994 | |
| 8995 | /* |
| 8996 | * Error everything on the txq since these iocbs have not been |
| 8997 | * given to the FW yet. |
| 8998 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 8999 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9000 | pring->txq_cnt = 0; |
| 9001 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9002 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9003 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9004 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9005 | /* Cancel all the IOCBs from the completions list */ |
| 9006 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9007 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9008 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9009 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9010 | list_splice_init(&phba->elsbuf, &completions); |
| 9011 | phba->elsbuf_cnt = 0; |
| 9012 | phba->elsbuf_prev_cnt = 0; |
| 9013 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9014 | |
| 9015 | while (!list_empty(&completions)) { |
| 9016 | list_remove_head(&completions, buf_ptr, |
| 9017 | struct lpfc_dmabuf, list); |
| 9018 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9019 | kfree(buf_ptr); |
| 9020 | } |
| 9021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9022 | /* Return any active mbox cmds */ |
| 9023 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9024 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9025 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9026 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9027 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9028 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9029 | return 1; |
| 9030 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9031 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9033 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9034 | * @srcp: Source memory pointer. |
| 9035 | * @destp: Destination memory pointer. |
| 9036 | * @cnt: Number of words required to be copied. |
| 9037 | * |
| 9038 | * This function is used for copying data between driver memory |
| 9039 | * and the SLI memory. This function also changes the endianness |
| 9040 | * of each word if native endianness is different from SLI |
| 9041 | * endianness. This function can be called with or without |
| 9042 | * lock. |
| 9043 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9044 | void |
| 9045 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9046 | { |
| 9047 | uint32_t *src = srcp; |
| 9048 | uint32_t *dest = destp; |
| 9049 | uint32_t ldata; |
| 9050 | int i; |
| 9051 | |
| 9052 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9053 | ldata = *src; |
| 9054 | ldata = le32_to_cpu(ldata); |
| 9055 | *dest = ldata; |
| 9056 | src++; |
| 9057 | dest++; |
| 9058 | } |
| 9059 | } |
| 9060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9061 | |
| 9062 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9063 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9064 | * @srcp: Source memory pointer. |
| 9065 | * @destp: Destination memory pointer. |
| 9066 | * @cnt: Number of words required to be copied. |
| 9067 | * |
| 9068 | * This function is used for copying data between a data structure |
| 9069 | * with big endian representation to local endianness. |
| 9070 | * This function can be called with or without lock. |
| 9071 | **/ |
| 9072 | void |
| 9073 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9074 | { |
| 9075 | uint32_t *src = srcp; |
| 9076 | uint32_t *dest = destp; |
| 9077 | uint32_t ldata; |
| 9078 | int i; |
| 9079 | |
| 9080 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9081 | ldata = *src; |
| 9082 | ldata = be32_to_cpu(ldata); |
| 9083 | *dest = ldata; |
| 9084 | src++; |
| 9085 | dest++; |
| 9086 | } |
| 9087 | } |
| 9088 | |
| 9089 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9090 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9091 | * @phba: Pointer to HBA context object. |
| 9092 | * @pring: Pointer to driver SLI ring object. |
| 9093 | * @mp: Pointer to driver buffer object. |
| 9094 | * |
| 9095 | * This function is called with no lock held. |
| 9096 | * It always return zero after adding the buffer to the postbufq |
| 9097 | * buffer list. |
| 9098 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9099 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9100 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9101 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9102 | { |
| 9103 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9104 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9105 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9106 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9107 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9108 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9109 | return 0; |
| 9110 | } |
| 9111 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9112 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9113 | * 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] | 9114 | * @phba: Pointer to HBA context object. |
| 9115 | * |
| 9116 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9117 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9118 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9119 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9120 | * The function returns the allocated tag. The function is called with |
| 9121 | * no locks held. |
| 9122 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9123 | uint32_t |
| 9124 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9125 | { |
| 9126 | spin_lock_irq(&phba->hbalock); |
| 9127 | phba->buffer_tag_count++; |
| 9128 | /* |
| 9129 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9130 | * a tag assigned by HBQ. |
| 9131 | */ |
| 9132 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9133 | spin_unlock_irq(&phba->hbalock); |
| 9134 | return phba->buffer_tag_count; |
| 9135 | } |
| 9136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9137 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9138 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9139 | * @phba: Pointer to HBA context object. |
| 9140 | * @pring: Pointer to driver SLI ring object. |
| 9141 | * @tag: Buffer tag. |
| 9142 | * |
| 9143 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9144 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9145 | * iocb is posted to the response ring with the tag of the buffer. |
| 9146 | * This function searches the pring->postbufq list using the tag |
| 9147 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9148 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9149 | * buffer is returned to the caller else NULL is returned. |
| 9150 | * This function is called with no lock held. |
| 9151 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9152 | struct lpfc_dmabuf * |
| 9153 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9154 | uint32_t tag) |
| 9155 | { |
| 9156 | struct lpfc_dmabuf *mp, *next_mp; |
| 9157 | struct list_head *slp = &pring->postbufq; |
| 9158 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9159 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9160 | spin_lock_irq(&phba->hbalock); |
| 9161 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9162 | if (mp->buffer_tag == tag) { |
| 9163 | list_del_init(&mp->list); |
| 9164 | pring->postbufq_cnt--; |
| 9165 | spin_unlock_irq(&phba->hbalock); |
| 9166 | return mp; |
| 9167 | } |
| 9168 | } |
| 9169 | |
| 9170 | spin_unlock_irq(&phba->hbalock); |
| 9171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9172 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9173 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9174 | pring->ringno, (unsigned long) tag, |
| 9175 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9176 | |
| 9177 | return NULL; |
| 9178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9180 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9181 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9182 | * @phba: Pointer to HBA context object. |
| 9183 | * @pring: Pointer to driver SLI ring object. |
| 9184 | * @phys: DMA address of the buffer. |
| 9185 | * |
| 9186 | * This function searches the buffer list using the dma_address |
| 9187 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9188 | * corresponding to the dma_address. The function returns the |
| 9189 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9190 | * This function is called by the ct and els unsolicited event |
| 9191 | * handlers to get the buffer associated with the unsolicited |
| 9192 | * event. |
| 9193 | * |
| 9194 | * This function is called with no lock held. |
| 9195 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9196 | struct lpfc_dmabuf * |
| 9197 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9198 | dma_addr_t phys) |
| 9199 | { |
| 9200 | struct lpfc_dmabuf *mp, *next_mp; |
| 9201 | struct list_head *slp = &pring->postbufq; |
| 9202 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9203 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9204 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9205 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9206 | if (mp->phys == phys) { |
| 9207 | list_del_init(&mp->list); |
| 9208 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9209 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9210 | return mp; |
| 9211 | } |
| 9212 | } |
| 9213 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9214 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9216 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9217 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9218 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9219 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9220 | return NULL; |
| 9221 | } |
| 9222 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9224 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9225 | * @phba: Pointer to HBA context object. |
| 9226 | * @cmdiocb: Pointer to driver command iocb object. |
| 9227 | * @rspiocb: Pointer to driver response iocb object. |
| 9228 | * |
| 9229 | * This function is the completion handler for the abort iocbs for |
| 9230 | * ELS commands. This function is called from the ELS ring event |
| 9231 | * handler with no lock held. This function frees memory resources |
| 9232 | * associated with the abort iocb. |
| 9233 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9234 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9235 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9236 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9237 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9238 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9239 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9240 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9241 | |
| 9242 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9243 | |
| 9244 | /* |
| 9245 | * Assume that the port already completed and returned, or |
| 9246 | * will return the iocb. Just Log the message. |
| 9247 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9248 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9249 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9251 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9252 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9253 | if (abort_iotag != 0 && |
| 9254 | abort_iotag <= phba->sli.last_iotag) |
| 9255 | abort_iocb = |
| 9256 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9257 | } else |
| 9258 | /* For sli4 the abort_tag is the XRI, |
| 9259 | * so the abort routine puts the iotag of the iocb |
| 9260 | * being aborted in the context field of the abort |
| 9261 | * IOCB. |
| 9262 | */ |
| 9263 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9264 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9265 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9266 | "0327 Cannot abort els iocb %p " |
| 9267 | "with tag %x context %x, abort status %x, " |
| 9268 | "abort code %x\n", |
| 9269 | abort_iocb, abort_iotag, abort_context, |
| 9270 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9271 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9272 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9273 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9274 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9275 | return; |
| 9276 | } |
| 9277 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9278 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9279 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9280 | * @phba: Pointer to HBA context object. |
| 9281 | * @cmdiocb: Pointer to driver command iocb object. |
| 9282 | * @rspiocb: Pointer to driver response iocb object. |
| 9283 | * |
| 9284 | * The function is called from SLI ring event handler with no |
| 9285 | * lock held. This function is the completion handler for ELS commands |
| 9286 | * which are aborted. The function frees memory resources used for |
| 9287 | * the aborted ELS commands. |
| 9288 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9289 | static void |
| 9290 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9291 | struct lpfc_iocbq *rspiocb) |
| 9292 | { |
| 9293 | IOCB_t *irsp = &rspiocb->iocb; |
| 9294 | |
| 9295 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9296 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9297 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9298 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9299 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9300 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9301 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9302 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9303 | else |
| 9304 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9305 | return; |
| 9306 | } |
| 9307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9308 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9309 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9310 | * @phba: Pointer to HBA context object. |
| 9311 | * @pring: Pointer to driver SLI ring object. |
| 9312 | * @cmdiocb: Pointer to driver command iocb object. |
| 9313 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9314 | * This function issues an abort iocb for the provided command iocb down to |
| 9315 | * the port. Other than the case the outstanding command iocb is an abort |
| 9316 | * request, this function issues abort out unconditionally. This function is |
| 9317 | * called with hbalock held. The function returns 0 when it fails due to |
| 9318 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9319 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9320 | static int |
| 9321 | 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] | 9322 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9323 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9324 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9325 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9326 | IOCB_t *icmd = NULL; |
| 9327 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9328 | int retval; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9329 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9330 | /* |
| 9331 | * There are certain command types we don't want to abort. And we |
| 9332 | * don't want to abort commands that are already in the process of |
| 9333 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9334 | */ |
| 9335 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9336 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9337 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9338 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9339 | return 0; |
| 9340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9341 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9342 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9343 | if (abtsiocbp == NULL) |
| 9344 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9345 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9346 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9347 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9348 | */ |
| 9349 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9350 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9352 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9353 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9354 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9355 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9356 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9357 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9358 | else |
| 9359 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9360 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9361 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9362 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9363 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9364 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9365 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9366 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9367 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9368 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9369 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9370 | else |
| 9371 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9372 | |
| 9373 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9374 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9375 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9376 | "0339 Abort xri x%x, original iotag x%x, " |
| 9377 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9378 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9379 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9380 | abtsiocbp->iotag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9381 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9382 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9383 | if (retval) |
| 9384 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9385 | |
| 9386 | /* |
| 9387 | * Caller to this routine should check for IOCB_ERROR |
| 9388 | * and handle it properly. This routine no longer removes |
| 9389 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9390 | */ |
| 9391 | return retval; |
| 9392 | } |
| 9393 | |
| 9394 | /** |
| 9395 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9396 | * @phba: Pointer to HBA context object. |
| 9397 | * @pring: Pointer to driver SLI ring object. |
| 9398 | * @cmdiocb: Pointer to driver command iocb object. |
| 9399 | * |
| 9400 | * This function issues an abort iocb for the provided command iocb. In case |
| 9401 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9402 | * ring. Instead, the callback function shall be changed to those commands |
| 9403 | * so that nothing happens when them finishes. This function is called with |
| 9404 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9405 | * request. |
| 9406 | **/ |
| 9407 | int |
| 9408 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9409 | struct lpfc_iocbq *cmdiocb) |
| 9410 | { |
| 9411 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9412 | int retval = IOCB_ERROR; |
| 9413 | IOCB_t *icmd = NULL; |
| 9414 | |
| 9415 | /* |
| 9416 | * There are certain command types we don't want to abort. And we |
| 9417 | * don't want to abort commands that are already in the process of |
| 9418 | * being aborted. |
| 9419 | */ |
| 9420 | icmd = &cmdiocb->iocb; |
| 9421 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9422 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9423 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9424 | return 0; |
| 9425 | |
| 9426 | /* |
| 9427 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9428 | * the callback so that nothing happens when it finishes. |
| 9429 | */ |
| 9430 | if ((vport->load_flag & FC_UNLOADING) && |
| 9431 | (pring->ringno == LPFC_ELS_RING)) { |
| 9432 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9433 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9434 | else |
| 9435 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9436 | goto abort_iotag_exit; |
| 9437 | } |
| 9438 | |
| 9439 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9440 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9441 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9442 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9443 | /* |
| 9444 | * Caller to this routine should check for IOCB_ERROR |
| 9445 | * and handle it properly. This routine no longer removes |
| 9446 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9447 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9448 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9449 | } |
| 9450 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9451 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9452 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9453 | * @phba: Pointer to HBA context object. |
| 9454 | * @pring: Pointer to driver SLI ring object. |
| 9455 | * |
| 9456 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9457 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9458 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9459 | * to complete before the return of this function. The caller is not required |
| 9460 | * to hold any locks. |
| 9461 | **/ |
| 9462 | static void |
| 9463 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9464 | { |
| 9465 | LIST_HEAD(completions); |
| 9466 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9467 | |
| 9468 | if (pring->ringno == LPFC_ELS_RING) |
| 9469 | lpfc_fabric_abort_hba(phba); |
| 9470 | |
| 9471 | spin_lock_irq(&phba->hbalock); |
| 9472 | |
| 9473 | /* Take off all the iocbs on txq for cancelling */ |
| 9474 | list_splice_init(&pring->txq, &completions); |
| 9475 | pring->txq_cnt = 0; |
| 9476 | |
| 9477 | /* Next issue ABTS for everything on the txcmplq */ |
| 9478 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9479 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9480 | |
| 9481 | spin_unlock_irq(&phba->hbalock); |
| 9482 | |
| 9483 | /* Cancel all the IOCBs from the completions list */ |
| 9484 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9485 | IOERR_SLI_ABORTED); |
| 9486 | } |
| 9487 | |
| 9488 | /** |
| 9489 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9490 | * @phba: pointer to lpfc HBA data structure. |
| 9491 | * |
| 9492 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9493 | **/ |
| 9494 | void |
| 9495 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9496 | { |
| 9497 | struct lpfc_sli *psli = &phba->sli; |
| 9498 | struct lpfc_sli_ring *pring; |
| 9499 | int i; |
| 9500 | |
| 9501 | for (i = 0; i < psli->num_rings; i++) { |
| 9502 | pring = &psli->ring[i]; |
| 9503 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9504 | } |
| 9505 | } |
| 9506 | |
| 9507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9508 | * 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] | 9509 | * @iocbq: Pointer to driver iocb object. |
| 9510 | * @vport: Pointer to driver virtual port object. |
| 9511 | * @tgt_id: SCSI ID of the target. |
| 9512 | * @lun_id: LUN ID of the scsi device. |
| 9513 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9514 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9515 | * 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] | 9516 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9517 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9518 | * 1 if the filtering criteria is not met. |
| 9519 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9520 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9521 | * lun_id parameter. |
| 9522 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9523 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9524 | * parameters. |
| 9525 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9526 | * given iocb is for the SCSI host associated with the given vport. |
| 9527 | * This function is called with no locks held. |
| 9528 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9529 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9530 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9531 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9532 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9533 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9534 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9535 | int rc = 1; |
| 9536 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9537 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9538 | return rc; |
| 9539 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9540 | if (iocbq->vport != vport) |
| 9541 | return rc; |
| 9542 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9543 | 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] | 9544 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9545 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9546 | return rc; |
| 9547 | |
| 9548 | switch (ctx_cmd) { |
| 9549 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9550 | if ((lpfc_cmd->rdata->pnode) && |
| 9551 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9552 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9553 | rc = 0; |
| 9554 | break; |
| 9555 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9556 | if ((lpfc_cmd->rdata->pnode) && |
| 9557 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9558 | rc = 0; |
| 9559 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9560 | case LPFC_CTX_HOST: |
| 9561 | rc = 0; |
| 9562 | break; |
| 9563 | default: |
| 9564 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9565 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9566 | break; |
| 9567 | } |
| 9568 | |
| 9569 | return rc; |
| 9570 | } |
| 9571 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9572 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9573 | * 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] | 9574 | * @vport: Pointer to virtual port. |
| 9575 | * @tgt_id: SCSI ID of the target. |
| 9576 | * @lun_id: LUN ID of the scsi device. |
| 9577 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9578 | * |
| 9579 | * This function returns number of FCP commands pending for the vport. |
| 9580 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9581 | * commands pending on the vport associated with SCSI device specified |
| 9582 | * by tgt_id and lun_id parameters. |
| 9583 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9584 | * commands pending on the vport associated with SCSI target specified |
| 9585 | * by tgt_id parameter. |
| 9586 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9587 | * commands pending on the vport. |
| 9588 | * This function returns the number of iocbs which satisfy the filter. |
| 9589 | * This function is called without any lock held. |
| 9590 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9591 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9592 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9593 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9594 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9595 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9596 | struct lpfc_iocbq *iocbq; |
| 9597 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9598 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9599 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9600 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9601 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9602 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9603 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9604 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9605 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9607 | return sum; |
| 9608 | } |
| 9609 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9610 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9611 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9612 | * @phba: Pointer to HBA context object |
| 9613 | * @cmdiocb: Pointer to command iocb object. |
| 9614 | * @rspiocb: Pointer to response iocb object. |
| 9615 | * |
| 9616 | * This function is called when an aborted FCP iocb completes. This |
| 9617 | * function is called by the ring event handler with no lock held. |
| 9618 | * This function frees the iocb. |
| 9619 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9620 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9621 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9622 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9623 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9624 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9625 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9626 | "original iotag x%x, abort cmd iotag x%x " |
| 9627 | "status 0x%x, reason 0x%x\n", |
| 9628 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9629 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9630 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9631 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9632 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9633 | return; |
| 9634 | } |
| 9635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9637 | * 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] | 9638 | * @vport: Pointer to virtual port. |
| 9639 | * @pring: Pointer to driver SLI ring object. |
| 9640 | * @tgt_id: SCSI ID of the target. |
| 9641 | * @lun_id: LUN ID of the scsi device. |
| 9642 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9643 | * |
| 9644 | * This function sends an abort command for every SCSI command |
| 9645 | * associated with the given virtual port pending on the ring |
| 9646 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9647 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9648 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9649 | * parameters |
| 9650 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9651 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9652 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9653 | * FCP iocbs associated with virtual port. |
| 9654 | * This function returns number of iocbs it failed to abort. |
| 9655 | * This function is called with no locks held. |
| 9656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9657 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9658 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9659 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9660 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9661 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9662 | struct lpfc_iocbq *iocbq; |
| 9663 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9664 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9665 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9666 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9667 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9668 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9669 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9670 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9671 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9672 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9673 | continue; |
| 9674 | |
| 9675 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9676 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9677 | if (abtsiocb == NULL) { |
| 9678 | errcnt++; |
| 9679 | continue; |
| 9680 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9681 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9682 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9683 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9684 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9685 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9686 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9687 | else |
| 9688 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9689 | abtsiocb->iocb.ulpLe = 1; |
| 9690 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9691 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9692 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9693 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9694 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9695 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9696 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9697 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9698 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9699 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9700 | else |
| 9701 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9702 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9703 | /* Setup callback routine and issue the command. */ |
| 9704 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9705 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9706 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9707 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9708 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9709 | errcnt++; |
| 9710 | continue; |
| 9711 | } |
| 9712 | } |
| 9713 | |
| 9714 | return errcnt; |
| 9715 | } |
| 9716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9717 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9718 | * 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] | 9719 | * @phba: Pointer to HBA context object. |
| 9720 | * @cmdiocbq: Pointer to command iocb. |
| 9721 | * @rspiocbq: Pointer to response iocb. |
| 9722 | * |
| 9723 | * This function is the completion handler for iocbs issued using |
| 9724 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9725 | * ring event handler function without any lock held. This function |
| 9726 | * can be called from both worker thread context and interrupt |
| 9727 | * context. This function also can be called from other thread which |
| 9728 | * cleans up the SLI layer objects. |
| 9729 | * This function copy the contents of the response iocb to the |
| 9730 | * response iocb memory object provided by the caller of |
| 9731 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9732 | * sleeps for the iocb completion. |
| 9733 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9734 | static void |
| 9735 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9736 | struct lpfc_iocbq *cmdiocbq, |
| 9737 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9738 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9739 | wait_queue_head_t *pdone_q; |
| 9740 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9741 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9742 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9743 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9744 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9745 | if (cmdiocbq->context2 && rspiocbq) |
| 9746 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9747 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9748 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9749 | /* Set the exchange busy flag for task management commands */ |
| 9750 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9751 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9752 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9753 | cur_iocbq); |
| 9754 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9755 | } |
| 9756 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9757 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9758 | if (pdone_q) |
| 9759 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9760 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9761 | return; |
| 9762 | } |
| 9763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9764 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9765 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9766 | * @phba: Pointer to HBA context object.. |
| 9767 | * @piocbq: Pointer to command iocb. |
| 9768 | * @flag: Flag to test. |
| 9769 | * |
| 9770 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9771 | * see if the passed in flag is set. |
| 9772 | * Returns: |
| 9773 | * 1 if flag is set. |
| 9774 | * 0 if flag is not set. |
| 9775 | **/ |
| 9776 | static int |
| 9777 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9778 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9779 | { |
| 9780 | unsigned long iflags; |
| 9781 | int ret; |
| 9782 | |
| 9783 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9784 | ret = piocbq->iocb_flag & flag; |
| 9785 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9786 | return ret; |
| 9787 | |
| 9788 | } |
| 9789 | |
| 9790 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9791 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9792 | * @phba: Pointer to HBA context object.. |
| 9793 | * @pring: Pointer to sli ring. |
| 9794 | * @piocb: Pointer to command iocb. |
| 9795 | * @prspiocbq: Pointer to response iocb. |
| 9796 | * @timeout: Timeout in number of seconds. |
| 9797 | * |
| 9798 | * This function issues the iocb to firmware and waits for the |
| 9799 | * iocb to complete. If the iocb command is not |
| 9800 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9801 | * Caller should not free the iocb resources if this function |
| 9802 | * returns IOCB_TIMEDOUT. |
| 9803 | * The function waits for the iocb completion using an |
| 9804 | * non-interruptible wait. |
| 9805 | * This function will sleep while waiting for iocb completion. |
| 9806 | * So, this function should not be called from any context which |
| 9807 | * does not allow sleeping. Due to the same reason, this function |
| 9808 | * cannot be called with interrupt disabled. |
| 9809 | * This function assumes that the iocb completions occur while |
| 9810 | * this function sleep. So, this function cannot be called from |
| 9811 | * the thread which process iocb completion for this ring. |
| 9812 | * This function clears the iocb_flag of the iocb object before |
| 9813 | * issuing the iocb and the iocb completion handler sets this |
| 9814 | * flag and wakes this thread when the iocb completes. |
| 9815 | * The contents of the response iocb will be copied to prspiocbq |
| 9816 | * by the completion handler when the command completes. |
| 9817 | * This function returns IOCB_SUCCESS when success. |
| 9818 | * This function is called with no lock held. |
| 9819 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9820 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9821 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9822 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9823 | struct lpfc_iocbq *piocb, |
| 9824 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9825 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9826 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9827 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9828 | long timeleft, timeout_req = 0; |
| 9829 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9830 | uint32_t creg_val; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9831 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9832 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9833 | * If the caller has provided a response iocbq buffer, then context2 |
| 9834 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9835 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9836 | if (prspiocbq) { |
| 9837 | if (piocb->context2) |
| 9838 | return IOCB_ERROR; |
| 9839 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9840 | } |
| 9841 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9842 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9843 | piocb->context_un.wait_queue = &done_q; |
| 9844 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9845 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9846 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9847 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9848 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9849 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9850 | writel(creg_val, phba->HCregaddr); |
| 9851 | readl(phba->HCregaddr); /* flush */ |
| 9852 | } |
| 9853 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9854 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 9855 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9856 | if (retval == IOCB_SUCCESS) { |
| 9857 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9858 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9859 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9860 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9861 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9862 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 9863 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9864 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9865 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9866 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9867 | "0338 IOCB wait timeout error - no " |
| 9868 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9869 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9870 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9871 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9872 | "0330 IOCB wake NOT set, " |
| 9873 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9874 | timeout, (timeleft / jiffies)); |
| 9875 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9876 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9877 | } else if (retval == IOCB_BUSY) { |
| 9878 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9879 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 9880 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); |
| 9881 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9882 | } else { |
| 9883 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9884 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9885 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9886 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9887 | } |
| 9888 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9889 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9890 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9891 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9892 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 9893 | writel(creg_val, phba->HCregaddr); |
| 9894 | readl(phba->HCregaddr); /* flush */ |
| 9895 | } |
| 9896 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9897 | if (prspiocbq) |
| 9898 | piocb->context2 = NULL; |
| 9899 | |
| 9900 | piocb->context_un.wait_queue = NULL; |
| 9901 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9902 | return retval; |
| 9903 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9906 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9907 | * @phba: Pointer to HBA context object. |
| 9908 | * @pmboxq: Pointer to driver mailbox object. |
| 9909 | * @timeout: Timeout in number of seconds. |
| 9910 | * |
| 9911 | * This function issues the mailbox to firmware and waits for the |
| 9912 | * mailbox command to complete. If the mailbox command is not |
| 9913 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 9914 | * The function waits for the mailbox completion using an |
| 9915 | * interruptible wait. If the thread is woken up due to a |
| 9916 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 9917 | * should not free the mailbox resources, if this function returns |
| 9918 | * MBX_TIMEOUT. |
| 9919 | * This function will sleep while waiting for mailbox completion. |
| 9920 | * So, this function should not be called from any context which |
| 9921 | * does not allow sleeping. Due to the same reason, this function |
| 9922 | * cannot be called with interrupt disabled. |
| 9923 | * This function assumes that the mailbox completion occurs while |
| 9924 | * this function sleep. So, this function cannot be called from |
| 9925 | * the worker thread which processes mailbox completion. |
| 9926 | * This function is called in the context of HBA management |
| 9927 | * applications. |
| 9928 | * This function returns MBX_SUCCESS when successful. |
| 9929 | * This function is called with no lock held. |
| 9930 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9931 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9932 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9933 | uint32_t timeout) |
| 9934 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9935 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9936 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9937 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9938 | |
| 9939 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9940 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9941 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9942 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9943 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9944 | /* setup wake call as IOCB callback */ |
| 9945 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 9946 | /* setup context field to pass wait_queue pointer to wake function */ |
| 9947 | pmboxq->context1 = &done_q; |
| 9948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9949 | /* now issue the command */ |
| 9950 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9951 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9952 | wait_event_interruptible_timeout(done_q, |
| 9953 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 9954 | timeout * HZ); |
| 9955 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9956 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9957 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9958 | /* |
| 9959 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 9960 | * else do not free the resources. |
| 9961 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 9962 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9963 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 9964 | lpfc_sli4_swap_str(phba, pmboxq); |
| 9965 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9966 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9967 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 9968 | } |
| 9969 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9970 | } |
| 9971 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9972 | return retval; |
| 9973 | } |
| 9974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9975 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9976 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9977 | * @phba: Pointer to HBA context. |
| 9978 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9979 | * This function is called to shutdown the driver's mailbox sub-system. |
| 9980 | * It first marks the mailbox sub-system is in a block state to prevent |
| 9981 | * the asynchronous mailbox command from issued off the pending mailbox |
| 9982 | * command queue. If the mailbox command sub-system shutdown is due to |
| 9983 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 9984 | * the mailbox sub-system flush routine to forcefully bring down the |
| 9985 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 9986 | * as with offline or HBA function reset), this routine will wait for the |
| 9987 | * outstanding mailbox command to complete before invoking the mailbox |
| 9988 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9989 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9990 | void |
| 9991 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 9992 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9993 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9994 | unsigned long timeout; |
| 9995 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9996 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 9997 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9998 | spin_lock_irq(&phba->hbalock); |
| 9999 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10000 | |
| 10001 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10002 | /* Determine how long we might wait for the active mailbox |
| 10003 | * command to be gracefully completed by firmware. |
| 10004 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10005 | if (phba->sli.mbox_active) |
| 10006 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10007 | phba->sli.mbox_active) * |
| 10008 | 1000) + jiffies; |
| 10009 | spin_unlock_irq(&phba->hbalock); |
| 10010 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10011 | while (phba->sli.mbox_active) { |
| 10012 | /* Check active mailbox complete status every 2ms */ |
| 10013 | msleep(2); |
| 10014 | if (time_after(jiffies, timeout)) |
| 10015 | /* Timeout, let the mailbox flush routine to |
| 10016 | * forcefully release active mailbox command |
| 10017 | */ |
| 10018 | break; |
| 10019 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10020 | } else |
| 10021 | spin_unlock_irq(&phba->hbalock); |
| 10022 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10023 | lpfc_sli_mbox_sys_flush(phba); |
| 10024 | } |
| 10025 | |
| 10026 | /** |
| 10027 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10028 | * @phba: Pointer to HBA context. |
| 10029 | * |
| 10030 | * This function is called to read the SLI3 device error attention registers |
| 10031 | * for possible error attention events. The caller must hold the hostlock |
| 10032 | * with spin_lock_irq(). |
| 10033 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10034 | * 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] | 10035 | * Register and returns 0 otherwise. |
| 10036 | **/ |
| 10037 | static int |
| 10038 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10039 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10040 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10041 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10042 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10043 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10044 | goto unplug_err; |
| 10045 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10046 | if (ha_copy & HA_ERATT) { |
| 10047 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10048 | if (lpfc_sli_read_hs(phba)) |
| 10049 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10050 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10051 | /* Check if there is a deferred error condition is active */ |
| 10052 | if ((HS_FFER1 & phba->work_hs) && |
| 10053 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10054 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10055 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10056 | /* Clear all interrupt enable conditions */ |
| 10057 | writel(0, phba->HCregaddr); |
| 10058 | readl(phba->HCregaddr); |
| 10059 | } |
| 10060 | |
| 10061 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10062 | phba->work_ha |= HA_ERATT; |
| 10063 | /* Indicate polling handles this ERATT */ |
| 10064 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10065 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10066 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10067 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10068 | |
| 10069 | unplug_err: |
| 10070 | /* Set the driver HS work bitmap */ |
| 10071 | phba->work_hs |= UNPLUG_ERR; |
| 10072 | /* Set the driver HA work bitmap */ |
| 10073 | phba->work_ha |= HA_ERATT; |
| 10074 | /* Indicate polling handles this ERATT */ |
| 10075 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10076 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10077 | } |
| 10078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10079 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10080 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10081 | * @phba: Pointer to HBA context. |
| 10082 | * |
| 10083 | * This function is called to read the SLI4 device error attention registers |
| 10084 | * for possible error attention events. The caller must hold the hostlock |
| 10085 | * with spin_lock_irq(). |
| 10086 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10087 | * 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] | 10088 | * Register and returns 0 otherwise. |
| 10089 | **/ |
| 10090 | static int |
| 10091 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10092 | { |
| 10093 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10094 | uint32_t if_type, portsmphr; |
| 10095 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10096 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10097 | /* |
| 10098 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10099 | * registers for error attention. This can be changed later. |
| 10100 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10101 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10102 | switch (if_type) { |
| 10103 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10104 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10105 | &uerr_sta_lo) || |
| 10106 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10107 | &uerr_sta_hi)) { |
| 10108 | phba->work_hs |= UNPLUG_ERR; |
| 10109 | phba->work_ha |= HA_ERATT; |
| 10110 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10111 | return 1; |
| 10112 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10113 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10114 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10116 | "1423 HBA Unrecoverable error: " |
| 10117 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10118 | "ue_mask_lo_reg=0x%x, " |
| 10119 | "ue_mask_hi_reg=0x%x\n", |
| 10120 | uerr_sta_lo, uerr_sta_hi, |
| 10121 | phba->sli4_hba.ue_mask_lo, |
| 10122 | phba->sli4_hba.ue_mask_hi); |
| 10123 | phba->work_status[0] = uerr_sta_lo; |
| 10124 | phba->work_status[1] = uerr_sta_hi; |
| 10125 | phba->work_ha |= HA_ERATT; |
| 10126 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10127 | return 1; |
| 10128 | } |
| 10129 | break; |
| 10130 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10131 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10132 | &portstat_reg.word0) || |
| 10133 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10134 | &portsmphr)){ |
| 10135 | phba->work_hs |= UNPLUG_ERR; |
| 10136 | phba->work_ha |= HA_ERATT; |
| 10137 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10138 | return 1; |
| 10139 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10140 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10141 | phba->work_status[0] = |
| 10142 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10143 | phba->work_status[1] = |
| 10144 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10146 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10147 | "port status reg 0x%x, " |
| 10148 | "port smphr reg 0x%x, " |
| 10149 | "error 1=0x%x, error 2=0x%x\n", |
| 10150 | portstat_reg.word0, |
| 10151 | portsmphr, |
| 10152 | phba->work_status[0], |
| 10153 | phba->work_status[1]); |
| 10154 | phba->work_ha |= HA_ERATT; |
| 10155 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10156 | return 1; |
| 10157 | } |
| 10158 | break; |
| 10159 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10160 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10162 | "2886 HBA Error Attention on unsupported " |
| 10163 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10164 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10165 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10166 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10167 | return 0; |
| 10168 | } |
| 10169 | |
| 10170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10171 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10172 | * @phba: Pointer to HBA context. |
| 10173 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10174 | * 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] | 10175 | * error attention register bit for error attention events. |
| 10176 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10177 | * 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] | 10178 | * Register and returns 0 otherwise. |
| 10179 | **/ |
| 10180 | int |
| 10181 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10182 | { |
| 10183 | uint32_t ha_copy; |
| 10184 | |
| 10185 | /* If somebody is waiting to handle an eratt, don't process it |
| 10186 | * here. The brdkill function will do this. |
| 10187 | */ |
| 10188 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10189 | return 0; |
| 10190 | |
| 10191 | /* Check if interrupt handler handles this ERATT */ |
| 10192 | spin_lock_irq(&phba->hbalock); |
| 10193 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10194 | /* Interrupt handler has handled ERATT */ |
| 10195 | spin_unlock_irq(&phba->hbalock); |
| 10196 | return 0; |
| 10197 | } |
| 10198 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10199 | /* |
| 10200 | * If there is deferred error attention, do not check for error |
| 10201 | * attention |
| 10202 | */ |
| 10203 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10204 | spin_unlock_irq(&phba->hbalock); |
| 10205 | return 0; |
| 10206 | } |
| 10207 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10208 | /* If PCI channel is offline, don't process it */ |
| 10209 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10210 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10211 | return 0; |
| 10212 | } |
| 10213 | |
| 10214 | switch (phba->sli_rev) { |
| 10215 | case LPFC_SLI_REV2: |
| 10216 | case LPFC_SLI_REV3: |
| 10217 | /* Read chip Host Attention (HA) register */ |
| 10218 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10219 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10220 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10221 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10222 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10223 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10224 | default: |
| 10225 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10226 | "0299 Invalid SLI revision (%d)\n", |
| 10227 | phba->sli_rev); |
| 10228 | ha_copy = 0; |
| 10229 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10230 | } |
| 10231 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10232 | |
| 10233 | return ha_copy; |
| 10234 | } |
| 10235 | |
| 10236 | /** |
| 10237 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10238 | * @phba: Pointer to HBA context. |
| 10239 | * |
| 10240 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10241 | * that the interrupt should be handled. |
| 10242 | * |
| 10243 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10244 | * interrupt should be handled, otherwise -EIO. |
| 10245 | */ |
| 10246 | static inline int |
| 10247 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10248 | { |
| 10249 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10250 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10251 | return -EIO; |
| 10252 | |
| 10253 | /* Update device level interrupt statistics */ |
| 10254 | phba->sli.slistat.sli_intr++; |
| 10255 | |
| 10256 | /* Ignore all interrupts during initialization. */ |
| 10257 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10258 | return -EIO; |
| 10259 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10260 | return 0; |
| 10261 | } |
| 10262 | |
| 10263 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10264 | * 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] | 10265 | * @irq: Interrupt number. |
| 10266 | * @dev_id: The device context pointer. |
| 10267 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10268 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10269 | * service routine when device with SLI-3 interface spec is enabled with |
| 10270 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10271 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10272 | * interrupt mode, this function is called as part of the device-level |
| 10273 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10274 | * is undergoing initialization, the interrupt handler will not process |
| 10275 | * the interrupt. The link attention and ELS ring attention events are |
| 10276 | * handled by the worker thread. The interrupt handler signals the worker |
| 10277 | * thread and returns for these events. This function is called without |
| 10278 | * 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] | 10279 | * structures. |
| 10280 | * |
| 10281 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10282 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10284 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10285 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10286 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10287 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10288 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10289 | uint32_t work_ha_copy; |
| 10290 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10291 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10292 | uint32_t control; |
| 10293 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10294 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10295 | struct lpfc_vport *vport; |
| 10296 | struct lpfc_nodelist *ndlp; |
| 10297 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10298 | LPFC_MBOXQ_t *pmb; |
| 10299 | int rc; |
| 10300 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10301 | /* |
| 10302 | * Get the driver's phba structure from the dev_id and |
| 10303 | * assume the HBA is not interrupting. |
| 10304 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10305 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10306 | |
| 10307 | if (unlikely(!phba)) |
| 10308 | return IRQ_NONE; |
| 10309 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10310 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10311 | * Stuff needs to be attented to when this function is invoked as an |
| 10312 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10313 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10314 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10315 | /* Check device state for handling interrupt */ |
| 10316 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10317 | return IRQ_NONE; |
| 10318 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10319 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10320 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10321 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10322 | /* If somebody is waiting to handle an eratt don't process it |
| 10323 | * here. The brdkill function will do this. |
| 10324 | */ |
| 10325 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10326 | ha_copy &= ~HA_ERATT; |
| 10327 | /* Check the need for handling ERATT in interrupt handler */ |
| 10328 | if (ha_copy & HA_ERATT) { |
| 10329 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10330 | /* ERATT polling has handled ERATT */ |
| 10331 | ha_copy &= ~HA_ERATT; |
| 10332 | else |
| 10333 | /* Indicate interrupt handler handles ERATT */ |
| 10334 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10335 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10336 | |
| 10337 | /* |
| 10338 | * If there is deferred error attention, do not check for any |
| 10339 | * interrupt. |
| 10340 | */ |
| 10341 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10342 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10343 | return IRQ_NONE; |
| 10344 | } |
| 10345 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10346 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10347 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10348 | goto unplug_error; |
| 10349 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10350 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10351 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10352 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10353 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10354 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10355 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10356 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10357 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10358 | } else |
| 10359 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10360 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10361 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10362 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10363 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10364 | if (work_ha_copy & HA_LATT) { |
| 10365 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10366 | /* |
| 10367 | * Turn off Link Attention interrupts |
| 10368 | * until CLEAR_LA done |
| 10369 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10370 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10371 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10372 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10373 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10374 | control &= ~HC_LAINT_ENA; |
| 10375 | writel(control, phba->HCregaddr); |
| 10376 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10377 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10378 | } |
| 10379 | else |
| 10380 | work_ha_copy &= ~HA_LATT; |
| 10381 | } |
| 10382 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10383 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10384 | /* |
| 10385 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10386 | * the only slow ring. |
| 10387 | */ |
| 10388 | status = (work_ha_copy & |
| 10389 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10390 | status >>= (4*LPFC_ELS_RING); |
| 10391 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10392 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10393 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10394 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10395 | |
| 10396 | lpfc_debugfs_slow_ring_trc(phba, |
| 10397 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10398 | control, status, |
| 10399 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10400 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10401 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10402 | lpfc_debugfs_slow_ring_trc(phba, |
| 10403 | "ISR Disable ring:" |
| 10404 | "pwork:x%x hawork:x%x wait:x%x", |
| 10405 | phba->work_ha, work_ha_copy, |
| 10406 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10407 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10408 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10409 | control &= |
| 10410 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10411 | writel(control, phba->HCregaddr); |
| 10412 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10413 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10414 | else { |
| 10415 | lpfc_debugfs_slow_ring_trc(phba, |
| 10416 | "ISR slow ring: pwork:" |
| 10417 | "x%x hawork:x%x wait:x%x", |
| 10418 | phba->work_ha, work_ha_copy, |
| 10419 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10420 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10421 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10422 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10423 | } |
| 10424 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10425 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10426 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10427 | if (lpfc_sli_read_hs(phba)) |
| 10428 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10429 | /* |
| 10430 | * Check if there is a deferred error condition |
| 10431 | * is active |
| 10432 | */ |
| 10433 | if ((HS_FFER1 & phba->work_hs) && |
| 10434 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10435 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10436 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10437 | phba->hba_flag |= DEFER_ERATT; |
| 10438 | /* Clear all interrupt enable conditions */ |
| 10439 | writel(0, phba->HCregaddr); |
| 10440 | readl(phba->HCregaddr); |
| 10441 | } |
| 10442 | } |
| 10443 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10444 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10445 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10446 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10447 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10448 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10449 | |
| 10450 | /* First check out the status word */ |
| 10451 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10452 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10453 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10454 | /* |
| 10455 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10456 | * mbxStatus <status> |
| 10457 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10458 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10459 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10460 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10461 | "Interrupt mbxCommand x%x " |
| 10462 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10463 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10464 | pmbox->mbxCommand, |
| 10465 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10466 | /* clear mailbox attention bit */ |
| 10467 | work_ha_copy &= ~HA_MBATT; |
| 10468 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10469 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10470 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10471 | phba->last_completion_time = jiffies; |
| 10472 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10473 | if (pmb->mbox_cmpl) { |
| 10474 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10475 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10476 | if (pmb->out_ext_byte_len && |
| 10477 | pmb->context2) |
| 10478 | lpfc_sli_pcimem_bcopy( |
| 10479 | phba->mbox_ext, |
| 10480 | pmb->context2, |
| 10481 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10482 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10483 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10484 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10485 | |
| 10486 | lpfc_debugfs_disc_trc(vport, |
| 10487 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10488 | "MBOX dflt rpi: : " |
| 10489 | "status:x%x rpi:x%x", |
| 10490 | (uint32_t)pmbox->mbxStatus, |
| 10491 | pmbox->un.varWords[0], 0); |
| 10492 | |
| 10493 | if (!pmbox->mbxStatus) { |
| 10494 | mp = (struct lpfc_dmabuf *) |
| 10495 | (pmb->context1); |
| 10496 | ndlp = (struct lpfc_nodelist *) |
| 10497 | pmb->context2; |
| 10498 | |
| 10499 | /* Reg_LOGIN of dflt RPI was |
| 10500 | * successful. new lets get |
| 10501 | * rid of the RPI using the |
| 10502 | * same mbox buffer. |
| 10503 | */ |
| 10504 | lpfc_unreg_login(phba, |
| 10505 | vport->vpi, |
| 10506 | pmbox->un.varWords[0], |
| 10507 | pmb); |
| 10508 | pmb->mbox_cmpl = |
| 10509 | lpfc_mbx_cmpl_dflt_rpi; |
| 10510 | pmb->context1 = mp; |
| 10511 | pmb->context2 = ndlp; |
| 10512 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10513 | rc = lpfc_sli_issue_mbox(phba, |
| 10514 | pmb, |
| 10515 | MBX_NOWAIT); |
| 10516 | if (rc != MBX_BUSY) |
| 10517 | lpfc_printf_log(phba, |
| 10518 | KERN_ERR, |
| 10519 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10520 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10521 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10522 | if (rc != MBX_NOT_FINISHED) |
| 10523 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10524 | } |
| 10525 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10526 | spin_lock_irqsave( |
| 10527 | &phba->pport->work_port_lock, |
| 10528 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10529 | phba->pport->work_port_events &= |
| 10530 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10531 | spin_unlock_irqrestore( |
| 10532 | &phba->pport->work_port_lock, |
| 10533 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10534 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10535 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10536 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10537 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10538 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10539 | if ((work_ha_copy & HA_MBATT) && |
| 10540 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10541 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10542 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10543 | do { |
| 10544 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10545 | MBX_NOWAIT); |
| 10546 | } while (rc == MBX_NOT_FINISHED); |
| 10547 | if (rc != MBX_SUCCESS) |
| 10548 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10549 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10550 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10551 | } |
| 10552 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10553 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10554 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10555 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10556 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10557 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10558 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10559 | unplug_error: |
| 10560 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10561 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10562 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10563 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10564 | |
| 10565 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10566 | * 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] | 10567 | * @irq: Interrupt number. |
| 10568 | * @dev_id: The device context pointer. |
| 10569 | * |
| 10570 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10571 | * service routine when device with SLI-3 interface spec is enabled with |
| 10572 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10573 | * ring event in the HBA. However, when the device is enabled with either |
| 10574 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10575 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10576 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10577 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10578 | * the intrrupt context. This function is called without any lock held. |
| 10579 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10580 | * |
| 10581 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10582 | * returns IRQ_NONE. |
| 10583 | **/ |
| 10584 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10585 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10586 | { |
| 10587 | struct lpfc_hba *phba; |
| 10588 | uint32_t ha_copy; |
| 10589 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10590 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10591 | |
| 10592 | /* Get the driver's phba structure from the dev_id and |
| 10593 | * assume the HBA is not interrupting. |
| 10594 | */ |
| 10595 | phba = (struct lpfc_hba *) dev_id; |
| 10596 | |
| 10597 | if (unlikely(!phba)) |
| 10598 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10599 | |
| 10600 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10601 | * Stuff needs to be attented to when this function is invoked as an |
| 10602 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10603 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10604 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10605 | /* Check device state for handling interrupt */ |
| 10606 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10607 | return IRQ_NONE; |
| 10608 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10609 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10610 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10611 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10612 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10613 | /* |
| 10614 | * If there is deferred error attention, do not check for |
| 10615 | * any interrupt. |
| 10616 | */ |
| 10617 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10618 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10619 | return IRQ_NONE; |
| 10620 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10621 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10622 | phba->HAregaddr); |
| 10623 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10624 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10625 | } else |
| 10626 | ha_copy = phba->ha_copy; |
| 10627 | |
| 10628 | /* |
| 10629 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10630 | */ |
| 10631 | ha_copy &= ~(phba->work_ha_mask); |
| 10632 | |
| 10633 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10634 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10635 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10636 | lpfc_sli_handle_fast_ring_event(phba, |
| 10637 | &phba->sli.ring[LPFC_FCP_RING], |
| 10638 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10639 | |
| 10640 | if (phba->cfg_multi_ring_support == 2) { |
| 10641 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10642 | * Process all events on extra ring. Take the optimized path |
| 10643 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10644 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10645 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10646 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10647 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10648 | lpfc_sli_handle_fast_ring_event(phba, |
| 10649 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10650 | status); |
| 10651 | } |
| 10652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10653 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10654 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10655 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10656 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10657 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10658 | * @irq: Interrupt number. |
| 10659 | * @dev_id: The device context pointer. |
| 10660 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10661 | * This function is the HBA device-level interrupt handler to device with |
| 10662 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10663 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10664 | * requires driver attention. This function invokes the slow-path interrupt |
| 10665 | * attention handling function and fast-path interrupt attention handling |
| 10666 | * function in turn to process the relevant HBA attention events. This |
| 10667 | * function is called without any lock held. It gets the hbalock to access |
| 10668 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10669 | * |
| 10670 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10671 | * returns IRQ_NONE. |
| 10672 | **/ |
| 10673 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10674 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10675 | { |
| 10676 | struct lpfc_hba *phba; |
| 10677 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10678 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10679 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10680 | |
| 10681 | /* |
| 10682 | * Get the driver's phba structure from the dev_id and |
| 10683 | * assume the HBA is not interrupting. |
| 10684 | */ |
| 10685 | phba = (struct lpfc_hba *) dev_id; |
| 10686 | |
| 10687 | if (unlikely(!phba)) |
| 10688 | return IRQ_NONE; |
| 10689 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10690 | /* Check device state for handling interrupt */ |
| 10691 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10692 | return IRQ_NONE; |
| 10693 | |
| 10694 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10695 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10696 | spin_unlock(&phba->hbalock); |
| 10697 | return IRQ_HANDLED; |
| 10698 | } |
| 10699 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10700 | if (unlikely(!phba->ha_copy)) { |
| 10701 | spin_unlock(&phba->hbalock); |
| 10702 | return IRQ_NONE; |
| 10703 | } else if (phba->ha_copy & HA_ERATT) { |
| 10704 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10705 | /* ERATT polling has handled ERATT */ |
| 10706 | phba->ha_copy &= ~HA_ERATT; |
| 10707 | else |
| 10708 | /* Indicate interrupt handler handles ERATT */ |
| 10709 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10710 | } |
| 10711 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10712 | /* |
| 10713 | * If there is deferred error attention, do not check for any interrupt. |
| 10714 | */ |
| 10715 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10716 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10717 | return IRQ_NONE; |
| 10718 | } |
| 10719 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10720 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10721 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10722 | spin_unlock(&phba->hbalock); |
| 10723 | return IRQ_HANDLED; |
| 10724 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10725 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10726 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10727 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10728 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10729 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10730 | readl(phba->HAregaddr); /* flush */ |
| 10731 | spin_unlock(&phba->hbalock); |
| 10732 | |
| 10733 | /* |
| 10734 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10735 | */ |
| 10736 | |
| 10737 | /* status of events with mailbox and link attention */ |
| 10738 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10739 | |
| 10740 | /* status of events with ELS ring */ |
| 10741 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10742 | status2 >>= (4*LPFC_ELS_RING); |
| 10743 | |
| 10744 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10745 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10746 | else |
| 10747 | sp_irq_rc = IRQ_NONE; |
| 10748 | |
| 10749 | /* |
| 10750 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10751 | */ |
| 10752 | |
| 10753 | /* status of events with FCP ring */ |
| 10754 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10755 | status1 >>= (4*LPFC_FCP_RING); |
| 10756 | |
| 10757 | /* status of events with extra ring */ |
| 10758 | if (phba->cfg_multi_ring_support == 2) { |
| 10759 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10760 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10761 | } else |
| 10762 | status2 = 0; |
| 10763 | |
| 10764 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10765 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10766 | else |
| 10767 | fp_irq_rc = IRQ_NONE; |
| 10768 | |
| 10769 | /* Return device-level interrupt handling status */ |
| 10770 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10771 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10772 | |
| 10773 | /** |
| 10774 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10775 | * @phba: pointer to lpfc hba data structure. |
| 10776 | * |
| 10777 | * This routine is invoked by the worker thread to process all the pending |
| 10778 | * SLI4 FCP abort XRI events. |
| 10779 | **/ |
| 10780 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10781 | { |
| 10782 | struct lpfc_cq_event *cq_event; |
| 10783 | |
| 10784 | /* First, declare the fcp xri abort event has been handled */ |
| 10785 | spin_lock_irq(&phba->hbalock); |
| 10786 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10787 | spin_unlock_irq(&phba->hbalock); |
| 10788 | /* Now, handle all the fcp xri abort events */ |
| 10789 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10790 | /* Get the first event from the head of the event queue */ |
| 10791 | spin_lock_irq(&phba->hbalock); |
| 10792 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10793 | cq_event, struct lpfc_cq_event, list); |
| 10794 | spin_unlock_irq(&phba->hbalock); |
| 10795 | /* Notify aborted XRI for FCP work queue */ |
| 10796 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10797 | /* Free the event processed back to the free pool */ |
| 10798 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10799 | } |
| 10800 | } |
| 10801 | |
| 10802 | /** |
| 10803 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10804 | * @phba: pointer to lpfc hba data structure. |
| 10805 | * |
| 10806 | * This routine is invoked by the worker thread to process all the pending |
| 10807 | * SLI4 els abort xri events. |
| 10808 | **/ |
| 10809 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10810 | { |
| 10811 | struct lpfc_cq_event *cq_event; |
| 10812 | |
| 10813 | /* First, declare the els xri abort event has been handled */ |
| 10814 | spin_lock_irq(&phba->hbalock); |
| 10815 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10816 | spin_unlock_irq(&phba->hbalock); |
| 10817 | /* Now, handle all the els xri abort events */ |
| 10818 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10819 | /* Get the first event from the head of the event queue */ |
| 10820 | spin_lock_irq(&phba->hbalock); |
| 10821 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10822 | cq_event, struct lpfc_cq_event, list); |
| 10823 | spin_unlock_irq(&phba->hbalock); |
| 10824 | /* Notify aborted XRI for ELS work queue */ |
| 10825 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10826 | /* Free the event processed back to the free pool */ |
| 10827 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10828 | } |
| 10829 | } |
| 10830 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10831 | /** |
| 10832 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10833 | * @phba: pointer to lpfc hba data structure |
| 10834 | * @pIocbIn: pointer to the rspiocbq |
| 10835 | * @pIocbOut: pointer to the cmdiocbq |
| 10836 | * @wcqe: pointer to the complete wcqe |
| 10837 | * |
| 10838 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 10839 | * by copying all the IOCB fields from command iocbq and transferring the |
| 10840 | * completion status information from the complete wcqe. |
| 10841 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10842 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10843 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 10844 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10845 | struct lpfc_iocbq *pIocbOut, |
| 10846 | struct lpfc_wcqe_complete *wcqe) |
| 10847 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10848 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10849 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10850 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 10851 | |
| 10852 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 10853 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10854 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10855 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 10856 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10857 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 10858 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 10859 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 10860 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 10861 | wcqe->total_data_placed; |
| 10862 | else |
| 10863 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10864 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10865 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10866 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 10867 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10868 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10869 | /* Convert BG errors for completion status */ |
| 10870 | if (status == CQE_STATUS_DI_ERROR) { |
| 10871 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 10872 | |
| 10873 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 10874 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 10875 | else |
| 10876 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 10877 | |
| 10878 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 10879 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 10880 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10881 | BGS_GUARD_ERR_MASK; |
| 10882 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 10883 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10884 | BGS_APPTAG_ERR_MASK; |
| 10885 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 10886 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10887 | BGS_REFTAG_ERR_MASK; |
| 10888 | |
| 10889 | /* Check to see if there was any good data before the error */ |
| 10890 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 10891 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10892 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 10893 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 10894 | wcqe->total_data_placed; |
| 10895 | } |
| 10896 | |
| 10897 | /* |
| 10898 | * Set ALL the error bits to indicate we don't know what |
| 10899 | * type of error it is. |
| 10900 | */ |
| 10901 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 10902 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10903 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 10904 | BGS_GUARD_ERR_MASK); |
| 10905 | } |
| 10906 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10907 | /* Pick up HBA exchange busy condition */ |
| 10908 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 10909 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10910 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 10911 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10912 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10913 | } |
| 10914 | |
| 10915 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10916 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 10917 | * @phba: Pointer to HBA context object. |
| 10918 | * @wcqe: Pointer to work-queue completion queue entry. |
| 10919 | * |
| 10920 | * This routine handles an ELS work-queue completion event and construct |
| 10921 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 10922 | * discovery engine to handle. |
| 10923 | * |
| 10924 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 10925 | **/ |
| 10926 | static struct lpfc_iocbq * |
| 10927 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 10928 | struct lpfc_iocbq *irspiocbq) |
| 10929 | { |
| 10930 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 10931 | struct lpfc_iocbq *cmdiocbq; |
| 10932 | struct lpfc_wcqe_complete *wcqe; |
| 10933 | unsigned long iflags; |
| 10934 | |
| 10935 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
| 10936 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10937 | pring->stats.iocb_event++; |
| 10938 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 10939 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 10940 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10941 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10942 | |
| 10943 | if (unlikely(!cmdiocbq)) { |
| 10944 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10945 | "0386 ELS complete with no corresponding " |
| 10946 | "cmdiocb: iotag (%d)\n", |
| 10947 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10948 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 10949 | return NULL; |
| 10950 | } |
| 10951 | |
| 10952 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10953 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10954 | |
| 10955 | return irspiocbq; |
| 10956 | } |
| 10957 | |
| 10958 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10959 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 10960 | * @phba: Pointer to HBA context object. |
| 10961 | * @cqe: Pointer to mailbox completion queue entry. |
| 10962 | * |
| 10963 | * This routine process a mailbox completion queue entry with asynchrous |
| 10964 | * event. |
| 10965 | * |
| 10966 | * Return: true if work posted to worker thread, otherwise false. |
| 10967 | **/ |
| 10968 | static bool |
| 10969 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 10970 | { |
| 10971 | struct lpfc_cq_event *cq_event; |
| 10972 | unsigned long iflags; |
| 10973 | |
| 10974 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10975 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 10976 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 10977 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 10978 | |
| 10979 | /* Allocate a new internal CQ_EVENT entry */ |
| 10980 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 10981 | if (!cq_event) { |
| 10982 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 10983 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 10984 | return false; |
| 10985 | } |
| 10986 | |
| 10987 | /* Move the CQE into an asynchronous event entry */ |
| 10988 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 10989 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10990 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 10991 | /* Set the async event flag */ |
| 10992 | phba->hba_flag |= ASYNC_EVENT; |
| 10993 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10994 | |
| 10995 | return true; |
| 10996 | } |
| 10997 | |
| 10998 | /** |
| 10999 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11000 | * @phba: Pointer to HBA context object. |
| 11001 | * @cqe: Pointer to mailbox completion queue entry. |
| 11002 | * |
| 11003 | * This routine process a mailbox completion queue entry with mailbox |
| 11004 | * completion event. |
| 11005 | * |
| 11006 | * Return: true if work posted to worker thread, otherwise false. |
| 11007 | **/ |
| 11008 | static bool |
| 11009 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11010 | { |
| 11011 | uint32_t mcqe_status; |
| 11012 | MAILBOX_t *mbox, *pmbox; |
| 11013 | struct lpfc_mqe *mqe; |
| 11014 | struct lpfc_vport *vport; |
| 11015 | struct lpfc_nodelist *ndlp; |
| 11016 | struct lpfc_dmabuf *mp; |
| 11017 | unsigned long iflags; |
| 11018 | LPFC_MBOXQ_t *pmb; |
| 11019 | bool workposted = false; |
| 11020 | int rc; |
| 11021 | |
| 11022 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11023 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11024 | goto out_no_mqe_complete; |
| 11025 | |
| 11026 | /* Get the reference to the active mbox command */ |
| 11027 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11028 | pmb = phba->sli.mbox_active; |
| 11029 | if (unlikely(!pmb)) { |
| 11030 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11031 | "1832 No pending MBOX command to handle\n"); |
| 11032 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11033 | goto out_no_mqe_complete; |
| 11034 | } |
| 11035 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11036 | mqe = &pmb->u.mqe; |
| 11037 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11038 | mbox = phba->mbox; |
| 11039 | vport = pmb->vport; |
| 11040 | |
| 11041 | /* Reset heartbeat timer */ |
| 11042 | phba->last_completion_time = jiffies; |
| 11043 | del_timer(&phba->sli.mbox_tmo); |
| 11044 | |
| 11045 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11046 | if (pmb->mbox_cmpl && mbox) |
| 11047 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11048 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11049 | /* |
| 11050 | * For mcqe errors, conditionally move a modified error code to |
| 11051 | * the mbox so that the error will not be missed. |
| 11052 | */ |
| 11053 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11054 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11055 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11056 | bf_set(lpfc_mqe_status, mqe, |
| 11057 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11058 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11059 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11060 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11061 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11062 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11063 | mcqe_status, |
| 11064 | pmbox->un.varWords[0], 0); |
| 11065 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11066 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11067 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11068 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11069 | * RID of the PPI using the same mbox buffer. |
| 11070 | */ |
| 11071 | lpfc_unreg_login(phba, vport->vpi, |
| 11072 | pmbox->un.varWords[0], pmb); |
| 11073 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11074 | pmb->context1 = mp; |
| 11075 | pmb->context2 = ndlp; |
| 11076 | pmb->vport = vport; |
| 11077 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11078 | if (rc != MBX_BUSY) |
| 11079 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11080 | LOG_SLI, "0385 rc should " |
| 11081 | "have been MBX_BUSY\n"); |
| 11082 | if (rc != MBX_NOT_FINISHED) |
| 11083 | goto send_current_mbox; |
| 11084 | } |
| 11085 | } |
| 11086 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11087 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11088 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11089 | |
| 11090 | /* There is mailbox completion work to do */ |
| 11091 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11092 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11093 | phba->work_ha |= HA_MBATT; |
| 11094 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11095 | workposted = true; |
| 11096 | |
| 11097 | send_current_mbox: |
| 11098 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11099 | /* Release the mailbox command posting token */ |
| 11100 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11101 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11102 | phba->sli.mbox_active = NULL; |
| 11103 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11104 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11105 | lpfc_worker_wake_up(phba); |
| 11106 | out_no_mqe_complete: |
| 11107 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11108 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11109 | return workposted; |
| 11110 | } |
| 11111 | |
| 11112 | /** |
| 11113 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11114 | * @phba: Pointer to HBA context object. |
| 11115 | * @cqe: Pointer to mailbox completion queue entry. |
| 11116 | * |
| 11117 | * This routine process a mailbox completion queue entry, it invokes the |
| 11118 | * proper mailbox complete handling or asynchrous event handling routine |
| 11119 | * according to the MCQE's async bit. |
| 11120 | * |
| 11121 | * Return: true if work posted to worker thread, otherwise false. |
| 11122 | **/ |
| 11123 | static bool |
| 11124 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11125 | { |
| 11126 | struct lpfc_mcqe mcqe; |
| 11127 | bool workposted; |
| 11128 | |
| 11129 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11130 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11131 | |
| 11132 | /* Invoke the proper event handling routine */ |
| 11133 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11134 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11135 | else |
| 11136 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11137 | return workposted; |
| 11138 | } |
| 11139 | |
| 11140 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11141 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11142 | * @phba: Pointer to HBA context object. |
| 11143 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11144 | * |
| 11145 | * This routine handles an ELS work-queue completion event. |
| 11146 | * |
| 11147 | * Return: true if work posted to worker thread, otherwise false. |
| 11148 | **/ |
| 11149 | static bool |
| 11150 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, |
| 11151 | struct lpfc_wcqe_complete *wcqe) |
| 11152 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11153 | struct lpfc_iocbq *irspiocbq; |
| 11154 | unsigned long iflags; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11155 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11156 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11157 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11158 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11159 | if (!irspiocbq) { |
| 11160 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11161 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11162 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
| 11163 | pring->txq_cnt, phba->iocb_cnt, |
| 11164 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, |
| 11165 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11166 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11167 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11168 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11169 | /* Save off the slow-path queue event for work thread to process */ |
| 11170 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11171 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11172 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11173 | &phba->sli4_hba.sp_queue_event); |
| 11174 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11175 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11176 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11177 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11178 | } |
| 11179 | |
| 11180 | /** |
| 11181 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11182 | * @phba: Pointer to HBA context object. |
| 11183 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11184 | * |
| 11185 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11186 | * proper WQ release routine to the slow-path WQ. |
| 11187 | **/ |
| 11188 | static void |
| 11189 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11190 | struct lpfc_wcqe_release *wcqe) |
| 11191 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11192 | /* sanity check on queue memory */ |
| 11193 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11194 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11195 | /* Check for the slow-path ELS work queue */ |
| 11196 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11197 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11198 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11199 | else |
| 11200 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11201 | "2579 Slow-path wqe consume event carries " |
| 11202 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11203 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11204 | phba->sli4_hba.els_wq->queue_id); |
| 11205 | } |
| 11206 | |
| 11207 | /** |
| 11208 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11209 | * @phba: Pointer to HBA context object. |
| 11210 | * @cq: Pointer to a WQ completion queue. |
| 11211 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11212 | * |
| 11213 | * This routine handles an XRI abort event. |
| 11214 | * |
| 11215 | * Return: true if work posted to worker thread, otherwise false. |
| 11216 | **/ |
| 11217 | static bool |
| 11218 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11219 | struct lpfc_queue *cq, |
| 11220 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11221 | { |
| 11222 | bool workposted = false; |
| 11223 | struct lpfc_cq_event *cq_event; |
| 11224 | unsigned long iflags; |
| 11225 | |
| 11226 | /* Allocate a new internal CQ_EVENT entry */ |
| 11227 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11228 | if (!cq_event) { |
| 11229 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11230 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11231 | return false; |
| 11232 | } |
| 11233 | |
| 11234 | /* Move the CQE into the proper xri abort event list */ |
| 11235 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11236 | switch (cq->subtype) { |
| 11237 | case LPFC_FCP: |
| 11238 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11239 | list_add_tail(&cq_event->list, |
| 11240 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11241 | /* Set the fcp xri abort event flag */ |
| 11242 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11243 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11244 | workposted = true; |
| 11245 | break; |
| 11246 | case LPFC_ELS: |
| 11247 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11248 | list_add_tail(&cq_event->list, |
| 11249 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11250 | /* Set the els xri abort event flag */ |
| 11251 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11252 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11253 | workposted = true; |
| 11254 | break; |
| 11255 | default: |
| 11256 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11257 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11258 | cq->subtype); |
| 11259 | workposted = false; |
| 11260 | break; |
| 11261 | } |
| 11262 | return workposted; |
| 11263 | } |
| 11264 | |
| 11265 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11266 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11267 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11268 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11269 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11270 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11271 | * |
| 11272 | * Return: true if work posted to worker thread, otherwise false. |
| 11273 | **/ |
| 11274 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11275 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11276 | { |
| 11277 | bool workposted = false; |
| 11278 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11279 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11280 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11281 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11282 | unsigned long iflags; |
| 11283 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11284 | /* sanity check on queue memory */ |
| 11285 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11286 | return workposted; |
| 11287 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11288 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11289 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11290 | else |
| 11291 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11292 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11293 | goto out; |
| 11294 | |
| 11295 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11296 | switch (status) { |
| 11297 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11298 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11299 | "2537 Receive Frame Truncated!!\n"); |
| 11300 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11301 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11302 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11303 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11304 | if (!dma_buf) { |
| 11305 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11306 | goto out; |
| 11307 | } |
| 11308 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11309 | /* save off the frame for the word thread to process */ |
| 11310 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11311 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11312 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11313 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11314 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11315 | workposted = true; |
| 11316 | break; |
| 11317 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11318 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
| 11319 | /* Post more buffers if possible */ |
| 11320 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11321 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11322 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11323 | workposted = true; |
| 11324 | break; |
| 11325 | } |
| 11326 | out: |
| 11327 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11328 | } |
| 11329 | |
| 11330 | /** |
| 11331 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11332 | * @phba: Pointer to HBA context object. |
| 11333 | * @cq: Pointer to the completion queue. |
| 11334 | * @wcqe: Pointer to a completion queue entry. |
| 11335 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11336 | * 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] | 11337 | * entry. |
| 11338 | * |
| 11339 | * Return: true if work posted to worker thread, otherwise false. |
| 11340 | **/ |
| 11341 | static bool |
| 11342 | 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] | 11343 | struct lpfc_cqe *cqe) |
| 11344 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11345 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11346 | bool workposted = false; |
| 11347 | |
| 11348 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11349 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11350 | |
| 11351 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11352 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11353 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11354 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11355 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11356 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11357 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11358 | break; |
| 11359 | case CQE_CODE_RELEASE_WQE: |
| 11360 | /* Process the WQ release event */ |
| 11361 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11362 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11363 | break; |
| 11364 | case CQE_CODE_XRI_ABORTED: |
| 11365 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11366 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11367 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11368 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11369 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11370 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11371 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11372 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11373 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11374 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11375 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11376 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11377 | default: |
| 11378 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11379 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11380 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11381 | break; |
| 11382 | } |
| 11383 | return workposted; |
| 11384 | } |
| 11385 | |
| 11386 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11387 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11388 | * @phba: Pointer to HBA context object. |
| 11389 | * @eqe: Pointer to fast-path event queue entry. |
| 11390 | * |
| 11391 | * This routine process a event queue entry from the slow-path event queue. |
| 11392 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11393 | * completion event on a completion queue, if not, an error shall be logged |
| 11394 | * and just return. Otherwise, it will get to the corresponding completion |
| 11395 | * queue and process all the entries on that completion queue, rearm the |
| 11396 | * completion queue, and then return. |
| 11397 | * |
| 11398 | **/ |
| 11399 | static void |
| 11400 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 11401 | { |
| 11402 | struct lpfc_queue *cq = NULL, *childq, *speq; |
| 11403 | struct lpfc_cqe *cqe; |
| 11404 | bool workposted = false; |
| 11405 | int ecount = 0; |
| 11406 | uint16_t cqid; |
| 11407 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11408 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11409 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11410 | "0359 Not a valid slow-path completion " |
| 11411 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11412 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11413 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11414 | return; |
| 11415 | } |
| 11416 | |
| 11417 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11418 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11419 | |
| 11420 | /* Search for completion queue pointer matching this cqid */ |
| 11421 | speq = phba->sli4_hba.sp_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11422 | /* sanity check on queue memory */ |
| 11423 | if (unlikely(!speq)) |
| 11424 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11425 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11426 | if (childq->queue_id == cqid) { |
| 11427 | cq = childq; |
| 11428 | break; |
| 11429 | } |
| 11430 | } |
| 11431 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11432 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11433 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11434 | "0365 Slow-path CQ identifier " |
| 11435 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11436 | return; |
| 11437 | } |
| 11438 | |
| 11439 | /* Process all the entries to the CQ */ |
| 11440 | switch (cq->type) { |
| 11441 | case LPFC_MCQ: |
| 11442 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11443 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11444 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11445 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11446 | } |
| 11447 | break; |
| 11448 | case LPFC_WCQ: |
| 11449 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11450 | if (cq->subtype == LPFC_FCP) |
| 11451 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11452 | cqe); |
| 11453 | else |
| 11454 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11455 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11456 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11457 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11458 | } |
| 11459 | break; |
| 11460 | default: |
| 11461 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11462 | "0370 Invalid completion queue type (%d)\n", |
| 11463 | cq->type); |
| 11464 | return; |
| 11465 | } |
| 11466 | |
| 11467 | /* Catch the no cq entry condition, log an error */ |
| 11468 | if (unlikely(ecount == 0)) |
| 11469 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11470 | "0371 No entry from the CQ: identifier " |
| 11471 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11472 | |
| 11473 | /* In any case, flash and re-arm the RCQ */ |
| 11474 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11475 | |
| 11476 | /* wake up worker thread if there are works to be done */ |
| 11477 | if (workposted) |
| 11478 | lpfc_worker_wake_up(phba); |
| 11479 | } |
| 11480 | |
| 11481 | /** |
| 11482 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry |
| 11483 | * @eqe: Pointer to fast-path completion queue entry. |
| 11484 | * |
| 11485 | * This routine process a fast-path work queue completion entry from fast-path |
| 11486 | * event queue for FCP command response completion. |
| 11487 | **/ |
| 11488 | static void |
| 11489 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, |
| 11490 | struct lpfc_wcqe_complete *wcqe) |
| 11491 | { |
| 11492 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
| 11493 | struct lpfc_iocbq *cmdiocbq; |
| 11494 | struct lpfc_iocbq irspiocbq; |
| 11495 | unsigned long iflags; |
| 11496 | |
| 11497 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11498 | pring->stats.iocb_event++; |
| 11499 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11500 | |
| 11501 | /* Check for response status */ |
| 11502 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11503 | /* If resource errors reported from HBA, reduce queue |
| 11504 | * depth of the SCSI device. |
| 11505 | */ |
| 11506 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11507 | IOSTAT_LOCAL_REJECT) && |
| 11508 | (wcqe->parameter == IOERR_NO_RESOURCES)) { |
| 11509 | phba->lpfc_rampdown_queue_depth(phba); |
| 11510 | } |
| 11511 | /* Log the error status */ |
| 11512 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11513 | "0373 FCP complete error: status=x%x, " |
| 11514 | "hw_status=x%x, total_data_specified=%d, " |
| 11515 | "parameter=x%x, word3=x%x\n", |
| 11516 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11517 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11518 | wcqe->total_data_placed, wcqe->parameter, |
| 11519 | wcqe->word3); |
| 11520 | } |
| 11521 | |
| 11522 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
| 11523 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11524 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11525 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11526 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11527 | if (unlikely(!cmdiocbq)) { |
| 11528 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11529 | "0374 FCP complete with no corresponding " |
| 11530 | "cmdiocb: iotag (%d)\n", |
| 11531 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11532 | return; |
| 11533 | } |
| 11534 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11535 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11536 | "0375 FCP cmdiocb not callback function " |
| 11537 | "iotag: (%d)\n", |
| 11538 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11539 | return; |
| 11540 | } |
| 11541 | |
| 11542 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11543 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11544 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11545 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11546 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11547 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11548 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11549 | } |
| 11550 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11551 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11552 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11553 | } |
| 11554 | |
| 11555 | /** |
| 11556 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11557 | * @phba: Pointer to HBA context object. |
| 11558 | * @cq: Pointer to completion queue. |
| 11559 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11560 | * |
| 11561 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11562 | * proper WQ release routine to the slow-path WQ. |
| 11563 | **/ |
| 11564 | static void |
| 11565 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11566 | struct lpfc_wcqe_release *wcqe) |
| 11567 | { |
| 11568 | struct lpfc_queue *childwq; |
| 11569 | bool wqid_matched = false; |
| 11570 | uint16_t fcp_wqid; |
| 11571 | |
| 11572 | /* Check for fast-path FCP work queue release */ |
| 11573 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11574 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11575 | if (childwq->queue_id == fcp_wqid) { |
| 11576 | lpfc_sli4_wq_release(childwq, |
| 11577 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11578 | wqid_matched = true; |
| 11579 | break; |
| 11580 | } |
| 11581 | } |
| 11582 | /* Report warning log message if no match found */ |
| 11583 | if (wqid_matched != true) |
| 11584 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11585 | "2580 Fast-path wqe consume event carries " |
| 11586 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11587 | } |
| 11588 | |
| 11589 | /** |
| 11590 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11591 | * @cq: Pointer to the completion queue. |
| 11592 | * @eqe: Pointer to fast-path completion queue entry. |
| 11593 | * |
| 11594 | * This routine process a fast-path work queue completion entry from fast-path |
| 11595 | * event queue for FCP command response completion. |
| 11596 | **/ |
| 11597 | static int |
| 11598 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11599 | struct lpfc_cqe *cqe) |
| 11600 | { |
| 11601 | struct lpfc_wcqe_release wcqe; |
| 11602 | bool workposted = false; |
| 11603 | |
| 11604 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11605 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11606 | |
| 11607 | /* Check and process for different type of WCQE and dispatch */ |
| 11608 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11609 | case CQE_CODE_COMPL_WQE: |
| 11610 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11611 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11612 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
| 11613 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11614 | break; |
| 11615 | case CQE_CODE_RELEASE_WQE: |
| 11616 | /* Process the WQ release event */ |
| 11617 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11618 | (struct lpfc_wcqe_release *)&wcqe); |
| 11619 | break; |
| 11620 | case CQE_CODE_XRI_ABORTED: |
| 11621 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11622 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11623 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11624 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11625 | break; |
| 11626 | default: |
| 11627 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11628 | "0144 Not a valid WCQE code: x%x\n", |
| 11629 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11630 | break; |
| 11631 | } |
| 11632 | return workposted; |
| 11633 | } |
| 11634 | |
| 11635 | /** |
| 11636 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry |
| 11637 | * @phba: Pointer to HBA context object. |
| 11638 | * @eqe: Pointer to fast-path event queue entry. |
| 11639 | * |
| 11640 | * This routine process a event queue entry from the fast-path event queue. |
| 11641 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11642 | * completion event on a completion queue, if not, an error shall be logged |
| 11643 | * and just return. Otherwise, it will get to the corresponding completion |
| 11644 | * queue and process all the entries on the completion queue, rearm the |
| 11645 | * completion queue, and then return. |
| 11646 | **/ |
| 11647 | static void |
| 11648 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11649 | uint32_t fcp_cqidx) |
| 11650 | { |
| 11651 | struct lpfc_queue *cq; |
| 11652 | struct lpfc_cqe *cqe; |
| 11653 | bool workposted = false; |
| 11654 | uint16_t cqid; |
| 11655 | int ecount = 0; |
| 11656 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11657 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11658 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11659 | "0366 Not a valid fast-path completion " |
| 11660 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11661 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11662 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11663 | return; |
| 11664 | } |
| 11665 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11666 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11667 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11668 | "3146 Fast-path completion queues " |
| 11669 | "does not exist\n"); |
| 11670 | return; |
| 11671 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11672 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; |
| 11673 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11674 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11675 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11676 | "0367 Fast-path completion queue " |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11677 | "(%d) does not exist\n", fcp_cqidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11678 | return; |
| 11679 | } |
| 11680 | |
| 11681 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11682 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11683 | if (unlikely(cqid != cq->queue_id)) { |
| 11684 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11685 | "0368 Miss-matched fast-path completion " |
| 11686 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11687 | cqid, cq->queue_id); |
| 11688 | return; |
| 11689 | } |
| 11690 | |
| 11691 | /* Process all the entries to the CQ */ |
| 11692 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11693 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11694 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11695 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11696 | } |
| 11697 | |
| 11698 | /* Catch the no cq entry condition */ |
| 11699 | if (unlikely(ecount == 0)) |
| 11700 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11701 | "0369 No entry from fast-path completion " |
| 11702 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11703 | |
| 11704 | /* In any case, flash and re-arm the CQ */ |
| 11705 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11706 | |
| 11707 | /* wake up worker thread if there are works to be done */ |
| 11708 | if (workposted) |
| 11709 | lpfc_worker_wake_up(phba); |
| 11710 | } |
| 11711 | |
| 11712 | static void |
| 11713 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11714 | { |
| 11715 | struct lpfc_eqe *eqe; |
| 11716 | |
| 11717 | /* walk all the EQ entries and drop on the floor */ |
| 11718 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11719 | ; |
| 11720 | |
| 11721 | /* Clear and re-arm the EQ */ |
| 11722 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11723 | } |
| 11724 | |
| 11725 | /** |
| 11726 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device |
| 11727 | * @irq: Interrupt number. |
| 11728 | * @dev_id: The device context pointer. |
| 11729 | * |
| 11730 | * This function is directly called from the PCI layer as an interrupt |
| 11731 | * service routine when device with SLI-4 interface spec is enabled with |
| 11732 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11733 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11734 | * interrupt mode, this function is called as part of the device-level |
| 11735 | * interrupt handler. When the PCI slot is in error recovery or the HBA is |
| 11736 | * undergoing initialization, the interrupt handler will not process the |
| 11737 | * interrupt. The link attention and ELS ring attention events are handled |
| 11738 | * by the worker thread. The interrupt handler signals the worker thread |
| 11739 | * and returns for these events. This function is called without any lock |
| 11740 | * held. It gets the hbalock to access and update SLI data structures. |
| 11741 | * |
| 11742 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11743 | * returns IRQ_NONE. |
| 11744 | **/ |
| 11745 | irqreturn_t |
| 11746 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) |
| 11747 | { |
| 11748 | struct lpfc_hba *phba; |
| 11749 | struct lpfc_queue *speq; |
| 11750 | struct lpfc_eqe *eqe; |
| 11751 | unsigned long iflag; |
| 11752 | int ecount = 0; |
| 11753 | |
| 11754 | /* |
| 11755 | * Get the driver's phba structure from the dev_id |
| 11756 | */ |
| 11757 | phba = (struct lpfc_hba *)dev_id; |
| 11758 | |
| 11759 | if (unlikely(!phba)) |
| 11760 | return IRQ_NONE; |
| 11761 | |
| 11762 | /* Get to the EQ struct associated with this vector */ |
| 11763 | speq = phba->sli4_hba.sp_eq; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11764 | if (unlikely(!speq)) |
| 11765 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11766 | |
| 11767 | /* Check device state for handling interrupt */ |
| 11768 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 11769 | /* Check again for link_state with lock held */ |
| 11770 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11771 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11772 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11773 | lpfc_sli4_eq_flush(phba, speq); |
| 11774 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11775 | return IRQ_NONE; |
| 11776 | } |
| 11777 | |
| 11778 | /* |
| 11779 | * Process all the event on FCP slow-path EQ |
| 11780 | */ |
| 11781 | while ((eqe = lpfc_sli4_eq_get(speq))) { |
| 11782 | lpfc_sli4_sp_handle_eqe(phba, eqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11783 | if (!(++ecount % speq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11784 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); |
| 11785 | } |
| 11786 | |
| 11787 | /* Always clear and re-arm the slow-path EQ */ |
| 11788 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); |
| 11789 | |
| 11790 | /* Catch the no cq entry condition */ |
| 11791 | if (unlikely(ecount == 0)) { |
| 11792 | if (phba->intr_type == MSIX) |
| 11793 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11794 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11795 | "0357 MSI-X interrupt with no EQE\n"); |
| 11796 | else |
| 11797 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11798 | return IRQ_NONE; |
| 11799 | } |
| 11800 | |
| 11801 | return IRQ_HANDLED; |
| 11802 | } /* lpfc_sli4_sp_intr_handler */ |
| 11803 | |
| 11804 | /** |
| 11805 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device |
| 11806 | * @irq: Interrupt number. |
| 11807 | * @dev_id: The device context pointer. |
| 11808 | * |
| 11809 | * This function is directly called from the PCI layer as an interrupt |
| 11810 | * service routine when device with SLI-4 interface spec is enabled with |
| 11811 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11812 | * ring event in the HBA. However, when the device is enabled with either |
| 11813 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11814 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11815 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11816 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11817 | * the intrrupt context. This function is called without any lock held. |
| 11818 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11819 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11820 | * equal to that of FCP CQ index. |
| 11821 | * |
| 11822 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11823 | * returns IRQ_NONE. |
| 11824 | **/ |
| 11825 | irqreturn_t |
| 11826 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) |
| 11827 | { |
| 11828 | struct lpfc_hba *phba; |
| 11829 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11830 | struct lpfc_queue *fpeq; |
| 11831 | struct lpfc_eqe *eqe; |
| 11832 | unsigned long iflag; |
| 11833 | int ecount = 0; |
| 11834 | uint32_t fcp_eqidx; |
| 11835 | |
| 11836 | /* Get the driver's phba structure from the dev_id */ |
| 11837 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11838 | phba = fcp_eq_hdl->phba; |
| 11839 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11840 | |
| 11841 | if (unlikely(!phba)) |
| 11842 | return IRQ_NONE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11843 | if (unlikely(!phba->sli4_hba.fp_eq)) |
| 11844 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11845 | |
| 11846 | /* Get to the EQ struct associated with this vector */ |
| 11847 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11848 | if (unlikely(!fpeq)) |
| 11849 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11850 | |
| 11851 | /* Check device state for handling interrupt */ |
| 11852 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 11853 | /* Check again for link_state with lock held */ |
| 11854 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11855 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11856 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11857 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11858 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11859 | return IRQ_NONE; |
| 11860 | } |
| 11861 | |
| 11862 | /* |
| 11863 | * Process all the event on FCP fast-path EQ |
| 11864 | */ |
| 11865 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 11866 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11867 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11868 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
| 11869 | } |
| 11870 | |
| 11871 | /* Always clear and re-arm the fast-path EQ */ |
| 11872 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11873 | |
| 11874 | if (unlikely(ecount == 0)) { |
| 11875 | if (phba->intr_type == MSIX) |
| 11876 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11877 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11878 | "0358 MSI-X interrupt with no EQE\n"); |
| 11879 | else |
| 11880 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11881 | return IRQ_NONE; |
| 11882 | } |
| 11883 | |
| 11884 | return IRQ_HANDLED; |
| 11885 | } /* lpfc_sli4_fp_intr_handler */ |
| 11886 | |
| 11887 | /** |
| 11888 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 11889 | * @irq: Interrupt number. |
| 11890 | * @dev_id: The device context pointer. |
| 11891 | * |
| 11892 | * This function is the device-level interrupt handler to device with SLI-4 |
| 11893 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 11894 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 11895 | * driver attention. This function invokes the slow-path interrupt attention |
| 11896 | * handling function and fast-path interrupt attention handling function in |
| 11897 | * turn to process the relevant HBA attention events. This function is called |
| 11898 | * without any lock held. It gets the hbalock to access and update SLI data |
| 11899 | * structures. |
| 11900 | * |
| 11901 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11902 | * returns IRQ_NONE. |
| 11903 | **/ |
| 11904 | irqreturn_t |
| 11905 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 11906 | { |
| 11907 | struct lpfc_hba *phba; |
| 11908 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11909 | bool fp_handled = false; |
| 11910 | uint32_t fcp_eqidx; |
| 11911 | |
| 11912 | /* Get the driver's phba structure from the dev_id */ |
| 11913 | phba = (struct lpfc_hba *)dev_id; |
| 11914 | |
| 11915 | if (unlikely(!phba)) |
| 11916 | return IRQ_NONE; |
| 11917 | |
| 11918 | /* |
| 11919 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11920 | */ |
| 11921 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); |
| 11922 | |
| 11923 | /* |
| 11924 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11925 | */ |
| 11926 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 11927 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, |
| 11928 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
| 11929 | if (fp_irq_rc == IRQ_HANDLED) |
| 11930 | fp_handled |= true; |
| 11931 | } |
| 11932 | |
| 11933 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; |
| 11934 | } /* lpfc_sli4_intr_handler */ |
| 11935 | |
| 11936 | /** |
| 11937 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 11938 | * @queue: The queue structure to free. |
| 11939 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 11940 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11941 | * the host resident queue. This function must be called after destroying the |
| 11942 | * queue on the HBA. |
| 11943 | **/ |
| 11944 | void |
| 11945 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 11946 | { |
| 11947 | struct lpfc_dmabuf *dmabuf; |
| 11948 | |
| 11949 | if (!queue) |
| 11950 | return; |
| 11951 | |
| 11952 | while (!list_empty(&queue->page_list)) { |
| 11953 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 11954 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 11955 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11956 | dmabuf->virt, dmabuf->phys); |
| 11957 | kfree(dmabuf); |
| 11958 | } |
| 11959 | kfree(queue); |
| 11960 | return; |
| 11961 | } |
| 11962 | |
| 11963 | /** |
| 11964 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 11965 | * @phba: The HBA that this queue is being created on. |
| 11966 | * @entry_size: The size of each queue entry for this queue. |
| 11967 | * @entry count: The number of entries that this queue will handle. |
| 11968 | * |
| 11969 | * This function allocates a queue structure and the DMAable memory used for |
| 11970 | * the host resident queue. This function must be called before creating the |
| 11971 | * queue on the HBA. |
| 11972 | **/ |
| 11973 | struct lpfc_queue * |
| 11974 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 11975 | uint32_t entry_count) |
| 11976 | { |
| 11977 | struct lpfc_queue *queue; |
| 11978 | struct lpfc_dmabuf *dmabuf; |
| 11979 | int x, total_qe_count; |
| 11980 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11981 | 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] | 11982 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11983 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 11984 | hw_page_size = SLI4_PAGE_SIZE; |
| 11985 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11986 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 11987 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 11988 | if (!queue) |
| 11989 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11990 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 11991 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11992 | INIT_LIST_HEAD(&queue->list); |
| 11993 | INIT_LIST_HEAD(&queue->page_list); |
| 11994 | INIT_LIST_HEAD(&queue->child_list); |
| 11995 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 11996 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 11997 | if (!dmabuf) |
| 11998 | goto out_fail; |
| 11999 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12000 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12001 | GFP_KERNEL); |
| 12002 | if (!dmabuf->virt) { |
| 12003 | kfree(dmabuf); |
| 12004 | goto out_fail; |
| 12005 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12006 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12007 | dmabuf->buffer_tag = x; |
| 12008 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12009 | /* initialize queue's entry array */ |
| 12010 | dma_pointer = dmabuf->virt; |
| 12011 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12012 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12013 | total_qe_count++, dma_pointer += entry_size) { |
| 12014 | queue->qe[total_qe_count].address = dma_pointer; |
| 12015 | } |
| 12016 | } |
| 12017 | queue->entry_size = entry_size; |
| 12018 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12019 | |
| 12020 | /* |
| 12021 | * entry_repost is calculated based on the number of entries in the |
| 12022 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12023 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12024 | */ |
| 12025 | queue->entry_repost = (entry_count >> 3); |
| 12026 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12027 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12028 | queue->phba = phba; |
| 12029 | |
| 12030 | return queue; |
| 12031 | out_fail: |
| 12032 | lpfc_sli4_queue_free(queue); |
| 12033 | return NULL; |
| 12034 | } |
| 12035 | |
| 12036 | /** |
| 12037 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12038 | * @phba: HBA structure that indicates port to create a queue on. |
| 12039 | * @eq: The queue structure to use to create the event queue. |
| 12040 | * @imax: The maximum interrupt per second limit. |
| 12041 | * |
| 12042 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12043 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12044 | * |
| 12045 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12046 | * is used to get the entry count and entry size that are necessary to |
| 12047 | * determine the number of pages to allocate and use for this queue. This |
| 12048 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12049 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12050 | * command to finish before continuing. |
| 12051 | * |
| 12052 | * 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] | 12053 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12054 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12055 | **/ |
| 12056 | uint32_t |
| 12057 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) |
| 12058 | { |
| 12059 | struct lpfc_mbx_eq_create *eq_create; |
| 12060 | LPFC_MBOXQ_t *mbox; |
| 12061 | int rc, length, status = 0; |
| 12062 | struct lpfc_dmabuf *dmabuf; |
| 12063 | uint32_t shdr_status, shdr_add_status; |
| 12064 | union lpfc_sli4_cfg_shdr *shdr; |
| 12065 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12066 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12067 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12068 | /* sanity check on queue memory */ |
| 12069 | if (!eq) |
| 12070 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12071 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12072 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12073 | |
| 12074 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12075 | if (!mbox) |
| 12076 | return -ENOMEM; |
| 12077 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12078 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12079 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12080 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12081 | length, LPFC_SLI4_MBX_EMBED); |
| 12082 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12083 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12084 | eq->page_count); |
| 12085 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12086 | LPFC_EQE_SIZE); |
| 12087 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12088 | /* Calculate delay multiper from maximum interrupt per second */ |
| 12089 | dmult = LPFC_DMULT_CONST/imax - 1; |
| 12090 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12091 | dmult); |
| 12092 | switch (eq->entry_count) { |
| 12093 | default: |
| 12094 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12095 | "0360 Unsupported EQ count. (%d)\n", |
| 12096 | eq->entry_count); |
| 12097 | if (eq->entry_count < 256) |
| 12098 | return -EINVAL; |
| 12099 | /* otherwise default to smallest count (drop through) */ |
| 12100 | case 256: |
| 12101 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12102 | LPFC_EQ_CNT_256); |
| 12103 | break; |
| 12104 | case 512: |
| 12105 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12106 | LPFC_EQ_CNT_512); |
| 12107 | break; |
| 12108 | case 1024: |
| 12109 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12110 | LPFC_EQ_CNT_1024); |
| 12111 | break; |
| 12112 | case 2048: |
| 12113 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12114 | LPFC_EQ_CNT_2048); |
| 12115 | break; |
| 12116 | case 4096: |
| 12117 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12118 | LPFC_EQ_CNT_4096); |
| 12119 | break; |
| 12120 | } |
| 12121 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12122 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12123 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12124 | putPaddrLow(dmabuf->phys); |
| 12125 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12126 | putPaddrHigh(dmabuf->phys); |
| 12127 | } |
| 12128 | mbox->vport = phba->pport; |
| 12129 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12130 | mbox->context1 = NULL; |
| 12131 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12132 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12133 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12134 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12135 | if (shdr_status || shdr_add_status || rc) { |
| 12136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12137 | "2500 EQ_CREATE mailbox failed with " |
| 12138 | "status x%x add_status x%x, mbx status x%x\n", |
| 12139 | shdr_status, shdr_add_status, rc); |
| 12140 | status = -ENXIO; |
| 12141 | } |
| 12142 | eq->type = LPFC_EQ; |
| 12143 | eq->subtype = LPFC_NONE; |
| 12144 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12145 | if (eq->queue_id == 0xFFFF) |
| 12146 | status = -ENXIO; |
| 12147 | eq->host_index = 0; |
| 12148 | eq->hba_index = 0; |
| 12149 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12150 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12151 | return status; |
| 12152 | } |
| 12153 | |
| 12154 | /** |
| 12155 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12156 | * @phba: HBA structure that indicates port to create a queue on. |
| 12157 | * @cq: The queue structure to use to create the completion queue. |
| 12158 | * @eq: The event queue to bind this completion queue to. |
| 12159 | * |
| 12160 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12161 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12162 | * |
| 12163 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12164 | * is used to get the entry count and entry size that are necessary to |
| 12165 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12166 | * is used to indicate which event queue to bind this completion queue to. This |
| 12167 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12168 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12169 | * command to finish before continuing. |
| 12170 | * |
| 12171 | * 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] | 12172 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12173 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12174 | **/ |
| 12175 | uint32_t |
| 12176 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12177 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12178 | { |
| 12179 | struct lpfc_mbx_cq_create *cq_create; |
| 12180 | struct lpfc_dmabuf *dmabuf; |
| 12181 | LPFC_MBOXQ_t *mbox; |
| 12182 | int rc, length, status = 0; |
| 12183 | uint32_t shdr_status, shdr_add_status; |
| 12184 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12185 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12186 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12187 | /* sanity check on queue memory */ |
| 12188 | if (!cq || !eq) |
| 12189 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12190 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12191 | hw_page_size = SLI4_PAGE_SIZE; |
| 12192 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12193 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12194 | if (!mbox) |
| 12195 | return -ENOMEM; |
| 12196 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12197 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12198 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12199 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12200 | length, LPFC_SLI4_MBX_EMBED); |
| 12201 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12202 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12203 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12204 | cq->page_count); |
| 12205 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12206 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12207 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12208 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12209 | 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] | 12210 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12211 | 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] | 12212 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12213 | eq->queue_id); |
| 12214 | } else { |
| 12215 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12216 | eq->queue_id); |
| 12217 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12218 | switch (cq->entry_count) { |
| 12219 | default: |
| 12220 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12221 | "0361 Unsupported CQ count. (%d)\n", |
| 12222 | cq->entry_count); |
| 12223 | if (cq->entry_count < 256) |
| 12224 | return -EINVAL; |
| 12225 | /* otherwise default to smallest count (drop through) */ |
| 12226 | case 256: |
| 12227 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12228 | LPFC_CQ_CNT_256); |
| 12229 | break; |
| 12230 | case 512: |
| 12231 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12232 | LPFC_CQ_CNT_512); |
| 12233 | break; |
| 12234 | case 1024: |
| 12235 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12236 | LPFC_CQ_CNT_1024); |
| 12237 | break; |
| 12238 | } |
| 12239 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12240 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12241 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12242 | putPaddrLow(dmabuf->phys); |
| 12243 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12244 | putPaddrHigh(dmabuf->phys); |
| 12245 | } |
| 12246 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12247 | |
| 12248 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12249 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12250 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12251 | if (shdr_status || shdr_add_status || rc) { |
| 12252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12253 | "2501 CQ_CREATE mailbox failed with " |
| 12254 | "status x%x add_status x%x, mbx status x%x\n", |
| 12255 | shdr_status, shdr_add_status, rc); |
| 12256 | status = -ENXIO; |
| 12257 | goto out; |
| 12258 | } |
| 12259 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12260 | if (cq->queue_id == 0xFFFF) { |
| 12261 | status = -ENXIO; |
| 12262 | goto out; |
| 12263 | } |
| 12264 | /* link the cq onto the parent eq child list */ |
| 12265 | list_add_tail(&cq->list, &eq->child_list); |
| 12266 | /* Set up completion queue's type and subtype */ |
| 12267 | cq->type = type; |
| 12268 | cq->subtype = subtype; |
| 12269 | 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] | 12270 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12271 | cq->host_index = 0; |
| 12272 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12273 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12274 | out: |
| 12275 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12276 | return status; |
| 12277 | } |
| 12278 | |
| 12279 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12280 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12281 | * @phba: HBA structure that indicates port to create a queue on. |
| 12282 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12283 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12284 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12285 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12286 | * This function provides failback (fb) functionality when the |
| 12287 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12288 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12289 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12290 | * This routine cannot fail as all attributes were previously accessed and |
| 12291 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12292 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12293 | static void |
| 12294 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12295 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12296 | { |
| 12297 | struct lpfc_mbx_mq_create *mq_create; |
| 12298 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12299 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12300 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12301 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12302 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12303 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12304 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12305 | length, LPFC_SLI4_MBX_EMBED); |
| 12306 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12307 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12308 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12309 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12310 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12311 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12312 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12313 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12314 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12315 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12316 | break; |
| 12317 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12318 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12319 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12320 | break; |
| 12321 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12322 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12323 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12324 | break; |
| 12325 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12326 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12327 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12328 | break; |
| 12329 | } |
| 12330 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12331 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12332 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12333 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12334 | putPaddrHigh(dmabuf->phys); |
| 12335 | } |
| 12336 | } |
| 12337 | |
| 12338 | /** |
| 12339 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12340 | * @phba: HBA structure that indicates port to create a queue on. |
| 12341 | * @mq: The queue structure to use to create the mailbox queue. |
| 12342 | * @cq: The completion queue to associate with this cq. |
| 12343 | * @subtype: The queue's subtype. |
| 12344 | * |
| 12345 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12346 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12347 | * |
| 12348 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12349 | * is used to get the entry count and entry size that are necessary to |
| 12350 | * determine the number of pages to allocate and use for this queue. This |
| 12351 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12352 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12353 | * command to finish before continuing. |
| 12354 | * |
| 12355 | * 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] | 12356 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12357 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12358 | **/ |
| 12359 | int32_t |
| 12360 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12361 | struct lpfc_queue *cq, uint32_t subtype) |
| 12362 | { |
| 12363 | struct lpfc_mbx_mq_create *mq_create; |
| 12364 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12365 | struct lpfc_dmabuf *dmabuf; |
| 12366 | LPFC_MBOXQ_t *mbox; |
| 12367 | int rc, length, status = 0; |
| 12368 | uint32_t shdr_status, shdr_add_status; |
| 12369 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12370 | 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] | 12371 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12372 | /* sanity check on queue memory */ |
| 12373 | if (!mq || !cq) |
| 12374 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12375 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12376 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12377 | |
| 12378 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12379 | if (!mbox) |
| 12380 | return -ENOMEM; |
| 12381 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12382 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12383 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12384 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12385 | length, LPFC_SLI4_MBX_EMBED); |
| 12386 | |
| 12387 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12388 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12389 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12390 | &mq_create_ext->u.request, mq->page_count); |
| 12391 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12392 | &mq_create_ext->u.request, 1); |
| 12393 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12394 | &mq_create_ext->u.request, 1); |
| 12395 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12396 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12397 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12398 | &mq_create_ext->u.request, 1); |
| 12399 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12400 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12401 | 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] | 12402 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12403 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12404 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12405 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12406 | cq->queue_id); |
| 12407 | else |
| 12408 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12409 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12410 | switch (mq->entry_count) { |
| 12411 | default: |
| 12412 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12413 | "0362 Unsupported MQ count. (%d)\n", |
| 12414 | mq->entry_count); |
| 12415 | if (mq->entry_count < 16) |
| 12416 | return -EINVAL; |
| 12417 | /* otherwise default to smallest count (drop through) */ |
| 12418 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12419 | bf_set(lpfc_mq_context_ring_size, |
| 12420 | &mq_create_ext->u.request.context, |
| 12421 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12422 | break; |
| 12423 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12424 | bf_set(lpfc_mq_context_ring_size, |
| 12425 | &mq_create_ext->u.request.context, |
| 12426 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12427 | break; |
| 12428 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12429 | bf_set(lpfc_mq_context_ring_size, |
| 12430 | &mq_create_ext->u.request.context, |
| 12431 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12432 | break; |
| 12433 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12434 | bf_set(lpfc_mq_context_ring_size, |
| 12435 | &mq_create_ext->u.request.context, |
| 12436 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12437 | break; |
| 12438 | } |
| 12439 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12440 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12441 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12442 | putPaddrLow(dmabuf->phys); |
| 12443 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12444 | putPaddrHigh(dmabuf->phys); |
| 12445 | } |
| 12446 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12447 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12448 | &mq_create_ext->u.response); |
| 12449 | if (rc != MBX_SUCCESS) { |
| 12450 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12451 | "2795 MQ_CREATE_EXT failed with " |
| 12452 | "status x%x. Failback to MQ_CREATE.\n", |
| 12453 | rc); |
| 12454 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12455 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12456 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12457 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12458 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12459 | &mq_create->u.response); |
| 12460 | } |
| 12461 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12462 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12463 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12464 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12465 | if (shdr_status || shdr_add_status || rc) { |
| 12466 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12467 | "2502 MQ_CREATE mailbox failed with " |
| 12468 | "status x%x add_status x%x, mbx status x%x\n", |
| 12469 | shdr_status, shdr_add_status, rc); |
| 12470 | status = -ENXIO; |
| 12471 | goto out; |
| 12472 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12473 | if (mq->queue_id == 0xFFFF) { |
| 12474 | status = -ENXIO; |
| 12475 | goto out; |
| 12476 | } |
| 12477 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12478 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12479 | mq->subtype = subtype; |
| 12480 | mq->host_index = 0; |
| 12481 | mq->hba_index = 0; |
| 12482 | |
| 12483 | /* link the mq onto the parent cq child list */ |
| 12484 | list_add_tail(&mq->list, &cq->child_list); |
| 12485 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12486 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12487 | return status; |
| 12488 | } |
| 12489 | |
| 12490 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12491 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12492 | * @phba: HBA structure that indicates port to create a queue on. |
| 12493 | * @wq: The queue structure to use to create the work queue. |
| 12494 | * @cq: The completion queue to bind this work queue to. |
| 12495 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12496 | * |
| 12497 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12498 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12499 | * |
| 12500 | * The @phba struct is used to send mailbox command to HBA. The @wq 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. The @cq |
| 12503 | * is used to indicate which completion queue to bind this work queue to. This |
| 12504 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12505 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12506 | * command to finish before continuing. |
| 12507 | * |
| 12508 | * 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] | 12509 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12510 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12511 | **/ |
| 12512 | uint32_t |
| 12513 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12514 | struct lpfc_queue *cq, uint32_t subtype) |
| 12515 | { |
| 12516 | struct lpfc_mbx_wq_create *wq_create; |
| 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 | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12523 | struct dma_address *page; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12524 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12525 | /* sanity check on queue memory */ |
| 12526 | if (!wq || !cq) |
| 12527 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12528 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12529 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12530 | |
| 12531 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12532 | if (!mbox) |
| 12533 | return -ENOMEM; |
| 12534 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12535 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12536 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12537 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12538 | length, LPFC_SLI4_MBX_EMBED); |
| 12539 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12540 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12541 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12542 | wq->page_count); |
| 12543 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12544 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12545 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12546 | phba->sli4_hba.pc_sli4_params.wqv); |
| 12547 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12548 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12549 | wq->entry_count); |
| 12550 | switch (wq->entry_size) { |
| 12551 | default: |
| 12552 | case 64: |
| 12553 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12554 | &wq_create->u.request_1, |
| 12555 | LPFC_WQ_WQE_SIZE_64); |
| 12556 | break; |
| 12557 | case 128: |
| 12558 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12559 | &wq_create->u.request_1, |
| 12560 | LPFC_WQ_WQE_SIZE_128); |
| 12561 | break; |
| 12562 | } |
| 12563 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12564 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12565 | page = wq_create->u.request_1.page; |
| 12566 | } else { |
| 12567 | page = wq_create->u.request.page; |
| 12568 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12569 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12570 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12571 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12572 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12573 | } |
| 12574 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12575 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12576 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12577 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12578 | if (shdr_status || shdr_add_status || rc) { |
| 12579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12580 | "2503 WQ_CREATE mailbox failed with " |
| 12581 | "status x%x add_status x%x, mbx status x%x\n", |
| 12582 | shdr_status, shdr_add_status, rc); |
| 12583 | status = -ENXIO; |
| 12584 | goto out; |
| 12585 | } |
| 12586 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12587 | if (wq->queue_id == 0xFFFF) { |
| 12588 | status = -ENXIO; |
| 12589 | goto out; |
| 12590 | } |
| 12591 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12592 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12593 | wq->subtype = subtype; |
| 12594 | wq->host_index = 0; |
| 12595 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12596 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12597 | |
| 12598 | /* link the wq onto the parent cq child list */ |
| 12599 | list_add_tail(&wq->list, &cq->child_list); |
| 12600 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12601 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12602 | return status; |
| 12603 | } |
| 12604 | |
| 12605 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12606 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12607 | * @phba: HBA structure that indicates port to create a queue on. |
| 12608 | * @rq: The queue structure to use for the receive queue. |
| 12609 | * @qno: The associated HBQ number |
| 12610 | * |
| 12611 | * |
| 12612 | * For SLI4 we need to adjust the RQ repost value based on |
| 12613 | * the number of buffers that are initially posted to the RQ. |
| 12614 | */ |
| 12615 | void |
| 12616 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12617 | { |
| 12618 | uint32_t cnt; |
| 12619 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12620 | /* sanity check on queue memory */ |
| 12621 | if (!rq) |
| 12622 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12623 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12624 | |
| 12625 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12626 | cnt = (cnt >> 3); |
| 12627 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12628 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12629 | |
| 12630 | rq->entry_repost = cnt; |
| 12631 | } |
| 12632 | |
| 12633 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12634 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12635 | * @phba: HBA structure that indicates port to create a queue on. |
| 12636 | * @hrq: The queue structure to use to create the header receive queue. |
| 12637 | * @drq: The queue structure to use to create the data receive queue. |
| 12638 | * @cq: The completion queue to bind this work queue to. |
| 12639 | * |
| 12640 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12641 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12642 | * to the HBA. |
| 12643 | * |
| 12644 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12645 | * struct is used to get the entry count that is necessary to determine the |
| 12646 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12647 | * completion queue to bind received buffers that are posted to these queues to. |
| 12648 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12649 | * receive queue pair. This function is asynchronous and will wait for the |
| 12650 | * mailbox command to finish before continuing. |
| 12651 | * |
| 12652 | * 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] | 12653 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12654 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12655 | **/ |
| 12656 | uint32_t |
| 12657 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12658 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12659 | { |
| 12660 | struct lpfc_mbx_rq_create *rq_create; |
| 12661 | struct lpfc_dmabuf *dmabuf; |
| 12662 | LPFC_MBOXQ_t *mbox; |
| 12663 | int rc, length, status = 0; |
| 12664 | uint32_t shdr_status, shdr_add_status; |
| 12665 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12666 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12667 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12668 | /* sanity check on queue memory */ |
| 12669 | if (!hrq || !drq || !cq) |
| 12670 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12671 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12672 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12673 | |
| 12674 | if (hrq->entry_count != drq->entry_count) |
| 12675 | return -EINVAL; |
| 12676 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12677 | if (!mbox) |
| 12678 | return -ENOMEM; |
| 12679 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12680 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12681 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12682 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12683 | length, LPFC_SLI4_MBX_EMBED); |
| 12684 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12685 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12686 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12687 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12688 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12689 | bf_set(lpfc_rq_context_rqe_count_1, |
| 12690 | &rq_create->u.request.context, |
| 12691 | hrq->entry_count); |
| 12692 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12693 | bf_set(lpfc_rq_context_rqe_size, |
| 12694 | &rq_create->u.request.context, |
| 12695 | LPFC_RQE_SIZE_8); |
| 12696 | bf_set(lpfc_rq_context_page_size, |
| 12697 | &rq_create->u.request.context, |
| 12698 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12699 | } else { |
| 12700 | switch (hrq->entry_count) { |
| 12701 | default: |
| 12702 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12703 | "2535 Unsupported RQ count. (%d)\n", |
| 12704 | hrq->entry_count); |
| 12705 | if (hrq->entry_count < 512) |
| 12706 | return -EINVAL; |
| 12707 | /* otherwise default to smallest count (drop through) */ |
| 12708 | case 512: |
| 12709 | bf_set(lpfc_rq_context_rqe_count, |
| 12710 | &rq_create->u.request.context, |
| 12711 | LPFC_RQ_RING_SIZE_512); |
| 12712 | break; |
| 12713 | case 1024: |
| 12714 | bf_set(lpfc_rq_context_rqe_count, |
| 12715 | &rq_create->u.request.context, |
| 12716 | LPFC_RQ_RING_SIZE_1024); |
| 12717 | break; |
| 12718 | case 2048: |
| 12719 | bf_set(lpfc_rq_context_rqe_count, |
| 12720 | &rq_create->u.request.context, |
| 12721 | LPFC_RQ_RING_SIZE_2048); |
| 12722 | break; |
| 12723 | case 4096: |
| 12724 | bf_set(lpfc_rq_context_rqe_count, |
| 12725 | &rq_create->u.request.context, |
| 12726 | LPFC_RQ_RING_SIZE_4096); |
| 12727 | break; |
| 12728 | } |
| 12729 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12730 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12731 | } |
| 12732 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12733 | cq->queue_id); |
| 12734 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12735 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12736 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12737 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12738 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12739 | putPaddrLow(dmabuf->phys); |
| 12740 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12741 | putPaddrHigh(dmabuf->phys); |
| 12742 | } |
| 12743 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12744 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12745 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12746 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12747 | if (shdr_status || shdr_add_status || rc) { |
| 12748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12749 | "2504 RQ_CREATE mailbox failed with " |
| 12750 | "status x%x add_status x%x, mbx status x%x\n", |
| 12751 | shdr_status, shdr_add_status, rc); |
| 12752 | status = -ENXIO; |
| 12753 | goto out; |
| 12754 | } |
| 12755 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12756 | if (hrq->queue_id == 0xFFFF) { |
| 12757 | status = -ENXIO; |
| 12758 | goto out; |
| 12759 | } |
| 12760 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12761 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12762 | hrq->subtype = subtype; |
| 12763 | hrq->host_index = 0; |
| 12764 | hrq->hba_index = 0; |
| 12765 | |
| 12766 | /* now create the data queue */ |
| 12767 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12768 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12769 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12770 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12771 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12772 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12773 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12774 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12775 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12776 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 12777 | LPFC_RQE_SIZE_8); |
| 12778 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 12779 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12780 | } else { |
| 12781 | switch (drq->entry_count) { |
| 12782 | default: |
| 12783 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12784 | "2536 Unsupported RQ count. (%d)\n", |
| 12785 | drq->entry_count); |
| 12786 | if (drq->entry_count < 512) |
| 12787 | return -EINVAL; |
| 12788 | /* otherwise default to smallest count (drop through) */ |
| 12789 | case 512: |
| 12790 | bf_set(lpfc_rq_context_rqe_count, |
| 12791 | &rq_create->u.request.context, |
| 12792 | LPFC_RQ_RING_SIZE_512); |
| 12793 | break; |
| 12794 | case 1024: |
| 12795 | bf_set(lpfc_rq_context_rqe_count, |
| 12796 | &rq_create->u.request.context, |
| 12797 | LPFC_RQ_RING_SIZE_1024); |
| 12798 | break; |
| 12799 | case 2048: |
| 12800 | bf_set(lpfc_rq_context_rqe_count, |
| 12801 | &rq_create->u.request.context, |
| 12802 | LPFC_RQ_RING_SIZE_2048); |
| 12803 | break; |
| 12804 | case 4096: |
| 12805 | bf_set(lpfc_rq_context_rqe_count, |
| 12806 | &rq_create->u.request.context, |
| 12807 | LPFC_RQ_RING_SIZE_4096); |
| 12808 | break; |
| 12809 | } |
| 12810 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12811 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12812 | } |
| 12813 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12814 | cq->queue_id); |
| 12815 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12816 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12817 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 12818 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12819 | putPaddrLow(dmabuf->phys); |
| 12820 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12821 | putPaddrHigh(dmabuf->phys); |
| 12822 | } |
| 12823 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12824 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12825 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12826 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12827 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12828 | if (shdr_status || shdr_add_status || rc) { |
| 12829 | status = -ENXIO; |
| 12830 | goto out; |
| 12831 | } |
| 12832 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12833 | if (drq->queue_id == 0xFFFF) { |
| 12834 | status = -ENXIO; |
| 12835 | goto out; |
| 12836 | } |
| 12837 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12838 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12839 | drq->subtype = subtype; |
| 12840 | drq->host_index = 0; |
| 12841 | drq->hba_index = 0; |
| 12842 | |
| 12843 | /* link the header and data RQs onto the parent cq child list */ |
| 12844 | list_add_tail(&hrq->list, &cq->child_list); |
| 12845 | list_add_tail(&drq->list, &cq->child_list); |
| 12846 | |
| 12847 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12848 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12849 | return status; |
| 12850 | } |
| 12851 | |
| 12852 | /** |
| 12853 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 12854 | * @eq: The queue structure associated with the queue to destroy. |
| 12855 | * |
| 12856 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 12857 | * command, specific to the type of queue, to the HBA. |
| 12858 | * |
| 12859 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 12860 | * |
| 12861 | * 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] | 12862 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12863 | **/ |
| 12864 | uint32_t |
| 12865 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12866 | { |
| 12867 | LPFC_MBOXQ_t *mbox; |
| 12868 | int rc, length, status = 0; |
| 12869 | uint32_t shdr_status, shdr_add_status; |
| 12870 | union lpfc_sli4_cfg_shdr *shdr; |
| 12871 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12872 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12873 | if (!eq) |
| 12874 | return -ENODEV; |
| 12875 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12876 | if (!mbox) |
| 12877 | return -ENOMEM; |
| 12878 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 12879 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12880 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12881 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 12882 | length, LPFC_SLI4_MBX_EMBED); |
| 12883 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 12884 | eq->queue_id); |
| 12885 | mbox->vport = eq->phba->pport; |
| 12886 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12887 | |
| 12888 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 12889 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12890 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12891 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 12892 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12893 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12894 | if (shdr_status || shdr_add_status || rc) { |
| 12895 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12896 | "2505 EQ_DESTROY mailbox failed with " |
| 12897 | "status x%x add_status x%x, mbx status x%x\n", |
| 12898 | shdr_status, shdr_add_status, rc); |
| 12899 | status = -ENXIO; |
| 12900 | } |
| 12901 | |
| 12902 | /* Remove eq from any list */ |
| 12903 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12904 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12905 | return status; |
| 12906 | } |
| 12907 | |
| 12908 | /** |
| 12909 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 12910 | * @cq: The queue structure associated with the queue to destroy. |
| 12911 | * |
| 12912 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 12913 | * command, specific to the type of queue, to the HBA. |
| 12914 | * |
| 12915 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 12916 | * |
| 12917 | * 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] | 12918 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12919 | **/ |
| 12920 | uint32_t |
| 12921 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 12922 | { |
| 12923 | LPFC_MBOXQ_t *mbox; |
| 12924 | int rc, length, status = 0; |
| 12925 | uint32_t shdr_status, shdr_add_status; |
| 12926 | union lpfc_sli4_cfg_shdr *shdr; |
| 12927 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12928 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12929 | if (!cq) |
| 12930 | return -ENODEV; |
| 12931 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12932 | if (!mbox) |
| 12933 | return -ENOMEM; |
| 12934 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 12935 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12936 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12937 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 12938 | length, LPFC_SLI4_MBX_EMBED); |
| 12939 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 12940 | cq->queue_id); |
| 12941 | mbox->vport = cq->phba->pport; |
| 12942 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12943 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 12944 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12945 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 12946 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 12947 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12948 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12949 | if (shdr_status || shdr_add_status || rc) { |
| 12950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12951 | "2506 CQ_DESTROY mailbox failed with " |
| 12952 | "status x%x add_status x%x, mbx status x%x\n", |
| 12953 | shdr_status, shdr_add_status, rc); |
| 12954 | status = -ENXIO; |
| 12955 | } |
| 12956 | /* Remove cq from any list */ |
| 12957 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12958 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12959 | return status; |
| 12960 | } |
| 12961 | |
| 12962 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12963 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 12964 | * @qm: The queue structure associated with the queue to destroy. |
| 12965 | * |
| 12966 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 12967 | * command, specific to the type of queue, to the HBA. |
| 12968 | * |
| 12969 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 12970 | * |
| 12971 | * 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] | 12972 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12973 | **/ |
| 12974 | uint32_t |
| 12975 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 12976 | { |
| 12977 | LPFC_MBOXQ_t *mbox; |
| 12978 | int rc, length, status = 0; |
| 12979 | uint32_t shdr_status, shdr_add_status; |
| 12980 | union lpfc_sli4_cfg_shdr *shdr; |
| 12981 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12982 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12983 | if (!mq) |
| 12984 | return -ENODEV; |
| 12985 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 12986 | if (!mbox) |
| 12987 | return -ENOMEM; |
| 12988 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 12989 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12990 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12991 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 12992 | length, LPFC_SLI4_MBX_EMBED); |
| 12993 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 12994 | mq->queue_id); |
| 12995 | mbox->vport = mq->phba->pport; |
| 12996 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12997 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 12998 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12999 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13000 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13001 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13002 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13003 | if (shdr_status || shdr_add_status || rc) { |
| 13004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13005 | "2507 MQ_DESTROY mailbox failed with " |
| 13006 | "status x%x add_status x%x, mbx status x%x\n", |
| 13007 | shdr_status, shdr_add_status, rc); |
| 13008 | status = -ENXIO; |
| 13009 | } |
| 13010 | /* Remove mq from any list */ |
| 13011 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13012 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13013 | return status; |
| 13014 | } |
| 13015 | |
| 13016 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13017 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13018 | * @wq: The queue structure associated with the queue to destroy. |
| 13019 | * |
| 13020 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13021 | * command, specific to the type of queue, to the HBA. |
| 13022 | * |
| 13023 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13024 | * |
| 13025 | * 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] | 13026 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13027 | **/ |
| 13028 | uint32_t |
| 13029 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13030 | { |
| 13031 | LPFC_MBOXQ_t *mbox; |
| 13032 | int rc, length, status = 0; |
| 13033 | uint32_t shdr_status, shdr_add_status; |
| 13034 | union lpfc_sli4_cfg_shdr *shdr; |
| 13035 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13036 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13037 | if (!wq) |
| 13038 | return -ENODEV; |
| 13039 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13040 | if (!mbox) |
| 13041 | return -ENOMEM; |
| 13042 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13043 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13044 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13045 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13046 | length, LPFC_SLI4_MBX_EMBED); |
| 13047 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13048 | wq->queue_id); |
| 13049 | mbox->vport = wq->phba->pport; |
| 13050 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13051 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13052 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13053 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13054 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13055 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13056 | if (shdr_status || shdr_add_status || rc) { |
| 13057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13058 | "2508 WQ_DESTROY mailbox failed with " |
| 13059 | "status x%x add_status x%x, mbx status x%x\n", |
| 13060 | shdr_status, shdr_add_status, rc); |
| 13061 | status = -ENXIO; |
| 13062 | } |
| 13063 | /* Remove wq from any list */ |
| 13064 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13065 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13066 | return status; |
| 13067 | } |
| 13068 | |
| 13069 | /** |
| 13070 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13071 | * @rq: The queue structure associated with the queue to destroy. |
| 13072 | * |
| 13073 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13074 | * command, specific to the type of queue, to the HBA. |
| 13075 | * |
| 13076 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13077 | * |
| 13078 | * 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] | 13079 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13080 | **/ |
| 13081 | uint32_t |
| 13082 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13083 | struct lpfc_queue *drq) |
| 13084 | { |
| 13085 | LPFC_MBOXQ_t *mbox; |
| 13086 | int rc, length, status = 0; |
| 13087 | uint32_t shdr_status, shdr_add_status; |
| 13088 | union lpfc_sli4_cfg_shdr *shdr; |
| 13089 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13090 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13091 | if (!hrq || !drq) |
| 13092 | return -ENODEV; |
| 13093 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13094 | if (!mbox) |
| 13095 | return -ENOMEM; |
| 13096 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13097 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13098 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13099 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13100 | length, LPFC_SLI4_MBX_EMBED); |
| 13101 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13102 | hrq->queue_id); |
| 13103 | mbox->vport = hrq->phba->pport; |
| 13104 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13105 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13106 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13107 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13108 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13109 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13110 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13111 | if (shdr_status || shdr_add_status || rc) { |
| 13112 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13113 | "2509 RQ_DESTROY mailbox failed with " |
| 13114 | "status x%x add_status x%x, mbx status x%x\n", |
| 13115 | shdr_status, shdr_add_status, rc); |
| 13116 | if (rc != MBX_TIMEOUT) |
| 13117 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13118 | return -ENXIO; |
| 13119 | } |
| 13120 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13121 | drq->queue_id); |
| 13122 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13123 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13124 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13125 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13126 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13127 | if (shdr_status || shdr_add_status || rc) { |
| 13128 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13129 | "2510 RQ_DESTROY mailbox failed with " |
| 13130 | "status x%x add_status x%x, mbx status x%x\n", |
| 13131 | shdr_status, shdr_add_status, rc); |
| 13132 | status = -ENXIO; |
| 13133 | } |
| 13134 | list_del_init(&hrq->list); |
| 13135 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13136 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13137 | return status; |
| 13138 | } |
| 13139 | |
| 13140 | /** |
| 13141 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13142 | * @phba: The virtual port for which this call being executed. |
| 13143 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13144 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13145 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13146 | * |
| 13147 | * This routine will post the sgl pages for the IO that has the xritag |
| 13148 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13149 | * creation and persists for as long as the driver is loaded. |
| 13150 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13151 | * pdma_phys_addr1 should be 0. |
| 13152 | * If the caller needs to map more than 256 scatter gather segment then |
| 13153 | * pdma_phys_addr1 should be a valid physical address. |
| 13154 | * physical address for SGLs must be 64 byte aligned. |
| 13155 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13156 | * the second sgl can have between 1 and 256 entries. |
| 13157 | * |
| 13158 | * Return codes: |
| 13159 | * 0 - Success |
| 13160 | * -ENXIO, -ENOMEM - Failure |
| 13161 | **/ |
| 13162 | int |
| 13163 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13164 | dma_addr_t pdma_phys_addr0, |
| 13165 | dma_addr_t pdma_phys_addr1, |
| 13166 | uint16_t xritag) |
| 13167 | { |
| 13168 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13169 | LPFC_MBOXQ_t *mbox; |
| 13170 | int rc; |
| 13171 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13172 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13173 | union lpfc_sli4_cfg_shdr *shdr; |
| 13174 | |
| 13175 | if (xritag == NO_XRI) { |
| 13176 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13177 | "0364 Invalid param:\n"); |
| 13178 | return -EINVAL; |
| 13179 | } |
| 13180 | |
| 13181 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13182 | if (!mbox) |
| 13183 | return -ENOMEM; |
| 13184 | |
| 13185 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13186 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13187 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13188 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13189 | |
| 13190 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13191 | &mbox->u.mqe.un.post_sgl_pages; |
| 13192 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13193 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13194 | |
| 13195 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13196 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13197 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13198 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13199 | |
| 13200 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13201 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13202 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13203 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13204 | if (!phba->sli4_hba.intr_enable) |
| 13205 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13206 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13207 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13208 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13209 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13210 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13211 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->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 (rc != MBX_TIMEOUT) |
| 13215 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13216 | if (shdr_status || shdr_add_status || rc) { |
| 13217 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13218 | "2511 POST_SGL mailbox failed with " |
| 13219 | "status x%x add_status x%x, mbx status x%x\n", |
| 13220 | shdr_status, shdr_add_status, rc); |
| 13221 | rc = -ENXIO; |
| 13222 | } |
| 13223 | return 0; |
| 13224 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13225 | |
| 13226 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13227 | * 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] | 13228 | * @phba: pointer to lpfc hba data structure. |
| 13229 | * |
| 13230 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13231 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13232 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13233 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13234 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13235 | * Returns |
| 13236 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13237 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13238 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13239 | uint16_t |
| 13240 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13241 | { |
| 13242 | unsigned long xri; |
| 13243 | |
| 13244 | /* |
| 13245 | * Fetch the next logical xri. Because this index is logical, |
| 13246 | * the driver starts at 0 each time. |
| 13247 | */ |
| 13248 | spin_lock_irq(&phba->hbalock); |
| 13249 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13250 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13251 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13252 | spin_unlock_irq(&phba->hbalock); |
| 13253 | return NO_XRI; |
| 13254 | } else { |
| 13255 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13256 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13257 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13258 | spin_unlock_irq(&phba->hbalock); |
| 13259 | return xri; |
| 13260 | } |
| 13261 | |
| 13262 | /** |
| 13263 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13264 | * @phba: pointer to lpfc hba data structure. |
| 13265 | * |
| 13266 | * This routine is invoked to release an xri to the pool of |
| 13267 | * available rpis maintained by the driver. |
| 13268 | **/ |
| 13269 | void |
| 13270 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13271 | { |
| 13272 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13273 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13274 | } |
| 13275 | } |
| 13276 | |
| 13277 | /** |
| 13278 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13279 | * @phba: pointer to lpfc hba data structure. |
| 13280 | * |
| 13281 | * This routine is invoked to release an xri to the pool of |
| 13282 | * available rpis maintained by the driver. |
| 13283 | **/ |
| 13284 | void |
| 13285 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13286 | { |
| 13287 | spin_lock_irq(&phba->hbalock); |
| 13288 | __lpfc_sli4_free_xri(phba, xri); |
| 13289 | spin_unlock_irq(&phba->hbalock); |
| 13290 | } |
| 13291 | |
| 13292 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13293 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13294 | * @phba: Pointer to HBA context object. |
| 13295 | * |
| 13296 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13297 | * it will return 0xffff. |
| 13298 | * The function returns the allocated xritag if successful, else returns zero. |
| 13299 | * Zero is not a valid xritag. |
| 13300 | * The caller is not required to hold any lock. |
| 13301 | **/ |
| 13302 | uint16_t |
| 13303 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13304 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13305 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13306 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13307 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13308 | if (xri_index == NO_XRI) |
| 13309 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13310 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13311 | " Max XRI is %d, Used XRI is %d\n", |
| 13312 | xri_index, |
| 13313 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13314 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13315 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13316 | } |
| 13317 | |
| 13318 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13319 | * 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] | 13320 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13321 | * @post_sgl_list: pointer to els sgl entry list. |
| 13322 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13323 | * |
| 13324 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13325 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13326 | * is only called when the driver is loading and after all IO has been |
| 13327 | * stopped. |
| 13328 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13329 | static int |
| 13330 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13331 | struct list_head *post_sgl_list, |
| 13332 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13333 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13334 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13335 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13336 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13337 | void *viraddr; |
| 13338 | LPFC_MBOXQ_t *mbox; |
| 13339 | uint32_t reqlen, alloclen, pg_pairs; |
| 13340 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13341 | uint16_t xritag_start = 0; |
| 13342 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13343 | uint32_t shdr_status, shdr_add_status; |
| 13344 | union lpfc_sli4_cfg_shdr *shdr; |
| 13345 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13346 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13347 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13348 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13349 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13350 | "2559 Block sgl registration required DMA " |
| 13351 | "size (%d) great than a page\n", reqlen); |
| 13352 | return -ENOMEM; |
| 13353 | } |
| 13354 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13355 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13356 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13357 | |
| 13358 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13359 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13360 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13361 | LPFC_SLI4_MBX_NEMBED); |
| 13362 | |
| 13363 | if (alloclen < reqlen) { |
| 13364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13365 | "0285 Allocated DMA memory size (%d) is " |
| 13366 | "less than the requested DMA memory " |
| 13367 | "size (%d)\n", alloclen, reqlen); |
| 13368 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13369 | return -ENOMEM; |
| 13370 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13371 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13372 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13373 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13374 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13375 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13376 | pg_pairs = 0; |
| 13377 | 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] | 13378 | /* Set up the sge entry */ |
| 13379 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13380 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13381 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13382 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13383 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13384 | cpu_to_le32(putPaddrLow(0)); |
| 13385 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13386 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13387 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13388 | /* Keep the first xritag on the list */ |
| 13389 | if (pg_pairs == 0) |
| 13390 | xritag_start = sglq_entry->sli4_xritag; |
| 13391 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13392 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13393 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13394 | |
| 13395 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13396 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13397 | 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] | 13398 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13399 | if (!phba->sli4_hba.intr_enable) |
| 13400 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13401 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13402 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13403 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13404 | } |
| 13405 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13406 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13407 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13408 | if (rc != MBX_TIMEOUT) |
| 13409 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13410 | if (shdr_status || shdr_add_status || rc) { |
| 13411 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13412 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13413 | "status x%x add_status x%x mbx status x%x\n", |
| 13414 | shdr_status, shdr_add_status, rc); |
| 13415 | rc = -ENXIO; |
| 13416 | } |
| 13417 | return rc; |
| 13418 | } |
| 13419 | |
| 13420 | /** |
| 13421 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13422 | * @phba: pointer to lpfc hba data structure. |
| 13423 | * @sblist: pointer to scsi buffer list. |
| 13424 | * @count: number of scsi buffers on the list. |
| 13425 | * |
| 13426 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13427 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13428 | * No Lock is held. |
| 13429 | * |
| 13430 | **/ |
| 13431 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13432 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 13433 | struct list_head *sblist, |
| 13434 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13435 | { |
| 13436 | struct lpfc_scsi_buf *psb; |
| 13437 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13438 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13439 | void *viraddr; |
| 13440 | LPFC_MBOXQ_t *mbox; |
| 13441 | uint32_t reqlen, alloclen, pg_pairs; |
| 13442 | uint32_t mbox_tmo; |
| 13443 | uint16_t xritag_start = 0; |
| 13444 | int rc = 0; |
| 13445 | uint32_t shdr_status, shdr_add_status; |
| 13446 | dma_addr_t pdma_phys_bpl1; |
| 13447 | union lpfc_sli4_cfg_shdr *shdr; |
| 13448 | |
| 13449 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13450 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13451 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13452 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13453 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13454 | "0217 Block sgl registration required DMA " |
| 13455 | "size (%d) great than a page\n", reqlen); |
| 13456 | return -ENOMEM; |
| 13457 | } |
| 13458 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13459 | if (!mbox) { |
| 13460 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13461 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13462 | return -ENOMEM; |
| 13463 | } |
| 13464 | |
| 13465 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13466 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13467 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13468 | LPFC_SLI4_MBX_NEMBED); |
| 13469 | |
| 13470 | if (alloclen < reqlen) { |
| 13471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13472 | "2561 Allocated DMA memory size (%d) is " |
| 13473 | "less than the requested DMA memory " |
| 13474 | "size (%d)\n", alloclen, reqlen); |
| 13475 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13476 | return -ENOMEM; |
| 13477 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13478 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13479 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13480 | viraddr = mbox->sge_array->addr[0]; |
| 13481 | |
| 13482 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13483 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13484 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13485 | |
| 13486 | pg_pairs = 0; |
| 13487 | list_for_each_entry(psb, sblist, list) { |
| 13488 | /* Set up the sge entry */ |
| 13489 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13490 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13491 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13492 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13493 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13494 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13495 | else |
| 13496 | pdma_phys_bpl1 = 0; |
| 13497 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13498 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13499 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13500 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13501 | /* Keep the first xritag on the list */ |
| 13502 | if (pg_pairs == 0) |
| 13503 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13504 | sgl_pg_pairs++; |
| 13505 | pg_pairs++; |
| 13506 | } |
| 13507 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13508 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13509 | /* Perform endian conversion if necessary */ |
| 13510 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13511 | |
| 13512 | if (!phba->sli4_hba.intr_enable) |
| 13513 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13514 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13515 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13516 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13517 | } |
| 13518 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13519 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13520 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13521 | if (rc != MBX_TIMEOUT) |
| 13522 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13523 | if (shdr_status || shdr_add_status || rc) { |
| 13524 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13525 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13526 | "status x%x add_status x%x mbx status x%x\n", |
| 13527 | shdr_status, shdr_add_status, rc); |
| 13528 | rc = -ENXIO; |
| 13529 | } |
| 13530 | return rc; |
| 13531 | } |
| 13532 | |
| 13533 | /** |
| 13534 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13535 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13536 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13537 | * |
| 13538 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13539 | * valid type of frame that the LPFC driver will handle. This function will |
| 13540 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13541 | * frame does not pass the check. |
| 13542 | **/ |
| 13543 | static int |
| 13544 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13545 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13546 | /* make rctl_names static to save stack space */ |
| 13547 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13548 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13549 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13550 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13551 | |
| 13552 | switch (fc_hdr->fh_r_ctl) { |
| 13553 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13554 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13555 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13556 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13557 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13558 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13559 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13560 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13561 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13562 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13563 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13564 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13565 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13566 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13567 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13568 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13569 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13570 | case FC_RCTL_BA_PRMT: |
| 13571 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13572 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13573 | case FC_RCTL_P_RJT: /* port reject */ |
| 13574 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13575 | case FC_RCTL_P_BSY: /* port busy */ |
| 13576 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13577 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13578 | case FC_RCTL_LCR: /* link credit reset */ |
| 13579 | case FC_RCTL_END: /* end */ |
| 13580 | break; |
| 13581 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13582 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13583 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13584 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13585 | default: |
| 13586 | goto drop; |
| 13587 | } |
| 13588 | switch (fc_hdr->fh_type) { |
| 13589 | case FC_TYPE_BLS: |
| 13590 | case FC_TYPE_ELS: |
| 13591 | case FC_TYPE_FCP: |
| 13592 | case FC_TYPE_CT: |
| 13593 | break; |
| 13594 | case FC_TYPE_IP: |
| 13595 | case FC_TYPE_ILS: |
| 13596 | default: |
| 13597 | goto drop; |
| 13598 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13599 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13600 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13601 | "2538 Received frame rctl:%s type:%s " |
| 13602 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13603 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13604 | type_names[fc_hdr->fh_type], |
| 13605 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13606 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13607 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13608 | return 0; |
| 13609 | drop: |
| 13610 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13611 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13612 | rctl_names[fc_hdr->fh_r_ctl], |
| 13613 | type_names[fc_hdr->fh_type]); |
| 13614 | return 1; |
| 13615 | } |
| 13616 | |
| 13617 | /** |
| 13618 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13619 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13620 | * |
| 13621 | * This function processes the FC header to retrieve the VFI from the VF |
| 13622 | * header, if one exists. This function will return the VFI if one exists |
| 13623 | * or 0 if no VSAN Header exists. |
| 13624 | **/ |
| 13625 | static uint32_t |
| 13626 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13627 | { |
| 13628 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13629 | |
| 13630 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 13631 | return 0; |
| 13632 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 13633 | } |
| 13634 | |
| 13635 | /** |
| 13636 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 13637 | * @phba: Pointer to the HBA structure to search for the vport on |
| 13638 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13639 | * @fcfi: The FC Fabric ID that the frame came from |
| 13640 | * |
| 13641 | * This function searches the @phba for a vport that matches the content of the |
| 13642 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 13643 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 13644 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 13645 | * vport. |
| 13646 | **/ |
| 13647 | static struct lpfc_vport * |
| 13648 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 13649 | uint16_t fcfi) |
| 13650 | { |
| 13651 | struct lpfc_vport **vports; |
| 13652 | struct lpfc_vport *vport = NULL; |
| 13653 | int i; |
| 13654 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 13655 | fc_hdr->fh_d_id[1] << 8 | |
| 13656 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13657 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 13658 | if (did == Fabric_DID) |
| 13659 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13660 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 13661 | !(phba->link_state == LPFC_HBA_READY)) |
| 13662 | return phba->pport; |
| 13663 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13664 | vports = lpfc_create_vport_work_array(phba); |
| 13665 | if (vports != NULL) |
| 13666 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 13667 | if (phba->fcf.fcfi == fcfi && |
| 13668 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 13669 | vports[i]->fc_myDID == did) { |
| 13670 | vport = vports[i]; |
| 13671 | break; |
| 13672 | } |
| 13673 | } |
| 13674 | lpfc_destroy_vport_work_array(phba, vports); |
| 13675 | return vport; |
| 13676 | } |
| 13677 | |
| 13678 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13679 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 13680 | * @vport: The vport to work on. |
| 13681 | * |
| 13682 | * This function updates the receive sequence time stamp for this vport. The |
| 13683 | * receive sequence time stamp indicates the time that the last frame of the |
| 13684 | * the sequence that has been idle for the longest amount of time was received. |
| 13685 | * the driver uses this time stamp to indicate if any received sequences have |
| 13686 | * timed out. |
| 13687 | **/ |
| 13688 | void |
| 13689 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 13690 | { |
| 13691 | struct lpfc_dmabuf *h_buf; |
| 13692 | struct hbq_dmabuf *dmabuf = NULL; |
| 13693 | |
| 13694 | /* get the oldest sequence on the rcv list */ |
| 13695 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 13696 | struct lpfc_dmabuf, list); |
| 13697 | if (!h_buf) |
| 13698 | return; |
| 13699 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13700 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 13701 | } |
| 13702 | |
| 13703 | /** |
| 13704 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 13705 | * @vport: The vport that the received sequences were sent to. |
| 13706 | * |
| 13707 | * This function cleans up all outstanding received sequences. This is called |
| 13708 | * by the driver when a link event or user action invalidates all the received |
| 13709 | * sequences. |
| 13710 | **/ |
| 13711 | void |
| 13712 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 13713 | { |
| 13714 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13715 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13716 | struct hbq_dmabuf *dmabuf = NULL; |
| 13717 | |
| 13718 | /* start with the oldest sequence on the rcv list */ |
| 13719 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13720 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13721 | list_del_init(&dmabuf->hbuf.list); |
| 13722 | list_for_each_entry_safe(d_buf, dnext, |
| 13723 | &dmabuf->dbuf.list, list) { |
| 13724 | list_del_init(&d_buf->list); |
| 13725 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13726 | } |
| 13727 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13728 | } |
| 13729 | } |
| 13730 | |
| 13731 | /** |
| 13732 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 13733 | * @vport: The vport that the received sequences were sent to. |
| 13734 | * |
| 13735 | * This function determines whether any received sequences have timed out by |
| 13736 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 13737 | * indicates that there is at least one timed out sequence this routine will |
| 13738 | * go through the received sequences one at a time from most inactive to most |
| 13739 | * active to determine which ones need to be cleaned up. Once it has determined |
| 13740 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 13741 | * without sending an abort. |
| 13742 | **/ |
| 13743 | void |
| 13744 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 13745 | { |
| 13746 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13747 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13748 | struct hbq_dmabuf *dmabuf = NULL; |
| 13749 | unsigned long timeout; |
| 13750 | int abort_count = 0; |
| 13751 | |
| 13752 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13753 | vport->rcv_buffer_time_stamp); |
| 13754 | if (list_empty(&vport->rcv_buffer_list) || |
| 13755 | time_before(jiffies, timeout)) |
| 13756 | return; |
| 13757 | /* start with the oldest sequence on the rcv list */ |
| 13758 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13759 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13760 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13761 | dmabuf->time_stamp); |
| 13762 | if (time_before(jiffies, timeout)) |
| 13763 | break; |
| 13764 | abort_count++; |
| 13765 | list_del_init(&dmabuf->hbuf.list); |
| 13766 | list_for_each_entry_safe(d_buf, dnext, |
| 13767 | &dmabuf->dbuf.list, list) { |
| 13768 | list_del_init(&d_buf->list); |
| 13769 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13770 | } |
| 13771 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13772 | } |
| 13773 | if (abort_count) |
| 13774 | lpfc_update_rcv_time_stamp(vport); |
| 13775 | } |
| 13776 | |
| 13777 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13778 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 13779 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 13780 | * |
| 13781 | * This function searches through the existing incomplete sequences that have |
| 13782 | * been sent to this @vport. If the frame matches one of the incomplete |
| 13783 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 13784 | * make up that sequence. If no sequence is found that matches this frame then |
| 13785 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 13786 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 13787 | * the frame was linked to. |
| 13788 | **/ |
| 13789 | static struct hbq_dmabuf * |
| 13790 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 13791 | { |
| 13792 | struct fc_frame_header *new_hdr; |
| 13793 | struct fc_frame_header *temp_hdr; |
| 13794 | struct lpfc_dmabuf *d_buf; |
| 13795 | struct lpfc_dmabuf *h_buf; |
| 13796 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13797 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 13798 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13799 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13800 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13801 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13802 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 13803 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13804 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13805 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13806 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13807 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13808 | continue; |
| 13809 | /* found a pending sequence that matches this frame */ |
| 13810 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13811 | break; |
| 13812 | } |
| 13813 | if (!seq_dmabuf) { |
| 13814 | /* |
| 13815 | * This indicates first frame received for this sequence. |
| 13816 | * Queue the buffer on the vport's rcv_buffer_list. |
| 13817 | */ |
| 13818 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13819 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13820 | return dmabuf; |
| 13821 | } |
| 13822 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13823 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 13824 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13825 | list_del_init(&seq_dmabuf->hbuf.list); |
| 13826 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13827 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13828 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13829 | return dmabuf; |
| 13830 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13831 | /* move this sequence to the tail to indicate a young sequence */ |
| 13832 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13833 | seq_dmabuf->time_stamp = jiffies; |
| 13834 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13835 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 13836 | temp_hdr = dmabuf->hbuf.virt; |
| 13837 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 13838 | return seq_dmabuf; |
| 13839 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13840 | /* find the correct place in the sequence to insert this frame */ |
| 13841 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 13842 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 13843 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 13844 | /* |
| 13845 | * If the frame's sequence count is greater than the frame on |
| 13846 | * the list then insert the frame right after this frame |
| 13847 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13848 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 13849 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13850 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 13851 | return seq_dmabuf; |
| 13852 | } |
| 13853 | } |
| 13854 | return NULL; |
| 13855 | } |
| 13856 | |
| 13857 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13858 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 13859 | * @vport: pointer to a vitural port |
| 13860 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 13861 | * |
| 13862 | * This function tries to abort from the partially assembed sequence, described |
| 13863 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 13864 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 13865 | * the frames from the partially assembled sequence. |
| 13866 | * |
| 13867 | * Return |
| 13868 | * true -- if there is matching partially assembled sequence present and all |
| 13869 | * the frames freed with the sequence; |
| 13870 | * false -- if there is no matching partially assembled sequence present so |
| 13871 | * nothing got aborted in the lower layer driver |
| 13872 | **/ |
| 13873 | static bool |
| 13874 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 13875 | struct hbq_dmabuf *dmabuf) |
| 13876 | { |
| 13877 | struct fc_frame_header *new_hdr; |
| 13878 | struct fc_frame_header *temp_hdr; |
| 13879 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 13880 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13881 | |
| 13882 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 13883 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 13884 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 13885 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13886 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13887 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13888 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13889 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13890 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13891 | continue; |
| 13892 | /* found a pending sequence that matches this frame */ |
| 13893 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13894 | break; |
| 13895 | } |
| 13896 | |
| 13897 | /* Free up all the frames from the partially assembled sequence */ |
| 13898 | if (seq_dmabuf) { |
| 13899 | list_for_each_entry_safe(d_buf, n_buf, |
| 13900 | &seq_dmabuf->dbuf.list, list) { |
| 13901 | list_del_init(&d_buf->list); |
| 13902 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13903 | } |
| 13904 | return true; |
| 13905 | } |
| 13906 | return false; |
| 13907 | } |
| 13908 | |
| 13909 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13910 | * 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] | 13911 | * @phba: Pointer to HBA context object. |
| 13912 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 13913 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 13914 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13915 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13916 | * event. It properly releases the memory allocated to the sequence abort |
| 13917 | * accept iocb. |
| 13918 | **/ |
| 13919 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13920 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13921 | struct lpfc_iocbq *cmd_iocbq, |
| 13922 | struct lpfc_iocbq *rsp_iocbq) |
| 13923 | { |
| 13924 | if (cmd_iocbq) |
| 13925 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 13926 | |
| 13927 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 13928 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 13929 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13930 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 13931 | rsp_iocbq->iocb.ulpStatus, |
| 13932 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13933 | } |
| 13934 | |
| 13935 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13936 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 13937 | * @phba: Pointer to HBA context object. |
| 13938 | * @xri: xri id in transaction. |
| 13939 | * |
| 13940 | * This function validates the xri maps to the known range of XRIs allocated an |
| 13941 | * used by the driver. |
| 13942 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13943 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13944 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 13945 | uint16_t xri) |
| 13946 | { |
| 13947 | int i; |
| 13948 | |
| 13949 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 13950 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 13951 | return i; |
| 13952 | } |
| 13953 | return NO_XRI; |
| 13954 | } |
| 13955 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13956 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13957 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13958 | * @phba: Pointer to HBA context object. |
| 13959 | * @fc_hdr: pointer to a FC frame header. |
| 13960 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13961 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13962 | * event after aborting the sequence handling. |
| 13963 | **/ |
| 13964 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13965 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13966 | struct fc_frame_header *fc_hdr) |
| 13967 | { |
| 13968 | struct lpfc_iocbq *ctiocb = NULL; |
| 13969 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame^] | 13970 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 13971 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13972 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13973 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13974 | |
| 13975 | if (!lpfc_is_link_up(phba)) |
| 13976 | return; |
| 13977 | |
| 13978 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 13979 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 13980 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13981 | |
| 13982 | ndlp = lpfc_findnode_did(phba->pport, sid); |
| 13983 | if (!ndlp) { |
| 13984 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13985 | "1268 Find ndlp returned NULL for oxid:x%x " |
| 13986 | "SID:x%x\n", oxid, sid); |
| 13987 | return; |
| 13988 | } |
| 13989 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13990 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13991 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 13992 | if (!ctiocb) |
| 13993 | return; |
| 13994 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 13995 | /* Extract the F_CTL field from FC_HDR */ |
| 13996 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 13997 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13998 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13999 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14000 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14001 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14002 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14003 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14004 | |
| 14005 | /* Fill in the rest of iocb fields */ |
| 14006 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14007 | icmd->ulpBdeCount = 0; |
| 14008 | icmd->ulpLe = 1; |
| 14009 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14010 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 14011 | ctiocb->context1 = ndlp; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14012 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14013 | ctiocb->iocb_cmpl = NULL; |
| 14014 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14015 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14016 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14017 | ctiocb->sli4_xritag = NO_XRI; |
| 14018 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame^] | 14019 | if (fctl & FC_FC_EX_CTX) |
| 14020 | /* Exchange responder sent the abort so we |
| 14021 | * own the oxid. |
| 14022 | */ |
| 14023 | xri = oxid; |
| 14024 | else |
| 14025 | xri = rxid; |
| 14026 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14027 | if (lxri != NO_XRI) |
| 14028 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14029 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14030 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
| 14031 | * send a BLS_RJT. The driver no longer has that exchange. |
| 14032 | * Override the IOCB for a BA_RJT. |
| 14033 | */ |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame^] | 14034 | if (xri > (phba->sli4_hba.max_cfg_param.max_xri + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14035 | phba->sli4_hba.max_cfg_param.xri_base) || |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame^] | 14036 | xri > (lpfc_sli4_get_els_iocb_cnt(phba) + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14037 | phba->sli4_hba.max_cfg_param.xri_base)) { |
| 14038 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14039 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14040 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14041 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14042 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14043 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14044 | if (fctl & FC_FC_EX_CTX) { |
| 14045 | /* ABTS sent by responder to CT exchange, construction |
| 14046 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14047 | * field and RX_ID from ABTS for RX_ID field. |
| 14048 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14049 | 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] | 14050 | } else { |
| 14051 | /* ABTS sent by initiator to CT exchange, construction |
| 14052 | * 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] | 14053 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14054 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14055 | 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] | 14056 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14057 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14058 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14059 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14060 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14061 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14062 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14063 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
| 14064 | |
| 14065 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14066 | if (rc == IOCB_ERROR) { |
| 14067 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 14068 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14069 | "xri x%x, Data x%x\n", |
| 14070 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14071 | phba->link_state); |
| 14072 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14073 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14074 | } |
| 14075 | |
| 14076 | /** |
| 14077 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14078 | * @vport: Pointer to the vport on which this sequence was received |
| 14079 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14080 | * |
| 14081 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14082 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14083 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14084 | * unsolicited receive sequence has been completely assembled and passed to |
| 14085 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14086 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14087 | * accept to accept the abort. |
| 14088 | **/ |
| 14089 | void |
| 14090 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14091 | struct hbq_dmabuf *dmabuf) |
| 14092 | { |
| 14093 | struct lpfc_hba *phba = vport->phba; |
| 14094 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14095 | uint32_t fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14096 | bool abts_par; |
| 14097 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14098 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14099 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14100 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14101 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14102 | if (fctl & FC_FC_EX_CTX) { |
| 14103 | /* |
| 14104 | * ABTS sent by responder to exchange, just free the buffer |
| 14105 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14106 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14107 | } else { |
| 14108 | /* |
| 14109 | * ABTS sent by initiator to exchange, need to do cleanup |
| 14110 | */ |
| 14111 | /* Try to abort partially assembled seq */ |
| 14112 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14113 | |
| 14114 | /* Send abort to ULP if partially seq abort failed */ |
| 14115 | if (abts_par == false) |
| 14116 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); |
| 14117 | else |
| 14118 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14119 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14120 | /* Send basic accept (BA_ACC) to the abort requester */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14121 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14122 | } |
| 14123 | |
| 14124 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14125 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14126 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14127 | * |
| 14128 | * This function checks the sequence, starting with the frame described by |
| 14129 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14130 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14131 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14132 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14133 | * set. 3) That there are no holes in the sequence count. The function will |
| 14134 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14135 | **/ |
| 14136 | static int |
| 14137 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14138 | { |
| 14139 | struct fc_frame_header *hdr; |
| 14140 | struct lpfc_dmabuf *d_buf; |
| 14141 | struct hbq_dmabuf *seq_dmabuf; |
| 14142 | uint32_t fctl; |
| 14143 | int seq_count = 0; |
| 14144 | |
| 14145 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14146 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14147 | if (hdr->fh_seq_cnt != seq_count) |
| 14148 | return 0; |
| 14149 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14150 | hdr->fh_f_ctl[1] << 8 | |
| 14151 | hdr->fh_f_ctl[2]); |
| 14152 | /* If last frame of sequence we can return success. */ |
| 14153 | if (fctl & FC_FC_END_SEQ) |
| 14154 | return 1; |
| 14155 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14156 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14157 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14158 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14159 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14160 | return 0; |
| 14161 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14162 | hdr->fh_f_ctl[1] << 8 | |
| 14163 | hdr->fh_f_ctl[2]); |
| 14164 | /* If last frame of sequence we can return success. */ |
| 14165 | if (fctl & FC_FC_END_SEQ) |
| 14166 | return 1; |
| 14167 | } |
| 14168 | return 0; |
| 14169 | } |
| 14170 | |
| 14171 | /** |
| 14172 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14173 | * @vport: Pointer to the vport on which this sequence was received |
| 14174 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14175 | * |
| 14176 | * This function takes a sequence, described by a list of frames, and creates |
| 14177 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14178 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14179 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14180 | * to allocate an iocbq then it throw out the received frames that were not |
| 14181 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14182 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14183 | **/ |
| 14184 | static struct lpfc_iocbq * |
| 14185 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14186 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14187 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14188 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14189 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14190 | struct fc_frame_header *fc_hdr; |
| 14191 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14192 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14193 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14194 | |
| 14195 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14196 | /* remove from receive buffer list */ |
| 14197 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14198 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14199 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14200 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14201 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14202 | /* Get an iocbq struct to fill in. */ |
| 14203 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14204 | if (first_iocbq) { |
| 14205 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14206 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14207 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14208 | |
| 14209 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14210 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14211 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14212 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14213 | sli4_did_from_fc_hdr(fc_hdr); |
| 14214 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14215 | } else |
| 14216 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14217 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14218 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14219 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14220 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14221 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14222 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14223 | /* put the first buffer into the first IOCBq */ |
| 14224 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14225 | first_iocbq->context3 = NULL; |
| 14226 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14227 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14228 | LPFC_DATA_BUF_SIZE; |
| 14229 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14230 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14231 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14232 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14233 | } |
| 14234 | iocbq = first_iocbq; |
| 14235 | /* |
| 14236 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14237 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14238 | */ |
| 14239 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14240 | if (!iocbq) { |
| 14241 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14242 | continue; |
| 14243 | } |
| 14244 | if (!iocbq->context3) { |
| 14245 | iocbq->context3 = d_buf; |
| 14246 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14247 | pbde = (struct ulp_bde64 *) |
| 14248 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14249 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14250 | |
| 14251 | /* We need to get the size out of the right CQE */ |
| 14252 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14253 | len = bf_get(lpfc_rcqe_length, |
| 14254 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14255 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14256 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14257 | } else { |
| 14258 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14259 | if (!iocbq) { |
| 14260 | if (first_iocbq) { |
| 14261 | first_iocbq->iocb.ulpStatus = |
| 14262 | IOSTAT_FCP_RSP_ERROR; |
| 14263 | first_iocbq->iocb.un.ulpWord[4] = |
| 14264 | IOERR_NO_RESOURCES; |
| 14265 | } |
| 14266 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14267 | continue; |
| 14268 | } |
| 14269 | iocbq->context2 = d_buf; |
| 14270 | iocbq->context3 = NULL; |
| 14271 | iocbq->iocb.ulpBdeCount = 1; |
| 14272 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14273 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14274 | |
| 14275 | /* We need to get the size out of the right CQE */ |
| 14276 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14277 | len = bf_get(lpfc_rcqe_length, |
| 14278 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14279 | tot_len += len; |
| 14280 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14281 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14282 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14283 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14284 | } |
| 14285 | } |
| 14286 | return first_iocbq; |
| 14287 | } |
| 14288 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14289 | static void |
| 14290 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14291 | struct hbq_dmabuf *seq_dmabuf) |
| 14292 | { |
| 14293 | struct fc_frame_header *fc_hdr; |
| 14294 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14295 | struct lpfc_hba *phba = vport->phba; |
| 14296 | |
| 14297 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14298 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14299 | if (!iocbq) { |
| 14300 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14301 | "2707 Ring %d handler: Failed to allocate " |
| 14302 | "iocb Rctl x%x Type x%x received\n", |
| 14303 | LPFC_ELS_RING, |
| 14304 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14305 | return; |
| 14306 | } |
| 14307 | if (!lpfc_complete_unsol_iocb(phba, |
| 14308 | &phba->sli.ring[LPFC_ELS_RING], |
| 14309 | iocbq, fc_hdr->fh_r_ctl, |
| 14310 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14311 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14312 | "2540 Ring %d handler: unexpected Rctl " |
| 14313 | "x%x Type x%x received\n", |
| 14314 | LPFC_ELS_RING, |
| 14315 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14316 | |
| 14317 | /* Free iocb created in lpfc_prep_seq */ |
| 14318 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14319 | &iocbq->list, list) { |
| 14320 | list_del_init(&curr_iocb->list); |
| 14321 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14322 | } |
| 14323 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14324 | } |
| 14325 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14326 | /** |
| 14327 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14328 | * @phba: Pointer to HBA context object. |
| 14329 | * |
| 14330 | * This function is called with no lock held. This function processes all |
| 14331 | * the received buffers and gives it to upper layers when a received buffer |
| 14332 | * indicates that it is the final frame in the sequence. The interrupt |
| 14333 | * service routine processes received buffers at interrupt contexts and adds |
| 14334 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14335 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14336 | * appropriate receive function when the final frame in a sequence is received. |
| 14337 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14338 | void |
| 14339 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14340 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14341 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14342 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14343 | struct fc_frame_header *fc_hdr; |
| 14344 | struct lpfc_vport *vport; |
| 14345 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14346 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14347 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14348 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14349 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14350 | /* check to see if this a valid type of frame */ |
| 14351 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14352 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14353 | return; |
| 14354 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14355 | if ((bf_get(lpfc_cqe_code, |
| 14356 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14357 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14358 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14359 | else |
| 14360 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14361 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14362 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14363 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14364 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14365 | /* throw out the frame */ |
| 14366 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14367 | return; |
| 14368 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14369 | |
| 14370 | /* d_id this frame is directed to */ |
| 14371 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 14372 | |
| 14373 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 14374 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 14375 | (did != Fabric_DID)) { |
| 14376 | /* |
| 14377 | * Throw out the frame if we are not pt2pt. |
| 14378 | * The pt2pt protocol allows for discovery frames |
| 14379 | * to be received without a registered VPI. |
| 14380 | */ |
| 14381 | if (!(vport->fc_flag & FC_PT2PT) || |
| 14382 | (phba->link_state == LPFC_HBA_READY)) { |
| 14383 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14384 | return; |
| 14385 | } |
| 14386 | } |
| 14387 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14388 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14389 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14390 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14391 | return; |
| 14392 | } |
| 14393 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14394 | /* Link this frame */ |
| 14395 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14396 | if (!seq_dmabuf) { |
| 14397 | /* unable to add frame to vport - throw it out */ |
| 14398 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14399 | return; |
| 14400 | } |
| 14401 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14402 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14403 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14404 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14405 | /* Send the complete sequence to the upper layer protocol */ |
| 14406 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14407 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14408 | |
| 14409 | /** |
| 14410 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14411 | * @phba: pointer to lpfc hba data structure. |
| 14412 | * |
| 14413 | * This routine is invoked to post rpi header templates to the |
| 14414 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14415 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14416 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14417 | * |
| 14418 | * This routine does not require any locks. It's usage is expected |
| 14419 | * to be driver load or reset recovery when the driver is |
| 14420 | * sequential. |
| 14421 | * |
| 14422 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14423 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14424 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14425 | * When this error occurs, the driver is not guaranteed |
| 14426 | * to have any rpi regions posted to the device and |
| 14427 | * must either attempt to repost the regions or take a |
| 14428 | * fatal error. |
| 14429 | **/ |
| 14430 | int |
| 14431 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14432 | { |
| 14433 | struct lpfc_rpi_hdr *rpi_page; |
| 14434 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14435 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14436 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14437 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14438 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14439 | goto exit; |
| 14440 | if (phba->sli4_hba.extents_in_use) |
| 14441 | return -EIO; |
| 14442 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14443 | 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] | 14444 | /* |
| 14445 | * Assign the rpi headers a physical rpi only if the driver |
| 14446 | * has not initialized those resources. A port reset only |
| 14447 | * needs the headers posted. |
| 14448 | */ |
| 14449 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14450 | LPFC_RPI_RSRC_RDY) |
| 14451 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14452 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14453 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14454 | if (rc != MBX_SUCCESS) { |
| 14455 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14456 | "2008 Error %d posting all rpi " |
| 14457 | "headers\n", rc); |
| 14458 | rc = -EIO; |
| 14459 | break; |
| 14460 | } |
| 14461 | } |
| 14462 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14463 | exit: |
| 14464 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14465 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14466 | return rc; |
| 14467 | } |
| 14468 | |
| 14469 | /** |
| 14470 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14471 | * @phba: pointer to lpfc hba data structure. |
| 14472 | * @rpi_page: pointer to the rpi memory region. |
| 14473 | * |
| 14474 | * This routine is invoked to post a single rpi header to the |
| 14475 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14476 | * maps up to 64 rpi context regions. |
| 14477 | * |
| 14478 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14479 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14480 | * -ENOMEM - No available memory |
| 14481 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14482 | **/ |
| 14483 | int |
| 14484 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14485 | { |
| 14486 | LPFC_MBOXQ_t *mboxq; |
| 14487 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14488 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14489 | uint32_t shdr_status, shdr_add_status; |
| 14490 | union lpfc_sli4_cfg_shdr *shdr; |
| 14491 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14492 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14493 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14494 | return rc; |
| 14495 | if (phba->sli4_hba.extents_in_use) |
| 14496 | return -EIO; |
| 14497 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14498 | /* The port is notified of the header region via a mailbox command. */ |
| 14499 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14500 | if (!mboxq) { |
| 14501 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14502 | "2001 Unable to allocate memory for issuing " |
| 14503 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14504 | return -ENOMEM; |
| 14505 | } |
| 14506 | |
| 14507 | /* Post all rpi memory regions to the port. */ |
| 14508 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14509 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14510 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14511 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14512 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14513 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14514 | |
| 14515 | |
| 14516 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14517 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14518 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14519 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14520 | hdr_tmpl, rpi_page->page_count); |
| 14521 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14522 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14523 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14524 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14525 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14526 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14527 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14528 | if (rc != MBX_TIMEOUT) |
| 14529 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14530 | if (shdr_status || shdr_add_status || rc) { |
| 14531 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14532 | "2514 POST_RPI_HDR mailbox failed with " |
| 14533 | "status x%x add_status x%x, mbx status x%x\n", |
| 14534 | shdr_status, shdr_add_status, rc); |
| 14535 | rc = -ENXIO; |
| 14536 | } |
| 14537 | return rc; |
| 14538 | } |
| 14539 | |
| 14540 | /** |
| 14541 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14542 | * @phba: pointer to lpfc hba data structure. |
| 14543 | * |
| 14544 | * This routine is invoked to post rpi header templates to the |
| 14545 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14546 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14547 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14548 | * |
| 14549 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14550 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14551 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14552 | **/ |
| 14553 | int |
| 14554 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14555 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14556 | unsigned long rpi; |
| 14557 | uint16_t max_rpi, rpi_limit; |
| 14558 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14559 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14560 | |
| 14561 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14562 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14563 | |
| 14564 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14565 | * Fetch the next logical rpi. Because this index is logical, |
| 14566 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14567 | */ |
| 14568 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14569 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 14570 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14571 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 14572 | else { |
| 14573 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 14574 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 14575 | phba->sli4_hba.rpi_count++; |
| 14576 | } |
| 14577 | |
| 14578 | /* |
| 14579 | * 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] | 14580 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14581 | */ |
| 14582 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 14583 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 14584 | spin_unlock_irq(&phba->hbalock); |
| 14585 | return rpi; |
| 14586 | } |
| 14587 | |
| 14588 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14589 | * RPI header postings are not required for SLI4 ports capable of |
| 14590 | * extents. |
| 14591 | */ |
| 14592 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 14593 | spin_unlock_irq(&phba->hbalock); |
| 14594 | return rpi; |
| 14595 | } |
| 14596 | |
| 14597 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14598 | * If the driver is running low on rpi resources, allocate another |
| 14599 | * page now. Note that the next_rpi value is used because |
| 14600 | * it represents how many are actually in use whereas max_rpi notes |
| 14601 | * how many are supported max by the device. |
| 14602 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14603 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14604 | spin_unlock_irq(&phba->hbalock); |
| 14605 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 14606 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 14607 | if (!rpi_hdr) { |
| 14608 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14609 | "2002 Error Could not grow rpi " |
| 14610 | "count\n"); |
| 14611 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14612 | lrpi = rpi_hdr->start_rpi; |
| 14613 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14614 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 14615 | } |
| 14616 | } |
| 14617 | |
| 14618 | return rpi; |
| 14619 | } |
| 14620 | |
| 14621 | /** |
| 14622 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14623 | * @phba: pointer to lpfc hba data structure. |
| 14624 | * |
| 14625 | * This routine is invoked to release an rpi to the pool of |
| 14626 | * available rpis maintained by the driver. |
| 14627 | **/ |
| 14628 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14629 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14630 | { |
| 14631 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 14632 | phba->sli4_hba.rpi_count--; |
| 14633 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 14634 | } |
| 14635 | } |
| 14636 | |
| 14637 | /** |
| 14638 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14639 | * @phba: pointer to lpfc hba data structure. |
| 14640 | * |
| 14641 | * This routine is invoked to release an rpi to the pool of |
| 14642 | * available rpis maintained by the driver. |
| 14643 | **/ |
| 14644 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14645 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14646 | { |
| 14647 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14648 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14649 | spin_unlock_irq(&phba->hbalock); |
| 14650 | } |
| 14651 | |
| 14652 | /** |
| 14653 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 14654 | * @phba: pointer to lpfc hba data structure. |
| 14655 | * |
| 14656 | * This routine is invoked to remove the memory region that |
| 14657 | * provided rpi via a bitmask. |
| 14658 | **/ |
| 14659 | void |
| 14660 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 14661 | { |
| 14662 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14663 | kfree(phba->sli4_hba.rpi_ids); |
| 14664 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14665 | } |
| 14666 | |
| 14667 | /** |
| 14668 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 14669 | * @phba: pointer to lpfc hba data structure. |
| 14670 | * |
| 14671 | * This routine is invoked to remove the memory region that |
| 14672 | * provided rpi via a bitmask. |
| 14673 | **/ |
| 14674 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14675 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 14676 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14677 | { |
| 14678 | LPFC_MBOXQ_t *mboxq; |
| 14679 | struct lpfc_hba *phba = ndlp->phba; |
| 14680 | int rc; |
| 14681 | |
| 14682 | /* The port is notified of the header region via a mailbox command. */ |
| 14683 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14684 | if (!mboxq) |
| 14685 | return -ENOMEM; |
| 14686 | |
| 14687 | /* Post all rpi memory regions to the port. */ |
| 14688 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14689 | if (cmpl) { |
| 14690 | mboxq->mbox_cmpl = cmpl; |
| 14691 | mboxq->context1 = arg; |
| 14692 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 14693 | } else |
| 14694 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14695 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14696 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14697 | if (rc == MBX_NOT_FINISHED) { |
| 14698 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14699 | "2010 Resume RPI Mailbox failed " |
| 14700 | "status %d, mbxStatus x%x\n", rc, |
| 14701 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 14702 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14703 | return -EIO; |
| 14704 | } |
| 14705 | return 0; |
| 14706 | } |
| 14707 | |
| 14708 | /** |
| 14709 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14710 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14711 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14712 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14713 | * |
| 14714 | * Returns: |
| 14715 | * 0 success |
| 14716 | * -Evalue otherwise |
| 14717 | **/ |
| 14718 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14719 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14720 | { |
| 14721 | LPFC_MBOXQ_t *mboxq; |
| 14722 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14723 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14724 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14725 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14726 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14727 | if (!mboxq) |
| 14728 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14729 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14730 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14731 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14732 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14733 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14734 | "2022 INIT VPI Mailbox failed " |
| 14735 | "status %d, mbxStatus x%x\n", rc, |
| 14736 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14737 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14738 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14739 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14740 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14741 | |
| 14742 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14743 | } |
| 14744 | |
| 14745 | /** |
| 14746 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 14747 | * @phba: pointer to lpfc hba data structure. |
| 14748 | * @mboxq: Pointer to mailbox object. |
| 14749 | * |
| 14750 | * This routine is invoked to manually add a single FCF record. The caller |
| 14751 | * must pass a completely initialized FCF_Record. This routine takes |
| 14752 | * care of the nonembedded mailbox operations. |
| 14753 | **/ |
| 14754 | static void |
| 14755 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 14756 | { |
| 14757 | void *virt_addr; |
| 14758 | union lpfc_sli4_cfg_shdr *shdr; |
| 14759 | uint32_t shdr_status, shdr_add_status; |
| 14760 | |
| 14761 | virt_addr = mboxq->sge_array->addr[0]; |
| 14762 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14763 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 14764 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14765 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14766 | |
| 14767 | if ((shdr_status || shdr_add_status) && |
| 14768 | (shdr_status != STATUS_FCF_IN_USE)) |
| 14769 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14770 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 14771 | "status x%x add_status x%x\n", |
| 14772 | shdr_status, shdr_add_status); |
| 14773 | |
| 14774 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14775 | } |
| 14776 | |
| 14777 | /** |
| 14778 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 14779 | * @phba: pointer to lpfc hba data structure. |
| 14780 | * @fcf_record: pointer to the initialized fcf record to add. |
| 14781 | * |
| 14782 | * This routine is invoked to manually add a single FCF record. The caller |
| 14783 | * must pass a completely initialized FCF_Record. This routine takes |
| 14784 | * care of the nonembedded mailbox operations. |
| 14785 | **/ |
| 14786 | int |
| 14787 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 14788 | { |
| 14789 | int rc = 0; |
| 14790 | LPFC_MBOXQ_t *mboxq; |
| 14791 | uint8_t *bytep; |
| 14792 | void *virt_addr; |
| 14793 | dma_addr_t phys_addr; |
| 14794 | struct lpfc_mbx_sge sge; |
| 14795 | uint32_t alloc_len, req_len; |
| 14796 | uint32_t fcfindex; |
| 14797 | |
| 14798 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14799 | if (!mboxq) { |
| 14800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14801 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 14802 | return -ENOMEM; |
| 14803 | } |
| 14804 | |
| 14805 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 14806 | sizeof(uint32_t); |
| 14807 | |
| 14808 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14809 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14810 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 14811 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 14812 | if (alloc_len < req_len) { |
| 14813 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14814 | "2523 Allocated DMA memory size (x%x) is " |
| 14815 | "less than the requested DMA memory " |
| 14816 | "size (x%x)\n", alloc_len, req_len); |
| 14817 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14818 | return -ENOMEM; |
| 14819 | } |
| 14820 | |
| 14821 | /* |
| 14822 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 14823 | * routine only uses a single SGE. |
| 14824 | */ |
| 14825 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 14826 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14827 | virt_addr = mboxq->sge_array->addr[0]; |
| 14828 | /* |
| 14829 | * Configure the FCF record for FCFI 0. This is the driver's |
| 14830 | * hardcoded default and gets used in nonFIP mode. |
| 14831 | */ |
| 14832 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 14833 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 14834 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 14835 | |
| 14836 | /* |
| 14837 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 14838 | * the FCoE header plus word10. The data copy needs to be endian |
| 14839 | * correct. |
| 14840 | */ |
| 14841 | bytep += sizeof(uint32_t); |
| 14842 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 14843 | mboxq->vport = phba->pport; |
| 14844 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 14845 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14846 | if (rc == MBX_NOT_FINISHED) { |
| 14847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14848 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 14849 | "status 0x%x\n", rc); |
| 14850 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14851 | rc = -EIO; |
| 14852 | } else |
| 14853 | rc = 0; |
| 14854 | |
| 14855 | return rc; |
| 14856 | } |
| 14857 | |
| 14858 | /** |
| 14859 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 14860 | * @phba: pointer to lpfc hba data structure. |
| 14861 | * @fcf_record: pointer to the fcf record to write the default data. |
| 14862 | * @fcf_index: FCF table entry index. |
| 14863 | * |
| 14864 | * This routine is invoked to build the driver's default FCF record. The |
| 14865 | * values used are hardcoded. This routine handles memory initialization. |
| 14866 | * |
| 14867 | **/ |
| 14868 | void |
| 14869 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 14870 | struct fcf_record *fcf_record, |
| 14871 | uint16_t fcf_index) |
| 14872 | { |
| 14873 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 14874 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 14875 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 14876 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 14877 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 14878 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 14879 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 14880 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 14881 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 14882 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 14883 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 14884 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 14885 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 14886 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 14887 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14888 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 14889 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 14890 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 14891 | /* Set the VLAN bit map */ |
| 14892 | if (phba->valid_vlan) { |
| 14893 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 14894 | = 1 << (phba->vlan_id % 8); |
| 14895 | } |
| 14896 | } |
| 14897 | |
| 14898 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14899 | * 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] | 14900 | * @phba: pointer to lpfc hba data structure. |
| 14901 | * @fcf_index: FCF table entry offset. |
| 14902 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14903 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 14904 | * record and processing it one at a time starting from the @fcf_index |
| 14905 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 14906 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 14907 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14908 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14909 | **/ |
| 14910 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14911 | 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] | 14912 | { |
| 14913 | int rc = 0, error; |
| 14914 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14915 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 14916 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 14917 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14918 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14919 | if (!mboxq) { |
| 14920 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14921 | "2000 Failed to allocate mbox for " |
| 14922 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14923 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14924 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14925 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 14926 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14927 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 14928 | if (rc) { |
| 14929 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14930 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14931 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 14932 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14933 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14934 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 14935 | |
| 14936 | spin_lock_irq(&phba->hbalock); |
| 14937 | phba->hba_flag |= FCF_TS_INPROG; |
| 14938 | spin_unlock_irq(&phba->hbalock); |
| 14939 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14940 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 14941 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14942 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 14943 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 14944 | /* Reset eligible FCF count for new scan */ |
| 14945 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 14946 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14947 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 14948 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14949 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14950 | if (error) { |
| 14951 | if (mboxq) |
| 14952 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 14953 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14954 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 14955 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14956 | spin_unlock_irq(&phba->hbalock); |
| 14957 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14958 | return error; |
| 14959 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 14960 | |
| 14961 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 14962 | * 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] | 14963 | * @phba: pointer to lpfc hba data structure. |
| 14964 | * @fcf_index: FCF table entry offset. |
| 14965 | * |
| 14966 | * 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] | 14967 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14968 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 14969 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 14970 | * otherwise. |
| 14971 | **/ |
| 14972 | int |
| 14973 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 14974 | { |
| 14975 | int rc = 0, error; |
| 14976 | LPFC_MBOXQ_t *mboxq; |
| 14977 | |
| 14978 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14979 | if (!mboxq) { |
| 14980 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 14981 | "2763 Failed to allocate mbox for " |
| 14982 | "READ_FCF cmd\n"); |
| 14983 | error = -ENOMEM; |
| 14984 | goto fail_fcf_read; |
| 14985 | } |
| 14986 | /* Construct the read FCF record mailbox command */ |
| 14987 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 14988 | if (rc) { |
| 14989 | error = -EINVAL; |
| 14990 | goto fail_fcf_read; |
| 14991 | } |
| 14992 | /* Issue the mailbox command asynchronously */ |
| 14993 | mboxq->vport = phba->pport; |
| 14994 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 14995 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14996 | if (rc == MBX_NOT_FINISHED) |
| 14997 | error = -EIO; |
| 14998 | else |
| 14999 | error = 0; |
| 15000 | |
| 15001 | fail_fcf_read: |
| 15002 | if (error && mboxq) |
| 15003 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15004 | return error; |
| 15005 | } |
| 15006 | |
| 15007 | /** |
| 15008 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15009 | * @phba: pointer to lpfc hba data structure. |
| 15010 | * @fcf_index: FCF table entry offset. |
| 15011 | * |
| 15012 | * 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] | 15013 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15014 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15015 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15016 | * otherwise. |
| 15017 | **/ |
| 15018 | int |
| 15019 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15020 | { |
| 15021 | int rc = 0, error; |
| 15022 | LPFC_MBOXQ_t *mboxq; |
| 15023 | |
| 15024 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15025 | if (!mboxq) { |
| 15026 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15027 | "2758 Failed to allocate mbox for " |
| 15028 | "READ_FCF cmd\n"); |
| 15029 | error = -ENOMEM; |
| 15030 | goto fail_fcf_read; |
| 15031 | } |
| 15032 | /* Construct the read FCF record mailbox command */ |
| 15033 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15034 | if (rc) { |
| 15035 | error = -EINVAL; |
| 15036 | goto fail_fcf_read; |
| 15037 | } |
| 15038 | /* Issue the mailbox command asynchronously */ |
| 15039 | mboxq->vport = phba->pport; |
| 15040 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15041 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15042 | if (rc == MBX_NOT_FINISHED) |
| 15043 | error = -EIO; |
| 15044 | else |
| 15045 | error = 0; |
| 15046 | |
| 15047 | fail_fcf_read: |
| 15048 | if (error && mboxq) |
| 15049 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15050 | return error; |
| 15051 | } |
| 15052 | |
| 15053 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15054 | * lpfc_check_next_fcf_pri |
| 15055 | * phba pointer to the lpfc_hba struct for this port. |
| 15056 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15057 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15058 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15059 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15060 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15061 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15062 | * fcf_indexes. |
| 15063 | * returns: |
| 15064 | * 1=success 0=failure |
| 15065 | **/ |
| 15066 | int |
| 15067 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15068 | { |
| 15069 | uint16_t next_fcf_pri; |
| 15070 | uint16_t last_index; |
| 15071 | struct lpfc_fcf_pri *fcf_pri; |
| 15072 | int rc; |
| 15073 | int ret = 0; |
| 15074 | |
| 15075 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15076 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15077 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15078 | "3060 Last IDX %d\n", last_index); |
| 15079 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 15080 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15081 | "3061 Last IDX %d\n", last_index); |
| 15082 | return 0; /* Empty rr list */ |
| 15083 | } |
| 15084 | next_fcf_pri = 0; |
| 15085 | /* |
| 15086 | * Clear the rr_bmask and set all of the bits that are at this |
| 15087 | * priority. |
| 15088 | */ |
| 15089 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15090 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15091 | spin_lock_irq(&phba->hbalock); |
| 15092 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15093 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15094 | continue; |
| 15095 | /* |
| 15096 | * the 1st priority that has not FLOGI failed |
| 15097 | * will be the highest. |
| 15098 | */ |
| 15099 | if (!next_fcf_pri) |
| 15100 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15101 | spin_unlock_irq(&phba->hbalock); |
| 15102 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15103 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15104 | fcf_pri->fcf_rec.fcf_index); |
| 15105 | if (rc) |
| 15106 | return 0; |
| 15107 | } |
| 15108 | spin_lock_irq(&phba->hbalock); |
| 15109 | } |
| 15110 | /* |
| 15111 | * if next_fcf_pri was not set above and the list is not empty then |
| 15112 | * we have failed flogis on all of them. So reset flogi failed |
| 15113 | * and start at the begining. |
| 15114 | */ |
| 15115 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15116 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15117 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15118 | /* |
| 15119 | * the 1st priority that has not FLOGI failed |
| 15120 | * will be the highest. |
| 15121 | */ |
| 15122 | if (!next_fcf_pri) |
| 15123 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15124 | spin_unlock_irq(&phba->hbalock); |
| 15125 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15126 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15127 | fcf_pri->fcf_rec.fcf_index); |
| 15128 | if (rc) |
| 15129 | return 0; |
| 15130 | } |
| 15131 | spin_lock_irq(&phba->hbalock); |
| 15132 | } |
| 15133 | } else |
| 15134 | ret = 1; |
| 15135 | spin_unlock_irq(&phba->hbalock); |
| 15136 | |
| 15137 | return ret; |
| 15138 | } |
| 15139 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15140 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15141 | * @phba: pointer to lpfc hba data structure. |
| 15142 | * |
| 15143 | * This routine is to get the next eligible FCF record index in a round |
| 15144 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15145 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15146 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15147 | * shall be returned. |
| 15148 | **/ |
| 15149 | uint16_t |
| 15150 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15151 | { |
| 15152 | uint16_t next_fcf_index; |
| 15153 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15154 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15155 | next_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15156 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
| 15157 | LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15158 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15159 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15160 | next_fcf_index); |
| 15161 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15162 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15163 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15164 | /* |
| 15165 | * If we have wrapped then we need to clear the bits that |
| 15166 | * have been tested so that we can detect when we should |
| 15167 | * change the priority level. |
| 15168 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15169 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15170 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15171 | } |
| 15172 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15173 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15174 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15175 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15176 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15177 | /* |
| 15178 | * If next fcf index is not found check if there are lower |
| 15179 | * Priority level fcf's in the fcf_priority list. |
| 15180 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15181 | * at that level and continue the selection process. |
| 15182 | */ |
| 15183 | if (lpfc_check_next_fcf_pri_level(phba)) |
| 15184 | goto next_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15185 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15186 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15187 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15188 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15189 | else { |
| 15190 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15191 | "3063 Only FCF available idx %d, flag %x\n", |
| 15192 | next_fcf_index, |
| 15193 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15194 | return next_fcf_index; |
| 15195 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15196 | } |
| 15197 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15198 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15199 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15200 | LPFC_FCF_FLOGI_FAILED) |
| 15201 | goto next_priority; |
| 15202 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15203 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15204 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15205 | next_fcf_index); |
| 15206 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15207 | return next_fcf_index; |
| 15208 | } |
| 15209 | |
| 15210 | /** |
| 15211 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15212 | * @phba: pointer to lpfc hba data structure. |
| 15213 | * |
| 15214 | * 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] | 15215 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15216 | * does not go beyond the range of the driver allocated bmask dimension |
| 15217 | * before setting the bit. |
| 15218 | * |
| 15219 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15220 | * -EINVAL. |
| 15221 | **/ |
| 15222 | int |
| 15223 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15224 | { |
| 15225 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15226 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15227 | "2610 FCF (x%x) reached driver's book " |
| 15228 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15229 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15230 | return -EINVAL; |
| 15231 | } |
| 15232 | /* Set the eligible FCF record index bmask */ |
| 15233 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15234 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15235 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15236 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15237 | "bmask\n", fcf_index); |
| 15238 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15239 | return 0; |
| 15240 | } |
| 15241 | |
| 15242 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15243 | * 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] | 15244 | * @phba: pointer to lpfc hba data structure. |
| 15245 | * |
| 15246 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15247 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15248 | * does not go beyond the range of the driver allocated bmask dimension |
| 15249 | * before clearing the bit. |
| 15250 | **/ |
| 15251 | void |
| 15252 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15253 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15254 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15255 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15256 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15257 | "2762 FCF (x%x) reached driver's book " |
| 15258 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15259 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15260 | return; |
| 15261 | } |
| 15262 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15263 | spin_lock_irq(&phba->hbalock); |
| 15264 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15265 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15266 | list_del_init(&fcf_pri->list); |
| 15267 | break; |
| 15268 | } |
| 15269 | } |
| 15270 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15271 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15272 | |
| 15273 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15274 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15275 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15276 | } |
| 15277 | |
| 15278 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15279 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15280 | * @phba: pointer to lpfc hba data structure. |
| 15281 | * |
| 15282 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15283 | * command. If the mailbox command returned failure, it will try to stop the |
| 15284 | * FCF rediscover wait timer. |
| 15285 | **/ |
| 15286 | void |
| 15287 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15288 | { |
| 15289 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15290 | uint32_t shdr_status, shdr_add_status; |
| 15291 | |
| 15292 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15293 | |
| 15294 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15295 | &redisc_fcf->header.cfg_shdr.response); |
| 15296 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15297 | &redisc_fcf->header.cfg_shdr.response); |
| 15298 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15299 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15300 | "2746 Requesting for FCF rediscovery failed " |
| 15301 | "status x%x add_status x%x\n", |
| 15302 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15303 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15304 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15305 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15306 | spin_unlock_irq(&phba->hbalock); |
| 15307 | /* |
| 15308 | * CVL event triggered FCF rediscover request failed, |
| 15309 | * last resort to re-try current registered FCF entry. |
| 15310 | */ |
| 15311 | lpfc_retry_pport_discovery(phba); |
| 15312 | } else { |
| 15313 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15314 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15315 | spin_unlock_irq(&phba->hbalock); |
| 15316 | /* |
| 15317 | * DEAD FCF event triggered FCF rediscover request |
| 15318 | * failed, last resort to fail over as a link down |
| 15319 | * to FCF registration. |
| 15320 | */ |
| 15321 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15322 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15323 | } else { |
| 15324 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15325 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15326 | /* |
| 15327 | * Start FCF rediscovery wait timer for pending FCF |
| 15328 | * before rescan FCF record table. |
| 15329 | */ |
| 15330 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15331 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15332 | |
| 15333 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15334 | } |
| 15335 | |
| 15336 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15337 | * 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] | 15338 | * @phba: pointer to lpfc hba data structure. |
| 15339 | * |
| 15340 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15341 | * by the port. |
| 15342 | **/ |
| 15343 | int |
| 15344 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15345 | { |
| 15346 | LPFC_MBOXQ_t *mbox; |
| 15347 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15348 | int rc, length; |
| 15349 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15350 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15351 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15352 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15353 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15354 | if (!mbox) { |
| 15355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15356 | "2745 Failed to allocate mbox for " |
| 15357 | "requesting FCF rediscover.\n"); |
| 15358 | return -ENOMEM; |
| 15359 | } |
| 15360 | |
| 15361 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15362 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15363 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15364 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15365 | length, LPFC_SLI4_MBX_EMBED); |
| 15366 | |
| 15367 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15368 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15369 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15370 | |
| 15371 | /* Issue the mailbox command asynchronously */ |
| 15372 | mbox->vport = phba->pport; |
| 15373 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15374 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15375 | |
| 15376 | if (rc == MBX_NOT_FINISHED) { |
| 15377 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15378 | return -EIO; |
| 15379 | } |
| 15380 | return 0; |
| 15381 | } |
| 15382 | |
| 15383 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15384 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15385 | * @phba: pointer to lpfc hba data structure. |
| 15386 | * |
| 15387 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15388 | * event when driver failed to perform fast FCF failover. |
| 15389 | **/ |
| 15390 | void |
| 15391 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15392 | { |
| 15393 | uint32_t link_state; |
| 15394 | |
| 15395 | /* |
| 15396 | * Last resort as FCF DEAD event failover will treat this as |
| 15397 | * a link down, but save the link state because we don't want |
| 15398 | * it to be changed to Link Down unless it is already down. |
| 15399 | */ |
| 15400 | link_state = phba->link_state; |
| 15401 | lpfc_linkdown(phba); |
| 15402 | phba->link_state = link_state; |
| 15403 | |
| 15404 | /* Unregister FCF if no devices connected to it */ |
| 15405 | lpfc_unregister_unused_fcf(phba); |
| 15406 | } |
| 15407 | |
| 15408 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15409 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15410 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15411 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15412 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15413 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15414 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15415 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15416 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15417 | static uint32_t |
| 15418 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15419 | { |
| 15420 | LPFC_MBOXQ_t *pmb = NULL; |
| 15421 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15422 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15423 | int rc; |
| 15424 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15425 | if (!rgn23_data) |
| 15426 | return 0; |
| 15427 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15428 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15429 | if (!pmb) { |
| 15430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15431 | "2600 failed to allocate mailbox memory\n"); |
| 15432 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15433 | } |
| 15434 | mb = &pmb->u.mb; |
| 15435 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15436 | do { |
| 15437 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15438 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15439 | |
| 15440 | if (rc != MBX_SUCCESS) { |
| 15441 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15442 | "2601 failed to read config " |
| 15443 | "region 23, rc 0x%x Status 0x%x\n", |
| 15444 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15445 | mb->un.varDmp.word_cnt = 0; |
| 15446 | } |
| 15447 | /* |
| 15448 | * dump mem may return a zero when finished or we got a |
| 15449 | * mailbox error, either way we are done. |
| 15450 | */ |
| 15451 | if (mb->un.varDmp.word_cnt == 0) |
| 15452 | break; |
| 15453 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15454 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15455 | |
| 15456 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15457 | rgn23_data + offset, |
| 15458 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15459 | offset += mb->un.varDmp.word_cnt; |
| 15460 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15461 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15462 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15463 | return offset; |
| 15464 | } |
| 15465 | |
| 15466 | /** |
| 15467 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15468 | * @phba: pointer to lpfc hba data structure. |
| 15469 | * @rgn23_data: pointer to configure region 23 data. |
| 15470 | * |
| 15471 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15472 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15473 | * will be returned, otherwise, 0 will be returned. |
| 15474 | **/ |
| 15475 | static uint32_t |
| 15476 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15477 | { |
| 15478 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15479 | struct lpfc_dmabuf *mp = NULL; |
| 15480 | struct lpfc_mqe *mqe; |
| 15481 | uint32_t data_length = 0; |
| 15482 | int rc; |
| 15483 | |
| 15484 | if (!rgn23_data) |
| 15485 | return 0; |
| 15486 | |
| 15487 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15488 | if (!mboxq) { |
| 15489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15490 | "3105 failed to allocate mailbox memory\n"); |
| 15491 | return 0; |
| 15492 | } |
| 15493 | |
| 15494 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15495 | goto out; |
| 15496 | mqe = &mboxq->u.mqe; |
| 15497 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15498 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15499 | if (rc) |
| 15500 | goto out; |
| 15501 | data_length = mqe->un.mb_words[5]; |
| 15502 | if (data_length == 0) |
| 15503 | goto out; |
| 15504 | if (data_length > DMP_RGN23_SIZE) { |
| 15505 | data_length = 0; |
| 15506 | goto out; |
| 15507 | } |
| 15508 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15509 | out: |
| 15510 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15511 | if (mp) { |
| 15512 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15513 | kfree(mp); |
| 15514 | } |
| 15515 | return data_length; |
| 15516 | } |
| 15517 | |
| 15518 | /** |
| 15519 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15520 | * @phba: pointer to lpfc hba data structure. |
| 15521 | * |
| 15522 | * This function read region 23 and parse TLV for port status to |
| 15523 | * decide if the user disaled the port. If the TLV indicates the |
| 15524 | * port is disabled, the hba_flag is set accordingly. |
| 15525 | **/ |
| 15526 | void |
| 15527 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15528 | { |
| 15529 | uint8_t *rgn23_data = NULL; |
| 15530 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15531 | uint32_t offset = 0; |
| 15532 | |
| 15533 | /* Get adapter Region 23 data */ |
| 15534 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15535 | if (!rgn23_data) |
| 15536 | goto out; |
| 15537 | |
| 15538 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15539 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15540 | else { |
| 15541 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15542 | &phba->sli4_hba.sli_intf); |
| 15543 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15544 | goto out; |
| 15545 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15546 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15547 | |
| 15548 | if (!data_size) |
| 15549 | goto out; |
| 15550 | |
| 15551 | /* Check the region signature first */ |
| 15552 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15554 | "2619 Config region 23 has bad signature\n"); |
| 15555 | goto out; |
| 15556 | } |
| 15557 | offset += 4; |
| 15558 | |
| 15559 | /* Check the data structure version */ |
| 15560 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 15561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15562 | "2620 Config region 23 has bad version\n"); |
| 15563 | goto out; |
| 15564 | } |
| 15565 | offset += 4; |
| 15566 | |
| 15567 | /* Parse TLV entries in the region */ |
| 15568 | while (offset < data_size) { |
| 15569 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 15570 | break; |
| 15571 | /* |
| 15572 | * If the TLV is not driver specific TLV or driver id is |
| 15573 | * not linux driver id, skip the record. |
| 15574 | */ |
| 15575 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 15576 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 15577 | (rgn23_data[offset + 3] != 0)) { |
| 15578 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15579 | continue; |
| 15580 | } |
| 15581 | |
| 15582 | /* Driver found a driver specific TLV in the config region */ |
| 15583 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 15584 | offset += 4; |
| 15585 | tlv_offset = 0; |
| 15586 | |
| 15587 | /* |
| 15588 | * Search for configured port state sub-TLV. |
| 15589 | */ |
| 15590 | while ((offset < data_size) && |
| 15591 | (tlv_offset < sub_tlv_len)) { |
| 15592 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 15593 | offset += 4; |
| 15594 | tlv_offset += 4; |
| 15595 | break; |
| 15596 | } |
| 15597 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 15598 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15599 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 15600 | continue; |
| 15601 | } |
| 15602 | |
| 15603 | /* This HBA contains PORT_STE configured */ |
| 15604 | if (!rgn23_data[offset + 2]) |
| 15605 | phba->hba_flag |= LINK_DISABLED; |
| 15606 | |
| 15607 | goto out; |
| 15608 | } |
| 15609 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15610 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15611 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15612 | kfree(rgn23_data); |
| 15613 | return; |
| 15614 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15615 | |
| 15616 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15617 | * lpfc_wr_object - write an object to the firmware |
| 15618 | * @phba: HBA structure that indicates port to create a queue on. |
| 15619 | * @dmabuf_list: list of dmabufs to write to the port. |
| 15620 | * @size: the total byte value of the objects to write to the port. |
| 15621 | * @offset: the current offset to be used to start the transfer. |
| 15622 | * |
| 15623 | * This routine will create a wr_object mailbox command to send to the port. |
| 15624 | * the mailbox command will be constructed using the dma buffers described in |
| 15625 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 15626 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 15627 | * used to indicate the starting offset of the transfer and will also return |
| 15628 | * the offset after the write object mailbox has completed. @size is used to |
| 15629 | * determine the end of the object and whether the eof bit should be set. |
| 15630 | * |
| 15631 | * Return 0 is successful and offset will contain the the new offset to use |
| 15632 | * for the next write. |
| 15633 | * Return negative value for error cases. |
| 15634 | **/ |
| 15635 | int |
| 15636 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 15637 | uint32_t size, uint32_t *offset) |
| 15638 | { |
| 15639 | struct lpfc_mbx_wr_object *wr_object; |
| 15640 | LPFC_MBOXQ_t *mbox; |
| 15641 | int rc = 0, i = 0; |
| 15642 | uint32_t shdr_status, shdr_add_status; |
| 15643 | uint32_t mbox_tmo; |
| 15644 | union lpfc_sli4_cfg_shdr *shdr; |
| 15645 | struct lpfc_dmabuf *dmabuf; |
| 15646 | uint32_t written = 0; |
| 15647 | |
| 15648 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15649 | if (!mbox) |
| 15650 | return -ENOMEM; |
| 15651 | |
| 15652 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15653 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 15654 | sizeof(struct lpfc_mbx_wr_object) - |
| 15655 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 15656 | |
| 15657 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 15658 | wr_object->u.request.write_offset = *offset; |
| 15659 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 15660 | wr_object->u.request.object_name[0] = |
| 15661 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 15662 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 15663 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 15664 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 15665 | break; |
| 15666 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 15667 | wr_object->u.request.bde[i].addrHigh = |
| 15668 | putPaddrHigh(dmabuf->phys); |
| 15669 | if (written + SLI4_PAGE_SIZE >= size) { |
| 15670 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15671 | (size - written); |
| 15672 | written += (size - written); |
| 15673 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 15674 | } else { |
| 15675 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15676 | SLI4_PAGE_SIZE; |
| 15677 | written += SLI4_PAGE_SIZE; |
| 15678 | } |
| 15679 | i++; |
| 15680 | } |
| 15681 | wr_object->u.request.bde_count = i; |
| 15682 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 15683 | if (!phba->sli4_hba.intr_enable) |
| 15684 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15685 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15686 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15687 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15688 | } |
| 15689 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15690 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 15691 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15692 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15693 | if (rc != MBX_TIMEOUT) |
| 15694 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15695 | if (shdr_status || shdr_add_status || rc) { |
| 15696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15697 | "3025 Write Object mailbox failed with " |
| 15698 | "status x%x add_status x%x, mbx status x%x\n", |
| 15699 | shdr_status, shdr_add_status, rc); |
| 15700 | rc = -ENXIO; |
| 15701 | } else |
| 15702 | *offset += wr_object->u.response.actual_write_length; |
| 15703 | return rc; |
| 15704 | } |
| 15705 | |
| 15706 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15707 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 15708 | * @vport: pointer to vport data structure. |
| 15709 | * |
| 15710 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 15711 | * and REG_VPI mailbox commands associated with the vport. This function |
| 15712 | * is called when driver want to restart discovery of the vport due to |
| 15713 | * a Clear Virtual Link event. |
| 15714 | **/ |
| 15715 | void |
| 15716 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 15717 | { |
| 15718 | struct lpfc_hba *phba = vport->phba; |
| 15719 | LPFC_MBOXQ_t *mb, *nextmb; |
| 15720 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15721 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15722 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15723 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15724 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15725 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15726 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15727 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15728 | spin_lock_irq(&phba->hbalock); |
| 15729 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 15730 | if (mb->vport != vport) |
| 15731 | continue; |
| 15732 | |
| 15733 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15734 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15735 | continue; |
| 15736 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15737 | list_del(&mb->list); |
| 15738 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 15739 | } |
| 15740 | /* Clean up active mailbox command with the vport */ |
| 15741 | mb = phba->sli.mbox_active; |
| 15742 | if (mb && (mb->vport == vport)) { |
| 15743 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 15744 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 15745 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15746 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15747 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15748 | /* Put reference count for delayed processing */ |
| 15749 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 15750 | /* Unregister the RPI when mailbox complete */ |
| 15751 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15752 | } |
| 15753 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15754 | /* Cleanup any mailbox completions which are not yet processed */ |
| 15755 | do { |
| 15756 | restart_loop = 0; |
| 15757 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 15758 | /* |
| 15759 | * If this mailox is already processed or it is |
| 15760 | * for another vport ignore it. |
| 15761 | */ |
| 15762 | if ((mb->vport != vport) || |
| 15763 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 15764 | continue; |
| 15765 | |
| 15766 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15767 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15768 | continue; |
| 15769 | |
| 15770 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15771 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15772 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15773 | /* Unregister the RPI when mailbox complete */ |
| 15774 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15775 | restart_loop = 1; |
| 15776 | spin_unlock_irq(&phba->hbalock); |
| 15777 | spin_lock(shost->host_lock); |
| 15778 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15779 | spin_unlock(shost->host_lock); |
| 15780 | spin_lock_irq(&phba->hbalock); |
| 15781 | break; |
| 15782 | } |
| 15783 | } |
| 15784 | } while (restart_loop); |
| 15785 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15786 | spin_unlock_irq(&phba->hbalock); |
| 15787 | |
| 15788 | /* Release the cleaned-up mailbox commands */ |
| 15789 | while (!list_empty(&mbox_cmd_list)) { |
| 15790 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15791 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15792 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 15793 | if (mp) { |
| 15794 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15795 | kfree(mp); |
| 15796 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15797 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15798 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15799 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15800 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15801 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15802 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15803 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15804 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15805 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15806 | mempool_free(mb, phba->mbox_mem_pool); |
| 15807 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15808 | |
| 15809 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 15810 | if (act_mbx_ndlp) { |
| 15811 | spin_lock(shost->host_lock); |
| 15812 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15813 | spin_unlock(shost->host_lock); |
| 15814 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15815 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15816 | } |
| 15817 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15818 | /** |
| 15819 | * lpfc_drain_txq - Drain the txq |
| 15820 | * @phba: Pointer to HBA context object. |
| 15821 | * |
| 15822 | * This function attempt to submit IOCBs on the txq |
| 15823 | * to the adapter. For SLI4 adapters, the txq contains |
| 15824 | * ELS IOCBs that have been deferred because the there |
| 15825 | * are no SGLs. This congestion can occur with large |
| 15826 | * vport counts during node discovery. |
| 15827 | **/ |
| 15828 | |
| 15829 | uint32_t |
| 15830 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 15831 | { |
| 15832 | LIST_HEAD(completions); |
| 15833 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 15834 | struct lpfc_iocbq *piocbq = 0; |
| 15835 | unsigned long iflags = 0; |
| 15836 | char *fail_msg = NULL; |
| 15837 | struct lpfc_sglq *sglq; |
| 15838 | union lpfc_wqe wqe; |
| 15839 | |
| 15840 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15841 | if (pring->txq_cnt > pring->txq_max) |
| 15842 | pring->txq_max = pring->txq_cnt; |
| 15843 | |
| 15844 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15845 | |
| 15846 | while (pring->txq_cnt) { |
| 15847 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 15848 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 15849 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
| 15850 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15851 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 15852 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15853 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15854 | break; |
| 15855 | } else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15856 | if (!piocbq) { |
| 15857 | /* The txq_cnt out of sync. This should |
| 15858 | * never happen |
| 15859 | */ |
| 15860 | sglq = __lpfc_clear_active_sglq(phba, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15861 | sglq->sli4_lxritag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15862 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15864 | "2823 txq empty and txq_cnt is %d\n ", |
| 15865 | pring->txq_cnt); |
| 15866 | break; |
| 15867 | } |
| 15868 | } |
| 15869 | |
| 15870 | /* The xri and iocb resources secured, |
| 15871 | * attempt to issue request |
| 15872 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15873 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15874 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 15875 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 15876 | fail_msg = "to convert bpl to sgl"; |
| 15877 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 15878 | fail_msg = "to convert iocb to wqe"; |
| 15879 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 15880 | fail_msg = " - Wq is full"; |
| 15881 | else |
| 15882 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 15883 | |
| 15884 | if (fail_msg) { |
| 15885 | /* Failed means we can't issue and need to cancel */ |
| 15886 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15887 | "2822 IOCB failed %s iotag 0x%x " |
| 15888 | "xri 0x%x\n", |
| 15889 | fail_msg, |
| 15890 | piocbq->iotag, piocbq->sli4_xritag); |
| 15891 | list_add_tail(&piocbq->list, &completions); |
| 15892 | } |
| 15893 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 15894 | } |
| 15895 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15896 | /* Cancel all the IOCBs that cannot be issued */ |
| 15897 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 15898 | IOERR_SLI_ABORTED); |
| 15899 | |
| 15900 | return pring->txq_cnt; |
| 15901 | } |