| 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; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 97 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 98 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 99 | /* sanity check on queue memory */ |
| 100 | if (unlikely(!q)) |
| 101 | return -ENOMEM; |
| 102 | temp_wqe = q->qe[q->host_index].wqe; |
| 103 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 104 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 105 | idx = ((q->host_index + 1) % q->entry_count); |
| 106 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 107 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 108 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 109 | } |
| 110 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 111 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 112 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 113 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 114 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 115 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 116 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 117 | |
| 118 | /* Update the host index before invoking device */ |
| 119 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 120 | |
| 121 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 122 | |
| 123 | /* Ring Doorbell */ |
| 124 | doorbell.word0 = 0; |
| 125 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); |
| 126 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); |
| 127 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); |
| 128 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 135 | * @q: The Work Queue to operate on. |
| 136 | * @index: The index to advance the hba index to. |
| 137 | * |
| 138 | * This routine will update the HBA index of a queue to reflect consumption of |
| 139 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 140 | * an entry the host calls this function to update the queue's internal |
| 141 | * pointers. This routine returns the number of entries that were consumed by |
| 142 | * the HBA. |
| 143 | **/ |
| 144 | static uint32_t |
| 145 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 146 | { |
| 147 | uint32_t released = 0; |
| 148 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 149 | /* sanity check on queue memory */ |
| 150 | if (unlikely(!q)) |
| 151 | return 0; |
| 152 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 153 | if (q->hba_index == index) |
| 154 | return 0; |
| 155 | do { |
| 156 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 157 | released++; |
| 158 | } while (q->hba_index != index); |
| 159 | return released; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 164 | * @q: The Mailbox Queue to operate on. |
| 165 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 166 | * |
| 167 | * This routine will copy the contents of @mqe to the next available entry on |
| 168 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 169 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 170 | * successful. If no entries are available on @q then this function will return |
| 171 | * -ENOMEM. |
| 172 | * The caller is expected to hold the hbalock when calling this routine. |
| 173 | **/ |
| 174 | static uint32_t |
| 175 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 176 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 177 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 178 | struct lpfc_register doorbell; |
| 179 | uint32_t host_index; |
| 180 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 181 | /* sanity check on queue memory */ |
| 182 | if (unlikely(!q)) |
| 183 | return -ENOMEM; |
| 184 | temp_mqe = q->qe[q->host_index].mqe; |
| 185 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 186 | /* If the host has not yet processed the next entry then we are done */ |
| 187 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 188 | return -ENOMEM; |
| 189 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 190 | /* Save off the mailbox pointer for completion */ |
| 191 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 192 | |
| 193 | /* Update the host index before invoking device */ |
| 194 | host_index = q->host_index; |
| 195 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 196 | |
| 197 | /* Ring Doorbell */ |
| 198 | doorbell.word0 = 0; |
| 199 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 200 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 201 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 207 | * @q: The Mailbox Queue to operate on. |
| 208 | * |
| 209 | * This routine will update the HBA index of a queue to reflect consumption of |
| 210 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 211 | * an entry the host calls this function to update the queue's internal |
| 212 | * pointers. This routine returns the number of entries that were consumed by |
| 213 | * the HBA. |
| 214 | **/ |
| 215 | static uint32_t |
| 216 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 217 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 218 | /* sanity check on queue memory */ |
| 219 | if (unlikely(!q)) |
| 220 | return 0; |
| 221 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 222 | /* Clear the mailbox pointer for completion */ |
| 223 | q->phba->mbox = NULL; |
| 224 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 230 | * @q: The Event Queue to get the first valid EQE from |
| 231 | * |
| 232 | * This routine will get the first valid Event Queue Entry from @q, update |
| 233 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 234 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 235 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 236 | **/ |
| 237 | static struct lpfc_eqe * |
| 238 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 239 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 240 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 241 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 242 | |
| 243 | /* sanity check on queue memory */ |
| 244 | if (unlikely(!q)) |
| 245 | return NULL; |
| 246 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 247 | |
| 248 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 249 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 250 | return NULL; |
| 251 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 252 | idx = ((q->hba_index + 1) % q->entry_count); |
| 253 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 254 | return NULL; |
| 255 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 256 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 257 | return eqe; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 262 | * @q: The Event Queue that the host has completed processing for. |
| 263 | * @arm: Indicates whether the host wants to arms this CQ. |
| 264 | * |
| 265 | * This routine will mark all Event Queue Entries on @q, from the last |
| 266 | * known completed entry to the last entry that was processed, as completed |
| 267 | * by clearing the valid bit for each completion queue entry. Then it will |
| 268 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 269 | * The internal host index in the @q will be updated by this routine to indicate |
| 270 | * that the host has finished processing the entries. The @arm parameter |
| 271 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 272 | * |
| 273 | * This function will return the number of EQEs that were popped. |
| 274 | **/ |
| 275 | uint32_t |
| 276 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 277 | { |
| 278 | uint32_t released = 0; |
| 279 | struct lpfc_eqe *temp_eqe; |
| 280 | struct lpfc_register doorbell; |
| 281 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 282 | /* sanity check on queue memory */ |
| 283 | if (unlikely(!q)) |
| 284 | return 0; |
| 285 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 286 | /* while there are valid entries */ |
| 287 | while (q->hba_index != q->host_index) { |
| 288 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 289 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 290 | released++; |
| 291 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 292 | } |
| 293 | if (unlikely(released == 0 && !arm)) |
| 294 | return 0; |
| 295 | |
| 296 | /* ring doorbell for number popped */ |
| 297 | doorbell.word0 = 0; |
| 298 | if (arm) { |
| 299 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 300 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 301 | } |
| 302 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 303 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 304 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 305 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 306 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 307 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 308 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 309 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 310 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 311 | return released; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 316 | * @q: The Completion Queue to get the first valid CQE from |
| 317 | * |
| 318 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 319 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 320 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 321 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 322 | **/ |
| 323 | static struct lpfc_cqe * |
| 324 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 325 | { |
| 326 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 327 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 328 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 329 | /* sanity check on queue memory */ |
| 330 | if (unlikely(!q)) |
| 331 | return NULL; |
| 332 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 333 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 334 | 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] | 335 | return NULL; |
| 336 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 337 | idx = ((q->hba_index + 1) % q->entry_count); |
| 338 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 339 | return NULL; |
| 340 | |
| 341 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 342 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 343 | return cqe; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 348 | * @q: The Completion Queue that the host has completed processing for. |
| 349 | * @arm: Indicates whether the host wants to arms this CQ. |
| 350 | * |
| 351 | * This routine will mark all Completion queue entries on @q, from the last |
| 352 | * known completed entry to the last entry that was processed, as completed |
| 353 | * by clearing the valid bit for each completion queue entry. Then it will |
| 354 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 355 | * The internal host index in the @q will be updated by this routine to indicate |
| 356 | * that the host has finished processing the entries. The @arm parameter |
| 357 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 358 | * |
| 359 | * This function will return the number of CQEs that were released. |
| 360 | **/ |
| 361 | uint32_t |
| 362 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 363 | { |
| 364 | uint32_t released = 0; |
| 365 | struct lpfc_cqe *temp_qe; |
| 366 | struct lpfc_register doorbell; |
| 367 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 368 | /* sanity check on queue memory */ |
| 369 | if (unlikely(!q)) |
| 370 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 371 | /* while there are valid entries */ |
| 372 | while (q->hba_index != q->host_index) { |
| 373 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 374 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 375 | released++; |
| 376 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 377 | } |
| 378 | if (unlikely(released == 0 && !arm)) |
| 379 | return 0; |
| 380 | |
| 381 | /* ring doorbell for number popped */ |
| 382 | doorbell.word0 = 0; |
| 383 | if (arm) |
| 384 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 385 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 386 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 387 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 388 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 389 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 390 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 391 | return released; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 396 | * @q: The Header Receive Queue to operate on. |
| 397 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 398 | * |
| 399 | * This routine will copy the contents of @wqe to the next available entry on |
| 400 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 401 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 402 | * index that the rqe was copied to if successful. If no entries are available |
| 403 | * on @q then this function will return -ENOMEM. |
| 404 | * The caller is expected to hold the hbalock when calling this routine. |
| 405 | **/ |
| 406 | static int |
| 407 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 408 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 409 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 410 | struct lpfc_rqe *temp_hrqe; |
| 411 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 412 | struct lpfc_register doorbell; |
| 413 | int put_index = hq->host_index; |
| 414 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 415 | /* sanity check on queue memory */ |
| 416 | if (unlikely(!hq) || unlikely(!dq)) |
| 417 | return -ENOMEM; |
| 418 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 419 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 420 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 421 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 422 | return -EINVAL; |
| 423 | if (hq->host_index != dq->host_index) |
| 424 | return -EINVAL; |
| 425 | /* If the host has not yet processed the next entry then we are done */ |
| 426 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 427 | return -EBUSY; |
| 428 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 429 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 430 | |
| 431 | /* Update the host index to point to the next slot */ |
| 432 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 433 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 434 | |
| 435 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 436 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 437 | doorbell.word0 = 0; |
| 438 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 439 | hq->entry_repost); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 440 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
| 441 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); |
| 442 | } |
| 443 | return put_index; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 448 | * @q: The Header Receive Queue to operate on. |
| 449 | * |
| 450 | * This routine will update the HBA index of a queue to reflect consumption of |
| 451 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 452 | * consumed an entry the host calls this function to update the queue's |
| 453 | * internal pointers. This routine returns the number of entries that were |
| 454 | * consumed by the HBA. |
| 455 | **/ |
| 456 | static uint32_t |
| 457 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 458 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 459 | /* sanity check on queue memory */ |
| 460 | if (unlikely(!hq) || unlikely(!dq)) |
| 461 | return 0; |
| 462 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 463 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 464 | return 0; |
| 465 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 466 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 467 | return 1; |
| 468 | } |
| 469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 470 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 471 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 472 | * @phba: Pointer to HBA context object. |
| 473 | * @pring: Pointer to driver SLI ring object. |
| 474 | * |
| 475 | * This function returns pointer to next command iocb entry |
| 476 | * in the command ring. The caller must hold hbalock to prevent |
| 477 | * other threads consume the next command iocb. |
| 478 | * SLI-2/SLI-3 provide different sized iocbs. |
| 479 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 480 | static inline IOCB_t * |
| 481 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 482 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 483 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 484 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 485 | } |
| 486 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 488 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 489 | * @phba: Pointer to HBA context object. |
| 490 | * @pring: Pointer to driver SLI ring object. |
| 491 | * |
| 492 | * This function returns pointer to next response iocb entry |
| 493 | * in the response ring. The caller must hold hbalock to make sure |
| 494 | * that no other thread consume the next response iocb. |
| 495 | * SLI-2/SLI-3 provide different sized iocbs. |
| 496 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 497 | static inline IOCB_t * |
| 498 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 499 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 500 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 501 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 502 | } |
| 503 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 504 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 505 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 506 | * @phba: Pointer to HBA context object. |
| 507 | * |
| 508 | * This function is called with hbalock held. This function |
| 509 | * allocates a new driver iocb object from the iocb pool. If the |
| 510 | * allocation is successful, it returns pointer to the newly |
| 511 | * allocated iocb object else it returns NULL. |
| 512 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 513 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 514 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 515 | { |
| 516 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 517 | struct lpfc_iocbq * iocbq = NULL; |
| 518 | |
| 519 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 520 | if (iocbq) |
| 521 | phba->iocb_cnt++; |
| 522 | if (phba->iocb_cnt > phba->iocb_max) |
| 523 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 524 | return iocbq; |
| 525 | } |
| 526 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 527 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 528 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 529 | * @phba: Pointer to HBA context object. |
| 530 | * @xritag: XRI value. |
| 531 | * |
| 532 | * This function clears the sglq pointer from the array of acive |
| 533 | * sglq's. The xritag that is passed in is used to index into the |
| 534 | * array. Before the xritag can be used it needs to be adjusted |
| 535 | * by subtracting the xribase. |
| 536 | * |
| 537 | * Returns sglq ponter = success, NULL = Failure. |
| 538 | **/ |
| 539 | static struct lpfc_sglq * |
| 540 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 541 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 542 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 543 | |
| 544 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 545 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 546 | return sglq; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 551 | * @phba: Pointer to HBA context object. |
| 552 | * @xritag: XRI value. |
| 553 | * |
| 554 | * This function returns the sglq pointer from the array of acive |
| 555 | * sglq's. The xritag that is passed in is used to index into the |
| 556 | * array. Before the xritag can be used it needs to be adjusted |
| 557 | * by subtracting the xribase. |
| 558 | * |
| 559 | * Returns sglq ponter = success, NULL = Failure. |
| 560 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 561 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 562 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 563 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 564 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 565 | |
| 566 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 567 | return sglq; |
| 568 | } |
| 569 | |
| 570 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 571 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 572 | * @phba: Pointer to HBA context object. |
| 573 | * @xritag: xri used in this exchange. |
| 574 | * @rrq: The RRQ to be cleared. |
| 575 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 576 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 577 | void |
| 578 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 579 | uint16_t xritag, |
| 580 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 581 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 582 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 583 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 584 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 585 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 586 | |
| 587 | /* The target DID could have been swapped (cable swap) |
| 588 | * we should use the ndlp from the findnode if it is |
| 589 | * available. |
| 590 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 591 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 592 | ndlp = rrq->ndlp; |
| 593 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 594 | if (!ndlp) |
| 595 | goto out; |
| 596 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 597 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 598 | rrq->send_rrq = 0; |
| 599 | rrq->xritag = 0; |
| 600 | rrq->rrq_stop_time = 0; |
| 601 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 602 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 603 | mempool_free(rrq, phba->rrq_pool); |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 608 | * @phba: Pointer to HBA context object. |
| 609 | * |
| 610 | * This function is called with hbalock held. This function |
| 611 | * Checks if stop_time (ratov from setting rrq active) has |
| 612 | * been reached, if it has and the send_rrq flag is set then |
| 613 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 614 | * then it will just call the routine to clear the rrq and |
| 615 | * free the rrq resource. |
| 616 | * The timer is set to the next rrq that is going to expire before |
| 617 | * leaving the routine. |
| 618 | * |
| 619 | **/ |
| 620 | void |
| 621 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 622 | { |
| 623 | struct lpfc_node_rrq *rrq; |
| 624 | struct lpfc_node_rrq *nextrrq; |
| 625 | unsigned long next_time; |
| 626 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 627 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 628 | |
| 629 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 630 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 631 | next_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 632 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 633 | &phba->active_rrq_list, list) { |
| 634 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 635 | list_move(&rrq->list, &send_rrq); |
| 636 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 637 | next_time = rrq->rrq_stop_time; |
| 638 | } |
| 639 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 640 | if (!list_empty(&phba->active_rrq_list)) |
| 641 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 642 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 643 | list_del(&rrq->list); |
| 644 | if (!rrq->send_rrq) |
| 645 | /* this call will free the rrq */ |
| 646 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 647 | else if (lpfc_send_rrq(phba, rrq)) { |
| 648 | /* if we send the rrq then the completion handler |
| 649 | * will clear the bit in the xribitmap. |
| 650 | */ |
| 651 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 652 | rrq); |
| 653 | } |
| 654 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /** |
| 658 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 659 | * @vport: Pointer to vport context object. |
| 660 | * @xri: The xri used in the exchange. |
| 661 | * @did: The targets DID for this exchange. |
| 662 | * |
| 663 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 664 | * rrq = rrq for this xri and target. |
| 665 | **/ |
| 666 | struct lpfc_node_rrq * |
| 667 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 668 | { |
| 669 | struct lpfc_hba *phba = vport->phba; |
| 670 | struct lpfc_node_rrq *rrq; |
| 671 | struct lpfc_node_rrq *nextrrq; |
| 672 | unsigned long iflags; |
| 673 | |
| 674 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 675 | return NULL; |
| 676 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 677 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 678 | if (rrq->vport == vport && rrq->xritag == xri && |
| 679 | rrq->nlp_DID == did){ |
| 680 | list_del(&rrq->list); |
| 681 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 682 | return rrq; |
| 683 | } |
| 684 | } |
| 685 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 686 | return NULL; |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 691 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 692 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 693 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 694 | * phba->active_rrq_list and clear the rrq. |
| 695 | * 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] | 696 | **/ |
| 697 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 698 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 699 | |
| 700 | { |
| 701 | struct lpfc_hba *phba = vport->phba; |
| 702 | struct lpfc_node_rrq *rrq; |
| 703 | struct lpfc_node_rrq *nextrrq; |
| 704 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 705 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 706 | |
| 707 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 708 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 709 | if (!ndlp) { |
| 710 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 711 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 712 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 713 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 714 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 715 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 716 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 717 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 718 | |
| 719 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 720 | list_del(&rrq->list); |
| 721 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 722 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** |
| 726 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 727 | * @phba: Pointer to HBA context object. |
| 728 | * |
| 729 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 730 | * calling __lpfc_clr_active_rrq |
| 731 | * |
| 732 | **/ |
| 733 | void |
| 734 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 735 | { |
| 736 | struct lpfc_node_rrq *rrq; |
| 737 | struct lpfc_node_rrq *nextrrq; |
| 738 | unsigned long next_time; |
| 739 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 740 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 741 | |
| 742 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 743 | return; |
| 744 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 745 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 746 | next_time = jiffies + HZ * (phba->fc_ratov * 2); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 747 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 748 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 749 | |
| 750 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 751 | list_del(&rrq->list); |
| 752 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 753 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 754 | if (!list_empty(&phba->active_rrq_list)) |
| 755 | mod_timer(&phba->rrq_tmr, next_time); |
| 756 | } |
| 757 | |
| 758 | |
| 759 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 760 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 761 | * @phba: Pointer to HBA context object. |
| 762 | * @ndlp: Targets nodelist pointer for this exchange. |
| 763 | * @xritag the xri in the bitmap to test. |
| 764 | * |
| 765 | * This function is called with hbalock held. This function |
| 766 | * returns 0 = rrq not active for this xri |
| 767 | * 1 = rrq is valid for this xri. |
| 768 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 769 | int |
| 770 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 771 | uint16_t xritag) |
| 772 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 773 | if (!ndlp) |
| 774 | return 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 775 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 776 | return 1; |
| 777 | else |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 783 | * @phba: Pointer to HBA context object. |
| 784 | * @ndlp: nodelist pointer for this target. |
| 785 | * @xritag: xri used in this exchange. |
| 786 | * @rxid: Remote Exchange ID. |
| 787 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 788 | * |
| 789 | * This function takes the hbalock. |
| 790 | * The active bit is always set in the active rrq xri_bitmap even |
| 791 | * if there is no slot avaiable for the other rrq information. |
| 792 | * |
| 793 | * returns 0 rrq actived for this xri |
| 794 | * < 0 No memory or invalid ndlp. |
| 795 | **/ |
| 796 | int |
| 797 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 798 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 799 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 800 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 801 | struct lpfc_node_rrq *rrq; |
| 802 | int empty; |
| 803 | |
| 804 | if (!ndlp) |
| 805 | return -EINVAL; |
| 806 | |
| 807 | if (!phba->cfg_enable_rrq) |
| 808 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 809 | |
| 810 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 811 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 812 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 813 | goto out; |
| 814 | } |
| 815 | |
| 816 | /* |
| 817 | * set the active bit even if there is no mem available. |
| 818 | */ |
| 819 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 820 | goto out; |
| 821 | |
| 822 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 823 | goto out; |
| 824 | |
| 825 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
| 826 | goto out; |
| 827 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 828 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 829 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 830 | if (!rrq) { |
| 831 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 832 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 833 | " DID:0x%x Send:%d\n", |
| 834 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 835 | return -EINVAL; |
| 836 | } |
| 837 | rrq->send_rrq = send_rrq; |
| 838 | rrq->xritag = xritag; |
| 839 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
| 840 | rrq->ndlp = ndlp; |
| 841 | rrq->nlp_DID = ndlp->nlp_DID; |
| 842 | rrq->vport = ndlp->vport; |
| 843 | rrq->rxid = rxid; |
| 844 | rrq->send_rrq = send_rrq; |
| 845 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 846 | empty = list_empty(&phba->active_rrq_list); |
| 847 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 848 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 849 | if (empty) |
| 850 | lpfc_worker_wake_up(phba); |
| 851 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 852 | return 0; |
| 853 | out: |
| 854 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 855 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 856 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 857 | " DID:0x%x Send:%d\n", |
| 858 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 859 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 863 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 864 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 866 | * |
| 867 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 868 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 869 | * list is not empty then it is successful, it returns pointer to the newly |
| 870 | * allocated sglq object else it returns NULL. |
| 871 | **/ |
| 872 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 873 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 874 | { |
| 875 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 876 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 877 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 878 | struct lpfc_scsi_buf *lpfc_cmd; |
| 879 | struct lpfc_nodelist *ndlp; |
| 880 | int found = 0; |
| 881 | |
| 882 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 883 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 884 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 885 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 886 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 887 | ndlp = piocbq->context_un.ndlp; |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 888 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
| 889 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
| 890 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 891 | else |
| 892 | ndlp = piocbq->context1; |
| 893 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 894 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 895 | start_sglq = sglq; |
| 896 | while (!found) { |
| 897 | if (!sglq) |
| 898 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 899 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 900 | /* This xri has an rrq outstanding for this DID. |
| 901 | * put it back in the list and get another xri. |
| 902 | */ |
| 903 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 904 | sglq = NULL; |
| 905 | list_remove_head(lpfc_sgl_list, sglq, |
| 906 | struct lpfc_sglq, list); |
| 907 | if (sglq == start_sglq) { |
| 908 | sglq = NULL; |
| 909 | break; |
| 910 | } else |
| 911 | continue; |
| 912 | } |
| 913 | sglq->ndlp = ndlp; |
| 914 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 915 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 916 | sglq->state = SGL_ALLOCATED; |
| 917 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 918 | return sglq; |
| 919 | } |
| 920 | |
| 921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 922 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 923 | * @phba: Pointer to HBA context object. |
| 924 | * |
| 925 | * This function is called with no lock held. This function |
| 926 | * allocates a new driver iocb object from the iocb pool. If the |
| 927 | * allocation is successful, it returns pointer to the newly |
| 928 | * allocated iocb object else it returns NULL. |
| 929 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 930 | struct lpfc_iocbq * |
| 931 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 932 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 933 | struct lpfc_iocbq * iocbq = NULL; |
| 934 | unsigned long iflags; |
| 935 | |
| 936 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 937 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 938 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 939 | return iocbq; |
| 940 | } |
| 941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 942 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 943 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 944 | * @phba: Pointer to HBA context object. |
| 945 | * @iocbq: Pointer to driver iocb object. |
| 946 | * |
| 947 | * This function is called with hbalock held to release driver |
| 948 | * iocb object to the iocb pool. The iotag in the iocb object |
| 949 | * does not change for each use of the iocb object. This function |
| 950 | * clears all other fields of the iocb object when it is freed. |
| 951 | * The sqlq structure that holds the xritag and phys and virtual |
| 952 | * mappings for the scatter gather list is retrieved from the |
| 953 | * active array of sglq. The get of the sglq pointer also clears |
| 954 | * the entry in the array. If the status of the IO indiactes that |
| 955 | * this IO was aborted then the sglq entry it put on the |
| 956 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 957 | * IO has good status or fails for any other reason then the sglq |
| 958 | * entry is added to the free list (lpfc_sgl_list). |
| 959 | **/ |
| 960 | static void |
| 961 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 962 | { |
| 963 | struct lpfc_sglq *sglq; |
| 964 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 965 | unsigned long iflag = 0; |
| 966 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 967 | |
| 968 | if (iocbq->sli4_xritag == NO_XRI) |
| 969 | sglq = NULL; |
| 970 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 971 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 972 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 973 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 974 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 975 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 976 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 977 | iflag); |
| 978 | list_add(&sglq->list, |
| 979 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 980 | spin_unlock_irqrestore( |
| 981 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 982 | } else { |
| 983 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 984 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 985 | list_add_tail(&sglq->list, |
| 986 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 987 | |
| 988 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 989 | if (pring->txq_cnt) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 990 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 991 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | |
| 995 | /* |
| 996 | * Clean all volatile data fields, preserve iotag and node struct. |
| 997 | */ |
| 998 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 999 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1000 | iocbq->sli4_xritag = NO_XRI; |
| 1001 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1002 | } |
| 1003 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1004 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1005 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1006 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1007 | * @phba: Pointer to HBA context object. |
| 1008 | * @iocbq: Pointer to driver iocb object. |
| 1009 | * |
| 1010 | * This function is called with hbalock held to release driver |
| 1011 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1012 | * does not change for each use of the iocb object. This function |
| 1013 | * clears all other fields of the iocb object when it is freed. |
| 1014 | **/ |
| 1015 | static void |
| 1016 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1017 | { |
| 1018 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1019 | |
| 1020 | /* |
| 1021 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1022 | */ |
| 1023 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1024 | iocbq->sli4_xritag = NO_XRI; |
| 1025 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1026 | } |
| 1027 | |
| 1028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1029 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1030 | * @phba: Pointer to HBA context object. |
| 1031 | * @iocbq: Pointer to driver iocb object. |
| 1032 | * |
| 1033 | * This function is called with hbalock held to release driver |
| 1034 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1035 | * does not change for each use of the iocb object. This function |
| 1036 | * clears all other fields of the iocb object when it is freed. |
| 1037 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1038 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1039 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1040 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1041 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1042 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1043 | } |
| 1044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1046 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1047 | * @phba: Pointer to HBA context object. |
| 1048 | * @iocbq: Pointer to driver iocb object. |
| 1049 | * |
| 1050 | * This function is called with no lock held to release the iocb to |
| 1051 | * iocb pool. |
| 1052 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1053 | void |
| 1054 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1055 | { |
| 1056 | unsigned long iflags; |
| 1057 | |
| 1058 | /* |
| 1059 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1060 | */ |
| 1061 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1062 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1063 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1064 | } |
| 1065 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1066 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1067 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1068 | * @phba: Pointer to HBA context object. |
| 1069 | * @iocblist: List of IOCBs. |
| 1070 | * @ulpstatus: ULP status in IOCB command field. |
| 1071 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1072 | * |
| 1073 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1074 | * on the list by invoking the complete callback function associated with the |
| 1075 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1076 | * fields. |
| 1077 | **/ |
| 1078 | void |
| 1079 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1080 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1081 | { |
| 1082 | struct lpfc_iocbq *piocb; |
| 1083 | |
| 1084 | while (!list_empty(iocblist)) { |
| 1085 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
| 1086 | |
| 1087 | if (!piocb->iocb_cmpl) |
| 1088 | lpfc_sli_release_iocbq(phba, piocb); |
| 1089 | else { |
| 1090 | piocb->iocb.ulpStatus = ulpstatus; |
| 1091 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1092 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1093 | } |
| 1094 | } |
| 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1099 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1100 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1101 | * |
| 1102 | * This function is called by ring event handler function to get the iocb type. |
| 1103 | * This function translates the iocb command to an iocb command type used to |
| 1104 | * decide the final disposition of each completed IOCB. |
| 1105 | * The function returns |
| 1106 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1107 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1108 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1109 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1110 | * |
| 1111 | * The caller is not required to hold any lock. |
| 1112 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | static lpfc_iocb_type |
| 1114 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1115 | { |
| 1116 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1117 | |
| 1118 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1119 | return 0; |
| 1120 | |
| 1121 | switch (iocb_cmnd) { |
| 1122 | case CMD_XMIT_SEQUENCE_CR: |
| 1123 | case CMD_XMIT_SEQUENCE_CX: |
| 1124 | case CMD_XMIT_BCAST_CN: |
| 1125 | case CMD_XMIT_BCAST_CX: |
| 1126 | case CMD_ELS_REQUEST_CR: |
| 1127 | case CMD_ELS_REQUEST_CX: |
| 1128 | case CMD_CREATE_XRI_CR: |
| 1129 | case CMD_CREATE_XRI_CX: |
| 1130 | case CMD_GET_RPI_CN: |
| 1131 | case CMD_XMIT_ELS_RSP_CX: |
| 1132 | case CMD_GET_RPI_CR: |
| 1133 | case CMD_FCP_IWRITE_CR: |
| 1134 | case CMD_FCP_IWRITE_CX: |
| 1135 | case CMD_FCP_IREAD_CR: |
| 1136 | case CMD_FCP_IREAD_CX: |
| 1137 | case CMD_FCP_ICMND_CR: |
| 1138 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1139 | case CMD_FCP_TSEND_CX: |
| 1140 | case CMD_FCP_TRSP_CX: |
| 1141 | case CMD_FCP_TRECEIVE_CX: |
| 1142 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | case CMD_ADAPTER_MSG: |
| 1144 | case CMD_ADAPTER_DUMP: |
| 1145 | case CMD_XMIT_SEQUENCE64_CR: |
| 1146 | case CMD_XMIT_SEQUENCE64_CX: |
| 1147 | case CMD_XMIT_BCAST64_CN: |
| 1148 | case CMD_XMIT_BCAST64_CX: |
| 1149 | case CMD_ELS_REQUEST64_CR: |
| 1150 | case CMD_ELS_REQUEST64_CX: |
| 1151 | case CMD_FCP_IWRITE64_CR: |
| 1152 | case CMD_FCP_IWRITE64_CX: |
| 1153 | case CMD_FCP_IREAD64_CR: |
| 1154 | case CMD_FCP_IREAD64_CX: |
| 1155 | case CMD_FCP_ICMND64_CR: |
| 1156 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1157 | case CMD_FCP_TSEND64_CX: |
| 1158 | case CMD_FCP_TRSP64_CX: |
| 1159 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | case CMD_GEN_REQUEST64_CR: |
| 1161 | case CMD_GEN_REQUEST64_CX: |
| 1162 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1163 | case DSSCMD_IWRITE64_CR: |
| 1164 | case DSSCMD_IWRITE64_CX: |
| 1165 | case DSSCMD_IREAD64_CR: |
| 1166 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1167 | type = LPFC_SOL_IOCB; |
| 1168 | break; |
| 1169 | case CMD_ABORT_XRI_CN: |
| 1170 | case CMD_ABORT_XRI_CX: |
| 1171 | case CMD_CLOSE_XRI_CN: |
| 1172 | case CMD_CLOSE_XRI_CX: |
| 1173 | case CMD_XRI_ABORTED_CX: |
| 1174 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1175 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1176 | type = LPFC_ABORT_IOCB; |
| 1177 | break; |
| 1178 | case CMD_RCV_SEQUENCE_CX: |
| 1179 | case CMD_RCV_ELS_REQ_CX: |
| 1180 | case CMD_RCV_SEQUENCE64_CX: |
| 1181 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1182 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1183 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1184 | case CMD_IOCB_RCV_ELS64_CX: |
| 1185 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1186 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1187 | type = LPFC_UNSOL_IOCB; |
| 1188 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1189 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1190 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1191 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1192 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1193 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1194 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1195 | case CMD_IOCB_RET_HBQE64_CN: |
| 1196 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1197 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1198 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1199 | case CMD_IOCB_LOGENTRY_CN: |
| 1200 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1201 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1202 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1203 | type = LPFC_UNKNOWN_IOCB; |
| 1204 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1205 | default: |
| 1206 | type = LPFC_UNKNOWN_IOCB; |
| 1207 | break; |
| 1208 | } |
| 1209 | |
| 1210 | return type; |
| 1211 | } |
| 1212 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1213 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1214 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1215 | * @phba: Pointer to HBA context object. |
| 1216 | * |
| 1217 | * This function is called from SLI initialization code |
| 1218 | * to configure every ring of the HBA's SLI interface. The |
| 1219 | * caller is not required to hold any lock. This function issues |
| 1220 | * a config_ring mailbox command for each ring. |
| 1221 | * This function returns zero if successful else returns a negative |
| 1222 | * error code. |
| 1223 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1225 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | { |
| 1227 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1228 | LPFC_MBOXQ_t *pmb; |
| 1229 | MAILBOX_t *pmbox; |
| 1230 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1232 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1233 | if (!pmb) |
| 1234 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1235 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1236 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | lpfc_config_ring(phba, i, pmb); |
| 1239 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1240 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1242 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1244 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1245 | rc, pmbox->mbxCommand, |
| 1246 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1247 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1248 | ret = -ENXIO; |
| 1249 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1250 | } |
| 1251 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1252 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1253 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | } |
| 1255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1257 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1258 | * @phba: Pointer to HBA context object. |
| 1259 | * @pring: Pointer to driver SLI ring object. |
| 1260 | * @piocb: Pointer to the driver iocb object. |
| 1261 | * |
| 1262 | * This function is called with hbalock held. The function adds the |
| 1263 | * new iocb to txcmplq of the given ring. This function always returns |
| 1264 | * 0. If this function is called for ELS ring, this function checks if |
| 1265 | * there is a vport associated with the ELS command. This function also |
| 1266 | * starts els_tmofunc timer if this is an ELS command. |
| 1267 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1268 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1270 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1272 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1273 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1275 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
| 1276 | pring->txcmplq_max = pring->txcmplq_cnt; |
| 1277 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1278 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1279 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1280 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1281 | if (!piocb->vport) |
| 1282 | BUG(); |
| 1283 | else |
| 1284 | mod_timer(&piocb->vport->els_tmofunc, |
| 1285 | jiffies + HZ * (phba->fc_ratov << 1)); |
| 1286 | } |
| 1287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1289 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | } |
| 1291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1293 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1294 | * @phba: Pointer to HBA context object. |
| 1295 | * @pring: Pointer to driver SLI ring object. |
| 1296 | * |
| 1297 | * This function is called with hbalock held to get next |
| 1298 | * iocb in txq of the given ring. If there is any iocb in |
| 1299 | * the txq, the function returns first iocb in the list after |
| 1300 | * removing the iocb from the list, else it returns NULL. |
| 1301 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1302 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1303 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | struct lpfc_iocbq *cmd_iocb; |
| 1306 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1307 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
| 1308 | if (cmd_iocb != NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | pring->txq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1310 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | } |
| 1312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1314 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * @phba: Pointer to HBA context object. |
| 1316 | * @pring: Pointer to driver SLI ring object. |
| 1317 | * |
| 1318 | * This function is called with hbalock held and the caller must post the |
| 1319 | * iocb without releasing the lock. If the caller releases the lock, |
| 1320 | * iocb slot returned by the function is not guaranteed to be available. |
| 1321 | * The function returns pointer to the next available iocb slot if there |
| 1322 | * is available slot in the ring, else it returns NULL. |
| 1323 | * If the get index of the ring is ahead of the put index, the function |
| 1324 | * will post an error attention event to the worker thread to take the |
| 1325 | * HBA to offline state. |
| 1326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | static IOCB_t * |
| 1328 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1329 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1330 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1331 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
| 1332 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1333 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1334 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1336 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1337 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1339 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1341 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1343 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1344 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1345 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1346 | pring->sli.sli3.local_getidx, |
| 1347 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1349 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1350 | /* |
| 1351 | * All error attention handlers are posted to |
| 1352 | * worker thread |
| 1353 | */ |
| 1354 | phba->work_ha |= HA_ERATT; |
| 1355 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1356 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1357 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | |
| 1359 | return NULL; |
| 1360 | } |
| 1361 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1362 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | return NULL; |
| 1364 | } |
| 1365 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1366 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | } |
| 1368 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1369 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1370 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1371 | * @phba: Pointer to HBA context object. |
| 1372 | * @iocbq: Pointer to driver iocb object. |
| 1373 | * |
| 1374 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1375 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1376 | * array and assigns a new iotag. |
| 1377 | * The function returns the allocated iotag if successful, else returns zero. |
| 1378 | * Zero is not a valid iotag. |
| 1379 | * The caller is not required to hold any lock. |
| 1380 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1381 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1382 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1384 | struct lpfc_iocbq **new_arr; |
| 1385 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1386 | size_t new_len; |
| 1387 | struct lpfc_sli *psli = &phba->sli; |
| 1388 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1390 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1391 | iotag = psli->last_iotag; |
| 1392 | if(++iotag < psli->iocbq_lookup_len) { |
| 1393 | psli->last_iotag = iotag; |
| 1394 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1395 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1396 | iocbq->iotag = iotag; |
| 1397 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1398 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1399 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1400 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1401 | spin_unlock_irq(&phba->hbalock); |
| 1402 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1403 | GFP_KERNEL); |
| 1404 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1406 | old_arr = psli->iocbq_lookup; |
| 1407 | if (new_len <= psli->iocbq_lookup_len) { |
| 1408 | /* highly unprobable case */ |
| 1409 | kfree(new_arr); |
| 1410 | iotag = psli->last_iotag; |
| 1411 | if(++iotag < psli->iocbq_lookup_len) { |
| 1412 | psli->last_iotag = iotag; |
| 1413 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1414 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1415 | iocbq->iotag = iotag; |
| 1416 | return iotag; |
| 1417 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1418 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
| 1421 | if (psli->iocbq_lookup) |
| 1422 | memcpy(new_arr, old_arr, |
| 1423 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1424 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1425 | psli->iocbq_lookup = new_arr; |
| 1426 | psli->iocbq_lookup_len = new_len; |
| 1427 | psli->last_iotag = iotag; |
| 1428 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1429 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1430 | iocbq->iotag = iotag; |
| 1431 | kfree(old_arr); |
| 1432 | return iotag; |
| 1433 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1434 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1435 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1437 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1438 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1439 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1441 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | } |
| 1443 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1444 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1445 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1446 | * @phba: Pointer to HBA context object. |
| 1447 | * @pring: Pointer to driver SLI ring object. |
| 1448 | * @iocb: Pointer to iocb slot in the ring. |
| 1449 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1450 | * posted to firmware. |
| 1451 | * |
| 1452 | * This function is called with hbalock held to post a new iocb to |
| 1453 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1454 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1455 | * a completion call back for this iocb else the function will free the |
| 1456 | * iocb object. |
| 1457 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | static void |
| 1459 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1460 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1461 | { |
| 1462 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1463 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1465 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1467 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1468 | if (pring->ringno == LPFC_ELS_RING) { |
| 1469 | lpfc_debugfs_slow_ring_trc(phba, |
| 1470 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1471 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1472 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1473 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1474 | } |
| 1475 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1476 | /* |
| 1477 | * Issue iocb command to adapter |
| 1478 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | wmb(); |
| 1481 | pring->stats.iocb_cmd++; |
| 1482 | |
| 1483 | /* |
| 1484 | * If there is no completion routine to call, we can release the |
| 1485 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1486 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1487 | */ |
| 1488 | if (nextiocb->iocb_cmpl) |
| 1489 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1490 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1491 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | |
| 1493 | /* |
| 1494 | * Let the HBA know what IOCB slot will be the next one the |
| 1495 | * driver will put a command into. |
| 1496 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1497 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1498 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1501 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1502 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1503 | * @phba: Pointer to HBA context object. |
| 1504 | * @pring: Pointer to driver SLI ring object. |
| 1505 | * |
| 1506 | * The caller is not required to hold any lock for calling this function. |
| 1507 | * This function updates the chip attention bits for the ring to inform firmware |
| 1508 | * that there are pending work to be done for this ring and requests an |
| 1509 | * interrupt when there is space available in the ring. This function is |
| 1510 | * called when the driver is unable to post more iocbs to the ring due |
| 1511 | * to unavailability of space in the ring. |
| 1512 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1514 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1515 | { |
| 1516 | int ringno = pring->ringno; |
| 1517 | |
| 1518 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1519 | |
| 1520 | wmb(); |
| 1521 | |
| 1522 | /* |
| 1523 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1524 | * The HBA will tell us when an IOCB entry is available. |
| 1525 | */ |
| 1526 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1527 | readl(phba->CAregaddr); /* flush */ |
| 1528 | |
| 1529 | pring->stats.iocb_cmd_full++; |
| 1530 | } |
| 1531 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1532 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1533 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | * @phba: Pointer to HBA context object. |
| 1535 | * @pring: Pointer to driver SLI ring object. |
| 1536 | * |
| 1537 | * This function updates the chip attention register bit for the |
| 1538 | * given ring to inform HBA that there is more work to be done |
| 1539 | * in this ring. The caller is not required to hold any lock. |
| 1540 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1542 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | { |
| 1544 | int ringno = pring->ringno; |
| 1545 | |
| 1546 | /* |
| 1547 | * Tell the HBA that there is work to do in this ring. |
| 1548 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1549 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1550 | wmb(); |
| 1551 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1552 | readl(phba->CAregaddr); /* flush */ |
| 1553 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | } |
| 1555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1557 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | * @phba: Pointer to HBA context object. |
| 1559 | * @pring: Pointer to driver SLI ring object. |
| 1560 | * |
| 1561 | * This function is called with hbalock held to post pending iocbs |
| 1562 | * in the txq to the firmware. This function is called when driver |
| 1563 | * detects space available in the ring. |
| 1564 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1566 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | { |
| 1568 | IOCB_t *iocb; |
| 1569 | struct lpfc_iocbq *nextiocb; |
| 1570 | |
| 1571 | /* |
| 1572 | * Check to see if: |
| 1573 | * (a) there is anything on the txq to send |
| 1574 | * (b) link is up |
| 1575 | * (c) link attention events can be processed (fcp ring only) |
| 1576 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1577 | */ |
| 1578 | if (pring->txq_cnt && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1579 | lpfc_is_link_up(phba) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1581 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | |
| 1583 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1584 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1585 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1586 | |
| 1587 | if (iocb) |
| 1588 | lpfc_sli_update_ring(phba, pring); |
| 1589 | else |
| 1590 | lpfc_sli_update_full_ring(phba, pring); |
| 1591 | } |
| 1592 | |
| 1593 | return; |
| 1594 | } |
| 1595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1597 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1598 | * @phba: Pointer to HBA context object. |
| 1599 | * @hbqno: HBQ number. |
| 1600 | * |
| 1601 | * This function is called with hbalock held to get the next |
| 1602 | * available slot for the given HBQ. If there is free slot |
| 1603 | * available for the HBQ it will return pointer to the next available |
| 1604 | * HBQ entry else it will return NULL. |
| 1605 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1606 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1607 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1608 | { |
| 1609 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1610 | |
| 1611 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1612 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1613 | hbqp->next_hbqPutIdx = 0; |
| 1614 | |
| 1615 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1616 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1617 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1618 | |
| 1619 | hbqp->local_hbqGetIdx = getidx; |
| 1620 | |
| 1621 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1622 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1623 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1624 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1625 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1626 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1627 | hbqp->entry_count); |
| 1628 | |
| 1629 | phba->link_state = LPFC_HBA_ERROR; |
| 1630 | return NULL; |
| 1631 | } |
| 1632 | |
| 1633 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1634 | return NULL; |
| 1635 | } |
| 1636 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1637 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1638 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1639 | } |
| 1640 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1641 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1642 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1643 | * @phba: Pointer to HBA context object. |
| 1644 | * |
| 1645 | * This function is called with no lock held to free all the |
| 1646 | * hbq buffers while uninitializing the SLI interface. It also |
| 1647 | * frees the HBQ buffers returned by the firmware but not yet |
| 1648 | * processed by the upper layers. |
| 1649 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1650 | void |
| 1651 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1652 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1653 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1654 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1655 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1656 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1657 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1658 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1659 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1660 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1661 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1662 | for (i = 0; i < hbq_count; ++i) { |
| 1663 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1664 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1665 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1666 | list_del(&hbq_buf->dbuf.list); |
| 1667 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1668 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1669 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1670 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1671 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1672 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1673 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1674 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1675 | list_del(&hbq_buf->dbuf.list); |
| 1676 | if (hbq_buf->tag == -1) { |
| 1677 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1678 | (phba, hbq_buf); |
| 1679 | } else { |
| 1680 | hbqno = hbq_buf->tag >> 16; |
| 1681 | if (hbqno >= LPFC_MAX_HBQS) |
| 1682 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1683 | (phba, hbq_buf); |
| 1684 | else |
| 1685 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1686 | hbq_buf); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | /* Mark the HBQs not in use */ |
| 1691 | phba->hbq_in_use = 0; |
| 1692 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1693 | } |
| 1694 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1696 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1697 | * @phba: Pointer to HBA context object. |
| 1698 | * @hbqno: HBQ number. |
| 1699 | * @hbq_buf: Pointer to HBQ buffer. |
| 1700 | * |
| 1701 | * This function is called with the hbalock held to post a |
| 1702 | * hbq buffer to the firmware. If the function finds an empty |
| 1703 | * slot in the HBQ, it will post the buffer. The function will return |
| 1704 | * pointer to the hbq entry if it successfully post the buffer |
| 1705 | * else it will return NULL. |
| 1706 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1707 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1708 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1709 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1710 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1711 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1716 | * @phba: Pointer to HBA context object. |
| 1717 | * @hbqno: HBQ number. |
| 1718 | * @hbq_buf: Pointer to HBQ buffer. |
| 1719 | * |
| 1720 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1721 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1722 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1723 | * it successfully post the buffer else it will return an error. |
| 1724 | **/ |
| 1725 | static int |
| 1726 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1727 | struct hbq_dmabuf *hbq_buf) |
| 1728 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1729 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1730 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1731 | |
| 1732 | /* Get next HBQ entry slot to use */ |
| 1733 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1734 | if (hbqe) { |
| 1735 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1736 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1737 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1738 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1739 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1740 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1741 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1742 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1743 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1744 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1745 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1746 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1747 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1748 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1749 | return 0; |
| 1750 | } else |
| 1751 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1752 | } |
| 1753 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1754 | /** |
| 1755 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1756 | * @phba: Pointer to HBA context object. |
| 1757 | * @hbqno: HBQ number. |
| 1758 | * @hbq_buf: Pointer to HBQ buffer. |
| 1759 | * |
| 1760 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1761 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1762 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1763 | **/ |
| 1764 | static int |
| 1765 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1766 | struct hbq_dmabuf *hbq_buf) |
| 1767 | { |
| 1768 | int rc; |
| 1769 | struct lpfc_rqe hrqe; |
| 1770 | struct lpfc_rqe drqe; |
| 1771 | |
| 1772 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1773 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1774 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1775 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1776 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1777 | &hrqe, &drqe); |
| 1778 | if (rc < 0) |
| 1779 | return rc; |
| 1780 | hbq_buf->tag = rc; |
| 1781 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1782 | return 0; |
| 1783 | } |
| 1784 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1785 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1786 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1787 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1788 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1789 | .mask_count = 0, |
| 1790 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1791 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1792 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1793 | .init_count = 40, |
| 1794 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1795 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1797 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1798 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1799 | .rn = 1, |
| 1800 | .entry_count = 200, |
| 1801 | .mask_count = 0, |
| 1802 | .profile = 0, |
| 1803 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1804 | .buffer_count = 0, |
| 1805 | .init_count = 0, |
| 1806 | .add_count = 5, |
| 1807 | }; |
| 1808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1809 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1810 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1811 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1812 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1813 | }; |
| 1814 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1815 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1816 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1817 | * @phba: Pointer to HBA context object. |
| 1818 | * @hbqno: HBQ number. |
| 1819 | * @count: Number of HBQ buffers to be posted. |
| 1820 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1821 | * This function is called with no lock held to post more hbq buffers to the |
| 1822 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1823 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1824 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1825 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1826 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1827 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1828 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1829 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1830 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1831 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1832 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1833 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1834 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1835 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1836 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1837 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1838 | phba->hbqs[hbqno].buffer_count; |
| 1839 | if (!count) |
| 1840 | return 0; |
| 1841 | /* Allocate HBQ entries */ |
| 1842 | for (i = 0; i < count; i++) { |
| 1843 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1844 | if (!hbq_buffer) |
| 1845 | break; |
| 1846 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1847 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1848 | /* Check whether HBQ is still in use */ |
| 1849 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1850 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1851 | goto err; |
| 1852 | while (!list_empty(&hbq_buf_list)) { |
| 1853 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1854 | dbuf.list); |
| 1855 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1856 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1857 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1858 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1859 | posted++; |
| 1860 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1861 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1862 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1863 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1864 | return posted; |
| 1865 | err: |
| 1866 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1867 | while (!list_empty(&hbq_buf_list)) { |
| 1868 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1869 | dbuf.list); |
| 1870 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1871 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1872 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1873 | } |
| 1874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1876 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1877 | * @phba: Pointer to HBA context object. |
| 1878 | * @qno: HBQ number. |
| 1879 | * |
| 1880 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1881 | * is called with no lock held. The function returns the number of HBQ entries |
| 1882 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1884 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1885 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1886 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1887 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1888 | return 0; |
| 1889 | else |
| 1890 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1891 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1892 | } |
| 1893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1894 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1895 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1896 | * @phba: Pointer to HBA context object. |
| 1897 | * @qno: HBQ queue number. |
| 1898 | * |
| 1899 | * This function is called from SLI initialization code path with |
| 1900 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1901 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1902 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1903 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1904 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1905 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1906 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1907 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1908 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1909 | else |
| 1910 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1911 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1912 | } |
| 1913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1915 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1916 | * @phba: Pointer to HBA context object. |
| 1917 | * @hbqno: HBQ number. |
| 1918 | * |
| 1919 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1920 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1921 | **/ |
| 1922 | static struct hbq_dmabuf * |
| 1923 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1924 | { |
| 1925 | struct lpfc_dmabuf *d_buf; |
| 1926 | |
| 1927 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1928 | if (!d_buf) |
| 1929 | return NULL; |
| 1930 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1931 | } |
| 1932 | |
| 1933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1934 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1935 | * @phba: Pointer to HBA context object. |
| 1936 | * @tag: Tag of the hbq buffer. |
| 1937 | * |
| 1938 | * This function is called with hbalock held. This function searches |
| 1939 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1940 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1941 | * it returns NULL. |
| 1942 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1943 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1944 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1945 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1946 | struct lpfc_dmabuf *d_buf; |
| 1947 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1948 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1949 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1950 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1951 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1952 | return NULL; |
| 1953 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1954 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1955 | 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] | 1956 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1957 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1958 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1959 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1960 | } |
| 1961 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1962 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1963 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1964 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1965 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1966 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1967 | } |
| 1968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1970 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1971 | * @phba: Pointer to HBA context object. |
| 1972 | * @hbq_buffer: Pointer to HBQ buffer. |
| 1973 | * |
| 1974 | * This function is called with hbalock. This function gives back |
| 1975 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 1976 | * post the buffer, it will free the buffer. |
| 1977 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1978 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1979 | 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] | 1980 | { |
| 1981 | uint32_t hbqno; |
| 1982 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1983 | if (hbq_buffer) { |
| 1984 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1985 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1986 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1991 | * 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] | 1992 | * @mbxCommand: mailbox command code. |
| 1993 | * |
| 1994 | * This function is called by the mailbox event handler function to verify |
| 1995 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 1996 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 1997 | * and the mailbox event handler will take the HBA offline. |
| 1998 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | static int |
| 2000 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2001 | { |
| 2002 | uint8_t ret; |
| 2003 | |
| 2004 | switch (mbxCommand) { |
| 2005 | case MBX_LOAD_SM: |
| 2006 | case MBX_READ_NV: |
| 2007 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2008 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | case MBX_RUN_BIU_DIAG: |
| 2010 | case MBX_INIT_LINK: |
| 2011 | case MBX_DOWN_LINK: |
| 2012 | case MBX_CONFIG_LINK: |
| 2013 | case MBX_CONFIG_RING: |
| 2014 | case MBX_RESET_RING: |
| 2015 | case MBX_READ_CONFIG: |
| 2016 | case MBX_READ_RCONFIG: |
| 2017 | case MBX_READ_SPARM: |
| 2018 | case MBX_READ_STATUS: |
| 2019 | case MBX_READ_RPI: |
| 2020 | case MBX_READ_XRI: |
| 2021 | case MBX_READ_REV: |
| 2022 | case MBX_READ_LNK_STAT: |
| 2023 | case MBX_REG_LOGIN: |
| 2024 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | case MBX_CLEAR_LA: |
| 2026 | case MBX_DUMP_MEMORY: |
| 2027 | case MBX_DUMP_CONTEXT: |
| 2028 | case MBX_RUN_DIAGS: |
| 2029 | case MBX_RESTART: |
| 2030 | case MBX_UPDATE_CFG: |
| 2031 | case MBX_DOWN_LOAD: |
| 2032 | case MBX_DEL_LD_ENTRY: |
| 2033 | case MBX_RUN_PROGRAM: |
| 2034 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2035 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2037 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2038 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2039 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | case MBX_LOAD_AREA: |
| 2041 | case MBX_RUN_BIU_DIAG64: |
| 2042 | case MBX_CONFIG_PORT: |
| 2043 | case MBX_READ_SPARM64: |
| 2044 | case MBX_READ_RPI64: |
| 2045 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2046 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2047 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | case MBX_SET_DEBUG: |
| 2049 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2050 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2051 | case MBX_REG_VPI: |
| 2052 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2053 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2054 | case MBX_PORT_CAPABILITIES: |
| 2055 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2056 | case MBX_SLI4_CONFIG: |
| 2057 | case MBX_SLI4_REQ_FTRS: |
| 2058 | case MBX_REG_FCFI: |
| 2059 | case MBX_UNREG_FCFI: |
| 2060 | case MBX_REG_VFI: |
| 2061 | case MBX_UNREG_VFI: |
| 2062 | case MBX_INIT_VPI: |
| 2063 | case MBX_INIT_VFI: |
| 2064 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2065 | case MBX_READ_EVENT_LOG_STATUS: |
| 2066 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2067 | case MBX_SECURITY_MGMT: |
| 2068 | case MBX_AUTH_PORT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | ret = mbxCommand; |
| 2070 | break; |
| 2071 | default: |
| 2072 | ret = MBX_SHUTDOWN; |
| 2073 | break; |
| 2074 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2077 | |
| 2078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2079 | * 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] | 2080 | * @phba: Pointer to HBA context object. |
| 2081 | * @pmboxq: Pointer to mailbox command. |
| 2082 | * |
| 2083 | * This is completion handler function for mailbox commands issued from |
| 2084 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2085 | * mailbox event handler function with no lock held. This function |
| 2086 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2087 | * of the mailbox. |
| 2088 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2089 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2090 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | { |
| 2092 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2093 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | |
| 2095 | /* |
| 2096 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2097 | * continued running. |
| 2098 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2099 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2100 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2102 | if (pdone_q) |
| 2103 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2104 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | return; |
| 2106 | } |
| 2107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2108 | |
| 2109 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2110 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2111 | * @phba: Pointer to HBA context object. |
| 2112 | * @pmb: Pointer to mailbox object. |
| 2113 | * |
| 2114 | * This function is the default mailbox completion handler. It |
| 2115 | * frees the memory resources associated with the completed mailbox |
| 2116 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2117 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2120 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2122 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2124 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2125 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2126 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2127 | int rc; |
| 2128 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2130 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | if (mp) { |
| 2132 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2133 | kfree(mp); |
| 2134 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2135 | |
| 2136 | /* |
| 2137 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2138 | * is in re-discovery driver need to cleanup the RPI. |
| 2139 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2140 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2141 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2142 | !pmb->u.mb.mbxStatus) { |
| 2143 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2144 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2145 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2146 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2147 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2148 | if (rc != MBX_NOT_FINISHED) |
| 2149 | return; |
| 2150 | } |
| 2151 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2152 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2153 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2154 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2155 | shost = lpfc_shost_from_vport(vport); |
| 2156 | spin_lock_irq(shost->host_lock); |
| 2157 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2158 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2159 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2160 | } |
| 2161 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2162 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2163 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2164 | lpfc_nlp_put(ndlp); |
| 2165 | pmb->context2 = NULL; |
| 2166 | } |
| 2167 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2168 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2169 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2170 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2171 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2172 | "2860 SLI authentication is required " |
| 2173 | "for INIT_LINK but has not done yet\n"); |
| 2174 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2175 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2176 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2177 | else |
| 2178 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | } |
| 2180 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2181 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2182 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2183 | * @phba: Pointer to HBA context object. |
| 2184 | * |
| 2185 | * This function is called with no lock held. This function processes all |
| 2186 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2187 | * service routine processes mailbox completion interrupt and adds completed |
| 2188 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2189 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2190 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2191 | * function returns the mailbox commands to the upper layer by calling the |
| 2192 | * completion handler function of each mailbox. |
| 2193 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2195 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2199 | int rc; |
| 2200 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2201 | |
| 2202 | phba->sli.slistat.mbox_event++; |
| 2203 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2204 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2205 | spin_lock_irq(&phba->hbalock); |
| 2206 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2207 | spin_unlock_irq(&phba->hbalock); |
| 2208 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2209 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2210 | do { |
| 2211 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2212 | if (pmb == NULL) |
| 2213 | break; |
| 2214 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2215 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2217 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2218 | if (pmb->vport) { |
| 2219 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2220 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2221 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2222 | (uint32_t)pmbox->mbxCommand, |
| 2223 | pmbox->un.varWords[0], |
| 2224 | pmbox->un.varWords[1]); |
| 2225 | } |
| 2226 | else { |
| 2227 | lpfc_debugfs_disc_trc(phba->pport, |
| 2228 | LPFC_DISC_TRC_MBOX, |
| 2229 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2230 | (uint32_t)pmbox->mbxCommand, |
| 2231 | pmbox->un.varWords[0], |
| 2232 | pmbox->un.varWords[1]); |
| 2233 | } |
| 2234 | } |
| 2235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | /* |
| 2237 | * It is a fatal error if unknown mbox command completion. |
| 2238 | */ |
| 2239 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2240 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2241 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2242 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2243 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2244 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2245 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2246 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2247 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2248 | pmb), |
| 2249 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2250 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | phba->work_hs = HS_FFER3; |
| 2253 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2254 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2255 | } |
| 2256 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | if (pmbox->mbxStatus) { |
| 2258 | phba->sli.slistat.mbox_stat_err++; |
| 2259 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2260 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2261 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2262 | LOG_MBOX | LOG_SLI, |
| 2263 | "(%d):0305 Mbox cmd cmpl " |
| 2264 | "error - RETRYing Data: x%x " |
| 2265 | "(x%x/x%x) x%x x%x x%x\n", |
| 2266 | pmb->vport ? pmb->vport->vpi : 0, |
| 2267 | pmbox->mbxCommand, |
| 2268 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2269 | pmb), |
| 2270 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2271 | pmb), |
| 2272 | pmbox->mbxStatus, |
| 2273 | pmbox->un.varWords[0], |
| 2274 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | pmbox->mbxStatus = 0; |
| 2276 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2278 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2279 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2284 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2285 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | "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] | 2287 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2289 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2290 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | pmb->mbox_cmpl, |
| 2292 | *((uint32_t *) pmbox), |
| 2293 | pmbox->un.varWords[0], |
| 2294 | pmbox->un.varWords[1], |
| 2295 | pmbox->un.varWords[2], |
| 2296 | pmbox->un.varWords[3], |
| 2297 | pmbox->un.varWords[4], |
| 2298 | pmbox->un.varWords[5], |
| 2299 | pmbox->un.varWords[6], |
| 2300 | pmbox->un.varWords[7]); |
| 2301 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2302 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2304 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2309 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2310 | * @phba: Pointer to HBA context object. |
| 2311 | * @pring: Pointer to driver SLI ring object. |
| 2312 | * @tag: buffer tag. |
| 2313 | * |
| 2314 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2315 | * is set in the tag the buffer is posted for a particular exchange, |
| 2316 | * the function will return the buffer without replacing the buffer. |
| 2317 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2318 | * returns the buffer and also posts another buffer to the firmware. |
| 2319 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2320 | static struct lpfc_dmabuf * |
| 2321 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2322 | struct lpfc_sli_ring *pring, |
| 2323 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2324 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2325 | struct hbq_dmabuf *hbq_entry; |
| 2326 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2327 | if (tag & QUE_BUFTAG_BIT) |
| 2328 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2329 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2330 | if (!hbq_entry) |
| 2331 | return NULL; |
| 2332 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2333 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2334 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2335 | /** |
| 2336 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2337 | * @phba: Pointer to HBA context object. |
| 2338 | * @pring: Pointer to driver SLI ring object. |
| 2339 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2340 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2341 | * @fch_type: the type for the first frame of the sequence. |
| 2342 | * |
| 2343 | * This function is called with no lock held. This function uses the r_ctl and |
| 2344 | * type of the received sequence to find the correct callback function to call |
| 2345 | * to process the sequence. |
| 2346 | **/ |
| 2347 | static int |
| 2348 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2349 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2350 | uint32_t fch_type) |
| 2351 | { |
| 2352 | int i; |
| 2353 | |
| 2354 | /* unSolicited Responses */ |
| 2355 | if (pring->prt[0].profile) { |
| 2356 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2357 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2358 | saveq); |
| 2359 | return 1; |
| 2360 | } |
| 2361 | /* We must search, based on rctl / type |
| 2362 | for the right routine */ |
| 2363 | for (i = 0; i < pring->num_mask; i++) { |
| 2364 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2365 | (pring->prt[i].type == fch_type)) { |
| 2366 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2367 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2368 | (phba, pring, saveq); |
| 2369 | return 1; |
| 2370 | } |
| 2371 | } |
| 2372 | return 0; |
| 2373 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2374 | |
| 2375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2376 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2377 | * @phba: Pointer to HBA context object. |
| 2378 | * @pring: Pointer to driver SLI ring object. |
| 2379 | * @saveq: Pointer to the unsolicited iocb. |
| 2380 | * |
| 2381 | * This function is called with no lock held by the ring event handler |
| 2382 | * when there is an unsolicited iocb posted to the response ring by the |
| 2383 | * firmware. This function gets the buffer associated with the iocbs |
| 2384 | * and calls the event handler for the ring. This function handles both |
| 2385 | * qring buffers and hbq buffers. |
| 2386 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2387 | * upper layer functions will free the iocb objects. |
| 2388 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | static int |
| 2390 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2391 | struct lpfc_iocbq *saveq) |
| 2392 | { |
| 2393 | IOCB_t * irsp; |
| 2394 | WORD5 * w5p; |
| 2395 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2396 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2397 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2398 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | |
| 2400 | match = 0; |
| 2401 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2402 | |
| 2403 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2404 | if (pring->lpfc_sli_rcv_async_status) |
| 2405 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2406 | else |
| 2407 | lpfc_printf_log(phba, |
| 2408 | KERN_WARNING, |
| 2409 | LOG_SLI, |
| 2410 | "0316 Ring %d handler: unexpected " |
| 2411 | "ASYNC_STATUS iocb received evt_code " |
| 2412 | "0x%x\n", |
| 2413 | pring->ringno, |
| 2414 | irsp->un.asyncstat.evt_code); |
| 2415 | return 1; |
| 2416 | } |
| 2417 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2418 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2419 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2420 | if (irsp->ulpBdeCount > 0) { |
| 2421 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2422 | irsp->un.ulpWord[3]); |
| 2423 | lpfc_in_buf_free(phba, dmzbuf); |
| 2424 | } |
| 2425 | |
| 2426 | if (irsp->ulpBdeCount > 1) { |
| 2427 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2428 | irsp->unsli3.sli3Words[3]); |
| 2429 | lpfc_in_buf_free(phba, dmzbuf); |
| 2430 | } |
| 2431 | |
| 2432 | if (irsp->ulpBdeCount > 2) { |
| 2433 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2434 | irsp->unsli3.sli3Words[7]); |
| 2435 | lpfc_in_buf_free(phba, dmzbuf); |
| 2436 | } |
| 2437 | |
| 2438 | return 1; |
| 2439 | } |
| 2440 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2441 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2442 | if (irsp->ulpBdeCount != 0) { |
| 2443 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2444 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2445 | if (!saveq->context2) |
| 2446 | lpfc_printf_log(phba, |
| 2447 | KERN_ERR, |
| 2448 | LOG_SLI, |
| 2449 | "0341 Ring %d Cannot find buffer for " |
| 2450 | "an unsolicited iocb. tag 0x%x\n", |
| 2451 | pring->ringno, |
| 2452 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2453 | } |
| 2454 | if (irsp->ulpBdeCount == 2) { |
| 2455 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2456 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2457 | if (!saveq->context3) |
| 2458 | lpfc_printf_log(phba, |
| 2459 | KERN_ERR, |
| 2460 | LOG_SLI, |
| 2461 | "0342 Ring %d Cannot find buffer for an" |
| 2462 | " unsolicited iocb. tag 0x%x\n", |
| 2463 | pring->ringno, |
| 2464 | irsp->unsli3.sli3Words[7]); |
| 2465 | } |
| 2466 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2467 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2468 | if (irsp->ulpBdeCount != 0) { |
| 2469 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2470 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2471 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2472 | lpfc_printf_log(phba, |
| 2473 | KERN_ERR, |
| 2474 | LOG_SLI, |
| 2475 | "0343 Ring %d Cannot find " |
| 2476 | "buffer for an unsolicited iocb" |
| 2477 | ". tag 0x%x\n", pring->ringno, |
| 2478 | irsp->un.ulpWord[3]); |
| 2479 | } |
| 2480 | if (irsp->ulpBdeCount == 2) { |
| 2481 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2482 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2483 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2484 | lpfc_printf_log(phba, |
| 2485 | KERN_ERR, |
| 2486 | LOG_SLI, |
| 2487 | "0344 Ring %d Cannot find " |
| 2488 | "buffer for an unsolicited " |
| 2489 | "iocb. tag 0x%x\n", |
| 2490 | pring->ringno, |
| 2491 | irsp->unsli3.sli3Words[7]); |
| 2492 | } |
| 2493 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2494 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2495 | if (irsp->ulpBdeCount != 0 && |
| 2496 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2497 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2498 | int found = 0; |
| 2499 | |
| 2500 | /* search continue save q for same XRI */ |
| 2501 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2502 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2503 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2504 | list_add_tail(&saveq->list, &iocbq->list); |
| 2505 | found = 1; |
| 2506 | break; |
| 2507 | } |
| 2508 | } |
| 2509 | if (!found) |
| 2510 | list_add_tail(&saveq->clist, |
| 2511 | &pring->iocb_continue_saveq); |
| 2512 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2513 | list_del_init(&iocbq->clist); |
| 2514 | saveq = iocbq; |
| 2515 | irsp = &(saveq->iocb); |
| 2516 | } else |
| 2517 | return 0; |
| 2518 | } |
| 2519 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2520 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2521 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2522 | Rctl = FC_RCTL_ELS_REQ; |
| 2523 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2524 | } else { |
| 2525 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2526 | Rctl = w5p->hcsw.Rctl; |
| 2527 | Type = w5p->hcsw.Type; |
| 2528 | |
| 2529 | /* Firmware Workaround */ |
| 2530 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2531 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2532 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2533 | Rctl = FC_RCTL_ELS_REQ; |
| 2534 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2535 | w5p->hcsw.Rctl = Rctl; |
| 2536 | w5p->hcsw.Type = Type; |
| 2537 | } |
| 2538 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2539 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2540 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2541 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2542 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2543 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2544 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2545 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2546 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2547 | } |
| 2548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2550 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2551 | * @phba: Pointer to HBA context object. |
| 2552 | * @pring: Pointer to driver SLI ring object. |
| 2553 | * @prspiocb: Pointer to response iocb object. |
| 2554 | * |
| 2555 | * This function looks up the iocb_lookup table to get the command iocb |
| 2556 | * corresponding to the given response iocb using the iotag of the |
| 2557 | * response iocb. This function is called with the hbalock held. |
| 2558 | * This function returns the command iocb object if it finds the command |
| 2559 | * iocb else returns NULL. |
| 2560 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2562 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2563 | struct lpfc_sli_ring *pring, |
| 2564 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2567 | uint16_t iotag; |
| 2568 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2569 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2571 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2572 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2573 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2574 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2575 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2576 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2577 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2578 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | } |
| 2580 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2582 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2583 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2584 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2585 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | return NULL; |
| 2587 | } |
| 2588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2589 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2590 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2591 | * @phba: Pointer to HBA context object. |
| 2592 | * @pring: Pointer to driver SLI ring object. |
| 2593 | * @iotag: IOCB tag. |
| 2594 | * |
| 2595 | * This function looks up the iocb_lookup table to get the command iocb |
| 2596 | * corresponding to the given iotag. This function is called with the |
| 2597 | * hbalock held. |
| 2598 | * This function returns the command iocb object if it finds the command |
| 2599 | * iocb else returns NULL. |
| 2600 | **/ |
| 2601 | static struct lpfc_iocbq * |
| 2602 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2603 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2604 | { |
| 2605 | struct lpfc_iocbq *cmd_iocb; |
| 2606 | |
| 2607 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2608 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2609 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2610 | /* remove from txcmpl queue list */ |
| 2611 | list_del_init(&cmd_iocb->list); |
| 2612 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2613 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2614 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2615 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2616 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2617 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2618 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2619 | iotag, phba->sli.last_iotag); |
| 2620 | return NULL; |
| 2621 | } |
| 2622 | |
| 2623 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2624 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2625 | * @phba: Pointer to HBA context object. |
| 2626 | * @pring: Pointer to driver SLI ring object. |
| 2627 | * @saveq: Pointer to the response iocb to be processed. |
| 2628 | * |
| 2629 | * This function is called by the ring event handler for non-fcp |
| 2630 | * rings when there is a new response iocb in the response ring. |
| 2631 | * The caller is not required to hold any locks. This function |
| 2632 | * gets the command iocb associated with the response iocb and |
| 2633 | * calls the completion handler for the command iocb. If there |
| 2634 | * is no completion handler, the function will free the resources |
| 2635 | * associated with command iocb. If the response iocb is for |
| 2636 | * an already aborted command iocb, the status of the completion |
| 2637 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2638 | * This function always returns 1. |
| 2639 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2641 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | struct lpfc_iocbq *saveq) |
| 2643 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2644 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | int rc = 1; |
| 2646 | unsigned long iflag; |
| 2647 | |
| 2648 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2650 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2651 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | if (cmdiocbp) { |
| 2654 | if (cmdiocbp->iocb_cmpl) { |
| 2655 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2656 | * If an ELS command failed send an event to mgmt |
| 2657 | * application. |
| 2658 | */ |
| 2659 | if (saveq->iocb.ulpStatus && |
| 2660 | (pring->ringno == LPFC_ELS_RING) && |
| 2661 | (cmdiocbp->iocb.ulpCommand == |
| 2662 | CMD_ELS_REQUEST64_CR)) |
| 2663 | lpfc_send_els_failure_event(phba, |
| 2664 | cmdiocbp, saveq); |
| 2665 | |
| 2666 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | * Post all ELS completions to the worker thread. |
| 2668 | * All other are passed to the completion callback. |
| 2669 | */ |
| 2670 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2671 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2672 | (cmdiocbp->iocb_flag & |
| 2673 | LPFC_DRIVER_ABORTED)) { |
| 2674 | spin_lock_irqsave(&phba->hbalock, |
| 2675 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2676 | cmdiocbp->iocb_flag &= |
| 2677 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2678 | spin_unlock_irqrestore(&phba->hbalock, |
| 2679 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2680 | saveq->iocb.ulpStatus = |
| 2681 | IOSTAT_LOCAL_REJECT; |
| 2682 | saveq->iocb.un.ulpWord[4] = |
| 2683 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2684 | |
| 2685 | /* Firmware could still be in progress |
| 2686 | * of DMAing payload, so don't free data |
| 2687 | * buffer till after a hbeat. |
| 2688 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2689 | spin_lock_irqsave(&phba->hbalock, |
| 2690 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2691 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2692 | spin_unlock_irqrestore(&phba->hbalock, |
| 2693 | iflag); |
| 2694 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2695 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2696 | if (saveq->iocb_flag & |
| 2697 | LPFC_EXCHANGE_BUSY) { |
| 2698 | /* Set cmdiocb flag for the |
| 2699 | * exchange busy so sgl (xri) |
| 2700 | * will not be released until |
| 2701 | * the abort xri is received |
| 2702 | * from hba. |
| 2703 | */ |
| 2704 | spin_lock_irqsave( |
| 2705 | &phba->hbalock, iflag); |
| 2706 | cmdiocbp->iocb_flag |= |
| 2707 | LPFC_EXCHANGE_BUSY; |
| 2708 | spin_unlock_irqrestore( |
| 2709 | &phba->hbalock, iflag); |
| 2710 | } |
| 2711 | if (cmdiocbp->iocb_flag & |
| 2712 | LPFC_DRIVER_ABORTED) { |
| 2713 | /* |
| 2714 | * Clear LPFC_DRIVER_ABORTED |
| 2715 | * bit in case it was driver |
| 2716 | * initiated abort. |
| 2717 | */ |
| 2718 | spin_lock_irqsave( |
| 2719 | &phba->hbalock, iflag); |
| 2720 | cmdiocbp->iocb_flag &= |
| 2721 | ~LPFC_DRIVER_ABORTED; |
| 2722 | spin_unlock_irqrestore( |
| 2723 | &phba->hbalock, iflag); |
| 2724 | cmdiocbp->iocb.ulpStatus = |
| 2725 | IOSTAT_LOCAL_REJECT; |
| 2726 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2727 | IOERR_ABORT_REQUESTED; |
| 2728 | /* |
| 2729 | * For SLI4, irsiocb contains |
| 2730 | * NO_XRI in sli_xritag, it |
| 2731 | * shall not affect releasing |
| 2732 | * sgl (xri) process. |
| 2733 | */ |
| 2734 | saveq->iocb.ulpStatus = |
| 2735 | IOSTAT_LOCAL_REJECT; |
| 2736 | saveq->iocb.un.ulpWord[4] = |
| 2737 | IOERR_SLI_ABORTED; |
| 2738 | spin_lock_irqsave( |
| 2739 | &phba->hbalock, iflag); |
| 2740 | saveq->iocb_flag |= |
| 2741 | LPFC_DELAY_MEM_FREE; |
| 2742 | spin_unlock_irqrestore( |
| 2743 | &phba->hbalock, iflag); |
| 2744 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2745 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2747 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2748 | } else |
| 2749 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | } else { |
| 2751 | /* |
| 2752 | * Unknown initiating command based on the response iotag. |
| 2753 | * This could be the case on the ELS ring because of |
| 2754 | * lpfc_els_abort(). |
| 2755 | */ |
| 2756 | if (pring->ringno != LPFC_ELS_RING) { |
| 2757 | /* |
| 2758 | * Ring <ringno> handler: unexpected completion IoTag |
| 2759 | * <IoTag> |
| 2760 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2761 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2762 | "0322 Ring %d handler: " |
| 2763 | "unexpected completion IoTag x%x " |
| 2764 | "Data: x%x x%x x%x x%x\n", |
| 2765 | pring->ringno, |
| 2766 | saveq->iocb.ulpIoTag, |
| 2767 | saveq->iocb.ulpStatus, |
| 2768 | saveq->iocb.un.ulpWord[4], |
| 2769 | saveq->iocb.ulpCommand, |
| 2770 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | } |
| 2772 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2773 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | return rc; |
| 2775 | } |
| 2776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2778 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | * @phba: Pointer to HBA context object. |
| 2780 | * @pring: Pointer to driver SLI ring object. |
| 2781 | * |
| 2782 | * This function is called from the iocb ring event handlers when |
| 2783 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2784 | * an error attention condition to the worker thread and the worker |
| 2785 | * thread will transition the HBA to offline state. |
| 2786 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2787 | static void |
| 2788 | 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] | 2789 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2790 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2791 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2792 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2793 | * rsp ring <portRspMax> |
| 2794 | */ |
| 2795 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2796 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2797 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2798 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2799 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2800 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2801 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2802 | |
| 2803 | /* |
| 2804 | * All error attention handlers are posted to |
| 2805 | * worker thread |
| 2806 | */ |
| 2807 | phba->work_ha |= HA_ERATT; |
| 2808 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2809 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2810 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2811 | |
| 2812 | return; |
| 2813 | } |
| 2814 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2815 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2816 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2817 | * @ptr: Pointer to address of HBA context object. |
| 2818 | * |
| 2819 | * This function is invoked by the Error Attention polling timer when the |
| 2820 | * timer times out. It will check the SLI Error Attention register for |
| 2821 | * possible attention events. If so, it will post an Error Attention event |
| 2822 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2823 | * Error Attention polling timer for the next poll. |
| 2824 | **/ |
| 2825 | void lpfc_poll_eratt(unsigned long ptr) |
| 2826 | { |
| 2827 | struct lpfc_hba *phba; |
| 2828 | uint32_t eratt = 0; |
| 2829 | |
| 2830 | phba = (struct lpfc_hba *)ptr; |
| 2831 | |
| 2832 | /* Check chip HA register for error event */ |
| 2833 | eratt = lpfc_sli_check_eratt(phba); |
| 2834 | |
| 2835 | if (eratt) |
| 2836 | /* Tell the worker thread there is work to do */ |
| 2837 | lpfc_worker_wake_up(phba); |
| 2838 | else |
| 2839 | /* Restart the timer for next eratt poll */ |
| 2840 | mod_timer(&phba->eratt_poll, jiffies + |
| 2841 | HZ * LPFC_ERATT_POLL_INTERVAL); |
| 2842 | return; |
| 2843 | } |
| 2844 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2846 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2847 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2848 | * @phba: Pointer to HBA context object. |
| 2849 | * @pring: Pointer to driver SLI ring object. |
| 2850 | * @mask: Host attention register mask for this ring. |
| 2851 | * |
| 2852 | * This function is called from the interrupt context when there is a ring |
| 2853 | * event for the fcp ring. The caller does not hold any lock. |
| 2854 | * 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] | 2855 | * 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] | 2856 | * LE bit set. The function will call the completion handler of the command iocb |
| 2857 | * if the response iocb indicates a completion for a command iocb or it is |
| 2858 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2859 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2861 | * to check it explicitly. |
| 2862 | */ |
| 2863 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2864 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2865 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2867 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2869 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2871 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | uint32_t status; |
| 2873 | uint32_t portRspPut, portRspMax; |
| 2874 | int rc = 1; |
| 2875 | lpfc_iocb_type type; |
| 2876 | unsigned long iflag; |
| 2877 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | pring->stats.iocb_event++; |
| 2881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | /* |
| 2883 | * The next available response entry should never exceed the maximum |
| 2884 | * entries. If it does, treat it as an adapter hardware error. |
| 2885 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2886 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2888 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2889 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2891 | return 1; |
| 2892 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2893 | if (phba->fcp_ring_in_use) { |
| 2894 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2895 | return 1; |
| 2896 | } else |
| 2897 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | |
| 2899 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2900 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2901 | /* |
| 2902 | * Fetch an entry off the ring and copy it into a local data |
| 2903 | * structure. The copy involves a byte-swap since the |
| 2904 | * network byte order and pci byte orders are different. |
| 2905 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2906 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2907 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2908 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2909 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 2910 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2911 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2912 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2913 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2914 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2915 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2916 | irsp = &rspiocbq.iocb; |
| 2917 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2919 | pring->stats.iocb_rsp++; |
| 2920 | rsp_cmpl++; |
| 2921 | |
| 2922 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2923 | /* |
| 2924 | * If resource errors reported from HBA, reduce |
| 2925 | * queuedepths of the SCSI device. |
| 2926 | */ |
| 2927 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 2928 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 2929 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2930 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2931 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2932 | } |
| 2933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | /* Rsp ring <ringno> error: IOCB */ |
| 2935 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2936 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2937 | "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] | 2938 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2939 | irsp->un.ulpWord[0], |
| 2940 | irsp->un.ulpWord[1], |
| 2941 | irsp->un.ulpWord[2], |
| 2942 | irsp->un.ulpWord[3], |
| 2943 | irsp->un.ulpWord[4], |
| 2944 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2945 | *(uint32_t *)&irsp->un1, |
| 2946 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | switch (type) { |
| 2950 | case LPFC_ABORT_IOCB: |
| 2951 | case LPFC_SOL_IOCB: |
| 2952 | /* |
| 2953 | * Idle exchange closed via ABTS from port. No iocb |
| 2954 | * resources need to be recovered. |
| 2955 | */ |
| 2956 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2957 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2958 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2959 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2960 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 2961 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | break; |
| 2963 | } |
| 2964 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2965 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 2966 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2967 | if (unlikely(!cmdiocbq)) |
| 2968 | break; |
| 2969 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 2970 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 2971 | if (cmdiocbq->iocb_cmpl) { |
| 2972 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2973 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 2974 | &rspiocbq); |
| 2975 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2976 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2978 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2979 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2980 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2981 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2982 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | default: |
| 2984 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 2985 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 2986 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 2987 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 2988 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 2989 | dev_warn(&((phba->pcidev)->dev), |
| 2990 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2991 | phba->brd_no, adaptermsg); |
| 2992 | } else { |
| 2993 | /* Unknown IOCB command */ |
| 2994 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2995 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2996 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2997 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | irsp->ulpStatus, |
| 2999 | irsp->ulpIoTag, |
| 3000 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | } |
| 3002 | break; |
| 3003 | } |
| 3004 | |
| 3005 | /* |
| 3006 | * The response IOCB has been processed. Update the ring |
| 3007 | * pointer in SLIM. If the port response put pointer has not |
| 3008 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3009 | * response put pointer. |
| 3010 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3011 | writel(pring->sli.sli3.rspidx, |
| 3012 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3014 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3016 | } |
| 3017 | |
| 3018 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3019 | pring->stats.iocb_rsp_full++; |
| 3020 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3021 | writel(status, phba->CAregaddr); |
| 3022 | readl(phba->CAregaddr); |
| 3023 | } |
| 3024 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3025 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3026 | pring->stats.iocb_cmd_empty++; |
| 3027 | |
| 3028 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3029 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | lpfc_sli_resume_iocb(phba, pring); |
| 3031 | |
| 3032 | if ((pring->lpfc_sli_cmd_available)) |
| 3033 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3034 | |
| 3035 | } |
| 3036 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3037 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | return rc; |
| 3040 | } |
| 3041 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3042 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3043 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3044 | * @phba: Pointer to HBA context object. |
| 3045 | * @pring: Pointer to driver SLI ring object. |
| 3046 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3047 | * |
| 3048 | * This function is called from the worker thread when there is a slow-path |
| 3049 | * response IOCB to process. This function chains all the response iocbs until |
| 3050 | * seeing the iocb with the LE bit set. The function will call |
| 3051 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3052 | * completion of a command iocb. The function will call the |
| 3053 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3054 | * The function frees the resources or calls the completion handler if this |
| 3055 | * iocb is an abort completion. The function returns NULL when the response |
| 3056 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3057 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3058 | * response iocb passed in. |
| 3059 | **/ |
| 3060 | static struct lpfc_iocbq * |
| 3061 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3062 | struct lpfc_iocbq *rspiocbp) |
| 3063 | { |
| 3064 | struct lpfc_iocbq *saveq; |
| 3065 | struct lpfc_iocbq *cmdiocbp; |
| 3066 | struct lpfc_iocbq *next_iocb; |
| 3067 | IOCB_t *irsp = NULL; |
| 3068 | uint32_t free_saveq; |
| 3069 | uint8_t iocb_cmd_type; |
| 3070 | lpfc_iocb_type type; |
| 3071 | unsigned long iflag; |
| 3072 | int rc; |
| 3073 | |
| 3074 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3075 | /* First add the response iocb to the countinueq list */ |
| 3076 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3077 | pring->iocb_continueq_cnt++; |
| 3078 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3079 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3080 | irsp = &rspiocbp->iocb; |
| 3081 | if (irsp->ulpLe) { |
| 3082 | /* |
| 3083 | * By default, the driver expects to free all resources |
| 3084 | * associated with this iocb completion. |
| 3085 | */ |
| 3086 | free_saveq = 1; |
| 3087 | saveq = list_get_first(&pring->iocb_continueq, |
| 3088 | struct lpfc_iocbq, list); |
| 3089 | irsp = &(saveq->iocb); |
| 3090 | list_del_init(&pring->iocb_continueq); |
| 3091 | pring->iocb_continueq_cnt = 0; |
| 3092 | |
| 3093 | pring->stats.iocb_rsp++; |
| 3094 | |
| 3095 | /* |
| 3096 | * If resource errors reported from HBA, reduce |
| 3097 | * queuedepths of the SCSI device. |
| 3098 | */ |
| 3099 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 3100 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
| 3101 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3102 | phba->lpfc_rampdown_queue_depth(phba); |
| 3103 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3104 | } |
| 3105 | |
| 3106 | if (irsp->ulpStatus) { |
| 3107 | /* Rsp ring <ringno> error: IOCB */ |
| 3108 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3109 | "0328 Rsp Ring %d error: " |
| 3110 | "IOCB Data: " |
| 3111 | "x%x x%x x%x x%x " |
| 3112 | "x%x x%x x%x x%x " |
| 3113 | "x%x x%x x%x x%x " |
| 3114 | "x%x x%x x%x x%x\n", |
| 3115 | pring->ringno, |
| 3116 | irsp->un.ulpWord[0], |
| 3117 | irsp->un.ulpWord[1], |
| 3118 | irsp->un.ulpWord[2], |
| 3119 | irsp->un.ulpWord[3], |
| 3120 | irsp->un.ulpWord[4], |
| 3121 | irsp->un.ulpWord[5], |
| 3122 | *(((uint32_t *) irsp) + 6), |
| 3123 | *(((uint32_t *) irsp) + 7), |
| 3124 | *(((uint32_t *) irsp) + 8), |
| 3125 | *(((uint32_t *) irsp) + 9), |
| 3126 | *(((uint32_t *) irsp) + 10), |
| 3127 | *(((uint32_t *) irsp) + 11), |
| 3128 | *(((uint32_t *) irsp) + 12), |
| 3129 | *(((uint32_t *) irsp) + 13), |
| 3130 | *(((uint32_t *) irsp) + 14), |
| 3131 | *(((uint32_t *) irsp) + 15)); |
| 3132 | } |
| 3133 | |
| 3134 | /* |
| 3135 | * Fetch the IOCB command type and call the correct completion |
| 3136 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3137 | * get freed back to the lpfc_iocb_list by the discovery |
| 3138 | * kernel thread. |
| 3139 | */ |
| 3140 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3141 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3142 | switch (type) { |
| 3143 | case LPFC_SOL_IOCB: |
| 3144 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3145 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3146 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3147 | break; |
| 3148 | |
| 3149 | case LPFC_UNSOL_IOCB: |
| 3150 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3151 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3152 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3153 | if (!rc) |
| 3154 | free_saveq = 0; |
| 3155 | break; |
| 3156 | |
| 3157 | case LPFC_ABORT_IOCB: |
| 3158 | cmdiocbp = NULL; |
| 3159 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3160 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3161 | saveq); |
| 3162 | if (cmdiocbp) { |
| 3163 | /* Call the specified completion routine */ |
| 3164 | if (cmdiocbp->iocb_cmpl) { |
| 3165 | spin_unlock_irqrestore(&phba->hbalock, |
| 3166 | iflag); |
| 3167 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3168 | saveq); |
| 3169 | spin_lock_irqsave(&phba->hbalock, |
| 3170 | iflag); |
| 3171 | } else |
| 3172 | __lpfc_sli_release_iocbq(phba, |
| 3173 | cmdiocbp); |
| 3174 | } |
| 3175 | break; |
| 3176 | |
| 3177 | case LPFC_UNKNOWN_IOCB: |
| 3178 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3179 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3180 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3181 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3182 | MAX_MSG_DATA); |
| 3183 | dev_warn(&((phba->pcidev)->dev), |
| 3184 | "lpfc%d: %s\n", |
| 3185 | phba->brd_no, adaptermsg); |
| 3186 | } else { |
| 3187 | /* Unknown IOCB command */ |
| 3188 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3189 | "0335 Unknown IOCB " |
| 3190 | "command Data: x%x " |
| 3191 | "x%x x%x x%x\n", |
| 3192 | irsp->ulpCommand, |
| 3193 | irsp->ulpStatus, |
| 3194 | irsp->ulpIoTag, |
| 3195 | irsp->ulpContext); |
| 3196 | } |
| 3197 | break; |
| 3198 | } |
| 3199 | |
| 3200 | if (free_saveq) { |
| 3201 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3202 | &saveq->list, list) { |
| 3203 | list_del(&rspiocbp->list); |
| 3204 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3205 | } |
| 3206 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3207 | } |
| 3208 | rspiocbp = NULL; |
| 3209 | } |
| 3210 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3211 | return rspiocbp; |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * 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] | 3216 | * @phba: Pointer to HBA context object. |
| 3217 | * @pring: Pointer to driver SLI ring object. |
| 3218 | * @mask: Host attention register mask for this ring. |
| 3219 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3220 | * This routine wraps the actual slow_ring event process routine from the |
| 3221 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3222 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3223 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3224 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3225 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3226 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3227 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3228 | } |
| 3229 | |
| 3230 | /** |
| 3231 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3232 | * @phba: Pointer to HBA context object. |
| 3233 | * @pring: Pointer to driver SLI ring object. |
| 3234 | * @mask: Host attention register mask for this ring. |
| 3235 | * |
| 3236 | * This function is called from the worker thread when there is a ring event |
| 3237 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3238 | * remove each response iocb in the response ring and calls the handle |
| 3239 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3240 | **/ |
| 3241 | static void |
| 3242 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3243 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3244 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3245 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | IOCB_t *entry; |
| 3247 | IOCB_t *irsp = NULL; |
| 3248 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3250 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3251 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3253 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3254 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | pring->stats.iocb_event++; |
| 3256 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | /* |
| 3258 | * The next available response entry should never exceed the maximum |
| 3259 | * entries. If it does, treat it as an adapter hardware error. |
| 3260 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3261 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3263 | if (portRspPut >= portRspMax) { |
| 3264 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3265 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | * rsp ring <portRspMax> |
| 3267 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3268 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3269 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3270 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3271 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3272 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3273 | phba->link_state = LPFC_HBA_ERROR; |
| 3274 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | |
| 3276 | phba->work_hs = HS_FFER3; |
| 3277 | lpfc_handle_eratt(phba); |
| 3278 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3279 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3283 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | /* |
| 3285 | * Build a completion list and call the appropriate handler. |
| 3286 | * The process is to get the next available response iocb, get |
| 3287 | * a free iocb from the list, copy the response data into the |
| 3288 | * free iocb, insert to the continuation list, and update the |
| 3289 | * next response index to slim. This process makes response |
| 3290 | * iocb's in the ring available to DMA as fast as possible but |
| 3291 | * pays a penalty for a copy operation. Since the iocb is |
| 3292 | * only 32 bytes, this penalty is considered small relative to |
| 3293 | * the PCI reads for register values and a slim write. When |
| 3294 | * the ulpLe field is set, the entire Command has been |
| 3295 | * received. |
| 3296 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3297 | entry = lpfc_resp_iocb(phba, pring); |
| 3298 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3299 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3301 | if (rspiocbp == NULL) { |
| 3302 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3303 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | break; |
| 3305 | } |
| 3306 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3307 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3308 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3309 | irsp = &rspiocbp->iocb; |
| 3310 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3311 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3312 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3314 | if (pring->ringno == LPFC_ELS_RING) { |
| 3315 | lpfc_debugfs_slow_ring_trc(phba, |
| 3316 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3317 | *(((uint32_t *) irsp) + 4), |
| 3318 | *(((uint32_t *) irsp) + 6), |
| 3319 | *(((uint32_t *) irsp) + 7)); |
| 3320 | } |
| 3321 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3322 | writel(pring->sli.sli3.rspidx, |
| 3323 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3325 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3326 | /* Handle the response IOCB */ |
| 3327 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3328 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | |
| 3330 | /* |
| 3331 | * If the port response put pointer has not been updated, sync |
| 3332 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3333 | * response put pointer. |
| 3334 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3335 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3337 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3338 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3340 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | /* At least one response entry has been freed */ |
| 3342 | pring->stats.iocb_rsp_full++; |
| 3343 | /* SET RxRE_RSP in Chip Att register */ |
| 3344 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3345 | writel(status, phba->CAregaddr); |
| 3346 | readl(phba->CAregaddr); /* flush */ |
| 3347 | } |
| 3348 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3349 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3350 | pring->stats.iocb_cmd_empty++; |
| 3351 | |
| 3352 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3353 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | lpfc_sli_resume_iocb(phba, pring); |
| 3355 | |
| 3356 | if ((pring->lpfc_sli_cmd_available)) |
| 3357 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3358 | |
| 3359 | } |
| 3360 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3361 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3362 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | } |
| 3364 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3365 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3366 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3367 | * @phba: Pointer to HBA context object. |
| 3368 | * @pring: Pointer to driver SLI ring object. |
| 3369 | * @mask: Host attention register mask for this ring. |
| 3370 | * |
| 3371 | * This function is called from the worker thread when there is a pending |
| 3372 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3373 | * queue. The caller does not hold any lock. The function will remove each |
| 3374 | * response iocb from the response worker queue and calls the handle |
| 3375 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3376 | **/ |
| 3377 | static void |
| 3378 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3379 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3380 | { |
| 3381 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3382 | struct hbq_dmabuf *dmabuf; |
| 3383 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3384 | unsigned long iflag; |
| 3385 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3386 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3387 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3388 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3389 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3390 | /* Get the response iocb from the head of work queue */ |
| 3391 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3392 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3393 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3394 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3395 | |
| 3396 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3397 | case CQE_CODE_COMPL_WQE: |
| 3398 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3399 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3400 | /* Translate ELS WCQE to response IOCBQ */ |
| 3401 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3402 | irspiocbq); |
| 3403 | if (irspiocbq) |
| 3404 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3405 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3406 | break; |
| 3407 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3408 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3409 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3410 | cq_event); |
| 3411 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3412 | break; |
| 3413 | default: |
| 3414 | break; |
| 3415 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3420 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3421 | * @phba: Pointer to HBA context object. |
| 3422 | * @pring: Pointer to driver SLI ring object. |
| 3423 | * |
| 3424 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3425 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3426 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3427 | * the return of this function. The caller is not required to hold any locks. |
| 3428 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3429 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3431 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3432 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3435 | if (pring->ringno == LPFC_ELS_RING) { |
| 3436 | lpfc_fabric_abort_hba(phba); |
| 3437 | } |
| 3438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | /* Error everything on txq and txcmplq |
| 3440 | * First do the txq. |
| 3441 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3443 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | pring->txq_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3445 | |
| 3446 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3447 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3448 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3449 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3450 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3451 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3452 | /* Cancel all the IOCBs from the completions list */ |
| 3453 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3454 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | } |
| 3456 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3457 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3458 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3459 | * @phba: Pointer to HBA context object. |
| 3460 | * |
| 3461 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3462 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3463 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3464 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3465 | * slot has been permanently disabled. |
| 3466 | **/ |
| 3467 | void |
| 3468 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3469 | { |
| 3470 | LIST_HEAD(txq); |
| 3471 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3472 | struct lpfc_sli *psli = &phba->sli; |
| 3473 | struct lpfc_sli_ring *pring; |
| 3474 | |
| 3475 | /* Currently, only one fcp ring */ |
| 3476 | pring = &psli->ring[psli->fcp_ring]; |
| 3477 | |
| 3478 | spin_lock_irq(&phba->hbalock); |
| 3479 | /* Retrieve everything on txq */ |
| 3480 | list_splice_init(&pring->txq, &txq); |
| 3481 | pring->txq_cnt = 0; |
| 3482 | |
| 3483 | /* Retrieve everything on the txcmplq */ |
| 3484 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3485 | pring->txcmplq_cnt = 0; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3486 | |
| 3487 | /* Indicate the I/O queues are flushed */ |
| 3488 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3489 | spin_unlock_irq(&phba->hbalock); |
| 3490 | |
| 3491 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3492 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3493 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3494 | |
| 3495 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3496 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3497 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3501 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3502 | * @phba: Pointer to HBA context object. |
| 3503 | * @mask: Bit mask to be checked. |
| 3504 | * |
| 3505 | * This function reads the host status register and compares |
| 3506 | * with the provided bit mask to check if HBA completed |
| 3507 | * the restart. This function will wait in a loop for the |
| 3508 | * HBA to complete restart. If the HBA does not restart within |
| 3509 | * 15 iterations, the function will reset the HBA again. The |
| 3510 | * function returns 1 when HBA fail to restart otherwise returns |
| 3511 | * zero. |
| 3512 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3513 | static int |
| 3514 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3516 | uint32_t status; |
| 3517 | int i = 0; |
| 3518 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3520 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3521 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3522 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3524 | /* |
| 3525 | * Check status register every 100ms for 5 retries, then every |
| 3526 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3527 | * every 2.5 sec for 4. |
| 3528 | * Break our of the loop if errors occurred during init. |
| 3529 | */ |
| 3530 | while (((status & mask) != mask) && |
| 3531 | !(status & HS_FFERM) && |
| 3532 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3533 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3534 | if (i <= 5) |
| 3535 | msleep(10); |
| 3536 | else if (i <= 10) |
| 3537 | msleep(500); |
| 3538 | else |
| 3539 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3541 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3542 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3543 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3544 | lpfc_sli_brdrestart(phba); |
| 3545 | } |
| 3546 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3547 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3548 | retval = 1; |
| 3549 | break; |
| 3550 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3551 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3553 | /* Check to see if any errors occurred during init */ |
| 3554 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3556 | "2751 Adapter failed to restart, " |
| 3557 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3558 | status, |
| 3559 | readl(phba->MBslimaddr + 0xa8), |
| 3560 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3561 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3562 | retval = 1; |
| 3563 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3565 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | } |
| 3567 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3568 | /** |
| 3569 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3570 | * @phba: Pointer to HBA context object. |
| 3571 | * @mask: Bit mask to be checked. |
| 3572 | * |
| 3573 | * This function checks the host status register to check if HBA is |
| 3574 | * ready. This function will wait in a loop for the HBA to be ready |
| 3575 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3576 | * function again. The function returns 1 when HBA fail to be ready |
| 3577 | * otherwise returns zero. |
| 3578 | **/ |
| 3579 | static int |
| 3580 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3581 | { |
| 3582 | uint32_t status; |
| 3583 | int retval = 0; |
| 3584 | |
| 3585 | /* Read the HBA Host Status Register */ |
| 3586 | status = lpfc_sli4_post_status_check(phba); |
| 3587 | |
| 3588 | if (status) { |
| 3589 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3590 | lpfc_sli_brdrestart(phba); |
| 3591 | status = lpfc_sli4_post_status_check(phba); |
| 3592 | } |
| 3593 | |
| 3594 | /* Check to see if any errors occurred during init */ |
| 3595 | if (status) { |
| 3596 | phba->link_state = LPFC_HBA_ERROR; |
| 3597 | retval = 1; |
| 3598 | } else |
| 3599 | phba->sli4_hba.intr_enable = 0; |
| 3600 | |
| 3601 | return retval; |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3606 | * @phba: Pointer to HBA context object. |
| 3607 | * @mask: Bit mask to be checked. |
| 3608 | * |
| 3609 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3610 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3611 | **/ |
| 3612 | int |
| 3613 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3614 | { |
| 3615 | return phba->lpfc_sli_brdready(phba, mask); |
| 3616 | } |
| 3617 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3618 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3619 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3620 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3621 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3622 | * @phba: Pointer to HBA context object. |
| 3623 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3624 | * This function is called before resetting an HBA. This function is called |
| 3625 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3626 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3627 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3628 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3629 | uint32_t __iomem *resp_buf; |
| 3630 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3631 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3632 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3633 | int i; |
| 3634 | uint8_t hdrtype; |
| 3635 | |
| 3636 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3637 | if (hdrtype != 0x80 || |
| 3638 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3639 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3640 | return; |
| 3641 | |
| 3642 | /* |
| 3643 | * Tell the other part of the chip to suspend temporarily all |
| 3644 | * its DMA activity. |
| 3645 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3646 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3647 | |
| 3648 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3649 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3650 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3651 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3652 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3653 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3654 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3655 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3656 | return; |
| 3657 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3658 | /* Clear Chip error bit */ |
| 3659 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3660 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | mbox = 0; |
| 3664 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3665 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3666 | |
| 3667 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3668 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3669 | writel(mbox, mbox_buf); |
| 3670 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3671 | for (i = 0; i < 50; i++) { |
| 3672 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3673 | return; |
| 3674 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3675 | mdelay(1); |
| 3676 | else |
| 3677 | break; |
| 3678 | } |
| 3679 | resp_data = 0; |
| 3680 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3681 | return; |
| 3682 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3683 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3684 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3685 | goto restore_hc; |
| 3686 | else |
| 3687 | goto clear_errat; |
| 3688 | } |
| 3689 | |
| 3690 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3691 | resp_data = 0; |
| 3692 | for (i = 0; i < 500; i++) { |
| 3693 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3694 | return; |
| 3695 | if (resp_data != mbox) |
| 3696 | mdelay(1); |
| 3697 | else |
| 3698 | break; |
| 3699 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3700 | |
| 3701 | clear_errat: |
| 3702 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3703 | while (++i < 500) { |
| 3704 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3705 | return; |
| 3706 | if (!(ha_copy & HA_ERATT)) |
| 3707 | mdelay(1); |
| 3708 | else |
| 3709 | break; |
| 3710 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3711 | |
| 3712 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3713 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3714 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3718 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3719 | writel(hc_copy, phba->HCregaddr); |
| 3720 | readl(phba->HCregaddr); /* flush */ |
| 3721 | } |
| 3722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3724 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3725 | * @phba: Pointer to HBA context object. |
| 3726 | * |
| 3727 | * This function issues a kill_board mailbox command and waits for |
| 3728 | * the error attention interrupt. This function is called for stopping |
| 3729 | * the firmware processing. The caller is not required to hold any |
| 3730 | * locks. This function calls lpfc_hba_down_post function to free |
| 3731 | * any pending commands after the kill. The function will return 1 when it |
| 3732 | * fails to kill the board else will return 0. |
| 3733 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3734 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3735 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3737 | struct lpfc_sli *psli; |
| 3738 | LPFC_MBOXQ_t *pmb; |
| 3739 | uint32_t status; |
| 3740 | uint32_t ha_copy; |
| 3741 | int retval; |
| 3742 | int i = 0; |
| 3743 | |
| 3744 | psli = &phba->sli; |
| 3745 | |
| 3746 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3747 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3748 | "0329 Kill HBA Data: x%x x%x\n", |
| 3749 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3750 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3751 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3752 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3753 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3754 | |
| 3755 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3756 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3757 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3758 | spin_unlock_irq(&phba->hbalock); |
| 3759 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3760 | return 1; |
| 3761 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3762 | status &= ~HC_ERINT_ENA; |
| 3763 | writel(status, phba->HCregaddr); |
| 3764 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3765 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3766 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3767 | |
| 3768 | lpfc_kill_board(phba, pmb); |
| 3769 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3770 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3771 | |
| 3772 | if (retval != MBX_SUCCESS) { |
| 3773 | if (retval != MBX_BUSY) |
| 3774 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3775 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3776 | "2752 KILL_BOARD command failed retval %d\n", |
| 3777 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3778 | spin_lock_irq(&phba->hbalock); |
| 3779 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3780 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3781 | return 1; |
| 3782 | } |
| 3783 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3784 | spin_lock_irq(&phba->hbalock); |
| 3785 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3786 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3787 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3788 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3789 | |
| 3790 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3791 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3792 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3793 | * board is now undefined. |
| 3794 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3795 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3796 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3797 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3798 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3799 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3800 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3804 | if (ha_copy & HA_ERATT) { |
| 3805 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3807 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3808 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3809 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3810 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3811 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3812 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3813 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3814 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3815 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3816 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3817 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3818 | } |
| 3819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3820 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3821 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3822 | * @phba: Pointer to HBA context object. |
| 3823 | * |
| 3824 | * This function resets the HBA by writing HC_INITFF to the control |
| 3825 | * register. After the HBA resets, this function resets all the iocb ring |
| 3826 | * indices. This function disables PCI layer parity checking during |
| 3827 | * the reset. |
| 3828 | * This function returns 0 always. |
| 3829 | * The caller is not required to hold any locks. |
| 3830 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3831 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3833 | { |
| 3834 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3835 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3836 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3839 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3841 | /* Reset HBA */ |
| 3842 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3843 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | |
| 3846 | /* perform board reset */ |
| 3847 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3848 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3849 | phba->pport->fc_myDID = 0; |
| 3850 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3852 | /* Turn off parity checking and serr during the physical reset */ |
| 3853 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3854 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3855 | (cfg_value & |
| 3856 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3857 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3858 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3859 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3860 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3861 | writel(HC_INITFF, phba->HCregaddr); |
| 3862 | mdelay(1); |
| 3863 | readl(phba->HCregaddr); /* flush */ |
| 3864 | writel(0, phba->HCregaddr); |
| 3865 | readl(phba->HCregaddr); /* flush */ |
| 3866 | |
| 3867 | /* Restore PCI cmd register */ |
| 3868 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | |
| 3870 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3871 | for (i = 0; i < psli->num_rings; i++) { |
| 3872 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3874 | pring->sli.sli3.rspidx = 0; |
| 3875 | pring->sli.sli3.next_cmdidx = 0; |
| 3876 | pring->sli.sli3.local_getidx = 0; |
| 3877 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | pring->missbufcnt = 0; |
| 3879 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3881 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3882 | return 0; |
| 3883 | } |
| 3884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3885 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3886 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3887 | * @phba: Pointer to HBA context object. |
| 3888 | * |
| 3889 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3890 | * checking during resets the device. The caller is not required to hold |
| 3891 | * any locks. |
| 3892 | * |
| 3893 | * This function returns 0 always. |
| 3894 | **/ |
| 3895 | int |
| 3896 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3897 | { |
| 3898 | struct lpfc_sli *psli = &phba->sli; |
| 3899 | uint16_t cfg_value; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3900 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3901 | |
| 3902 | /* Reset HBA */ |
| 3903 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3904 | "0295 Reset HBA Data: x%x x%x\n", |
| 3905 | phba->pport->port_state, psli->sli_flag); |
| 3906 | |
| 3907 | /* perform board reset */ |
| 3908 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3909 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3910 | phba->pport->fc_myDID = 0; |
| 3911 | phba->pport->fc_prevDID = 0; |
| 3912 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3913 | spin_lock_irq(&phba->hbalock); |
| 3914 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3915 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3916 | spin_unlock_irq(&phba->hbalock); |
| 3917 | |
| 3918 | /* Now physically reset the device */ |
| 3919 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3920 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3921 | |
| 3922 | /* Turn off parity checking and serr during the physical reset */ |
| 3923 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3924 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3925 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3926 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3927 | /* Perform FCoE PCI function reset */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 3928 | lpfc_sli4_queue_destroy(phba); |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3929 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3930 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3931 | /* Restore PCI cmd register */ |
| 3932 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3933 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3934 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | /** |
| 3938 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3939 | * @phba: Pointer to HBA context object. |
| 3940 | * |
| 3941 | * This function is called in the SLI initialization code path to |
| 3942 | * restart the HBA. The caller is not required to hold any lock. |
| 3943 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 3944 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 3945 | * function to free any pending commands. The function enables |
| 3946 | * POST only during the first initialization. The function returns zero. |
| 3947 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 3948 | * command before the return of this function. |
| 3949 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3950 | static int |
| 3951 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3952 | { |
| 3953 | MAILBOX_t *mb; |
| 3954 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3955 | volatile uint32_t word0; |
| 3956 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3957 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3959 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3960 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3961 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 3962 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 3963 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3964 | psli = &phba->sli; |
| 3965 | |
| 3966 | /* Restart HBA */ |
| 3967 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3968 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3970 | |
| 3971 | word0 = 0; |
| 3972 | mb = (MAILBOX_t *) &word0; |
| 3973 | mb->mbxCommand = MBX_RESTART; |
| 3974 | mb->mbxHc = 1; |
| 3975 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3976 | lpfc_reset_barrier(phba); |
| 3977 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3978 | to_slim = phba->MBslimaddr; |
| 3979 | writel(*(uint32_t *) mb, to_slim); |
| 3980 | readl(to_slim); /* flush */ |
| 3981 | |
| 3982 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3983 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3984 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3985 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3986 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3987 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3988 | writel(*(uint32_t *) mb, to_slim); |
| 3989 | readl(to_slim); /* flush */ |
| 3990 | |
| 3991 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | phba->pport->stopped = 0; |
| 3993 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3994 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3995 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3996 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 3997 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 3998 | psli->stats_start = get_seconds(); |
| 3999 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4000 | /* Give the INITFF and Post time to settle. */ |
| 4001 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4003 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4004 | if (hba_aer_enabled) |
| 4005 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4006 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4007 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4008 | |
| 4009 | return 0; |
| 4010 | } |
| 4011 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4012 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4013 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4014 | * @phba: Pointer to HBA context object. |
| 4015 | * |
| 4016 | * This function is called in the SLI initialization code path to restart |
| 4017 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4018 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4019 | * free any pending commands. |
| 4020 | **/ |
| 4021 | static int |
| 4022 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4023 | { |
| 4024 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4025 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4026 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4027 | |
| 4028 | /* Restart HBA */ |
| 4029 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4030 | "0296 Restart HBA Data: x%x x%x\n", |
| 4031 | phba->pport->port_state, psli->sli_flag); |
| 4032 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4033 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4034 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4035 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4036 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4037 | |
| 4038 | spin_lock_irq(&phba->hbalock); |
| 4039 | phba->pport->stopped = 0; |
| 4040 | phba->link_state = LPFC_INIT_START; |
| 4041 | phba->hba_flag = 0; |
| 4042 | spin_unlock_irq(&phba->hbalock); |
| 4043 | |
| 4044 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4045 | psli->stats_start = get_seconds(); |
| 4046 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4047 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4048 | if (hba_aer_enabled) |
| 4049 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4050 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4051 | lpfc_hba_down_post(phba); |
| 4052 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4053 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | /** |
| 4057 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4058 | * @phba: Pointer to HBA context object. |
| 4059 | * |
| 4060 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4061 | * API jump table function pointer from the lpfc_hba struct. |
| 4062 | **/ |
| 4063 | int |
| 4064 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4065 | { |
| 4066 | return phba->lpfc_sli_brdrestart(phba); |
| 4067 | } |
| 4068 | |
| 4069 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4070 | * 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] | 4071 | * @phba: Pointer to HBA context object. |
| 4072 | * |
| 4073 | * This function is called after a HBA restart to wait for successful |
| 4074 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4075 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4076 | * iteration, the function will restart the HBA again. The function returns |
| 4077 | * zero if HBA successfully restarted else returns negative error code. |
| 4078 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | static int |
| 4080 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4081 | { |
| 4082 | uint32_t status, i = 0; |
| 4083 | |
| 4084 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4085 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4086 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4087 | |
| 4088 | /* Check status register to see what current state is */ |
| 4089 | i = 0; |
| 4090 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4091 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4092 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4093 | * retries, then every 1 sec for 50 retires for a total of |
| 4094 | * ~60 seconds before reset the board again and check every |
| 4095 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4096 | * board ready is required by the Falcon FIPS zeroization |
| 4097 | * complete, and any reset the board in between shall cause |
| 4098 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4100 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | /* Adapter failed to init, timeout, status reg |
| 4102 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4104 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4105 | "timeout, status reg x%x, " |
| 4106 | "FW Data: A8 x%x AC x%x\n", status, |
| 4107 | readl(phba->MBslimaddr + 0xa8), |
| 4108 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | return -ETIMEDOUT; |
| 4111 | } |
| 4112 | |
| 4113 | /* Check to see if any errors occurred during init */ |
| 4114 | if (status & HS_FFERM) { |
| 4115 | /* ERROR: During chipset initialization */ |
| 4116 | /* Adapter failed to init, chipset, status reg |
| 4117 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4118 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4119 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4120 | "chipset, status reg x%x, " |
| 4121 | "FW Data: A8 x%x AC x%x\n", status, |
| 4122 | readl(phba->MBslimaddr + 0xa8), |
| 4123 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4124 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4125 | return -EIO; |
| 4126 | } |
| 4127 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4128 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4130 | else if (i <= 100) |
| 4131 | msleep(100); |
| 4132 | else |
| 4133 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4135 | if (i == 150) { |
| 4136 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4137 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4138 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | } |
| 4140 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4141 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4142 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | /* Check to see if any errors occurred during init */ |
| 4146 | if (status & HS_FFERM) { |
| 4147 | /* ERROR: During chipset initialization */ |
| 4148 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4150 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4151 | "status reg x%x, " |
| 4152 | "FW Data: A8 x%x AC x%x\n", status, |
| 4153 | readl(phba->MBslimaddr + 0xa8), |
| 4154 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4155 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | return -EIO; |
| 4157 | } |
| 4158 | |
| 4159 | /* Clear all interrupt enable conditions */ |
| 4160 | writel(0, phba->HCregaddr); |
| 4161 | readl(phba->HCregaddr); /* flush */ |
| 4162 | |
| 4163 | /* setup host attn register */ |
| 4164 | writel(0xffffffff, phba->HAregaddr); |
| 4165 | readl(phba->HAregaddr); /* flush */ |
| 4166 | return 0; |
| 4167 | } |
| 4168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4169 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4170 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4171 | * |
| 4172 | * This function calculates and returns the number of HBQs required to be |
| 4173 | * configured. |
| 4174 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4175 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4176 | lpfc_sli_hbq_count(void) |
| 4177 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4178 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4179 | } |
| 4180 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4181 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4182 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4183 | * |
| 4184 | * This function adds the number of hbq entries in every HBQ to get |
| 4185 | * the total number of hbq entries required for the HBA and returns |
| 4186 | * the total count. |
| 4187 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4188 | static int |
| 4189 | lpfc_sli_hbq_entry_count(void) |
| 4190 | { |
| 4191 | int hbq_count = lpfc_sli_hbq_count(); |
| 4192 | int count = 0; |
| 4193 | int i; |
| 4194 | |
| 4195 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4196 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4197 | return count; |
| 4198 | } |
| 4199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4201 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4202 | * |
| 4203 | * This function calculates amount of memory required for all hbq entries |
| 4204 | * to be configured and returns the total memory required. |
| 4205 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4206 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4207 | lpfc_sli_hbq_size(void) |
| 4208 | { |
| 4209 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4210 | } |
| 4211 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4212 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4213 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4214 | * @phba: Pointer to HBA context object. |
| 4215 | * |
| 4216 | * This function is called during the SLI initialization to configure |
| 4217 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4218 | * required to hold any locks. This function will return zero if successful |
| 4219 | * else it will return negative error code. |
| 4220 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4221 | static int |
| 4222 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4223 | { |
| 4224 | int hbq_count = lpfc_sli_hbq_count(); |
| 4225 | LPFC_MBOXQ_t *pmb; |
| 4226 | MAILBOX_t *pmbox; |
| 4227 | uint32_t hbqno; |
| 4228 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4229 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4230 | /* Get a Mailbox buffer to setup mailbox |
| 4231 | * commands for HBA initialization |
| 4232 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4233 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4234 | |
| 4235 | if (!pmb) |
| 4236 | return -ENOMEM; |
| 4237 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4238 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4239 | |
| 4240 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4241 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4242 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4243 | |
| 4244 | hbq_entry_index = 0; |
| 4245 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4246 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4247 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4248 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4249 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4250 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4251 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4252 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4253 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4254 | |
| 4255 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4256 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4257 | mbxStatus <status>, ring <num> */ |
| 4258 | |
| 4259 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4260 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4261 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4262 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4263 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4264 | pmbox->mbxStatus, hbqno); |
| 4265 | |
| 4266 | phba->link_state = LPFC_HBA_ERROR; |
| 4267 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4268 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4269 | } |
| 4270 | } |
| 4271 | phba->hbq_count = hbq_count; |
| 4272 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4273 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4275 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4276 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4277 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4278 | return 0; |
| 4279 | } |
| 4280 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4281 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4282 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4283 | * @phba: Pointer to HBA context object. |
| 4284 | * |
| 4285 | * This function is called during the SLI initialization to configure |
| 4286 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4287 | * required to hold any locks. This function will return zero if successful |
| 4288 | * else it will return negative error code. |
| 4289 | **/ |
| 4290 | static int |
| 4291 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4292 | { |
| 4293 | phba->hbq_in_use = 1; |
| 4294 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4295 | phba->hbq_count = 1; |
| 4296 | /* Initially populate or replenish the HBQs */ |
| 4297 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4298 | return 0; |
| 4299 | } |
| 4300 | |
| 4301 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4302 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4303 | * @phba: Pointer to HBA context object. |
| 4304 | * @sli_mode: sli mode - 2/3 |
| 4305 | * |
| 4306 | * This function is called by the sli intialization code path |
| 4307 | * to issue config_port mailbox command. This function restarts the |
| 4308 | * HBA firmware and issues a config_port mailbox command to configure |
| 4309 | * the SLI interface in the sli mode specified by sli_mode |
| 4310 | * variable. The caller is not required to hold any locks. |
| 4311 | * The function returns 0 if successful, else returns negative error |
| 4312 | * code. |
| 4313 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4314 | int |
| 4315 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | { |
| 4317 | LPFC_MBOXQ_t *pmb; |
| 4318 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4319 | |
| 4320 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4321 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | return -ENOMEM; |
| 4324 | } |
| 4325 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4326 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4327 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4328 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4329 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4331 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4332 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | rc = lpfc_sli_chipset_init(phba); |
| 4334 | if (rc) |
| 4335 | break; |
| 4336 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4338 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | resetcount++; |
| 4341 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4342 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4343 | * value of 0 means the call was successful. Any other |
| 4344 | * nonzero value is a failure, but if ERESTART is returned, |
| 4345 | * the driver may reset the HBA and try again. |
| 4346 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4347 | rc = lpfc_config_port_prep(phba); |
| 4348 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4349 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4351 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4352 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4353 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4354 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4355 | lpfc_config_port(phba, pmb); |
| 4356 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4357 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4358 | LPFC_SLI3_HBQ_ENABLED | |
| 4359 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4360 | LPFC_SLI3_BG_ENABLED | |
| 4361 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4362 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4364 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4365 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4366 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4368 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4369 | spin_unlock_irq(&phba->hbalock); |
| 4370 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4371 | } else { |
| 4372 | /* Allow asynchronous mailbox command to go through */ |
| 4373 | spin_lock_irq(&phba->hbalock); |
| 4374 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4375 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4376 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4377 | |
| 4378 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4379 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4380 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4381 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4382 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4384 | if (!done) { |
| 4385 | rc = -EINVAL; |
| 4386 | goto do_prep_failed; |
| 4387 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4388 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4389 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4390 | rc = -ENXIO; |
| 4391 | goto do_prep_failed; |
| 4392 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4393 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4394 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4395 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4396 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4397 | phba->max_vpi : phba->max_vports; |
| 4398 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4399 | } else |
| 4400 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4401 | phba->fips_level = 0; |
| 4402 | phba->fips_spec_rev = 0; |
| 4403 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4404 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4405 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4406 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4407 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4408 | "2850 Security Crypto Active. FIPS x%d " |
| 4409 | "(Spec Rev: x%d)", |
| 4410 | phba->fips_level, phba->fips_spec_rev); |
| 4411 | } |
| 4412 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4414 | "2856 Config Port Security Crypto " |
| 4415 | "Error: x%x ", |
| 4416 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4417 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4418 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4419 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4420 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4421 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4422 | |
| 4423 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4424 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4425 | |
| 4426 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4427 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4428 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4429 | else |
| 4430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4431 | "0443 Adapter did not grant " |
| 4432 | "BlockGuard\n"); |
| 4433 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4434 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4435 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4436 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4437 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4438 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4439 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4440 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4441 | return rc; |
| 4442 | } |
| 4443 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4444 | |
| 4445 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4446 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4447 | * @phba: Pointer to HBA context object. |
| 4448 | * |
| 4449 | * This function is the main SLI intialization function. This function |
| 4450 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4451 | * error attention handler code. Caller is not required to hold any |
| 4452 | * locks. This function issues config_port mailbox command to configure |
| 4453 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4454 | * calls the config_port_post function to issue init_link mailbox |
| 4455 | * command and to start the discovery. The function will return zero |
| 4456 | * if successful, else it will return negative error code. |
| 4457 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4458 | int |
| 4459 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4460 | { |
| 4461 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4462 | int mode = 3, i; |
| 4463 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4464 | |
| 4465 | switch (lpfc_sli_mode) { |
| 4466 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4467 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4469 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4470 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4471 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4472 | break; |
| 4473 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4474 | mode = 2; |
| 4475 | break; |
| 4476 | case 0: |
| 4477 | case 3: |
| 4478 | break; |
| 4479 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4480 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4481 | "1819 Unrecognized lpfc_sli_mode " |
| 4482 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4483 | |
| 4484 | break; |
| 4485 | } |
| 4486 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4487 | rc = lpfc_sli_config_port(phba, mode); |
| 4488 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4489 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4490 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4491 | "1820 Unable to select SLI-3. " |
| 4492 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4493 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4494 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4495 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4496 | goto lpfc_sli_hba_setup_error; |
| 4497 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4498 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4499 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4500 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4501 | if (!rc) { |
| 4502 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4503 | "2709 This device supports " |
| 4504 | "Advanced Error Reporting (AER)\n"); |
| 4505 | spin_lock_irq(&phba->hbalock); |
| 4506 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4507 | spin_unlock_irq(&phba->hbalock); |
| 4508 | } else { |
| 4509 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4510 | "2708 This device does not support " |
| 4511 | "Advanced Error Reporting (AER)\n"); |
| 4512 | phba->cfg_aer_support = 0; |
| 4513 | } |
| 4514 | } |
| 4515 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4516 | if (phba->sli_rev == 3) { |
| 4517 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4518 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4519 | } else { |
| 4520 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4521 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4522 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4526 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4527 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4528 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | |
| 4530 | if (rc) |
| 4531 | goto lpfc_sli_hba_setup_error; |
| 4532 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4533 | /* Initialize VPIs. */ |
| 4534 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4535 | /* |
| 4536 | * The VPI bitmask and physical ID array are allocated |
| 4537 | * and initialized once only - at driver load. A port |
| 4538 | * reset doesn't need to reinitialize this memory. |
| 4539 | */ |
| 4540 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4541 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4542 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4543 | GFP_KERNEL); |
| 4544 | if (!phba->vpi_bmask) { |
| 4545 | rc = -ENOMEM; |
| 4546 | goto lpfc_sli_hba_setup_error; |
| 4547 | } |
| 4548 | |
| 4549 | phba->vpi_ids = kzalloc( |
| 4550 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4551 | GFP_KERNEL); |
| 4552 | if (!phba->vpi_ids) { |
| 4553 | kfree(phba->vpi_bmask); |
| 4554 | rc = -ENOMEM; |
| 4555 | goto lpfc_sli_hba_setup_error; |
| 4556 | } |
| 4557 | for (i = 0; i < phba->max_vpi; i++) |
| 4558 | phba->vpi_ids[i] = i; |
| 4559 | } |
| 4560 | } |
| 4561 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4562 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4563 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4564 | rc = lpfc_sli_hbq_setup(phba); |
| 4565 | if (rc) |
| 4566 | goto lpfc_sli_hba_setup_error; |
| 4567 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4568 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4570 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4571 | |
| 4572 | rc = lpfc_config_port_post(phba); |
| 4573 | if (rc) |
| 4574 | goto lpfc_sli_hba_setup_error; |
| 4575 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4576 | return rc; |
| 4577 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4578 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4579 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4581 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4582 | return rc; |
| 4583 | } |
| 4584 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4585 | /** |
| 4586 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4587 | * @phba: Pointer to HBA context object. |
| 4588 | * @mboxq: mailbox pointer. |
| 4589 | * This function issue a dump mailbox command to read config region |
| 4590 | * 23 and parse the records in the region and populate driver |
| 4591 | * data structure. |
| 4592 | **/ |
| 4593 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4594 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4595 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4596 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4597 | struct lpfc_dmabuf *mp; |
| 4598 | struct lpfc_mqe *mqe; |
| 4599 | uint32_t data_length; |
| 4600 | int rc; |
| 4601 | |
| 4602 | /* Program the default value of vlan_id and fc_map */ |
| 4603 | phba->valid_vlan = 0; |
| 4604 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4605 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4606 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4607 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4608 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4609 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4610 | return -ENOMEM; |
| 4611 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4612 | mqe = &mboxq->u.mqe; |
| 4613 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4614 | rc = -ENOMEM; |
| 4615 | goto out_free_mboxq; |
| 4616 | } |
| 4617 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4618 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4619 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4620 | |
| 4621 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4622 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4623 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4624 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4625 | "CQ: x%x x%x x%x x%x\n", |
| 4626 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4627 | bf_get(lpfc_mqe_command, mqe), |
| 4628 | bf_get(lpfc_mqe_status, mqe), |
| 4629 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4630 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4631 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4632 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4633 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4634 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4635 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4636 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4637 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4638 | mboxq->mcqe.word0, |
| 4639 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4640 | mboxq->mcqe.trailer); |
| 4641 | |
| 4642 | if (rc) { |
| 4643 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4644 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4645 | rc = -EIO; |
| 4646 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4647 | } |
| 4648 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4649 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4650 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4651 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4652 | rc = -EIO; |
| 4653 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4654 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4655 | |
| 4656 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4657 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4658 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4659 | rc = 0; |
| 4660 | |
| 4661 | out_free_mboxq: |
| 4662 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4663 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | /** |
| 4667 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4668 | * @phba: pointer to lpfc hba data structure. |
| 4669 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4670 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4671 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4672 | * On output, the number of data bytes in @vpd. |
| 4673 | * |
| 4674 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4675 | * addition, this routine gets the port vpd data. |
| 4676 | * |
| 4677 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4678 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4679 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4680 | **/ |
| 4681 | static int |
| 4682 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4683 | uint8_t *vpd, uint32_t *vpd_size) |
| 4684 | { |
| 4685 | int rc = 0; |
| 4686 | uint32_t dma_size; |
| 4687 | struct lpfc_dmabuf *dmabuf; |
| 4688 | struct lpfc_mqe *mqe; |
| 4689 | |
| 4690 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4691 | if (!dmabuf) |
| 4692 | return -ENOMEM; |
| 4693 | |
| 4694 | /* |
| 4695 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4696 | * mailbox command. |
| 4697 | */ |
| 4698 | dma_size = *vpd_size; |
| 4699 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4700 | dma_size, |
| 4701 | &dmabuf->phys, |
| 4702 | GFP_KERNEL); |
| 4703 | if (!dmabuf->virt) { |
| 4704 | kfree(dmabuf); |
| 4705 | return -ENOMEM; |
| 4706 | } |
| 4707 | memset(dmabuf->virt, 0, dma_size); |
| 4708 | |
| 4709 | /* |
| 4710 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4711 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4712 | * in SLI3. This code corrects the conflicts. |
| 4713 | */ |
| 4714 | lpfc_read_rev(phba, mboxq); |
| 4715 | mqe = &mboxq->u.mqe; |
| 4716 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4717 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4718 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4719 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4720 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4721 | |
| 4722 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4723 | if (rc) { |
| 4724 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4725 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4726 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4727 | return -EIO; |
| 4728 | } |
| 4729 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4730 | /* |
| 4731 | * The available vpd length cannot be bigger than the |
| 4732 | * DMA buffer passed to the port. Catch the less than |
| 4733 | * case and update the caller's size. |
| 4734 | */ |
| 4735 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4736 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4737 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4738 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4739 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4740 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4741 | dmabuf->virt, dmabuf->phys); |
| 4742 | kfree(dmabuf); |
| 4743 | return 0; |
| 4744 | } |
| 4745 | |
| 4746 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4747 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4748 | * @phba: pointer to lpfc hba data structure. |
| 4749 | * |
| 4750 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4751 | * is attached to. |
| 4752 | * |
| 4753 | * Return codes |
| 4754 | * 0 - sucessful |
| 4755 | * otherwise - failed to retrieve physical port name |
| 4756 | **/ |
| 4757 | static int |
| 4758 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4759 | { |
| 4760 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4761 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4762 | struct lpfc_controller_attribute *cntl_attr; |
| 4763 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4764 | void *virtaddr = NULL; |
| 4765 | uint32_t alloclen, reqlen; |
| 4766 | uint32_t shdr_status, shdr_add_status; |
| 4767 | union lpfc_sli4_cfg_shdr *shdr; |
| 4768 | char cport_name = 0; |
| 4769 | int rc; |
| 4770 | |
| 4771 | /* We assume nothing at this point */ |
| 4772 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4773 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4774 | |
| 4775 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4776 | if (!mboxq) |
| 4777 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4778 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4779 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4780 | lpfc_sli4_read_config(phba); |
| 4781 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4782 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4783 | |
| 4784 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4785 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4786 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4787 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4788 | LPFC_SLI4_MBX_NEMBED); |
| 4789 | if (alloclen < reqlen) { |
| 4790 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4791 | "3084 Allocated DMA memory size (%d) is " |
| 4792 | "less than the requested DMA memory size " |
| 4793 | "(%d)\n", alloclen, reqlen); |
| 4794 | rc = -ENOMEM; |
| 4795 | goto out_free_mboxq; |
| 4796 | } |
| 4797 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4798 | virtaddr = mboxq->sge_array->addr[0]; |
| 4799 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4800 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4801 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4802 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4803 | if (shdr_status || shdr_add_status || rc) { |
| 4804 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4805 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4806 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4807 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4808 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4809 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4810 | rc, shdr_status, shdr_add_status); |
| 4811 | rc = -ENXIO; |
| 4812 | goto out_free_mboxq; |
| 4813 | } |
| 4814 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4815 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4816 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4817 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4818 | phba->sli4_hba.lnk_info.lnk_no = |
| 4819 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4820 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4821 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4822 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4823 | phba->sli4_hba.lnk_info.lnk_no); |
| 4824 | |
| 4825 | retrieve_ppname: |
| 4826 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4827 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4828 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4829 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4830 | LPFC_SLI4_MBX_EMBED); |
| 4831 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4832 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4833 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4834 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4835 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4836 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4837 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4838 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4839 | if (shdr_status || shdr_add_status || rc) { |
| 4840 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4841 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4842 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4843 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4844 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4845 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4846 | rc, shdr_status, shdr_add_status); |
| 4847 | rc = -ENXIO; |
| 4848 | goto out_free_mboxq; |
| 4849 | } |
| 4850 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4851 | case LPFC_LINK_NUMBER_0: |
| 4852 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4853 | &get_port_name->u.response); |
| 4854 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4855 | break; |
| 4856 | case LPFC_LINK_NUMBER_1: |
| 4857 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4858 | &get_port_name->u.response); |
| 4859 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4860 | break; |
| 4861 | case LPFC_LINK_NUMBER_2: |
| 4862 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4863 | &get_port_name->u.response); |
| 4864 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4865 | break; |
| 4866 | case LPFC_LINK_NUMBER_3: |
| 4867 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4868 | &get_port_name->u.response); |
| 4869 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4870 | break; |
| 4871 | default: |
| 4872 | break; |
| 4873 | } |
| 4874 | |
| 4875 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4876 | phba->Port[0] = cport_name; |
| 4877 | phba->Port[1] = '\0'; |
| 4878 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4879 | "3091 SLI get port name: %s\n", phba->Port); |
| 4880 | } |
| 4881 | |
| 4882 | out_free_mboxq: |
| 4883 | if (rc != MBX_TIMEOUT) { |
| 4884 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4885 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4886 | else |
| 4887 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4888 | } |
| 4889 | return rc; |
| 4890 | } |
| 4891 | |
| 4892 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4893 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4894 | * @phba: pointer to lpfc hba data structure. |
| 4895 | * |
| 4896 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4897 | * event queues |
| 4898 | **/ |
| 4899 | static void |
| 4900 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4901 | { |
| 4902 | uint8_t fcp_eqidx; |
| 4903 | |
| 4904 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4905 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4906 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4907 | if (phba->sli4_hba.fcp_cq) { |
| 4908 | do |
| 4909 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4910 | LPFC_QUEUE_REARM); |
| 4911 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
| 4912 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4914 | if (phba->sli4_hba.fp_eq) { |
| 4915 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 4916 | fcp_eqidx++) |
| 4917 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], |
| 4918 | LPFC_QUEUE_REARM); |
| 4919 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4923 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4924 | * @phba: Pointer to HBA context object. |
| 4925 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4926 | * @extnt_count: buffer to hold port available extent count. |
| 4927 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4928 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4929 | * This function calls the port and retrievs the number of available |
| 4930 | * extents and their size for a particular extent type. |
| 4931 | * |
| 4932 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4933 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4934 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4935 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 4936 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 4937 | { |
| 4938 | int rc = 0; |
| 4939 | uint32_t length; |
| 4940 | uint32_t mbox_tmo; |
| 4941 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 4942 | LPFC_MBOXQ_t *mbox; |
| 4943 | |
| 4944 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4945 | if (!mbox) |
| 4946 | return -ENOMEM; |
| 4947 | |
| 4948 | /* Find out how many extents are available for this resource type */ |
| 4949 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 4950 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 4951 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4952 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 4953 | length, LPFC_SLI4_MBX_EMBED); |
| 4954 | |
| 4955 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 4956 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 4957 | LPFC_SLI4_MBX_EMBED); |
| 4958 | if (unlikely(rc)) { |
| 4959 | rc = -EIO; |
| 4960 | goto err_exit; |
| 4961 | } |
| 4962 | |
| 4963 | if (!phba->sli4_hba.intr_enable) |
| 4964 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 4965 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 4966 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4967 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 4968 | } |
| 4969 | if (unlikely(rc)) { |
| 4970 | rc = -EIO; |
| 4971 | goto err_exit; |
| 4972 | } |
| 4973 | |
| 4974 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 4975 | if (bf_get(lpfc_mbox_hdr_status, |
| 4976 | &rsrc_info->header.cfg_shdr.response)) { |
| 4977 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 4978 | "2930 Failed to get resource extents " |
| 4979 | "Status 0x%x Add'l Status 0x%x\n", |
| 4980 | bf_get(lpfc_mbox_hdr_status, |
| 4981 | &rsrc_info->header.cfg_shdr.response), |
| 4982 | bf_get(lpfc_mbox_hdr_add_status, |
| 4983 | &rsrc_info->header.cfg_shdr.response)); |
| 4984 | rc = -EIO; |
| 4985 | goto err_exit; |
| 4986 | } |
| 4987 | |
| 4988 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 4989 | &rsrc_info->u.rsp); |
| 4990 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 4991 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4992 | |
| 4993 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4994 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 4995 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 4996 | |
| 4997 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4998 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4999 | return rc; |
| 5000 | } |
| 5001 | |
| 5002 | /** |
| 5003 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5004 | * @phba: Pointer to HBA context object. |
| 5005 | * @type: The extent type to check. |
| 5006 | * |
| 5007 | * This function reads the current available extents from the port and checks |
| 5008 | * if the extent count or extent size has changed since the last access. |
| 5009 | * Callers use this routine post port reset to understand if there is a |
| 5010 | * extent reprovisioning requirement. |
| 5011 | * |
| 5012 | * Returns: |
| 5013 | * -Error: error indicates problem. |
| 5014 | * 1: Extent count or size has changed. |
| 5015 | * 0: No changes. |
| 5016 | **/ |
| 5017 | static int |
| 5018 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5019 | { |
| 5020 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5021 | uint16_t size_diff, rsrc_ext_size; |
| 5022 | int rc = 0; |
| 5023 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5024 | struct list_head *rsrc_blk_list = NULL; |
| 5025 | |
| 5026 | size_diff = 0; |
| 5027 | curr_ext_cnt = 0; |
| 5028 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5029 | &rsrc_ext_cnt, |
| 5030 | &rsrc_ext_size); |
| 5031 | if (unlikely(rc)) |
| 5032 | return -EIO; |
| 5033 | |
| 5034 | switch (type) { |
| 5035 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5036 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5037 | break; |
| 5038 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5039 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5040 | break; |
| 5041 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5042 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5043 | break; |
| 5044 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5045 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5046 | break; |
| 5047 | default: |
| 5048 | break; |
| 5049 | } |
| 5050 | |
| 5051 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5052 | curr_ext_cnt++; |
| 5053 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5054 | size_diff++; |
| 5055 | } |
| 5056 | |
| 5057 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5058 | rc = 1; |
| 5059 | |
| 5060 | return rc; |
| 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * lpfc_sli4_cfg_post_extnts - |
| 5065 | * @phba: Pointer to HBA context object. |
| 5066 | * @extnt_cnt - number of available extents. |
| 5067 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5068 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5069 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5070 | * |
| 5071 | * This function executes the extents allocation request. It also |
| 5072 | * takes care of the amount of memory needed to allocate or get the |
| 5073 | * allocated extents. It is the caller's responsibility to evaluate |
| 5074 | * the response. |
| 5075 | * |
| 5076 | * Returns: |
| 5077 | * -Error: Error value describes the condition found. |
| 5078 | * 0: if successful |
| 5079 | **/ |
| 5080 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5081 | 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] | 5082 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5083 | { |
| 5084 | int rc = 0; |
| 5085 | uint32_t req_len; |
| 5086 | uint32_t emb_len; |
| 5087 | uint32_t alloc_len, mbox_tmo; |
| 5088 | |
| 5089 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5090 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5091 | |
| 5092 | /* |
| 5093 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5094 | * accounts for extents-specific word. |
| 5095 | */ |
| 5096 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5097 | sizeof(uint32_t); |
| 5098 | |
| 5099 | /* |
| 5100 | * Presume the allocation and response will fit into an embedded |
| 5101 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5102 | */ |
| 5103 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5104 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5105 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5106 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5107 | sizeof(uint32_t); |
| 5108 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5109 | } |
| 5110 | |
| 5111 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5112 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5113 | req_len, *emb); |
| 5114 | if (alloc_len < req_len) { |
| 5115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5116 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5117 | "less than the requested DMA memory " |
| 5118 | "size (x%x)\n", alloc_len, req_len); |
| 5119 | return -ENOMEM; |
| 5120 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5121 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5122 | if (unlikely(rc)) |
| 5123 | return -EIO; |
| 5124 | |
| 5125 | if (!phba->sli4_hba.intr_enable) |
| 5126 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5127 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5128 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5129 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5130 | } |
| 5131 | |
| 5132 | if (unlikely(rc)) |
| 5133 | rc = -EIO; |
| 5134 | return rc; |
| 5135 | } |
| 5136 | |
| 5137 | /** |
| 5138 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5139 | * @phba: Pointer to HBA context object. |
| 5140 | * @type: The resource extent type to allocate. |
| 5141 | * |
| 5142 | * This function allocates the number of elements for the specified |
| 5143 | * resource type. |
| 5144 | **/ |
| 5145 | static int |
| 5146 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5147 | { |
| 5148 | bool emb = false; |
| 5149 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5150 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5151 | uint16_t *ids; |
| 5152 | int i, rc; |
| 5153 | unsigned long longs; |
| 5154 | unsigned long *bmask; |
| 5155 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5156 | LPFC_MBOXQ_t *mbox; |
| 5157 | uint32_t length; |
| 5158 | struct lpfc_id_range *id_array = NULL; |
| 5159 | void *virtaddr = NULL; |
| 5160 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5161 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5162 | struct list_head *ext_blk_list; |
| 5163 | |
| 5164 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5165 | &rsrc_cnt, |
| 5166 | &rsrc_size); |
| 5167 | if (unlikely(rc)) |
| 5168 | return -EIO; |
| 5169 | |
| 5170 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5171 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5172 | "3009 No available Resource Extents " |
| 5173 | "for resource type 0x%x: Count: 0x%x, " |
| 5174 | "Size 0x%x\n", type, rsrc_cnt, |
| 5175 | rsrc_size); |
| 5176 | return -ENOMEM; |
| 5177 | } |
| 5178 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5179 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5180 | "2903 Post resource extents type-0x%x: " |
| 5181 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5182 | |
| 5183 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5184 | if (!mbox) |
| 5185 | return -ENOMEM; |
| 5186 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5187 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5188 | if (unlikely(rc)) { |
| 5189 | rc = -EIO; |
| 5190 | goto err_exit; |
| 5191 | } |
| 5192 | |
| 5193 | /* |
| 5194 | * Figure out where the response is located. Then get local pointers |
| 5195 | * to the response data. The port does not guarantee to respond to |
| 5196 | * all extents counts request so update the local variable with the |
| 5197 | * allocated count from the port. |
| 5198 | */ |
| 5199 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5200 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5201 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5202 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5203 | } else { |
| 5204 | virtaddr = mbox->sge_array->addr[0]; |
| 5205 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5206 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5207 | id_array = &n_rsrc->id; |
| 5208 | } |
| 5209 | |
| 5210 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5211 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5212 | |
| 5213 | /* |
| 5214 | * Based on the resource size and count, correct the base and max |
| 5215 | * resource values. |
| 5216 | */ |
| 5217 | length = sizeof(struct lpfc_rsrc_blks); |
| 5218 | switch (type) { |
| 5219 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5220 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5221 | sizeof(unsigned long), |
| 5222 | GFP_KERNEL); |
| 5223 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5224 | rc = -ENOMEM; |
| 5225 | goto err_exit; |
| 5226 | } |
| 5227 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5228 | sizeof(uint16_t), |
| 5229 | GFP_KERNEL); |
| 5230 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5231 | kfree(phba->sli4_hba.rpi_bmask); |
| 5232 | rc = -ENOMEM; |
| 5233 | goto err_exit; |
| 5234 | } |
| 5235 | |
| 5236 | /* |
| 5237 | * The next_rpi was initialized with the maximum available |
| 5238 | * count but the port may allocate a smaller number. Catch |
| 5239 | * that case and update the next_rpi. |
| 5240 | */ |
| 5241 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5242 | |
| 5243 | /* Initialize local ptrs for common extent processing later. */ |
| 5244 | bmask = phba->sli4_hba.rpi_bmask; |
| 5245 | ids = phba->sli4_hba.rpi_ids; |
| 5246 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5247 | break; |
| 5248 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5249 | phba->vpi_bmask = kzalloc(longs * |
| 5250 | sizeof(unsigned long), |
| 5251 | GFP_KERNEL); |
| 5252 | if (unlikely(!phba->vpi_bmask)) { |
| 5253 | rc = -ENOMEM; |
| 5254 | goto err_exit; |
| 5255 | } |
| 5256 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5257 | sizeof(uint16_t), |
| 5258 | GFP_KERNEL); |
| 5259 | if (unlikely(!phba->vpi_ids)) { |
| 5260 | kfree(phba->vpi_bmask); |
| 5261 | rc = -ENOMEM; |
| 5262 | goto err_exit; |
| 5263 | } |
| 5264 | |
| 5265 | /* Initialize local ptrs for common extent processing later. */ |
| 5266 | bmask = phba->vpi_bmask; |
| 5267 | ids = phba->vpi_ids; |
| 5268 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5269 | break; |
| 5270 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5271 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5272 | sizeof(unsigned long), |
| 5273 | GFP_KERNEL); |
| 5274 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5275 | rc = -ENOMEM; |
| 5276 | goto err_exit; |
| 5277 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5278 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5279 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5280 | sizeof(uint16_t), |
| 5281 | GFP_KERNEL); |
| 5282 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5283 | kfree(phba->sli4_hba.xri_bmask); |
| 5284 | rc = -ENOMEM; |
| 5285 | goto err_exit; |
| 5286 | } |
| 5287 | |
| 5288 | /* Initialize local ptrs for common extent processing later. */ |
| 5289 | bmask = phba->sli4_hba.xri_bmask; |
| 5290 | ids = phba->sli4_hba.xri_ids; |
| 5291 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5292 | break; |
| 5293 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5294 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5295 | sizeof(unsigned long), |
| 5296 | GFP_KERNEL); |
| 5297 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5298 | rc = -ENOMEM; |
| 5299 | goto err_exit; |
| 5300 | } |
| 5301 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5302 | sizeof(uint16_t), |
| 5303 | GFP_KERNEL); |
| 5304 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5305 | kfree(phba->sli4_hba.vfi_bmask); |
| 5306 | rc = -ENOMEM; |
| 5307 | goto err_exit; |
| 5308 | } |
| 5309 | |
| 5310 | /* Initialize local ptrs for common extent processing later. */ |
| 5311 | bmask = phba->sli4_hba.vfi_bmask; |
| 5312 | ids = phba->sli4_hba.vfi_ids; |
| 5313 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5314 | break; |
| 5315 | default: |
| 5316 | /* Unsupported Opcode. Fail call. */ |
| 5317 | id_array = NULL; |
| 5318 | bmask = NULL; |
| 5319 | ids = NULL; |
| 5320 | ext_blk_list = NULL; |
| 5321 | goto err_exit; |
| 5322 | } |
| 5323 | |
| 5324 | /* |
| 5325 | * Complete initializing the extent configuration with the |
| 5326 | * allocated ids assigned to this function. The bitmask serves |
| 5327 | * as an index into the array and manages the available ids. The |
| 5328 | * array just stores the ids communicated to the port via the wqes. |
| 5329 | */ |
| 5330 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5331 | if ((i % 2) == 0) |
| 5332 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5333 | &id_array[k]); |
| 5334 | else |
| 5335 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5336 | &id_array[k]); |
| 5337 | |
| 5338 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5339 | if (unlikely(!rsrc_blks)) { |
| 5340 | rc = -ENOMEM; |
| 5341 | kfree(bmask); |
| 5342 | kfree(ids); |
| 5343 | goto err_exit; |
| 5344 | } |
| 5345 | rsrc_blks->rsrc_start = rsrc_id; |
| 5346 | rsrc_blks->rsrc_size = rsrc_size; |
| 5347 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5348 | rsrc_start = rsrc_id; |
| 5349 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5350 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5351 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5352 | |
| 5353 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5354 | ids[j] = rsrc_id; |
| 5355 | rsrc_id++; |
| 5356 | j++; |
| 5357 | } |
| 5358 | /* Entire word processed. Get next word.*/ |
| 5359 | if ((i % 2) == 1) |
| 5360 | k++; |
| 5361 | } |
| 5362 | err_exit: |
| 5363 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5364 | return rc; |
| 5365 | } |
| 5366 | |
| 5367 | /** |
| 5368 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5369 | * @phba: Pointer to HBA context object. |
| 5370 | * @type: the extent's type. |
| 5371 | * |
| 5372 | * This function deallocates all extents of a particular resource type. |
| 5373 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5374 | * is the caller's responsibility to release all kernel memory resources. |
| 5375 | **/ |
| 5376 | static int |
| 5377 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5378 | { |
| 5379 | int rc; |
| 5380 | uint32_t length, mbox_tmo = 0; |
| 5381 | LPFC_MBOXQ_t *mbox; |
| 5382 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5383 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5384 | |
| 5385 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5386 | if (!mbox) |
| 5387 | return -ENOMEM; |
| 5388 | |
| 5389 | /* |
| 5390 | * This function sends an embedded mailbox because it only sends the |
| 5391 | * the resource type. All extents of this type are released by the |
| 5392 | * port. |
| 5393 | */ |
| 5394 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5395 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5396 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5397 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5398 | length, LPFC_SLI4_MBX_EMBED); |
| 5399 | |
| 5400 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5401 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5402 | LPFC_SLI4_MBX_EMBED); |
| 5403 | if (unlikely(rc)) { |
| 5404 | rc = -EIO; |
| 5405 | goto out_free_mbox; |
| 5406 | } |
| 5407 | if (!phba->sli4_hba.intr_enable) |
| 5408 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5409 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5410 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5411 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5412 | } |
| 5413 | if (unlikely(rc)) { |
| 5414 | rc = -EIO; |
| 5415 | goto out_free_mbox; |
| 5416 | } |
| 5417 | |
| 5418 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5419 | if (bf_get(lpfc_mbox_hdr_status, |
| 5420 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5421 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5422 | "2919 Failed to release resource extents " |
| 5423 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5424 | "Resource memory not released.\n", |
| 5425 | type, |
| 5426 | bf_get(lpfc_mbox_hdr_status, |
| 5427 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5428 | bf_get(lpfc_mbox_hdr_add_status, |
| 5429 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5430 | rc = -EIO; |
| 5431 | goto out_free_mbox; |
| 5432 | } |
| 5433 | |
| 5434 | /* Release kernel memory resources for the specific type. */ |
| 5435 | switch (type) { |
| 5436 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5437 | kfree(phba->vpi_bmask); |
| 5438 | kfree(phba->vpi_ids); |
| 5439 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5440 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5441 | &phba->lpfc_vpi_blk_list, list) { |
| 5442 | list_del_init(&rsrc_blk->list); |
| 5443 | kfree(rsrc_blk); |
| 5444 | } |
| 5445 | break; |
| 5446 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5447 | kfree(phba->sli4_hba.xri_bmask); |
| 5448 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5449 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5450 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5451 | list_del_init(&rsrc_blk->list); |
| 5452 | kfree(rsrc_blk); |
| 5453 | } |
| 5454 | break; |
| 5455 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5456 | kfree(phba->sli4_hba.vfi_bmask); |
| 5457 | kfree(phba->sli4_hba.vfi_ids); |
| 5458 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5459 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5460 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5461 | list_del_init(&rsrc_blk->list); |
| 5462 | kfree(rsrc_blk); |
| 5463 | } |
| 5464 | break; |
| 5465 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5466 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5467 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5468 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5469 | list_del_init(&rsrc_blk->list); |
| 5470 | kfree(rsrc_blk); |
| 5471 | } |
| 5472 | break; |
| 5473 | default: |
| 5474 | break; |
| 5475 | } |
| 5476 | |
| 5477 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5478 | |
| 5479 | out_free_mbox: |
| 5480 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5481 | return rc; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
| 5485 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5486 | * @phba: Pointer to HBA context object. |
| 5487 | * |
| 5488 | * This function allocates all SLI4 resource identifiers. |
| 5489 | **/ |
| 5490 | int |
| 5491 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5492 | { |
| 5493 | int i, rc, error = 0; |
| 5494 | uint16_t count, base; |
| 5495 | unsigned long longs; |
| 5496 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5497 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5498 | 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] | 5499 | if (phba->sli4_hba.extents_in_use) { |
| 5500 | /* |
| 5501 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5502 | * resource extent count must be read and allocated before |
| 5503 | * provisioning the resource id arrays. |
| 5504 | */ |
| 5505 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5506 | LPFC_IDX_RSRC_RDY) { |
| 5507 | /* |
| 5508 | * Extent-based resources are set - the driver could |
| 5509 | * be in a port reset. Figure out if any corrective |
| 5510 | * actions need to be taken. |
| 5511 | */ |
| 5512 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5513 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5514 | if (rc != 0) |
| 5515 | error++; |
| 5516 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5517 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5518 | if (rc != 0) |
| 5519 | error++; |
| 5520 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5521 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5522 | if (rc != 0) |
| 5523 | error++; |
| 5524 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5525 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5526 | if (rc != 0) |
| 5527 | error++; |
| 5528 | |
| 5529 | /* |
| 5530 | * It's possible that the number of resources |
| 5531 | * provided to this port instance changed between |
| 5532 | * resets. Detect this condition and reallocate |
| 5533 | * resources. Otherwise, there is no action. |
| 5534 | */ |
| 5535 | if (error) { |
| 5536 | lpfc_printf_log(phba, KERN_INFO, |
| 5537 | LOG_MBOX | LOG_INIT, |
| 5538 | "2931 Detected extent resource " |
| 5539 | "change. Reallocating all " |
| 5540 | "extents.\n"); |
| 5541 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5542 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5543 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5544 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5545 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5546 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5547 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5548 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5549 | } else |
| 5550 | return 0; |
| 5551 | } |
| 5552 | |
| 5553 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5554 | if (unlikely(rc)) |
| 5555 | goto err_exit; |
| 5556 | |
| 5557 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5558 | if (unlikely(rc)) |
| 5559 | goto err_exit; |
| 5560 | |
| 5561 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5562 | if (unlikely(rc)) |
| 5563 | goto err_exit; |
| 5564 | |
| 5565 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5566 | if (unlikely(rc)) |
| 5567 | goto err_exit; |
| 5568 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5569 | LPFC_IDX_RSRC_RDY); |
| 5570 | return rc; |
| 5571 | } else { |
| 5572 | /* |
| 5573 | * The port does not support resource extents. The XRI, VPI, |
| 5574 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5575 | * Just allocate the bitmasks and provision the resource id |
| 5576 | * arrays. If a port reset is active, the resources don't |
| 5577 | * need any action - just exit. |
| 5578 | */ |
| 5579 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5580 | LPFC_IDX_RSRC_RDY) { |
| 5581 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5582 | lpfc_sli4_remove_rpis(phba); |
| 5583 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5584 | /* RPIs. */ |
| 5585 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
| 5586 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5587 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5588 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5589 | sizeof(unsigned long), |
| 5590 | GFP_KERNEL); |
| 5591 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5592 | rc = -ENOMEM; |
| 5593 | goto err_exit; |
| 5594 | } |
| 5595 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5596 | sizeof(uint16_t), |
| 5597 | GFP_KERNEL); |
| 5598 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5599 | rc = -ENOMEM; |
| 5600 | goto free_rpi_bmask; |
| 5601 | } |
| 5602 | |
| 5603 | for (i = 0; i < count; i++) |
| 5604 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5605 | |
| 5606 | /* VPIs. */ |
| 5607 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
| 5608 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5609 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5610 | phba->vpi_bmask = kzalloc(longs * |
| 5611 | sizeof(unsigned long), |
| 5612 | GFP_KERNEL); |
| 5613 | if (unlikely(!phba->vpi_bmask)) { |
| 5614 | rc = -ENOMEM; |
| 5615 | goto free_rpi_ids; |
| 5616 | } |
| 5617 | phba->vpi_ids = kzalloc(count * |
| 5618 | sizeof(uint16_t), |
| 5619 | GFP_KERNEL); |
| 5620 | if (unlikely(!phba->vpi_ids)) { |
| 5621 | rc = -ENOMEM; |
| 5622 | goto free_vpi_bmask; |
| 5623 | } |
| 5624 | |
| 5625 | for (i = 0; i < count; i++) |
| 5626 | phba->vpi_ids[i] = base + i; |
| 5627 | |
| 5628 | /* XRIs. */ |
| 5629 | count = phba->sli4_hba.max_cfg_param.max_xri; |
| 5630 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5631 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5632 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5633 | sizeof(unsigned long), |
| 5634 | GFP_KERNEL); |
| 5635 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5636 | rc = -ENOMEM; |
| 5637 | goto free_vpi_ids; |
| 5638 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5639 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5640 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5641 | sizeof(uint16_t), |
| 5642 | GFP_KERNEL); |
| 5643 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5644 | rc = -ENOMEM; |
| 5645 | goto free_xri_bmask; |
| 5646 | } |
| 5647 | |
| 5648 | for (i = 0; i < count; i++) |
| 5649 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5650 | |
| 5651 | /* VFIs. */ |
| 5652 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
| 5653 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5654 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5655 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5656 | sizeof(unsigned long), |
| 5657 | GFP_KERNEL); |
| 5658 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5659 | rc = -ENOMEM; |
| 5660 | goto free_xri_ids; |
| 5661 | } |
| 5662 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5663 | sizeof(uint16_t), |
| 5664 | GFP_KERNEL); |
| 5665 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5666 | rc = -ENOMEM; |
| 5667 | goto free_vfi_bmask; |
| 5668 | } |
| 5669 | |
| 5670 | for (i = 0; i < count; i++) |
| 5671 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5672 | |
| 5673 | /* |
| 5674 | * Mark all resources ready. An HBA reset doesn't need |
| 5675 | * to reset the initialization. |
| 5676 | */ |
| 5677 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5678 | LPFC_IDX_RSRC_RDY); |
| 5679 | return 0; |
| 5680 | } |
| 5681 | |
| 5682 | free_vfi_bmask: |
| 5683 | kfree(phba->sli4_hba.vfi_bmask); |
| 5684 | free_xri_ids: |
| 5685 | kfree(phba->sli4_hba.xri_ids); |
| 5686 | free_xri_bmask: |
| 5687 | kfree(phba->sli4_hba.xri_bmask); |
| 5688 | free_vpi_ids: |
| 5689 | kfree(phba->vpi_ids); |
| 5690 | free_vpi_bmask: |
| 5691 | kfree(phba->vpi_bmask); |
| 5692 | free_rpi_ids: |
| 5693 | kfree(phba->sli4_hba.rpi_ids); |
| 5694 | free_rpi_bmask: |
| 5695 | kfree(phba->sli4_hba.rpi_bmask); |
| 5696 | err_exit: |
| 5697 | return rc; |
| 5698 | } |
| 5699 | |
| 5700 | /** |
| 5701 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5702 | * @phba: Pointer to HBA context object. |
| 5703 | * |
| 5704 | * This function allocates the number of elements for the specified |
| 5705 | * resource type. |
| 5706 | **/ |
| 5707 | int |
| 5708 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5709 | { |
| 5710 | if (phba->sli4_hba.extents_in_use) { |
| 5711 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5712 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5713 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5714 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5715 | } else { |
| 5716 | kfree(phba->vpi_bmask); |
| 5717 | kfree(phba->vpi_ids); |
| 5718 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5719 | kfree(phba->sli4_hba.xri_bmask); |
| 5720 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5721 | kfree(phba->sli4_hba.vfi_bmask); |
| 5722 | kfree(phba->sli4_hba.vfi_ids); |
| 5723 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5724 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5725 | } |
| 5726 | |
| 5727 | return 0; |
| 5728 | } |
| 5729 | |
| 5730 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5731 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5732 | * @phba: Pointer to HBA context object. |
| 5733 | * @type: The resource extent type. |
| 5734 | * @extnt_count: buffer to hold port extent count response |
| 5735 | * @extnt_size: buffer to hold port extent size response. |
| 5736 | * |
| 5737 | * This function calls the port to read the host allocated extents |
| 5738 | * for a particular type. |
| 5739 | **/ |
| 5740 | int |
| 5741 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5742 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5743 | { |
| 5744 | bool emb; |
| 5745 | int rc = 0; |
| 5746 | uint16_t curr_blks = 0; |
| 5747 | uint32_t req_len, emb_len; |
| 5748 | uint32_t alloc_len, mbox_tmo; |
| 5749 | struct list_head *blk_list_head; |
| 5750 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5751 | LPFC_MBOXQ_t *mbox; |
| 5752 | void *virtaddr = NULL; |
| 5753 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5754 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5755 | union lpfc_sli4_cfg_shdr *shdr; |
| 5756 | |
| 5757 | switch (type) { |
| 5758 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5759 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5760 | break; |
| 5761 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5762 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5763 | break; |
| 5764 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5765 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5766 | break; |
| 5767 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5768 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5769 | break; |
| 5770 | default: |
| 5771 | return -EIO; |
| 5772 | } |
| 5773 | |
| 5774 | /* Count the number of extents currently allocatd for this type. */ |
| 5775 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5776 | if (curr_blks == 0) { |
| 5777 | /* |
| 5778 | * The GET_ALLOCATED mailbox does not return the size, |
| 5779 | * just the count. The size should be just the size |
| 5780 | * stored in the current allocated block and all sizes |
| 5781 | * for an extent type are the same so set the return |
| 5782 | * value now. |
| 5783 | */ |
| 5784 | *extnt_size = rsrc_blk->rsrc_size; |
| 5785 | } |
| 5786 | curr_blks++; |
| 5787 | } |
| 5788 | |
| 5789 | /* Calculate the total requested length of the dma memory. */ |
| 5790 | req_len = curr_blks * sizeof(uint16_t); |
| 5791 | |
| 5792 | /* |
| 5793 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5794 | * accounts for extents-specific word. |
| 5795 | */ |
| 5796 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5797 | sizeof(uint32_t); |
| 5798 | |
| 5799 | /* |
| 5800 | * Presume the allocation and response will fit into an embedded |
| 5801 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5802 | */ |
| 5803 | emb = LPFC_SLI4_MBX_EMBED; |
| 5804 | req_len = emb_len; |
| 5805 | if (req_len > emb_len) { |
| 5806 | req_len = curr_blks * sizeof(uint16_t) + |
| 5807 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5808 | sizeof(uint32_t); |
| 5809 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5810 | } |
| 5811 | |
| 5812 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5813 | if (!mbox) |
| 5814 | return -ENOMEM; |
| 5815 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5816 | |
| 5817 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5818 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5819 | req_len, emb); |
| 5820 | if (alloc_len < req_len) { |
| 5821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5822 | "2983 Allocated DMA memory size (x%x) is " |
| 5823 | "less than the requested DMA memory " |
| 5824 | "size (x%x)\n", alloc_len, req_len); |
| 5825 | rc = -ENOMEM; |
| 5826 | goto err_exit; |
| 5827 | } |
| 5828 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5829 | if (unlikely(rc)) { |
| 5830 | rc = -EIO; |
| 5831 | goto err_exit; |
| 5832 | } |
| 5833 | |
| 5834 | if (!phba->sli4_hba.intr_enable) |
| 5835 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5836 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5837 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5838 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5839 | } |
| 5840 | |
| 5841 | if (unlikely(rc)) { |
| 5842 | rc = -EIO; |
| 5843 | goto err_exit; |
| 5844 | } |
| 5845 | |
| 5846 | /* |
| 5847 | * Figure out where the response is located. Then get local pointers |
| 5848 | * to the response data. The port does not guarantee to respond to |
| 5849 | * all extents counts request so update the local variable with the |
| 5850 | * allocated count from the port. |
| 5851 | */ |
| 5852 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5853 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5854 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5855 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5856 | } else { |
| 5857 | virtaddr = mbox->sge_array->addr[0]; |
| 5858 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5859 | shdr = &n_rsrc->cfg_shdr; |
| 5860 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5861 | } |
| 5862 | |
| 5863 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5864 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5865 | "2984 Failed to read allocated resources " |
| 5866 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5867 | type, |
| 5868 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5869 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5870 | rc = -EIO; |
| 5871 | goto err_exit; |
| 5872 | } |
| 5873 | err_exit: |
| 5874 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5875 | return rc; |
| 5876 | } |
| 5877 | |
| 5878 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5879 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5880 | * @phba: pointer to lpfc hba data structure. |
| 5881 | * |
| 5882 | * This routine walks the list of els buffers that have been allocated and |
| 5883 | * repost them to the port by using SGL block post. This is needed after a |
| 5884 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5885 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5886 | * SGL block post mailbox commands to post them to the port. For single els |
| 5887 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5888 | * mailbox command for posting. |
| 5889 | * |
| 5890 | * Returns: 0 = success, non-zero failure. |
| 5891 | **/ |
| 5892 | static int |
| 5893 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5894 | { |
| 5895 | struct lpfc_sglq *sglq_entry = NULL; |
| 5896 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5897 | struct lpfc_sglq *sglq_entry_first = NULL; |
| 5898 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; |
| 5899 | int last_xritag = NO_XRI; |
| 5900 | LIST_HEAD(prep_sgl_list); |
| 5901 | LIST_HEAD(blck_sgl_list); |
| 5902 | LIST_HEAD(allc_sgl_list); |
| 5903 | LIST_HEAD(post_sgl_list); |
| 5904 | LIST_HEAD(free_sgl_list); |
| 5905 | |
| 5906 | spin_lock(&phba->hbalock); |
| 5907 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
| 5908 | spin_unlock(&phba->hbalock); |
| 5909 | |
| 5910 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 5911 | &allc_sgl_list, list) { |
| 5912 | list_del_init(&sglq_entry->list); |
| 5913 | block_cnt++; |
| 5914 | if ((last_xritag != NO_XRI) && |
| 5915 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 5916 | /* a hole in xri block, form a sgl posting block */ |
| 5917 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 5918 | post_cnt = block_cnt - 1; |
| 5919 | /* prepare list for next posting block */ |
| 5920 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5921 | block_cnt = 1; |
| 5922 | } else { |
| 5923 | /* prepare list for next posting block */ |
| 5924 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 5925 | /* enough sgls for non-embed sgl mbox command */ |
| 5926 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 5927 | list_splice_init(&prep_sgl_list, |
| 5928 | &blck_sgl_list); |
| 5929 | post_cnt = block_cnt; |
| 5930 | block_cnt = 0; |
| 5931 | } |
| 5932 | } |
| 5933 | num_posted++; |
| 5934 | |
| 5935 | /* keep track of last sgl's xritag */ |
| 5936 | last_xritag = sglq_entry->sli4_xritag; |
| 5937 | |
| 5938 | /* end of repost sgl list condition for els buffers */ |
| 5939 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 5940 | if (post_cnt == 0) { |
| 5941 | list_splice_init(&prep_sgl_list, |
| 5942 | &blck_sgl_list); |
| 5943 | post_cnt = block_cnt; |
| 5944 | } else if (block_cnt == 1) { |
| 5945 | status = lpfc_sli4_post_sgl(phba, |
| 5946 | sglq_entry->phys, 0, |
| 5947 | sglq_entry->sli4_xritag); |
| 5948 | if (!status) { |
| 5949 | /* successful, put sgl to posted list */ |
| 5950 | list_add_tail(&sglq_entry->list, |
| 5951 | &post_sgl_list); |
| 5952 | } else { |
| 5953 | /* Failure, put sgl to free list */ |
| 5954 | lpfc_printf_log(phba, KERN_WARNING, |
| 5955 | LOG_SLI, |
| 5956 | "3159 Failed to post els " |
| 5957 | "sgl, xritag:x%x\n", |
| 5958 | sglq_entry->sli4_xritag); |
| 5959 | list_add_tail(&sglq_entry->list, |
| 5960 | &free_sgl_list); |
| 5961 | spin_lock_irq(&phba->hbalock); |
| 5962 | phba->sli4_hba.els_xri_cnt--; |
| 5963 | spin_unlock_irq(&phba->hbalock); |
| 5964 | } |
| 5965 | } |
| 5966 | } |
| 5967 | |
| 5968 | /* continue until a nembed page worth of sgls */ |
| 5969 | if (post_cnt == 0) |
| 5970 | continue; |
| 5971 | |
| 5972 | /* post the els buffer list sgls as a block */ |
| 5973 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 5974 | post_cnt); |
| 5975 | |
| 5976 | if (!status) { |
| 5977 | /* success, put sgl list to posted sgl list */ |
| 5978 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 5979 | } else { |
| 5980 | /* Failure, put sgl list to free sgl list */ |
| 5981 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 5982 | struct lpfc_sglq, |
| 5983 | list); |
| 5984 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5985 | "3160 Failed to post els sgl-list, " |
| 5986 | "xritag:x%x-x%x\n", |
| 5987 | sglq_entry_first->sli4_xritag, |
| 5988 | (sglq_entry_first->sli4_xritag + |
| 5989 | post_cnt - 1)); |
| 5990 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
| 5991 | spin_lock_irq(&phba->hbalock); |
| 5992 | phba->sli4_hba.els_xri_cnt -= post_cnt; |
| 5993 | spin_unlock_irq(&phba->hbalock); |
| 5994 | } |
| 5995 | |
| 5996 | /* don't reset xirtag due to hole in xri block */ |
| 5997 | if (block_cnt == 0) |
| 5998 | last_xritag = NO_XRI; |
| 5999 | |
| 6000 | /* reset els sgl post count for next round of posting */ |
| 6001 | post_cnt = 0; |
| 6002 | } |
| 6003 | |
| 6004 | /* free the els sgls failed to post */ |
| 6005 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6006 | |
| 6007 | /* push els sgls posted to the availble list */ |
| 6008 | if (!list_empty(&post_sgl_list)) { |
| 6009 | spin_lock(&phba->hbalock); |
| 6010 | list_splice_init(&post_sgl_list, |
| 6011 | &phba->sli4_hba.lpfc_sgl_list); |
| 6012 | spin_unlock(&phba->hbalock); |
| 6013 | } else { |
| 6014 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6015 | "3161 Failure to post els sgl to port.\n"); |
| 6016 | return -EIO; |
| 6017 | } |
| 6018 | return 0; |
| 6019 | } |
| 6020 | |
| 6021 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6022 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6023 | * @phba: Pointer to HBA context object. |
| 6024 | * |
| 6025 | * This function is the main SLI4 device intialization PCI function. This |
| 6026 | * function is called by the HBA intialization code, HBA reset code and |
| 6027 | * HBA error attention handler code. Caller is not required to hold any |
| 6028 | * locks. |
| 6029 | **/ |
| 6030 | int |
| 6031 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6032 | { |
| 6033 | int rc; |
| 6034 | LPFC_MBOXQ_t *mboxq; |
| 6035 | struct lpfc_mqe *mqe; |
| 6036 | uint8_t *vpd; |
| 6037 | uint32_t vpd_size; |
| 6038 | uint32_t ftr_rsp = 0; |
| 6039 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6040 | struct lpfc_vport *vport = phba->pport; |
| 6041 | struct lpfc_dmabuf *mp; |
| 6042 | |
| 6043 | /* Perform a PCI function reset to start from clean */ |
| 6044 | rc = lpfc_pci_function_reset(phba); |
| 6045 | if (unlikely(rc)) |
| 6046 | return -ENODEV; |
| 6047 | |
| 6048 | /* Check the HBA Host Status Register for readyness */ |
| 6049 | rc = lpfc_sli4_post_status_check(phba); |
| 6050 | if (unlikely(rc)) |
| 6051 | return -ENODEV; |
| 6052 | else { |
| 6053 | spin_lock_irq(&phba->hbalock); |
| 6054 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6055 | spin_unlock_irq(&phba->hbalock); |
| 6056 | } |
| 6057 | |
| 6058 | /* |
| 6059 | * Allocate a single mailbox container for initializing the |
| 6060 | * port. |
| 6061 | */ |
| 6062 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6063 | if (!mboxq) |
| 6064 | return -ENOMEM; |
| 6065 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6066 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6067 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6068 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6069 | if (!vpd) { |
| 6070 | rc = -ENOMEM; |
| 6071 | goto out_free_mbox; |
| 6072 | } |
| 6073 | |
| 6074 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6075 | if (unlikely(rc)) { |
| 6076 | kfree(vpd); |
| 6077 | goto out_free_mbox; |
| 6078 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6079 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6080 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6081 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6082 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6083 | else |
| 6084 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6085 | |
| 6086 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6087 | LPFC_DCBX_CEE_MODE) |
| 6088 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6089 | else |
| 6090 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6091 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6092 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6093 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6094 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6095 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6096 | "0376 READ_REV Error. SLI Level %d " |
| 6097 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6098 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6099 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6100 | kfree(vpd); |
| 6101 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6102 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6103 | |
| 6104 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6105 | * Continue initialization with default values even if driver failed |
| 6106 | * to read FCoE param config regions, only read parameters if the |
| 6107 | * board is FCoE |
| 6108 | */ |
| 6109 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6110 | lpfc_sli4_read_fcoe_params(phba)) |
| 6111 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6112 | "2570 Failed to read FCoE parameters\n"); |
| 6113 | |
| 6114 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6115 | * Retrieve sli4 device physical port name, failure of doing it |
| 6116 | * is considered as non-fatal. |
| 6117 | */ |
| 6118 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6119 | if (!rc) |
| 6120 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6121 | "3080 Successful retrieving SLI4 device " |
| 6122 | "physical port name: %s.\n", phba->Port); |
| 6123 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6124 | /* |
| 6125 | * Evaluate the read rev and vpd data. Populate the driver |
| 6126 | * state with the results. If this routine fails, the failure |
| 6127 | * is not fatal as the driver will use generic values. |
| 6128 | */ |
| 6129 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6130 | if (unlikely(!rc)) { |
| 6131 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6132 | "0377 Error %d parsing vpd. " |
| 6133 | "Using defaults.\n", rc); |
| 6134 | rc = 0; |
| 6135 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6136 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6137 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6138 | /* Save information as VPD data */ |
| 6139 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6140 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6141 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6142 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6143 | &mqe->un.read_rev); |
| 6144 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6145 | &mqe->un.read_rev); |
| 6146 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6147 | &mqe->un.read_rev); |
| 6148 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6149 | &mqe->un.read_rev); |
| 6150 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6151 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6152 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6153 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6154 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6155 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6156 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6157 | "(%d):0380 READ_REV Status x%x " |
| 6158 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6159 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6160 | bf_get(lpfc_mqe_status, mqe), |
| 6161 | phba->vpd.rev.opFwName, |
| 6162 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6163 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6164 | |
| 6165 | /* |
| 6166 | * Discover the port's supported feature set and match it against the |
| 6167 | * hosts requests. |
| 6168 | */ |
| 6169 | lpfc_request_features(phba, mboxq); |
| 6170 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6171 | if (unlikely(rc)) { |
| 6172 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6173 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | /* |
| 6177 | * The port must support FCP initiator mode as this is the |
| 6178 | * only mode running in the host. |
| 6179 | */ |
| 6180 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6181 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6182 | "0378 No support for fcpi mode.\n"); |
| 6183 | ftr_rsp++; |
| 6184 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6185 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6186 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6187 | else |
| 6188 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6189 | /* |
| 6190 | * If the port cannot support the host's requested features |
| 6191 | * then turn off the global config parameters to disable the |
| 6192 | * feature in the driver. This is not a fatal error. |
| 6193 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6194 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6195 | if (phba->cfg_enable_bg) { |
| 6196 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6197 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6198 | else |
| 6199 | ftr_rsp++; |
| 6200 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6201 | |
| 6202 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6203 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6204 | ftr_rsp++; |
| 6205 | |
| 6206 | if (ftr_rsp) { |
| 6207 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6208 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6209 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6210 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6211 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6212 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6213 | phba->cfg_enable_bg = 0; |
| 6214 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6215 | phba->cfg_enable_npiv = 0; |
| 6216 | } |
| 6217 | |
| 6218 | /* These SLI3 features are assumed in SLI4 */ |
| 6219 | spin_lock_irq(&phba->hbalock); |
| 6220 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6221 | spin_unlock_irq(&phba->hbalock); |
| 6222 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6223 | /* |
| 6224 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6225 | * calls depends on these resources to complete port setup. |
| 6226 | */ |
| 6227 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6228 | if (rc) { |
| 6229 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6230 | "2920 Failed to alloc Resource IDs " |
| 6231 | "rc = x%x\n", rc); |
| 6232 | goto out_free_mbox; |
| 6233 | } |
| 6234 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6235 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6236 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6237 | if (rc) { |
| 6238 | phba->link_state = LPFC_HBA_ERROR; |
| 6239 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6240 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6241 | } |
| 6242 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6243 | mboxq->vport = vport; |
| 6244 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6245 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6246 | if (rc == MBX_SUCCESS) { |
| 6247 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6248 | rc = 0; |
| 6249 | } |
| 6250 | |
| 6251 | /* |
| 6252 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6253 | * it to the mbuf pool. |
| 6254 | */ |
| 6255 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6256 | kfree(mp); |
| 6257 | mboxq->context1 = NULL; |
| 6258 | if (unlikely(rc)) { |
| 6259 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6260 | "0382 READ_SPARAM command failed " |
| 6261 | "status %d, mbxStatus x%x\n", |
| 6262 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6263 | phba->link_state = LPFC_HBA_ERROR; |
| 6264 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6265 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6266 | } |
| 6267 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6268 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6269 | |
| 6270 | /* Update the fc_host data structures with new wwn. */ |
| 6271 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6272 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6273 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6274 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6275 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6276 | if (unlikely(rc)) { |
| 6277 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6278 | "1400 Failed to update xri-sgl size and " |
| 6279 | "mapping: %d\n", rc); |
| 6280 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6281 | } |
| 6282 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6283 | /* register the els sgl pool to the port */ |
| 6284 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6285 | if (unlikely(rc)) { |
| 6286 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6287 | "0582 Error %d during els sgl post " |
| 6288 | "operation\n", rc); |
| 6289 | rc = -ENODEV; |
| 6290 | goto out_free_mbox; |
| 6291 | } |
| 6292 | |
| 6293 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6294 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6295 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6296 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6297 | "0383 Error %d during scsi sgl post " |
| 6298 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6299 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6300 | /* A pci function reset will repost them */ |
| 6301 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6302 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | /* Post the rpi header region to the device. */ |
| 6306 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6307 | if (unlikely(rc)) { |
| 6308 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6309 | "0393 Error %d during rpi post operation\n", |
| 6310 | rc); |
| 6311 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6312 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6313 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6314 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6315 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6316 | /* Create all the SLI4 queues */ |
| 6317 | rc = lpfc_sli4_queue_create(phba); |
| 6318 | if (rc) { |
| 6319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6320 | "3089 Failed to allocate queues\n"); |
| 6321 | rc = -ENODEV; |
| 6322 | goto out_stop_timers; |
| 6323 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6324 | /* Set up all the queues to the device */ |
| 6325 | rc = lpfc_sli4_queue_setup(phba); |
| 6326 | if (unlikely(rc)) { |
| 6327 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6328 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6329 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | /* Arm the CQs and then EQs on device */ |
| 6333 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6334 | |
| 6335 | /* Indicate device interrupt mode */ |
| 6336 | phba->sli4_hba.intr_enable = 1; |
| 6337 | |
| 6338 | /* Allow asynchronous mailbox command to go through */ |
| 6339 | spin_lock_irq(&phba->hbalock); |
| 6340 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6341 | spin_unlock_irq(&phba->hbalock); |
| 6342 | |
| 6343 | /* Post receive buffers to the device */ |
| 6344 | lpfc_sli4_rb_setup(phba); |
| 6345 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6346 | /* Reset HBA FCF states after HBA reset */ |
| 6347 | phba->fcf.fcf_flag = 0; |
| 6348 | phba->fcf.current_rec.flag = 0; |
| 6349 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6350 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6351 | mod_timer(&vport->els_tmofunc, |
| 6352 | jiffies + HZ * (phba->fc_ratov * 2)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6353 | |
| 6354 | /* Start heart beat timer */ |
| 6355 | mod_timer(&phba->hb_tmofunc, |
| 6356 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 6357 | phba->hb_outstanding = 0; |
| 6358 | phba->last_completion_time = jiffies; |
| 6359 | |
| 6360 | /* Start error attention (ERATT) polling timer */ |
| 6361 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| 6362 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6363 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6364 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6365 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6366 | if (!rc) { |
| 6367 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6368 | "2829 This device supports " |
| 6369 | "Advanced Error Reporting (AER)\n"); |
| 6370 | spin_lock_irq(&phba->hbalock); |
| 6371 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6372 | spin_unlock_irq(&phba->hbalock); |
| 6373 | } else { |
| 6374 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6375 | "2830 This device does not support " |
| 6376 | "Advanced Error Reporting (AER)\n"); |
| 6377 | phba->cfg_aer_support = 0; |
| 6378 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6379 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6380 | } |
| 6381 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6382 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6383 | /* |
| 6384 | * The FC Port needs to register FCFI (index 0) |
| 6385 | */ |
| 6386 | lpfc_reg_fcfi(phba, mboxq); |
| 6387 | mboxq->vport = phba->pport; |
| 6388 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6389 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6390 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6391 | rc = 0; |
| 6392 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6393 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6394 | |
| 6395 | /* Check if the port is configured to be disabled */ |
| 6396 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6397 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6398 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6399 | /* |
| 6400 | * The port is ready, set the host's link state to LINK_DOWN |
| 6401 | * in preparation for link interrupts. |
| 6402 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6403 | spin_lock_irq(&phba->hbalock); |
| 6404 | phba->link_state = LPFC_LINK_DOWN; |
| 6405 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6406 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6407 | (phba->hba_flag & LINK_DISABLED)) { |
| 6408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6409 | "3103 Adapter Link is disabled.\n"); |
| 6410 | lpfc_down_link(phba, mboxq); |
| 6411 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6412 | if (rc != MBX_SUCCESS) { |
| 6413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6414 | "3104 Adapter failed to issue " |
| 6415 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6416 | goto out_unset_queue; |
| 6417 | } |
| 6418 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6419 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6420 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6421 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6422 | if (rc) |
| 6423 | goto out_unset_queue; |
| 6424 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6425 | } |
| 6426 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6427 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6428 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6429 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6430 | lpfc_sli4_queue_unset(phba); |
| 6431 | out_destroy_queue: |
| 6432 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6433 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6434 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6435 | out_free_mbox: |
| 6436 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6437 | return rc; |
| 6438 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6439 | |
| 6440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6441 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6442 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6443 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6444 | * This is the callback function for mailbox timer. The mailbox |
| 6445 | * timer is armed when a new mailbox command is issued and the timer |
| 6446 | * is deleted when the mailbox complete. The function is called by |
| 6447 | * the kernel timer code when a mailbox does not complete within |
| 6448 | * expected time. This function wakes up the worker thread to |
| 6449 | * process the mailbox timeout and returns. All the processing is |
| 6450 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6451 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6452 | void |
| 6453 | lpfc_mbox_timeout(unsigned long ptr) |
| 6454 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6455 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6456 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6457 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6459 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6460 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6461 | if (!tmo_posted) |
| 6462 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6463 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6464 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6465 | if (!tmo_posted) |
| 6466 | lpfc_worker_wake_up(phba); |
| 6467 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6468 | } |
| 6469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6470 | |
| 6471 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6472 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6473 | * @phba: Pointer to HBA context object. |
| 6474 | * |
| 6475 | * This function is called from worker thread when a mailbox command times out. |
| 6476 | * The caller is not required to hold any locks. This function will reset the |
| 6477 | * HBA and recover all the pending commands. |
| 6478 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6479 | void |
| 6480 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6481 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6482 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6483 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6484 | struct lpfc_sli *psli = &phba->sli; |
| 6485 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6486 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6487 | /* Check the pmbox pointer first. There is a race condition |
| 6488 | * between the mbox timeout handler getting executed in the |
| 6489 | * worklist and the mailbox actually completing. When this |
| 6490 | * race condition occurs, the mbox_active will be NULL. |
| 6491 | */ |
| 6492 | spin_lock_irq(&phba->hbalock); |
| 6493 | if (pmbox == NULL) { |
| 6494 | lpfc_printf_log(phba, KERN_WARNING, |
| 6495 | LOG_MBOX | LOG_SLI, |
| 6496 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6497 | "exiting\n"); |
| 6498 | spin_unlock_irq(&phba->hbalock); |
| 6499 | return; |
| 6500 | } |
| 6501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6502 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6503 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6504 | "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] | 6505 | mb->mbxCommand, |
| 6506 | phba->pport->port_state, |
| 6507 | phba->sli.sli_flag, |
| 6508 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6509 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6510 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6511 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6512 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6513 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6514 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6515 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6516 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6517 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6518 | spin_lock_irq(&phba->hbalock); |
| 6519 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6520 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6521 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6522 | |
| 6523 | pring = &psli->ring[psli->fcp_ring]; |
| 6524 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6525 | |
| 6526 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6527 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6528 | |
| 6529 | /* Reset the HBA device */ |
| 6530 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6531 | } |
| 6532 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6533 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6534 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6535 | * @phba: Pointer to HBA context object. |
| 6536 | * @pmbox: Pointer to mailbox object. |
| 6537 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6538 | * |
| 6539 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6540 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6541 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6542 | * The mailbox command can be submitted in polling mode, in which case |
| 6543 | * this function will wait in a polling loop for the completion of the |
| 6544 | * mailbox. |
| 6545 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6546 | * function will submit the command and returns immediately without waiting |
| 6547 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6548 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6549 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6550 | * mailbox is issued in polling mode and there is already a mailbox |
| 6551 | * pending, then the function will return an error. If the mailbox is issued |
| 6552 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6553 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6554 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6555 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6556 | * return codes the caller owns the mailbox command after the return of |
| 6557 | * the function. |
| 6558 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6559 | static int |
| 6560 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6561 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6562 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6563 | MAILBOX_t *mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6564 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6565 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6566 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6567 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6568 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6569 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6570 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6571 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6572 | int processing_queue = 0; |
| 6573 | |
| 6574 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6575 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6576 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6577 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6578 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6579 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6580 | return MBX_SUCCESS; |
| 6581 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6582 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6583 | pmbox = lpfc_mbox_get(phba); |
| 6584 | if (!pmbox) { |
| 6585 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6586 | return MBX_SUCCESS; |
| 6587 | } |
| 6588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6589 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6590 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6591 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6592 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6593 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6594 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6595 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6596 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6597 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6598 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6599 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6600 | } |
| 6601 | } |
| 6602 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6603 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6604 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6605 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6606 | goto out_not_finished; |
| 6607 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6608 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6609 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6610 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6611 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6612 | goto out_not_finished; |
| 6613 | } |
| 6614 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6615 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6616 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6617 | mb = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6618 | status = MBX_SUCCESS; |
| 6619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6620 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6621 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6622 | |
| 6623 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6624 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6625 | "(%d):0311 Mailbox command x%x cannot " |
| 6626 | "issue Data: x%x x%x\n", |
| 6627 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6628 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6629 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6630 | } |
| 6631 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6632 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
| 6633 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6634 | !(hc_copy & HC_MBINT_ENA)) { |
| 6635 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6636 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6637 | "(%d):2528 Mailbox command x%x cannot " |
| 6638 | "issue Data: x%x x%x\n", |
| 6639 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6640 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6641 | goto out_not_finished; |
| 6642 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6643 | } |
| 6644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6645 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6646 | /* Polling for a mbox command when another one is already active |
| 6647 | * is not allowed in SLI. Also, the driver must have established |
| 6648 | * SLI2 mode to queue and process multiple mbox commands. |
| 6649 | */ |
| 6650 | |
| 6651 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6652 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6653 | |
| 6654 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6655 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6656 | "(%d):2529 Mailbox command x%x " |
| 6657 | "cannot issue Data: x%x x%x\n", |
| 6658 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6659 | pmbox->u.mb.mbxCommand, |
| 6660 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6661 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6662 | } |
| 6663 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6664 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6665 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6666 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6667 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6668 | "(%d):2530 Mailbox command x%x " |
| 6669 | "cannot issue Data: x%x x%x\n", |
| 6670 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6671 | pmbox->u.mb.mbxCommand, |
| 6672 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6673 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6674 | } |
| 6675 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6676 | /* Another mailbox command is still being processed, queue this |
| 6677 | * command to be processed later. |
| 6678 | */ |
| 6679 | lpfc_mbox_put(phba, pmbox); |
| 6680 | |
| 6681 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6682 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6683 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6684 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6685 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
| 6686 | mb->mbxCommand, phba->pport->port_state, |
| 6687 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6688 | |
| 6689 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6690 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6691 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6692 | if (pmbox->vport) { |
| 6693 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6694 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6695 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
| 6696 | (uint32_t)mb->mbxCommand, |
| 6697 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6698 | } |
| 6699 | else { |
| 6700 | lpfc_debugfs_disc_trc(phba->pport, |
| 6701 | LPFC_DISC_TRC_MBOX, |
| 6702 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
| 6703 | (uint32_t)mb->mbxCommand, |
| 6704 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6705 | } |
| 6706 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6707 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6708 | } |
| 6709 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6710 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6711 | |
| 6712 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6713 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6714 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6715 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6716 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6717 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6718 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6719 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6720 | "(%d):2531 Mailbox command x%x " |
| 6721 | "cannot issue Data: x%x x%x\n", |
| 6722 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6723 | pmbox->u.mb.mbxCommand, |
| 6724 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6725 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6726 | } |
| 6727 | /* timeout active mbox command */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 6728 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6729 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6733 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6734 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6735 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6736 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6737 | mb->mbxCommand, phba->pport->port_state, |
| 6738 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6739 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6740 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
| 6741 | if (pmbox->vport) { |
| 6742 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6743 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6744 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 6745 | (uint32_t)mb->mbxCommand, |
| 6746 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6747 | } |
| 6748 | else { |
| 6749 | lpfc_debugfs_disc_trc(phba->pport, |
| 6750 | LPFC_DISC_TRC_MBOX, |
| 6751 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 6752 | (uint32_t)mb->mbxCommand, |
| 6753 | mb->un.varWords[0], mb->un.varWords[1]); |
| 6754 | } |
| 6755 | } |
| 6756 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6757 | psli->slistat.mbox_cmd++; |
| 6758 | evtctr = psli->slistat.mbox_event; |
| 6759 | |
| 6760 | /* next set own bit for the adapter and copy over command word */ |
| 6761 | mb->mbxOwner = OWN_CHIP; |
| 6762 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6763 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6764 | /* Populate mbox extension offset word. */ |
| 6765 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
| 6766 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6767 | = (uint8_t *)phba->mbox_ext |
| 6768 | - (uint8_t *)phba->mbox; |
| 6769 | } |
| 6770 | |
| 6771 | /* Copy the mailbox extension data */ |
| 6772 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6773 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6774 | (uint8_t *)phba->mbox_ext, |
| 6775 | pmbox->in_ext_byte_len); |
| 6776 | } |
| 6777 | /* Copy command data to host SLIM area */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6778 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6779 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6780 | /* Populate mbox extension offset word. */ |
| 6781 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
| 6782 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) |
| 6783 | = MAILBOX_HBA_EXT_OFFSET; |
| 6784 | |
| 6785 | /* Copy the mailbox extension data */ |
| 6786 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6787 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 6788 | MAILBOX_HBA_EXT_OFFSET, |
| 6789 | pmbox->context2, pmbox->in_ext_byte_len); |
| 6790 | |
| 6791 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6792 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6793 | /* copy command data into host mbox for cmpl */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6794 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | /* First copy mbox command data to HBA SLIM, skip past first |
| 6798 | word */ |
| 6799 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
| 6800 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], |
| 6801 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 6802 | |
| 6803 | /* Next copy over first word, with mbxOwner set */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6804 | ldata = *((uint32_t *)mb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6805 | to_slim = phba->MBslimaddr; |
| 6806 | writel(ldata, to_slim); |
| 6807 | readl(to_slim); /* flush */ |
| 6808 | |
| 6809 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6810 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6811 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6812 | } |
| 6813 | } |
| 6814 | |
| 6815 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6816 | |
| 6817 | switch (flag) { |
| 6818 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6819 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6820 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6821 | /* Interrupt board to do it */ |
| 6822 | writel(CA_MBATT, phba->CAregaddr); |
| 6823 | readl(phba->CAregaddr); /* flush */ |
| 6824 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6825 | break; |
| 6826 | |
| 6827 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6828 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6829 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6830 | /* Interrupt board to do it */ |
| 6831 | writel(CA_MBATT, phba->CAregaddr); |
| 6832 | readl(phba->CAregaddr); /* flush */ |
| 6833 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6834 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6835 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6836 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6837 | word0 = le32_to_cpu(word0); |
| 6838 | } else { |
| 6839 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6840 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 6841 | spin_unlock_irqrestore(&phba->hbalock, |
| 6842 | drvr_flag); |
| 6843 | goto out_not_finished; |
| 6844 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6848 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6849 | spin_unlock_irqrestore(&phba->hbalock, |
| 6850 | drvr_flag); |
| 6851 | goto out_not_finished; |
| 6852 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6853 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6854 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6855 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6856 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6857 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 6858 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6859 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6860 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6861 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6862 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6863 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6864 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | /* Check if we took a mbox interrupt while we were |
| 6868 | polling */ |
| 6869 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 6870 | && (evtctr != psli->slistat.mbox_event)) |
| 6871 | break; |
| 6872 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6873 | if (i++ > 10) { |
| 6874 | spin_unlock_irqrestore(&phba->hbalock, |
| 6875 | drvr_flag); |
| 6876 | msleep(1); |
| 6877 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6878 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6879 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6880 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6881 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6882 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6883 | word0 = le32_to_cpu(word0); |
| 6884 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
| 6885 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6886 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6887 | /* Check real SLIM for any errors */ |
| 6888 | slimword0 = readl(phba->MBslimaddr); |
| 6889 | slimmb = (MAILBOX_t *) & slimword0; |
| 6890 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 6891 | && slimmb->mbxStatus) { |
| 6892 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6893 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6894 | word0 = slimword0; |
| 6895 | } |
| 6896 | } |
| 6897 | } else { |
| 6898 | /* First copy command data */ |
| 6899 | word0 = readl(phba->MBslimaddr); |
| 6900 | } |
| 6901 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6902 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 6903 | spin_unlock_irqrestore(&phba->hbalock, |
| 6904 | drvr_flag); |
| 6905 | goto out_not_finished; |
| 6906 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6907 | } |
| 6908 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6909 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6910 | /* copy results back to user */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6911 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6912 | /* Copy the mailbox extension data */ |
| 6913 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6914 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 6915 | pmbox->context2, |
| 6916 | pmbox->out_ext_byte_len); |
| 6917 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6918 | } else { |
| 6919 | /* First copy command data */ |
| 6920 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, |
| 6921 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6922 | /* Copy the mailbox extension data */ |
| 6923 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 6924 | lpfc_memcpy_from_slim(pmbox->context2, |
| 6925 | phba->MBslimaddr + |
| 6926 | MAILBOX_HBA_EXT_OFFSET, |
| 6927 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6928 | } |
| 6929 | } |
| 6930 | |
| 6931 | writel(HA_MBATT, phba->HAregaddr); |
| 6932 | readl(phba->HAregaddr); /* flush */ |
| 6933 | |
| 6934 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 6935 | status = mb->mbxStatus; |
| 6936 | } |
| 6937 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6938 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6939 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6940 | |
| 6941 | out_not_finished: |
| 6942 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6943 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6944 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 6945 | } |
| 6946 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6947 | } |
| 6948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6949 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6950 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 6951 | * @phba: Pointer to HBA context object. |
| 6952 | * |
| 6953 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 6954 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 6955 | * possible outstanding mailbox command before return. |
| 6956 | * |
| 6957 | * Returns: |
| 6958 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 6959 | * the outstanding mailbox command timed out. |
| 6960 | **/ |
| 6961 | static int |
| 6962 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 6963 | { |
| 6964 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6965 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6966 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6967 | |
| 6968 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 6969 | spin_lock_irq(&phba->hbalock); |
| 6970 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6971 | /* Determine how long we might wait for the active mailbox |
| 6972 | * command to be gracefully completed by firmware. |
| 6973 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6974 | if (phba->sli.mbox_active) |
| 6975 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 6976 | phba->sli.mbox_active) * |
| 6977 | 1000) + jiffies; |
| 6978 | spin_unlock_irq(&phba->hbalock); |
| 6979 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6980 | /* Wait for the outstnading mailbox command to complete */ |
| 6981 | while (phba->sli.mbox_active) { |
| 6982 | /* Check active mailbox complete status every 2ms */ |
| 6983 | msleep(2); |
| 6984 | if (time_after(jiffies, timeout)) { |
| 6985 | /* Timeout, marked the outstanding cmd not complete */ |
| 6986 | rc = 1; |
| 6987 | break; |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | /* Can not cleanly block async mailbox command, fails it */ |
| 6992 | if (rc) { |
| 6993 | spin_lock_irq(&phba->hbalock); |
| 6994 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6995 | spin_unlock_irq(&phba->hbalock); |
| 6996 | } |
| 6997 | return rc; |
| 6998 | } |
| 6999 | |
| 7000 | /** |
| 7001 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7002 | * @phba: Pointer to HBA context object. |
| 7003 | * |
| 7004 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7005 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7006 | * that there is no outstanding mailbox command before resuming posting |
| 7007 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7008 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7009 | * mailbox command posting. |
| 7010 | **/ |
| 7011 | static void |
| 7012 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7013 | { |
| 7014 | struct lpfc_sli *psli = &phba->sli; |
| 7015 | |
| 7016 | spin_lock_irq(&phba->hbalock); |
| 7017 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7018 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7019 | spin_unlock_irq(&phba->hbalock); |
| 7020 | return; |
| 7021 | } |
| 7022 | |
| 7023 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7024 | * successful or timeout, after timing-out the outstanding mailbox |
| 7025 | * command shall always be removed, so just unblock posting async |
| 7026 | * mailbox command and resume |
| 7027 | */ |
| 7028 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7029 | spin_unlock_irq(&phba->hbalock); |
| 7030 | |
| 7031 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7032 | lpfc_worker_wake_up(phba); |
| 7033 | } |
| 7034 | |
| 7035 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7036 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7037 | * @phba: Pointer to HBA context object. |
| 7038 | * @mboxq: Pointer to mailbox object. |
| 7039 | * |
| 7040 | * The function posts a mailbox to the port. The mailbox is expected |
| 7041 | * to be comletely filled in and ready for the port to operate on it. |
| 7042 | * This routine executes a synchronous completion operation on the |
| 7043 | * mailbox by polling for its completion. |
| 7044 | * |
| 7045 | * The caller must not be holding any locks when calling this routine. |
| 7046 | * |
| 7047 | * Returns: |
| 7048 | * MBX_SUCCESS - mailbox posted successfully |
| 7049 | * Any of the MBX error values. |
| 7050 | **/ |
| 7051 | static int |
| 7052 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7053 | { |
| 7054 | int rc = MBX_SUCCESS; |
| 7055 | unsigned long iflag; |
| 7056 | uint32_t db_ready; |
| 7057 | uint32_t mcqe_status; |
| 7058 | uint32_t mbx_cmnd; |
| 7059 | unsigned long timeout; |
| 7060 | struct lpfc_sli *psli = &phba->sli; |
| 7061 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7062 | struct lpfc_bmbx_create *mbox_rgn; |
| 7063 | struct dma_address *dma_address; |
| 7064 | struct lpfc_register bmbx_reg; |
| 7065 | |
| 7066 | /* |
| 7067 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7068 | * at a time and there is no queueing provided. |
| 7069 | */ |
| 7070 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7071 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7072 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7073 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7074 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7075 | "cannot issue Data: x%x x%x\n", |
| 7076 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7077 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7078 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7079 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7080 | psli->sli_flag, MBX_POLL); |
| 7081 | return MBXERR_ERROR; |
| 7082 | } |
| 7083 | /* The server grabs the token and owns it until release */ |
| 7084 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7085 | phba->sli.mbox_active = mboxq; |
| 7086 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7087 | |
| 7088 | /* |
| 7089 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7090 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7091 | * the bmbx mailbox region. |
| 7092 | */ |
| 7093 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7094 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7095 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7096 | sizeof(struct lpfc_mqe)); |
| 7097 | |
| 7098 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7099 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7100 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7101 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7102 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7103 | * 1000) + jiffies; |
| 7104 | do { |
| 7105 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7106 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7107 | if (!db_ready) |
| 7108 | msleep(2); |
| 7109 | |
| 7110 | if (time_after(jiffies, timeout)) { |
| 7111 | rc = MBXERR_ERROR; |
| 7112 | goto exit; |
| 7113 | } |
| 7114 | } while (!db_ready); |
| 7115 | |
| 7116 | /* Post the low mailbox dma address to the port. */ |
| 7117 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7118 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7119 | * 1000) + jiffies; |
| 7120 | do { |
| 7121 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7122 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7123 | if (!db_ready) |
| 7124 | msleep(2); |
| 7125 | |
| 7126 | if (time_after(jiffies, timeout)) { |
| 7127 | rc = MBXERR_ERROR; |
| 7128 | goto exit; |
| 7129 | } |
| 7130 | } while (!db_ready); |
| 7131 | |
| 7132 | /* |
| 7133 | * Read the CQ to ensure the mailbox has completed. |
| 7134 | * If so, update the mailbox status so that the upper layers |
| 7135 | * can complete the request normally. |
| 7136 | */ |
| 7137 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7138 | sizeof(struct lpfc_mqe)); |
| 7139 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7140 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7141 | sizeof(struct lpfc_mcqe)); |
| 7142 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7143 | /* |
| 7144 | * When the CQE status indicates a failure and the mailbox status |
| 7145 | * indicates success then copy the CQE status into the mailbox status |
| 7146 | * (and prefix it with x4000). |
| 7147 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7148 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7149 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7150 | bf_set(lpfc_mqe_status, mb, |
| 7151 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7152 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7153 | } else |
| 7154 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7155 | |
| 7156 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7157 | "(%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] | 7158 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7159 | " 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] | 7160 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7161 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7162 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7163 | bf_get(lpfc_mqe_status, mb), |
| 7164 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7165 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7166 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7167 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7168 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7169 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7170 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7171 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7172 | mboxq->mcqe.trailer); |
| 7173 | exit: |
| 7174 | /* We are holding the token, no needed for lock when release */ |
| 7175 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7176 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7177 | phba->sli.mbox_active = NULL; |
| 7178 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7179 | return rc; |
| 7180 | } |
| 7181 | |
| 7182 | /** |
| 7183 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7184 | * @phba: Pointer to HBA context object. |
| 7185 | * @pmbox: Pointer to mailbox object. |
| 7186 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7187 | * |
| 7188 | * This function is called by discovery code and HBA management code to submit |
| 7189 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7190 | * |
| 7191 | * Return codes the caller owns the mailbox command after the return of the |
| 7192 | * function. |
| 7193 | **/ |
| 7194 | static int |
| 7195 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7196 | uint32_t flag) |
| 7197 | { |
| 7198 | struct lpfc_sli *psli = &phba->sli; |
| 7199 | unsigned long iflags; |
| 7200 | int rc; |
| 7201 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7202 | /* dump from issue mailbox command if setup */ |
| 7203 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7204 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7205 | rc = lpfc_mbox_dev_check(phba); |
| 7206 | if (unlikely(rc)) { |
| 7207 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7208 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7209 | "cannot issue Data: x%x x%x\n", |
| 7210 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7211 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7212 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7213 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7214 | psli->sli_flag, flag); |
| 7215 | goto out_not_finished; |
| 7216 | } |
| 7217 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7218 | /* Detect polling mode and jump to a handler */ |
| 7219 | if (!phba->sli4_hba.intr_enable) { |
| 7220 | if (flag == MBX_POLL) |
| 7221 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7222 | else |
| 7223 | rc = -EIO; |
| 7224 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7225 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7226 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7227 | "(x%x/x%x) failure: " |
| 7228 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7229 | "Data: 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, |
| 7233 | mboxq), |
| 7234 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7235 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7236 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7237 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7238 | bf_get(lpfc_mcqe_ext_status, |
| 7239 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7240 | psli->sli_flag, flag); |
| 7241 | return rc; |
| 7242 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7243 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7244 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7245 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7246 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7247 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7248 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7249 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7250 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7251 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7252 | /* Try to block the asynchronous mailbox posting */ |
| 7253 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7254 | if (!rc) { |
| 7255 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7256 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7257 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7258 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7259 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7260 | "(%d):2597 Sync Mailbox command " |
| 7261 | "x%x (x%x/x%x) failure: " |
| 7262 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7263 | "Data: x%x x%x\n,", |
| 7264 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7265 | mboxq->u.mb.mbxCommand, |
| 7266 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7267 | mboxq), |
| 7268 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7269 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7270 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7271 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7272 | bf_get(lpfc_mcqe_ext_status, |
| 7273 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7274 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7275 | /* Unblock the async mailbox posting afterward */ |
| 7276 | lpfc_sli4_async_mbox_unblock(phba); |
| 7277 | } |
| 7278 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7279 | } |
| 7280 | |
| 7281 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7282 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7283 | if (rc) { |
| 7284 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7285 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7286 | "cannot issue Data: x%x x%x\n", |
| 7287 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7288 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7289 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7290 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7291 | psli->sli_flag, flag); |
| 7292 | goto out_not_finished; |
| 7293 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7294 | |
| 7295 | /* Put the mailbox command to the driver internal FIFO */ |
| 7296 | psli->slistat.mbox_busy++; |
| 7297 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7298 | lpfc_mbox_put(phba, mboxq); |
| 7299 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7300 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7301 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7302 | "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] | 7303 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7304 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7305 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7306 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7307 | phba->pport->port_state, |
| 7308 | psli->sli_flag, MBX_NOWAIT); |
| 7309 | /* Wake up worker thread to transport mailbox command from head */ |
| 7310 | lpfc_worker_wake_up(phba); |
| 7311 | |
| 7312 | return MBX_BUSY; |
| 7313 | |
| 7314 | out_not_finished: |
| 7315 | return MBX_NOT_FINISHED; |
| 7316 | } |
| 7317 | |
| 7318 | /** |
| 7319 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7320 | * @phba: Pointer to HBA context object. |
| 7321 | * |
| 7322 | * This function is called by worker thread to send a mailbox command to |
| 7323 | * SLI4 HBA firmware. |
| 7324 | * |
| 7325 | **/ |
| 7326 | int |
| 7327 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7328 | { |
| 7329 | struct lpfc_sli *psli = &phba->sli; |
| 7330 | LPFC_MBOXQ_t *mboxq; |
| 7331 | int rc = MBX_SUCCESS; |
| 7332 | unsigned long iflags; |
| 7333 | struct lpfc_mqe *mqe; |
| 7334 | uint32_t mbx_cmnd; |
| 7335 | |
| 7336 | /* Check interrupt mode before post async mailbox command */ |
| 7337 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7338 | return MBX_NOT_FINISHED; |
| 7339 | |
| 7340 | /* Check for mailbox command service token */ |
| 7341 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7342 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7343 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7344 | return MBX_NOT_FINISHED; |
| 7345 | } |
| 7346 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7347 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7348 | return MBX_NOT_FINISHED; |
| 7349 | } |
| 7350 | if (unlikely(phba->sli.mbox_active)) { |
| 7351 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7352 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7353 | "0384 There is pending active mailbox cmd\n"); |
| 7354 | return MBX_NOT_FINISHED; |
| 7355 | } |
| 7356 | /* Take the mailbox command service token */ |
| 7357 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7358 | |
| 7359 | /* Get the next mailbox command from head of queue */ |
| 7360 | mboxq = lpfc_mbox_get(phba); |
| 7361 | |
| 7362 | /* If no more mailbox command waiting for post, we're done */ |
| 7363 | if (!mboxq) { |
| 7364 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7365 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7366 | return MBX_SUCCESS; |
| 7367 | } |
| 7368 | phba->sli.mbox_active = mboxq; |
| 7369 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7370 | |
| 7371 | /* Check device readiness for posting mailbox command */ |
| 7372 | rc = lpfc_mbox_dev_check(phba); |
| 7373 | if (unlikely(rc)) |
| 7374 | /* Driver clean routine will clean up pending mailbox */ |
| 7375 | goto out_not_finished; |
| 7376 | |
| 7377 | /* Prepare the mbox command to be posted */ |
| 7378 | mqe = &mboxq->u.mqe; |
| 7379 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7380 | |
| 7381 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7382 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7383 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7384 | |
| 7385 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7386 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7387 | "x%x x%x\n", |
| 7388 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7389 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7390 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7391 | phba->pport->port_state, psli->sli_flag); |
| 7392 | |
| 7393 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7394 | if (mboxq->vport) { |
| 7395 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7396 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7397 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7398 | mbx_cmnd, mqe->un.mb_words[0], |
| 7399 | mqe->un.mb_words[1]); |
| 7400 | } else { |
| 7401 | lpfc_debugfs_disc_trc(phba->pport, |
| 7402 | LPFC_DISC_TRC_MBOX, |
| 7403 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7404 | mbx_cmnd, mqe->un.mb_words[0], |
| 7405 | mqe->un.mb_words[1]); |
| 7406 | } |
| 7407 | } |
| 7408 | psli->slistat.mbox_cmd++; |
| 7409 | |
| 7410 | /* Post the mailbox command to the port */ |
| 7411 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7412 | if (rc != MBX_SUCCESS) { |
| 7413 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7414 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7415 | "cannot issue Data: x%x x%x\n", |
| 7416 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7417 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7418 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7419 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7420 | psli->sli_flag, MBX_NOWAIT); |
| 7421 | goto out_not_finished; |
| 7422 | } |
| 7423 | |
| 7424 | return rc; |
| 7425 | |
| 7426 | out_not_finished: |
| 7427 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7428 | if (phba->sli.mbox_active) { |
| 7429 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7430 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7431 | /* Release the token */ |
| 7432 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7433 | phba->sli.mbox_active = NULL; |
| 7434 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7435 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7436 | |
| 7437 | return MBX_NOT_FINISHED; |
| 7438 | } |
| 7439 | |
| 7440 | /** |
| 7441 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7442 | * @phba: Pointer to HBA context object. |
| 7443 | * @pmbox: Pointer to mailbox object. |
| 7444 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7445 | * |
| 7446 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7447 | * the API jump table function pointer from the lpfc_hba struct. |
| 7448 | * |
| 7449 | * Return codes the caller owns the mailbox command after the return of the |
| 7450 | * function. |
| 7451 | **/ |
| 7452 | int |
| 7453 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7454 | { |
| 7455 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7456 | } |
| 7457 | |
| 7458 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7459 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7460 | * @phba: The hba struct for which this call is being executed. |
| 7461 | * @dev_grp: The HBA PCI-Device group number. |
| 7462 | * |
| 7463 | * This routine sets up the mbox interface API function jump table in @phba |
| 7464 | * struct. |
| 7465 | * Returns: 0 - success, -ENODEV - failure. |
| 7466 | **/ |
| 7467 | int |
| 7468 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7469 | { |
| 7470 | |
| 7471 | switch (dev_grp) { |
| 7472 | case LPFC_PCI_DEV_LP: |
| 7473 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7474 | phba->lpfc_sli_handle_slow_ring_event = |
| 7475 | lpfc_sli_handle_slow_ring_event_s3; |
| 7476 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7477 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7478 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7479 | break; |
| 7480 | case LPFC_PCI_DEV_OC: |
| 7481 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7482 | phba->lpfc_sli_handle_slow_ring_event = |
| 7483 | lpfc_sli_handle_slow_ring_event_s4; |
| 7484 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7485 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7486 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7487 | break; |
| 7488 | default: |
| 7489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7490 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7491 | dev_grp); |
| 7492 | return -ENODEV; |
| 7493 | break; |
| 7494 | } |
| 7495 | return 0; |
| 7496 | } |
| 7497 | |
| 7498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7499 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7500 | * @phba: Pointer to HBA context object. |
| 7501 | * @pring: Pointer to driver SLI ring object. |
| 7502 | * @piocb: Pointer to address of newly added command iocb. |
| 7503 | * |
| 7504 | * This function is called with hbalock held to add a command |
| 7505 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7506 | * to the ring. |
| 7507 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7508 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7509 | __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] | 7510 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7511 | { |
| 7512 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7513 | list_add_tail(&piocb->list, &pring->txq); |
| 7514 | pring->txq_cnt++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7515 | } |
| 7516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7518 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7519 | * @phba: Pointer to HBA context object. |
| 7520 | * @pring: Pointer to driver SLI ring object. |
| 7521 | * @piocb: Pointer to address of newly added command iocb. |
| 7522 | * |
| 7523 | * This function is called with hbalock held before a new |
| 7524 | * iocb is submitted to the firmware. This function checks |
| 7525 | * txq to flush the iocbs in txq to Firmware before |
| 7526 | * submitting new iocbs to the Firmware. |
| 7527 | * If there are iocbs in the txq which need to be submitted |
| 7528 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7529 | * of the txq after dequeuing it from txq. |
| 7530 | * If there is no iocb in the txq then the function will return |
| 7531 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7532 | * *piocb to find if there are more commands in the txq. |
| 7533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7534 | static struct lpfc_iocbq * |
| 7535 | 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] | 7536 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7537 | { |
| 7538 | struct lpfc_iocbq * nextiocb; |
| 7539 | |
| 7540 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7541 | if (!nextiocb) { |
| 7542 | nextiocb = *piocb; |
| 7543 | *piocb = NULL; |
| 7544 | } |
| 7545 | |
| 7546 | return nextiocb; |
| 7547 | } |
| 7548 | |
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 | * __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] | 7551 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7552 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7553 | * @piocb: Pointer to command iocb. |
| 7554 | * @flag: Flag indicating if this command can be put into txq. |
| 7555 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7556 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7557 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7558 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7559 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7560 | * this function allows only iocbs for posting buffers. This function finds |
| 7561 | * next available slot in the command ring and posts the command to the |
| 7562 | * available slot and writes the port attention register to request HBA start |
| 7563 | * processing new iocb. If there is no slot available in the ring and |
| 7564 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7565 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7566 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7567 | * This function is called with hbalock held. The function will return success |
| 7568 | * after it successfully submit the iocb to firmware or after adding to the |
| 7569 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7570 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7571 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7572 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7573 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7574 | { |
| 7575 | struct lpfc_iocbq *nextiocb; |
| 7576 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7577 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7578 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7579 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7580 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7581 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7582 | lpfc_printf_log(phba, KERN_ERR, |
| 7583 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7584 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7585 | piocb->iocb.ulpCommand); |
| 7586 | dump_stack(); |
| 7587 | return IOCB_ERROR; |
| 7588 | } |
| 7589 | |
| 7590 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7591 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7592 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7593 | return IOCB_ERROR; |
| 7594 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7595 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7596 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7597 | return IOCB_ERROR; |
| 7598 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7599 | /* |
| 7600 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7601 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7602 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7603 | return IOCB_ERROR; |
| 7604 | |
| 7605 | /* |
| 7606 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7607 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7608 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7609 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7610 | goto iocb_busy; |
| 7611 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7612 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7613 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7614 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7615 | * can be issued if the link is not up. |
| 7616 | */ |
| 7617 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7618 | case CMD_GEN_REQUEST64_CR: |
| 7619 | case CMD_GEN_REQUEST64_CX: |
| 7620 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7621 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7622 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7623 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7624 | MENLO_TRANSPORT_TYPE)) |
| 7625 | |
| 7626 | goto iocb_busy; |
| 7627 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7628 | case CMD_QUE_RING_BUF_CN: |
| 7629 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7630 | /* |
| 7631 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7632 | * completion, iocb_cmpl MUST be 0. |
| 7633 | */ |
| 7634 | if (piocb->iocb_cmpl) |
| 7635 | piocb->iocb_cmpl = NULL; |
| 7636 | /*FALLTHROUGH*/ |
| 7637 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7638 | case CMD_CLOSE_XRI_CN: |
| 7639 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7640 | break; |
| 7641 | default: |
| 7642 | goto iocb_busy; |
| 7643 | } |
| 7644 | |
| 7645 | /* |
| 7646 | * For FCP commands, we must be in a state where we can process link |
| 7647 | * attention events. |
| 7648 | */ |
| 7649 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7650 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7651 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7653 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7654 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7655 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7656 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7657 | |
| 7658 | if (iocb) |
| 7659 | lpfc_sli_update_ring(phba, pring); |
| 7660 | else |
| 7661 | lpfc_sli_update_full_ring(phba, pring); |
| 7662 | |
| 7663 | if (!piocb) |
| 7664 | return IOCB_SUCCESS; |
| 7665 | |
| 7666 | goto out_busy; |
| 7667 | |
| 7668 | iocb_busy: |
| 7669 | pring->stats.iocb_cmd_delay++; |
| 7670 | |
| 7671 | out_busy: |
| 7672 | |
| 7673 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7674 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7675 | return IOCB_SUCCESS; |
| 7676 | } |
| 7677 | |
| 7678 | return IOCB_BUSY; |
| 7679 | } |
| 7680 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7681 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7682 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7683 | * @phba: Pointer to HBA context object. |
| 7684 | * @piocb: Pointer to command iocb. |
| 7685 | * @sglq: Pointer to the scatter gather queue object. |
| 7686 | * |
| 7687 | * This routine converts the bpl or bde that is in the IOCB |
| 7688 | * to a sgl list for the sli4 hardware. The physical address |
| 7689 | * of the bpl/bde is converted back to a virtual address. |
| 7690 | * If the IOCB contains a BPL then the list of BDE's is |
| 7691 | * converted to sli4_sge's. If the IOCB contains a single |
| 7692 | * BDE then it is converted to a single sli_sge. |
| 7693 | * The IOCB is still in cpu endianess so the contents of |
| 7694 | * the bpl can be used without byte swapping. |
| 7695 | * |
| 7696 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7697 | **/ |
| 7698 | static uint16_t |
| 7699 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7700 | struct lpfc_sglq *sglq) |
| 7701 | { |
| 7702 | uint16_t xritag = NO_XRI; |
| 7703 | struct ulp_bde64 *bpl = NULL; |
| 7704 | struct ulp_bde64 bde; |
| 7705 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7706 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7707 | IOCB_t *icmd; |
| 7708 | int numBdes = 0; |
| 7709 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7710 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7711 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7712 | |
| 7713 | if (!piocbq || !sglq) |
| 7714 | return xritag; |
| 7715 | |
| 7716 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7717 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7718 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7719 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7720 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7721 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7722 | sizeof(struct ulp_bde64); |
| 7723 | /* The addrHigh and addrLow fields within the IOCB |
| 7724 | * have not been byteswapped yet so there is no |
| 7725 | * need to swap them back. |
| 7726 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7727 | if (piocbq->context3) |
| 7728 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7729 | else |
| 7730 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7731 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7732 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7733 | if (!bpl) |
| 7734 | return xritag; |
| 7735 | |
| 7736 | for (i = 0; i < numBdes; i++) { |
| 7737 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7738 | sgl->addr_hi = bpl->addrHigh; |
| 7739 | sgl->addr_lo = bpl->addrLow; |
| 7740 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7741 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7742 | if ((i+1) == numBdes) |
| 7743 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7744 | else |
| 7745 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7746 | /* swap the size field back to the cpu so we |
| 7747 | * can assign it to the sgl. |
| 7748 | */ |
| 7749 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7750 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7751 | /* The offsets in the sgl need to be accumulated |
| 7752 | * separately for the request and reply lists. |
| 7753 | * The request is always first, the reply follows. |
| 7754 | */ |
| 7755 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7756 | /* add up the reply sg entries */ |
| 7757 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7758 | inbound++; |
| 7759 | /* first inbound? reset the offset */ |
| 7760 | if (inbound == 1) |
| 7761 | offset = 0; |
| 7762 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7763 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7764 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7765 | offset += bde.tus.f.bdeSize; |
| 7766 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 7767 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7768 | bpl++; |
| 7769 | sgl++; |
| 7770 | } |
| 7771 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 7772 | /* The addrHigh and addrLow fields of the BDE have not |
| 7773 | * been byteswapped yet so they need to be swapped |
| 7774 | * before putting them in the sgl. |
| 7775 | */ |
| 7776 | sgl->addr_hi = |
| 7777 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 7778 | sgl->addr_lo = |
| 7779 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7780 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7781 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7782 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7783 | sgl->sge_len = |
| 7784 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7785 | } |
| 7786 | return sglq->sli4_xritag; |
| 7787 | } |
| 7788 | |
| 7789 | /** |
| 7790 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 7791 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7792 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7793 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7794 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 7795 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7796 | * |
| 7797 | * Return: index into SLI4 fast-path FCP queue index. |
| 7798 | **/ |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 7799 | static inline uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7800 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7801 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 7802 | int i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7803 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 7804 | i = atomic_add_return(1, &phba->fcp_qidx); |
| 7805 | i = (i % phba->cfg_fcp_wq_count); |
| 7806 | return i; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7807 | } |
| 7808 | |
| 7809 | /** |
| 7810 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 7811 | * @phba: Pointer to HBA context object. |
| 7812 | * @piocb: Pointer to command iocb. |
| 7813 | * @wqe: Pointer to the work queue entry. |
| 7814 | * |
| 7815 | * This routine converts the iocb command to its Work Queue Entry |
| 7816 | * equivalent. The wqe pointer should not have any fields set when |
| 7817 | * this routine is called because it will memcpy over them. |
| 7818 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 7819 | * wqe. |
| 7820 | * |
| 7821 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 7822 | **/ |
| 7823 | static int |
| 7824 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 7825 | union lpfc_wqe *wqe) |
| 7826 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7827 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7828 | uint8_t ct = 0; |
| 7829 | uint32_t fip; |
| 7830 | uint32_t abort_tag; |
| 7831 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 7832 | uint8_t cmnd; |
| 7833 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 7834 | uint16_t abrt_iotag; |
| 7835 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7836 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7837 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7838 | int numBdes, i; |
| 7839 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7840 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7841 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7842 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7843 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7844 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7845 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7846 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7847 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7848 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 7849 | command_type = ELS_COMMAND_FIP; |
| 7850 | else |
| 7851 | command_type = ELS_COMMAND_NON_FIP; |
| 7852 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7853 | /* Some of the fields are in the right position already */ |
| 7854 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 7855 | abort_tag = (uint32_t) iocbq->iotag; |
| 7856 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7857 | 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] | 7858 | /* words0-2 bpl convert bde */ |
| 7859 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7860 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 7861 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7862 | bpl = (struct ulp_bde64 *) |
| 7863 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 7864 | if (!bpl) |
| 7865 | return IOCB_ERROR; |
| 7866 | |
| 7867 | /* Should already be byte swapped. */ |
| 7868 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 7869 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 7870 | /* swap the size field back to the cpu so we |
| 7871 | * can assign it to the sgl. |
| 7872 | */ |
| 7873 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7874 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 7875 | total_len = 0; |
| 7876 | for (i = 0; i < numBdes; i++) { |
| 7877 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 7878 | total_len += bde.tus.f.bdeSize; |
| 7879 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7880 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7881 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7882 | |
| 7883 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 7884 | cmnd = iocbq->iocb.ulpCommand; |
| 7885 | |
| 7886 | switch (iocbq->iocb.ulpCommand) { |
| 7887 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 7888 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 7889 | ndlp = iocbq->context_un.ndlp; |
| 7890 | else |
| 7891 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7892 | if (!iocbq->iocb.ulpLe) { |
| 7893 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7894 | "2007 Only Limited Edition cmd Format" |
| 7895 | " supported 0x%x\n", |
| 7896 | iocbq->iocb.ulpCommand); |
| 7897 | return IOCB_ERROR; |
| 7898 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7899 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7900 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7901 | /* Els_reguest64 has a TMO */ |
| 7902 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 7903 | iocbq->iocb.ulpTimeout); |
| 7904 | /* Need a VF for word 4 set the vf bit*/ |
| 7905 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 7906 | /* And a VFID for word 12 */ |
| 7907 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7908 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7909 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7910 | iocbq->iocb.ulpContext); |
| 7911 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 7912 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7913 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7914 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7915 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 7916 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7917 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 7918 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7919 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7920 | &phba->sli4_hba.sli_intf); |
| 7921 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7922 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 7923 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7924 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 7925 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7926 | *pcmd == ELS_CMD_PLOGI)) { |
| 7927 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 7928 | bf_set(els_req64_sid, &wqe->els_req, |
| 7929 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 7930 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 7931 | !(phba->fc_topology == |
| 7932 | LPFC_TOPOLOGY_LOOP)) |
| 7933 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7934 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 7935 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 7936 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 7937 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7938 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 7939 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 7940 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 7941 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 7942 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7943 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 7944 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7945 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 7946 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 7947 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 7948 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 7949 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 7950 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7951 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7952 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7953 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 7954 | iocbq->iocb.un.ulpWord[3]); |
| 7955 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7956 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7957 | /* The entire sequence is transmitted for this IOCB */ |
| 7958 | xmit_len = total_len; |
| 7959 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7960 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 7961 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7962 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7963 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 7964 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7965 | /* word4 relative_offset memcpy */ |
| 7966 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7967 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 7968 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 7969 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 7970 | LPFC_WQE_IOD_WRITE); |
| 7971 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 7972 | LPFC_WQE_LENLOC_WORD12); |
| 7973 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7974 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 7975 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7976 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7977 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7978 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 7979 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7980 | /* word4 iocb=rsvd wqe=rsvd */ |
| 7981 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 7982 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7983 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7984 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7985 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 7986 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 7987 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 7988 | LPFC_WQE_LENLOC_WORD3); |
| 7989 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7990 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7991 | case CMD_FCP_IWRITE64_CR: |
| 7992 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7993 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 7994 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 7995 | wqe->fcp_iwrite.payload_offset_len = |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7996 | xmit_len + sizeof(struct fcp_rsp); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 7997 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 7998 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 7999 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8000 | iocbq->iocb.ulpFCP2Rcvy); |
| 8001 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8002 | /* Always open the exchange */ |
| 8003 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8004 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8005 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8006 | LPFC_WQE_LENLOC_WORD4); |
| 8007 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8008 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8009 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 8010 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 8011 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 8012 | } |
| 8013 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8014 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8015 | case CMD_FCP_IREAD64_CR: |
| 8016 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8017 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8018 | wqe->fcp_iread.payload_offset_len = |
| 8019 | xmit_len + sizeof(struct fcp_rsp); |
| 8020 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8021 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8022 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8023 | iocbq->iocb.ulpFCP2Rcvy); |
| 8024 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8025 | /* Always open the exchange */ |
| 8026 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8027 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8028 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8029 | LPFC_WQE_LENLOC_WORD4); |
| 8030 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8031 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8032 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
| 8033 | iocbq->iocb_flag &= ~LPFC_IO_DIF; |
| 8034 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); |
| 8035 | } |
| 8036 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8037 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8038 | case CMD_FCP_ICMND64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8039 | /* word3 iocb=IO_TAG wqe=reserved */ |
| 8040 | wqe->fcp_icmd.rsrvd3 = 0; |
| 8041 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8042 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8043 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8044 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8045 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8046 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8047 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8048 | LPFC_WQE_LENLOC_NONE); |
| 8049 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8050 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8051 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8052 | /* For this command calculate the xmit length of the |
| 8053 | * request bde. |
| 8054 | */ |
| 8055 | xmit_len = 0; |
| 8056 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8057 | sizeof(struct ulp_bde64); |
| 8058 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8059 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8060 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8061 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8062 | xmit_len += bde.tus.f.bdeSize; |
| 8063 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8064 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8065 | wqe->gen_req.request_payload_len = xmit_len; |
| 8066 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8067 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8068 | /* word6 context tag copied in memcpy */ |
| 8069 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8070 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8071 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8072 | "2015 Invalid CT %x command 0x%x\n", |
| 8073 | ct, iocbq->iocb.ulpCommand); |
| 8074 | return IOCB_ERROR; |
| 8075 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8076 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8077 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8078 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8079 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8080 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8081 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8082 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8083 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8084 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8085 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8086 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8087 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8088 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8089 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8090 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8091 | /* word4 */ |
| 8092 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8093 | /* word5 iocb=rsvd wge=did */ |
| 8094 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8095 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8096 | |
| 8097 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8098 | &phba->sli4_hba.sli_intf); |
| 8099 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8100 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8101 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8102 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8103 | iocbq->vport->fc_myDID); |
| 8104 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8105 | bf_set(wqe_els_did, |
| 8106 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8107 | } |
| 8108 | } |
| 8109 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8110 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8111 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8112 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8113 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8114 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8115 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8116 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8117 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8118 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8119 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8120 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8121 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8122 | LPFC_WQE_LENLOC_WORD3); |
| 8123 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8124 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8125 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8126 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8127 | iocbq->context2)->virt); |
| 8128 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8129 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8130 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8131 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8132 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8133 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8134 | phba->vpi_ids[phba->pport->vpi]); |
| 8135 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8136 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8137 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8138 | case CMD_CLOSE_XRI_CN: |
| 8139 | case CMD_ABORT_XRI_CN: |
| 8140 | case CMD_ABORT_XRI_CX: |
| 8141 | /* words 0-2 memcpy should be 0 rserved */ |
| 8142 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8143 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8144 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8145 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8146 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8147 | } else |
| 8148 | fip = 0; |
| 8149 | |
| 8150 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8151 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8152 | * The link is down, or the command was ELS_FIP |
| 8153 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8154 | * on the wire. |
| 8155 | */ |
| 8156 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8157 | else |
| 8158 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8159 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8160 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8161 | wqe->abort_cmd.rsrvd5 = 0; |
| 8162 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8163 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8164 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8165 | /* |
| 8166 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8167 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8168 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8169 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8170 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8171 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8172 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8173 | cmnd = CMD_ABORT_XRI_CX; |
| 8174 | command_type = OTHER_COMMAND; |
| 8175 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8176 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8177 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8178 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8179 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8180 | * we re-construct this WQE here based on information in |
| 8181 | * iocbq from scratch. |
| 8182 | */ |
| 8183 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8184 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8185 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8186 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8187 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8188 | LPFC_ABTS_UNSOL_INT) { |
| 8189 | /* ABTS sent by initiator to CT exchange, the |
| 8190 | * RX_ID field will be filled with the newly |
| 8191 | * allocated responder XRI. |
| 8192 | */ |
| 8193 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8194 | iocbq->sli4_xritag); |
| 8195 | } else { |
| 8196 | /* ABTS sent by responder to CT exchange, the |
| 8197 | * RX_ID field will be filled with the responder |
| 8198 | * RX_ID from ABTS. |
| 8199 | */ |
| 8200 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8201 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8202 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8203 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8204 | 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] | 8205 | |
| 8206 | /* Use CT=VPI */ |
| 8207 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8208 | ndlp->nlp_DID); |
| 8209 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8210 | iocbq->iocb.ulpContext); |
| 8211 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8212 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8213 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8214 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8215 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8216 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8217 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8218 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8219 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8220 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8221 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8222 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8223 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8224 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8225 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8226 | } |
| 8227 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8228 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8229 | case CMD_XRI_ABORTED_CX: |
| 8230 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8231 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8232 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8233 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8234 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8235 | default: |
| 8236 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8237 | "2014 Invalid command 0x%x\n", |
| 8238 | iocbq->iocb.ulpCommand); |
| 8239 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8240 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8241 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8242 | |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8243 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8244 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8245 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8246 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8247 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8248 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8249 | 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] | 8250 | return 0; |
| 8251 | } |
| 8252 | |
| 8253 | /** |
| 8254 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8255 | * @phba: Pointer to HBA context object. |
| 8256 | * @ring_number: SLI ring number to issue iocb on. |
| 8257 | * @piocb: Pointer to command iocb. |
| 8258 | * @flag: Flag indicating if this command can be put into txq. |
| 8259 | * |
| 8260 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8261 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8262 | * |
| 8263 | * This function is called with hbalock held. The function will return success |
| 8264 | * after it successfully submit the iocb to firmware or after adding to the |
| 8265 | * txq. |
| 8266 | **/ |
| 8267 | static int |
| 8268 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8269 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8270 | { |
| 8271 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8272 | union lpfc_wqe wqe; |
| 8273 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8274 | |
| 8275 | if (piocb->sli4_xritag == NO_XRI) { |
| 8276 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8277 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8278 | sglq = NULL; |
| 8279 | else { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8280 | if (pring->txq_cnt) { |
| 8281 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8282 | __lpfc_sli_ringtx_put(phba, |
| 8283 | pring, piocb); |
| 8284 | return IOCB_SUCCESS; |
| 8285 | } else { |
| 8286 | return IOCB_BUSY; |
| 8287 | } |
| 8288 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8289 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8290 | if (!sglq) { |
| 8291 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8292 | __lpfc_sli_ringtx_put(phba, |
| 8293 | pring, |
| 8294 | piocb); |
| 8295 | return IOCB_SUCCESS; |
| 8296 | } else |
| 8297 | return IOCB_BUSY; |
| 8298 | } |
| 8299 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8300 | } |
| 8301 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8302 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8303 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8304 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8305 | /* |
| 8306 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8307 | * sglq is on the active list |
| 8308 | */ |
| 8309 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); |
| 8310 | if (!sglq) |
| 8311 | return IOCB_ERROR; |
| 8312 | } |
| 8313 | |
| 8314 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8315 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8316 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8317 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8318 | return IOCB_ERROR; |
| 8319 | } |
| 8320 | |
| 8321 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8322 | return IOCB_ERROR; |
| 8323 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8324 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8325 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8326 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8327 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8328 | return IOCB_ERROR; |
| 8329 | } else { |
| 8330 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8331 | return IOCB_ERROR; |
| 8332 | } |
| 8333 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8334 | |
| 8335 | return 0; |
| 8336 | } |
| 8337 | |
| 8338 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8339 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8340 | * |
| 8341 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8342 | * pointer from the lpfc_hba struct. |
| 8343 | * |
| 8344 | * Return codes: |
| 8345 | * IOCB_ERROR - Error |
| 8346 | * IOCB_SUCCESS - Success |
| 8347 | * IOCB_BUSY - Busy |
| 8348 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8349 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8350 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8351 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8352 | { |
| 8353 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8354 | } |
| 8355 | |
| 8356 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8357 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8358 | * @phba: The hba struct for which this call is being executed. |
| 8359 | * @dev_grp: The HBA PCI-Device group number. |
| 8360 | * |
| 8361 | * This routine sets up the SLI interface API function jump table in @phba |
| 8362 | * struct. |
| 8363 | * Returns: 0 - success, -ENODEV - failure. |
| 8364 | **/ |
| 8365 | int |
| 8366 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8367 | { |
| 8368 | |
| 8369 | switch (dev_grp) { |
| 8370 | case LPFC_PCI_DEV_LP: |
| 8371 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8372 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8373 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8374 | case LPFC_PCI_DEV_OC: |
| 8375 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8376 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8377 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8378 | default: |
| 8379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8380 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8381 | dev_grp); |
| 8382 | return -ENODEV; |
| 8383 | break; |
| 8384 | } |
| 8385 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8386 | return 0; |
| 8387 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8390 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8391 | * @phba: Pointer to HBA context object. |
| 8392 | * @pring: Pointer to driver SLI ring object. |
| 8393 | * @piocb: Pointer to command iocb. |
| 8394 | * @flag: Flag indicating if this command can be put into txq. |
| 8395 | * |
| 8396 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8397 | * function. This function gets the hbalock and calls |
| 8398 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8399 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8400 | * functions which do not hold hbalock. |
| 8401 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8402 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8403 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8404 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8405 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 8406 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8407 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 8408 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8409 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8410 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 8411 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
| 8412 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8413 | return IOCB_ERROR; |
| 8414 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
| 8415 | piocb->fcp_wqidx = idx; |
| 8416 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; |
| 8417 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8418 | pring = &phba->sli.ring[ring_number]; |
| 8419 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8420 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8421 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8422 | } else { |
| 8423 | /* For now, SLI2/3 will still use hbalock */ |
| 8424 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8425 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8426 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8427 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8428 | return rc; |
| 8429 | } |
| 8430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8432 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8433 | * @phba: Pointer to HBA context object. |
| 8434 | * |
| 8435 | * This function is called while driver attaches with the |
| 8436 | * HBA to setup the extra ring. The extra ring is used |
| 8437 | * only when driver needs to support target mode functionality |
| 8438 | * or IP over FC functionalities. |
| 8439 | * |
| 8440 | * This function is called with no lock held. |
| 8441 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8442 | static int |
| 8443 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8444 | { |
| 8445 | struct lpfc_sli *psli; |
| 8446 | struct lpfc_sli_ring *pring; |
| 8447 | |
| 8448 | psli = &phba->sli; |
| 8449 | |
| 8450 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8451 | |
| 8452 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8453 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8454 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8455 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8456 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8457 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8458 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8459 | /* and give them to the extra ring */ |
| 8460 | pring = &psli->ring[psli->extra_ring]; |
| 8461 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8462 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8463 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8464 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8465 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8466 | |
| 8467 | /* Setup default profile for this ring */ |
| 8468 | pring->iotag_max = 4096; |
| 8469 | pring->num_mask = 1; |
| 8470 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8471 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8472 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8473 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8474 | return 0; |
| 8475 | } |
| 8476 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8477 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
| 8478 | * @vport: pointer to virtual port object. |
| 8479 | * @ndlp: nodelist pointer for the impacted rport. |
| 8480 | * |
| 8481 | * The driver calls this routine in response to a XRI ABORT CQE |
| 8482 | * event from the port. In this event, the driver is required to |
| 8483 | * recover its login to the rport even though its login may be valid |
| 8484 | * from the driver's perspective. The failed ABTS notice from the |
| 8485 | * port indicates the rport is not responding. |
| 8486 | */ |
| 8487 | static void |
| 8488 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, |
| 8489 | struct lpfc_nodelist *ndlp) |
| 8490 | { |
| 8491 | struct Scsi_Host *shost; |
| 8492 | struct lpfc_hba *phba; |
| 8493 | unsigned long flags = 0; |
| 8494 | |
| 8495 | shost = lpfc_shost_from_vport(vport); |
| 8496 | phba = vport->phba; |
| 8497 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { |
| 8498 | lpfc_printf_log(phba, KERN_INFO, |
| 8499 | LOG_SLI, "3093 No rport recovery needed. " |
| 8500 | "rport in state 0x%x\n", |
| 8501 | ndlp->nlp_state); |
| 8502 | return; |
| 8503 | } |
| 8504 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8505 | "3094 Start rport recovery on shost id 0x%x " |
| 8506 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " |
| 8507 | "flags 0x%x\n", |
| 8508 | shost->host_no, ndlp->nlp_DID, |
| 8509 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, |
| 8510 | ndlp->nlp_flag); |
| 8511 | /* |
| 8512 | * The rport is not responding. Don't attempt ADISC recovery. |
| 8513 | * Remove the FCP-2 flag to force a PLOGI. |
| 8514 | */ |
| 8515 | spin_lock_irqsave(shost->host_lock, flags); |
| 8516 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; |
| 8517 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8518 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 8519 | NLP_EVT_DEVICE_RECOVERY); |
| 8520 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| 8521 | spin_lock_irqsave(shost->host_lock, flags); |
| 8522 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 8523 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 8524 | lpfc_disc_start(vport); |
| 8525 | } |
| 8526 | |
| 8527 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8528 | * @phba: Pointer to HBA context object. |
| 8529 | * @iocbq: Pointer to iocb object. |
| 8530 | * |
| 8531 | * The async_event handler calls this routine when it receives |
| 8532 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8533 | * this event when an Abort Sequence request to an rport fails |
| 8534 | * twice in succession. The abort could be originated by the |
| 8535 | * driver or by the port. The ABTS could have been for an ELS |
| 8536 | * or FCP IO. The port only generates this event when an ABTS |
| 8537 | * fails to complete after one retry. |
| 8538 | */ |
| 8539 | static void |
| 8540 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8541 | struct lpfc_iocbq *iocbq) |
| 8542 | { |
| 8543 | struct lpfc_nodelist *ndlp = NULL; |
| 8544 | uint16_t rpi = 0, vpi = 0; |
| 8545 | struct lpfc_vport *vport = NULL; |
| 8546 | |
| 8547 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8548 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8549 | rpi = iocbq->iocb.ulpContext; |
| 8550 | |
| 8551 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8552 | "3092 Port generated ABTS async event " |
| 8553 | "on vpi %d rpi %d status 0x%x\n", |
| 8554 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8555 | |
| 8556 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8557 | if (!vport) |
| 8558 | goto err_exit; |
| 8559 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8560 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8561 | goto err_exit; |
| 8562 | |
| 8563 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8564 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8565 | return; |
| 8566 | |
| 8567 | err_exit: |
| 8568 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8569 | "3095 Event Context not found, no " |
| 8570 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8571 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8572 | vpi, rpi); |
| 8573 | } |
| 8574 | |
| 8575 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8576 | * @phba: pointer to HBA context object. |
| 8577 | * @ndlp: nodelist pointer for the impacted rport. |
| 8578 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8579 | * |
| 8580 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8581 | * port. The port generates this event when an abort exchange request to an |
| 8582 | * rport fails twice in succession with no reply. The abort could be originated |
| 8583 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8584 | */ |
| 8585 | void |
| 8586 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8587 | struct lpfc_nodelist *ndlp, |
| 8588 | struct sli4_wcqe_xri_aborted *axri) |
| 8589 | { |
| 8590 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8591 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8592 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8593 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8594 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8595 | "3115 Node Context not found, driver " |
| 8596 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8597 | return; |
| 8598 | } |
| 8599 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8600 | vport = ndlp->vport; |
| 8601 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8602 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8603 | "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] | 8604 | ndlp->vport->vpi, ndlp->nlp_rpi, |
| 8605 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8606 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8607 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8608 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8609 | /* |
| 8610 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8611 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8612 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8613 | */ |
| 8614 | ext_status = axri->parameter & WCQE_PARAM_MASK; |
| 8615 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8616 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8617 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8618 | } |
| 8619 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8620 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8621 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8622 | * @phba: Pointer to HBA context object. |
| 8623 | * @pring: Pointer to driver SLI ring object. |
| 8624 | * @iocbq: Pointer to iocb object. |
| 8625 | * |
| 8626 | * This function is called by the slow ring event handler |
| 8627 | * function when there is an ASYNC event iocb in the ring. |
| 8628 | * This function is called with no lock held. |
| 8629 | * Currently this function handles only temperature related |
| 8630 | * ASYNC events. The function decodes the temperature sensor |
| 8631 | * event message and posts events for the management applications. |
| 8632 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8633 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8634 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8635 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8636 | { |
| 8637 | IOCB_t *icmd; |
| 8638 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8639 | struct temp_event temp_event_data; |
| 8640 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8641 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8642 | |
| 8643 | icmd = &iocbq->iocb; |
| 8644 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8645 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8646 | switch (evt_code) { |
| 8647 | case ASYNC_TEMP_WARN: |
| 8648 | case ASYNC_TEMP_SAFE: |
| 8649 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8650 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8651 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8652 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8653 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8654 | "0347 Adapter is very hot, please take " |
| 8655 | "corrective action. temperature : %d Celsius\n", |
| 8656 | (uint32_t) icmd->ulpContext); |
| 8657 | } else { |
| 8658 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8659 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8660 | "0340 Adapter temperature is OK now. " |
| 8661 | "temperature : %d Celsius\n", |
| 8662 | (uint32_t) icmd->ulpContext); |
| 8663 | } |
| 8664 | |
| 8665 | /* Send temperature change event to applications */ |
| 8666 | shost = lpfc_shost_from_vport(phba->pport); |
| 8667 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8668 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8669 | LPFC_NL_VENDOR_ID); |
| 8670 | break; |
| 8671 | case ASYNC_STATUS_CN: |
| 8672 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8673 | break; |
| 8674 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8675 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8677 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8678 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8679 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8680 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8681 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8682 | "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] | 8683 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8684 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8685 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8686 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8687 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8688 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8689 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8690 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8691 | } |
| 8692 | |
| 8693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8694 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8695 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8696 | * @phba: Pointer to HBA context object. |
| 8697 | * |
| 8698 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8699 | * number of iocbs per ring and iotags. This function is |
| 8700 | * called while driver attach to the HBA and before the |
| 8701 | * interrupts are enabled. So there is no need for locking. |
| 8702 | * |
| 8703 | * This function always returns 0. |
| 8704 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8705 | int |
| 8706 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8707 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8708 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8709 | struct lpfc_sli *psli = &phba->sli; |
| 8710 | struct lpfc_sli_ring *pring; |
| 8711 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 8712 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 8713 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8714 | psli->num_rings += phba->cfg_fcp_eq_count; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8715 | psli->sli_flag = 0; |
| 8716 | psli->fcp_ring = LPFC_FCP_RING; |
| 8717 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8718 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8719 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8720 | psli->iocbq_lookup = NULL; |
| 8721 | psli->iocbq_lookup_len = 0; |
| 8722 | psli->last_iotag = 0; |
| 8723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8724 | for (i = 0; i < psli->num_rings; i++) { |
| 8725 | pring = &psli->ring[i]; |
| 8726 | switch (i) { |
| 8727 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8728 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8729 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8730 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8731 | pring->sli.sli3.numCiocb += |
| 8732 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8733 | pring->sli.sli3.numRiocb += |
| 8734 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8735 | pring->sli.sli3.numCiocb += |
| 8736 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8737 | pring->sli.sli3.numRiocb += |
| 8738 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8739 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8740 | SLI3_IOCB_CMD_SIZE : |
| 8741 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8742 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8743 | SLI3_IOCB_RSP_SIZE : |
| 8744 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8745 | pring->iotag_ctr = 0; |
| 8746 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8747 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8748 | pring->fast_iotag = pring->iotag_max; |
| 8749 | pring->num_mask = 0; |
| 8750 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8751 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8752 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8753 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 8754 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 8755 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8756 | SLI3_IOCB_CMD_SIZE : |
| 8757 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8758 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8759 | SLI3_IOCB_RSP_SIZE : |
| 8760 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8761 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8762 | pring->num_mask = 0; |
| 8763 | break; |
| 8764 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 8765 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8766 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 8767 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 8768 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8769 | SLI3_IOCB_CMD_SIZE : |
| 8770 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8771 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8772 | SLI3_IOCB_RSP_SIZE : |
| 8773 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8774 | pring->fast_iotag = 0; |
| 8775 | pring->iotag_ctr = 0; |
| 8776 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8777 | pring->lpfc_sli_rcv_async_status = |
| 8778 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8779 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8780 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8781 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 8782 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8783 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8784 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8785 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8786 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 8787 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8788 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8789 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8790 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 8791 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8792 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8793 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8794 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8795 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8796 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8797 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 8798 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8799 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8800 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8801 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8802 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8803 | lpfc_ct_unsol_event; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8804 | /* abort unsolicited sequence */ |
| 8805 | pring->prt[4].profile = 0; /* Mask 4 */ |
| 8806 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; |
| 8807 | pring->prt[4].type = FC_TYPE_BLS; |
| 8808 | pring->prt[4].lpfc_sli_rcv_unsol_event = |
| 8809 | lpfc_sli4_ct_abort_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8810 | break; |
| 8811 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8812 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 8813 | pring->sli.sli3.sizeCiocb) + |
| 8814 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8815 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8816 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8817 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8818 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 8819 | "SLI2 SLIM Data: x%x x%lx\n", |
| 8820 | phba->brd_no, totiocbsize, |
| 8821 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8822 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8823 | if (phba->cfg_multi_ring_support == 2) |
| 8824 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8825 | |
| 8826 | return 0; |
| 8827 | } |
| 8828 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8829 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8830 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8831 | * @phba: Pointer to HBA context object. |
| 8832 | * |
| 8833 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 8834 | * ring. This function also initializes ring indices of each ring. |
| 8835 | * This function is called during the initialization of the SLI |
| 8836 | * interface of an HBA. |
| 8837 | * This function is called with no lock held and always returns |
| 8838 | * 1. |
| 8839 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8840 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8841 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8842 | { |
| 8843 | struct lpfc_sli *psli; |
| 8844 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8845 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8846 | |
| 8847 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8848 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8849 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8850 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8851 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 8852 | for (i = 0; i < psli->num_rings; i++) { |
| 8853 | pring = &psli->ring[i]; |
| 8854 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8855 | pring->sli.sli3.next_cmdidx = 0; |
| 8856 | pring->sli.sli3.local_getidx = 0; |
| 8857 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8858 | INIT_LIST_HEAD(&pring->txq); |
| 8859 | INIT_LIST_HEAD(&pring->txcmplq); |
| 8860 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 8861 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8862 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8863 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8864 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8865 | spin_unlock_irq(&phba->hbalock); |
| 8866 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8867 | } |
| 8868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8869 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 8870 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 8871 | * @phba: Pointer to HBA context object. |
| 8872 | * |
| 8873 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 8874 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 8875 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 8876 | * command; and completed mailbox command queue. It is caller's responsibility |
| 8877 | * to make sure that the driver is in the proper state to flush the mailbox |
| 8878 | * command sub-system. Namely, the posting of mailbox commands into the |
| 8879 | * pending mailbox command queue from the various clients must be stopped; |
| 8880 | * either the HBA is in a state that it will never works on the outstanding |
| 8881 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 8882 | * mailbox command has been completed. |
| 8883 | **/ |
| 8884 | static void |
| 8885 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 8886 | { |
| 8887 | LIST_HEAD(completions); |
| 8888 | struct lpfc_sli *psli = &phba->sli; |
| 8889 | LPFC_MBOXQ_t *pmb; |
| 8890 | unsigned long iflag; |
| 8891 | |
| 8892 | /* Flush all the mailbox commands in the mbox system */ |
| 8893 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8894 | /* The pending mailbox command queue */ |
| 8895 | list_splice_init(&phba->sli.mboxq, &completions); |
| 8896 | /* The outstanding active mailbox command */ |
| 8897 | if (psli->mbox_active) { |
| 8898 | list_add_tail(&psli->mbox_active->list, &completions); |
| 8899 | psli->mbox_active = NULL; |
| 8900 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8901 | } |
| 8902 | /* The completed mailbox command queue */ |
| 8903 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 8904 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8905 | |
| 8906 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 8907 | while (!list_empty(&completions)) { |
| 8908 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 8909 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8910 | if (pmb->mbox_cmpl) |
| 8911 | pmb->mbox_cmpl(phba, pmb); |
| 8912 | } |
| 8913 | } |
| 8914 | |
| 8915 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8916 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8917 | * @vport: Pointer to virtual port object. |
| 8918 | * |
| 8919 | * lpfc_sli_host_down is called to clean up the resources |
| 8920 | * associated with a vport before destroying virtual |
| 8921 | * port data structures. |
| 8922 | * This function does following operations: |
| 8923 | * - Free discovery resources associated with this virtual |
| 8924 | * port. |
| 8925 | * - Free iocbs associated with this virtual port in |
| 8926 | * the txq. |
| 8927 | * - Send abort for all iocb commands associated with this |
| 8928 | * vport in txcmplq. |
| 8929 | * |
| 8930 | * This function is called with no lock held and always returns 1. |
| 8931 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8932 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8933 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 8934 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8935 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8936 | struct lpfc_hba *phba = vport->phba; |
| 8937 | struct lpfc_sli *psli = &phba->sli; |
| 8938 | struct lpfc_sli_ring *pring; |
| 8939 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8940 | int i; |
| 8941 | unsigned long flags = 0; |
| 8942 | uint16_t prev_pring_flag; |
| 8943 | |
| 8944 | lpfc_cleanup_discovery_resources(vport); |
| 8945 | |
| 8946 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8947 | for (i = 0; i < psli->num_rings; i++) { |
| 8948 | pring = &psli->ring[i]; |
| 8949 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8950 | /* Only slow rings */ |
| 8951 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8952 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 8953 | /* Set the lpfc data pending flag */ |
| 8954 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 8955 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8956 | /* |
| 8957 | * Error everything on the txq since these iocbs have not been |
| 8958 | * given to the FW yet. |
| 8959 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8960 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 8961 | if (iocb->vport != vport) |
| 8962 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8963 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8964 | pring->txq_cnt--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8965 | } |
| 8966 | |
| 8967 | /* Next issue ABTS for everything on the txcmplq */ |
| 8968 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 8969 | list) { |
| 8970 | if (iocb->vport != vport) |
| 8971 | continue; |
| 8972 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 8973 | } |
| 8974 | |
| 8975 | pring->flag = prev_pring_flag; |
| 8976 | } |
| 8977 | |
| 8978 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 8979 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8980 | /* Cancel all the IOCBs from the completions list */ |
| 8981 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 8982 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8983 | return 1; |
| 8984 | } |
| 8985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8987 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8988 | * @phba: Pointer to HBA context object. |
| 8989 | * |
| 8990 | * This function cleans up all iocb, buffers, mailbox commands |
| 8991 | * while shutting down the HBA. This function is called with no |
| 8992 | * lock held and always returns 1. |
| 8993 | * This function does the following to cleanup driver resources: |
| 8994 | * - Free discovery resources for each virtual port |
| 8995 | * - Cleanup any pending fabric iocbs |
| 8996 | * - Iterate through the iocb txq and free each entry |
| 8997 | * in the list. |
| 8998 | * - Free up any buffer posted to the HBA |
| 8999 | * - Free mailbox commands in the mailbox queue. |
| 9000 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9001 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9002 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9003 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9004 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9005 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9006 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9007 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9008 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9009 | int i; |
| 9010 | |
| 9011 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9012 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9013 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9014 | lpfc_hba_down_prep(phba); |
| 9015 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9016 | lpfc_fabric_abort_hba(phba); |
| 9017 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9018 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9019 | for (i = 0; i < psli->num_rings; i++) { |
| 9020 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9021 | /* Only slow rings */ |
| 9022 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9023 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9024 | /* Set the lpfc data pending flag */ |
| 9025 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9026 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9027 | |
| 9028 | /* |
| 9029 | * Error everything on the txq since these iocbs have not been |
| 9030 | * given to the FW yet. |
| 9031 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9032 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9033 | pring->txq_cnt = 0; |
| 9034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9035 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9036 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9037 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9038 | /* Cancel all the IOCBs from the completions list */ |
| 9039 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9040 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9041 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9042 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9043 | list_splice_init(&phba->elsbuf, &completions); |
| 9044 | phba->elsbuf_cnt = 0; |
| 9045 | phba->elsbuf_prev_cnt = 0; |
| 9046 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9047 | |
| 9048 | while (!list_empty(&completions)) { |
| 9049 | list_remove_head(&completions, buf_ptr, |
| 9050 | struct lpfc_dmabuf, list); |
| 9051 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9052 | kfree(buf_ptr); |
| 9053 | } |
| 9054 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9055 | /* Return any active mbox cmds */ |
| 9056 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9057 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9058 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9059 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9060 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9061 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9062 | return 1; |
| 9063 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9064 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9065 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9066 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9067 | * @srcp: Source memory pointer. |
| 9068 | * @destp: Destination memory pointer. |
| 9069 | * @cnt: Number of words required to be copied. |
| 9070 | * |
| 9071 | * This function is used for copying data between driver memory |
| 9072 | * and the SLI memory. This function also changes the endianness |
| 9073 | * of each word if native endianness is different from SLI |
| 9074 | * endianness. This function can be called with or without |
| 9075 | * lock. |
| 9076 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9077 | void |
| 9078 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9079 | { |
| 9080 | uint32_t *src = srcp; |
| 9081 | uint32_t *dest = destp; |
| 9082 | uint32_t ldata; |
| 9083 | int i; |
| 9084 | |
| 9085 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9086 | ldata = *src; |
| 9087 | ldata = le32_to_cpu(ldata); |
| 9088 | *dest = ldata; |
| 9089 | src++; |
| 9090 | dest++; |
| 9091 | } |
| 9092 | } |
| 9093 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9094 | |
| 9095 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9096 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9097 | * @srcp: Source memory pointer. |
| 9098 | * @destp: Destination memory pointer. |
| 9099 | * @cnt: Number of words required to be copied. |
| 9100 | * |
| 9101 | * This function is used for copying data between a data structure |
| 9102 | * with big endian representation to local endianness. |
| 9103 | * This function can be called with or without lock. |
| 9104 | **/ |
| 9105 | void |
| 9106 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9107 | { |
| 9108 | uint32_t *src = srcp; |
| 9109 | uint32_t *dest = destp; |
| 9110 | uint32_t ldata; |
| 9111 | int i; |
| 9112 | |
| 9113 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9114 | ldata = *src; |
| 9115 | ldata = be32_to_cpu(ldata); |
| 9116 | *dest = ldata; |
| 9117 | src++; |
| 9118 | dest++; |
| 9119 | } |
| 9120 | } |
| 9121 | |
| 9122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9123 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9124 | * @phba: Pointer to HBA context object. |
| 9125 | * @pring: Pointer to driver SLI ring object. |
| 9126 | * @mp: Pointer to driver buffer object. |
| 9127 | * |
| 9128 | * This function is called with no lock held. |
| 9129 | * It always return zero after adding the buffer to the postbufq |
| 9130 | * buffer list. |
| 9131 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9132 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9133 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9134 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9135 | { |
| 9136 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9137 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9138 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9139 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9140 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9141 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9142 | return 0; |
| 9143 | } |
| 9144 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9146 | * 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] | 9147 | * @phba: Pointer to HBA context object. |
| 9148 | * |
| 9149 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9150 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9151 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9152 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9153 | * The function returns the allocated tag. The function is called with |
| 9154 | * no locks held. |
| 9155 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9156 | uint32_t |
| 9157 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9158 | { |
| 9159 | spin_lock_irq(&phba->hbalock); |
| 9160 | phba->buffer_tag_count++; |
| 9161 | /* |
| 9162 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9163 | * a tag assigned by HBQ. |
| 9164 | */ |
| 9165 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9166 | spin_unlock_irq(&phba->hbalock); |
| 9167 | return phba->buffer_tag_count; |
| 9168 | } |
| 9169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9171 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9172 | * @phba: Pointer to HBA context object. |
| 9173 | * @pring: Pointer to driver SLI ring object. |
| 9174 | * @tag: Buffer tag. |
| 9175 | * |
| 9176 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9177 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9178 | * iocb is posted to the response ring with the tag of the buffer. |
| 9179 | * This function searches the pring->postbufq list using the tag |
| 9180 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9181 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9182 | * buffer is returned to the caller else NULL is returned. |
| 9183 | * This function is called with no lock held. |
| 9184 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9185 | struct lpfc_dmabuf * |
| 9186 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9187 | uint32_t tag) |
| 9188 | { |
| 9189 | struct lpfc_dmabuf *mp, *next_mp; |
| 9190 | struct list_head *slp = &pring->postbufq; |
| 9191 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9192 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9193 | spin_lock_irq(&phba->hbalock); |
| 9194 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9195 | if (mp->buffer_tag == tag) { |
| 9196 | list_del_init(&mp->list); |
| 9197 | pring->postbufq_cnt--; |
| 9198 | spin_unlock_irq(&phba->hbalock); |
| 9199 | return mp; |
| 9200 | } |
| 9201 | } |
| 9202 | |
| 9203 | spin_unlock_irq(&phba->hbalock); |
| 9204 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9205 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9206 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9207 | pring->ringno, (unsigned long) tag, |
| 9208 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9209 | |
| 9210 | return NULL; |
| 9211 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9212 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9213 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9214 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9215 | * @phba: Pointer to HBA context object. |
| 9216 | * @pring: Pointer to driver SLI ring object. |
| 9217 | * @phys: DMA address of the buffer. |
| 9218 | * |
| 9219 | * This function searches the buffer list using the dma_address |
| 9220 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9221 | * corresponding to the dma_address. The function returns the |
| 9222 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9223 | * This function is called by the ct and els unsolicited event |
| 9224 | * handlers to get the buffer associated with the unsolicited |
| 9225 | * event. |
| 9226 | * |
| 9227 | * This function is called with no lock held. |
| 9228 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9229 | struct lpfc_dmabuf * |
| 9230 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9231 | dma_addr_t phys) |
| 9232 | { |
| 9233 | struct lpfc_dmabuf *mp, *next_mp; |
| 9234 | struct list_head *slp = &pring->postbufq; |
| 9235 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9236 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9237 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9238 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9239 | if (mp->phys == phys) { |
| 9240 | list_del_init(&mp->list); |
| 9241 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9242 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9243 | return mp; |
| 9244 | } |
| 9245 | } |
| 9246 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9247 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9249 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9250 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9251 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9252 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9253 | return NULL; |
| 9254 | } |
| 9255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9257 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9258 | * @phba: Pointer to HBA context object. |
| 9259 | * @cmdiocb: Pointer to driver command iocb object. |
| 9260 | * @rspiocb: Pointer to driver response iocb object. |
| 9261 | * |
| 9262 | * This function is the completion handler for the abort iocbs for |
| 9263 | * ELS commands. This function is called from the ELS ring event |
| 9264 | * handler with no lock held. This function frees memory resources |
| 9265 | * associated with the abort iocb. |
| 9266 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9267 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9268 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9269 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9270 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9271 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9272 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9273 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9274 | |
| 9275 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9276 | |
| 9277 | /* |
| 9278 | * Assume that the port already completed and returned, or |
| 9279 | * will return the iocb. Just Log the message. |
| 9280 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9281 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9282 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9283 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9284 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9285 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9286 | if (abort_iotag != 0 && |
| 9287 | abort_iotag <= phba->sli.last_iotag) |
| 9288 | abort_iocb = |
| 9289 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9290 | } else |
| 9291 | /* For sli4 the abort_tag is the XRI, |
| 9292 | * so the abort routine puts the iotag of the iocb |
| 9293 | * being aborted in the context field of the abort |
| 9294 | * IOCB. |
| 9295 | */ |
| 9296 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9297 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9298 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9299 | "0327 Cannot abort els iocb %p " |
| 9300 | "with tag %x context %x, abort status %x, " |
| 9301 | "abort code %x\n", |
| 9302 | abort_iocb, abort_iotag, abort_context, |
| 9303 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9304 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9305 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9306 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9307 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9308 | return; |
| 9309 | } |
| 9310 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9312 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9313 | * @phba: Pointer to HBA context object. |
| 9314 | * @cmdiocb: Pointer to driver command iocb object. |
| 9315 | * @rspiocb: Pointer to driver response iocb object. |
| 9316 | * |
| 9317 | * The function is called from SLI ring event handler with no |
| 9318 | * lock held. This function is the completion handler for ELS commands |
| 9319 | * which are aborted. The function frees memory resources used for |
| 9320 | * the aborted ELS commands. |
| 9321 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9322 | static void |
| 9323 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9324 | struct lpfc_iocbq *rspiocb) |
| 9325 | { |
| 9326 | IOCB_t *irsp = &rspiocb->iocb; |
| 9327 | |
| 9328 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9329 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9330 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9331 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9332 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9333 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9334 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9335 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9336 | else |
| 9337 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9338 | return; |
| 9339 | } |
| 9340 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9341 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9342 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9343 | * @phba: Pointer to HBA context object. |
| 9344 | * @pring: Pointer to driver SLI ring object. |
| 9345 | * @cmdiocb: Pointer to driver command iocb object. |
| 9346 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9347 | * This function issues an abort iocb for the provided command iocb down to |
| 9348 | * the port. Other than the case the outstanding command iocb is an abort |
| 9349 | * request, this function issues abort out unconditionally. This function is |
| 9350 | * called with hbalock held. The function returns 0 when it fails due to |
| 9351 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9352 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9353 | static int |
| 9354 | 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] | 9355 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9356 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9357 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9358 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9359 | IOCB_t *icmd = NULL; |
| 9360 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9361 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9362 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9363 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9364 | /* |
| 9365 | * There are certain command types we don't want to abort. And we |
| 9366 | * don't want to abort commands that are already in the process of |
| 9367 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9368 | */ |
| 9369 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9370 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9371 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9372 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9373 | return 0; |
| 9374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9375 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9376 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9377 | if (abtsiocbp == NULL) |
| 9378 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9379 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9380 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9381 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9382 | */ |
| 9383 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9385 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9386 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9387 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9388 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9389 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9390 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9391 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9392 | else |
| 9393 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9394 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9395 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9396 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9397 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9398 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9399 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9400 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9401 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9402 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9403 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9404 | else |
| 9405 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9406 | |
| 9407 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9408 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9409 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9410 | "0339 Abort xri x%x, original iotag x%x, " |
| 9411 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9412 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9413 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9414 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9415 | |
| 9416 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9417 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9418 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9419 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9420 | abtsiocbp, 0); |
| 9421 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9422 | } else { |
| 9423 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9424 | abtsiocbp, 0); |
| 9425 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9426 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9427 | if (retval) |
| 9428 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9429 | |
| 9430 | /* |
| 9431 | * Caller to this routine should check for IOCB_ERROR |
| 9432 | * and handle it properly. This routine no longer removes |
| 9433 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9434 | */ |
| 9435 | return retval; |
| 9436 | } |
| 9437 | |
| 9438 | /** |
| 9439 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9440 | * @phba: Pointer to HBA context object. |
| 9441 | * @pring: Pointer to driver SLI ring object. |
| 9442 | * @cmdiocb: Pointer to driver command iocb object. |
| 9443 | * |
| 9444 | * This function issues an abort iocb for the provided command iocb. In case |
| 9445 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9446 | * ring. Instead, the callback function shall be changed to those commands |
| 9447 | * so that nothing happens when them finishes. This function is called with |
| 9448 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9449 | * request. |
| 9450 | **/ |
| 9451 | int |
| 9452 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9453 | struct lpfc_iocbq *cmdiocb) |
| 9454 | { |
| 9455 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9456 | int retval = IOCB_ERROR; |
| 9457 | IOCB_t *icmd = NULL; |
| 9458 | |
| 9459 | /* |
| 9460 | * There are certain command types we don't want to abort. And we |
| 9461 | * don't want to abort commands that are already in the process of |
| 9462 | * being aborted. |
| 9463 | */ |
| 9464 | icmd = &cmdiocb->iocb; |
| 9465 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9466 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9467 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9468 | return 0; |
| 9469 | |
| 9470 | /* |
| 9471 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9472 | * the callback so that nothing happens when it finishes. |
| 9473 | */ |
| 9474 | if ((vport->load_flag & FC_UNLOADING) && |
| 9475 | (pring->ringno == LPFC_ELS_RING)) { |
| 9476 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9477 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9478 | else |
| 9479 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9480 | goto abort_iotag_exit; |
| 9481 | } |
| 9482 | |
| 9483 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9484 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9485 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9486 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9487 | /* |
| 9488 | * Caller to this routine should check for IOCB_ERROR |
| 9489 | * and handle it properly. This routine no longer removes |
| 9490 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9491 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9492 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9493 | } |
| 9494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9495 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9496 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9497 | * @phba: Pointer to HBA context object. |
| 9498 | * @pring: Pointer to driver SLI ring object. |
| 9499 | * |
| 9500 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9501 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9502 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9503 | * to complete before the return of this function. The caller is not required |
| 9504 | * to hold any locks. |
| 9505 | **/ |
| 9506 | static void |
| 9507 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9508 | { |
| 9509 | LIST_HEAD(completions); |
| 9510 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9511 | |
| 9512 | if (pring->ringno == LPFC_ELS_RING) |
| 9513 | lpfc_fabric_abort_hba(phba); |
| 9514 | |
| 9515 | spin_lock_irq(&phba->hbalock); |
| 9516 | |
| 9517 | /* Take off all the iocbs on txq for cancelling */ |
| 9518 | list_splice_init(&pring->txq, &completions); |
| 9519 | pring->txq_cnt = 0; |
| 9520 | |
| 9521 | /* Next issue ABTS for everything on the txcmplq */ |
| 9522 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9523 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9524 | |
| 9525 | spin_unlock_irq(&phba->hbalock); |
| 9526 | |
| 9527 | /* Cancel all the IOCBs from the completions list */ |
| 9528 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9529 | IOERR_SLI_ABORTED); |
| 9530 | } |
| 9531 | |
| 9532 | /** |
| 9533 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9534 | * @phba: pointer to lpfc HBA data structure. |
| 9535 | * |
| 9536 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9537 | **/ |
| 9538 | void |
| 9539 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9540 | { |
| 9541 | struct lpfc_sli *psli = &phba->sli; |
| 9542 | struct lpfc_sli_ring *pring; |
| 9543 | int i; |
| 9544 | |
| 9545 | for (i = 0; i < psli->num_rings; i++) { |
| 9546 | pring = &psli->ring[i]; |
| 9547 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9548 | } |
| 9549 | } |
| 9550 | |
| 9551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9552 | * 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] | 9553 | * @iocbq: Pointer to driver iocb object. |
| 9554 | * @vport: Pointer to driver virtual port object. |
| 9555 | * @tgt_id: SCSI ID of the target. |
| 9556 | * @lun_id: LUN ID of the scsi device. |
| 9557 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9558 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9559 | * 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] | 9560 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9561 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9562 | * 1 if the filtering criteria is not met. |
| 9563 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9564 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9565 | * lun_id parameter. |
| 9566 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9567 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9568 | * parameters. |
| 9569 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9570 | * given iocb is for the SCSI host associated with the given vport. |
| 9571 | * This function is called with no locks held. |
| 9572 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9573 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9574 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9575 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9576 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9577 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9578 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9579 | int rc = 1; |
| 9580 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9581 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9582 | return rc; |
| 9583 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9584 | if (iocbq->vport != vport) |
| 9585 | return rc; |
| 9586 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9587 | 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] | 9588 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9589 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9590 | return rc; |
| 9591 | |
| 9592 | switch (ctx_cmd) { |
| 9593 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9594 | if ((lpfc_cmd->rdata->pnode) && |
| 9595 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9596 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9597 | rc = 0; |
| 9598 | break; |
| 9599 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9600 | if ((lpfc_cmd->rdata->pnode) && |
| 9601 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9602 | rc = 0; |
| 9603 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9604 | case LPFC_CTX_HOST: |
| 9605 | rc = 0; |
| 9606 | break; |
| 9607 | default: |
| 9608 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9609 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9610 | break; |
| 9611 | } |
| 9612 | |
| 9613 | return rc; |
| 9614 | } |
| 9615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9617 | * 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] | 9618 | * @vport: Pointer to virtual port. |
| 9619 | * @tgt_id: SCSI ID of the target. |
| 9620 | * @lun_id: LUN ID of the scsi device. |
| 9621 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9622 | * |
| 9623 | * This function returns number of FCP commands pending for the vport. |
| 9624 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9625 | * commands pending on the vport associated with SCSI device specified |
| 9626 | * by tgt_id and lun_id parameters. |
| 9627 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9628 | * commands pending on the vport associated with SCSI target specified |
| 9629 | * by tgt_id parameter. |
| 9630 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9631 | * commands pending on the vport. |
| 9632 | * This function returns the number of iocbs which satisfy the filter. |
| 9633 | * This function is called without any lock held. |
| 9634 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9635 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9636 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9637 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9638 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9639 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9640 | struct lpfc_iocbq *iocbq; |
| 9641 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9642 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9643 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9644 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9645 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9646 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9647 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9648 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9649 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9650 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9651 | return sum; |
| 9652 | } |
| 9653 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9654 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9655 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9656 | * @phba: Pointer to HBA context object |
| 9657 | * @cmdiocb: Pointer to command iocb object. |
| 9658 | * @rspiocb: Pointer to response iocb object. |
| 9659 | * |
| 9660 | * This function is called when an aborted FCP iocb completes. This |
| 9661 | * function is called by the ring event handler with no lock held. |
| 9662 | * This function frees the iocb. |
| 9663 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9664 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9665 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9666 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9667 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9668 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9669 | "3096 ABORT_XRI_CN completing on xri x%x " |
| 9670 | "original iotag x%x, abort cmd iotag x%x " |
| 9671 | "status 0x%x, reason 0x%x\n", |
| 9672 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9673 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9674 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9675 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9676 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9677 | return; |
| 9678 | } |
| 9679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9681 | * 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] | 9682 | * @vport: Pointer to virtual port. |
| 9683 | * @pring: Pointer to driver SLI ring object. |
| 9684 | * @tgt_id: SCSI ID of the target. |
| 9685 | * @lun_id: LUN ID of the scsi device. |
| 9686 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9687 | * |
| 9688 | * This function sends an abort command for every SCSI command |
| 9689 | * associated with the given virtual port pending on the ring |
| 9690 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9691 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9692 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9693 | * parameters |
| 9694 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9695 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9696 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9697 | * FCP iocbs associated with virtual port. |
| 9698 | * This function returns number of iocbs it failed to abort. |
| 9699 | * This function is called with no locks held. |
| 9700 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9701 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9702 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9703 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9704 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9705 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9706 | struct lpfc_iocbq *iocbq; |
| 9707 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9708 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9709 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9710 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9711 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9712 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9713 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9714 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9715 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9716 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9717 | continue; |
| 9718 | |
| 9719 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9720 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9721 | if (abtsiocb == NULL) { |
| 9722 | errcnt++; |
| 9723 | continue; |
| 9724 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9725 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9726 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9727 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9728 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9729 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9730 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9731 | else |
| 9732 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9733 | abtsiocb->iocb.ulpLe = 1; |
| 9734 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9735 | abtsiocb->vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9736 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9737 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9738 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9739 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9740 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9742 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9743 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9744 | else |
| 9745 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 9746 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9747 | /* Setup callback routine and issue the command. */ |
| 9748 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9749 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9750 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9751 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9752 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9753 | errcnt++; |
| 9754 | continue; |
| 9755 | } |
| 9756 | } |
| 9757 | |
| 9758 | return errcnt; |
| 9759 | } |
| 9760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9761 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9762 | * 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] | 9763 | * @phba: Pointer to HBA context object. |
| 9764 | * @cmdiocbq: Pointer to command iocb. |
| 9765 | * @rspiocbq: Pointer to response iocb. |
| 9766 | * |
| 9767 | * This function is the completion handler for iocbs issued using |
| 9768 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 9769 | * ring event handler function without any lock held. This function |
| 9770 | * can be called from both worker thread context and interrupt |
| 9771 | * context. This function also can be called from other thread which |
| 9772 | * cleans up the SLI layer objects. |
| 9773 | * This function copy the contents of the response iocb to the |
| 9774 | * response iocb memory object provided by the caller of |
| 9775 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 9776 | * sleeps for the iocb completion. |
| 9777 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9778 | static void |
| 9779 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 9780 | struct lpfc_iocbq *cmdiocbq, |
| 9781 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9782 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9783 | wait_queue_head_t *pdone_q; |
| 9784 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9785 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9786 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9787 | spin_lock_irqsave(&phba->hbalock, iflags); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9788 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 9789 | if (cmdiocbq->context2 && rspiocbq) |
| 9790 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 9791 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 9792 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 9793 | /* Set the exchange busy flag for task management commands */ |
| 9794 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 9795 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 9796 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 9797 | cur_iocbq); |
| 9798 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 9799 | } |
| 9800 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9801 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9802 | if (pdone_q) |
| 9803 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9804 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9805 | return; |
| 9806 | } |
| 9807 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9808 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9809 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 9810 | * @phba: Pointer to HBA context object.. |
| 9811 | * @piocbq: Pointer to command iocb. |
| 9812 | * @flag: Flag to test. |
| 9813 | * |
| 9814 | * This routine grabs the hbalock and then test the iocb_flag to |
| 9815 | * see if the passed in flag is set. |
| 9816 | * Returns: |
| 9817 | * 1 if flag is set. |
| 9818 | * 0 if flag is not set. |
| 9819 | **/ |
| 9820 | static int |
| 9821 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 9822 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 9823 | { |
| 9824 | unsigned long iflags; |
| 9825 | int ret; |
| 9826 | |
| 9827 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9828 | ret = piocbq->iocb_flag & flag; |
| 9829 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9830 | return ret; |
| 9831 | |
| 9832 | } |
| 9833 | |
| 9834 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9835 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9836 | * @phba: Pointer to HBA context object.. |
| 9837 | * @pring: Pointer to sli ring. |
| 9838 | * @piocb: Pointer to command iocb. |
| 9839 | * @prspiocbq: Pointer to response iocb. |
| 9840 | * @timeout: Timeout in number of seconds. |
| 9841 | * |
| 9842 | * This function issues the iocb to firmware and waits for the |
| 9843 | * iocb to complete. If the iocb command is not |
| 9844 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. |
| 9845 | * Caller should not free the iocb resources if this function |
| 9846 | * returns IOCB_TIMEDOUT. |
| 9847 | * The function waits for the iocb completion using an |
| 9848 | * non-interruptible wait. |
| 9849 | * This function will sleep while waiting for iocb completion. |
| 9850 | * So, this function should not be called from any context which |
| 9851 | * does not allow sleeping. Due to the same reason, this function |
| 9852 | * cannot be called with interrupt disabled. |
| 9853 | * This function assumes that the iocb completions occur while |
| 9854 | * this function sleep. So, this function cannot be called from |
| 9855 | * the thread which process iocb completion for this ring. |
| 9856 | * This function clears the iocb_flag of the iocb object before |
| 9857 | * issuing the iocb and the iocb completion handler sets this |
| 9858 | * flag and wakes this thread when the iocb completes. |
| 9859 | * The contents of the response iocb will be copied to prspiocbq |
| 9860 | * by the completion handler when the command completes. |
| 9861 | * This function returns IOCB_SUCCESS when success. |
| 9862 | * This function is called with no lock held. |
| 9863 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9864 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9865 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9866 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9867 | struct lpfc_iocbq *piocb, |
| 9868 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9869 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9870 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9871 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9872 | long timeleft, timeout_req = 0; |
| 9873 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9874 | uint32_t creg_val; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9875 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9876 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9877 | * If the caller has provided a response iocbq buffer, then context2 |
| 9878 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9879 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9880 | if (prspiocbq) { |
| 9881 | if (piocb->context2) |
| 9882 | return IOCB_ERROR; |
| 9883 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9884 | } |
| 9885 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9886 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 9887 | piocb->context_un.wait_queue = &done_q; |
| 9888 | piocb->iocb_flag &= ~LPFC_IO_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9889 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9890 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9891 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9892 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9893 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 9894 | writel(creg_val, phba->HCregaddr); |
| 9895 | readl(phba->HCregaddr); /* flush */ |
| 9896 | } |
| 9897 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9898 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 9899 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9900 | if (retval == IOCB_SUCCESS) { |
| 9901 | timeout_req = timeout * HZ; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9902 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 9903 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9904 | timeout_req); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9905 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9906 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
| 9907 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9908 | "0331 IOCB wake signaled\n"); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9909 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9910 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9911 | "0338 IOCB wait timeout error - no " |
| 9912 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9913 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9914 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9915 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9916 | "0330 IOCB wake NOT set, " |
| 9917 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9918 | timeout, (timeleft / jiffies)); |
| 9919 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9920 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9921 | } else if (retval == IOCB_BUSY) { |
| 9922 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9923 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 9924 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); |
| 9925 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9926 | } else { |
| 9927 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9928 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9929 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9930 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9931 | } |
| 9932 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9933 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9934 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 9935 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 9936 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 9937 | writel(creg_val, phba->HCregaddr); |
| 9938 | readl(phba->HCregaddr); /* flush */ |
| 9939 | } |
| 9940 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9941 | if (prspiocbq) |
| 9942 | piocb->context2 = NULL; |
| 9943 | |
| 9944 | piocb->context_un.wait_queue = NULL; |
| 9945 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9946 | return retval; |
| 9947 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 9948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9950 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9951 | * @phba: Pointer to HBA context object. |
| 9952 | * @pmboxq: Pointer to driver mailbox object. |
| 9953 | * @timeout: Timeout in number of seconds. |
| 9954 | * |
| 9955 | * This function issues the mailbox to firmware and waits for the |
| 9956 | * mailbox command to complete. If the mailbox command is not |
| 9957 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 9958 | * The function waits for the mailbox completion using an |
| 9959 | * interruptible wait. If the thread is woken up due to a |
| 9960 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 9961 | * should not free the mailbox resources, if this function returns |
| 9962 | * MBX_TIMEOUT. |
| 9963 | * This function will sleep while waiting for mailbox completion. |
| 9964 | * So, this function should not be called from any context which |
| 9965 | * does not allow sleeping. Due to the same reason, this function |
| 9966 | * cannot be called with interrupt disabled. |
| 9967 | * This function assumes that the mailbox completion occurs while |
| 9968 | * this function sleep. So, this function cannot be called from |
| 9969 | * the worker thread which processes mailbox completion. |
| 9970 | * This function is called in the context of HBA management |
| 9971 | * applications. |
| 9972 | * This function returns MBX_SUCCESS when successful. |
| 9973 | * This function is called with no lock held. |
| 9974 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9975 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9976 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9977 | uint32_t timeout) |
| 9978 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 9979 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9980 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9981 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9982 | |
| 9983 | /* The caller must leave context1 empty. */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9984 | if (pmboxq->context1) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9985 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9986 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9987 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9988 | /* setup wake call as IOCB callback */ |
| 9989 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 9990 | /* setup context field to pass wait_queue pointer to wake function */ |
| 9991 | pmboxq->context1 = &done_q; |
| 9992 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9993 | /* now issue the command */ |
| 9994 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9995 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 9996 | wait_event_interruptible_timeout(done_q, |
| 9997 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
| 9998 | timeout * HZ); |
| 9999 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10000 | spin_lock_irqsave(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10001 | pmboxq->context1 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10002 | /* |
| 10003 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10004 | * else do not free the resources. |
| 10005 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10006 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10007 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10008 | lpfc_sli4_swap_str(phba, pmboxq); |
| 10009 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10010 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10011 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10012 | } |
| 10013 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10014 | } |
| 10015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10016 | return retval; |
| 10017 | } |
| 10018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10019 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10020 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10021 | * @phba: Pointer to HBA context. |
| 10022 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10023 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10024 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10025 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10026 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10027 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10028 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10029 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10030 | * as with offline or HBA function reset), this routine will wait for the |
| 10031 | * outstanding mailbox command to complete before invoking the mailbox |
| 10032 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10033 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10034 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10035 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10036 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10037 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10038 | unsigned long timeout; |
| 10039 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10040 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10041 | /* delay 100ms for port state */ |
| 10042 | msleep(100); |
| 10043 | lpfc_sli_mbox_sys_flush(phba); |
| 10044 | return; |
| 10045 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10046 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10047 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10048 | spin_lock_irq(&phba->hbalock); |
| 10049 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10050 | |
| 10051 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10052 | /* Determine how long we might wait for the active mailbox |
| 10053 | * command to be gracefully completed by firmware. |
| 10054 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10055 | if (phba->sli.mbox_active) |
| 10056 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10057 | phba->sli.mbox_active) * |
| 10058 | 1000) + jiffies; |
| 10059 | spin_unlock_irq(&phba->hbalock); |
| 10060 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10061 | while (phba->sli.mbox_active) { |
| 10062 | /* Check active mailbox complete status every 2ms */ |
| 10063 | msleep(2); |
| 10064 | if (time_after(jiffies, timeout)) |
| 10065 | /* Timeout, let the mailbox flush routine to |
| 10066 | * forcefully release active mailbox command |
| 10067 | */ |
| 10068 | break; |
| 10069 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10070 | } else |
| 10071 | spin_unlock_irq(&phba->hbalock); |
| 10072 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10073 | lpfc_sli_mbox_sys_flush(phba); |
| 10074 | } |
| 10075 | |
| 10076 | /** |
| 10077 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10078 | * @phba: Pointer to HBA context. |
| 10079 | * |
| 10080 | * This function is called to read the SLI3 device error attention registers |
| 10081 | * for possible error attention events. The caller must hold the hostlock |
| 10082 | * with spin_lock_irq(). |
| 10083 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10084 | * 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] | 10085 | * Register and returns 0 otherwise. |
| 10086 | **/ |
| 10087 | static int |
| 10088 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10089 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10090 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10091 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10092 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10093 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10094 | goto unplug_err; |
| 10095 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10096 | if (ha_copy & HA_ERATT) { |
| 10097 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10098 | if (lpfc_sli_read_hs(phba)) |
| 10099 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10100 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10101 | /* Check if there is a deferred error condition is active */ |
| 10102 | if ((HS_FFER1 & phba->work_hs) && |
| 10103 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10104 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10105 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10106 | /* Clear all interrupt enable conditions */ |
| 10107 | writel(0, phba->HCregaddr); |
| 10108 | readl(phba->HCregaddr); |
| 10109 | } |
| 10110 | |
| 10111 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10112 | phba->work_ha |= HA_ERATT; |
| 10113 | /* Indicate polling handles this ERATT */ |
| 10114 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10115 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10116 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10117 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10118 | |
| 10119 | unplug_err: |
| 10120 | /* Set the driver HS work bitmap */ |
| 10121 | phba->work_hs |= UNPLUG_ERR; |
| 10122 | /* Set the driver HA work bitmap */ |
| 10123 | phba->work_ha |= HA_ERATT; |
| 10124 | /* Indicate polling handles this ERATT */ |
| 10125 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10126 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10127 | } |
| 10128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10129 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10130 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10131 | * @phba: Pointer to HBA context. |
| 10132 | * |
| 10133 | * This function is called to read the SLI4 device error attention registers |
| 10134 | * for possible error attention events. The caller must hold the hostlock |
| 10135 | * with spin_lock_irq(). |
| 10136 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10137 | * 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] | 10138 | * Register and returns 0 otherwise. |
| 10139 | **/ |
| 10140 | static int |
| 10141 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10142 | { |
| 10143 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10144 | uint32_t if_type, portsmphr; |
| 10145 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10146 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10147 | /* |
| 10148 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10149 | * registers for error attention. This can be changed later. |
| 10150 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10151 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10152 | switch (if_type) { |
| 10153 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10154 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10155 | &uerr_sta_lo) || |
| 10156 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10157 | &uerr_sta_hi)) { |
| 10158 | phba->work_hs |= UNPLUG_ERR; |
| 10159 | phba->work_ha |= HA_ERATT; |
| 10160 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10161 | return 1; |
| 10162 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10163 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10164 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10165 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10166 | "1423 HBA Unrecoverable error: " |
| 10167 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10168 | "ue_mask_lo_reg=0x%x, " |
| 10169 | "ue_mask_hi_reg=0x%x\n", |
| 10170 | uerr_sta_lo, uerr_sta_hi, |
| 10171 | phba->sli4_hba.ue_mask_lo, |
| 10172 | phba->sli4_hba.ue_mask_hi); |
| 10173 | phba->work_status[0] = uerr_sta_lo; |
| 10174 | phba->work_status[1] = uerr_sta_hi; |
| 10175 | phba->work_ha |= HA_ERATT; |
| 10176 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10177 | return 1; |
| 10178 | } |
| 10179 | break; |
| 10180 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10181 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10182 | &portstat_reg.word0) || |
| 10183 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10184 | &portsmphr)){ |
| 10185 | phba->work_hs |= UNPLUG_ERR; |
| 10186 | phba->work_ha |= HA_ERATT; |
| 10187 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10188 | return 1; |
| 10189 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10190 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10191 | phba->work_status[0] = |
| 10192 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10193 | phba->work_status[1] = |
| 10194 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10195 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10196 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10197 | "port status reg 0x%x, " |
| 10198 | "port smphr reg 0x%x, " |
| 10199 | "error 1=0x%x, error 2=0x%x\n", |
| 10200 | portstat_reg.word0, |
| 10201 | portsmphr, |
| 10202 | phba->work_status[0], |
| 10203 | phba->work_status[1]); |
| 10204 | phba->work_ha |= HA_ERATT; |
| 10205 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10206 | return 1; |
| 10207 | } |
| 10208 | break; |
| 10209 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10210 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10211 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10212 | "2886 HBA Error Attention on unsupported " |
| 10213 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10214 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10215 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10216 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10217 | return 0; |
| 10218 | } |
| 10219 | |
| 10220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10221 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10222 | * @phba: Pointer to HBA context. |
| 10223 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10224 | * 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] | 10225 | * error attention register bit for error attention events. |
| 10226 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10227 | * 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] | 10228 | * Register and returns 0 otherwise. |
| 10229 | **/ |
| 10230 | int |
| 10231 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10232 | { |
| 10233 | uint32_t ha_copy; |
| 10234 | |
| 10235 | /* If somebody is waiting to handle an eratt, don't process it |
| 10236 | * here. The brdkill function will do this. |
| 10237 | */ |
| 10238 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10239 | return 0; |
| 10240 | |
| 10241 | /* Check if interrupt handler handles this ERATT */ |
| 10242 | spin_lock_irq(&phba->hbalock); |
| 10243 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10244 | /* Interrupt handler has handled ERATT */ |
| 10245 | spin_unlock_irq(&phba->hbalock); |
| 10246 | return 0; |
| 10247 | } |
| 10248 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10249 | /* |
| 10250 | * If there is deferred error attention, do not check for error |
| 10251 | * attention |
| 10252 | */ |
| 10253 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10254 | spin_unlock_irq(&phba->hbalock); |
| 10255 | return 0; |
| 10256 | } |
| 10257 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10258 | /* If PCI channel is offline, don't process it */ |
| 10259 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10260 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10261 | return 0; |
| 10262 | } |
| 10263 | |
| 10264 | switch (phba->sli_rev) { |
| 10265 | case LPFC_SLI_REV2: |
| 10266 | case LPFC_SLI_REV3: |
| 10267 | /* Read chip Host Attention (HA) register */ |
| 10268 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10269 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10270 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10271 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10272 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10273 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10274 | default: |
| 10275 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10276 | "0299 Invalid SLI revision (%d)\n", |
| 10277 | phba->sli_rev); |
| 10278 | ha_copy = 0; |
| 10279 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10280 | } |
| 10281 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10282 | |
| 10283 | return ha_copy; |
| 10284 | } |
| 10285 | |
| 10286 | /** |
| 10287 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10288 | * @phba: Pointer to HBA context. |
| 10289 | * |
| 10290 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10291 | * that the interrupt should be handled. |
| 10292 | * |
| 10293 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10294 | * interrupt should be handled, otherwise -EIO. |
| 10295 | */ |
| 10296 | static inline int |
| 10297 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10298 | { |
| 10299 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10300 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10301 | return -EIO; |
| 10302 | |
| 10303 | /* Update device level interrupt statistics */ |
| 10304 | phba->sli.slistat.sli_intr++; |
| 10305 | |
| 10306 | /* Ignore all interrupts during initialization. */ |
| 10307 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10308 | return -EIO; |
| 10309 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10310 | return 0; |
| 10311 | } |
| 10312 | |
| 10313 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10314 | * 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] | 10315 | * @irq: Interrupt number. |
| 10316 | * @dev_id: The device context pointer. |
| 10317 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10318 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10319 | * service routine when device with SLI-3 interface spec is enabled with |
| 10320 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10321 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10322 | * interrupt mode, this function is called as part of the device-level |
| 10323 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10324 | * is undergoing initialization, the interrupt handler will not process |
| 10325 | * the interrupt. The link attention and ELS ring attention events are |
| 10326 | * handled by the worker thread. The interrupt handler signals the worker |
| 10327 | * thread and returns for these events. This function is called without |
| 10328 | * 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] | 10329 | * structures. |
| 10330 | * |
| 10331 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10332 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10333 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10334 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10335 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10336 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10337 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10338 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10339 | uint32_t work_ha_copy; |
| 10340 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10341 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10342 | uint32_t control; |
| 10343 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10344 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10345 | struct lpfc_vport *vport; |
| 10346 | struct lpfc_nodelist *ndlp; |
| 10347 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10348 | LPFC_MBOXQ_t *pmb; |
| 10349 | int rc; |
| 10350 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10351 | /* |
| 10352 | * Get the driver's phba structure from the dev_id and |
| 10353 | * assume the HBA is not interrupting. |
| 10354 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10355 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10356 | |
| 10357 | if (unlikely(!phba)) |
| 10358 | return IRQ_NONE; |
| 10359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10360 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10361 | * Stuff needs to be attented to when this function is invoked as an |
| 10362 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10363 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10364 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10365 | /* Check device state for handling interrupt */ |
| 10366 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10367 | return IRQ_NONE; |
| 10368 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10369 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10370 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10371 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10372 | /* If somebody is waiting to handle an eratt don't process it |
| 10373 | * here. The brdkill function will do this. |
| 10374 | */ |
| 10375 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10376 | ha_copy &= ~HA_ERATT; |
| 10377 | /* Check the need for handling ERATT in interrupt handler */ |
| 10378 | if (ha_copy & HA_ERATT) { |
| 10379 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10380 | /* ERATT polling has handled ERATT */ |
| 10381 | ha_copy &= ~HA_ERATT; |
| 10382 | else |
| 10383 | /* Indicate interrupt handler handles ERATT */ |
| 10384 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10385 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10386 | |
| 10387 | /* |
| 10388 | * If there is deferred error attention, do not check for any |
| 10389 | * interrupt. |
| 10390 | */ |
| 10391 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10392 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10393 | return IRQ_NONE; |
| 10394 | } |
| 10395 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10396 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10397 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10398 | goto unplug_error; |
| 10399 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10400 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10401 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10402 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10403 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10404 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10405 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10406 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10407 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10408 | } else |
| 10409 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10410 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10411 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10412 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10413 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10414 | if (work_ha_copy & HA_LATT) { |
| 10415 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10416 | /* |
| 10417 | * Turn off Link Attention interrupts |
| 10418 | * until CLEAR_LA done |
| 10419 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10420 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10421 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10422 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10423 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10424 | control &= ~HC_LAINT_ENA; |
| 10425 | writel(control, phba->HCregaddr); |
| 10426 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10427 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10428 | } |
| 10429 | else |
| 10430 | work_ha_copy &= ~HA_LATT; |
| 10431 | } |
| 10432 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10433 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10434 | /* |
| 10435 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10436 | * the only slow ring. |
| 10437 | */ |
| 10438 | status = (work_ha_copy & |
| 10439 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10440 | status >>= (4*LPFC_ELS_RING); |
| 10441 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10442 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10443 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10444 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10445 | |
| 10446 | lpfc_debugfs_slow_ring_trc(phba, |
| 10447 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10448 | control, status, |
| 10449 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10450 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10451 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10452 | lpfc_debugfs_slow_ring_trc(phba, |
| 10453 | "ISR Disable ring:" |
| 10454 | "pwork:x%x hawork:x%x wait:x%x", |
| 10455 | phba->work_ha, work_ha_copy, |
| 10456 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10457 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10458 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10459 | control &= |
| 10460 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10461 | writel(control, phba->HCregaddr); |
| 10462 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10463 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10464 | else { |
| 10465 | lpfc_debugfs_slow_ring_trc(phba, |
| 10466 | "ISR slow ring: pwork:" |
| 10467 | "x%x hawork:x%x wait:x%x", |
| 10468 | phba->work_ha, work_ha_copy, |
| 10469 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10470 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10471 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10472 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10473 | } |
| 10474 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10475 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10476 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10477 | if (lpfc_sli_read_hs(phba)) |
| 10478 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10479 | /* |
| 10480 | * Check if there is a deferred error condition |
| 10481 | * is active |
| 10482 | */ |
| 10483 | if ((HS_FFER1 & phba->work_hs) && |
| 10484 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10485 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10486 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10487 | phba->hba_flag |= DEFER_ERATT; |
| 10488 | /* Clear all interrupt enable conditions */ |
| 10489 | writel(0, phba->HCregaddr); |
| 10490 | readl(phba->HCregaddr); |
| 10491 | } |
| 10492 | } |
| 10493 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10494 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10495 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10496 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10497 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10498 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10499 | |
| 10500 | /* First check out the status word */ |
| 10501 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10502 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10503 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10504 | /* |
| 10505 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10506 | * mbxStatus <status> |
| 10507 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10508 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10509 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10510 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10511 | "Interrupt mbxCommand x%x " |
| 10512 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10513 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10514 | pmbox->mbxCommand, |
| 10515 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10516 | /* clear mailbox attention bit */ |
| 10517 | work_ha_copy &= ~HA_MBATT; |
| 10518 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10519 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10520 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10521 | phba->last_completion_time = jiffies; |
| 10522 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10523 | if (pmb->mbox_cmpl) { |
| 10524 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10525 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10526 | if (pmb->out_ext_byte_len && |
| 10527 | pmb->context2) |
| 10528 | lpfc_sli_pcimem_bcopy( |
| 10529 | phba->mbox_ext, |
| 10530 | pmb->context2, |
| 10531 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10532 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10533 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10534 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10535 | |
| 10536 | lpfc_debugfs_disc_trc(vport, |
| 10537 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10538 | "MBOX dflt rpi: : " |
| 10539 | "status:x%x rpi:x%x", |
| 10540 | (uint32_t)pmbox->mbxStatus, |
| 10541 | pmbox->un.varWords[0], 0); |
| 10542 | |
| 10543 | if (!pmbox->mbxStatus) { |
| 10544 | mp = (struct lpfc_dmabuf *) |
| 10545 | (pmb->context1); |
| 10546 | ndlp = (struct lpfc_nodelist *) |
| 10547 | pmb->context2; |
| 10548 | |
| 10549 | /* Reg_LOGIN of dflt RPI was |
| 10550 | * successful. new lets get |
| 10551 | * rid of the RPI using the |
| 10552 | * same mbox buffer. |
| 10553 | */ |
| 10554 | lpfc_unreg_login(phba, |
| 10555 | vport->vpi, |
| 10556 | pmbox->un.varWords[0], |
| 10557 | pmb); |
| 10558 | pmb->mbox_cmpl = |
| 10559 | lpfc_mbx_cmpl_dflt_rpi; |
| 10560 | pmb->context1 = mp; |
| 10561 | pmb->context2 = ndlp; |
| 10562 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10563 | rc = lpfc_sli_issue_mbox(phba, |
| 10564 | pmb, |
| 10565 | MBX_NOWAIT); |
| 10566 | if (rc != MBX_BUSY) |
| 10567 | lpfc_printf_log(phba, |
| 10568 | KERN_ERR, |
| 10569 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10570 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10571 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10572 | if (rc != MBX_NOT_FINISHED) |
| 10573 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10574 | } |
| 10575 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10576 | spin_lock_irqsave( |
| 10577 | &phba->pport->work_port_lock, |
| 10578 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10579 | phba->pport->work_port_events &= |
| 10580 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10581 | spin_unlock_irqrestore( |
| 10582 | &phba->pport->work_port_lock, |
| 10583 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10584 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10585 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10586 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10587 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10588 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10589 | if ((work_ha_copy & HA_MBATT) && |
| 10590 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10591 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10592 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10593 | do { |
| 10594 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10595 | MBX_NOWAIT); |
| 10596 | } while (rc == MBX_NOT_FINISHED); |
| 10597 | if (rc != MBX_SUCCESS) |
| 10598 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10599 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10600 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10601 | } |
| 10602 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10603 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10604 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10605 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10606 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10607 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10608 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10609 | unplug_error: |
| 10610 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10611 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10612 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10613 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10614 | |
| 10615 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10616 | * 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] | 10617 | * @irq: Interrupt number. |
| 10618 | * @dev_id: The device context pointer. |
| 10619 | * |
| 10620 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10621 | * service routine when device with SLI-3 interface spec is enabled with |
| 10622 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10623 | * ring event in the HBA. However, when the device is enabled with either |
| 10624 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10625 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10626 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10627 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10628 | * the intrrupt context. This function is called without any lock held. |
| 10629 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10630 | * |
| 10631 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10632 | * returns IRQ_NONE. |
| 10633 | **/ |
| 10634 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10635 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10636 | { |
| 10637 | struct lpfc_hba *phba; |
| 10638 | uint32_t ha_copy; |
| 10639 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10640 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10641 | |
| 10642 | /* Get the driver's phba structure from the dev_id and |
| 10643 | * assume the HBA is not interrupting. |
| 10644 | */ |
| 10645 | phba = (struct lpfc_hba *) dev_id; |
| 10646 | |
| 10647 | if (unlikely(!phba)) |
| 10648 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10649 | |
| 10650 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10651 | * Stuff needs to be attented to when this function is invoked as an |
| 10652 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10653 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10654 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10655 | /* Check device state for handling interrupt */ |
| 10656 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10657 | return IRQ_NONE; |
| 10658 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10659 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10660 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10661 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10662 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10663 | /* |
| 10664 | * If there is deferred error attention, do not check for |
| 10665 | * any interrupt. |
| 10666 | */ |
| 10667 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10668 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10669 | return IRQ_NONE; |
| 10670 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10671 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10672 | phba->HAregaddr); |
| 10673 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10674 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10675 | } else |
| 10676 | ha_copy = phba->ha_copy; |
| 10677 | |
| 10678 | /* |
| 10679 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10680 | */ |
| 10681 | ha_copy &= ~(phba->work_ha_mask); |
| 10682 | |
| 10683 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10684 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10685 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10686 | lpfc_sli_handle_fast_ring_event(phba, |
| 10687 | &phba->sli.ring[LPFC_FCP_RING], |
| 10688 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10689 | |
| 10690 | if (phba->cfg_multi_ring_support == 2) { |
| 10691 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10692 | * Process all events on extra ring. Take the optimized path |
| 10693 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10694 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10695 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10696 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10697 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10698 | lpfc_sli_handle_fast_ring_event(phba, |
| 10699 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 10700 | status); |
| 10701 | } |
| 10702 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10703 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10704 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10705 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10706 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10707 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10708 | * @irq: Interrupt number. |
| 10709 | * @dev_id: The device context pointer. |
| 10710 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10711 | * This function is the HBA device-level interrupt handler to device with |
| 10712 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 10713 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 10714 | * requires driver attention. This function invokes the slow-path interrupt |
| 10715 | * attention handling function and fast-path interrupt attention handling |
| 10716 | * function in turn to process the relevant HBA attention events. This |
| 10717 | * function is called without any lock held. It gets the hbalock to access |
| 10718 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10719 | * |
| 10720 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 10721 | * returns IRQ_NONE. |
| 10722 | **/ |
| 10723 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10724 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10725 | { |
| 10726 | struct lpfc_hba *phba; |
| 10727 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 10728 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10729 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10730 | |
| 10731 | /* |
| 10732 | * Get the driver's phba structure from the dev_id and |
| 10733 | * assume the HBA is not interrupting. |
| 10734 | */ |
| 10735 | phba = (struct lpfc_hba *) dev_id; |
| 10736 | |
| 10737 | if (unlikely(!phba)) |
| 10738 | return IRQ_NONE; |
| 10739 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10740 | /* Check device state for handling interrupt */ |
| 10741 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10742 | return IRQ_NONE; |
| 10743 | |
| 10744 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10745 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 10746 | spin_unlock(&phba->hbalock); |
| 10747 | return IRQ_HANDLED; |
| 10748 | } |
| 10749 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10750 | if (unlikely(!phba->ha_copy)) { |
| 10751 | spin_unlock(&phba->hbalock); |
| 10752 | return IRQ_NONE; |
| 10753 | } else if (phba->ha_copy & HA_ERATT) { |
| 10754 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10755 | /* ERATT polling has handled ERATT */ |
| 10756 | phba->ha_copy &= ~HA_ERATT; |
| 10757 | else |
| 10758 | /* Indicate interrupt handler handles ERATT */ |
| 10759 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10760 | } |
| 10761 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10762 | /* |
| 10763 | * If there is deferred error attention, do not check for any interrupt. |
| 10764 | */ |
| 10765 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 10766 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10767 | return IRQ_NONE; |
| 10768 | } |
| 10769 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10770 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10771 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 10772 | spin_unlock(&phba->hbalock); |
| 10773 | return IRQ_HANDLED; |
| 10774 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10775 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 10776 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10777 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10778 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10779 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10780 | readl(phba->HAregaddr); /* flush */ |
| 10781 | spin_unlock(&phba->hbalock); |
| 10782 | |
| 10783 | /* |
| 10784 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 10785 | */ |
| 10786 | |
| 10787 | /* status of events with mailbox and link attention */ |
| 10788 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 10789 | |
| 10790 | /* status of events with ELS ring */ |
| 10791 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10792 | status2 >>= (4*LPFC_ELS_RING); |
| 10793 | |
| 10794 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10795 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10796 | else |
| 10797 | sp_irq_rc = IRQ_NONE; |
| 10798 | |
| 10799 | /* |
| 10800 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 10801 | */ |
| 10802 | |
| 10803 | /* status of events with FCP ring */ |
| 10804 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 10805 | status1 >>= (4*LPFC_FCP_RING); |
| 10806 | |
| 10807 | /* status of events with extra ring */ |
| 10808 | if (phba->cfg_multi_ring_support == 2) { |
| 10809 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 10810 | status2 >>= (4*LPFC_EXTRA_RING); |
| 10811 | } else |
| 10812 | status2 = 0; |
| 10813 | |
| 10814 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10815 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10816 | else |
| 10817 | fp_irq_rc = IRQ_NONE; |
| 10818 | |
| 10819 | /* Return device-level interrupt handling status */ |
| 10820 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10821 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10822 | |
| 10823 | /** |
| 10824 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 10825 | * @phba: pointer to lpfc hba data structure. |
| 10826 | * |
| 10827 | * This routine is invoked by the worker thread to process all the pending |
| 10828 | * SLI4 FCP abort XRI events. |
| 10829 | **/ |
| 10830 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10831 | { |
| 10832 | struct lpfc_cq_event *cq_event; |
| 10833 | |
| 10834 | /* First, declare the fcp xri abort event has been handled */ |
| 10835 | spin_lock_irq(&phba->hbalock); |
| 10836 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 10837 | spin_unlock_irq(&phba->hbalock); |
| 10838 | /* Now, handle all the fcp xri abort events */ |
| 10839 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 10840 | /* Get the first event from the head of the event queue */ |
| 10841 | spin_lock_irq(&phba->hbalock); |
| 10842 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10843 | cq_event, struct lpfc_cq_event, list); |
| 10844 | spin_unlock_irq(&phba->hbalock); |
| 10845 | /* Notify aborted XRI for FCP work queue */ |
| 10846 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10847 | /* Free the event processed back to the free pool */ |
| 10848 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10849 | } |
| 10850 | } |
| 10851 | |
| 10852 | /** |
| 10853 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 10854 | * @phba: pointer to lpfc hba data structure. |
| 10855 | * |
| 10856 | * This routine is invoked by the worker thread to process all the pending |
| 10857 | * SLI4 els abort xri events. |
| 10858 | **/ |
| 10859 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 10860 | { |
| 10861 | struct lpfc_cq_event *cq_event; |
| 10862 | |
| 10863 | /* First, declare the els xri abort event has been handled */ |
| 10864 | spin_lock_irq(&phba->hbalock); |
| 10865 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 10866 | spin_unlock_irq(&phba->hbalock); |
| 10867 | /* Now, handle all the els xri abort events */ |
| 10868 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 10869 | /* Get the first event from the head of the event queue */ |
| 10870 | spin_lock_irq(&phba->hbalock); |
| 10871 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10872 | cq_event, struct lpfc_cq_event, list); |
| 10873 | spin_unlock_irq(&phba->hbalock); |
| 10874 | /* Notify aborted XRI for ELS work queue */ |
| 10875 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 10876 | /* Free the event processed back to the free pool */ |
| 10877 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 10878 | } |
| 10879 | } |
| 10880 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10881 | /** |
| 10882 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 10883 | * @phba: pointer to lpfc hba data structure |
| 10884 | * @pIocbIn: pointer to the rspiocbq |
| 10885 | * @pIocbOut: pointer to the cmdiocbq |
| 10886 | * @wcqe: pointer to the complete wcqe |
| 10887 | * |
| 10888 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 10889 | * by copying all the IOCB fields from command iocbq and transferring the |
| 10890 | * completion status information from the complete wcqe. |
| 10891 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10892 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10893 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 10894 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10895 | struct lpfc_iocbq *pIocbOut, |
| 10896 | struct lpfc_wcqe_complete *wcqe) |
| 10897 | { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10898 | unsigned long iflags; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10899 | uint32_t status; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10900 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 10901 | |
| 10902 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 10903 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10904 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10905 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 10906 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10907 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 10908 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 10909 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 10910 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 10911 | wcqe->total_data_placed; |
| 10912 | else |
| 10913 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10914 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10915 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 10916 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
| 10917 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10918 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 10919 | /* Convert BG errors for completion status */ |
| 10920 | if (status == CQE_STATUS_DI_ERROR) { |
| 10921 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 10922 | |
| 10923 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 10924 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 10925 | else |
| 10926 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 10927 | |
| 10928 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 10929 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 10930 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10931 | BGS_GUARD_ERR_MASK; |
| 10932 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 10933 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10934 | BGS_APPTAG_ERR_MASK; |
| 10935 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 10936 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10937 | BGS_REFTAG_ERR_MASK; |
| 10938 | |
| 10939 | /* Check to see if there was any good data before the error */ |
| 10940 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 10941 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10942 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 10943 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 10944 | wcqe->total_data_placed; |
| 10945 | } |
| 10946 | |
| 10947 | /* |
| 10948 | * Set ALL the error bits to indicate we don't know what |
| 10949 | * type of error it is. |
| 10950 | */ |
| 10951 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 10952 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 10953 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 10954 | BGS_GUARD_ERR_MASK); |
| 10955 | } |
| 10956 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10957 | /* Pick up HBA exchange busy condition */ |
| 10958 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 10959 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10960 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 10961 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10962 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10963 | } |
| 10964 | |
| 10965 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10966 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 10967 | * @phba: Pointer to HBA context object. |
| 10968 | * @wcqe: Pointer to work-queue completion queue entry. |
| 10969 | * |
| 10970 | * This routine handles an ELS work-queue completion event and construct |
| 10971 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 10972 | * discovery engine to handle. |
| 10973 | * |
| 10974 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 10975 | **/ |
| 10976 | static struct lpfc_iocbq * |
| 10977 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 10978 | struct lpfc_iocbq *irspiocbq) |
| 10979 | { |
| 10980 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 10981 | struct lpfc_iocbq *cmdiocbq; |
| 10982 | struct lpfc_wcqe_complete *wcqe; |
| 10983 | unsigned long iflags; |
| 10984 | |
| 10985 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10986 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10987 | pring->stats.iocb_event++; |
| 10988 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 10989 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 10990 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10991 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10992 | |
| 10993 | if (unlikely(!cmdiocbq)) { |
| 10994 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10995 | "0386 ELS complete with no corresponding " |
| 10996 | "cmdiocb: iotag (%d)\n", |
| 10997 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 10998 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 10999 | return NULL; |
| 11000 | } |
| 11001 | |
| 11002 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11003 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11004 | |
| 11005 | return irspiocbq; |
| 11006 | } |
| 11007 | |
| 11008 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11009 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11010 | * @phba: Pointer to HBA context object. |
| 11011 | * @cqe: Pointer to mailbox completion queue entry. |
| 11012 | * |
| 11013 | * This routine process a mailbox completion queue entry with asynchrous |
| 11014 | * event. |
| 11015 | * |
| 11016 | * Return: true if work posted to worker thread, otherwise false. |
| 11017 | **/ |
| 11018 | static bool |
| 11019 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11020 | { |
| 11021 | struct lpfc_cq_event *cq_event; |
| 11022 | unsigned long iflags; |
| 11023 | |
| 11024 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11025 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11026 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11027 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11028 | |
| 11029 | /* Allocate a new internal CQ_EVENT entry */ |
| 11030 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11031 | if (!cq_event) { |
| 11032 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11033 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11034 | return false; |
| 11035 | } |
| 11036 | |
| 11037 | /* Move the CQE into an asynchronous event entry */ |
| 11038 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11039 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11040 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11041 | /* Set the async event flag */ |
| 11042 | phba->hba_flag |= ASYNC_EVENT; |
| 11043 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11044 | |
| 11045 | return true; |
| 11046 | } |
| 11047 | |
| 11048 | /** |
| 11049 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11050 | * @phba: Pointer to HBA context object. |
| 11051 | * @cqe: Pointer to mailbox completion queue entry. |
| 11052 | * |
| 11053 | * This routine process a mailbox completion queue entry with mailbox |
| 11054 | * completion event. |
| 11055 | * |
| 11056 | * Return: true if work posted to worker thread, otherwise false. |
| 11057 | **/ |
| 11058 | static bool |
| 11059 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11060 | { |
| 11061 | uint32_t mcqe_status; |
| 11062 | MAILBOX_t *mbox, *pmbox; |
| 11063 | struct lpfc_mqe *mqe; |
| 11064 | struct lpfc_vport *vport; |
| 11065 | struct lpfc_nodelist *ndlp; |
| 11066 | struct lpfc_dmabuf *mp; |
| 11067 | unsigned long iflags; |
| 11068 | LPFC_MBOXQ_t *pmb; |
| 11069 | bool workposted = false; |
| 11070 | int rc; |
| 11071 | |
| 11072 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11073 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11074 | goto out_no_mqe_complete; |
| 11075 | |
| 11076 | /* Get the reference to the active mbox command */ |
| 11077 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11078 | pmb = phba->sli.mbox_active; |
| 11079 | if (unlikely(!pmb)) { |
| 11080 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11081 | "1832 No pending MBOX command to handle\n"); |
| 11082 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11083 | goto out_no_mqe_complete; |
| 11084 | } |
| 11085 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11086 | mqe = &pmb->u.mqe; |
| 11087 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11088 | mbox = phba->mbox; |
| 11089 | vport = pmb->vport; |
| 11090 | |
| 11091 | /* Reset heartbeat timer */ |
| 11092 | phba->last_completion_time = jiffies; |
| 11093 | del_timer(&phba->sli.mbox_tmo); |
| 11094 | |
| 11095 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11096 | if (pmb->mbox_cmpl && mbox) |
| 11097 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11098 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11099 | /* |
| 11100 | * For mcqe errors, conditionally move a modified error code to |
| 11101 | * the mbox so that the error will not be missed. |
| 11102 | */ |
| 11103 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11104 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11105 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11106 | bf_set(lpfc_mqe_status, mqe, |
| 11107 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11108 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11109 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11110 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11111 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11112 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11113 | mcqe_status, |
| 11114 | pmbox->un.varWords[0], 0); |
| 11115 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11116 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11117 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11118 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11119 | * RID of the PPI using the same mbox buffer. |
| 11120 | */ |
| 11121 | lpfc_unreg_login(phba, vport->vpi, |
| 11122 | pmbox->un.varWords[0], pmb); |
| 11123 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11124 | pmb->context1 = mp; |
| 11125 | pmb->context2 = ndlp; |
| 11126 | pmb->vport = vport; |
| 11127 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11128 | if (rc != MBX_BUSY) |
| 11129 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11130 | LOG_SLI, "0385 rc should " |
| 11131 | "have been MBX_BUSY\n"); |
| 11132 | if (rc != MBX_NOT_FINISHED) |
| 11133 | goto send_current_mbox; |
| 11134 | } |
| 11135 | } |
| 11136 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11137 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11138 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11139 | |
| 11140 | /* There is mailbox completion work to do */ |
| 11141 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11142 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11143 | phba->work_ha |= HA_MBATT; |
| 11144 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11145 | workposted = true; |
| 11146 | |
| 11147 | send_current_mbox: |
| 11148 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11149 | /* Release the mailbox command posting token */ |
| 11150 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11151 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11152 | phba->sli.mbox_active = NULL; |
| 11153 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11154 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11155 | lpfc_worker_wake_up(phba); |
| 11156 | out_no_mqe_complete: |
| 11157 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11158 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11159 | return workposted; |
| 11160 | } |
| 11161 | |
| 11162 | /** |
| 11163 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11164 | * @phba: Pointer to HBA context object. |
| 11165 | * @cqe: Pointer to mailbox completion queue entry. |
| 11166 | * |
| 11167 | * This routine process a mailbox completion queue entry, it invokes the |
| 11168 | * proper mailbox complete handling or asynchrous event handling routine |
| 11169 | * according to the MCQE's async bit. |
| 11170 | * |
| 11171 | * Return: true if work posted to worker thread, otherwise false. |
| 11172 | **/ |
| 11173 | static bool |
| 11174 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11175 | { |
| 11176 | struct lpfc_mcqe mcqe; |
| 11177 | bool workposted; |
| 11178 | |
| 11179 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11180 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11181 | |
| 11182 | /* Invoke the proper event handling routine */ |
| 11183 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11184 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11185 | else |
| 11186 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11187 | return workposted; |
| 11188 | } |
| 11189 | |
| 11190 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11191 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11192 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11193 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11194 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11195 | * |
| 11196 | * This routine handles an ELS work-queue completion event. |
| 11197 | * |
| 11198 | * Return: true if work posted to worker thread, otherwise false. |
| 11199 | **/ |
| 11200 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11201 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11202 | struct lpfc_wcqe_complete *wcqe) |
| 11203 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11204 | struct lpfc_iocbq *irspiocbq; |
| 11205 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11206 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11207 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11208 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11209 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11210 | if (!irspiocbq) { |
| 11211 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11212 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11213 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
| 11214 | pring->txq_cnt, phba->iocb_cnt, |
| 11215 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, |
| 11216 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11217 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11218 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11219 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11220 | /* Save off the slow-path queue event for work thread to process */ |
| 11221 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11222 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11223 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11224 | &phba->sli4_hba.sp_queue_event); |
| 11225 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11226 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11227 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11228 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11229 | } |
| 11230 | |
| 11231 | /** |
| 11232 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11233 | * @phba: Pointer to HBA context object. |
| 11234 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11235 | * |
| 11236 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11237 | * proper WQ release routine to the slow-path WQ. |
| 11238 | **/ |
| 11239 | static void |
| 11240 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11241 | struct lpfc_wcqe_release *wcqe) |
| 11242 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11243 | /* sanity check on queue memory */ |
| 11244 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11245 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11246 | /* Check for the slow-path ELS work queue */ |
| 11247 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11248 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11249 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11250 | else |
| 11251 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11252 | "2579 Slow-path wqe consume event carries " |
| 11253 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11254 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11255 | phba->sli4_hba.els_wq->queue_id); |
| 11256 | } |
| 11257 | |
| 11258 | /** |
| 11259 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11260 | * @phba: Pointer to HBA context object. |
| 11261 | * @cq: Pointer to a WQ completion queue. |
| 11262 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11263 | * |
| 11264 | * This routine handles an XRI abort event. |
| 11265 | * |
| 11266 | * Return: true if work posted to worker thread, otherwise false. |
| 11267 | **/ |
| 11268 | static bool |
| 11269 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11270 | struct lpfc_queue *cq, |
| 11271 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11272 | { |
| 11273 | bool workposted = false; |
| 11274 | struct lpfc_cq_event *cq_event; |
| 11275 | unsigned long iflags; |
| 11276 | |
| 11277 | /* Allocate a new internal CQ_EVENT entry */ |
| 11278 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11279 | if (!cq_event) { |
| 11280 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11281 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11282 | return false; |
| 11283 | } |
| 11284 | |
| 11285 | /* Move the CQE into the proper xri abort event list */ |
| 11286 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11287 | switch (cq->subtype) { |
| 11288 | case LPFC_FCP: |
| 11289 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11290 | list_add_tail(&cq_event->list, |
| 11291 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11292 | /* Set the fcp xri abort event flag */ |
| 11293 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11294 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11295 | workposted = true; |
| 11296 | break; |
| 11297 | case LPFC_ELS: |
| 11298 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11299 | list_add_tail(&cq_event->list, |
| 11300 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11301 | /* Set the els xri abort event flag */ |
| 11302 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11303 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11304 | workposted = true; |
| 11305 | break; |
| 11306 | default: |
| 11307 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11308 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11309 | cq->subtype); |
| 11310 | workposted = false; |
| 11311 | break; |
| 11312 | } |
| 11313 | return workposted; |
| 11314 | } |
| 11315 | |
| 11316 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11317 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11318 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11319 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11320 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11321 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11322 | * |
| 11323 | * Return: true if work posted to worker thread, otherwise false. |
| 11324 | **/ |
| 11325 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11326 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11327 | { |
| 11328 | bool workposted = false; |
| 11329 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11330 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11331 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11332 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11333 | unsigned long iflags; |
| 11334 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11335 | /* sanity check on queue memory */ |
| 11336 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11337 | return workposted; |
| 11338 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11339 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11340 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11341 | else |
| 11342 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11343 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11344 | goto out; |
| 11345 | |
| 11346 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11347 | switch (status) { |
| 11348 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11349 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11350 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11351 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11352 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11353 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11354 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11355 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11356 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11357 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11358 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11359 | goto out; |
| 11360 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11361 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11362 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11363 | /* save off the frame for the word thread to process */ |
| 11364 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11365 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11366 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11367 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11368 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11369 | workposted = true; |
| 11370 | break; |
| 11371 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11372 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11373 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11374 | /* Post more buffers if possible */ |
| 11375 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11376 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11377 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11378 | workposted = true; |
| 11379 | break; |
| 11380 | } |
| 11381 | out: |
| 11382 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11383 | } |
| 11384 | |
| 11385 | /** |
| 11386 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11387 | * @phba: Pointer to HBA context object. |
| 11388 | * @cq: Pointer to the completion queue. |
| 11389 | * @wcqe: Pointer to a completion queue entry. |
| 11390 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11391 | * 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] | 11392 | * entry. |
| 11393 | * |
| 11394 | * Return: true if work posted to worker thread, otherwise false. |
| 11395 | **/ |
| 11396 | static bool |
| 11397 | 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] | 11398 | struct lpfc_cqe *cqe) |
| 11399 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11400 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11401 | bool workposted = false; |
| 11402 | |
| 11403 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11404 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11405 | |
| 11406 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11407 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11408 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11409 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11410 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11411 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11412 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11413 | break; |
| 11414 | case CQE_CODE_RELEASE_WQE: |
| 11415 | /* Process the WQ release event */ |
| 11416 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11417 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11418 | break; |
| 11419 | case CQE_CODE_XRI_ABORTED: |
| 11420 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11421 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11422 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11423 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11424 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11425 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11426 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11427 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11428 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11429 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11430 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11431 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11432 | default: |
| 11433 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11434 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11435 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11436 | break; |
| 11437 | } |
| 11438 | return workposted; |
| 11439 | } |
| 11440 | |
| 11441 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11442 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11443 | * @phba: Pointer to HBA context object. |
| 11444 | * @eqe: Pointer to fast-path event queue entry. |
| 11445 | * |
| 11446 | * This routine process a event queue entry from the slow-path event queue. |
| 11447 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11448 | * completion event on a completion queue, if not, an error shall be logged |
| 11449 | * and just return. Otherwise, it will get to the corresponding completion |
| 11450 | * queue and process all the entries on that completion queue, rearm the |
| 11451 | * completion queue, and then return. |
| 11452 | * |
| 11453 | **/ |
| 11454 | static void |
| 11455 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 11456 | { |
| 11457 | struct lpfc_queue *cq = NULL, *childq, *speq; |
| 11458 | struct lpfc_cqe *cqe; |
| 11459 | bool workposted = false; |
| 11460 | int ecount = 0; |
| 11461 | uint16_t cqid; |
| 11462 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11463 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11464 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11465 | "0359 Not a valid slow-path completion " |
| 11466 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11467 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11468 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11469 | return; |
| 11470 | } |
| 11471 | |
| 11472 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11473 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11474 | |
| 11475 | /* Search for completion queue pointer matching this cqid */ |
| 11476 | speq = phba->sli4_hba.sp_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11477 | /* sanity check on queue memory */ |
| 11478 | if (unlikely(!speq)) |
| 11479 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11480 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11481 | if (childq->queue_id == cqid) { |
| 11482 | cq = childq; |
| 11483 | break; |
| 11484 | } |
| 11485 | } |
| 11486 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11487 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11488 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11489 | "0365 Slow-path CQ identifier " |
| 11490 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11491 | return; |
| 11492 | } |
| 11493 | |
| 11494 | /* Process all the entries to the CQ */ |
| 11495 | switch (cq->type) { |
| 11496 | case LPFC_MCQ: |
| 11497 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11498 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11499 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11500 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11501 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11502 | } |
| 11503 | break; |
| 11504 | case LPFC_WCQ: |
| 11505 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11506 | if (cq->subtype == LPFC_FCP) |
| 11507 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11508 | cqe); |
| 11509 | else |
| 11510 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11511 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11512 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11513 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11514 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11515 | |
| 11516 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11517 | if (ecount > cq->CQ_max_cqe) |
| 11518 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11519 | break; |
| 11520 | default: |
| 11521 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11522 | "0370 Invalid completion queue type (%d)\n", |
| 11523 | cq->type); |
| 11524 | return; |
| 11525 | } |
| 11526 | |
| 11527 | /* Catch the no cq entry condition, log an error */ |
| 11528 | if (unlikely(ecount == 0)) |
| 11529 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11530 | "0371 No entry from the CQ: identifier " |
| 11531 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11532 | |
| 11533 | /* In any case, flash and re-arm the RCQ */ |
| 11534 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11535 | |
| 11536 | /* wake up worker thread if there are works to be done */ |
| 11537 | if (workposted) |
| 11538 | lpfc_worker_wake_up(phba); |
| 11539 | } |
| 11540 | |
| 11541 | /** |
| 11542 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11543 | * @phba: Pointer to HBA context object. |
| 11544 | * @cq: Pointer to associated CQ |
| 11545 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11546 | * |
| 11547 | * This routine process a fast-path work queue completion entry from fast-path |
| 11548 | * event queue for FCP command response completion. |
| 11549 | **/ |
| 11550 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11551 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11552 | struct lpfc_wcqe_complete *wcqe) |
| 11553 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11554 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11555 | struct lpfc_iocbq *cmdiocbq; |
| 11556 | struct lpfc_iocbq irspiocbq; |
| 11557 | unsigned long iflags; |
| 11558 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11559 | /* Check for response status */ |
| 11560 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11561 | /* If resource errors reported from HBA, reduce queue |
| 11562 | * depth of the SCSI device. |
| 11563 | */ |
| 11564 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11565 | IOSTAT_LOCAL_REJECT) && |
| 11566 | (wcqe->parameter == IOERR_NO_RESOURCES)) { |
| 11567 | phba->lpfc_rampdown_queue_depth(phba); |
| 11568 | } |
| 11569 | /* Log the error status */ |
| 11570 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11571 | "0373 FCP complete error: status=x%x, " |
| 11572 | "hw_status=x%x, total_data_specified=%d, " |
| 11573 | "parameter=x%x, word3=x%x\n", |
| 11574 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11575 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11576 | wcqe->total_data_placed, wcqe->parameter, |
| 11577 | wcqe->word3); |
| 11578 | } |
| 11579 | |
| 11580 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11581 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11582 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11583 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11584 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11585 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11586 | if (unlikely(!cmdiocbq)) { |
| 11587 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11588 | "0374 FCP complete with no corresponding " |
| 11589 | "cmdiocb: iotag (%d)\n", |
| 11590 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11591 | return; |
| 11592 | } |
| 11593 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11594 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11595 | "0375 FCP cmdiocb not callback function " |
| 11596 | "iotag: (%d)\n", |
| 11597 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11598 | return; |
| 11599 | } |
| 11600 | |
| 11601 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11602 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11603 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11604 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11605 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11606 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11607 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11608 | } |
| 11609 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11610 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11611 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11612 | } |
| 11613 | |
| 11614 | /** |
| 11615 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11616 | * @phba: Pointer to HBA context object. |
| 11617 | * @cq: Pointer to completion queue. |
| 11618 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11619 | * |
| 11620 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11621 | * proper WQ release routine to the slow-path WQ. |
| 11622 | **/ |
| 11623 | static void |
| 11624 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11625 | struct lpfc_wcqe_release *wcqe) |
| 11626 | { |
| 11627 | struct lpfc_queue *childwq; |
| 11628 | bool wqid_matched = false; |
| 11629 | uint16_t fcp_wqid; |
| 11630 | |
| 11631 | /* Check for fast-path FCP work queue release */ |
| 11632 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11633 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11634 | if (childwq->queue_id == fcp_wqid) { |
| 11635 | lpfc_sli4_wq_release(childwq, |
| 11636 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11637 | wqid_matched = true; |
| 11638 | break; |
| 11639 | } |
| 11640 | } |
| 11641 | /* Report warning log message if no match found */ |
| 11642 | if (wqid_matched != true) |
| 11643 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11644 | "2580 Fast-path wqe consume event carries " |
| 11645 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11646 | } |
| 11647 | |
| 11648 | /** |
| 11649 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11650 | * @cq: Pointer to the completion queue. |
| 11651 | * @eqe: Pointer to fast-path completion queue entry. |
| 11652 | * |
| 11653 | * This routine process a fast-path work queue completion entry from fast-path |
| 11654 | * event queue for FCP command response completion. |
| 11655 | **/ |
| 11656 | static int |
| 11657 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11658 | struct lpfc_cqe *cqe) |
| 11659 | { |
| 11660 | struct lpfc_wcqe_release wcqe; |
| 11661 | bool workposted = false; |
| 11662 | |
| 11663 | /* Copy the work queue CQE and convert endian order if needed */ |
| 11664 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 11665 | |
| 11666 | /* Check and process for different type of WCQE and dispatch */ |
| 11667 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 11668 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11669 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11670 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11671 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame^] | 11672 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11673 | (struct lpfc_wcqe_complete *)&wcqe); |
| 11674 | break; |
| 11675 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11676 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11677 | /* Process the WQ release event */ |
| 11678 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 11679 | (struct lpfc_wcqe_release *)&wcqe); |
| 11680 | break; |
| 11681 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11682 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11683 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11684 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11685 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 11686 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 11687 | break; |
| 11688 | default: |
| 11689 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11690 | "0144 Not a valid WCQE code: x%x\n", |
| 11691 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 11692 | break; |
| 11693 | } |
| 11694 | return workposted; |
| 11695 | } |
| 11696 | |
| 11697 | /** |
| 11698 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry |
| 11699 | * @phba: Pointer to HBA context object. |
| 11700 | * @eqe: Pointer to fast-path event queue entry. |
| 11701 | * |
| 11702 | * This routine process a event queue entry from the fast-path event queue. |
| 11703 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11704 | * completion event on a completion queue, if not, an error shall be logged |
| 11705 | * and just return. Otherwise, it will get to the corresponding completion |
| 11706 | * queue and process all the entries on the completion queue, rearm the |
| 11707 | * completion queue, and then return. |
| 11708 | **/ |
| 11709 | static void |
| 11710 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11711 | uint32_t fcp_cqidx) |
| 11712 | { |
| 11713 | struct lpfc_queue *cq; |
| 11714 | struct lpfc_cqe *cqe; |
| 11715 | bool workposted = false; |
| 11716 | uint16_t cqid; |
| 11717 | int ecount = 0; |
| 11718 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11719 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11720 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11721 | "0366 Not a valid fast-path completion " |
| 11722 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11723 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 11724 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11725 | return; |
| 11726 | } |
| 11727 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11728 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 11729 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11730 | "3146 Fast-path completion queues " |
| 11731 | "does not exist\n"); |
| 11732 | return; |
| 11733 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11734 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; |
| 11735 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11736 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11737 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11738 | "0367 Fast-path completion queue " |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11739 | "(%d) does not exist\n", fcp_cqidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11740 | return; |
| 11741 | } |
| 11742 | |
| 11743 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11744 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11745 | if (unlikely(cqid != cq->queue_id)) { |
| 11746 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11747 | "0368 Miss-matched fast-path completion " |
| 11748 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 11749 | cqid, cq->queue_id); |
| 11750 | return; |
| 11751 | } |
| 11752 | |
| 11753 | /* Process all the entries to the CQ */ |
| 11754 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11755 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11756 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11757 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11758 | } |
| 11759 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11760 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11761 | if (ecount > cq->CQ_max_cqe) |
| 11762 | cq->CQ_max_cqe = ecount; |
| 11763 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11764 | /* Catch the no cq entry condition */ |
| 11765 | if (unlikely(ecount == 0)) |
| 11766 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11767 | "0369 No entry from fast-path completion " |
| 11768 | "queue fcpcqid=%d\n", cq->queue_id); |
| 11769 | |
| 11770 | /* In any case, flash and re-arm the CQ */ |
| 11771 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11772 | |
| 11773 | /* wake up worker thread if there are works to be done */ |
| 11774 | if (workposted) |
| 11775 | lpfc_worker_wake_up(phba); |
| 11776 | } |
| 11777 | |
| 11778 | static void |
| 11779 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 11780 | { |
| 11781 | struct lpfc_eqe *eqe; |
| 11782 | |
| 11783 | /* walk all the EQ entries and drop on the floor */ |
| 11784 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 11785 | ; |
| 11786 | |
| 11787 | /* Clear and re-arm the EQ */ |
| 11788 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 11789 | } |
| 11790 | |
| 11791 | /** |
| 11792 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device |
| 11793 | * @irq: Interrupt number. |
| 11794 | * @dev_id: The device context pointer. |
| 11795 | * |
| 11796 | * This function is directly called from the PCI layer as an interrupt |
| 11797 | * service routine when device with SLI-4 interface spec is enabled with |
| 11798 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11799 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11800 | * interrupt mode, this function is called as part of the device-level |
| 11801 | * interrupt handler. When the PCI slot is in error recovery or the HBA is |
| 11802 | * undergoing initialization, the interrupt handler will not process the |
| 11803 | * interrupt. The link attention and ELS ring attention events are handled |
| 11804 | * by the worker thread. The interrupt handler signals the worker thread |
| 11805 | * and returns for these events. This function is called without any lock |
| 11806 | * held. It gets the hbalock to access and update SLI data structures. |
| 11807 | * |
| 11808 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11809 | * returns IRQ_NONE. |
| 11810 | **/ |
| 11811 | irqreturn_t |
| 11812 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) |
| 11813 | { |
| 11814 | struct lpfc_hba *phba; |
| 11815 | struct lpfc_queue *speq; |
| 11816 | struct lpfc_eqe *eqe; |
| 11817 | unsigned long iflag; |
| 11818 | int ecount = 0; |
| 11819 | |
| 11820 | /* |
| 11821 | * Get the driver's phba structure from the dev_id |
| 11822 | */ |
| 11823 | phba = (struct lpfc_hba *)dev_id; |
| 11824 | |
| 11825 | if (unlikely(!phba)) |
| 11826 | return IRQ_NONE; |
| 11827 | |
| 11828 | /* Get to the EQ struct associated with this vector */ |
| 11829 | speq = phba->sli4_hba.sp_eq; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11830 | if (unlikely(!speq)) |
| 11831 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11832 | |
| 11833 | /* Check device state for handling interrupt */ |
| 11834 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11835 | speq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11836 | /* Check again for link_state with lock held */ |
| 11837 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11838 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11839 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11840 | lpfc_sli4_eq_flush(phba, speq); |
| 11841 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11842 | return IRQ_NONE; |
| 11843 | } |
| 11844 | |
| 11845 | /* |
| 11846 | * Process all the event on FCP slow-path EQ |
| 11847 | */ |
| 11848 | while ((eqe = lpfc_sli4_eq_get(speq))) { |
| 11849 | lpfc_sli4_sp_handle_eqe(phba, eqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11850 | if (!(++ecount % speq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11851 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11852 | speq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11853 | } |
| 11854 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11855 | /* Track the max number of EQEs processed in 1 intr */ |
| 11856 | if (ecount > speq->EQ_max_eqe) |
| 11857 | speq->EQ_max_eqe = ecount; |
| 11858 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11859 | /* Always clear and re-arm the slow-path EQ */ |
| 11860 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); |
| 11861 | |
| 11862 | /* Catch the no cq entry condition */ |
| 11863 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11864 | speq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11865 | if (phba->intr_type == MSIX) |
| 11866 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11867 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11868 | "0357 MSI-X interrupt with no EQE\n"); |
| 11869 | else |
| 11870 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11871 | return IRQ_NONE; |
| 11872 | } |
| 11873 | |
| 11874 | return IRQ_HANDLED; |
| 11875 | } /* lpfc_sli4_sp_intr_handler */ |
| 11876 | |
| 11877 | /** |
| 11878 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device |
| 11879 | * @irq: Interrupt number. |
| 11880 | * @dev_id: The device context pointer. |
| 11881 | * |
| 11882 | * This function is directly called from the PCI layer as an interrupt |
| 11883 | * service routine when device with SLI-4 interface spec is enabled with |
| 11884 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11885 | * ring event in the HBA. However, when the device is enabled with either |
| 11886 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11887 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11888 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11889 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11890 | * the intrrupt context. This function is called without any lock held. |
| 11891 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 11892 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 11893 | * equal to that of FCP CQ index. |
| 11894 | * |
| 11895 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11896 | * returns IRQ_NONE. |
| 11897 | **/ |
| 11898 | irqreturn_t |
| 11899 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) |
| 11900 | { |
| 11901 | struct lpfc_hba *phba; |
| 11902 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 11903 | struct lpfc_queue *fpeq; |
| 11904 | struct lpfc_eqe *eqe; |
| 11905 | unsigned long iflag; |
| 11906 | int ecount = 0; |
| 11907 | uint32_t fcp_eqidx; |
| 11908 | |
| 11909 | /* Get the driver's phba structure from the dev_id */ |
| 11910 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 11911 | phba = fcp_eq_hdl->phba; |
| 11912 | fcp_eqidx = fcp_eq_hdl->idx; |
| 11913 | |
| 11914 | if (unlikely(!phba)) |
| 11915 | return IRQ_NONE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11916 | if (unlikely(!phba->sli4_hba.fp_eq)) |
| 11917 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11918 | |
| 11919 | /* Get to the EQ struct associated with this vector */ |
| 11920 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11921 | if (unlikely(!fpeq)) |
| 11922 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11923 | |
| 11924 | /* Check device state for handling interrupt */ |
| 11925 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11926 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11927 | /* Check again for link_state with lock held */ |
| 11928 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 11929 | if (phba->link_state < LPFC_LINK_DOWN) |
| 11930 | /* Flush, clear interrupt, and rearm the EQ */ |
| 11931 | lpfc_sli4_eq_flush(phba, fpeq); |
| 11932 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11933 | return IRQ_NONE; |
| 11934 | } |
| 11935 | |
| 11936 | /* |
| 11937 | * Process all the event on FCP fast-path EQ |
| 11938 | */ |
| 11939 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 11940 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11941 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11942 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11943 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11944 | } |
| 11945 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11946 | /* Track the max number of EQEs processed in 1 intr */ |
| 11947 | if (ecount > fpeq->EQ_max_eqe) |
| 11948 | fpeq->EQ_max_eqe = ecount; |
| 11949 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11950 | /* Always clear and re-arm the fast-path EQ */ |
| 11951 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 11952 | |
| 11953 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11954 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11955 | if (phba->intr_type == MSIX) |
| 11956 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 11957 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11958 | "0358 MSI-X interrupt with no EQE\n"); |
| 11959 | else |
| 11960 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 11961 | return IRQ_NONE; |
| 11962 | } |
| 11963 | |
| 11964 | return IRQ_HANDLED; |
| 11965 | } /* lpfc_sli4_fp_intr_handler */ |
| 11966 | |
| 11967 | /** |
| 11968 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 11969 | * @irq: Interrupt number. |
| 11970 | * @dev_id: The device context pointer. |
| 11971 | * |
| 11972 | * This function is the device-level interrupt handler to device with SLI-4 |
| 11973 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 11974 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 11975 | * driver attention. This function invokes the slow-path interrupt attention |
| 11976 | * handling function and fast-path interrupt attention handling function in |
| 11977 | * turn to process the relevant HBA attention events. This function is called |
| 11978 | * without any lock held. It gets the hbalock to access and update SLI data |
| 11979 | * structures. |
| 11980 | * |
| 11981 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11982 | * returns IRQ_NONE. |
| 11983 | **/ |
| 11984 | irqreturn_t |
| 11985 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 11986 | { |
| 11987 | struct lpfc_hba *phba; |
| 11988 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11989 | bool fp_handled = false; |
| 11990 | uint32_t fcp_eqidx; |
| 11991 | |
| 11992 | /* Get the driver's phba structure from the dev_id */ |
| 11993 | phba = (struct lpfc_hba *)dev_id; |
| 11994 | |
| 11995 | if (unlikely(!phba)) |
| 11996 | return IRQ_NONE; |
| 11997 | |
| 11998 | /* |
| 11999 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12000 | */ |
| 12001 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); |
| 12002 | |
| 12003 | /* |
| 12004 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12005 | */ |
| 12006 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 12007 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, |
| 12008 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
| 12009 | if (fp_irq_rc == IRQ_HANDLED) |
| 12010 | fp_handled |= true; |
| 12011 | } |
| 12012 | |
| 12013 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; |
| 12014 | } /* lpfc_sli4_intr_handler */ |
| 12015 | |
| 12016 | /** |
| 12017 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12018 | * @queue: The queue structure to free. |
| 12019 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12020 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12021 | * the host resident queue. This function must be called after destroying the |
| 12022 | * queue on the HBA. |
| 12023 | **/ |
| 12024 | void |
| 12025 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12026 | { |
| 12027 | struct lpfc_dmabuf *dmabuf; |
| 12028 | |
| 12029 | if (!queue) |
| 12030 | return; |
| 12031 | |
| 12032 | while (!list_empty(&queue->page_list)) { |
| 12033 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12034 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12035 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12036 | dmabuf->virt, dmabuf->phys); |
| 12037 | kfree(dmabuf); |
| 12038 | } |
| 12039 | kfree(queue); |
| 12040 | return; |
| 12041 | } |
| 12042 | |
| 12043 | /** |
| 12044 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12045 | * @phba: The HBA that this queue is being created on. |
| 12046 | * @entry_size: The size of each queue entry for this queue. |
| 12047 | * @entry count: The number of entries that this queue will handle. |
| 12048 | * |
| 12049 | * This function allocates a queue structure and the DMAable memory used for |
| 12050 | * the host resident queue. This function must be called before creating the |
| 12051 | * queue on the HBA. |
| 12052 | **/ |
| 12053 | struct lpfc_queue * |
| 12054 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12055 | uint32_t entry_count) |
| 12056 | { |
| 12057 | struct lpfc_queue *queue; |
| 12058 | struct lpfc_dmabuf *dmabuf; |
| 12059 | int x, total_qe_count; |
| 12060 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12061 | 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] | 12062 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12063 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12064 | hw_page_size = SLI4_PAGE_SIZE; |
| 12065 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12066 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12067 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12068 | if (!queue) |
| 12069 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12070 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12071 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12072 | INIT_LIST_HEAD(&queue->list); |
| 12073 | INIT_LIST_HEAD(&queue->page_list); |
| 12074 | INIT_LIST_HEAD(&queue->child_list); |
| 12075 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12076 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12077 | if (!dmabuf) |
| 12078 | goto out_fail; |
| 12079 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12080 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12081 | GFP_KERNEL); |
| 12082 | if (!dmabuf->virt) { |
| 12083 | kfree(dmabuf); |
| 12084 | goto out_fail; |
| 12085 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12086 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12087 | dmabuf->buffer_tag = x; |
| 12088 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12089 | /* initialize queue's entry array */ |
| 12090 | dma_pointer = dmabuf->virt; |
| 12091 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12092 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12093 | total_qe_count++, dma_pointer += entry_size) { |
| 12094 | queue->qe[total_qe_count].address = dma_pointer; |
| 12095 | } |
| 12096 | } |
| 12097 | queue->entry_size = entry_size; |
| 12098 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12099 | |
| 12100 | /* |
| 12101 | * entry_repost is calculated based on the number of entries in the |
| 12102 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12103 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12104 | */ |
| 12105 | queue->entry_repost = (entry_count >> 3); |
| 12106 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12107 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12108 | queue->phba = phba; |
| 12109 | |
| 12110 | return queue; |
| 12111 | out_fail: |
| 12112 | lpfc_sli4_queue_free(queue); |
| 12113 | return NULL; |
| 12114 | } |
| 12115 | |
| 12116 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12117 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12118 | * @phba: HBA structure that indicates port to create a queue on. |
| 12119 | * @startq: The starting FCP EQ to modify |
| 12120 | * |
| 12121 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12122 | * |
| 12123 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12124 | * is used to get the starting FCP EQ to change. |
| 12125 | * This function is asynchronous and will wait for the mailbox |
| 12126 | * command to finish before continuing. |
| 12127 | * |
| 12128 | * On success this function will return a zero. If unable to allocate enough |
| 12129 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12130 | * fails this function will return -ENXIO. |
| 12131 | **/ |
| 12132 | uint32_t |
| 12133 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12134 | { |
| 12135 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12136 | LPFC_MBOXQ_t *mbox; |
| 12137 | struct lpfc_queue *eq; |
| 12138 | int cnt, rc, length, status = 0; |
| 12139 | uint32_t shdr_status, shdr_add_status; |
| 12140 | int fcp_eqidx; |
| 12141 | union lpfc_sli4_cfg_shdr *shdr; |
| 12142 | uint16_t dmult; |
| 12143 | |
| 12144 | if (startq >= phba->cfg_fcp_eq_count) |
| 12145 | return 0; |
| 12146 | |
| 12147 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12148 | if (!mbox) |
| 12149 | return -ENOMEM; |
| 12150 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12151 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12152 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12153 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12154 | length, LPFC_SLI4_MBX_EMBED); |
| 12155 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12156 | |
| 12157 | /* Calculate delay multiper from maximum interrupt per second */ |
| 12158 | dmult = LPFC_DMULT_CONST/phba->cfg_fcp_imax - 1; |
| 12159 | |
| 12160 | cnt = 0; |
| 12161 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_eq_count; |
| 12162 | fcp_eqidx++) { |
| 12163 | eq = phba->sli4_hba.fp_eq[fcp_eqidx]; |
| 12164 | if (!eq) |
| 12165 | continue; |
| 12166 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12167 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12168 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12169 | cnt++; |
| 12170 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12171 | break; |
| 12172 | } |
| 12173 | eq_delay->u.request.num_eq = cnt; |
| 12174 | |
| 12175 | mbox->vport = phba->pport; |
| 12176 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12177 | mbox->context1 = NULL; |
| 12178 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12179 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12180 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12181 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12182 | if (shdr_status || shdr_add_status || rc) { |
| 12183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12184 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12185 | "status x%x add_status x%x, mbx status x%x\n", |
| 12186 | shdr_status, shdr_add_status, rc); |
| 12187 | status = -ENXIO; |
| 12188 | } |
| 12189 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12190 | return status; |
| 12191 | } |
| 12192 | |
| 12193 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12194 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12195 | * @phba: HBA structure that indicates port to create a queue on. |
| 12196 | * @eq: The queue structure to use to create the event queue. |
| 12197 | * @imax: The maximum interrupt per second limit. |
| 12198 | * |
| 12199 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12200 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12201 | * |
| 12202 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12203 | * is used to get the entry count and entry size that are necessary to |
| 12204 | * determine the number of pages to allocate and use for this queue. This |
| 12205 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12206 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12207 | * command to finish before continuing. |
| 12208 | * |
| 12209 | * 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] | 12210 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12211 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12212 | **/ |
| 12213 | uint32_t |
| 12214 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) |
| 12215 | { |
| 12216 | struct lpfc_mbx_eq_create *eq_create; |
| 12217 | LPFC_MBOXQ_t *mbox; |
| 12218 | int rc, length, status = 0; |
| 12219 | struct lpfc_dmabuf *dmabuf; |
| 12220 | uint32_t shdr_status, shdr_add_status; |
| 12221 | union lpfc_sli4_cfg_shdr *shdr; |
| 12222 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12223 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12224 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12225 | /* sanity check on queue memory */ |
| 12226 | if (!eq) |
| 12227 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12228 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12229 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12230 | |
| 12231 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12232 | if (!mbox) |
| 12233 | return -ENOMEM; |
| 12234 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12235 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12236 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12237 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12238 | length, LPFC_SLI4_MBX_EMBED); |
| 12239 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12240 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12241 | eq->page_count); |
| 12242 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12243 | LPFC_EQE_SIZE); |
| 12244 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12245 | /* Calculate delay multiper from maximum interrupt per second */ |
| 12246 | dmult = LPFC_DMULT_CONST/imax - 1; |
| 12247 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12248 | dmult); |
| 12249 | switch (eq->entry_count) { |
| 12250 | default: |
| 12251 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12252 | "0360 Unsupported EQ count. (%d)\n", |
| 12253 | eq->entry_count); |
| 12254 | if (eq->entry_count < 256) |
| 12255 | return -EINVAL; |
| 12256 | /* otherwise default to smallest count (drop through) */ |
| 12257 | case 256: |
| 12258 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12259 | LPFC_EQ_CNT_256); |
| 12260 | break; |
| 12261 | case 512: |
| 12262 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12263 | LPFC_EQ_CNT_512); |
| 12264 | break; |
| 12265 | case 1024: |
| 12266 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12267 | LPFC_EQ_CNT_1024); |
| 12268 | break; |
| 12269 | case 2048: |
| 12270 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12271 | LPFC_EQ_CNT_2048); |
| 12272 | break; |
| 12273 | case 4096: |
| 12274 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12275 | LPFC_EQ_CNT_4096); |
| 12276 | break; |
| 12277 | } |
| 12278 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12279 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12280 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12281 | putPaddrLow(dmabuf->phys); |
| 12282 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12283 | putPaddrHigh(dmabuf->phys); |
| 12284 | } |
| 12285 | mbox->vport = phba->pport; |
| 12286 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12287 | mbox->context1 = NULL; |
| 12288 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12289 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12290 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12291 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12292 | if (shdr_status || shdr_add_status || rc) { |
| 12293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12294 | "2500 EQ_CREATE mailbox failed with " |
| 12295 | "status x%x add_status x%x, mbx status x%x\n", |
| 12296 | shdr_status, shdr_add_status, rc); |
| 12297 | status = -ENXIO; |
| 12298 | } |
| 12299 | eq->type = LPFC_EQ; |
| 12300 | eq->subtype = LPFC_NONE; |
| 12301 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12302 | if (eq->queue_id == 0xFFFF) |
| 12303 | status = -ENXIO; |
| 12304 | eq->host_index = 0; |
| 12305 | eq->hba_index = 0; |
| 12306 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12307 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12308 | return status; |
| 12309 | } |
| 12310 | |
| 12311 | /** |
| 12312 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12313 | * @phba: HBA structure that indicates port to create a queue on. |
| 12314 | * @cq: The queue structure to use to create the completion queue. |
| 12315 | * @eq: The event queue to bind this completion queue to. |
| 12316 | * |
| 12317 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12318 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12319 | * |
| 12320 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12321 | * is used to get the entry count and entry size that are necessary to |
| 12322 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12323 | * is used to indicate which event queue to bind this completion queue to. This |
| 12324 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12325 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12326 | * command to finish before continuing. |
| 12327 | * |
| 12328 | * 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] | 12329 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12330 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12331 | **/ |
| 12332 | uint32_t |
| 12333 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12334 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12335 | { |
| 12336 | struct lpfc_mbx_cq_create *cq_create; |
| 12337 | struct lpfc_dmabuf *dmabuf; |
| 12338 | LPFC_MBOXQ_t *mbox; |
| 12339 | int rc, length, status = 0; |
| 12340 | uint32_t shdr_status, shdr_add_status; |
| 12341 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12342 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12343 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12344 | /* sanity check on queue memory */ |
| 12345 | if (!cq || !eq) |
| 12346 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12347 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12348 | hw_page_size = SLI4_PAGE_SIZE; |
| 12349 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12350 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12351 | if (!mbox) |
| 12352 | return -ENOMEM; |
| 12353 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12354 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12355 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12356 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12357 | length, LPFC_SLI4_MBX_EMBED); |
| 12358 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12359 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12360 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12361 | cq->page_count); |
| 12362 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12363 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12364 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12365 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12366 | 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] | 12367 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12368 | 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] | 12369 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12370 | eq->queue_id); |
| 12371 | } else { |
| 12372 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12373 | eq->queue_id); |
| 12374 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12375 | switch (cq->entry_count) { |
| 12376 | default: |
| 12377 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12378 | "0361 Unsupported CQ count. (%d)\n", |
| 12379 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12380 | if (cq->entry_count < 256) { |
| 12381 | status = -EINVAL; |
| 12382 | goto out; |
| 12383 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12384 | /* otherwise default to smallest count (drop through) */ |
| 12385 | case 256: |
| 12386 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12387 | LPFC_CQ_CNT_256); |
| 12388 | break; |
| 12389 | case 512: |
| 12390 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12391 | LPFC_CQ_CNT_512); |
| 12392 | break; |
| 12393 | case 1024: |
| 12394 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12395 | LPFC_CQ_CNT_1024); |
| 12396 | break; |
| 12397 | } |
| 12398 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12399 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12400 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12401 | putPaddrLow(dmabuf->phys); |
| 12402 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12403 | putPaddrHigh(dmabuf->phys); |
| 12404 | } |
| 12405 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12406 | |
| 12407 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12408 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12409 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12410 | if (shdr_status || shdr_add_status || rc) { |
| 12411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12412 | "2501 CQ_CREATE mailbox failed with " |
| 12413 | "status x%x add_status x%x, mbx status x%x\n", |
| 12414 | shdr_status, shdr_add_status, rc); |
| 12415 | status = -ENXIO; |
| 12416 | goto out; |
| 12417 | } |
| 12418 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12419 | if (cq->queue_id == 0xFFFF) { |
| 12420 | status = -ENXIO; |
| 12421 | goto out; |
| 12422 | } |
| 12423 | /* link the cq onto the parent eq child list */ |
| 12424 | list_add_tail(&cq->list, &eq->child_list); |
| 12425 | /* Set up completion queue's type and subtype */ |
| 12426 | cq->type = type; |
| 12427 | cq->subtype = subtype; |
| 12428 | 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] | 12429 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12430 | cq->host_index = 0; |
| 12431 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12432 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12433 | out: |
| 12434 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12435 | return status; |
| 12436 | } |
| 12437 | |
| 12438 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12439 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12440 | * @phba: HBA structure that indicates port to create a queue on. |
| 12441 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12442 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12443 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12444 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12445 | * This function provides failback (fb) functionality when the |
| 12446 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12447 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12448 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12449 | * This routine cannot fail as all attributes were previously accessed and |
| 12450 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12451 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12452 | static void |
| 12453 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12454 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12455 | { |
| 12456 | struct lpfc_mbx_mq_create *mq_create; |
| 12457 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12458 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12459 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12460 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12461 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12462 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12463 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12464 | length, LPFC_SLI4_MBX_EMBED); |
| 12465 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12466 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12467 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12468 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12469 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12470 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12471 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12472 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12473 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12474 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12475 | break; |
| 12476 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12477 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12478 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12479 | break; |
| 12480 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12481 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12482 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12483 | break; |
| 12484 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12485 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12486 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12487 | break; |
| 12488 | } |
| 12489 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12490 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12491 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12492 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12493 | putPaddrHigh(dmabuf->phys); |
| 12494 | } |
| 12495 | } |
| 12496 | |
| 12497 | /** |
| 12498 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12499 | * @phba: HBA structure that indicates port to create a queue on. |
| 12500 | * @mq: The queue structure to use to create the mailbox queue. |
| 12501 | * @cq: The completion queue to associate with this cq. |
| 12502 | * @subtype: The queue's subtype. |
| 12503 | * |
| 12504 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12505 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12506 | * |
| 12507 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12508 | * is used to get the entry count and entry size that are necessary to |
| 12509 | * determine the number of pages to allocate and use for this queue. This |
| 12510 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12511 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12512 | * command to finish before continuing. |
| 12513 | * |
| 12514 | * 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] | 12515 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12516 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12517 | **/ |
| 12518 | int32_t |
| 12519 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12520 | struct lpfc_queue *cq, uint32_t subtype) |
| 12521 | { |
| 12522 | struct lpfc_mbx_mq_create *mq_create; |
| 12523 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12524 | struct lpfc_dmabuf *dmabuf; |
| 12525 | LPFC_MBOXQ_t *mbox; |
| 12526 | int rc, length, status = 0; |
| 12527 | uint32_t shdr_status, shdr_add_status; |
| 12528 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12529 | 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] | 12530 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12531 | /* sanity check on queue memory */ |
| 12532 | if (!mq || !cq) |
| 12533 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12534 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12535 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12536 | |
| 12537 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12538 | if (!mbox) |
| 12539 | return -ENOMEM; |
| 12540 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12541 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12542 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12543 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12544 | length, LPFC_SLI4_MBX_EMBED); |
| 12545 | |
| 12546 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12547 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12548 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12549 | &mq_create_ext->u.request, mq->page_count); |
| 12550 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12551 | &mq_create_ext->u.request, 1); |
| 12552 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12553 | &mq_create_ext->u.request, 1); |
| 12554 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12555 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12556 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12557 | &mq_create_ext->u.request, 1); |
| 12558 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12559 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12560 | 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] | 12561 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12562 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12563 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12564 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12565 | cq->queue_id); |
| 12566 | else |
| 12567 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12568 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12569 | switch (mq->entry_count) { |
| 12570 | default: |
| 12571 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12572 | "0362 Unsupported MQ count. (%d)\n", |
| 12573 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12574 | if (mq->entry_count < 16) { |
| 12575 | status = -EINVAL; |
| 12576 | goto out; |
| 12577 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12578 | /* otherwise default to smallest count (drop through) */ |
| 12579 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12580 | bf_set(lpfc_mq_context_ring_size, |
| 12581 | &mq_create_ext->u.request.context, |
| 12582 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12583 | break; |
| 12584 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12585 | bf_set(lpfc_mq_context_ring_size, |
| 12586 | &mq_create_ext->u.request.context, |
| 12587 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12588 | break; |
| 12589 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12590 | bf_set(lpfc_mq_context_ring_size, |
| 12591 | &mq_create_ext->u.request.context, |
| 12592 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12593 | break; |
| 12594 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12595 | bf_set(lpfc_mq_context_ring_size, |
| 12596 | &mq_create_ext->u.request.context, |
| 12597 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12598 | break; |
| 12599 | } |
| 12600 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12601 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12602 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12603 | putPaddrLow(dmabuf->phys); |
| 12604 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12605 | putPaddrHigh(dmabuf->phys); |
| 12606 | } |
| 12607 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12608 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12609 | &mq_create_ext->u.response); |
| 12610 | if (rc != MBX_SUCCESS) { |
| 12611 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12612 | "2795 MQ_CREATE_EXT failed with " |
| 12613 | "status x%x. Failback to MQ_CREATE.\n", |
| 12614 | rc); |
| 12615 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12616 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12617 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12618 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12619 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12620 | &mq_create->u.response); |
| 12621 | } |
| 12622 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12623 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12624 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12625 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12626 | if (shdr_status || shdr_add_status || rc) { |
| 12627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12628 | "2502 MQ_CREATE mailbox failed with " |
| 12629 | "status x%x add_status x%x, mbx status x%x\n", |
| 12630 | shdr_status, shdr_add_status, rc); |
| 12631 | status = -ENXIO; |
| 12632 | goto out; |
| 12633 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12634 | if (mq->queue_id == 0xFFFF) { |
| 12635 | status = -ENXIO; |
| 12636 | goto out; |
| 12637 | } |
| 12638 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12639 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12640 | mq->subtype = subtype; |
| 12641 | mq->host_index = 0; |
| 12642 | mq->hba_index = 0; |
| 12643 | |
| 12644 | /* link the mq onto the parent cq child list */ |
| 12645 | list_add_tail(&mq->list, &cq->child_list); |
| 12646 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12647 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12648 | return status; |
| 12649 | } |
| 12650 | |
| 12651 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12652 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12653 | * @phba: HBA structure that indicates port to create a queue on. |
| 12654 | * @wq: The queue structure to use to create the work queue. |
| 12655 | * @cq: The completion queue to bind this work queue to. |
| 12656 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12657 | * |
| 12658 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12659 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12660 | * |
| 12661 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12662 | * is used to get the entry count and entry size that are necessary to |
| 12663 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12664 | * is used to indicate which completion queue to bind this work queue to. This |
| 12665 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12666 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12667 | * command to finish before continuing. |
| 12668 | * |
| 12669 | * 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] | 12670 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12671 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12672 | **/ |
| 12673 | uint32_t |
| 12674 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12675 | struct lpfc_queue *cq, uint32_t subtype) |
| 12676 | { |
| 12677 | struct lpfc_mbx_wq_create *wq_create; |
| 12678 | struct lpfc_dmabuf *dmabuf; |
| 12679 | LPFC_MBOXQ_t *mbox; |
| 12680 | int rc, length, status = 0; |
| 12681 | uint32_t shdr_status, shdr_add_status; |
| 12682 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12683 | 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] | 12684 | struct dma_address *page; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12685 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12686 | /* sanity check on queue memory */ |
| 12687 | if (!wq || !cq) |
| 12688 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12689 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12690 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12691 | |
| 12692 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12693 | if (!mbox) |
| 12694 | return -ENOMEM; |
| 12695 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 12696 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12697 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12698 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 12699 | length, LPFC_SLI4_MBX_EMBED); |
| 12700 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12701 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12702 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 12703 | wq->page_count); |
| 12704 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 12705 | cq->queue_id); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12706 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12707 | phba->sli4_hba.pc_sli4_params.wqv); |
| 12708 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { |
| 12709 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 12710 | wq->entry_count); |
| 12711 | switch (wq->entry_size) { |
| 12712 | default: |
| 12713 | case 64: |
| 12714 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12715 | &wq_create->u.request_1, |
| 12716 | LPFC_WQ_WQE_SIZE_64); |
| 12717 | break; |
| 12718 | case 128: |
| 12719 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 12720 | &wq_create->u.request_1, |
| 12721 | LPFC_WQ_WQE_SIZE_128); |
| 12722 | break; |
| 12723 | } |
| 12724 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 12725 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 12726 | page = wq_create->u.request_1.page; |
| 12727 | } else { |
| 12728 | page = wq_create->u.request.page; |
| 12729 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12730 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12731 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12732 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 12733 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12734 | } |
| 12735 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12736 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12737 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12738 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12739 | if (shdr_status || shdr_add_status || rc) { |
| 12740 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12741 | "2503 WQ_CREATE mailbox failed with " |
| 12742 | "status x%x add_status x%x, mbx status x%x\n", |
| 12743 | shdr_status, shdr_add_status, rc); |
| 12744 | status = -ENXIO; |
| 12745 | goto out; |
| 12746 | } |
| 12747 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 12748 | if (wq->queue_id == 0xFFFF) { |
| 12749 | status = -ENXIO; |
| 12750 | goto out; |
| 12751 | } |
| 12752 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12753 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12754 | wq->subtype = subtype; |
| 12755 | wq->host_index = 0; |
| 12756 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 12757 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12758 | |
| 12759 | /* link the wq onto the parent cq child list */ |
| 12760 | list_add_tail(&wq->list, &cq->child_list); |
| 12761 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12762 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12763 | return status; |
| 12764 | } |
| 12765 | |
| 12766 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12767 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 12768 | * @phba: HBA structure that indicates port to create a queue on. |
| 12769 | * @rq: The queue structure to use for the receive queue. |
| 12770 | * @qno: The associated HBQ number |
| 12771 | * |
| 12772 | * |
| 12773 | * For SLI4 we need to adjust the RQ repost value based on |
| 12774 | * the number of buffers that are initially posted to the RQ. |
| 12775 | */ |
| 12776 | void |
| 12777 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 12778 | { |
| 12779 | uint32_t cnt; |
| 12780 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12781 | /* sanity check on queue memory */ |
| 12782 | if (!rq) |
| 12783 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12784 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 12785 | |
| 12786 | /* Recalc repost for RQs based on buffers initially posted */ |
| 12787 | cnt = (cnt >> 3); |
| 12788 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 12789 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 12790 | |
| 12791 | rq->entry_repost = cnt; |
| 12792 | } |
| 12793 | |
| 12794 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12795 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 12796 | * @phba: HBA structure that indicates port to create a queue on. |
| 12797 | * @hrq: The queue structure to use to create the header receive queue. |
| 12798 | * @drq: The queue structure to use to create the data receive queue. |
| 12799 | * @cq: The completion queue to bind this work queue to. |
| 12800 | * |
| 12801 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 12802 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 12803 | * to the HBA. |
| 12804 | * |
| 12805 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 12806 | * struct is used to get the entry count that is necessary to determine the |
| 12807 | * number of pages to use for this queue. The @cq is used to indicate which |
| 12808 | * completion queue to bind received buffers that are posted to these queues to. |
| 12809 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 12810 | * receive queue pair. This function is asynchronous and will wait for the |
| 12811 | * mailbox command to finish before continuing. |
| 12812 | * |
| 12813 | * 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] | 12814 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12815 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12816 | **/ |
| 12817 | uint32_t |
| 12818 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 12819 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 12820 | { |
| 12821 | struct lpfc_mbx_rq_create *rq_create; |
| 12822 | struct lpfc_dmabuf *dmabuf; |
| 12823 | LPFC_MBOXQ_t *mbox; |
| 12824 | int rc, length, status = 0; |
| 12825 | uint32_t shdr_status, shdr_add_status; |
| 12826 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12827 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12828 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12829 | /* sanity check on queue memory */ |
| 12830 | if (!hrq || !drq || !cq) |
| 12831 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12832 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12833 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12834 | |
| 12835 | if (hrq->entry_count != drq->entry_count) |
| 12836 | return -EINVAL; |
| 12837 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12838 | if (!mbox) |
| 12839 | return -ENOMEM; |
| 12840 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 12841 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12842 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12843 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12844 | length, LPFC_SLI4_MBX_EMBED); |
| 12845 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12846 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12847 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12848 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12849 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12850 | bf_set(lpfc_rq_context_rqe_count_1, |
| 12851 | &rq_create->u.request.context, |
| 12852 | hrq->entry_count); |
| 12853 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12854 | bf_set(lpfc_rq_context_rqe_size, |
| 12855 | &rq_create->u.request.context, |
| 12856 | LPFC_RQE_SIZE_8); |
| 12857 | bf_set(lpfc_rq_context_page_size, |
| 12858 | &rq_create->u.request.context, |
| 12859 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12860 | } else { |
| 12861 | switch (hrq->entry_count) { |
| 12862 | default: |
| 12863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12864 | "2535 Unsupported RQ count. (%d)\n", |
| 12865 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12866 | if (hrq->entry_count < 512) { |
| 12867 | status = -EINVAL; |
| 12868 | goto out; |
| 12869 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12870 | /* otherwise default to smallest count (drop through) */ |
| 12871 | case 512: |
| 12872 | bf_set(lpfc_rq_context_rqe_count, |
| 12873 | &rq_create->u.request.context, |
| 12874 | LPFC_RQ_RING_SIZE_512); |
| 12875 | break; |
| 12876 | case 1024: |
| 12877 | bf_set(lpfc_rq_context_rqe_count, |
| 12878 | &rq_create->u.request.context, |
| 12879 | LPFC_RQ_RING_SIZE_1024); |
| 12880 | break; |
| 12881 | case 2048: |
| 12882 | bf_set(lpfc_rq_context_rqe_count, |
| 12883 | &rq_create->u.request.context, |
| 12884 | LPFC_RQ_RING_SIZE_2048); |
| 12885 | break; |
| 12886 | case 4096: |
| 12887 | bf_set(lpfc_rq_context_rqe_count, |
| 12888 | &rq_create->u.request.context, |
| 12889 | LPFC_RQ_RING_SIZE_4096); |
| 12890 | break; |
| 12891 | } |
| 12892 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12893 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12894 | } |
| 12895 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12896 | cq->queue_id); |
| 12897 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12898 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12899 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12900 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12901 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12902 | putPaddrLow(dmabuf->phys); |
| 12903 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12904 | putPaddrHigh(dmabuf->phys); |
| 12905 | } |
| 12906 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12907 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12908 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12909 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12910 | if (shdr_status || shdr_add_status || rc) { |
| 12911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12912 | "2504 RQ_CREATE mailbox failed with " |
| 12913 | "status x%x add_status x%x, mbx status x%x\n", |
| 12914 | shdr_status, shdr_add_status, rc); |
| 12915 | status = -ENXIO; |
| 12916 | goto out; |
| 12917 | } |
| 12918 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12919 | if (hrq->queue_id == 0xFFFF) { |
| 12920 | status = -ENXIO; |
| 12921 | goto out; |
| 12922 | } |
| 12923 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12924 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12925 | hrq->subtype = subtype; |
| 12926 | hrq->host_index = 0; |
| 12927 | hrq->hba_index = 0; |
| 12928 | |
| 12929 | /* now create the data queue */ |
| 12930 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 12931 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 12932 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12933 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12934 | phba->sli4_hba.pc_sli4_params.rqv); |
| 12935 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 12936 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12937 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12938 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 12939 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 12940 | LPFC_RQE_SIZE_8); |
| 12941 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 12942 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12943 | } else { |
| 12944 | switch (drq->entry_count) { |
| 12945 | default: |
| 12946 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12947 | "2536 Unsupported RQ count. (%d)\n", |
| 12948 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12949 | if (drq->entry_count < 512) { |
| 12950 | status = -EINVAL; |
| 12951 | goto out; |
| 12952 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12953 | /* otherwise default to smallest count (drop through) */ |
| 12954 | case 512: |
| 12955 | bf_set(lpfc_rq_context_rqe_count, |
| 12956 | &rq_create->u.request.context, |
| 12957 | LPFC_RQ_RING_SIZE_512); |
| 12958 | break; |
| 12959 | case 1024: |
| 12960 | bf_set(lpfc_rq_context_rqe_count, |
| 12961 | &rq_create->u.request.context, |
| 12962 | LPFC_RQ_RING_SIZE_1024); |
| 12963 | break; |
| 12964 | case 2048: |
| 12965 | bf_set(lpfc_rq_context_rqe_count, |
| 12966 | &rq_create->u.request.context, |
| 12967 | LPFC_RQ_RING_SIZE_2048); |
| 12968 | break; |
| 12969 | case 4096: |
| 12970 | bf_set(lpfc_rq_context_rqe_count, |
| 12971 | &rq_create->u.request.context, |
| 12972 | LPFC_RQ_RING_SIZE_4096); |
| 12973 | break; |
| 12974 | } |
| 12975 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 12976 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12977 | } |
| 12978 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 12979 | cq->queue_id); |
| 12980 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 12981 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12982 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 12983 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12984 | putPaddrLow(dmabuf->phys); |
| 12985 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12986 | putPaddrHigh(dmabuf->phys); |
| 12987 | } |
| 12988 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12989 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 12990 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 12991 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12992 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12993 | if (shdr_status || shdr_add_status || rc) { |
| 12994 | status = -ENXIO; |
| 12995 | goto out; |
| 12996 | } |
| 12997 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 12998 | if (drq->queue_id == 0xFFFF) { |
| 12999 | status = -ENXIO; |
| 13000 | goto out; |
| 13001 | } |
| 13002 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13003 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13004 | drq->subtype = subtype; |
| 13005 | drq->host_index = 0; |
| 13006 | drq->hba_index = 0; |
| 13007 | |
| 13008 | /* link the header and data RQs onto the parent cq child list */ |
| 13009 | list_add_tail(&hrq->list, &cq->child_list); |
| 13010 | list_add_tail(&drq->list, &cq->child_list); |
| 13011 | |
| 13012 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13013 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13014 | return status; |
| 13015 | } |
| 13016 | |
| 13017 | /** |
| 13018 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13019 | * @eq: The queue structure associated with the queue to destroy. |
| 13020 | * |
| 13021 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13022 | * command, specific to the type of queue, to the HBA. |
| 13023 | * |
| 13024 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13025 | * |
| 13026 | * 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] | 13027 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13028 | **/ |
| 13029 | uint32_t |
| 13030 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13031 | { |
| 13032 | LPFC_MBOXQ_t *mbox; |
| 13033 | int rc, length, status = 0; |
| 13034 | uint32_t shdr_status, shdr_add_status; |
| 13035 | union lpfc_sli4_cfg_shdr *shdr; |
| 13036 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13037 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13038 | if (!eq) |
| 13039 | return -ENODEV; |
| 13040 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13041 | if (!mbox) |
| 13042 | return -ENOMEM; |
| 13043 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13044 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13045 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13046 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13047 | length, LPFC_SLI4_MBX_EMBED); |
| 13048 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13049 | eq->queue_id); |
| 13050 | mbox->vport = eq->phba->pport; |
| 13051 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13052 | |
| 13053 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13054 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13055 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13056 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13057 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13058 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13059 | if (shdr_status || shdr_add_status || rc) { |
| 13060 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13061 | "2505 EQ_DESTROY mailbox failed with " |
| 13062 | "status x%x add_status x%x, mbx status x%x\n", |
| 13063 | shdr_status, shdr_add_status, rc); |
| 13064 | status = -ENXIO; |
| 13065 | } |
| 13066 | |
| 13067 | /* Remove eq from any list */ |
| 13068 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13069 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13070 | return status; |
| 13071 | } |
| 13072 | |
| 13073 | /** |
| 13074 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13075 | * @cq: The queue structure associated with the queue to destroy. |
| 13076 | * |
| 13077 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13078 | * command, specific to the type of queue, to the HBA. |
| 13079 | * |
| 13080 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13081 | * |
| 13082 | * 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] | 13083 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13084 | **/ |
| 13085 | uint32_t |
| 13086 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13087 | { |
| 13088 | LPFC_MBOXQ_t *mbox; |
| 13089 | int rc, length, status = 0; |
| 13090 | uint32_t shdr_status, shdr_add_status; |
| 13091 | union lpfc_sli4_cfg_shdr *shdr; |
| 13092 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13093 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13094 | if (!cq) |
| 13095 | return -ENODEV; |
| 13096 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13097 | if (!mbox) |
| 13098 | return -ENOMEM; |
| 13099 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13100 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13101 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13102 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13103 | length, LPFC_SLI4_MBX_EMBED); |
| 13104 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13105 | cq->queue_id); |
| 13106 | mbox->vport = cq->phba->pport; |
| 13107 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13108 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13109 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13110 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13111 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13112 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13113 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13114 | if (shdr_status || shdr_add_status || rc) { |
| 13115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13116 | "2506 CQ_DESTROY mailbox failed with " |
| 13117 | "status x%x add_status x%x, mbx status x%x\n", |
| 13118 | shdr_status, shdr_add_status, rc); |
| 13119 | status = -ENXIO; |
| 13120 | } |
| 13121 | /* Remove cq from any list */ |
| 13122 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13123 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13124 | return status; |
| 13125 | } |
| 13126 | |
| 13127 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13128 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13129 | * @qm: The queue structure associated with the queue to destroy. |
| 13130 | * |
| 13131 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13132 | * command, specific to the type of queue, to the HBA. |
| 13133 | * |
| 13134 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13135 | * |
| 13136 | * 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] | 13137 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13138 | **/ |
| 13139 | uint32_t |
| 13140 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13141 | { |
| 13142 | LPFC_MBOXQ_t *mbox; |
| 13143 | int rc, length, status = 0; |
| 13144 | uint32_t shdr_status, shdr_add_status; |
| 13145 | union lpfc_sli4_cfg_shdr *shdr; |
| 13146 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13147 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13148 | if (!mq) |
| 13149 | return -ENODEV; |
| 13150 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13151 | if (!mbox) |
| 13152 | return -ENOMEM; |
| 13153 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13154 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13155 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13156 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13157 | length, LPFC_SLI4_MBX_EMBED); |
| 13158 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13159 | mq->queue_id); |
| 13160 | mbox->vport = mq->phba->pport; |
| 13161 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13162 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13163 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13164 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13165 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13166 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13167 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13168 | if (shdr_status || shdr_add_status || rc) { |
| 13169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13170 | "2507 MQ_DESTROY mailbox failed with " |
| 13171 | "status x%x add_status x%x, mbx status x%x\n", |
| 13172 | shdr_status, shdr_add_status, rc); |
| 13173 | status = -ENXIO; |
| 13174 | } |
| 13175 | /* Remove mq from any list */ |
| 13176 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13177 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13178 | return status; |
| 13179 | } |
| 13180 | |
| 13181 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13182 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13183 | * @wq: The queue structure associated with the queue to destroy. |
| 13184 | * |
| 13185 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13186 | * command, specific to the type of queue, to the HBA. |
| 13187 | * |
| 13188 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13189 | * |
| 13190 | * 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] | 13191 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13192 | **/ |
| 13193 | uint32_t |
| 13194 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13195 | { |
| 13196 | LPFC_MBOXQ_t *mbox; |
| 13197 | int rc, length, status = 0; |
| 13198 | uint32_t shdr_status, shdr_add_status; |
| 13199 | union lpfc_sli4_cfg_shdr *shdr; |
| 13200 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13201 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13202 | if (!wq) |
| 13203 | return -ENODEV; |
| 13204 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13205 | if (!mbox) |
| 13206 | return -ENOMEM; |
| 13207 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13208 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13209 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13210 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13211 | length, LPFC_SLI4_MBX_EMBED); |
| 13212 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13213 | wq->queue_id); |
| 13214 | mbox->vport = wq->phba->pport; |
| 13215 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13216 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13217 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13218 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13219 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13220 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13221 | if (shdr_status || shdr_add_status || rc) { |
| 13222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13223 | "2508 WQ_DESTROY mailbox failed with " |
| 13224 | "status x%x add_status x%x, mbx status x%x\n", |
| 13225 | shdr_status, shdr_add_status, rc); |
| 13226 | status = -ENXIO; |
| 13227 | } |
| 13228 | /* Remove wq from any list */ |
| 13229 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13230 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13231 | return status; |
| 13232 | } |
| 13233 | |
| 13234 | /** |
| 13235 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13236 | * @rq: The queue structure associated with the queue to destroy. |
| 13237 | * |
| 13238 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13239 | * command, specific to the type of queue, to the HBA. |
| 13240 | * |
| 13241 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13242 | * |
| 13243 | * 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] | 13244 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13245 | **/ |
| 13246 | uint32_t |
| 13247 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13248 | struct lpfc_queue *drq) |
| 13249 | { |
| 13250 | LPFC_MBOXQ_t *mbox; |
| 13251 | int rc, length, status = 0; |
| 13252 | uint32_t shdr_status, shdr_add_status; |
| 13253 | union lpfc_sli4_cfg_shdr *shdr; |
| 13254 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13255 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13256 | if (!hrq || !drq) |
| 13257 | return -ENODEV; |
| 13258 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13259 | if (!mbox) |
| 13260 | return -ENOMEM; |
| 13261 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13262 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13263 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13264 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13265 | length, LPFC_SLI4_MBX_EMBED); |
| 13266 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13267 | hrq->queue_id); |
| 13268 | mbox->vport = hrq->phba->pport; |
| 13269 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13270 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13271 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13272 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13273 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13274 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13275 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13276 | if (shdr_status || shdr_add_status || rc) { |
| 13277 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13278 | "2509 RQ_DESTROY mailbox failed with " |
| 13279 | "status x%x add_status x%x, mbx status x%x\n", |
| 13280 | shdr_status, shdr_add_status, rc); |
| 13281 | if (rc != MBX_TIMEOUT) |
| 13282 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13283 | return -ENXIO; |
| 13284 | } |
| 13285 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13286 | drq->queue_id); |
| 13287 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13288 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13289 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13290 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13291 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13292 | if (shdr_status || shdr_add_status || rc) { |
| 13293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13294 | "2510 RQ_DESTROY mailbox failed with " |
| 13295 | "status x%x add_status x%x, mbx status x%x\n", |
| 13296 | shdr_status, shdr_add_status, rc); |
| 13297 | status = -ENXIO; |
| 13298 | } |
| 13299 | list_del_init(&hrq->list); |
| 13300 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13301 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13302 | return status; |
| 13303 | } |
| 13304 | |
| 13305 | /** |
| 13306 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13307 | * @phba: The virtual port for which this call being executed. |
| 13308 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13309 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13310 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13311 | * |
| 13312 | * This routine will post the sgl pages for the IO that has the xritag |
| 13313 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13314 | * creation and persists for as long as the driver is loaded. |
| 13315 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13316 | * pdma_phys_addr1 should be 0. |
| 13317 | * If the caller needs to map more than 256 scatter gather segment then |
| 13318 | * pdma_phys_addr1 should be a valid physical address. |
| 13319 | * physical address for SGLs must be 64 byte aligned. |
| 13320 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13321 | * the second sgl can have between 1 and 256 entries. |
| 13322 | * |
| 13323 | * Return codes: |
| 13324 | * 0 - Success |
| 13325 | * -ENXIO, -ENOMEM - Failure |
| 13326 | **/ |
| 13327 | int |
| 13328 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13329 | dma_addr_t pdma_phys_addr0, |
| 13330 | dma_addr_t pdma_phys_addr1, |
| 13331 | uint16_t xritag) |
| 13332 | { |
| 13333 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13334 | LPFC_MBOXQ_t *mbox; |
| 13335 | int rc; |
| 13336 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13337 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13338 | union lpfc_sli4_cfg_shdr *shdr; |
| 13339 | |
| 13340 | if (xritag == NO_XRI) { |
| 13341 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13342 | "0364 Invalid param:\n"); |
| 13343 | return -EINVAL; |
| 13344 | } |
| 13345 | |
| 13346 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13347 | if (!mbox) |
| 13348 | return -ENOMEM; |
| 13349 | |
| 13350 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13351 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13352 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13353 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13354 | |
| 13355 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13356 | &mbox->u.mqe.un.post_sgl_pages; |
| 13357 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13358 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13359 | |
| 13360 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13361 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13362 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13363 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13364 | |
| 13365 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13366 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13367 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13368 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13369 | if (!phba->sli4_hba.intr_enable) |
| 13370 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13371 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13372 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13373 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13374 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13375 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13376 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13377 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13378 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13379 | if (rc != MBX_TIMEOUT) |
| 13380 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13381 | if (shdr_status || shdr_add_status || rc) { |
| 13382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13383 | "2511 POST_SGL mailbox failed with " |
| 13384 | "status x%x add_status x%x, mbx status x%x\n", |
| 13385 | shdr_status, shdr_add_status, rc); |
| 13386 | rc = -ENXIO; |
| 13387 | } |
| 13388 | return 0; |
| 13389 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13390 | |
| 13391 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13392 | * 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] | 13393 | * @phba: pointer to lpfc hba data structure. |
| 13394 | * |
| 13395 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13396 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13397 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13398 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13399 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13400 | * Returns |
| 13401 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13402 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13403 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13404 | uint16_t |
| 13405 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13406 | { |
| 13407 | unsigned long xri; |
| 13408 | |
| 13409 | /* |
| 13410 | * Fetch the next logical xri. Because this index is logical, |
| 13411 | * the driver starts at 0 each time. |
| 13412 | */ |
| 13413 | spin_lock_irq(&phba->hbalock); |
| 13414 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13415 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13416 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13417 | spin_unlock_irq(&phba->hbalock); |
| 13418 | return NO_XRI; |
| 13419 | } else { |
| 13420 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13421 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13422 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13423 | spin_unlock_irq(&phba->hbalock); |
| 13424 | return xri; |
| 13425 | } |
| 13426 | |
| 13427 | /** |
| 13428 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13429 | * @phba: pointer to lpfc hba data structure. |
| 13430 | * |
| 13431 | * This routine is invoked to release an xri to the pool of |
| 13432 | * available rpis maintained by the driver. |
| 13433 | **/ |
| 13434 | void |
| 13435 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13436 | { |
| 13437 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13438 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13439 | } |
| 13440 | } |
| 13441 | |
| 13442 | /** |
| 13443 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13444 | * @phba: pointer to lpfc hba data structure. |
| 13445 | * |
| 13446 | * This routine is invoked to release an xri to the pool of |
| 13447 | * available rpis maintained by the driver. |
| 13448 | **/ |
| 13449 | void |
| 13450 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13451 | { |
| 13452 | spin_lock_irq(&phba->hbalock); |
| 13453 | __lpfc_sli4_free_xri(phba, xri); |
| 13454 | spin_unlock_irq(&phba->hbalock); |
| 13455 | } |
| 13456 | |
| 13457 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13458 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13459 | * @phba: Pointer to HBA context object. |
| 13460 | * |
| 13461 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13462 | * it will return 0xffff. |
| 13463 | * The function returns the allocated xritag if successful, else returns zero. |
| 13464 | * Zero is not a valid xritag. |
| 13465 | * The caller is not required to hold any lock. |
| 13466 | **/ |
| 13467 | uint16_t |
| 13468 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13469 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13470 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13471 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13472 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13473 | if (xri_index == NO_XRI) |
| 13474 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13475 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13476 | " Max XRI is %d, Used XRI is %d\n", |
| 13477 | xri_index, |
| 13478 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13479 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13480 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13481 | } |
| 13482 | |
| 13483 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13484 | * 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] | 13485 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13486 | * @post_sgl_list: pointer to els sgl entry list. |
| 13487 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13488 | * |
| 13489 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13490 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13491 | * is only called when the driver is loading and after all IO has been |
| 13492 | * stopped. |
| 13493 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13494 | static int |
| 13495 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13496 | struct list_head *post_sgl_list, |
| 13497 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13498 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13499 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13500 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13501 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13502 | void *viraddr; |
| 13503 | LPFC_MBOXQ_t *mbox; |
| 13504 | uint32_t reqlen, alloclen, pg_pairs; |
| 13505 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13506 | uint16_t xritag_start = 0; |
| 13507 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13508 | uint32_t shdr_status, shdr_add_status; |
| 13509 | union lpfc_sli4_cfg_shdr *shdr; |
| 13510 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13511 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13512 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13513 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13514 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13515 | "2559 Block sgl registration required DMA " |
| 13516 | "size (%d) great than a page\n", reqlen); |
| 13517 | return -ENOMEM; |
| 13518 | } |
| 13519 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13520 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13521 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13522 | |
| 13523 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13524 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13525 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13526 | LPFC_SLI4_MBX_NEMBED); |
| 13527 | |
| 13528 | if (alloclen < reqlen) { |
| 13529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13530 | "0285 Allocated DMA memory size (%d) is " |
| 13531 | "less than the requested DMA memory " |
| 13532 | "size (%d)\n", alloclen, reqlen); |
| 13533 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13534 | return -ENOMEM; |
| 13535 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13536 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13537 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13538 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13539 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13540 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13541 | pg_pairs = 0; |
| 13542 | 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] | 13543 | /* Set up the sge entry */ |
| 13544 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13545 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 13546 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13547 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 13548 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13549 | cpu_to_le32(putPaddrLow(0)); |
| 13550 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13551 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13552 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13553 | /* Keep the first xritag on the list */ |
| 13554 | if (pg_pairs == 0) |
| 13555 | xritag_start = sglq_entry->sli4_xritag; |
| 13556 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13557 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13558 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13559 | |
| 13560 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13561 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13562 | 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] | 13563 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13564 | if (!phba->sli4_hba.intr_enable) |
| 13565 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13566 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13567 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13568 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13569 | } |
| 13570 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13571 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13572 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13573 | if (rc != MBX_TIMEOUT) |
| 13574 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13575 | if (shdr_status || shdr_add_status || rc) { |
| 13576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13577 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 13578 | "status x%x add_status x%x mbx status x%x\n", |
| 13579 | shdr_status, shdr_add_status, rc); |
| 13580 | rc = -ENXIO; |
| 13581 | } |
| 13582 | return rc; |
| 13583 | } |
| 13584 | |
| 13585 | /** |
| 13586 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 13587 | * @phba: pointer to lpfc hba data structure. |
| 13588 | * @sblist: pointer to scsi buffer list. |
| 13589 | * @count: number of scsi buffers on the list. |
| 13590 | * |
| 13591 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 13592 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 13593 | * No Lock is held. |
| 13594 | * |
| 13595 | **/ |
| 13596 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13597 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 13598 | struct list_head *sblist, |
| 13599 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13600 | { |
| 13601 | struct lpfc_scsi_buf *psb; |
| 13602 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13603 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13604 | void *viraddr; |
| 13605 | LPFC_MBOXQ_t *mbox; |
| 13606 | uint32_t reqlen, alloclen, pg_pairs; |
| 13607 | uint32_t mbox_tmo; |
| 13608 | uint16_t xritag_start = 0; |
| 13609 | int rc = 0; |
| 13610 | uint32_t shdr_status, shdr_add_status; |
| 13611 | dma_addr_t pdma_phys_bpl1; |
| 13612 | union lpfc_sli4_cfg_shdr *shdr; |
| 13613 | |
| 13614 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13615 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13616 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13617 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13618 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13619 | "0217 Block sgl registration required DMA " |
| 13620 | "size (%d) great than a page\n", reqlen); |
| 13621 | return -ENOMEM; |
| 13622 | } |
| 13623 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13624 | if (!mbox) { |
| 13625 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13626 | "0283 Failed to allocate mbox cmd memory\n"); |
| 13627 | return -ENOMEM; |
| 13628 | } |
| 13629 | |
| 13630 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13631 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13632 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13633 | LPFC_SLI4_MBX_NEMBED); |
| 13634 | |
| 13635 | if (alloclen < reqlen) { |
| 13636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13637 | "2561 Allocated DMA memory size (%d) is " |
| 13638 | "less than the requested DMA memory " |
| 13639 | "size (%d)\n", alloclen, reqlen); |
| 13640 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13641 | return -ENOMEM; |
| 13642 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13643 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13644 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13645 | viraddr = mbox->sge_array->addr[0]; |
| 13646 | |
| 13647 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 13648 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 13649 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 13650 | |
| 13651 | pg_pairs = 0; |
| 13652 | list_for_each_entry(psb, sblist, list) { |
| 13653 | /* Set up the sge entry */ |
| 13654 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 13655 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 13656 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 13657 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 13658 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 13659 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 13660 | else |
| 13661 | pdma_phys_bpl1 = 0; |
| 13662 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 13663 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 13664 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 13665 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 13666 | /* Keep the first xritag on the list */ |
| 13667 | if (pg_pairs == 0) |
| 13668 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 13669 | sgl_pg_pairs++; |
| 13670 | pg_pairs++; |
| 13671 | } |
| 13672 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 13673 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 13674 | /* Perform endian conversion if necessary */ |
| 13675 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 13676 | |
| 13677 | if (!phba->sli4_hba.intr_enable) |
| 13678 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13679 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13680 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13681 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13682 | } |
| 13683 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 13684 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13685 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13686 | if (rc != MBX_TIMEOUT) |
| 13687 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 13688 | if (shdr_status || shdr_add_status || rc) { |
| 13689 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13690 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 13691 | "status x%x add_status x%x mbx status x%x\n", |
| 13692 | shdr_status, shdr_add_status, rc); |
| 13693 | rc = -ENXIO; |
| 13694 | } |
| 13695 | return rc; |
| 13696 | } |
| 13697 | |
| 13698 | /** |
| 13699 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 13700 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 13701 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13702 | * |
| 13703 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 13704 | * valid type of frame that the LPFC driver will handle. This function will |
| 13705 | * return a zero if the frame is a valid frame or a non zero value when the |
| 13706 | * frame does not pass the check. |
| 13707 | **/ |
| 13708 | static int |
| 13709 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 13710 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 13711 | /* make rctl_names static to save stack space */ |
| 13712 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13713 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 13714 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13715 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13716 | |
| 13717 | switch (fc_hdr->fh_r_ctl) { |
| 13718 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 13719 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 13720 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 13721 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 13722 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 13723 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 13724 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 13725 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 13726 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 13727 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 13728 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 13729 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 13730 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 13731 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 13732 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 13733 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 13734 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 13735 | case FC_RCTL_BA_PRMT: |
| 13736 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 13737 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 13738 | case FC_RCTL_P_RJT: /* port reject */ |
| 13739 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 13740 | case FC_RCTL_P_BSY: /* port busy */ |
| 13741 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 13742 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 13743 | case FC_RCTL_LCR: /* link credit reset */ |
| 13744 | case FC_RCTL_END: /* end */ |
| 13745 | break; |
| 13746 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 13747 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13748 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 13749 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 13750 | default: |
| 13751 | goto drop; |
| 13752 | } |
| 13753 | switch (fc_hdr->fh_type) { |
| 13754 | case FC_TYPE_BLS: |
| 13755 | case FC_TYPE_ELS: |
| 13756 | case FC_TYPE_FCP: |
| 13757 | case FC_TYPE_CT: |
| 13758 | break; |
| 13759 | case FC_TYPE_IP: |
| 13760 | case FC_TYPE_ILS: |
| 13761 | default: |
| 13762 | goto drop; |
| 13763 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13764 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13765 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13766 | "2538 Received frame rctl:%s type:%s " |
| 13767 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13768 | rctl_names[fc_hdr->fh_r_ctl], |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 13769 | type_names[fc_hdr->fh_type], |
| 13770 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 13771 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 13772 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13773 | return 0; |
| 13774 | drop: |
| 13775 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 13776 | "2539 Dropped frame rctl:%s type:%s\n", |
| 13777 | rctl_names[fc_hdr->fh_r_ctl], |
| 13778 | type_names[fc_hdr->fh_type]); |
| 13779 | return 1; |
| 13780 | } |
| 13781 | |
| 13782 | /** |
| 13783 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 13784 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13785 | * |
| 13786 | * This function processes the FC header to retrieve the VFI from the VF |
| 13787 | * header, if one exists. This function will return the VFI if one exists |
| 13788 | * or 0 if no VSAN Header exists. |
| 13789 | **/ |
| 13790 | static uint32_t |
| 13791 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 13792 | { |
| 13793 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 13794 | |
| 13795 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 13796 | return 0; |
| 13797 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 13798 | } |
| 13799 | |
| 13800 | /** |
| 13801 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 13802 | * @phba: Pointer to the HBA structure to search for the vport on |
| 13803 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 13804 | * @fcfi: The FC Fabric ID that the frame came from |
| 13805 | * |
| 13806 | * This function searches the @phba for a vport that matches the content of the |
| 13807 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 13808 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 13809 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 13810 | * vport. |
| 13811 | **/ |
| 13812 | static struct lpfc_vport * |
| 13813 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 13814 | uint16_t fcfi) |
| 13815 | { |
| 13816 | struct lpfc_vport **vports; |
| 13817 | struct lpfc_vport *vport = NULL; |
| 13818 | int i; |
| 13819 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 13820 | fc_hdr->fh_d_id[1] << 8 | |
| 13821 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13822 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 13823 | if (did == Fabric_DID) |
| 13824 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 13825 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 13826 | !(phba->link_state == LPFC_HBA_READY)) |
| 13827 | return phba->pport; |
| 13828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13829 | vports = lpfc_create_vport_work_array(phba); |
| 13830 | if (vports != NULL) |
| 13831 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 13832 | if (phba->fcf.fcfi == fcfi && |
| 13833 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 13834 | vports[i]->fc_myDID == did) { |
| 13835 | vport = vports[i]; |
| 13836 | break; |
| 13837 | } |
| 13838 | } |
| 13839 | lpfc_destroy_vport_work_array(phba, vports); |
| 13840 | return vport; |
| 13841 | } |
| 13842 | |
| 13843 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13844 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 13845 | * @vport: The vport to work on. |
| 13846 | * |
| 13847 | * This function updates the receive sequence time stamp for this vport. The |
| 13848 | * receive sequence time stamp indicates the time that the last frame of the |
| 13849 | * the sequence that has been idle for the longest amount of time was received. |
| 13850 | * the driver uses this time stamp to indicate if any received sequences have |
| 13851 | * timed out. |
| 13852 | **/ |
| 13853 | void |
| 13854 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 13855 | { |
| 13856 | struct lpfc_dmabuf *h_buf; |
| 13857 | struct hbq_dmabuf *dmabuf = NULL; |
| 13858 | |
| 13859 | /* get the oldest sequence on the rcv list */ |
| 13860 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 13861 | struct lpfc_dmabuf, list); |
| 13862 | if (!h_buf) |
| 13863 | return; |
| 13864 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13865 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 13866 | } |
| 13867 | |
| 13868 | /** |
| 13869 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 13870 | * @vport: The vport that the received sequences were sent to. |
| 13871 | * |
| 13872 | * This function cleans up all outstanding received sequences. This is called |
| 13873 | * by the driver when a link event or user action invalidates all the received |
| 13874 | * sequences. |
| 13875 | **/ |
| 13876 | void |
| 13877 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 13878 | { |
| 13879 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13880 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13881 | struct hbq_dmabuf *dmabuf = NULL; |
| 13882 | |
| 13883 | /* start with the oldest sequence on the rcv list */ |
| 13884 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13885 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13886 | list_del_init(&dmabuf->hbuf.list); |
| 13887 | list_for_each_entry_safe(d_buf, dnext, |
| 13888 | &dmabuf->dbuf.list, list) { |
| 13889 | list_del_init(&d_buf->list); |
| 13890 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13891 | } |
| 13892 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13893 | } |
| 13894 | } |
| 13895 | |
| 13896 | /** |
| 13897 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 13898 | * @vport: The vport that the received sequences were sent to. |
| 13899 | * |
| 13900 | * This function determines whether any received sequences have timed out by |
| 13901 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 13902 | * indicates that there is at least one timed out sequence this routine will |
| 13903 | * go through the received sequences one at a time from most inactive to most |
| 13904 | * active to determine which ones need to be cleaned up. Once it has determined |
| 13905 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 13906 | * without sending an abort. |
| 13907 | **/ |
| 13908 | void |
| 13909 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 13910 | { |
| 13911 | struct lpfc_dmabuf *h_buf, *hnext; |
| 13912 | struct lpfc_dmabuf *d_buf, *dnext; |
| 13913 | struct hbq_dmabuf *dmabuf = NULL; |
| 13914 | unsigned long timeout; |
| 13915 | int abort_count = 0; |
| 13916 | |
| 13917 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13918 | vport->rcv_buffer_time_stamp); |
| 13919 | if (list_empty(&vport->rcv_buffer_list) || |
| 13920 | time_before(jiffies, timeout)) |
| 13921 | return; |
| 13922 | /* start with the oldest sequence on the rcv list */ |
| 13923 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 13924 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13925 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 13926 | dmabuf->time_stamp); |
| 13927 | if (time_before(jiffies, timeout)) |
| 13928 | break; |
| 13929 | abort_count++; |
| 13930 | list_del_init(&dmabuf->hbuf.list); |
| 13931 | list_for_each_entry_safe(d_buf, dnext, |
| 13932 | &dmabuf->dbuf.list, list) { |
| 13933 | list_del_init(&d_buf->list); |
| 13934 | lpfc_in_buf_free(vport->phba, d_buf); |
| 13935 | } |
| 13936 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 13937 | } |
| 13938 | if (abort_count) |
| 13939 | lpfc_update_rcv_time_stamp(vport); |
| 13940 | } |
| 13941 | |
| 13942 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13943 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 13944 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 13945 | * |
| 13946 | * This function searches through the existing incomplete sequences that have |
| 13947 | * been sent to this @vport. If the frame matches one of the incomplete |
| 13948 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 13949 | * make up that sequence. If no sequence is found that matches this frame then |
| 13950 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 13951 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 13952 | * the frame was linked to. |
| 13953 | **/ |
| 13954 | static struct hbq_dmabuf * |
| 13955 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 13956 | { |
| 13957 | struct fc_frame_header *new_hdr; |
| 13958 | struct fc_frame_header *temp_hdr; |
| 13959 | struct lpfc_dmabuf *d_buf; |
| 13960 | struct lpfc_dmabuf *h_buf; |
| 13961 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 13962 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 13963 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13964 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13965 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13966 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 13967 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 13968 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 13969 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 13970 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 13971 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 13972 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 13973 | continue; |
| 13974 | /* found a pending sequence that matches this frame */ |
| 13975 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 13976 | break; |
| 13977 | } |
| 13978 | if (!seq_dmabuf) { |
| 13979 | /* |
| 13980 | * This indicates first frame received for this sequence. |
| 13981 | * Queue the buffer on the vport's rcv_buffer_list. |
| 13982 | */ |
| 13983 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13984 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13985 | return dmabuf; |
| 13986 | } |
| 13987 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 13988 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 13989 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13990 | list_del_init(&seq_dmabuf->hbuf.list); |
| 13991 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13992 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13993 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13994 | return dmabuf; |
| 13995 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13996 | /* move this sequence to the tail to indicate a young sequence */ |
| 13997 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 13998 | seq_dmabuf->time_stamp = jiffies; |
| 13999 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14000 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 14001 | temp_hdr = dmabuf->hbuf.virt; |
| 14002 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 14003 | return seq_dmabuf; |
| 14004 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14005 | /* find the correct place in the sequence to insert this frame */ |
| 14006 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14007 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14008 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14009 | /* |
| 14010 | * If the frame's sequence count is greater than the frame on |
| 14011 | * the list then insert the frame right after this frame |
| 14012 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14013 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14014 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14015 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14016 | return seq_dmabuf; |
| 14017 | } |
| 14018 | } |
| 14019 | return NULL; |
| 14020 | } |
| 14021 | |
| 14022 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14023 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14024 | * @vport: pointer to a vitural port |
| 14025 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14026 | * |
| 14027 | * This function tries to abort from the partially assembed sequence, described |
| 14028 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14029 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14030 | * the frames from the partially assembled sequence. |
| 14031 | * |
| 14032 | * Return |
| 14033 | * true -- if there is matching partially assembled sequence present and all |
| 14034 | * the frames freed with the sequence; |
| 14035 | * false -- if there is no matching partially assembled sequence present so |
| 14036 | * nothing got aborted in the lower layer driver |
| 14037 | **/ |
| 14038 | static bool |
| 14039 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14040 | struct hbq_dmabuf *dmabuf) |
| 14041 | { |
| 14042 | struct fc_frame_header *new_hdr; |
| 14043 | struct fc_frame_header *temp_hdr; |
| 14044 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14045 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14046 | |
| 14047 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14048 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14049 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14050 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14051 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14052 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14053 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14054 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14055 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14056 | continue; |
| 14057 | /* found a pending sequence that matches this frame */ |
| 14058 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14059 | break; |
| 14060 | } |
| 14061 | |
| 14062 | /* Free up all the frames from the partially assembled sequence */ |
| 14063 | if (seq_dmabuf) { |
| 14064 | list_for_each_entry_safe(d_buf, n_buf, |
| 14065 | &seq_dmabuf->dbuf.list, list) { |
| 14066 | list_del_init(&d_buf->list); |
| 14067 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14068 | } |
| 14069 | return true; |
| 14070 | } |
| 14071 | return false; |
| 14072 | } |
| 14073 | |
| 14074 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14075 | * 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] | 14076 | * @phba: Pointer to HBA context object. |
| 14077 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14078 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14079 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14080 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14081 | * event. It properly releases the memory allocated to the sequence abort |
| 14082 | * accept iocb. |
| 14083 | **/ |
| 14084 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14085 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14086 | struct lpfc_iocbq *cmd_iocbq, |
| 14087 | struct lpfc_iocbq *rsp_iocbq) |
| 14088 | { |
| 14089 | if (cmd_iocbq) |
| 14090 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14091 | |
| 14092 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14093 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14094 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14095 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14096 | rsp_iocbq->iocb.ulpStatus, |
| 14097 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14098 | } |
| 14099 | |
| 14100 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14101 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14102 | * @phba: Pointer to HBA context object. |
| 14103 | * @xri: xri id in transaction. |
| 14104 | * |
| 14105 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14106 | * used by the driver. |
| 14107 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14108 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14109 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14110 | uint16_t xri) |
| 14111 | { |
| 14112 | int i; |
| 14113 | |
| 14114 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14115 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14116 | return i; |
| 14117 | } |
| 14118 | return NO_XRI; |
| 14119 | } |
| 14120 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14121 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14122 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14123 | * @phba: Pointer to HBA context object. |
| 14124 | * @fc_hdr: pointer to a FC frame header. |
| 14125 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14126 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14127 | * event after aborting the sequence handling. |
| 14128 | **/ |
| 14129 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14130 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14131 | struct fc_frame_header *fc_hdr) |
| 14132 | { |
| 14133 | struct lpfc_iocbq *ctiocb = NULL; |
| 14134 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14135 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14136 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14137 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14138 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14139 | |
| 14140 | if (!lpfc_is_link_up(phba)) |
| 14141 | return; |
| 14142 | |
| 14143 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14144 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14145 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14146 | |
| 14147 | ndlp = lpfc_findnode_did(phba->pport, sid); |
| 14148 | if (!ndlp) { |
| 14149 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14150 | "1268 Find ndlp returned NULL for oxid:x%x " |
| 14151 | "SID:x%x\n", oxid, sid); |
| 14152 | return; |
| 14153 | } |
| 14154 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14155 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14156 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14157 | if (!ctiocb) |
| 14158 | return; |
| 14159 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14160 | /* Extract the F_CTL field from FC_HDR */ |
| 14161 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14162 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14163 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14164 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14165 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14166 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14167 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14168 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14169 | |
| 14170 | /* Fill in the rest of iocb fields */ |
| 14171 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14172 | icmd->ulpBdeCount = 0; |
| 14173 | icmd->ulpLe = 1; |
| 14174 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14175 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 14176 | ctiocb->context1 = ndlp; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14177 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14178 | ctiocb->iocb_cmpl = NULL; |
| 14179 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14180 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14181 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14182 | ctiocb->sli4_xritag = NO_XRI; |
| 14183 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14184 | if (fctl & FC_FC_EX_CTX) |
| 14185 | /* Exchange responder sent the abort so we |
| 14186 | * own the oxid. |
| 14187 | */ |
| 14188 | xri = oxid; |
| 14189 | else |
| 14190 | xri = rxid; |
| 14191 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14192 | if (lxri != NO_XRI) |
| 14193 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14194 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14195 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
| 14196 | * send a BLS_RJT. The driver no longer has that exchange. |
| 14197 | * Override the IOCB for a BA_RJT. |
| 14198 | */ |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14199 | if (xri > (phba->sli4_hba.max_cfg_param.max_xri + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14200 | phba->sli4_hba.max_cfg_param.xri_base) || |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14201 | xri > (lpfc_sli4_get_els_iocb_cnt(phba) + |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14202 | phba->sli4_hba.max_cfg_param.xri_base)) { |
| 14203 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14204 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14205 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14206 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14207 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14208 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14209 | if (fctl & FC_FC_EX_CTX) { |
| 14210 | /* ABTS sent by responder to CT exchange, construction |
| 14211 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14212 | * field and RX_ID from ABTS for RX_ID field. |
| 14213 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14214 | 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] | 14215 | } else { |
| 14216 | /* ABTS sent by initiator to CT exchange, construction |
| 14217 | * 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] | 14218 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14219 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14220 | 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] | 14221 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14222 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14223 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14224 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14225 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14226 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14227 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14228 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
| 14229 | |
| 14230 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14231 | if (rc == IOCB_ERROR) { |
| 14232 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 14233 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14234 | "xri x%x, Data x%x\n", |
| 14235 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14236 | phba->link_state); |
| 14237 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14238 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14239 | } |
| 14240 | |
| 14241 | /** |
| 14242 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14243 | * @vport: Pointer to the vport on which this sequence was received |
| 14244 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14245 | * |
| 14246 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14247 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14248 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14249 | * unsolicited receive sequence has been completely assembled and passed to |
| 14250 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14251 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14252 | * accept to accept the abort. |
| 14253 | **/ |
| 14254 | void |
| 14255 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14256 | struct hbq_dmabuf *dmabuf) |
| 14257 | { |
| 14258 | struct lpfc_hba *phba = vport->phba; |
| 14259 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14260 | uint32_t fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14261 | bool abts_par; |
| 14262 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14263 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14264 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14265 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14266 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14267 | if (fctl & FC_FC_EX_CTX) { |
| 14268 | /* |
| 14269 | * ABTS sent by responder to exchange, just free the buffer |
| 14270 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14271 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14272 | } else { |
| 14273 | /* |
| 14274 | * ABTS sent by initiator to exchange, need to do cleanup |
| 14275 | */ |
| 14276 | /* Try to abort partially assembled seq */ |
| 14277 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14278 | |
| 14279 | /* Send abort to ULP if partially seq abort failed */ |
| 14280 | if (abts_par == false) |
| 14281 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); |
| 14282 | else |
| 14283 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14284 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14285 | /* Send basic accept (BA_ACC) to the abort requester */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14286 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14287 | } |
| 14288 | |
| 14289 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14290 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14291 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14292 | * |
| 14293 | * This function checks the sequence, starting with the frame described by |
| 14294 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14295 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14296 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14297 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14298 | * set. 3) That there are no holes in the sequence count. The function will |
| 14299 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14300 | **/ |
| 14301 | static int |
| 14302 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14303 | { |
| 14304 | struct fc_frame_header *hdr; |
| 14305 | struct lpfc_dmabuf *d_buf; |
| 14306 | struct hbq_dmabuf *seq_dmabuf; |
| 14307 | uint32_t fctl; |
| 14308 | int seq_count = 0; |
| 14309 | |
| 14310 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14311 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14312 | if (hdr->fh_seq_cnt != seq_count) |
| 14313 | return 0; |
| 14314 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14315 | hdr->fh_f_ctl[1] << 8 | |
| 14316 | hdr->fh_f_ctl[2]); |
| 14317 | /* If last frame of sequence we can return success. */ |
| 14318 | if (fctl & FC_FC_END_SEQ) |
| 14319 | return 1; |
| 14320 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14321 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14322 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14323 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14324 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14325 | return 0; |
| 14326 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14327 | hdr->fh_f_ctl[1] << 8 | |
| 14328 | hdr->fh_f_ctl[2]); |
| 14329 | /* If last frame of sequence we can return success. */ |
| 14330 | if (fctl & FC_FC_END_SEQ) |
| 14331 | return 1; |
| 14332 | } |
| 14333 | return 0; |
| 14334 | } |
| 14335 | |
| 14336 | /** |
| 14337 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14338 | * @vport: Pointer to the vport on which this sequence was received |
| 14339 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14340 | * |
| 14341 | * This function takes a sequence, described by a list of frames, and creates |
| 14342 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14343 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14344 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14345 | * to allocate an iocbq then it throw out the received frames that were not |
| 14346 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14347 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14348 | **/ |
| 14349 | static struct lpfc_iocbq * |
| 14350 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14351 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14352 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14353 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14354 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14355 | struct fc_frame_header *fc_hdr; |
| 14356 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14357 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14358 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14359 | |
| 14360 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14361 | /* remove from receive buffer list */ |
| 14362 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14363 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14364 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14365 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14366 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14367 | /* Get an iocbq struct to fill in. */ |
| 14368 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14369 | if (first_iocbq) { |
| 14370 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14371 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14372 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14373 | |
| 14374 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14375 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14376 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14377 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14378 | sli4_did_from_fc_hdr(fc_hdr); |
| 14379 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14380 | } else |
| 14381 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14382 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14383 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14384 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14385 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14386 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14387 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14388 | /* put the first buffer into the first IOCBq */ |
| 14389 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14390 | first_iocbq->context3 = NULL; |
| 14391 | first_iocbq->iocb.ulpBdeCount = 1; |
| 14392 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14393 | LPFC_DATA_BUF_SIZE; |
| 14394 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14395 | tot_len = bf_get(lpfc_rcqe_length, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14396 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14397 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14398 | } |
| 14399 | iocbq = first_iocbq; |
| 14400 | /* |
| 14401 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14402 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14403 | */ |
| 14404 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14405 | if (!iocbq) { |
| 14406 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14407 | continue; |
| 14408 | } |
| 14409 | if (!iocbq->context3) { |
| 14410 | iocbq->context3 = d_buf; |
| 14411 | iocbq->iocb.ulpBdeCount++; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14412 | pbde = (struct ulp_bde64 *) |
| 14413 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14414 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14415 | |
| 14416 | /* We need to get the size out of the right CQE */ |
| 14417 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14418 | len = bf_get(lpfc_rcqe_length, |
| 14419 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14420 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14421 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14422 | } else { |
| 14423 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14424 | if (!iocbq) { |
| 14425 | if (first_iocbq) { |
| 14426 | first_iocbq->iocb.ulpStatus = |
| 14427 | IOSTAT_FCP_RSP_ERROR; |
| 14428 | first_iocbq->iocb.un.ulpWord[4] = |
| 14429 | IOERR_NO_RESOURCES; |
| 14430 | } |
| 14431 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14432 | continue; |
| 14433 | } |
| 14434 | iocbq->context2 = d_buf; |
| 14435 | iocbq->context3 = NULL; |
| 14436 | iocbq->iocb.ulpBdeCount = 1; |
| 14437 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14438 | LPFC_DATA_BUF_SIZE; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14439 | |
| 14440 | /* We need to get the size out of the right CQE */ |
| 14441 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14442 | len = bf_get(lpfc_rcqe_length, |
| 14443 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
| 14444 | tot_len += len; |
| 14445 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14446 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14447 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14448 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14449 | } |
| 14450 | } |
| 14451 | return first_iocbq; |
| 14452 | } |
| 14453 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14454 | static void |
| 14455 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14456 | struct hbq_dmabuf *seq_dmabuf) |
| 14457 | { |
| 14458 | struct fc_frame_header *fc_hdr; |
| 14459 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 14460 | struct lpfc_hba *phba = vport->phba; |
| 14461 | |
| 14462 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14463 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 14464 | if (!iocbq) { |
| 14465 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14466 | "2707 Ring %d handler: Failed to allocate " |
| 14467 | "iocb Rctl x%x Type x%x received\n", |
| 14468 | LPFC_ELS_RING, |
| 14469 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14470 | return; |
| 14471 | } |
| 14472 | if (!lpfc_complete_unsol_iocb(phba, |
| 14473 | &phba->sli.ring[LPFC_ELS_RING], |
| 14474 | iocbq, fc_hdr->fh_r_ctl, |
| 14475 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14476 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14477 | "2540 Ring %d handler: unexpected Rctl " |
| 14478 | "x%x Type x%x received\n", |
| 14479 | LPFC_ELS_RING, |
| 14480 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 14481 | |
| 14482 | /* Free iocb created in lpfc_prep_seq */ |
| 14483 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 14484 | &iocbq->list, list) { |
| 14485 | list_del_init(&curr_iocb->list); |
| 14486 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 14487 | } |
| 14488 | lpfc_sli_release_iocbq(phba, iocbq); |
| 14489 | } |
| 14490 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14491 | /** |
| 14492 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 14493 | * @phba: Pointer to HBA context object. |
| 14494 | * |
| 14495 | * This function is called with no lock held. This function processes all |
| 14496 | * the received buffers and gives it to upper layers when a received buffer |
| 14497 | * indicates that it is the final frame in the sequence. The interrupt |
| 14498 | * service routine processes received buffers at interrupt contexts and adds |
| 14499 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 14500 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 14501 | * appropriate receive function when the final frame in a sequence is received. |
| 14502 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14503 | void |
| 14504 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 14505 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14506 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14507 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14508 | struct fc_frame_header *fc_hdr; |
| 14509 | struct lpfc_vport *vport; |
| 14510 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14511 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14512 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14513 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14514 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14515 | /* check to see if this a valid type of frame */ |
| 14516 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 14517 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14518 | return; |
| 14519 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14520 | if ((bf_get(lpfc_cqe_code, |
| 14521 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 14522 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 14523 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14524 | else |
| 14525 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 14526 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14527 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14528 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14529 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14530 | /* throw out the frame */ |
| 14531 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14532 | return; |
| 14533 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14534 | |
| 14535 | /* d_id this frame is directed to */ |
| 14536 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 14537 | |
| 14538 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 14539 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 14540 | (did != Fabric_DID)) { |
| 14541 | /* |
| 14542 | * Throw out the frame if we are not pt2pt. |
| 14543 | * The pt2pt protocol allows for discovery frames |
| 14544 | * to be received without a registered VPI. |
| 14545 | */ |
| 14546 | if (!(vport->fc_flag & FC_PT2PT) || |
| 14547 | (phba->link_state == LPFC_HBA_READY)) { |
| 14548 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14549 | return; |
| 14550 | } |
| 14551 | } |
| 14552 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14553 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 14554 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 14555 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 14556 | return; |
| 14557 | } |
| 14558 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14559 | /* Link this frame */ |
| 14560 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 14561 | if (!seq_dmabuf) { |
| 14562 | /* unable to add frame to vport - throw it out */ |
| 14563 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14564 | return; |
| 14565 | } |
| 14566 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14567 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14568 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 14569 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14570 | /* Send the complete sequence to the upper layer protocol */ |
| 14571 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14572 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14573 | |
| 14574 | /** |
| 14575 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 14576 | * @phba: pointer to lpfc hba data structure. |
| 14577 | * |
| 14578 | * This routine is invoked to post rpi header templates to the |
| 14579 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14580 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14581 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14582 | * |
| 14583 | * This routine does not require any locks. It's usage is expected |
| 14584 | * to be driver load or reset recovery when the driver is |
| 14585 | * sequential. |
| 14586 | * |
| 14587 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14588 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14589 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14590 | * When this error occurs, the driver is not guaranteed |
| 14591 | * to have any rpi regions posted to the device and |
| 14592 | * must either attempt to repost the regions or take a |
| 14593 | * fatal error. |
| 14594 | **/ |
| 14595 | int |
| 14596 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 14597 | { |
| 14598 | struct lpfc_rpi_hdr *rpi_page; |
| 14599 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14600 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14601 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14602 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14603 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14604 | goto exit; |
| 14605 | if (phba->sli4_hba.extents_in_use) |
| 14606 | return -EIO; |
| 14607 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14608 | 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] | 14609 | /* |
| 14610 | * Assign the rpi headers a physical rpi only if the driver |
| 14611 | * has not initialized those resources. A port reset only |
| 14612 | * needs the headers posted. |
| 14613 | */ |
| 14614 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 14615 | LPFC_RPI_RSRC_RDY) |
| 14616 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 14617 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14618 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 14619 | if (rc != MBX_SUCCESS) { |
| 14620 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14621 | "2008 Error %d posting all rpi " |
| 14622 | "headers\n", rc); |
| 14623 | rc = -EIO; |
| 14624 | break; |
| 14625 | } |
| 14626 | } |
| 14627 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14628 | exit: |
| 14629 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 14630 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14631 | return rc; |
| 14632 | } |
| 14633 | |
| 14634 | /** |
| 14635 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 14636 | * @phba: pointer to lpfc hba data structure. |
| 14637 | * @rpi_page: pointer to the rpi memory region. |
| 14638 | * |
| 14639 | * This routine is invoked to post a single rpi header to the |
| 14640 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 14641 | * maps up to 64 rpi context regions. |
| 14642 | * |
| 14643 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14644 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14645 | * -ENOMEM - No available memory |
| 14646 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14647 | **/ |
| 14648 | int |
| 14649 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 14650 | { |
| 14651 | LPFC_MBOXQ_t *mboxq; |
| 14652 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 14653 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14654 | uint32_t shdr_status, shdr_add_status; |
| 14655 | union lpfc_sli4_cfg_shdr *shdr; |
| 14656 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14657 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 14658 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 14659 | return rc; |
| 14660 | if (phba->sli4_hba.extents_in_use) |
| 14661 | return -EIO; |
| 14662 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14663 | /* The port is notified of the header region via a mailbox command. */ |
| 14664 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14665 | if (!mboxq) { |
| 14666 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14667 | "2001 Unable to allocate memory for issuing " |
| 14668 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 14669 | return -ENOMEM; |
| 14670 | } |
| 14671 | |
| 14672 | /* Post all rpi memory regions to the port. */ |
| 14673 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14674 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14675 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 14676 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14677 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 14678 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14679 | |
| 14680 | |
| 14681 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14682 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 14683 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14684 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 14685 | hdr_tmpl, rpi_page->page_count); |
| 14686 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14687 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 14688 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14689 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14690 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 14691 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14692 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14693 | if (rc != MBX_TIMEOUT) |
| 14694 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14695 | if (shdr_status || shdr_add_status || rc) { |
| 14696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14697 | "2514 POST_RPI_HDR mailbox failed with " |
| 14698 | "status x%x add_status x%x, mbx status x%x\n", |
| 14699 | shdr_status, shdr_add_status, rc); |
| 14700 | rc = -ENXIO; |
| 14701 | } |
| 14702 | return rc; |
| 14703 | } |
| 14704 | |
| 14705 | /** |
| 14706 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 14707 | * @phba: pointer to lpfc hba data structure. |
| 14708 | * |
| 14709 | * This routine is invoked to post rpi header templates to the |
| 14710 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14711 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14712 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14713 | * |
| 14714 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 14715 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14716 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14717 | **/ |
| 14718 | int |
| 14719 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 14720 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14721 | unsigned long rpi; |
| 14722 | uint16_t max_rpi, rpi_limit; |
| 14723 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14724 | struct lpfc_rpi_hdr *rpi_hdr; |
| 14725 | |
| 14726 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14727 | rpi_limit = phba->sli4_hba.next_rpi; |
| 14728 | |
| 14729 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14730 | * Fetch the next logical rpi. Because this index is logical, |
| 14731 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14732 | */ |
| 14733 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14734 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 14735 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14736 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 14737 | else { |
| 14738 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 14739 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 14740 | phba->sli4_hba.rpi_count++; |
| 14741 | } |
| 14742 | |
| 14743 | /* |
| 14744 | * 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] | 14745 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14746 | */ |
| 14747 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 14748 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
| 14749 | spin_unlock_irq(&phba->hbalock); |
| 14750 | return rpi; |
| 14751 | } |
| 14752 | |
| 14753 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14754 | * RPI header postings are not required for SLI4 ports capable of |
| 14755 | * extents. |
| 14756 | */ |
| 14757 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
| 14758 | spin_unlock_irq(&phba->hbalock); |
| 14759 | return rpi; |
| 14760 | } |
| 14761 | |
| 14762 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14763 | * If the driver is running low on rpi resources, allocate another |
| 14764 | * page now. Note that the next_rpi value is used because |
| 14765 | * it represents how many are actually in use whereas max_rpi notes |
| 14766 | * how many are supported max by the device. |
| 14767 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14768 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14769 | spin_unlock_irq(&phba->hbalock); |
| 14770 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 14771 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 14772 | if (!rpi_hdr) { |
| 14773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14774 | "2002 Error Could not grow rpi " |
| 14775 | "count\n"); |
| 14776 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14777 | lrpi = rpi_hdr->start_rpi; |
| 14778 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14779 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 14780 | } |
| 14781 | } |
| 14782 | |
| 14783 | return rpi; |
| 14784 | } |
| 14785 | |
| 14786 | /** |
| 14787 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14788 | * @phba: pointer to lpfc hba data structure. |
| 14789 | * |
| 14790 | * This routine is invoked to release an rpi to the pool of |
| 14791 | * available rpis maintained by the driver. |
| 14792 | **/ |
| 14793 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14794 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14795 | { |
| 14796 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 14797 | phba->sli4_hba.rpi_count--; |
| 14798 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 14799 | } |
| 14800 | } |
| 14801 | |
| 14802 | /** |
| 14803 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 14804 | * @phba: pointer to lpfc hba data structure. |
| 14805 | * |
| 14806 | * This routine is invoked to release an rpi to the pool of |
| 14807 | * available rpis maintained by the driver. |
| 14808 | **/ |
| 14809 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14810 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 14811 | { |
| 14812 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 14813 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14814 | spin_unlock_irq(&phba->hbalock); |
| 14815 | } |
| 14816 | |
| 14817 | /** |
| 14818 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 14819 | * @phba: pointer to lpfc hba data structure. |
| 14820 | * |
| 14821 | * This routine is invoked to remove the memory region that |
| 14822 | * provided rpi via a bitmask. |
| 14823 | **/ |
| 14824 | void |
| 14825 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 14826 | { |
| 14827 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14828 | kfree(phba->sli4_hba.rpi_ids); |
| 14829 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14830 | } |
| 14831 | |
| 14832 | /** |
| 14833 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 14834 | * @phba: pointer to lpfc hba data structure. |
| 14835 | * |
| 14836 | * This routine is invoked to remove the memory region that |
| 14837 | * provided rpi via a bitmask. |
| 14838 | **/ |
| 14839 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14840 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 14841 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14842 | { |
| 14843 | LPFC_MBOXQ_t *mboxq; |
| 14844 | struct lpfc_hba *phba = ndlp->phba; |
| 14845 | int rc; |
| 14846 | |
| 14847 | /* The port is notified of the header region via a mailbox command. */ |
| 14848 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14849 | if (!mboxq) |
| 14850 | return -ENOMEM; |
| 14851 | |
| 14852 | /* Post all rpi memory regions to the port. */ |
| 14853 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14854 | if (cmpl) { |
| 14855 | mboxq->mbox_cmpl = cmpl; |
| 14856 | mboxq->context1 = arg; |
| 14857 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 14858 | } else |
| 14859 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14860 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14861 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 14862 | if (rc == MBX_NOT_FINISHED) { |
| 14863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14864 | "2010 Resume RPI Mailbox failed " |
| 14865 | "status %d, mbxStatus x%x\n", rc, |
| 14866 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 14867 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 14868 | return -EIO; |
| 14869 | } |
| 14870 | return 0; |
| 14871 | } |
| 14872 | |
| 14873 | /** |
| 14874 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14875 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14876 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14877 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14878 | * |
| 14879 | * Returns: |
| 14880 | * 0 success |
| 14881 | * -Evalue otherwise |
| 14882 | **/ |
| 14883 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14884 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14885 | { |
| 14886 | LPFC_MBOXQ_t *mboxq; |
| 14887 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14888 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14889 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14890 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14891 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14892 | if (!mboxq) |
| 14893 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14894 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14895 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14896 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14897 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14898 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14899 | "2022 INIT VPI Mailbox failed " |
| 14900 | "status %d, mbxStatus x%x\n", rc, |
| 14901 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14902 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14903 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14904 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 14905 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14906 | |
| 14907 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14908 | } |
| 14909 | |
| 14910 | /** |
| 14911 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 14912 | * @phba: pointer to lpfc hba data structure. |
| 14913 | * @mboxq: Pointer to mailbox object. |
| 14914 | * |
| 14915 | * This routine is invoked to manually add a single FCF record. The caller |
| 14916 | * must pass a completely initialized FCF_Record. This routine takes |
| 14917 | * care of the nonembedded mailbox operations. |
| 14918 | **/ |
| 14919 | static void |
| 14920 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 14921 | { |
| 14922 | void *virt_addr; |
| 14923 | union lpfc_sli4_cfg_shdr *shdr; |
| 14924 | uint32_t shdr_status, shdr_add_status; |
| 14925 | |
| 14926 | virt_addr = mboxq->sge_array->addr[0]; |
| 14927 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14928 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 14929 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14930 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14931 | |
| 14932 | if ((shdr_status || shdr_add_status) && |
| 14933 | (shdr_status != STATUS_FCF_IN_USE)) |
| 14934 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14935 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 14936 | "status x%x add_status x%x\n", |
| 14937 | shdr_status, shdr_add_status); |
| 14938 | |
| 14939 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14940 | } |
| 14941 | |
| 14942 | /** |
| 14943 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 14944 | * @phba: pointer to lpfc hba data structure. |
| 14945 | * @fcf_record: pointer to the initialized fcf record to add. |
| 14946 | * |
| 14947 | * This routine is invoked to manually add a single FCF record. The caller |
| 14948 | * must pass a completely initialized FCF_Record. This routine takes |
| 14949 | * care of the nonembedded mailbox operations. |
| 14950 | **/ |
| 14951 | int |
| 14952 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 14953 | { |
| 14954 | int rc = 0; |
| 14955 | LPFC_MBOXQ_t *mboxq; |
| 14956 | uint8_t *bytep; |
| 14957 | void *virt_addr; |
| 14958 | dma_addr_t phys_addr; |
| 14959 | struct lpfc_mbx_sge sge; |
| 14960 | uint32_t alloc_len, req_len; |
| 14961 | uint32_t fcfindex; |
| 14962 | |
| 14963 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14964 | if (!mboxq) { |
| 14965 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14966 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 14967 | return -ENOMEM; |
| 14968 | } |
| 14969 | |
| 14970 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 14971 | sizeof(uint32_t); |
| 14972 | |
| 14973 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14974 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14975 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 14976 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 14977 | if (alloc_len < req_len) { |
| 14978 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14979 | "2523 Allocated DMA memory size (x%x) is " |
| 14980 | "less than the requested DMA memory " |
| 14981 | "size (x%x)\n", alloc_len, req_len); |
| 14982 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 14983 | return -ENOMEM; |
| 14984 | } |
| 14985 | |
| 14986 | /* |
| 14987 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 14988 | * routine only uses a single SGE. |
| 14989 | */ |
| 14990 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 14991 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 14992 | virt_addr = mboxq->sge_array->addr[0]; |
| 14993 | /* |
| 14994 | * Configure the FCF record for FCFI 0. This is the driver's |
| 14995 | * hardcoded default and gets used in nonFIP mode. |
| 14996 | */ |
| 14997 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 14998 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 14999 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 15000 | |
| 15001 | /* |
| 15002 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 15003 | * the FCoE header plus word10. The data copy needs to be endian |
| 15004 | * correct. |
| 15005 | */ |
| 15006 | bytep += sizeof(uint32_t); |
| 15007 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15008 | mboxq->vport = phba->pport; |
| 15009 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15010 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15011 | if (rc == MBX_NOT_FINISHED) { |
| 15012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15013 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15014 | "status 0x%x\n", rc); |
| 15015 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15016 | rc = -EIO; |
| 15017 | } else |
| 15018 | rc = 0; |
| 15019 | |
| 15020 | return rc; |
| 15021 | } |
| 15022 | |
| 15023 | /** |
| 15024 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15025 | * @phba: pointer to lpfc hba data structure. |
| 15026 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15027 | * @fcf_index: FCF table entry index. |
| 15028 | * |
| 15029 | * This routine is invoked to build the driver's default FCF record. The |
| 15030 | * values used are hardcoded. This routine handles memory initialization. |
| 15031 | * |
| 15032 | **/ |
| 15033 | void |
| 15034 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15035 | struct fcf_record *fcf_record, |
| 15036 | uint16_t fcf_index) |
| 15037 | { |
| 15038 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15039 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15040 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15041 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15042 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15043 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15044 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15045 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15046 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15047 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15048 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15049 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15050 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15051 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15052 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15053 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15054 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15055 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15056 | /* Set the VLAN bit map */ |
| 15057 | if (phba->valid_vlan) { |
| 15058 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15059 | = 1 << (phba->vlan_id % 8); |
| 15060 | } |
| 15061 | } |
| 15062 | |
| 15063 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15064 | * 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] | 15065 | * @phba: pointer to lpfc hba data structure. |
| 15066 | * @fcf_index: FCF table entry offset. |
| 15067 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15068 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15069 | * record and processing it one at a time starting from the @fcf_index |
| 15070 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15071 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15072 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15073 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15074 | **/ |
| 15075 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15076 | 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] | 15077 | { |
| 15078 | int rc = 0, error; |
| 15079 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15080 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15081 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15082 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15083 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15084 | if (!mboxq) { |
| 15085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15086 | "2000 Failed to allocate mbox for " |
| 15087 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15088 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15089 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15090 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15091 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15092 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15093 | if (rc) { |
| 15094 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15095 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15096 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15097 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15098 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15099 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15100 | |
| 15101 | spin_lock_irq(&phba->hbalock); |
| 15102 | phba->hba_flag |= FCF_TS_INPROG; |
| 15103 | spin_unlock_irq(&phba->hbalock); |
| 15104 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15105 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15106 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15107 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15108 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15109 | /* Reset eligible FCF count for new scan */ |
| 15110 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15111 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15112 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15113 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15114 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15115 | if (error) { |
| 15116 | if (mboxq) |
| 15117 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15118 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15119 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15120 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15121 | spin_unlock_irq(&phba->hbalock); |
| 15122 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15123 | return error; |
| 15124 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15125 | |
| 15126 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15127 | * 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] | 15128 | * @phba: pointer to lpfc hba data structure. |
| 15129 | * @fcf_index: FCF table entry offset. |
| 15130 | * |
| 15131 | * 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] | 15132 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15133 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15134 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15135 | * otherwise. |
| 15136 | **/ |
| 15137 | int |
| 15138 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15139 | { |
| 15140 | int rc = 0, error; |
| 15141 | LPFC_MBOXQ_t *mboxq; |
| 15142 | |
| 15143 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15144 | if (!mboxq) { |
| 15145 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15146 | "2763 Failed to allocate mbox for " |
| 15147 | "READ_FCF cmd\n"); |
| 15148 | error = -ENOMEM; |
| 15149 | goto fail_fcf_read; |
| 15150 | } |
| 15151 | /* Construct the read FCF record mailbox command */ |
| 15152 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15153 | if (rc) { |
| 15154 | error = -EINVAL; |
| 15155 | goto fail_fcf_read; |
| 15156 | } |
| 15157 | /* Issue the mailbox command asynchronously */ |
| 15158 | mboxq->vport = phba->pport; |
| 15159 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15160 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15161 | if (rc == MBX_NOT_FINISHED) |
| 15162 | error = -EIO; |
| 15163 | else |
| 15164 | error = 0; |
| 15165 | |
| 15166 | fail_fcf_read: |
| 15167 | if (error && mboxq) |
| 15168 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15169 | return error; |
| 15170 | } |
| 15171 | |
| 15172 | /** |
| 15173 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15174 | * @phba: pointer to lpfc hba data structure. |
| 15175 | * @fcf_index: FCF table entry offset. |
| 15176 | * |
| 15177 | * 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] | 15178 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15179 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15180 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15181 | * otherwise. |
| 15182 | **/ |
| 15183 | int |
| 15184 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15185 | { |
| 15186 | int rc = 0, error; |
| 15187 | LPFC_MBOXQ_t *mboxq; |
| 15188 | |
| 15189 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15190 | if (!mboxq) { |
| 15191 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15192 | "2758 Failed to allocate mbox for " |
| 15193 | "READ_FCF cmd\n"); |
| 15194 | error = -ENOMEM; |
| 15195 | goto fail_fcf_read; |
| 15196 | } |
| 15197 | /* Construct the read FCF record mailbox command */ |
| 15198 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15199 | if (rc) { |
| 15200 | error = -EINVAL; |
| 15201 | goto fail_fcf_read; |
| 15202 | } |
| 15203 | /* Issue the mailbox command asynchronously */ |
| 15204 | mboxq->vport = phba->pport; |
| 15205 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15206 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15207 | if (rc == MBX_NOT_FINISHED) |
| 15208 | error = -EIO; |
| 15209 | else |
| 15210 | error = 0; |
| 15211 | |
| 15212 | fail_fcf_read: |
| 15213 | if (error && mboxq) |
| 15214 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15215 | return error; |
| 15216 | } |
| 15217 | |
| 15218 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15219 | * lpfc_check_next_fcf_pri |
| 15220 | * phba pointer to the lpfc_hba struct for this port. |
| 15221 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15222 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15223 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15224 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15225 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15226 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15227 | * fcf_indexes. |
| 15228 | * returns: |
| 15229 | * 1=success 0=failure |
| 15230 | **/ |
| 15231 | int |
| 15232 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15233 | { |
| 15234 | uint16_t next_fcf_pri; |
| 15235 | uint16_t last_index; |
| 15236 | struct lpfc_fcf_pri *fcf_pri; |
| 15237 | int rc; |
| 15238 | int ret = 0; |
| 15239 | |
| 15240 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15241 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15242 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15243 | "3060 Last IDX %d\n", last_index); |
| 15244 | if (list_empty(&phba->fcf.fcf_pri_list)) { |
| 15245 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15246 | "3061 Last IDX %d\n", last_index); |
| 15247 | return 0; /* Empty rr list */ |
| 15248 | } |
| 15249 | next_fcf_pri = 0; |
| 15250 | /* |
| 15251 | * Clear the rr_bmask and set all of the bits that are at this |
| 15252 | * priority. |
| 15253 | */ |
| 15254 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15255 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15256 | spin_lock_irq(&phba->hbalock); |
| 15257 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15258 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15259 | continue; |
| 15260 | /* |
| 15261 | * the 1st priority that has not FLOGI failed |
| 15262 | * will be the highest. |
| 15263 | */ |
| 15264 | if (!next_fcf_pri) |
| 15265 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15266 | spin_unlock_irq(&phba->hbalock); |
| 15267 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15268 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15269 | fcf_pri->fcf_rec.fcf_index); |
| 15270 | if (rc) |
| 15271 | return 0; |
| 15272 | } |
| 15273 | spin_lock_irq(&phba->hbalock); |
| 15274 | } |
| 15275 | /* |
| 15276 | * if next_fcf_pri was not set above and the list is not empty then |
| 15277 | * we have failed flogis on all of them. So reset flogi failed |
| 15278 | * and start at the begining. |
| 15279 | */ |
| 15280 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15281 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15282 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15283 | /* |
| 15284 | * the 1st priority that has not FLOGI failed |
| 15285 | * will be the highest. |
| 15286 | */ |
| 15287 | if (!next_fcf_pri) |
| 15288 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15289 | spin_unlock_irq(&phba->hbalock); |
| 15290 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15291 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15292 | fcf_pri->fcf_rec.fcf_index); |
| 15293 | if (rc) |
| 15294 | return 0; |
| 15295 | } |
| 15296 | spin_lock_irq(&phba->hbalock); |
| 15297 | } |
| 15298 | } else |
| 15299 | ret = 1; |
| 15300 | spin_unlock_irq(&phba->hbalock); |
| 15301 | |
| 15302 | return ret; |
| 15303 | } |
| 15304 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15305 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15306 | * @phba: pointer to lpfc hba data structure. |
| 15307 | * |
| 15308 | * This routine is to get the next eligible FCF record index in a round |
| 15309 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15310 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15311 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15312 | * shall be returned. |
| 15313 | **/ |
| 15314 | uint16_t |
| 15315 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15316 | { |
| 15317 | uint16_t next_fcf_index; |
| 15318 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15319 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15320 | next_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15321 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
| 15322 | LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15323 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15324 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15325 | next_fcf_index); |
| 15326 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15327 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15328 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15329 | /* |
| 15330 | * If we have wrapped then we need to clear the bits that |
| 15331 | * have been tested so that we can detect when we should |
| 15332 | * change the priority level. |
| 15333 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15334 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15335 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15336 | } |
| 15337 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15338 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15339 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15340 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15341 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15342 | /* |
| 15343 | * If next fcf index is not found check if there are lower |
| 15344 | * Priority level fcf's in the fcf_priority list. |
| 15345 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15346 | * at that level and continue the selection process. |
| 15347 | */ |
| 15348 | if (lpfc_check_next_fcf_pri_level(phba)) |
| 15349 | goto next_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15350 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15351 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15352 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15353 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15354 | else { |
| 15355 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15356 | "3063 Only FCF available idx %d, flag %x\n", |
| 15357 | next_fcf_index, |
| 15358 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15359 | return next_fcf_index; |
| 15360 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15361 | } |
| 15362 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15363 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15364 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15365 | LPFC_FCF_FLOGI_FAILED) |
| 15366 | goto next_priority; |
| 15367 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15368 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15369 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15370 | next_fcf_index); |
| 15371 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15372 | return next_fcf_index; |
| 15373 | } |
| 15374 | |
| 15375 | /** |
| 15376 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15377 | * @phba: pointer to lpfc hba data structure. |
| 15378 | * |
| 15379 | * 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] | 15380 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15381 | * does not go beyond the range of the driver allocated bmask dimension |
| 15382 | * before setting the bit. |
| 15383 | * |
| 15384 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15385 | * -EINVAL. |
| 15386 | **/ |
| 15387 | int |
| 15388 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15389 | { |
| 15390 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15391 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15392 | "2610 FCF (x%x) reached driver's book " |
| 15393 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15394 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15395 | return -EINVAL; |
| 15396 | } |
| 15397 | /* Set the eligible FCF record index bmask */ |
| 15398 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15399 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15400 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15401 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15402 | "bmask\n", fcf_index); |
| 15403 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15404 | return 0; |
| 15405 | } |
| 15406 | |
| 15407 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15408 | * 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] | 15409 | * @phba: pointer to lpfc hba data structure. |
| 15410 | * |
| 15411 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15412 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15413 | * does not go beyond the range of the driver allocated bmask dimension |
| 15414 | * before clearing the bit. |
| 15415 | **/ |
| 15416 | void |
| 15417 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15418 | { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15419 | struct lpfc_fcf_pri *fcf_pri; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15420 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15421 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15422 | "2762 FCF (x%x) reached driver's book " |
| 15423 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15424 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15425 | return; |
| 15426 | } |
| 15427 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15428 | spin_lock_irq(&phba->hbalock); |
| 15429 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15430 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15431 | list_del_init(&fcf_pri->list); |
| 15432 | break; |
| 15433 | } |
| 15434 | } |
| 15435 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15436 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15437 | |
| 15438 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15439 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15440 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15441 | } |
| 15442 | |
| 15443 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15444 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15445 | * @phba: pointer to lpfc hba data structure. |
| 15446 | * |
| 15447 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 15448 | * command. If the mailbox command returned failure, it will try to stop the |
| 15449 | * FCF rediscover wait timer. |
| 15450 | **/ |
| 15451 | void |
| 15452 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 15453 | { |
| 15454 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15455 | uint32_t shdr_status, shdr_add_status; |
| 15456 | |
| 15457 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15458 | |
| 15459 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 15460 | &redisc_fcf->header.cfg_shdr.response); |
| 15461 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 15462 | &redisc_fcf->header.cfg_shdr.response); |
| 15463 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15464 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15465 | "2746 Requesting for FCF rediscovery failed " |
| 15466 | "status x%x add_status x%x\n", |
| 15467 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15468 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15469 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15470 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15471 | spin_unlock_irq(&phba->hbalock); |
| 15472 | /* |
| 15473 | * CVL event triggered FCF rediscover request failed, |
| 15474 | * last resort to re-try current registered FCF entry. |
| 15475 | */ |
| 15476 | lpfc_retry_pport_discovery(phba); |
| 15477 | } else { |
| 15478 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15479 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15480 | spin_unlock_irq(&phba->hbalock); |
| 15481 | /* |
| 15482 | * DEAD FCF event triggered FCF rediscover request |
| 15483 | * failed, last resort to fail over as a link down |
| 15484 | * to FCF registration. |
| 15485 | */ |
| 15486 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 15487 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15488 | } else { |
| 15489 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15490 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15491 | /* |
| 15492 | * Start FCF rediscovery wait timer for pending FCF |
| 15493 | * before rescan FCF record table. |
| 15494 | */ |
| 15495 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15496 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15497 | |
| 15498 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15499 | } |
| 15500 | |
| 15501 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15502 | * 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] | 15503 | * @phba: pointer to lpfc hba data structure. |
| 15504 | * |
| 15505 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 15506 | * by the port. |
| 15507 | **/ |
| 15508 | int |
| 15509 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 15510 | { |
| 15511 | LPFC_MBOXQ_t *mbox; |
| 15512 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 15513 | int rc, length; |
| 15514 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15515 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 15516 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 15517 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15518 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15519 | if (!mbox) { |
| 15520 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15521 | "2745 Failed to allocate mbox for " |
| 15522 | "requesting FCF rediscover.\n"); |
| 15523 | return -ENOMEM; |
| 15524 | } |
| 15525 | |
| 15526 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 15527 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15528 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15529 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 15530 | length, LPFC_SLI4_MBX_EMBED); |
| 15531 | |
| 15532 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 15533 | /* Set count to 0 for invalidating the entire FCF database */ |
| 15534 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 15535 | |
| 15536 | /* Issue the mailbox command asynchronously */ |
| 15537 | mbox->vport = phba->pport; |
| 15538 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 15539 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 15540 | |
| 15541 | if (rc == MBX_NOT_FINISHED) { |
| 15542 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15543 | return -EIO; |
| 15544 | } |
| 15545 | return 0; |
| 15546 | } |
| 15547 | |
| 15548 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 15549 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 15550 | * @phba: pointer to lpfc hba data structure. |
| 15551 | * |
| 15552 | * This function is the failover routine as a last resort to the FCF DEAD |
| 15553 | * event when driver failed to perform fast FCF failover. |
| 15554 | **/ |
| 15555 | void |
| 15556 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 15557 | { |
| 15558 | uint32_t link_state; |
| 15559 | |
| 15560 | /* |
| 15561 | * Last resort as FCF DEAD event failover will treat this as |
| 15562 | * a link down, but save the link state because we don't want |
| 15563 | * it to be changed to Link Down unless it is already down. |
| 15564 | */ |
| 15565 | link_state = phba->link_state; |
| 15566 | lpfc_linkdown(phba); |
| 15567 | phba->link_state = link_state; |
| 15568 | |
| 15569 | /* Unregister FCF if no devices connected to it */ |
| 15570 | lpfc_unregister_unused_fcf(phba); |
| 15571 | } |
| 15572 | |
| 15573 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15574 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15575 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15576 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15577 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15578 | * This function gets SLI3 port configure region 23 data through memory dump |
| 15579 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15580 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15581 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15582 | static uint32_t |
| 15583 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15584 | { |
| 15585 | LPFC_MBOXQ_t *pmb = NULL; |
| 15586 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15587 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15588 | int rc; |
| 15589 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15590 | if (!rgn23_data) |
| 15591 | return 0; |
| 15592 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15593 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15594 | if (!pmb) { |
| 15595 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15596 | "2600 failed to allocate mailbox memory\n"); |
| 15597 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15598 | } |
| 15599 | mb = &pmb->u.mb; |
| 15600 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15601 | do { |
| 15602 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 15603 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 15604 | |
| 15605 | if (rc != MBX_SUCCESS) { |
| 15606 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15607 | "2601 failed to read config " |
| 15608 | "region 23, rc 0x%x Status 0x%x\n", |
| 15609 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15610 | mb->un.varDmp.word_cnt = 0; |
| 15611 | } |
| 15612 | /* |
| 15613 | * dump mem may return a zero when finished or we got a |
| 15614 | * mailbox error, either way we are done. |
| 15615 | */ |
| 15616 | if (mb->un.varDmp.word_cnt == 0) |
| 15617 | break; |
| 15618 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 15619 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 15620 | |
| 15621 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15622 | rgn23_data + offset, |
| 15623 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15624 | offset += mb->un.varDmp.word_cnt; |
| 15625 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 15626 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15627 | mempool_free(pmb, phba->mbox_mem_pool); |
| 15628 | return offset; |
| 15629 | } |
| 15630 | |
| 15631 | /** |
| 15632 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 15633 | * @phba: pointer to lpfc hba data structure. |
| 15634 | * @rgn23_data: pointer to configure region 23 data. |
| 15635 | * |
| 15636 | * This function gets SLI4 port configure region 23 data through memory dump |
| 15637 | * mailbox command. When it successfully retrieves data, the size of the data |
| 15638 | * will be returned, otherwise, 0 will be returned. |
| 15639 | **/ |
| 15640 | static uint32_t |
| 15641 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 15642 | { |
| 15643 | LPFC_MBOXQ_t *mboxq = NULL; |
| 15644 | struct lpfc_dmabuf *mp = NULL; |
| 15645 | struct lpfc_mqe *mqe; |
| 15646 | uint32_t data_length = 0; |
| 15647 | int rc; |
| 15648 | |
| 15649 | if (!rgn23_data) |
| 15650 | return 0; |
| 15651 | |
| 15652 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15653 | if (!mboxq) { |
| 15654 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15655 | "3105 failed to allocate mailbox memory\n"); |
| 15656 | return 0; |
| 15657 | } |
| 15658 | |
| 15659 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 15660 | goto out; |
| 15661 | mqe = &mboxq->u.mqe; |
| 15662 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 15663 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 15664 | if (rc) |
| 15665 | goto out; |
| 15666 | data_length = mqe->un.mb_words[5]; |
| 15667 | if (data_length == 0) |
| 15668 | goto out; |
| 15669 | if (data_length > DMP_RGN23_SIZE) { |
| 15670 | data_length = 0; |
| 15671 | goto out; |
| 15672 | } |
| 15673 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 15674 | out: |
| 15675 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15676 | if (mp) { |
| 15677 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15678 | kfree(mp); |
| 15679 | } |
| 15680 | return data_length; |
| 15681 | } |
| 15682 | |
| 15683 | /** |
| 15684 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 15685 | * @phba: pointer to lpfc hba data structure. |
| 15686 | * |
| 15687 | * This function read region 23 and parse TLV for port status to |
| 15688 | * decide if the user disaled the port. If the TLV indicates the |
| 15689 | * port is disabled, the hba_flag is set accordingly. |
| 15690 | **/ |
| 15691 | void |
| 15692 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 15693 | { |
| 15694 | uint8_t *rgn23_data = NULL; |
| 15695 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 15696 | uint32_t offset = 0; |
| 15697 | |
| 15698 | /* Get adapter Region 23 data */ |
| 15699 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 15700 | if (!rgn23_data) |
| 15701 | goto out; |
| 15702 | |
| 15703 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15704 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 15705 | else { |
| 15706 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 15707 | &phba->sli4_hba.sli_intf); |
| 15708 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 15709 | goto out; |
| 15710 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 15711 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15712 | |
| 15713 | if (!data_size) |
| 15714 | goto out; |
| 15715 | |
| 15716 | /* Check the region signature first */ |
| 15717 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 15718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15719 | "2619 Config region 23 has bad signature\n"); |
| 15720 | goto out; |
| 15721 | } |
| 15722 | offset += 4; |
| 15723 | |
| 15724 | /* Check the data structure version */ |
| 15725 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 15726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15727 | "2620 Config region 23 has bad version\n"); |
| 15728 | goto out; |
| 15729 | } |
| 15730 | offset += 4; |
| 15731 | |
| 15732 | /* Parse TLV entries in the region */ |
| 15733 | while (offset < data_size) { |
| 15734 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 15735 | break; |
| 15736 | /* |
| 15737 | * If the TLV is not driver specific TLV or driver id is |
| 15738 | * not linux driver id, skip the record. |
| 15739 | */ |
| 15740 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 15741 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 15742 | (rgn23_data[offset + 3] != 0)) { |
| 15743 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15744 | continue; |
| 15745 | } |
| 15746 | |
| 15747 | /* Driver found a driver specific TLV in the config region */ |
| 15748 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 15749 | offset += 4; |
| 15750 | tlv_offset = 0; |
| 15751 | |
| 15752 | /* |
| 15753 | * Search for configured port state sub-TLV. |
| 15754 | */ |
| 15755 | while ((offset < data_size) && |
| 15756 | (tlv_offset < sub_tlv_len)) { |
| 15757 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 15758 | offset += 4; |
| 15759 | tlv_offset += 4; |
| 15760 | break; |
| 15761 | } |
| 15762 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 15763 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 15764 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 15765 | continue; |
| 15766 | } |
| 15767 | |
| 15768 | /* This HBA contains PORT_STE configured */ |
| 15769 | if (!rgn23_data[offset + 2]) |
| 15770 | phba->hba_flag |= LINK_DISABLED; |
| 15771 | |
| 15772 | goto out; |
| 15773 | } |
| 15774 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 15775 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15776 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15777 | kfree(rgn23_data); |
| 15778 | return; |
| 15779 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15780 | |
| 15781 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15782 | * lpfc_wr_object - write an object to the firmware |
| 15783 | * @phba: HBA structure that indicates port to create a queue on. |
| 15784 | * @dmabuf_list: list of dmabufs to write to the port. |
| 15785 | * @size: the total byte value of the objects to write to the port. |
| 15786 | * @offset: the current offset to be used to start the transfer. |
| 15787 | * |
| 15788 | * This routine will create a wr_object mailbox command to send to the port. |
| 15789 | * the mailbox command will be constructed using the dma buffers described in |
| 15790 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 15791 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 15792 | * used to indicate the starting offset of the transfer and will also return |
| 15793 | * the offset after the write object mailbox has completed. @size is used to |
| 15794 | * determine the end of the object and whether the eof bit should be set. |
| 15795 | * |
| 15796 | * Return 0 is successful and offset will contain the the new offset to use |
| 15797 | * for the next write. |
| 15798 | * Return negative value for error cases. |
| 15799 | **/ |
| 15800 | int |
| 15801 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 15802 | uint32_t size, uint32_t *offset) |
| 15803 | { |
| 15804 | struct lpfc_mbx_wr_object *wr_object; |
| 15805 | LPFC_MBOXQ_t *mbox; |
| 15806 | int rc = 0, i = 0; |
| 15807 | uint32_t shdr_status, shdr_add_status; |
| 15808 | uint32_t mbox_tmo; |
| 15809 | union lpfc_sli4_cfg_shdr *shdr; |
| 15810 | struct lpfc_dmabuf *dmabuf; |
| 15811 | uint32_t written = 0; |
| 15812 | |
| 15813 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15814 | if (!mbox) |
| 15815 | return -ENOMEM; |
| 15816 | |
| 15817 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15818 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 15819 | sizeof(struct lpfc_mbx_wr_object) - |
| 15820 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 15821 | |
| 15822 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 15823 | wr_object->u.request.write_offset = *offset; |
| 15824 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 15825 | wr_object->u.request.object_name[0] = |
| 15826 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 15827 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 15828 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 15829 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 15830 | break; |
| 15831 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 15832 | wr_object->u.request.bde[i].addrHigh = |
| 15833 | putPaddrHigh(dmabuf->phys); |
| 15834 | if (written + SLI4_PAGE_SIZE >= size) { |
| 15835 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15836 | (size - written); |
| 15837 | written += (size - written); |
| 15838 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 15839 | } else { |
| 15840 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 15841 | SLI4_PAGE_SIZE; |
| 15842 | written += SLI4_PAGE_SIZE; |
| 15843 | } |
| 15844 | i++; |
| 15845 | } |
| 15846 | wr_object->u.request.bde_count = i; |
| 15847 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 15848 | if (!phba->sli4_hba.intr_enable) |
| 15849 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15850 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15851 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 15852 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15853 | } |
| 15854 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15855 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 15856 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15857 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15858 | if (rc != MBX_TIMEOUT) |
| 15859 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15860 | if (shdr_status || shdr_add_status || rc) { |
| 15861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15862 | "3025 Write Object mailbox failed with " |
| 15863 | "status x%x add_status x%x, mbx status x%x\n", |
| 15864 | shdr_status, shdr_add_status, rc); |
| 15865 | rc = -ENXIO; |
| 15866 | } else |
| 15867 | *offset += wr_object->u.response.actual_write_length; |
| 15868 | return rc; |
| 15869 | } |
| 15870 | |
| 15871 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15872 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 15873 | * @vport: pointer to vport data structure. |
| 15874 | * |
| 15875 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 15876 | * and REG_VPI mailbox commands associated with the vport. This function |
| 15877 | * is called when driver want to restart discovery of the vport due to |
| 15878 | * a Clear Virtual Link event. |
| 15879 | **/ |
| 15880 | void |
| 15881 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 15882 | { |
| 15883 | struct lpfc_hba *phba = vport->phba; |
| 15884 | LPFC_MBOXQ_t *mb, *nextmb; |
| 15885 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15886 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15887 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15888 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15889 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15890 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15891 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15892 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15893 | spin_lock_irq(&phba->hbalock); |
| 15894 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 15895 | if (mb->vport != vport) |
| 15896 | continue; |
| 15897 | |
| 15898 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15899 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15900 | continue; |
| 15901 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15902 | list_del(&mb->list); |
| 15903 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 15904 | } |
| 15905 | /* Clean up active mailbox command with the vport */ |
| 15906 | mb = phba->sli.mbox_active; |
| 15907 | if (mb && (mb->vport == vport)) { |
| 15908 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 15909 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 15910 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15911 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15912 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15913 | /* Put reference count for delayed processing */ |
| 15914 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 15915 | /* Unregister the RPI when mailbox complete */ |
| 15916 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15917 | } |
| 15918 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 15919 | /* Cleanup any mailbox completions which are not yet processed */ |
| 15920 | do { |
| 15921 | restart_loop = 0; |
| 15922 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 15923 | /* |
| 15924 | * If this mailox is already processed or it is |
| 15925 | * for another vport ignore it. |
| 15926 | */ |
| 15927 | if ((mb->vport != vport) || |
| 15928 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 15929 | continue; |
| 15930 | |
| 15931 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 15932 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 15933 | continue; |
| 15934 | |
| 15935 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15936 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15937 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 15938 | /* Unregister the RPI when mailbox complete */ |
| 15939 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 15940 | restart_loop = 1; |
| 15941 | spin_unlock_irq(&phba->hbalock); |
| 15942 | spin_lock(shost->host_lock); |
| 15943 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15944 | spin_unlock(shost->host_lock); |
| 15945 | spin_lock_irq(&phba->hbalock); |
| 15946 | break; |
| 15947 | } |
| 15948 | } |
| 15949 | } while (restart_loop); |
| 15950 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15951 | spin_unlock_irq(&phba->hbalock); |
| 15952 | |
| 15953 | /* Release the cleaned-up mailbox commands */ |
| 15954 | while (!list_empty(&mbox_cmd_list)) { |
| 15955 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15956 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 15957 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 15958 | if (mp) { |
| 15959 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 15960 | kfree(mp); |
| 15961 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15962 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15963 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15964 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15965 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 15966 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 15967 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15968 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 15969 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15970 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15971 | mempool_free(mb, phba->mbox_mem_pool); |
| 15972 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15973 | |
| 15974 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 15975 | if (act_mbx_ndlp) { |
| 15976 | spin_lock(shost->host_lock); |
| 15977 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 15978 | spin_unlock(shost->host_lock); |
| 15979 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15980 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 15981 | } |
| 15982 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 15983 | /** |
| 15984 | * lpfc_drain_txq - Drain the txq |
| 15985 | * @phba: Pointer to HBA context object. |
| 15986 | * |
| 15987 | * This function attempt to submit IOCBs on the txq |
| 15988 | * to the adapter. For SLI4 adapters, the txq contains |
| 15989 | * ELS IOCBs that have been deferred because the there |
| 15990 | * are no SGLs. This congestion can occur with large |
| 15991 | * vport counts during node discovery. |
| 15992 | **/ |
| 15993 | |
| 15994 | uint32_t |
| 15995 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 15996 | { |
| 15997 | LIST_HEAD(completions); |
| 15998 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 15999 | struct lpfc_iocbq *piocbq = 0; |
| 16000 | unsigned long iflags = 0; |
| 16001 | char *fail_msg = NULL; |
| 16002 | struct lpfc_sglq *sglq; |
| 16003 | union lpfc_wqe wqe; |
| 16004 | |
| 16005 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16006 | if (pring->txq_cnt > pring->txq_max) |
| 16007 | pring->txq_max = pring->txq_cnt; |
| 16008 | |
| 16009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16010 | |
| 16011 | while (pring->txq_cnt) { |
| 16012 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 16013 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16014 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16015 | if (!piocbq) { |
| 16016 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16017 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16018 | "2823 txq empty and txq_cnt is %d\n ", |
| 16019 | pring->txq_cnt); |
| 16020 | break; |
| 16021 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16022 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16023 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16024 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16025 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16026 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16027 | } |
| 16028 | |
| 16029 | /* The xri and iocb resources secured, |
| 16030 | * attempt to issue request |
| 16031 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16032 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16033 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16034 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16035 | fail_msg = "to convert bpl to sgl"; |
| 16036 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16037 | fail_msg = "to convert iocb to wqe"; |
| 16038 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16039 | fail_msg = " - Wq is full"; |
| 16040 | else |
| 16041 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16042 | |
| 16043 | if (fail_msg) { |
| 16044 | /* Failed means we can't issue and need to cancel */ |
| 16045 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16046 | "2822 IOCB failed %s iotag 0x%x " |
| 16047 | "xri 0x%x\n", |
| 16048 | fail_msg, |
| 16049 | piocbq->iotag, piocbq->sli4_xritag); |
| 16050 | list_add_tail(&piocbq->list, &completions); |
| 16051 | } |
| 16052 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 16053 | } |
| 16054 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16055 | /* Cancel all the IOCBs that cannot be issued */ |
| 16056 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16057 | IOERR_SLI_ABORTED); |
| 16058 | |
| 16059 | return pring->txq_cnt; |
| 16060 | } |