| 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 | f25e8e7 | 2015-04-07 15:07:28 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2015 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> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 27 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_cmnd.h> |
| 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 33 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 35 | #include <linux/aer.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | #include "lpfc_hw.h" |
| 39 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 40 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 41 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_disc.h" |
| 43 | #include "lpfc_scsi.h" |
| 44 | #include "lpfc.h" |
| 45 | #include "lpfc_crtn.h" |
| 46 | #include "lpfc_logmsg.h" |
| 47 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 48 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 49 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | |
| 51 | /* There are only four IOCB completion types. */ |
| 52 | typedef enum _lpfc_iocb_type { |
| 53 | LPFC_UNKNOWN_IOCB, |
| 54 | LPFC_UNSOL_IOCB, |
| 55 | LPFC_SOL_IOCB, |
| 56 | LPFC_ABORT_IOCB |
| 57 | } lpfc_iocb_type; |
| 58 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 59 | |
| 60 | /* Provide function prototypes local to this module. */ |
| 61 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 62 | uint32_t); |
| 63 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 64 | uint8_t *, uint32_t *); |
| 65 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 66 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 67 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 68 | struct hbq_dmabuf *); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 69 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
| 70 | struct lpfc_cqe *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 71 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
| 72 | int); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 73 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
| 74 | uint32_t); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 75 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 76 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 77 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 78 | static IOCB_t * |
| 79 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 80 | { |
| 81 | return &iocbq->iocb; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 86 | * @q: The Work Queue to operate on. |
| 87 | * @wqe: The work Queue Entry to put on the Work queue. |
| 88 | * |
| 89 | * This routine will copy the contents of @wqe to the next available entry on |
| 90 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 91 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 92 | * successful. If no entries are available on @q then this function will return |
| 93 | * -ENOMEM. |
| 94 | * The caller is expected to hold the hbalock when calling this routine. |
| 95 | **/ |
| 96 | static uint32_t |
| 97 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 98 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 99 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 100 | struct lpfc_register doorbell; |
| 101 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 102 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 103 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 104 | /* sanity check on queue memory */ |
| 105 | if (unlikely(!q)) |
| 106 | return -ENOMEM; |
| 107 | temp_wqe = q->qe[q->host_index].wqe; |
| 108 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 109 | /* 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] | 110 | idx = ((q->host_index + 1) % q->entry_count); |
| 111 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 112 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 113 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 114 | } |
| 115 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 116 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 117 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 118 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 119 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 120 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 121 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 122 | |
| 123 | /* Update the host index before invoking device */ |
| 124 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 125 | |
| 126 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 127 | |
| 128 | /* Ring Doorbell */ |
| 129 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 130 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 131 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 132 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 133 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 134 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 135 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 136 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 137 | } else { |
| 138 | return -EINVAL; |
| 139 | } |
| 140 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 147 | * @q: The Work Queue to operate on. |
| 148 | * @index: The index to advance the hba index to. |
| 149 | * |
| 150 | * This routine will update the HBA index of a queue to reflect consumption of |
| 151 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 152 | * an entry the host calls this function to update the queue's internal |
| 153 | * pointers. This routine returns the number of entries that were consumed by |
| 154 | * the HBA. |
| 155 | **/ |
| 156 | static uint32_t |
| 157 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 158 | { |
| 159 | uint32_t released = 0; |
| 160 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 161 | /* sanity check on queue memory */ |
| 162 | if (unlikely(!q)) |
| 163 | return 0; |
| 164 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 165 | if (q->hba_index == index) |
| 166 | return 0; |
| 167 | do { |
| 168 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 169 | released++; |
| 170 | } while (q->hba_index != index); |
| 171 | return released; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 176 | * @q: The Mailbox Queue to operate on. |
| 177 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 178 | * |
| 179 | * This routine will copy the contents of @mqe to the next available entry on |
| 180 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 181 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 182 | * successful. If no entries are available on @q then this function will return |
| 183 | * -ENOMEM. |
| 184 | * The caller is expected to hold the hbalock when calling this routine. |
| 185 | **/ |
| 186 | static uint32_t |
| 187 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 188 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 189 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 190 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 191 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 192 | /* sanity check on queue memory */ |
| 193 | if (unlikely(!q)) |
| 194 | return -ENOMEM; |
| 195 | temp_mqe = q->qe[q->host_index].mqe; |
| 196 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 197 | /* If the host has not yet processed the next entry then we are done */ |
| 198 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 199 | return -ENOMEM; |
| 200 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 201 | /* Save off the mailbox pointer for completion */ |
| 202 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 203 | |
| 204 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 205 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 206 | |
| 207 | /* Ring Doorbell */ |
| 208 | doorbell.word0 = 0; |
| 209 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 210 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 211 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 217 | * @q: The Mailbox Queue to operate on. |
| 218 | * |
| 219 | * This routine will update the HBA index of a queue to reflect consumption of |
| 220 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 221 | * an entry the host calls this function to update the queue's internal |
| 222 | * pointers. This routine returns the number of entries that were consumed by |
| 223 | * the HBA. |
| 224 | **/ |
| 225 | static uint32_t |
| 226 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 227 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 228 | /* sanity check on queue memory */ |
| 229 | if (unlikely(!q)) |
| 230 | return 0; |
| 231 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 232 | /* Clear the mailbox pointer for completion */ |
| 233 | q->phba->mbox = NULL; |
| 234 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 235 | return 1; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 240 | * @q: The Event Queue to get the first valid EQE from |
| 241 | * |
| 242 | * This routine will get the first valid Event Queue Entry from @q, update |
| 243 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 244 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 245 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 246 | **/ |
| 247 | static struct lpfc_eqe * |
| 248 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 249 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 250 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 251 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 252 | |
| 253 | /* sanity check on queue memory */ |
| 254 | if (unlikely(!q)) |
| 255 | return NULL; |
| 256 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 257 | |
| 258 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 259 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 260 | return NULL; |
| 261 | /* 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] | 262 | idx = ((q->hba_index + 1) % q->entry_count); |
| 263 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 264 | return NULL; |
| 265 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 266 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * insert barrier for instruction interlock : data from the hardware |
| 270 | * must have the valid bit checked before it can be copied and acted |
| 271 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 272 | * instructions allowing action on content before valid bit checked, |
| 273 | * add barrier here as well. May not be needed as "content" is a |
| 274 | * single 32-bit entity here (vs multi word structure for cq's). |
| 275 | */ |
| 276 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 277 | return eqe; |
| 278 | } |
| 279 | |
| 280 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 281 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 282 | * @q: The Event Queue to disable interrupts |
| 283 | * |
| 284 | **/ |
| 285 | static inline void |
| 286 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 287 | { |
| 288 | struct lpfc_register doorbell; |
| 289 | |
| 290 | doorbell.word0 = 0; |
| 291 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 292 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 293 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 294 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 295 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 296 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 297 | } |
| 298 | |
| 299 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 300 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 301 | * @q: The Event Queue that the host has completed processing for. |
| 302 | * @arm: Indicates whether the host wants to arms this CQ. |
| 303 | * |
| 304 | * This routine will mark all Event Queue Entries on @q, from the last |
| 305 | * known completed entry to the last entry that was processed, as completed |
| 306 | * by clearing the valid bit for each completion queue entry. Then it will |
| 307 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 308 | * The internal host index in the @q will be updated by this routine to indicate |
| 309 | * that the host has finished processing the entries. The @arm parameter |
| 310 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 311 | * |
| 312 | * This function will return the number of EQEs that were popped. |
| 313 | **/ |
| 314 | uint32_t |
| 315 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 316 | { |
| 317 | uint32_t released = 0; |
| 318 | struct lpfc_eqe *temp_eqe; |
| 319 | struct lpfc_register doorbell; |
| 320 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 321 | /* sanity check on queue memory */ |
| 322 | if (unlikely(!q)) |
| 323 | return 0; |
| 324 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 325 | /* while there are valid entries */ |
| 326 | while (q->hba_index != q->host_index) { |
| 327 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 328 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 329 | released++; |
| 330 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 331 | } |
| 332 | if (unlikely(released == 0 && !arm)) |
| 333 | return 0; |
| 334 | |
| 335 | /* ring doorbell for number popped */ |
| 336 | doorbell.word0 = 0; |
| 337 | if (arm) { |
| 338 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 339 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 340 | } |
| 341 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 342 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 343 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 344 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 345 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 346 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 347 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 348 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 349 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 350 | return released; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 355 | * @q: The Completion Queue to get the first valid CQE from |
| 356 | * |
| 357 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 358 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 359 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 360 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 361 | **/ |
| 362 | static struct lpfc_cqe * |
| 363 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 364 | { |
| 365 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 366 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 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 NULL; |
| 371 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 372 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 373 | 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] | 374 | return NULL; |
| 375 | /* 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] | 376 | idx = ((q->hba_index + 1) % q->entry_count); |
| 377 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 378 | return NULL; |
| 379 | |
| 380 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 381 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 382 | |
| 383 | /* |
| 384 | * insert barrier for instruction interlock : data from the hardware |
| 385 | * must have the valid bit checked before it can be copied and acted |
| 386 | * upon. Speculative instructions were allowing a bcopy at the start |
| 387 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 388 | * after our return, to copy data before the valid bit check above |
| 389 | * was done. As such, some of the copied data was stale. The barrier |
| 390 | * ensures the check is before any data is copied. |
| 391 | */ |
| 392 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 393 | return cqe; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 398 | * @q: The Completion Queue that the host has completed processing for. |
| 399 | * @arm: Indicates whether the host wants to arms this CQ. |
| 400 | * |
| 401 | * This routine will mark all Completion queue entries on @q, from the last |
| 402 | * known completed entry to the last entry that was processed, as completed |
| 403 | * by clearing the valid bit for each completion queue entry. Then it will |
| 404 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 405 | * The internal host index in the @q will be updated by this routine to indicate |
| 406 | * that the host has finished processing the entries. The @arm parameter |
| 407 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 408 | * |
| 409 | * This function will return the number of CQEs that were released. |
| 410 | **/ |
| 411 | uint32_t |
| 412 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 413 | { |
| 414 | uint32_t released = 0; |
| 415 | struct lpfc_cqe *temp_qe; |
| 416 | struct lpfc_register doorbell; |
| 417 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 418 | /* sanity check on queue memory */ |
| 419 | if (unlikely(!q)) |
| 420 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 421 | /* while there are valid entries */ |
| 422 | while (q->hba_index != q->host_index) { |
| 423 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 424 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 425 | released++; |
| 426 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 427 | } |
| 428 | if (unlikely(released == 0 && !arm)) |
| 429 | return 0; |
| 430 | |
| 431 | /* ring doorbell for number popped */ |
| 432 | doorbell.word0 = 0; |
| 433 | if (arm) |
| 434 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 435 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 436 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 437 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 438 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 439 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 440 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 441 | return released; |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 446 | * @q: The Header Receive Queue to operate on. |
| 447 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 448 | * |
| 449 | * This routine will copy the contents of @wqe to the next available entry on |
| 450 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 451 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 452 | * index that the rqe was copied to if successful. If no entries are available |
| 453 | * on @q then this function will return -ENOMEM. |
| 454 | * The caller is expected to hold the hbalock when calling this routine. |
| 455 | **/ |
| 456 | static int |
| 457 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 458 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 459 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 460 | struct lpfc_rqe *temp_hrqe; |
| 461 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 462 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 463 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 464 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 465 | /* sanity check on queue memory */ |
| 466 | if (unlikely(!hq) || unlikely(!dq)) |
| 467 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 468 | put_index = hq->host_index; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 469 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 470 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 471 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 472 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 473 | return -EINVAL; |
| 474 | if (hq->host_index != dq->host_index) |
| 475 | return -EINVAL; |
| 476 | /* If the host has not yet processed the next entry then we are done */ |
| 477 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 478 | return -EBUSY; |
| 479 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 480 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 481 | |
| 482 | /* Update the host index to point to the next slot */ |
| 483 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 484 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 485 | |
| 486 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 487 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 488 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 489 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 490 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 491 | hq->entry_repost); |
| 492 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 493 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 494 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 495 | hq->entry_repost); |
| 496 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 497 | hq->host_index); |
| 498 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 499 | } else { |
| 500 | return -EINVAL; |
| 501 | } |
| 502 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 503 | } |
| 504 | return put_index; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 509 | * @q: The Header Receive Queue to operate on. |
| 510 | * |
| 511 | * This routine will update the HBA index of a queue to reflect consumption of |
| 512 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 513 | * consumed an entry the host calls this function to update the queue's |
| 514 | * internal pointers. This routine returns the number of entries that were |
| 515 | * consumed by the HBA. |
| 516 | **/ |
| 517 | static uint32_t |
| 518 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 519 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 520 | /* sanity check on queue memory */ |
| 521 | if (unlikely(!hq) || unlikely(!dq)) |
| 522 | return 0; |
| 523 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 524 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 525 | return 0; |
| 526 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 527 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 528 | return 1; |
| 529 | } |
| 530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 532 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 533 | * @phba: Pointer to HBA context object. |
| 534 | * @pring: Pointer to driver SLI ring object. |
| 535 | * |
| 536 | * This function returns pointer to next command iocb entry |
| 537 | * in the command ring. The caller must hold hbalock to prevent |
| 538 | * other threads consume the next command iocb. |
| 539 | * SLI-2/SLI-3 provide different sized iocbs. |
| 540 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 541 | static inline IOCB_t * |
| 542 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 543 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 544 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 545 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 546 | } |
| 547 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 548 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 549 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 550 | * @phba: Pointer to HBA context object. |
| 551 | * @pring: Pointer to driver SLI ring object. |
| 552 | * |
| 553 | * This function returns pointer to next response iocb entry |
| 554 | * in the response ring. The caller must hold hbalock to make sure |
| 555 | * that no other thread consume the next response iocb. |
| 556 | * SLI-2/SLI-3 provide different sized iocbs. |
| 557 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 558 | static inline IOCB_t * |
| 559 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 560 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 561 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 562 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 563 | } |
| 564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 566 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 567 | * @phba: Pointer to HBA context object. |
| 568 | * |
| 569 | * This function is called with hbalock held. This function |
| 570 | * allocates a new driver iocb object from the iocb pool. If the |
| 571 | * allocation is successful, it returns pointer to the newly |
| 572 | * allocated iocb object else it returns NULL. |
| 573 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 574 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 575 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 576 | { |
| 577 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 578 | struct lpfc_iocbq * iocbq = NULL; |
| 579 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 580 | lockdep_assert_held(&phba->hbalock); |
| 581 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 582 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 583 | if (iocbq) |
| 584 | phba->iocb_cnt++; |
| 585 | if (phba->iocb_cnt > phba->iocb_max) |
| 586 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 587 | return iocbq; |
| 588 | } |
| 589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 590 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 591 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 592 | * @phba: Pointer to HBA context object. |
| 593 | * @xritag: XRI value. |
| 594 | * |
| 595 | * This function clears the sglq pointer from the array of acive |
| 596 | * sglq's. The xritag that is passed in is used to index into the |
| 597 | * array. Before the xritag can be used it needs to be adjusted |
| 598 | * by subtracting the xribase. |
| 599 | * |
| 600 | * Returns sglq ponter = success, NULL = Failure. |
| 601 | **/ |
| 602 | static struct lpfc_sglq * |
| 603 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 604 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 605 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 606 | |
| 607 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 608 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 609 | return sglq; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 614 | * @phba: Pointer to HBA context object. |
| 615 | * @xritag: XRI value. |
| 616 | * |
| 617 | * This function returns the sglq pointer from the array of acive |
| 618 | * sglq's. The xritag that is passed in is used to index into the |
| 619 | * array. Before the xritag can be used it needs to be adjusted |
| 620 | * by subtracting the xribase. |
| 621 | * |
| 622 | * Returns sglq ponter = success, NULL = Failure. |
| 623 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 624 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 625 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 626 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 627 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 628 | |
| 629 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 630 | return sglq; |
| 631 | } |
| 632 | |
| 633 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 634 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 635 | * @phba: Pointer to HBA context object. |
| 636 | * @xritag: xri used in this exchange. |
| 637 | * @rrq: The RRQ to be cleared. |
| 638 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 639 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 640 | void |
| 641 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 642 | uint16_t xritag, |
| 643 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 644 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 645 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 646 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 647 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 648 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 649 | |
| 650 | /* The target DID could have been swapped (cable swap) |
| 651 | * we should use the ndlp from the findnode if it is |
| 652 | * available. |
| 653 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 654 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 655 | ndlp = rrq->ndlp; |
| 656 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 657 | if (!ndlp) |
| 658 | goto out; |
| 659 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 660 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 661 | rrq->send_rrq = 0; |
| 662 | rrq->xritag = 0; |
| 663 | rrq->rrq_stop_time = 0; |
| 664 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 665 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 666 | mempool_free(rrq, phba->rrq_pool); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 671 | * @phba: Pointer to HBA context object. |
| 672 | * |
| 673 | * This function is called with hbalock held. This function |
| 674 | * Checks if stop_time (ratov from setting rrq active) has |
| 675 | * been reached, if it has and the send_rrq flag is set then |
| 676 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 677 | * then it will just call the routine to clear the rrq and |
| 678 | * free the rrq resource. |
| 679 | * The timer is set to the next rrq that is going to expire before |
| 680 | * leaving the routine. |
| 681 | * |
| 682 | **/ |
| 683 | void |
| 684 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 685 | { |
| 686 | struct lpfc_node_rrq *rrq; |
| 687 | struct lpfc_node_rrq *nextrrq; |
| 688 | unsigned long next_time; |
| 689 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 690 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 691 | |
| 692 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 693 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 694 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 695 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 696 | &phba->active_rrq_list, list) { |
| 697 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 698 | list_move(&rrq->list, &send_rrq); |
| 699 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 700 | next_time = rrq->rrq_stop_time; |
| 701 | } |
| 702 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 703 | if ((!list_empty(&phba->active_rrq_list)) && |
| 704 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 705 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 706 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 707 | list_del(&rrq->list); |
| 708 | if (!rrq->send_rrq) |
| 709 | /* this call will free the rrq */ |
| 710 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 711 | else if (lpfc_send_rrq(phba, rrq)) { |
| 712 | /* if we send the rrq then the completion handler |
| 713 | * will clear the bit in the xribitmap. |
| 714 | */ |
| 715 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 716 | rrq); |
| 717 | } |
| 718 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /** |
| 722 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 723 | * @vport: Pointer to vport context object. |
| 724 | * @xri: The xri used in the exchange. |
| 725 | * @did: The targets DID for this exchange. |
| 726 | * |
| 727 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 728 | * rrq = rrq for this xri and target. |
| 729 | **/ |
| 730 | struct lpfc_node_rrq * |
| 731 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 732 | { |
| 733 | struct lpfc_hba *phba = vport->phba; |
| 734 | struct lpfc_node_rrq *rrq; |
| 735 | struct lpfc_node_rrq *nextrrq; |
| 736 | unsigned long iflags; |
| 737 | |
| 738 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 739 | return NULL; |
| 740 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 741 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 742 | if (rrq->vport == vport && rrq->xritag == xri && |
| 743 | rrq->nlp_DID == did){ |
| 744 | list_del(&rrq->list); |
| 745 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 746 | return rrq; |
| 747 | } |
| 748 | } |
| 749 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 750 | return NULL; |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 755 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 756 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 757 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 758 | * phba->active_rrq_list and clear the rrq. |
| 759 | * 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] | 760 | **/ |
| 761 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 762 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 763 | |
| 764 | { |
| 765 | struct lpfc_hba *phba = vport->phba; |
| 766 | struct lpfc_node_rrq *rrq; |
| 767 | struct lpfc_node_rrq *nextrrq; |
| 768 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 769 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 770 | |
| 771 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 772 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 773 | if (!ndlp) { |
| 774 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 775 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 776 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 777 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 778 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 779 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 780 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 781 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 782 | |
| 783 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 784 | list_del(&rrq->list); |
| 785 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 786 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 790 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 791 | * @phba: Pointer to HBA context object. |
| 792 | * @ndlp: Targets nodelist pointer for this exchange. |
| 793 | * @xritag the xri in the bitmap to test. |
| 794 | * |
| 795 | * This function is called with hbalock held. This function |
| 796 | * returns 0 = rrq not active for this xri |
| 797 | * 1 = rrq is valid for this xri. |
| 798 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 799 | int |
| 800 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 801 | uint16_t xritag) |
| 802 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 803 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 804 | if (!ndlp) |
| 805 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 806 | if (!ndlp->active_rrqs_xri_bitmap) |
| 807 | return 0; |
| 808 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 809 | return 1; |
| 810 | else |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 816 | * @phba: Pointer to HBA context object. |
| 817 | * @ndlp: nodelist pointer for this target. |
| 818 | * @xritag: xri used in this exchange. |
| 819 | * @rxid: Remote Exchange ID. |
| 820 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 821 | * |
| 822 | * This function takes the hbalock. |
| 823 | * The active bit is always set in the active rrq xri_bitmap even |
| 824 | * if there is no slot avaiable for the other rrq information. |
| 825 | * |
| 826 | * returns 0 rrq actived for this xri |
| 827 | * < 0 No memory or invalid ndlp. |
| 828 | **/ |
| 829 | int |
| 830 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 831 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 832 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 833 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 834 | struct lpfc_node_rrq *rrq; |
| 835 | int empty; |
| 836 | |
| 837 | if (!ndlp) |
| 838 | return -EINVAL; |
| 839 | |
| 840 | if (!phba->cfg_enable_rrq) |
| 841 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 842 | |
| 843 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 844 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 845 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 846 | goto out; |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | * set the active bit even if there is no mem available. |
| 851 | */ |
| 852 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 853 | goto out; |
| 854 | |
| 855 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 856 | goto out; |
| 857 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 858 | if (!ndlp->active_rrqs_xri_bitmap) |
| 859 | goto out; |
| 860 | |
| 861 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 862 | goto out; |
| 863 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 864 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 865 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 866 | if (!rrq) { |
| 867 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 868 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 869 | " DID:0x%x Send:%d\n", |
| 870 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 871 | return -EINVAL; |
| 872 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 873 | if (phba->cfg_enable_rrq == 1) |
| 874 | rrq->send_rrq = send_rrq; |
| 875 | else |
| 876 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 877 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 878 | rrq->rrq_stop_time = jiffies + |
| 879 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 880 | rrq->ndlp = ndlp; |
| 881 | rrq->nlp_DID = ndlp->nlp_DID; |
| 882 | rrq->vport = ndlp->vport; |
| 883 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 884 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 885 | empty = list_empty(&phba->active_rrq_list); |
| 886 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 887 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 888 | if (empty) |
| 889 | lpfc_worker_wake_up(phba); |
| 890 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 891 | return 0; |
| 892 | out: |
| 893 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 894 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 895 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 896 | " DID:0x%x Send:%d\n", |
| 897 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 898 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 902 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 903 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 904 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 905 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 906 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 907 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 908 | * list is not empty then it is successful, it returns pointer to the newly |
| 909 | * allocated sglq object else it returns NULL. |
| 910 | **/ |
| 911 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 912 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 913 | { |
| 914 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 915 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 916 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 917 | struct lpfc_scsi_buf *lpfc_cmd; |
| 918 | struct lpfc_nodelist *ndlp; |
| 919 | int found = 0; |
| 920 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 921 | lockdep_assert_held(&phba->hbalock); |
| 922 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 923 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 924 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 925 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 926 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 927 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 928 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 929 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 930 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 931 | ndlp = NULL; |
| 932 | else |
| 933 | ndlp = piocbq->context_un.ndlp; |
| 934 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 935 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 936 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 937 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 938 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 939 | start_sglq = sglq; |
| 940 | while (!found) { |
| 941 | if (!sglq) |
| 942 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 943 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 944 | /* This xri has an rrq outstanding for this DID. |
| 945 | * put it back in the list and get another xri. |
| 946 | */ |
| 947 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 948 | sglq = NULL; |
| 949 | list_remove_head(lpfc_sgl_list, sglq, |
| 950 | struct lpfc_sglq, list); |
| 951 | if (sglq == start_sglq) { |
| 952 | sglq = NULL; |
| 953 | break; |
| 954 | } else |
| 955 | continue; |
| 956 | } |
| 957 | sglq->ndlp = ndlp; |
| 958 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 959 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 960 | sglq->state = SGL_ALLOCATED; |
| 961 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 962 | return sglq; |
| 963 | } |
| 964 | |
| 965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 966 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 967 | * @phba: Pointer to HBA context object. |
| 968 | * |
| 969 | * This function is called with no lock held. This function |
| 970 | * allocates a new driver iocb object from the iocb pool. If the |
| 971 | * allocation is successful, it returns pointer to the newly |
| 972 | * allocated iocb object else it returns NULL. |
| 973 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 974 | struct lpfc_iocbq * |
| 975 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 976 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 977 | struct lpfc_iocbq * iocbq = NULL; |
| 978 | unsigned long iflags; |
| 979 | |
| 980 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 981 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 982 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 983 | return iocbq; |
| 984 | } |
| 985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 986 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 987 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 988 | * @phba: Pointer to HBA context object. |
| 989 | * @iocbq: Pointer to driver iocb object. |
| 990 | * |
| 991 | * This function is called with hbalock held to release driver |
| 992 | * iocb object to the iocb pool. The iotag in the iocb object |
| 993 | * does not change for each use of the iocb object. This function |
| 994 | * clears all other fields of the iocb object when it is freed. |
| 995 | * The sqlq structure that holds the xritag and phys and virtual |
| 996 | * mappings for the scatter gather list is retrieved from the |
| 997 | * active array of sglq. The get of the sglq pointer also clears |
| 998 | * the entry in the array. If the status of the IO indiactes that |
| 999 | * this IO was aborted then the sglq entry it put on the |
| 1000 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1001 | * IO has good status or fails for any other reason then the sglq |
| 1002 | * entry is added to the free list (lpfc_sgl_list). |
| 1003 | **/ |
| 1004 | static void |
| 1005 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1006 | { |
| 1007 | struct lpfc_sglq *sglq; |
| 1008 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1009 | unsigned long iflag = 0; |
| 1010 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1011 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1012 | lockdep_assert_held(&phba->hbalock); |
| 1013 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1014 | if (iocbq->sli4_xritag == NO_XRI) |
| 1015 | sglq = NULL; |
| 1016 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1017 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1018 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1019 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1020 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1021 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1022 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1023 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 1024 | iflag); |
| 1025 | list_add(&sglq->list, |
| 1026 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1027 | spin_unlock_irqrestore( |
| 1028 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1029 | } else { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1030 | spin_lock_irqsave(&pring->ring_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1031 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1032 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1033 | list_add_tail(&sglq->list, |
| 1034 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1035 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1036 | |
| 1037 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1038 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1039 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1040 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | /* |
| 1045 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1046 | */ |
| 1047 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1048 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1049 | iocbq->sli4_xritag = NO_XRI; |
| 1050 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1051 | } |
| 1052 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1053 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1054 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1055 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1056 | * @phba: Pointer to HBA context object. |
| 1057 | * @iocbq: Pointer to driver iocb object. |
| 1058 | * |
| 1059 | * This function is called with hbalock held to release driver |
| 1060 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1061 | * does not change for each use of the iocb object. This function |
| 1062 | * clears all other fields of the iocb object when it is freed. |
| 1063 | **/ |
| 1064 | static void |
| 1065 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1066 | { |
| 1067 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1068 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1069 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1070 | |
| 1071 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1072 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1073 | */ |
| 1074 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1075 | iocbq->sli4_xritag = NO_XRI; |
| 1076 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1080 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1081 | * @phba: Pointer to HBA context object. |
| 1082 | * @iocbq: Pointer to driver iocb object. |
| 1083 | * |
| 1084 | * This function is called with hbalock held to release driver |
| 1085 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1086 | * does not change for each use of the iocb object. This function |
| 1087 | * clears all other fields of the iocb object when it is freed. |
| 1088 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1089 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1090 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1091 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1092 | lockdep_assert_held(&phba->hbalock); |
| 1093 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1094 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1095 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1096 | } |
| 1097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1099 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1100 | * @phba: Pointer to HBA context object. |
| 1101 | * @iocbq: Pointer to driver iocb object. |
| 1102 | * |
| 1103 | * This function is called with no lock held to release the iocb to |
| 1104 | * iocb pool. |
| 1105 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1106 | void |
| 1107 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1108 | { |
| 1109 | unsigned long iflags; |
| 1110 | |
| 1111 | /* |
| 1112 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1113 | */ |
| 1114 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1115 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1116 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1117 | } |
| 1118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1119 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1120 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1121 | * @phba: Pointer to HBA context object. |
| 1122 | * @iocblist: List of IOCBs. |
| 1123 | * @ulpstatus: ULP status in IOCB command field. |
| 1124 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1125 | * |
| 1126 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1127 | * on the list by invoking the complete callback function associated with the |
| 1128 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1129 | * fields. |
| 1130 | **/ |
| 1131 | void |
| 1132 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1133 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1134 | { |
| 1135 | struct lpfc_iocbq *piocb; |
| 1136 | |
| 1137 | while (!list_empty(iocblist)) { |
| 1138 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1139 | if (!piocb->iocb_cmpl) |
| 1140 | lpfc_sli_release_iocbq(phba, piocb); |
| 1141 | else { |
| 1142 | piocb->iocb.ulpStatus = ulpstatus; |
| 1143 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1144 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1145 | } |
| 1146 | } |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1151 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1152 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1153 | * |
| 1154 | * This function is called by ring event handler function to get the iocb type. |
| 1155 | * This function translates the iocb command to an iocb command type used to |
| 1156 | * decide the final disposition of each completed IOCB. |
| 1157 | * The function returns |
| 1158 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1159 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1160 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1161 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1162 | * |
| 1163 | * The caller is not required to hold any lock. |
| 1164 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1165 | static lpfc_iocb_type |
| 1166 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1167 | { |
| 1168 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1169 | |
| 1170 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1171 | return 0; |
| 1172 | |
| 1173 | switch (iocb_cmnd) { |
| 1174 | case CMD_XMIT_SEQUENCE_CR: |
| 1175 | case CMD_XMIT_SEQUENCE_CX: |
| 1176 | case CMD_XMIT_BCAST_CN: |
| 1177 | case CMD_XMIT_BCAST_CX: |
| 1178 | case CMD_ELS_REQUEST_CR: |
| 1179 | case CMD_ELS_REQUEST_CX: |
| 1180 | case CMD_CREATE_XRI_CR: |
| 1181 | case CMD_CREATE_XRI_CX: |
| 1182 | case CMD_GET_RPI_CN: |
| 1183 | case CMD_XMIT_ELS_RSP_CX: |
| 1184 | case CMD_GET_RPI_CR: |
| 1185 | case CMD_FCP_IWRITE_CR: |
| 1186 | case CMD_FCP_IWRITE_CX: |
| 1187 | case CMD_FCP_IREAD_CR: |
| 1188 | case CMD_FCP_IREAD_CX: |
| 1189 | case CMD_FCP_ICMND_CR: |
| 1190 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1191 | case CMD_FCP_TSEND_CX: |
| 1192 | case CMD_FCP_TRSP_CX: |
| 1193 | case CMD_FCP_TRECEIVE_CX: |
| 1194 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | case CMD_ADAPTER_MSG: |
| 1196 | case CMD_ADAPTER_DUMP: |
| 1197 | case CMD_XMIT_SEQUENCE64_CR: |
| 1198 | case CMD_XMIT_SEQUENCE64_CX: |
| 1199 | case CMD_XMIT_BCAST64_CN: |
| 1200 | case CMD_XMIT_BCAST64_CX: |
| 1201 | case CMD_ELS_REQUEST64_CR: |
| 1202 | case CMD_ELS_REQUEST64_CX: |
| 1203 | case CMD_FCP_IWRITE64_CR: |
| 1204 | case CMD_FCP_IWRITE64_CX: |
| 1205 | case CMD_FCP_IREAD64_CR: |
| 1206 | case CMD_FCP_IREAD64_CX: |
| 1207 | case CMD_FCP_ICMND64_CR: |
| 1208 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1209 | case CMD_FCP_TSEND64_CX: |
| 1210 | case CMD_FCP_TRSP64_CX: |
| 1211 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | case CMD_GEN_REQUEST64_CR: |
| 1213 | case CMD_GEN_REQUEST64_CX: |
| 1214 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1215 | case DSSCMD_IWRITE64_CR: |
| 1216 | case DSSCMD_IWRITE64_CX: |
| 1217 | case DSSCMD_IREAD64_CR: |
| 1218 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | type = LPFC_SOL_IOCB; |
| 1220 | break; |
| 1221 | case CMD_ABORT_XRI_CN: |
| 1222 | case CMD_ABORT_XRI_CX: |
| 1223 | case CMD_CLOSE_XRI_CN: |
| 1224 | case CMD_CLOSE_XRI_CX: |
| 1225 | case CMD_XRI_ABORTED_CX: |
| 1226 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1227 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | type = LPFC_ABORT_IOCB; |
| 1229 | break; |
| 1230 | case CMD_RCV_SEQUENCE_CX: |
| 1231 | case CMD_RCV_ELS_REQ_CX: |
| 1232 | case CMD_RCV_SEQUENCE64_CX: |
| 1233 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1234 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1235 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1236 | case CMD_IOCB_RCV_ELS64_CX: |
| 1237 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1238 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | type = LPFC_UNSOL_IOCB; |
| 1240 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1241 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1242 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1243 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1244 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1245 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1246 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1247 | case CMD_IOCB_RET_HBQE64_CN: |
| 1248 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1249 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1250 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1251 | case CMD_IOCB_LOGENTRY_CN: |
| 1252 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1253 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1254 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1255 | type = LPFC_UNKNOWN_IOCB; |
| 1256 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | default: |
| 1258 | type = LPFC_UNKNOWN_IOCB; |
| 1259 | break; |
| 1260 | } |
| 1261 | |
| 1262 | return type; |
| 1263 | } |
| 1264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1266 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1267 | * @phba: Pointer to HBA context object. |
| 1268 | * |
| 1269 | * This function is called from SLI initialization code |
| 1270 | * to configure every ring of the HBA's SLI interface. The |
| 1271 | * caller is not required to hold any lock. This function issues |
| 1272 | * a config_ring mailbox command for each ring. |
| 1273 | * This function returns zero if successful else returns a negative |
| 1274 | * error code. |
| 1275 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1276 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1277 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | { |
| 1279 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1280 | LPFC_MBOXQ_t *pmb; |
| 1281 | MAILBOX_t *pmbox; |
| 1282 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1284 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1285 | if (!pmb) |
| 1286 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1287 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1288 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | lpfc_config_ring(phba, i, pmb); |
| 1291 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1292 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1294 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1296 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1297 | rc, pmbox->mbxCommand, |
| 1298 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1299 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1300 | ret = -ENXIO; |
| 1301 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | } |
| 1303 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1304 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1305 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | } |
| 1307 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1308 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1309 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1310 | * @phba: Pointer to HBA context object. |
| 1311 | * @pring: Pointer to driver SLI ring object. |
| 1312 | * @piocb: Pointer to the driver iocb object. |
| 1313 | * |
| 1314 | * This function is called with hbalock held. The function adds the |
| 1315 | * new iocb to txcmplq of the given ring. This function always returns |
| 1316 | * 0. If this function is called for ELS ring, this function checks if |
| 1317 | * there is a vport associated with the ELS command. This function also |
| 1318 | * starts els_tmofunc timer if this is an ELS command. |
| 1319 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1321 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1322 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1324 | lockdep_assert_held(&phba->hbalock); |
| 1325 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1327 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1328 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1329 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1330 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1331 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) && |
| 1332 | (!(piocb->vport->load_flag & FC_UNLOADING))) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1333 | if (!piocb->vport) |
| 1334 | BUG(); |
| 1335 | else |
| 1336 | mod_timer(&piocb->vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1337 | jiffies + |
| 1338 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1339 | } |
| 1340 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1342 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | } |
| 1344 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1346 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1347 | * @phba: Pointer to HBA context object. |
| 1348 | * @pring: Pointer to driver SLI ring object. |
| 1349 | * |
| 1350 | * This function is called with hbalock held to get next |
| 1351 | * iocb in txq of the given ring. If there is any iocb in |
| 1352 | * the txq, the function returns first iocb in the list after |
| 1353 | * removing the iocb from the list, else it returns NULL. |
| 1354 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1355 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1356 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1357 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | struct lpfc_iocbq *cmd_iocb; |
| 1359 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1360 | lockdep_assert_held(&phba->hbalock); |
| 1361 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1362 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | } |
| 1365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1367 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1368 | * @phba: Pointer to HBA context object. |
| 1369 | * @pring: Pointer to driver SLI ring object. |
| 1370 | * |
| 1371 | * This function is called with hbalock held and the caller must post the |
| 1372 | * iocb without releasing the lock. If the caller releases the lock, |
| 1373 | * iocb slot returned by the function is not guaranteed to be available. |
| 1374 | * The function returns pointer to the next available iocb slot if there |
| 1375 | * is available slot in the ring, else it returns NULL. |
| 1376 | * If the get index of the ring is ahead of the put index, the function |
| 1377 | * will post an error attention event to the worker thread to take the |
| 1378 | * HBA to offline state. |
| 1379 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | static IOCB_t * |
| 1381 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1382 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1383 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1384 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1385 | |
| 1386 | lockdep_assert_held(&phba->hbalock); |
| 1387 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1388 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1389 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1390 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1392 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1393 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1395 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1397 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1399 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1400 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1401 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1402 | pring->sli.sli3.local_getidx, |
| 1403 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1405 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | /* |
| 1407 | * All error attention handlers are posted to |
| 1408 | * worker thread |
| 1409 | */ |
| 1410 | phba->work_ha |= HA_ERATT; |
| 1411 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1412 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1413 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | |
| 1415 | return NULL; |
| 1416 | } |
| 1417 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1418 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | return NULL; |
| 1420 | } |
| 1421 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1422 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | } |
| 1424 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1425 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1426 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1427 | * @phba: Pointer to HBA context object. |
| 1428 | * @iocbq: Pointer to driver iocb object. |
| 1429 | * |
| 1430 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1431 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1432 | * array and assigns a new iotag. |
| 1433 | * The function returns the allocated iotag if successful, else returns zero. |
| 1434 | * Zero is not a valid iotag. |
| 1435 | * The caller is not required to hold any lock. |
| 1436 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1437 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1438 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1439 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1440 | struct lpfc_iocbq **new_arr; |
| 1441 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1442 | size_t new_len; |
| 1443 | struct lpfc_sli *psli = &phba->sli; |
| 1444 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1446 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1447 | iotag = psli->last_iotag; |
| 1448 | if(++iotag < psli->iocbq_lookup_len) { |
| 1449 | psli->last_iotag = iotag; |
| 1450 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1451 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1452 | iocbq->iotag = iotag; |
| 1453 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1454 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1455 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1456 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | spin_unlock_irq(&phba->hbalock); |
| 1458 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1459 | GFP_KERNEL); |
| 1460 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1461 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1462 | old_arr = psli->iocbq_lookup; |
| 1463 | if (new_len <= psli->iocbq_lookup_len) { |
| 1464 | /* highly unprobable case */ |
| 1465 | kfree(new_arr); |
| 1466 | iotag = psli->last_iotag; |
| 1467 | if(++iotag < psli->iocbq_lookup_len) { |
| 1468 | psli->last_iotag = iotag; |
| 1469 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1471 | iocbq->iotag = iotag; |
| 1472 | return iotag; |
| 1473 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1474 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1475 | return 0; |
| 1476 | } |
| 1477 | if (psli->iocbq_lookup) |
| 1478 | memcpy(new_arr, old_arr, |
| 1479 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1480 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1481 | psli->iocbq_lookup = new_arr; |
| 1482 | psli->iocbq_lookup_len = new_len; |
| 1483 | psli->last_iotag = iotag; |
| 1484 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1485 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1486 | iocbq->iotag = iotag; |
| 1487 | kfree(old_arr); |
| 1488 | return iotag; |
| 1489 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1490 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1491 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1493 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1494 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1495 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1497 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1498 | } |
| 1499 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1500 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1501 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1502 | * @phba: Pointer to HBA context object. |
| 1503 | * @pring: Pointer to driver SLI ring object. |
| 1504 | * @iocb: Pointer to iocb slot in the ring. |
| 1505 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1506 | * posted to firmware. |
| 1507 | * |
| 1508 | * This function is called with hbalock held to post a new iocb to |
| 1509 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1510 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1511 | * a completion call back for this iocb else the function will free the |
| 1512 | * iocb object. |
| 1513 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1514 | static void |
| 1515 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1516 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1517 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1518 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1519 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1520 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1521 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1522 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1524 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1525 | if (pring->ringno == LPFC_ELS_RING) { |
| 1526 | lpfc_debugfs_slow_ring_trc(phba, |
| 1527 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1528 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1529 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1530 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1531 | } |
| 1532 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1533 | /* |
| 1534 | * Issue iocb command to adapter |
| 1535 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1536 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | wmb(); |
| 1538 | pring->stats.iocb_cmd++; |
| 1539 | |
| 1540 | /* |
| 1541 | * If there is no completion routine to call, we can release the |
| 1542 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1543 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1544 | */ |
| 1545 | if (nextiocb->iocb_cmpl) |
| 1546 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1547 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1548 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | |
| 1550 | /* |
| 1551 | * Let the HBA know what IOCB slot will be the next one the |
| 1552 | * driver will put a command into. |
| 1553 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1554 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1555 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | } |
| 1557 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1559 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1560 | * @phba: Pointer to HBA context object. |
| 1561 | * @pring: Pointer to driver SLI ring object. |
| 1562 | * |
| 1563 | * The caller is not required to hold any lock for calling this function. |
| 1564 | * This function updates the chip attention bits for the ring to inform firmware |
| 1565 | * that there are pending work to be done for this ring and requests an |
| 1566 | * interrupt when there is space available in the ring. This function is |
| 1567 | * called when the driver is unable to post more iocbs to the ring due |
| 1568 | * to unavailability of space in the ring. |
| 1569 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1570 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1571 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | { |
| 1573 | int ringno = pring->ringno; |
| 1574 | |
| 1575 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1576 | |
| 1577 | wmb(); |
| 1578 | |
| 1579 | /* |
| 1580 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1581 | * The HBA will tell us when an IOCB entry is available. |
| 1582 | */ |
| 1583 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1584 | readl(phba->CAregaddr); /* flush */ |
| 1585 | |
| 1586 | pring->stats.iocb_cmd_full++; |
| 1587 | } |
| 1588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1590 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1591 | * @phba: Pointer to HBA context object. |
| 1592 | * @pring: Pointer to driver SLI ring object. |
| 1593 | * |
| 1594 | * This function updates the chip attention register bit for the |
| 1595 | * given ring to inform HBA that there is more work to be done |
| 1596 | * in this ring. The caller is not required to hold any lock. |
| 1597 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1599 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | { |
| 1601 | int ringno = pring->ringno; |
| 1602 | |
| 1603 | /* |
| 1604 | * Tell the HBA that there is work to do in this ring. |
| 1605 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1606 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1607 | wmb(); |
| 1608 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1609 | readl(phba->CAregaddr); /* flush */ |
| 1610 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | } |
| 1612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1614 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1615 | * @phba: Pointer to HBA context object. |
| 1616 | * @pring: Pointer to driver SLI ring object. |
| 1617 | * |
| 1618 | * This function is called with hbalock held to post pending iocbs |
| 1619 | * in the txq to the firmware. This function is called when driver |
| 1620 | * detects space available in the ring. |
| 1621 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1623 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | { |
| 1625 | IOCB_t *iocb; |
| 1626 | struct lpfc_iocbq *nextiocb; |
| 1627 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1628 | lockdep_assert_held(&phba->hbalock); |
| 1629 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1630 | /* |
| 1631 | * Check to see if: |
| 1632 | * (a) there is anything on the txq to send |
| 1633 | * (b) link is up |
| 1634 | * (c) link attention events can be processed (fcp ring only) |
| 1635 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1636 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1637 | |
| 1638 | if (lpfc_is_link_up(phba) && |
| 1639 | (!list_empty(&pring->txq)) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1641 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1642 | |
| 1643 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1644 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1645 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1646 | |
| 1647 | if (iocb) |
| 1648 | lpfc_sli_update_ring(phba, pring); |
| 1649 | else |
| 1650 | lpfc_sli_update_full_ring(phba, pring); |
| 1651 | } |
| 1652 | |
| 1653 | return; |
| 1654 | } |
| 1655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1657 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1658 | * @phba: Pointer to HBA context object. |
| 1659 | * @hbqno: HBQ number. |
| 1660 | * |
| 1661 | * This function is called with hbalock held to get the next |
| 1662 | * available slot for the given HBQ. If there is free slot |
| 1663 | * available for the HBQ it will return pointer to the next available |
| 1664 | * HBQ entry else it will return NULL. |
| 1665 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1666 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1667 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1668 | { |
| 1669 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1670 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1671 | lockdep_assert_held(&phba->hbalock); |
| 1672 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1673 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1674 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1675 | hbqp->next_hbqPutIdx = 0; |
| 1676 | |
| 1677 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1678 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1679 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1680 | |
| 1681 | hbqp->local_hbqGetIdx = getidx; |
| 1682 | |
| 1683 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1684 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1685 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1686 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1687 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1688 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1689 | hbqp->entry_count); |
| 1690 | |
| 1691 | phba->link_state = LPFC_HBA_ERROR; |
| 1692 | return NULL; |
| 1693 | } |
| 1694 | |
| 1695 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1696 | return NULL; |
| 1697 | } |
| 1698 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1699 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1700 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1701 | } |
| 1702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1704 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1705 | * @phba: Pointer to HBA context object. |
| 1706 | * |
| 1707 | * This function is called with no lock held to free all the |
| 1708 | * hbq buffers while uninitializing the SLI interface. It also |
| 1709 | * frees the HBQ buffers returned by the firmware but not yet |
| 1710 | * processed by the upper layers. |
| 1711 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1712 | void |
| 1713 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1714 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1715 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1716 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1717 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1718 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1719 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1720 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1721 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1722 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1723 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1724 | for (i = 0; i < hbq_count; ++i) { |
| 1725 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1726 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1727 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1728 | list_del(&hbq_buf->dbuf.list); |
| 1729 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1730 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1731 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1732 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1733 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1734 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1735 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1736 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1737 | list_del(&hbq_buf->dbuf.list); |
| 1738 | if (hbq_buf->tag == -1) { |
| 1739 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1740 | (phba, hbq_buf); |
| 1741 | } else { |
| 1742 | hbqno = hbq_buf->tag >> 16; |
| 1743 | if (hbqno >= LPFC_MAX_HBQS) |
| 1744 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1745 | (phba, hbq_buf); |
| 1746 | else |
| 1747 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1748 | hbq_buf); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | /* Mark the HBQs not in use */ |
| 1753 | phba->hbq_in_use = 0; |
| 1754 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1757 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1758 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1759 | * @phba: Pointer to HBA context object. |
| 1760 | * @hbqno: HBQ number. |
| 1761 | * @hbq_buf: Pointer to HBQ buffer. |
| 1762 | * |
| 1763 | * This function is called with the hbalock held to post a |
| 1764 | * hbq buffer to the firmware. If the function finds an empty |
| 1765 | * slot in the HBQ, it will post the buffer. The function will return |
| 1766 | * pointer to the hbq entry if it successfully post the buffer |
| 1767 | * else it will return NULL. |
| 1768 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1769 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1770 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1771 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1772 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1773 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1774 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1775 | } |
| 1776 | |
| 1777 | /** |
| 1778 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1779 | * @phba: Pointer to HBA context object. |
| 1780 | * @hbqno: HBQ number. |
| 1781 | * @hbq_buf: Pointer to HBQ buffer. |
| 1782 | * |
| 1783 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1784 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1785 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1786 | * it successfully post the buffer else it will return an error. |
| 1787 | **/ |
| 1788 | static int |
| 1789 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1790 | struct hbq_dmabuf *hbq_buf) |
| 1791 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1792 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1793 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1794 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1795 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1796 | /* Get next HBQ entry slot to use */ |
| 1797 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1798 | if (hbqe) { |
| 1799 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1800 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1801 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1802 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1803 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1804 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1805 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1806 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1807 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1808 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1809 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1810 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1811 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1812 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1813 | return 0; |
| 1814 | } else |
| 1815 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1816 | } |
| 1817 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1818 | /** |
| 1819 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1820 | * @phba: Pointer to HBA context object. |
| 1821 | * @hbqno: HBQ number. |
| 1822 | * @hbq_buf: Pointer to HBQ buffer. |
| 1823 | * |
| 1824 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1825 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1826 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1827 | **/ |
| 1828 | static int |
| 1829 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1830 | struct hbq_dmabuf *hbq_buf) |
| 1831 | { |
| 1832 | int rc; |
| 1833 | struct lpfc_rqe hrqe; |
| 1834 | struct lpfc_rqe drqe; |
| 1835 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1836 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1837 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1838 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1839 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1840 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1841 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1842 | &hrqe, &drqe); |
| 1843 | if (rc < 0) |
| 1844 | return rc; |
| 1845 | hbq_buf->tag = rc; |
| 1846 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1850 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1851 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1852 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1853 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1854 | .mask_count = 0, |
| 1855 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1856 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1858 | .init_count = 40, |
| 1859 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1860 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1862 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1863 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1864 | .rn = 1, |
| 1865 | .entry_count = 200, |
| 1866 | .mask_count = 0, |
| 1867 | .profile = 0, |
| 1868 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1869 | .buffer_count = 0, |
| 1870 | .init_count = 0, |
| 1871 | .add_count = 5, |
| 1872 | }; |
| 1873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1874 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1875 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1876 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1877 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1878 | }; |
| 1879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1881 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1882 | * @phba: Pointer to HBA context object. |
| 1883 | * @hbqno: HBQ number. |
| 1884 | * @count: Number of HBQ buffers to be posted. |
| 1885 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1886 | * This function is called with no lock held to post more hbq buffers to the |
| 1887 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1888 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1889 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1890 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1891 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1892 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1893 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1894 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1895 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1896 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1897 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1898 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1899 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1900 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1901 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1902 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1903 | phba->hbqs[hbqno].buffer_count; |
| 1904 | if (!count) |
| 1905 | return 0; |
| 1906 | /* Allocate HBQ entries */ |
| 1907 | for (i = 0; i < count; i++) { |
| 1908 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1909 | if (!hbq_buffer) |
| 1910 | break; |
| 1911 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1912 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1913 | /* Check whether HBQ is still in use */ |
| 1914 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1915 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1916 | goto err; |
| 1917 | while (!list_empty(&hbq_buf_list)) { |
| 1918 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1919 | dbuf.list); |
| 1920 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1921 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1922 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1923 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1924 | posted++; |
| 1925 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1926 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1927 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1928 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1929 | return posted; |
| 1930 | err: |
| 1931 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1932 | while (!list_empty(&hbq_buf_list)) { |
| 1933 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1934 | dbuf.list); |
| 1935 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1936 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1937 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1938 | } |
| 1939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1941 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1942 | * @phba: Pointer to HBA context object. |
| 1943 | * @qno: HBQ number. |
| 1944 | * |
| 1945 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1946 | * is called with no lock held. The function returns the number of HBQ entries |
| 1947 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1948 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1949 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1951 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1952 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1953 | return 0; |
| 1954 | else |
| 1955 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1956 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1957 | } |
| 1958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1959 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1960 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1961 | * @phba: Pointer to HBA context object. |
| 1962 | * @qno: HBQ queue number. |
| 1963 | * |
| 1964 | * This function is called from SLI initialization code path with |
| 1965 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1966 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1967 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1968 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1969 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1970 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1971 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1972 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1973 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1974 | else |
| 1975 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1976 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1977 | } |
| 1978 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1979 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1980 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1981 | * @phba: Pointer to HBA context object. |
| 1982 | * @hbqno: HBQ number. |
| 1983 | * |
| 1984 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1985 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1986 | **/ |
| 1987 | static struct hbq_dmabuf * |
| 1988 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1989 | { |
| 1990 | struct lpfc_dmabuf *d_buf; |
| 1991 | |
| 1992 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1993 | if (!d_buf) |
| 1994 | return NULL; |
| 1995 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1996 | } |
| 1997 | |
| 1998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1999 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2000 | * @phba: Pointer to HBA context object. |
| 2001 | * @tag: Tag of the hbq buffer. |
| 2002 | * |
| 2003 | * This function is called with hbalock held. This function searches |
| 2004 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 2005 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 2006 | * it returns NULL. |
| 2007 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2008 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2009 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2010 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2011 | struct lpfc_dmabuf *d_buf; |
| 2012 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2013 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2014 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2015 | lockdep_assert_held(&phba->hbalock); |
| 2016 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2017 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2018 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2019 | return NULL; |
| 2020 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2021 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2022 | 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] | 2023 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2024 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2025 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2026 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2027 | } |
| 2028 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2029 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2030 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2031 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2032 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2033 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2034 | } |
| 2035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2037 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2038 | * @phba: Pointer to HBA context object. |
| 2039 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2040 | * |
| 2041 | * This function is called with hbalock. This function gives back |
| 2042 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2043 | * post the buffer, it will free the buffer. |
| 2044 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2046 | 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] | 2047 | { |
| 2048 | uint32_t hbqno; |
| 2049 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2050 | if (hbq_buffer) { |
| 2051 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2052 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2053 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2057 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2058 | * 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] | 2059 | * @mbxCommand: mailbox command code. |
| 2060 | * |
| 2061 | * This function is called by the mailbox event handler function to verify |
| 2062 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2063 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2064 | * and the mailbox event handler will take the HBA offline. |
| 2065 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | static int |
| 2067 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2068 | { |
| 2069 | uint8_t ret; |
| 2070 | |
| 2071 | switch (mbxCommand) { |
| 2072 | case MBX_LOAD_SM: |
| 2073 | case MBX_READ_NV: |
| 2074 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2075 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | case MBX_RUN_BIU_DIAG: |
| 2077 | case MBX_INIT_LINK: |
| 2078 | case MBX_DOWN_LINK: |
| 2079 | case MBX_CONFIG_LINK: |
| 2080 | case MBX_CONFIG_RING: |
| 2081 | case MBX_RESET_RING: |
| 2082 | case MBX_READ_CONFIG: |
| 2083 | case MBX_READ_RCONFIG: |
| 2084 | case MBX_READ_SPARM: |
| 2085 | case MBX_READ_STATUS: |
| 2086 | case MBX_READ_RPI: |
| 2087 | case MBX_READ_XRI: |
| 2088 | case MBX_READ_REV: |
| 2089 | case MBX_READ_LNK_STAT: |
| 2090 | case MBX_REG_LOGIN: |
| 2091 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | case MBX_CLEAR_LA: |
| 2093 | case MBX_DUMP_MEMORY: |
| 2094 | case MBX_DUMP_CONTEXT: |
| 2095 | case MBX_RUN_DIAGS: |
| 2096 | case MBX_RESTART: |
| 2097 | case MBX_UPDATE_CFG: |
| 2098 | case MBX_DOWN_LOAD: |
| 2099 | case MBX_DEL_LD_ENTRY: |
| 2100 | case MBX_RUN_PROGRAM: |
| 2101 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2102 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2104 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2106 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | case MBX_LOAD_AREA: |
| 2108 | case MBX_RUN_BIU_DIAG64: |
| 2109 | case MBX_CONFIG_PORT: |
| 2110 | case MBX_READ_SPARM64: |
| 2111 | case MBX_READ_RPI64: |
| 2112 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2113 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2114 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | case MBX_SET_DEBUG: |
| 2116 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2117 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2118 | case MBX_REG_VPI: |
| 2119 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2120 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2121 | case MBX_PORT_CAPABILITIES: |
| 2122 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2123 | case MBX_SLI4_CONFIG: |
| 2124 | case MBX_SLI4_REQ_FTRS: |
| 2125 | case MBX_REG_FCFI: |
| 2126 | case MBX_UNREG_FCFI: |
| 2127 | case MBX_REG_VFI: |
| 2128 | case MBX_UNREG_VFI: |
| 2129 | case MBX_INIT_VPI: |
| 2130 | case MBX_INIT_VFI: |
| 2131 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2132 | case MBX_READ_EVENT_LOG_STATUS: |
| 2133 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2134 | case MBX_SECURITY_MGMT: |
| 2135 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2136 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | ret = mbxCommand; |
| 2138 | break; |
| 2139 | default: |
| 2140 | ret = MBX_SHUTDOWN; |
| 2141 | break; |
| 2142 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2145 | |
| 2146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2147 | * 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] | 2148 | * @phba: Pointer to HBA context object. |
| 2149 | * @pmboxq: Pointer to mailbox command. |
| 2150 | * |
| 2151 | * This is completion handler function for mailbox commands issued from |
| 2152 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2153 | * mailbox event handler function with no lock held. This function |
| 2154 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2155 | * of the mailbox. |
| 2156 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2157 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2158 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | { |
| 2160 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2161 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
| 2163 | /* |
| 2164 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2165 | * continued running. |
| 2166 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2167 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2168 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2170 | if (pdone_q) |
| 2171 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2172 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | return; |
| 2174 | } |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | |
| 2177 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2178 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2179 | * @phba: Pointer to HBA context object. |
| 2180 | * @pmb: Pointer to mailbox object. |
| 2181 | * |
| 2182 | * This function is the default mailbox completion handler. It |
| 2183 | * frees the memory resources associated with the completed mailbox |
| 2184 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2185 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2186 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2190 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2192 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2193 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2194 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2195 | int rc; |
| 2196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | if (mp) { |
| 2200 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2201 | kfree(mp); |
| 2202 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2203 | |
| 2204 | /* |
| 2205 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2206 | * is in re-discovery driver need to cleanup the RPI. |
| 2207 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2209 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2210 | !pmb->u.mb.mbxStatus) { |
| 2211 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2212 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2213 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2214 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2215 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2216 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2217 | if (rc != MBX_NOT_FINISHED) |
| 2218 | return; |
| 2219 | } |
| 2220 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2221 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2222 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2223 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2224 | shost = lpfc_shost_from_vport(vport); |
| 2225 | spin_lock_irq(shost->host_lock); |
| 2226 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2227 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2228 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2229 | } |
| 2230 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2231 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2232 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2233 | lpfc_nlp_put(ndlp); |
| 2234 | pmb->context2 = NULL; |
| 2235 | } |
| 2236 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2237 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2238 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2239 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2240 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2241 | "2860 SLI authentication is required " |
| 2242 | "for INIT_LINK but has not done yet\n"); |
| 2243 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2244 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2245 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2246 | else |
| 2247 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2249 | /** |
| 2250 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2251 | * @phba: Pointer to HBA context object. |
| 2252 | * @pmb: Pointer to mailbox object. |
| 2253 | * |
| 2254 | * This function is the unreg rpi mailbox completion handler. It |
| 2255 | * frees the memory resources associated with the completed mailbox |
| 2256 | * command. An additional refrenece is put on the ndlp to prevent |
| 2257 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2258 | * the unreg mailbox command completes, this routine puts the |
| 2259 | * reference back. |
| 2260 | * |
| 2261 | **/ |
| 2262 | void |
| 2263 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2264 | { |
| 2265 | struct lpfc_vport *vport = pmb->vport; |
| 2266 | struct lpfc_nodelist *ndlp; |
| 2267 | |
| 2268 | ndlp = pmb->context1; |
| 2269 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2270 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2271 | (bf_get(lpfc_sli_intf_if_type, |
| 2272 | &phba->sli4_hba.sli_intf) == |
| 2273 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2274 | if (ndlp) { |
| 2275 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2276 | "0010 UNREG_LOGIN vpi:%x " |
| 2277 | "rpi:%x DID:%x map:%x %p\n", |
| 2278 | vport->vpi, ndlp->nlp_rpi, |
| 2279 | ndlp->nlp_DID, |
| 2280 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2281 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2282 | lpfc_nlp_put(ndlp); |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2288 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2291 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2292 | * @phba: Pointer to HBA context object. |
| 2293 | * |
| 2294 | * This function is called with no lock held. This function processes all |
| 2295 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2296 | * service routine processes mailbox completion interrupt and adds completed |
| 2297 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2298 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2299 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2300 | * function returns the mailbox commands to the upper layer by calling the |
| 2301 | * completion handler function of each mailbox. |
| 2302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | int rc; |
| 2309 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
| 2311 | phba->sli.slistat.mbox_event++; |
| 2312 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2313 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2314 | spin_lock_irq(&phba->hbalock); |
| 2315 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2316 | spin_unlock_irq(&phba->hbalock); |
| 2317 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2319 | do { |
| 2320 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2321 | if (pmb == NULL) |
| 2322 | break; |
| 2323 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2324 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2326 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2327 | if (pmb->vport) { |
| 2328 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2329 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2330 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2331 | (uint32_t)pmbox->mbxCommand, |
| 2332 | pmbox->un.varWords[0], |
| 2333 | pmbox->un.varWords[1]); |
| 2334 | } |
| 2335 | else { |
| 2336 | lpfc_debugfs_disc_trc(phba->pport, |
| 2337 | LPFC_DISC_TRC_MBOX, |
| 2338 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2339 | (uint32_t)pmbox->mbxCommand, |
| 2340 | pmbox->un.varWords[0], |
| 2341 | pmbox->un.varWords[1]); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | /* |
| 2346 | * It is a fatal error if unknown mbox command completion. |
| 2347 | */ |
| 2348 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2349 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2350 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2351 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2352 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2353 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2354 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2355 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2356 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2357 | pmb), |
| 2358 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2359 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | phba->work_hs = HS_FFER3; |
| 2362 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2363 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | } |
| 2365 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | if (pmbox->mbxStatus) { |
| 2367 | phba->sli.slistat.mbox_stat_err++; |
| 2368 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2369 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2370 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2371 | LOG_MBOX | LOG_SLI, |
| 2372 | "(%d):0305 Mbox cmd cmpl " |
| 2373 | "error - RETRYing Data: x%x " |
| 2374 | "(x%x/x%x) x%x x%x x%x\n", |
| 2375 | pmb->vport ? pmb->vport->vpi : 0, |
| 2376 | pmbox->mbxCommand, |
| 2377 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2378 | pmb), |
| 2379 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2380 | pmb), |
| 2381 | pmbox->mbxStatus, |
| 2382 | pmbox->un.varWords[0], |
| 2383 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | pmbox->mbxStatus = 0; |
| 2385 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2387 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2394 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2395 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2396 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2397 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2399 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2400 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | pmb->mbox_cmpl, |
| 2402 | *((uint32_t *) pmbox), |
| 2403 | pmbox->un.varWords[0], |
| 2404 | pmbox->un.varWords[1], |
| 2405 | pmbox->un.varWords[2], |
| 2406 | pmbox->un.varWords[3], |
| 2407 | pmbox->un.varWords[4], |
| 2408 | pmbox->un.varWords[5], |
| 2409 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2410 | pmbox->un.varWords[7], |
| 2411 | pmbox->un.varWords[8], |
| 2412 | pmbox->un.varWords[9], |
| 2413 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2415 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2417 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2418 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2422 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2423 | * @phba: Pointer to HBA context object. |
| 2424 | * @pring: Pointer to driver SLI ring object. |
| 2425 | * @tag: buffer tag. |
| 2426 | * |
| 2427 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2428 | * is set in the tag the buffer is posted for a particular exchange, |
| 2429 | * the function will return the buffer without replacing the buffer. |
| 2430 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2431 | * returns the buffer and also posts another buffer to the firmware. |
| 2432 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2433 | static struct lpfc_dmabuf * |
| 2434 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2435 | struct lpfc_sli_ring *pring, |
| 2436 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2437 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2438 | struct hbq_dmabuf *hbq_entry; |
| 2439 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2440 | if (tag & QUE_BUFTAG_BIT) |
| 2441 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2442 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2443 | if (!hbq_entry) |
| 2444 | return NULL; |
| 2445 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2446 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2447 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2448 | /** |
| 2449 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2450 | * @phba: Pointer to HBA context object. |
| 2451 | * @pring: Pointer to driver SLI ring object. |
| 2452 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2453 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2454 | * @fch_type: the type for the first frame of the sequence. |
| 2455 | * |
| 2456 | * This function is called with no lock held. This function uses the r_ctl and |
| 2457 | * type of the received sequence to find the correct callback function to call |
| 2458 | * to process the sequence. |
| 2459 | **/ |
| 2460 | static int |
| 2461 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2462 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2463 | uint32_t fch_type) |
| 2464 | { |
| 2465 | int i; |
| 2466 | |
| 2467 | /* unSolicited Responses */ |
| 2468 | if (pring->prt[0].profile) { |
| 2469 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2470 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2471 | saveq); |
| 2472 | return 1; |
| 2473 | } |
| 2474 | /* We must search, based on rctl / type |
| 2475 | for the right routine */ |
| 2476 | for (i = 0; i < pring->num_mask; i++) { |
| 2477 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2478 | (pring->prt[i].type == fch_type)) { |
| 2479 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2480 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2481 | (phba, pring, saveq); |
| 2482 | return 1; |
| 2483 | } |
| 2484 | } |
| 2485 | return 0; |
| 2486 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2487 | |
| 2488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2489 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2490 | * @phba: Pointer to HBA context object. |
| 2491 | * @pring: Pointer to driver SLI ring object. |
| 2492 | * @saveq: Pointer to the unsolicited iocb. |
| 2493 | * |
| 2494 | * This function is called with no lock held by the ring event handler |
| 2495 | * when there is an unsolicited iocb posted to the response ring by the |
| 2496 | * firmware. This function gets the buffer associated with the iocbs |
| 2497 | * and calls the event handler for the ring. This function handles both |
| 2498 | * qring buffers and hbq buffers. |
| 2499 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2500 | * upper layer functions will free the iocb objects. |
| 2501 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | static int |
| 2503 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2504 | struct lpfc_iocbq *saveq) |
| 2505 | { |
| 2506 | IOCB_t * irsp; |
| 2507 | WORD5 * w5p; |
| 2508 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2509 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2510 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2513 | |
| 2514 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2515 | if (pring->lpfc_sli_rcv_async_status) |
| 2516 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2517 | else |
| 2518 | lpfc_printf_log(phba, |
| 2519 | KERN_WARNING, |
| 2520 | LOG_SLI, |
| 2521 | "0316 Ring %d handler: unexpected " |
| 2522 | "ASYNC_STATUS iocb received evt_code " |
| 2523 | "0x%x\n", |
| 2524 | pring->ringno, |
| 2525 | irsp->un.asyncstat.evt_code); |
| 2526 | return 1; |
| 2527 | } |
| 2528 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2529 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2530 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2531 | if (irsp->ulpBdeCount > 0) { |
| 2532 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2533 | irsp->un.ulpWord[3]); |
| 2534 | lpfc_in_buf_free(phba, dmzbuf); |
| 2535 | } |
| 2536 | |
| 2537 | if (irsp->ulpBdeCount > 1) { |
| 2538 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2539 | irsp->unsli3.sli3Words[3]); |
| 2540 | lpfc_in_buf_free(phba, dmzbuf); |
| 2541 | } |
| 2542 | |
| 2543 | if (irsp->ulpBdeCount > 2) { |
| 2544 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2545 | irsp->unsli3.sli3Words[7]); |
| 2546 | lpfc_in_buf_free(phba, dmzbuf); |
| 2547 | } |
| 2548 | |
| 2549 | return 1; |
| 2550 | } |
| 2551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2553 | if (irsp->ulpBdeCount != 0) { |
| 2554 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2556 | if (!saveq->context2) |
| 2557 | lpfc_printf_log(phba, |
| 2558 | KERN_ERR, |
| 2559 | LOG_SLI, |
| 2560 | "0341 Ring %d Cannot find buffer for " |
| 2561 | "an unsolicited iocb. tag 0x%x\n", |
| 2562 | pring->ringno, |
| 2563 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2564 | } |
| 2565 | if (irsp->ulpBdeCount == 2) { |
| 2566 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2567 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2568 | if (!saveq->context3) |
| 2569 | lpfc_printf_log(phba, |
| 2570 | KERN_ERR, |
| 2571 | LOG_SLI, |
| 2572 | "0342 Ring %d Cannot find buffer for an" |
| 2573 | " unsolicited iocb. tag 0x%x\n", |
| 2574 | pring->ringno, |
| 2575 | irsp->unsli3.sli3Words[7]); |
| 2576 | } |
| 2577 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2578 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2579 | if (irsp->ulpBdeCount != 0) { |
| 2580 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2581 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2582 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2583 | lpfc_printf_log(phba, |
| 2584 | KERN_ERR, |
| 2585 | LOG_SLI, |
| 2586 | "0343 Ring %d Cannot find " |
| 2587 | "buffer for an unsolicited iocb" |
| 2588 | ". tag 0x%x\n", pring->ringno, |
| 2589 | irsp->un.ulpWord[3]); |
| 2590 | } |
| 2591 | if (irsp->ulpBdeCount == 2) { |
| 2592 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2593 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2594 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2595 | lpfc_printf_log(phba, |
| 2596 | KERN_ERR, |
| 2597 | LOG_SLI, |
| 2598 | "0344 Ring %d Cannot find " |
| 2599 | "buffer for an unsolicited " |
| 2600 | "iocb. tag 0x%x\n", |
| 2601 | pring->ringno, |
| 2602 | irsp->unsli3.sli3Words[7]); |
| 2603 | } |
| 2604 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2605 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2606 | if (irsp->ulpBdeCount != 0 && |
| 2607 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2608 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2609 | int found = 0; |
| 2610 | |
| 2611 | /* search continue save q for same XRI */ |
| 2612 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2613 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2614 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2615 | list_add_tail(&saveq->list, &iocbq->list); |
| 2616 | found = 1; |
| 2617 | break; |
| 2618 | } |
| 2619 | } |
| 2620 | if (!found) |
| 2621 | list_add_tail(&saveq->clist, |
| 2622 | &pring->iocb_continue_saveq); |
| 2623 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2624 | list_del_init(&iocbq->clist); |
| 2625 | saveq = iocbq; |
| 2626 | irsp = &(saveq->iocb); |
| 2627 | } else |
| 2628 | return 0; |
| 2629 | } |
| 2630 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2631 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2632 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2633 | Rctl = FC_RCTL_ELS_REQ; |
| 2634 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2635 | } else { |
| 2636 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2637 | Rctl = w5p->hcsw.Rctl; |
| 2638 | Type = w5p->hcsw.Type; |
| 2639 | |
| 2640 | /* Firmware Workaround */ |
| 2641 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2642 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2643 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2644 | Rctl = FC_RCTL_ELS_REQ; |
| 2645 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2646 | w5p->hcsw.Rctl = Rctl; |
| 2647 | w5p->hcsw.Type = Type; |
| 2648 | } |
| 2649 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2650 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2651 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2652 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2653 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2654 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2655 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2656 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | } |
| 2659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2661 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2662 | * @phba: Pointer to HBA context object. |
| 2663 | * @pring: Pointer to driver SLI ring object. |
| 2664 | * @prspiocb: Pointer to response iocb object. |
| 2665 | * |
| 2666 | * This function looks up the iocb_lookup table to get the command iocb |
| 2667 | * corresponding to the given response iocb using the iotag of the |
| 2668 | * response iocb. This function is called with the hbalock held. |
| 2669 | * This function returns the command iocb object if it finds the command |
| 2670 | * iocb else returns NULL. |
| 2671 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2674 | struct lpfc_sli_ring *pring, |
| 2675 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2678 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2679 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2681 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2683 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2684 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2686 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2687 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2688 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2689 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | } |
| 2691 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2692 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2693 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2694 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2695 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2696 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | return NULL; |
| 2698 | } |
| 2699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2700 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2701 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2702 | * @phba: Pointer to HBA context object. |
| 2703 | * @pring: Pointer to driver SLI ring object. |
| 2704 | * @iotag: IOCB tag. |
| 2705 | * |
| 2706 | * This function looks up the iocb_lookup table to get the command iocb |
| 2707 | * corresponding to the given iotag. This function is called with the |
| 2708 | * hbalock held. |
| 2709 | * This function returns the command iocb object if it finds the command |
| 2710 | * iocb else returns NULL. |
| 2711 | **/ |
| 2712 | static struct lpfc_iocbq * |
| 2713 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2714 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2715 | { |
| 2716 | struct lpfc_iocbq *cmd_iocb; |
| 2717 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2718 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2719 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2720 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2721 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2722 | /* remove from txcmpl queue list */ |
| 2723 | list_del_init(&cmd_iocb->list); |
| 2724 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2725 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2726 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2727 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2728 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2729 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2730 | iotag, phba->sli.last_iotag); |
| 2731 | return NULL; |
| 2732 | } |
| 2733 | |
| 2734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2735 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2736 | * @phba: Pointer to HBA context object. |
| 2737 | * @pring: Pointer to driver SLI ring object. |
| 2738 | * @saveq: Pointer to the response iocb to be processed. |
| 2739 | * |
| 2740 | * This function is called by the ring event handler for non-fcp |
| 2741 | * rings when there is a new response iocb in the response ring. |
| 2742 | * The caller is not required to hold any locks. This function |
| 2743 | * gets the command iocb associated with the response iocb and |
| 2744 | * calls the completion handler for the command iocb. If there |
| 2745 | * is no completion handler, the function will free the resources |
| 2746 | * associated with command iocb. If the response iocb is for |
| 2747 | * an already aborted command iocb, the status of the completion |
| 2748 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2749 | * This function always returns 1. |
| 2750 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2752 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | struct lpfc_iocbq *saveq) |
| 2754 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | int rc = 1; |
| 2757 | unsigned long iflag; |
| 2758 | |
| 2759 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2760 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2761 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2763 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | if (cmdiocbp) { |
| 2765 | if (cmdiocbp->iocb_cmpl) { |
| 2766 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2767 | * If an ELS command failed send an event to mgmt |
| 2768 | * application. |
| 2769 | */ |
| 2770 | if (saveq->iocb.ulpStatus && |
| 2771 | (pring->ringno == LPFC_ELS_RING) && |
| 2772 | (cmdiocbp->iocb.ulpCommand == |
| 2773 | CMD_ELS_REQUEST64_CR)) |
| 2774 | lpfc_send_els_failure_event(phba, |
| 2775 | cmdiocbp, saveq); |
| 2776 | |
| 2777 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | * Post all ELS completions to the worker thread. |
| 2779 | * All other are passed to the completion callback. |
| 2780 | */ |
| 2781 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2782 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2783 | (cmdiocbp->iocb_flag & |
| 2784 | LPFC_DRIVER_ABORTED)) { |
| 2785 | spin_lock_irqsave(&phba->hbalock, |
| 2786 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2787 | cmdiocbp->iocb_flag &= |
| 2788 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2789 | spin_unlock_irqrestore(&phba->hbalock, |
| 2790 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2791 | saveq->iocb.ulpStatus = |
| 2792 | IOSTAT_LOCAL_REJECT; |
| 2793 | saveq->iocb.un.ulpWord[4] = |
| 2794 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2795 | |
| 2796 | /* Firmware could still be in progress |
| 2797 | * of DMAing payload, so don't free data |
| 2798 | * buffer till after a hbeat. |
| 2799 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2800 | spin_lock_irqsave(&phba->hbalock, |
| 2801 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2802 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2803 | spin_unlock_irqrestore(&phba->hbalock, |
| 2804 | iflag); |
| 2805 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2806 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2807 | if (saveq->iocb_flag & |
| 2808 | LPFC_EXCHANGE_BUSY) { |
| 2809 | /* Set cmdiocb flag for the |
| 2810 | * exchange busy so sgl (xri) |
| 2811 | * will not be released until |
| 2812 | * the abort xri is received |
| 2813 | * from hba. |
| 2814 | */ |
| 2815 | spin_lock_irqsave( |
| 2816 | &phba->hbalock, iflag); |
| 2817 | cmdiocbp->iocb_flag |= |
| 2818 | LPFC_EXCHANGE_BUSY; |
| 2819 | spin_unlock_irqrestore( |
| 2820 | &phba->hbalock, iflag); |
| 2821 | } |
| 2822 | if (cmdiocbp->iocb_flag & |
| 2823 | LPFC_DRIVER_ABORTED) { |
| 2824 | /* |
| 2825 | * Clear LPFC_DRIVER_ABORTED |
| 2826 | * bit in case it was driver |
| 2827 | * initiated abort. |
| 2828 | */ |
| 2829 | spin_lock_irqsave( |
| 2830 | &phba->hbalock, iflag); |
| 2831 | cmdiocbp->iocb_flag &= |
| 2832 | ~LPFC_DRIVER_ABORTED; |
| 2833 | spin_unlock_irqrestore( |
| 2834 | &phba->hbalock, iflag); |
| 2835 | cmdiocbp->iocb.ulpStatus = |
| 2836 | IOSTAT_LOCAL_REJECT; |
| 2837 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2838 | IOERR_ABORT_REQUESTED; |
| 2839 | /* |
| 2840 | * For SLI4, irsiocb contains |
| 2841 | * NO_XRI in sli_xritag, it |
| 2842 | * shall not affect releasing |
| 2843 | * sgl (xri) process. |
| 2844 | */ |
| 2845 | saveq->iocb.ulpStatus = |
| 2846 | IOSTAT_LOCAL_REJECT; |
| 2847 | saveq->iocb.un.ulpWord[4] = |
| 2848 | IOERR_SLI_ABORTED; |
| 2849 | spin_lock_irqsave( |
| 2850 | &phba->hbalock, iflag); |
| 2851 | saveq->iocb_flag |= |
| 2852 | LPFC_DELAY_MEM_FREE; |
| 2853 | spin_unlock_irqrestore( |
| 2854 | &phba->hbalock, iflag); |
| 2855 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2856 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2859 | } else |
| 2860 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | } else { |
| 2862 | /* |
| 2863 | * Unknown initiating command based on the response iotag. |
| 2864 | * This could be the case on the ELS ring because of |
| 2865 | * lpfc_els_abort(). |
| 2866 | */ |
| 2867 | if (pring->ringno != LPFC_ELS_RING) { |
| 2868 | /* |
| 2869 | * Ring <ringno> handler: unexpected completion IoTag |
| 2870 | * <IoTag> |
| 2871 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2872 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2873 | "0322 Ring %d handler: " |
| 2874 | "unexpected completion IoTag x%x " |
| 2875 | "Data: x%x x%x x%x x%x\n", |
| 2876 | pring->ringno, |
| 2877 | saveq->iocb.ulpIoTag, |
| 2878 | saveq->iocb.ulpStatus, |
| 2879 | saveq->iocb.un.ulpWord[4], |
| 2880 | saveq->iocb.ulpCommand, |
| 2881 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | } |
| 2883 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | return rc; |
| 2886 | } |
| 2887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2889 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2890 | * @phba: Pointer to HBA context object. |
| 2891 | * @pring: Pointer to driver SLI ring object. |
| 2892 | * |
| 2893 | * This function is called from the iocb ring event handlers when |
| 2894 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2895 | * an error attention condition to the worker thread and the worker |
| 2896 | * thread will transition the HBA to offline state. |
| 2897 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | static void |
| 2899 | 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] | 2900 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2901 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2902 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2903 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2904 | * rsp ring <portRspMax> |
| 2905 | */ |
| 2906 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2907 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2908 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2909 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2910 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2912 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2913 | |
| 2914 | /* |
| 2915 | * All error attention handlers are posted to |
| 2916 | * worker thread |
| 2917 | */ |
| 2918 | phba->work_ha |= HA_ERATT; |
| 2919 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2920 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2921 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2922 | |
| 2923 | return; |
| 2924 | } |
| 2925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2926 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2927 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2928 | * @ptr: Pointer to address of HBA context object. |
| 2929 | * |
| 2930 | * This function is invoked by the Error Attention polling timer when the |
| 2931 | * timer times out. It will check the SLI Error Attention register for |
| 2932 | * possible attention events. If so, it will post an Error Attention event |
| 2933 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2934 | * Error Attention polling timer for the next poll. |
| 2935 | **/ |
| 2936 | void lpfc_poll_eratt(unsigned long ptr) |
| 2937 | { |
| 2938 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2939 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2940 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2941 | |
| 2942 | phba = (struct lpfc_hba *)ptr; |
| 2943 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2944 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2945 | sli_intr = phba->sli.slistat.sli_intr; |
| 2946 | |
| 2947 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2948 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2949 | sli_intr); |
| 2950 | else |
| 2951 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2952 | |
| 2953 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2954 | do_div(cnt, LPFC_ERATT_POLL_INTERVAL); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2955 | phba->sli.slistat.sli_ips = cnt; |
| 2956 | |
| 2957 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2958 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2959 | /* Check chip HA register for error event */ |
| 2960 | eratt = lpfc_sli_check_eratt(phba); |
| 2961 | |
| 2962 | if (eratt) |
| 2963 | /* Tell the worker thread there is work to do */ |
| 2964 | lpfc_worker_wake_up(phba); |
| 2965 | else |
| 2966 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 2967 | mod_timer(&phba->eratt_poll, |
| 2968 | jiffies + |
| 2969 | msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2970 | return; |
| 2971 | } |
| 2972 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2975 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2976 | * @phba: Pointer to HBA context object. |
| 2977 | * @pring: Pointer to driver SLI ring object. |
| 2978 | * @mask: Host attention register mask for this ring. |
| 2979 | * |
| 2980 | * This function is called from the interrupt context when there is a ring |
| 2981 | * event for the fcp ring. The caller does not hold any lock. |
| 2982 | * 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] | 2983 | * 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] | 2984 | * LE bit set. The function will call the completion handler of the command iocb |
| 2985 | * if the response iocb indicates a completion for a command iocb or it is |
| 2986 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2987 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2989 | * to check it explicitly. |
| 2990 | */ |
| 2991 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2992 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2993 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2994 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2995 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2996 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2997 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2999 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | uint32_t status; |
| 3001 | uint32_t portRspPut, portRspMax; |
| 3002 | int rc = 1; |
| 3003 | lpfc_iocb_type type; |
| 3004 | unsigned long iflag; |
| 3005 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3007 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | pring->stats.iocb_event++; |
| 3009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | /* |
| 3011 | * The next available response entry should never exceed the maximum |
| 3012 | * entries. If it does, treat it as an adapter hardware error. |
| 3013 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3014 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3016 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3017 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | return 1; |
| 3020 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3021 | if (phba->fcp_ring_in_use) { |
| 3022 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3023 | return 1; |
| 3024 | } else |
| 3025 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | |
| 3027 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3028 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3029 | /* |
| 3030 | * Fetch an entry off the ring and copy it into a local data |
| 3031 | * structure. The copy involves a byte-swap since the |
| 3032 | * network byte order and pci byte orders are different. |
| 3033 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3034 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3035 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3036 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3037 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3038 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3039 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3040 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3041 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3042 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3043 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3044 | irsp = &rspiocbq.iocb; |
| 3045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3047 | pring->stats.iocb_rsp++; |
| 3048 | rsp_cmpl++; |
| 3049 | |
| 3050 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | /* |
| 3052 | * If resource errors reported from HBA, reduce |
| 3053 | * queuedepths of the SCSI device. |
| 3054 | */ |
| 3055 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3056 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3057 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3058 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3059 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3060 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3061 | } |
| 3062 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | /* Rsp ring <ringno> error: IOCB */ |
| 3064 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3065 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3066 | "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] | 3067 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | irsp->un.ulpWord[0], |
| 3069 | irsp->un.ulpWord[1], |
| 3070 | irsp->un.ulpWord[2], |
| 3071 | irsp->un.ulpWord[3], |
| 3072 | irsp->un.ulpWord[4], |
| 3073 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3074 | *(uint32_t *)&irsp->un1, |
| 3075 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | switch (type) { |
| 3079 | case LPFC_ABORT_IOCB: |
| 3080 | case LPFC_SOL_IOCB: |
| 3081 | /* |
| 3082 | * Idle exchange closed via ABTS from port. No iocb |
| 3083 | * resources need to be recovered. |
| 3084 | */ |
| 3085 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3086 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3087 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3088 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3089 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3090 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3094 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3095 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3096 | if (unlikely(!cmdiocbq)) |
| 3097 | break; |
| 3098 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3099 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3100 | if (cmdiocbq->iocb_cmpl) { |
| 3101 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3102 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3103 | &rspiocbq); |
| 3104 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3105 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3107 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3109 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3110 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3111 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | default: |
| 3113 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3114 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3115 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3116 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3117 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3118 | dev_warn(&((phba->pcidev)->dev), |
| 3119 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | phba->brd_no, adaptermsg); |
| 3121 | } else { |
| 3122 | /* Unknown IOCB command */ |
| 3123 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3124 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3125 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3126 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3127 | irsp->ulpStatus, |
| 3128 | irsp->ulpIoTag, |
| 3129 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | } |
| 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | /* |
| 3135 | * The response IOCB has been processed. Update the ring |
| 3136 | * pointer in SLIM. If the port response put pointer has not |
| 3137 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3138 | * response put pointer. |
| 3139 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3140 | writel(pring->sli.sli3.rspidx, |
| 3141 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3143 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3145 | } |
| 3146 | |
| 3147 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3148 | pring->stats.iocb_rsp_full++; |
| 3149 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3150 | writel(status, phba->CAregaddr); |
| 3151 | readl(phba->CAregaddr); |
| 3152 | } |
| 3153 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3154 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3155 | pring->stats.iocb_cmd_empty++; |
| 3156 | |
| 3157 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3158 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | lpfc_sli_resume_iocb(phba, pring); |
| 3160 | |
| 3161 | if ((pring->lpfc_sli_cmd_available)) |
| 3162 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3163 | |
| 3164 | } |
| 3165 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3166 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3167 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | return rc; |
| 3169 | } |
| 3170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3172 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3173 | * @phba: Pointer to HBA context object. |
| 3174 | * @pring: Pointer to driver SLI ring object. |
| 3175 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3176 | * |
| 3177 | * This function is called from the worker thread when there is a slow-path |
| 3178 | * response IOCB to process. This function chains all the response iocbs until |
| 3179 | * seeing the iocb with the LE bit set. The function will call |
| 3180 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3181 | * completion of a command iocb. The function will call the |
| 3182 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3183 | * The function frees the resources or calls the completion handler if this |
| 3184 | * iocb is an abort completion. The function returns NULL when the response |
| 3185 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3186 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3187 | * response iocb passed in. |
| 3188 | **/ |
| 3189 | static struct lpfc_iocbq * |
| 3190 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3191 | struct lpfc_iocbq *rspiocbp) |
| 3192 | { |
| 3193 | struct lpfc_iocbq *saveq; |
| 3194 | struct lpfc_iocbq *cmdiocbp; |
| 3195 | struct lpfc_iocbq *next_iocb; |
| 3196 | IOCB_t *irsp = NULL; |
| 3197 | uint32_t free_saveq; |
| 3198 | uint8_t iocb_cmd_type; |
| 3199 | lpfc_iocb_type type; |
| 3200 | unsigned long iflag; |
| 3201 | int rc; |
| 3202 | |
| 3203 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3204 | /* First add the response iocb to the countinueq list */ |
| 3205 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3206 | pring->iocb_continueq_cnt++; |
| 3207 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3208 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3209 | irsp = &rspiocbp->iocb; |
| 3210 | if (irsp->ulpLe) { |
| 3211 | /* |
| 3212 | * By default, the driver expects to free all resources |
| 3213 | * associated with this iocb completion. |
| 3214 | */ |
| 3215 | free_saveq = 1; |
| 3216 | saveq = list_get_first(&pring->iocb_continueq, |
| 3217 | struct lpfc_iocbq, list); |
| 3218 | irsp = &(saveq->iocb); |
| 3219 | list_del_init(&pring->iocb_continueq); |
| 3220 | pring->iocb_continueq_cnt = 0; |
| 3221 | |
| 3222 | pring->stats.iocb_rsp++; |
| 3223 | |
| 3224 | /* |
| 3225 | * If resource errors reported from HBA, reduce |
| 3226 | * queuedepths of the SCSI device. |
| 3227 | */ |
| 3228 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3229 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3230 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3231 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3232 | phba->lpfc_rampdown_queue_depth(phba); |
| 3233 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3234 | } |
| 3235 | |
| 3236 | if (irsp->ulpStatus) { |
| 3237 | /* Rsp ring <ringno> error: IOCB */ |
| 3238 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3239 | "0328 Rsp Ring %d error: " |
| 3240 | "IOCB Data: " |
| 3241 | "x%x x%x x%x x%x " |
| 3242 | "x%x x%x x%x x%x " |
| 3243 | "x%x x%x x%x x%x " |
| 3244 | "x%x x%x x%x x%x\n", |
| 3245 | pring->ringno, |
| 3246 | irsp->un.ulpWord[0], |
| 3247 | irsp->un.ulpWord[1], |
| 3248 | irsp->un.ulpWord[2], |
| 3249 | irsp->un.ulpWord[3], |
| 3250 | irsp->un.ulpWord[4], |
| 3251 | irsp->un.ulpWord[5], |
| 3252 | *(((uint32_t *) irsp) + 6), |
| 3253 | *(((uint32_t *) irsp) + 7), |
| 3254 | *(((uint32_t *) irsp) + 8), |
| 3255 | *(((uint32_t *) irsp) + 9), |
| 3256 | *(((uint32_t *) irsp) + 10), |
| 3257 | *(((uint32_t *) irsp) + 11), |
| 3258 | *(((uint32_t *) irsp) + 12), |
| 3259 | *(((uint32_t *) irsp) + 13), |
| 3260 | *(((uint32_t *) irsp) + 14), |
| 3261 | *(((uint32_t *) irsp) + 15)); |
| 3262 | } |
| 3263 | |
| 3264 | /* |
| 3265 | * Fetch the IOCB command type and call the correct completion |
| 3266 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3267 | * get freed back to the lpfc_iocb_list by the discovery |
| 3268 | * kernel thread. |
| 3269 | */ |
| 3270 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3271 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3272 | switch (type) { |
| 3273 | case LPFC_SOL_IOCB: |
| 3274 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3275 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3276 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3277 | break; |
| 3278 | |
| 3279 | case LPFC_UNSOL_IOCB: |
| 3280 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3281 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3282 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3283 | if (!rc) |
| 3284 | free_saveq = 0; |
| 3285 | break; |
| 3286 | |
| 3287 | case LPFC_ABORT_IOCB: |
| 3288 | cmdiocbp = NULL; |
| 3289 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3290 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3291 | saveq); |
| 3292 | if (cmdiocbp) { |
| 3293 | /* Call the specified completion routine */ |
| 3294 | if (cmdiocbp->iocb_cmpl) { |
| 3295 | spin_unlock_irqrestore(&phba->hbalock, |
| 3296 | iflag); |
| 3297 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3298 | saveq); |
| 3299 | spin_lock_irqsave(&phba->hbalock, |
| 3300 | iflag); |
| 3301 | } else |
| 3302 | __lpfc_sli_release_iocbq(phba, |
| 3303 | cmdiocbp); |
| 3304 | } |
| 3305 | break; |
| 3306 | |
| 3307 | case LPFC_UNKNOWN_IOCB: |
| 3308 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3309 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3310 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3311 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3312 | MAX_MSG_DATA); |
| 3313 | dev_warn(&((phba->pcidev)->dev), |
| 3314 | "lpfc%d: %s\n", |
| 3315 | phba->brd_no, adaptermsg); |
| 3316 | } else { |
| 3317 | /* Unknown IOCB command */ |
| 3318 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3319 | "0335 Unknown IOCB " |
| 3320 | "command Data: x%x " |
| 3321 | "x%x x%x x%x\n", |
| 3322 | irsp->ulpCommand, |
| 3323 | irsp->ulpStatus, |
| 3324 | irsp->ulpIoTag, |
| 3325 | irsp->ulpContext); |
| 3326 | } |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | if (free_saveq) { |
| 3331 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3332 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3333 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3334 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3335 | } |
| 3336 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3337 | } |
| 3338 | rspiocbp = NULL; |
| 3339 | } |
| 3340 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3341 | return rspiocbp; |
| 3342 | } |
| 3343 | |
| 3344 | /** |
| 3345 | * 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] | 3346 | * @phba: Pointer to HBA context object. |
| 3347 | * @pring: Pointer to driver SLI ring object. |
| 3348 | * @mask: Host attention register mask for this ring. |
| 3349 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3350 | * This routine wraps the actual slow_ring event process routine from the |
| 3351 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3352 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3353 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3354 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3355 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3357 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3362 | * @phba: Pointer to HBA context object. |
| 3363 | * @pring: Pointer to driver SLI ring object. |
| 3364 | * @mask: Host attention register mask for this ring. |
| 3365 | * |
| 3366 | * This function is called from the worker thread when there is a ring event |
| 3367 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3368 | * remove each response iocb in the response ring and calls the handle |
| 3369 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3370 | **/ |
| 3371 | static void |
| 3372 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3373 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3374 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3375 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | IOCB_t *entry; |
| 3377 | IOCB_t *irsp = NULL; |
| 3378 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3381 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3383 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | pring->stats.iocb_event++; |
| 3386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | /* |
| 3388 | * The next available response entry should never exceed the maximum |
| 3389 | * entries. If it does, treat it as an adapter hardware error. |
| 3390 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3391 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3393 | if (portRspPut >= portRspMax) { |
| 3394 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3395 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | * rsp ring <portRspMax> |
| 3397 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3399 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3400 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3401 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3402 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | phba->link_state = LPFC_HBA_ERROR; |
| 3404 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | |
| 3406 | phba->work_hs = HS_FFER3; |
| 3407 | lpfc_handle_eratt(phba); |
| 3408 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3409 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3413 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | /* |
| 3415 | * Build a completion list and call the appropriate handler. |
| 3416 | * The process is to get the next available response iocb, get |
| 3417 | * a free iocb from the list, copy the response data into the |
| 3418 | * free iocb, insert to the continuation list, and update the |
| 3419 | * next response index to slim. This process makes response |
| 3420 | * iocb's in the ring available to DMA as fast as possible but |
| 3421 | * pays a penalty for a copy operation. Since the iocb is |
| 3422 | * only 32 bytes, this penalty is considered small relative to |
| 3423 | * the PCI reads for register values and a slim write. When |
| 3424 | * the ulpLe field is set, the entire Command has been |
| 3425 | * received. |
| 3426 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3427 | entry = lpfc_resp_iocb(phba, pring); |
| 3428 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3429 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3430 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | if (rspiocbp == NULL) { |
| 3432 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3433 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | break; |
| 3435 | } |
| 3436 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3437 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3438 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | irsp = &rspiocbp->iocb; |
| 3440 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3441 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3442 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3444 | if (pring->ringno == LPFC_ELS_RING) { |
| 3445 | lpfc_debugfs_slow_ring_trc(phba, |
| 3446 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3447 | *(((uint32_t *) irsp) + 4), |
| 3448 | *(((uint32_t *) irsp) + 6), |
| 3449 | *(((uint32_t *) irsp) + 7)); |
| 3450 | } |
| 3451 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3452 | writel(pring->sli.sli3.rspidx, |
| 3453 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3455 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3456 | /* Handle the response IOCB */ |
| 3457 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3458 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | |
| 3460 | /* |
| 3461 | * If the port response put pointer has not been updated, sync |
| 3462 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3463 | * response put pointer. |
| 3464 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3465 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3467 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3468 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3470 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | /* At least one response entry has been freed */ |
| 3472 | pring->stats.iocb_rsp_full++; |
| 3473 | /* SET RxRE_RSP in Chip Att register */ |
| 3474 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3475 | writel(status, phba->CAregaddr); |
| 3476 | readl(phba->CAregaddr); /* flush */ |
| 3477 | } |
| 3478 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3479 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3480 | pring->stats.iocb_cmd_empty++; |
| 3481 | |
| 3482 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3483 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | lpfc_sli_resume_iocb(phba, pring); |
| 3485 | |
| 3486 | if ((pring->lpfc_sli_cmd_available)) |
| 3487 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3488 | |
| 3489 | } |
| 3490 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3491 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3492 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | } |
| 3494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3495 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3496 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3497 | * @phba: Pointer to HBA context object. |
| 3498 | * @pring: Pointer to driver SLI ring object. |
| 3499 | * @mask: Host attention register mask for this ring. |
| 3500 | * |
| 3501 | * This function is called from the worker thread when there is a pending |
| 3502 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3503 | * queue. The caller does not hold any lock. The function will remove each |
| 3504 | * response iocb from the response worker queue and calls the handle |
| 3505 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3506 | **/ |
| 3507 | static void |
| 3508 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3509 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3510 | { |
| 3511 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3512 | struct hbq_dmabuf *dmabuf; |
| 3513 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3514 | unsigned long iflag; |
| 3515 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3516 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3517 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3518 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3519 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3520 | /* Get the response iocb from the head of work queue */ |
| 3521 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3522 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3523 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3524 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3525 | |
| 3526 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3527 | case CQE_CODE_COMPL_WQE: |
| 3528 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3529 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3530 | /* Translate ELS WCQE to response IOCBQ */ |
| 3531 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3532 | irspiocbq); |
| 3533 | if (irspiocbq) |
| 3534 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3535 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3536 | break; |
| 3537 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3538 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3539 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3540 | cq_event); |
| 3541 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3542 | break; |
| 3543 | default: |
| 3544 | break; |
| 3545 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3550 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3551 | * @phba: Pointer to HBA context object. |
| 3552 | * @pring: Pointer to driver SLI ring object. |
| 3553 | * |
| 3554 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3555 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3556 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3557 | * the return of this function. The caller is not required to hold any locks. |
| 3558 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3559 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3561 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3562 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3565 | if (pring->ringno == LPFC_ELS_RING) { |
| 3566 | lpfc_fabric_abort_hba(phba); |
| 3567 | } |
| 3568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | /* Error everything on txq and txcmplq |
| 3570 | * First do the txq. |
| 3571 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3572 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3573 | spin_lock_irq(&pring->ring_lock); |
| 3574 | list_splice_init(&pring->txq, &completions); |
| 3575 | pring->txq_cnt = 0; |
| 3576 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3578 | spin_lock_irq(&phba->hbalock); |
| 3579 | /* Next issue ABTS for everything on the txcmplq */ |
| 3580 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3581 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3582 | spin_unlock_irq(&phba->hbalock); |
| 3583 | } else { |
| 3584 | spin_lock_irq(&phba->hbalock); |
| 3585 | list_splice_init(&pring->txq, &completions); |
| 3586 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3587 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3588 | /* Next issue ABTS for everything on the txcmplq */ |
| 3589 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3590 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3591 | spin_unlock_irq(&phba->hbalock); |
| 3592 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3593 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3594 | /* Cancel all the IOCBs from the completions list */ |
| 3595 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3596 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | } |
| 3598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3599 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3600 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3601 | * @phba: Pointer to HBA context object. |
| 3602 | * @pring: Pointer to driver SLI ring object. |
| 3603 | * |
| 3604 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3605 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3606 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3607 | * the return of this function. The caller is not required to hold any locks. |
| 3608 | **/ |
| 3609 | void |
| 3610 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3611 | { |
| 3612 | struct lpfc_sli *psli = &phba->sli; |
| 3613 | struct lpfc_sli_ring *pring; |
| 3614 | uint32_t i; |
| 3615 | |
| 3616 | /* Look on all the FCP Rings for the iotag */ |
| 3617 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3618 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3619 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
| 3620 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3621 | } |
| 3622 | } else { |
| 3623 | pring = &psli->ring[psli->fcp_ring]; |
| 3624 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3630 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3631 | * @phba: Pointer to HBA context object. |
| 3632 | * |
| 3633 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3634 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3635 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3636 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3637 | * slot has been permanently disabled. |
| 3638 | **/ |
| 3639 | void |
| 3640 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3641 | { |
| 3642 | LIST_HEAD(txq); |
| 3643 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3644 | struct lpfc_sli *psli = &phba->sli; |
| 3645 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3646 | uint32_t i; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3647 | |
| 3648 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3649 | /* Indicate the I/O queues are flushed */ |
| 3650 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3651 | spin_unlock_irq(&phba->hbalock); |
| 3652 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3653 | /* Look on all the FCP Rings for the iotag */ |
| 3654 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3655 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3656 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3657 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3658 | spin_lock_irq(&pring->ring_lock); |
| 3659 | /* Retrieve everything on txq */ |
| 3660 | list_splice_init(&pring->txq, &txq); |
| 3661 | /* Retrieve everything on the txcmplq */ |
| 3662 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3663 | pring->txq_cnt = 0; |
| 3664 | pring->txcmplq_cnt = 0; |
| 3665 | spin_unlock_irq(&pring->ring_lock); |
| 3666 | |
| 3667 | /* Flush the txq */ |
| 3668 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3669 | IOSTAT_LOCAL_REJECT, |
| 3670 | IOERR_SLI_DOWN); |
| 3671 | /* Flush the txcmpq */ |
| 3672 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3673 | IOSTAT_LOCAL_REJECT, |
| 3674 | IOERR_SLI_DOWN); |
| 3675 | } |
| 3676 | } else { |
| 3677 | pring = &psli->ring[psli->fcp_ring]; |
| 3678 | |
| 3679 | spin_lock_irq(&phba->hbalock); |
| 3680 | /* Retrieve everything on txq */ |
| 3681 | list_splice_init(&pring->txq, &txq); |
| 3682 | /* Retrieve everything on the txcmplq */ |
| 3683 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3684 | pring->txq_cnt = 0; |
| 3685 | pring->txcmplq_cnt = 0; |
| 3686 | spin_unlock_irq(&phba->hbalock); |
| 3687 | |
| 3688 | /* Flush the txq */ |
| 3689 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3690 | IOERR_SLI_DOWN); |
| 3691 | /* Flush the txcmpq */ |
| 3692 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3693 | IOERR_SLI_DOWN); |
| 3694 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3698 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3699 | * @phba: Pointer to HBA context object. |
| 3700 | * @mask: Bit mask to be checked. |
| 3701 | * |
| 3702 | * This function reads the host status register and compares |
| 3703 | * with the provided bit mask to check if HBA completed |
| 3704 | * the restart. This function will wait in a loop for the |
| 3705 | * HBA to complete restart. If the HBA does not restart within |
| 3706 | * 15 iterations, the function will reset the HBA again. The |
| 3707 | * function returns 1 when HBA fail to restart otherwise returns |
| 3708 | * zero. |
| 3709 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3710 | static int |
| 3711 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3713 | uint32_t status; |
| 3714 | int i = 0; |
| 3715 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3717 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3718 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3719 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3721 | /* |
| 3722 | * Check status register every 100ms for 5 retries, then every |
| 3723 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3724 | * every 2.5 sec for 4. |
| 3725 | * Break our of the loop if errors occurred during init. |
| 3726 | */ |
| 3727 | while (((status & mask) != mask) && |
| 3728 | !(status & HS_FFERM) && |
| 3729 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3731 | if (i <= 5) |
| 3732 | msleep(10); |
| 3733 | else if (i <= 10) |
| 3734 | msleep(500); |
| 3735 | else |
| 3736 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3738 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3740 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3741 | lpfc_sli_brdrestart(phba); |
| 3742 | } |
| 3743 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3744 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3745 | retval = 1; |
| 3746 | break; |
| 3747 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3750 | /* Check to see if any errors occurred during init */ |
| 3751 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3753 | "2751 Adapter failed to restart, " |
| 3754 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3755 | status, |
| 3756 | readl(phba->MBslimaddr + 0xa8), |
| 3757 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3758 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3759 | retval = 1; |
| 3760 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3762 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | } |
| 3764 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3765 | /** |
| 3766 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3767 | * @phba: Pointer to HBA context object. |
| 3768 | * @mask: Bit mask to be checked. |
| 3769 | * |
| 3770 | * This function checks the host status register to check if HBA is |
| 3771 | * ready. This function will wait in a loop for the HBA to be ready |
| 3772 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3773 | * function again. The function returns 1 when HBA fail to be ready |
| 3774 | * otherwise returns zero. |
| 3775 | **/ |
| 3776 | static int |
| 3777 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3778 | { |
| 3779 | uint32_t status; |
| 3780 | int retval = 0; |
| 3781 | |
| 3782 | /* Read the HBA Host Status Register */ |
| 3783 | status = lpfc_sli4_post_status_check(phba); |
| 3784 | |
| 3785 | if (status) { |
| 3786 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3787 | lpfc_sli_brdrestart(phba); |
| 3788 | status = lpfc_sli4_post_status_check(phba); |
| 3789 | } |
| 3790 | |
| 3791 | /* Check to see if any errors occurred during init */ |
| 3792 | if (status) { |
| 3793 | phba->link_state = LPFC_HBA_ERROR; |
| 3794 | retval = 1; |
| 3795 | } else |
| 3796 | phba->sli4_hba.intr_enable = 0; |
| 3797 | |
| 3798 | return retval; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3803 | * @phba: Pointer to HBA context object. |
| 3804 | * @mask: Bit mask to be checked. |
| 3805 | * |
| 3806 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3807 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3808 | **/ |
| 3809 | int |
| 3810 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3811 | { |
| 3812 | return phba->lpfc_sli_brdready(phba, mask); |
| 3813 | } |
| 3814 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3815 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3818 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3819 | * @phba: Pointer to HBA context object. |
| 3820 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3821 | * This function is called before resetting an HBA. This function is called |
| 3822 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3823 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3824 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3825 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3826 | uint32_t __iomem *resp_buf; |
| 3827 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3828 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3829 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3830 | int i; |
| 3831 | uint8_t hdrtype; |
| 3832 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3833 | lockdep_assert_held(&phba->hbalock); |
| 3834 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3835 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3836 | if (hdrtype != 0x80 || |
| 3837 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3838 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3839 | return; |
| 3840 | |
| 3841 | /* |
| 3842 | * Tell the other part of the chip to suspend temporarily all |
| 3843 | * its DMA activity. |
| 3844 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3845 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3846 | |
| 3847 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3848 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3849 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3850 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3851 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3853 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3854 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3855 | return; |
| 3856 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3857 | /* Clear Chip error bit */ |
| 3858 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3859 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | mbox = 0; |
| 3863 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3864 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3865 | |
| 3866 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3867 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3868 | writel(mbox, mbox_buf); |
| 3869 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3870 | for (i = 0; i < 50; i++) { |
| 3871 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3872 | return; |
| 3873 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3874 | mdelay(1); |
| 3875 | else |
| 3876 | break; |
| 3877 | } |
| 3878 | resp_data = 0; |
| 3879 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3880 | return; |
| 3881 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3882 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3883 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3884 | goto restore_hc; |
| 3885 | else |
| 3886 | goto clear_errat; |
| 3887 | } |
| 3888 | |
| 3889 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3890 | resp_data = 0; |
| 3891 | for (i = 0; i < 500; i++) { |
| 3892 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3893 | return; |
| 3894 | if (resp_data != mbox) |
| 3895 | mdelay(1); |
| 3896 | else |
| 3897 | break; |
| 3898 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3899 | |
| 3900 | clear_errat: |
| 3901 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3902 | while (++i < 500) { |
| 3903 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3904 | return; |
| 3905 | if (!(ha_copy & HA_ERATT)) |
| 3906 | mdelay(1); |
| 3907 | else |
| 3908 | break; |
| 3909 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3910 | |
| 3911 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3912 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3918 | writel(hc_copy, phba->HCregaddr); |
| 3919 | readl(phba->HCregaddr); /* flush */ |
| 3920 | } |
| 3921 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3922 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3923 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3924 | * @phba: Pointer to HBA context object. |
| 3925 | * |
| 3926 | * This function issues a kill_board mailbox command and waits for |
| 3927 | * the error attention interrupt. This function is called for stopping |
| 3928 | * the firmware processing. The caller is not required to hold any |
| 3929 | * locks. This function calls lpfc_hba_down_post function to free |
| 3930 | * any pending commands after the kill. The function will return 1 when it |
| 3931 | * fails to kill the board else will return 0. |
| 3932 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3933 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3934 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3936 | struct lpfc_sli *psli; |
| 3937 | LPFC_MBOXQ_t *pmb; |
| 3938 | uint32_t status; |
| 3939 | uint32_t ha_copy; |
| 3940 | int retval; |
| 3941 | int i = 0; |
| 3942 | |
| 3943 | psli = &phba->sli; |
| 3944 | |
| 3945 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3946 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3947 | "0329 Kill HBA Data: x%x x%x\n", |
| 3948 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3949 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3950 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3951 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3952 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3953 | |
| 3954 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3955 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3956 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3957 | spin_unlock_irq(&phba->hbalock); |
| 3958 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3959 | return 1; |
| 3960 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3961 | status &= ~HC_ERINT_ENA; |
| 3962 | writel(status, phba->HCregaddr); |
| 3963 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3964 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3965 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3966 | |
| 3967 | lpfc_kill_board(phba, pmb); |
| 3968 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3969 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3970 | |
| 3971 | if (retval != MBX_SUCCESS) { |
| 3972 | if (retval != MBX_BUSY) |
| 3973 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3975 | "2752 KILL_BOARD command failed retval %d\n", |
| 3976 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3977 | spin_lock_irq(&phba->hbalock); |
| 3978 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3979 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3980 | return 1; |
| 3981 | } |
| 3982 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3983 | spin_lock_irq(&phba->hbalock); |
| 3984 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3985 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3986 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3987 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3988 | |
| 3989 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3990 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3991 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3992 | * board is now undefined. |
| 3993 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3994 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3995 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3996 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3997 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3998 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3999 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4003 | if (ha_copy & HA_ERATT) { |
| 4004 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4005 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4006 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4008 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4009 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4011 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4012 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4013 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4019 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4020 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4021 | * @phba: Pointer to HBA context object. |
| 4022 | * |
| 4023 | * This function resets the HBA by writing HC_INITFF to the control |
| 4024 | * register. After the HBA resets, this function resets all the iocb ring |
| 4025 | * indices. This function disables PCI layer parity checking during |
| 4026 | * the reset. |
| 4027 | * This function returns 0 always. |
| 4028 | * The caller is not required to hold any locks. |
| 4029 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4030 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4031 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4032 | { |
| 4033 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4035 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4038 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4040 | /* Reset HBA */ |
| 4041 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4042 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4043 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | |
| 4045 | /* perform board reset */ |
| 4046 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4047 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4048 | phba->pport->fc_myDID = 0; |
| 4049 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4051 | /* Turn off parity checking and serr during the physical reset */ |
| 4052 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4053 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4054 | (cfg_value & |
| 4055 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4056 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4057 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4058 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4059 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4060 | writel(HC_INITFF, phba->HCregaddr); |
| 4061 | mdelay(1); |
| 4062 | readl(phba->HCregaddr); /* flush */ |
| 4063 | writel(0, phba->HCregaddr); |
| 4064 | readl(phba->HCregaddr); /* flush */ |
| 4065 | |
| 4066 | /* Restore PCI cmd register */ |
| 4067 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | |
| 4069 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4070 | for (i = 0; i < psli->num_rings; i++) { |
| 4071 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4073 | pring->sli.sli3.rspidx = 0; |
| 4074 | pring->sli.sli3.next_cmdidx = 0; |
| 4075 | pring->sli.sli3.local_getidx = 0; |
| 4076 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | pring->missbufcnt = 0; |
| 4078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4080 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4081 | return 0; |
| 4082 | } |
| 4083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4084 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4085 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4086 | * @phba: Pointer to HBA context object. |
| 4087 | * |
| 4088 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4089 | * checking during resets the device. The caller is not required to hold |
| 4090 | * any locks. |
| 4091 | * |
| 4092 | * This function returns 0 always. |
| 4093 | **/ |
| 4094 | int |
| 4095 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4096 | { |
| 4097 | struct lpfc_sli *psli = &phba->sli; |
| 4098 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4099 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4100 | |
| 4101 | /* Reset HBA */ |
| 4102 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4103 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4104 | phba->pport->port_state, psli->sli_flag, |
| 4105 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4106 | |
| 4107 | /* perform board reset */ |
| 4108 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4109 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4110 | phba->pport->fc_myDID = 0; |
| 4111 | phba->pport->fc_prevDID = 0; |
| 4112 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4113 | spin_lock_irq(&phba->hbalock); |
| 4114 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4115 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4116 | spin_unlock_irq(&phba->hbalock); |
| 4117 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4118 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4119 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4120 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4121 | return rc; |
| 4122 | } |
| 4123 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4124 | /* Now physically reset the device */ |
| 4125 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4126 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4127 | |
| 4128 | /* Turn off parity checking and serr during the physical reset */ |
| 4129 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4130 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4131 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4132 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4133 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4134 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4135 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4136 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4137 | /* Restore PCI cmd register */ |
| 4138 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4139 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4140 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /** |
| 4144 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4145 | * @phba: Pointer to HBA context object. |
| 4146 | * |
| 4147 | * This function is called in the SLI initialization code path to |
| 4148 | * restart the HBA. The caller is not required to hold any lock. |
| 4149 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4150 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4151 | * function to free any pending commands. The function enables |
| 4152 | * POST only during the first initialization. The function returns zero. |
| 4153 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4154 | * command before the return of this function. |
| 4155 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4156 | static int |
| 4157 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4158 | { |
| 4159 | MAILBOX_t *mb; |
| 4160 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4161 | volatile uint32_t word0; |
| 4162 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4163 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4166 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4167 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4168 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4169 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4170 | psli = &phba->sli; |
| 4171 | |
| 4172 | /* Restart HBA */ |
| 4173 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4174 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4175 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4176 | |
| 4177 | word0 = 0; |
| 4178 | mb = (MAILBOX_t *) &word0; |
| 4179 | mb->mbxCommand = MBX_RESTART; |
| 4180 | mb->mbxHc = 1; |
| 4181 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4182 | lpfc_reset_barrier(phba); |
| 4183 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4184 | to_slim = phba->MBslimaddr; |
| 4185 | writel(*(uint32_t *) mb, to_slim); |
| 4186 | readl(to_slim); /* flush */ |
| 4187 | |
| 4188 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4189 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4190 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4191 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4192 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4193 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4194 | writel(*(uint32_t *) mb, to_slim); |
| 4195 | readl(to_slim); /* flush */ |
| 4196 | |
| 4197 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4198 | phba->pport->stopped = 0; |
| 4199 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4200 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4201 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4202 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4203 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4204 | psli->stats_start = get_seconds(); |
| 4205 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4206 | /* Give the INITFF and Post time to settle. */ |
| 4207 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4209 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4210 | if (hba_aer_enabled) |
| 4211 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4212 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4213 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | |
| 4215 | return 0; |
| 4216 | } |
| 4217 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4218 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4219 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4220 | * @phba: Pointer to HBA context object. |
| 4221 | * |
| 4222 | * This function is called in the SLI initialization code path to restart |
| 4223 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4224 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4225 | * free any pending commands. |
| 4226 | **/ |
| 4227 | static int |
| 4228 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4229 | { |
| 4230 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4231 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4232 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4233 | |
| 4234 | /* Restart HBA */ |
| 4235 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4236 | "0296 Restart HBA Data: x%x x%x\n", |
| 4237 | phba->pport->port_state, psli->sli_flag); |
| 4238 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4239 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4240 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4241 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4242 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4243 | |
| 4244 | spin_lock_irq(&phba->hbalock); |
| 4245 | phba->pport->stopped = 0; |
| 4246 | phba->link_state = LPFC_INIT_START; |
| 4247 | phba->hba_flag = 0; |
| 4248 | spin_unlock_irq(&phba->hbalock); |
| 4249 | |
| 4250 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4251 | psli->stats_start = get_seconds(); |
| 4252 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4253 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4254 | if (hba_aer_enabled) |
| 4255 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4256 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4257 | lpfc_hba_down_post(phba); |
| 4258 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4259 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4264 | * @phba: Pointer to HBA context object. |
| 4265 | * |
| 4266 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4267 | * API jump table function pointer from the lpfc_hba struct. |
| 4268 | **/ |
| 4269 | int |
| 4270 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4271 | { |
| 4272 | return phba->lpfc_sli_brdrestart(phba); |
| 4273 | } |
| 4274 | |
| 4275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4276 | * 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] | 4277 | * @phba: Pointer to HBA context object. |
| 4278 | * |
| 4279 | * This function is called after a HBA restart to wait for successful |
| 4280 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4281 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4282 | * iteration, the function will restart the HBA again. The function returns |
| 4283 | * zero if HBA successfully restarted else returns negative error code. |
| 4284 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | static int |
| 4286 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4287 | { |
| 4288 | uint32_t status, i = 0; |
| 4289 | |
| 4290 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4291 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4292 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | |
| 4294 | /* Check status register to see what current state is */ |
| 4295 | i = 0; |
| 4296 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4297 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4298 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4299 | * retries, then every 1 sec for 50 retires for a total of |
| 4300 | * ~60 seconds before reset the board again and check every |
| 4301 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4302 | * board ready is required by the Falcon FIPS zeroization |
| 4303 | * complete, and any reset the board in between shall cause |
| 4304 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4306 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | /* Adapter failed to init, timeout, status reg |
| 4308 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4309 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4310 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4311 | "timeout, status reg x%x, " |
| 4312 | "FW Data: A8 x%x AC x%x\n", status, |
| 4313 | readl(phba->MBslimaddr + 0xa8), |
| 4314 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4315 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | return -ETIMEDOUT; |
| 4317 | } |
| 4318 | |
| 4319 | /* Check to see if any errors occurred during init */ |
| 4320 | if (status & HS_FFERM) { |
| 4321 | /* ERROR: During chipset initialization */ |
| 4322 | /* Adapter failed to init, chipset, status reg |
| 4323 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4325 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4326 | "chipset, status reg x%x, " |
| 4327 | "FW Data: A8 x%x AC x%x\n", status, |
| 4328 | readl(phba->MBslimaddr + 0xa8), |
| 4329 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | return -EIO; |
| 4332 | } |
| 4333 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4334 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4336 | else if (i <= 100) |
| 4337 | msleep(100); |
| 4338 | else |
| 4339 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4341 | if (i == 150) { |
| 4342 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4343 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4344 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | } |
| 4346 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4347 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4348 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | /* Check to see if any errors occurred during init */ |
| 4352 | if (status & HS_FFERM) { |
| 4353 | /* ERROR: During chipset initialization */ |
| 4354 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4356 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4357 | "status reg x%x, " |
| 4358 | "FW Data: A8 x%x AC x%x\n", status, |
| 4359 | readl(phba->MBslimaddr + 0xa8), |
| 4360 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4361 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | return -EIO; |
| 4363 | } |
| 4364 | |
| 4365 | /* Clear all interrupt enable conditions */ |
| 4366 | writel(0, phba->HCregaddr); |
| 4367 | readl(phba->HCregaddr); /* flush */ |
| 4368 | |
| 4369 | /* setup host attn register */ |
| 4370 | writel(0xffffffff, phba->HAregaddr); |
| 4371 | readl(phba->HAregaddr); /* flush */ |
| 4372 | return 0; |
| 4373 | } |
| 4374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4376 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4377 | * |
| 4378 | * This function calculates and returns the number of HBQs required to be |
| 4379 | * configured. |
| 4380 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4381 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4382 | lpfc_sli_hbq_count(void) |
| 4383 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4385 | } |
| 4386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4388 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4389 | * |
| 4390 | * This function adds the number of hbq entries in every HBQ to get |
| 4391 | * the total number of hbq entries required for the HBA and returns |
| 4392 | * the total count. |
| 4393 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4394 | static int |
| 4395 | lpfc_sli_hbq_entry_count(void) |
| 4396 | { |
| 4397 | int hbq_count = lpfc_sli_hbq_count(); |
| 4398 | int count = 0; |
| 4399 | int i; |
| 4400 | |
| 4401 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4402 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4403 | return count; |
| 4404 | } |
| 4405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4407 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4408 | * |
| 4409 | * This function calculates amount of memory required for all hbq entries |
| 4410 | * to be configured and returns the total memory required. |
| 4411 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4413 | lpfc_sli_hbq_size(void) |
| 4414 | { |
| 4415 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4416 | } |
| 4417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4419 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4420 | * @phba: Pointer to HBA context object. |
| 4421 | * |
| 4422 | * This function is called during the SLI initialization to configure |
| 4423 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4424 | * required to hold any locks. This function will return zero if successful |
| 4425 | * else it will return negative error code. |
| 4426 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4427 | static int |
| 4428 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4429 | { |
| 4430 | int hbq_count = lpfc_sli_hbq_count(); |
| 4431 | LPFC_MBOXQ_t *pmb; |
| 4432 | MAILBOX_t *pmbox; |
| 4433 | uint32_t hbqno; |
| 4434 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4435 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4436 | /* Get a Mailbox buffer to setup mailbox |
| 4437 | * commands for HBA initialization |
| 4438 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4439 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4440 | |
| 4441 | if (!pmb) |
| 4442 | return -ENOMEM; |
| 4443 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4444 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4445 | |
| 4446 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4447 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4448 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4449 | |
| 4450 | hbq_entry_index = 0; |
| 4451 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4452 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4453 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4454 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4455 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4456 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4457 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4458 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4459 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4460 | |
| 4461 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4462 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4463 | mbxStatus <status>, ring <num> */ |
| 4464 | |
| 4465 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4466 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4467 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4468 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4469 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4470 | pmbox->mbxStatus, hbqno); |
| 4471 | |
| 4472 | phba->link_state = LPFC_HBA_ERROR; |
| 4473 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4474 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | phba->hbq_count = hbq_count; |
| 4478 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4479 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4480 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4481 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4482 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4483 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4484 | return 0; |
| 4485 | } |
| 4486 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4487 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4488 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4489 | * @phba: Pointer to HBA context object. |
| 4490 | * |
| 4491 | * This function is called during the SLI initialization to configure |
| 4492 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4493 | * required to hold any locks. This function will return zero if successful |
| 4494 | * else it will return negative error code. |
| 4495 | **/ |
| 4496 | static int |
| 4497 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4498 | { |
| 4499 | phba->hbq_in_use = 1; |
| 4500 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4501 | phba->hbq_count = 1; |
| 4502 | /* Initially populate or replenish the HBQs */ |
| 4503 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4504 | return 0; |
| 4505 | } |
| 4506 | |
| 4507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4508 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4509 | * @phba: Pointer to HBA context object. |
| 4510 | * @sli_mode: sli mode - 2/3 |
| 4511 | * |
| 4512 | * This function is called by the sli intialization code path |
| 4513 | * to issue config_port mailbox command. This function restarts the |
| 4514 | * HBA firmware and issues a config_port mailbox command to configure |
| 4515 | * the SLI interface in the sli mode specified by sli_mode |
| 4516 | * variable. The caller is not required to hold any locks. |
| 4517 | * The function returns 0 if successful, else returns negative error |
| 4518 | * code. |
| 4519 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4520 | int |
| 4521 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | { |
| 4523 | LPFC_MBOXQ_t *pmb; |
| 4524 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4525 | |
| 4526 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4527 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4528 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | return -ENOMEM; |
| 4530 | } |
| 4531 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4532 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4535 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4538 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | rc = lpfc_sli_chipset_init(phba); |
| 4540 | if (rc) |
| 4541 | break; |
| 4542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4544 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | resetcount++; |
| 4547 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4548 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4549 | * value of 0 means the call was successful. Any other |
| 4550 | * nonzero value is a failure, but if ERESTART is returned, |
| 4551 | * the driver may reset the HBA and try again. |
| 4552 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4553 | rc = lpfc_config_port_prep(phba); |
| 4554 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4555 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4557 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4558 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4560 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | lpfc_config_port(phba, pmb); |
| 4562 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4563 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4564 | LPFC_SLI3_HBQ_ENABLED | |
| 4565 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4566 | LPFC_SLI3_BG_ENABLED | |
| 4567 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4568 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4570 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4571 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4572 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4573 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4574 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | spin_unlock_irq(&phba->hbalock); |
| 4576 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4577 | } else { |
| 4578 | /* Allow asynchronous mailbox command to go through */ |
| 4579 | spin_lock_irq(&phba->hbalock); |
| 4580 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4581 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4582 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4583 | |
| 4584 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4585 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4586 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4587 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4590 | if (!done) { |
| 4591 | rc = -EINVAL; |
| 4592 | goto do_prep_failed; |
| 4593 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4594 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4595 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4596 | rc = -ENXIO; |
| 4597 | goto do_prep_failed; |
| 4598 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4599 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4600 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4601 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4602 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4603 | phba->max_vpi : phba->max_vports; |
| 4604 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4605 | } else |
| 4606 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4607 | phba->fips_level = 0; |
| 4608 | phba->fips_spec_rev = 0; |
| 4609 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4610 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4611 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4612 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4613 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4614 | "2850 Security Crypto Active. FIPS x%d " |
| 4615 | "(Spec Rev: x%d)", |
| 4616 | phba->fips_level, phba->fips_spec_rev); |
| 4617 | } |
| 4618 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4620 | "2856 Config Port Security Crypto " |
| 4621 | "Error: x%x ", |
| 4622 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4623 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4624 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4625 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4626 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4627 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4628 | |
| 4629 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4630 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4631 | |
| 4632 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4633 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4634 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4635 | else |
| 4636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4637 | "0443 Adapter did not grant " |
| 4638 | "BlockGuard\n"); |
| 4639 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4640 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4641 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4642 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4643 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4644 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4645 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4646 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4647 | return rc; |
| 4648 | } |
| 4649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4650 | |
| 4651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4652 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4653 | * @phba: Pointer to HBA context object. |
| 4654 | * |
| 4655 | * This function is the main SLI intialization function. This function |
| 4656 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4657 | * error attention handler code. Caller is not required to hold any |
| 4658 | * locks. This function issues config_port mailbox command to configure |
| 4659 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4660 | * calls the config_port_post function to issue init_link mailbox |
| 4661 | * command and to start the discovery. The function will return zero |
| 4662 | * if successful, else it will return negative error code. |
| 4663 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4664 | int |
| 4665 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4666 | { |
| 4667 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4668 | int mode = 3, i; |
| 4669 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4670 | |
| 4671 | switch (lpfc_sli_mode) { |
| 4672 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4673 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4675 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4676 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4677 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4678 | break; |
| 4679 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4680 | mode = 2; |
| 4681 | break; |
| 4682 | case 0: |
| 4683 | case 3: |
| 4684 | break; |
| 4685 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4686 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4687 | "1819 Unrecognized lpfc_sli_mode " |
| 4688 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4689 | |
| 4690 | break; |
| 4691 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 4692 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4693 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4694 | rc = lpfc_sli_config_port(phba, mode); |
| 4695 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4696 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4697 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4698 | "1820 Unable to select SLI-3. " |
| 4699 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4700 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4701 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4702 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | goto lpfc_sli_hba_setup_error; |
| 4704 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4705 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4706 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4707 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4708 | if (!rc) { |
| 4709 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4710 | "2709 This device supports " |
| 4711 | "Advanced Error Reporting (AER)\n"); |
| 4712 | spin_lock_irq(&phba->hbalock); |
| 4713 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4714 | spin_unlock_irq(&phba->hbalock); |
| 4715 | } else { |
| 4716 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4717 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4718 | "Advanced Error Reporting (AER): %d\n", |
| 4719 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4720 | phba->cfg_aer_support = 0; |
| 4721 | } |
| 4722 | } |
| 4723 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4724 | if (phba->sli_rev == 3) { |
| 4725 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4726 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4727 | } else { |
| 4728 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4729 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4730 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4734 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4735 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4736 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4737 | |
| 4738 | if (rc) |
| 4739 | goto lpfc_sli_hba_setup_error; |
| 4740 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4741 | /* Initialize VPIs. */ |
| 4742 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4743 | /* |
| 4744 | * The VPI bitmask and physical ID array are allocated |
| 4745 | * and initialized once only - at driver load. A port |
| 4746 | * reset doesn't need to reinitialize this memory. |
| 4747 | */ |
| 4748 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4749 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4750 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4751 | GFP_KERNEL); |
| 4752 | if (!phba->vpi_bmask) { |
| 4753 | rc = -ENOMEM; |
| 4754 | goto lpfc_sli_hba_setup_error; |
| 4755 | } |
| 4756 | |
| 4757 | phba->vpi_ids = kzalloc( |
| 4758 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4759 | GFP_KERNEL); |
| 4760 | if (!phba->vpi_ids) { |
| 4761 | kfree(phba->vpi_bmask); |
| 4762 | rc = -ENOMEM; |
| 4763 | goto lpfc_sli_hba_setup_error; |
| 4764 | } |
| 4765 | for (i = 0; i < phba->max_vpi; i++) |
| 4766 | phba->vpi_ids[i] = i; |
| 4767 | } |
| 4768 | } |
| 4769 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4770 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4771 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4772 | rc = lpfc_sli_hbq_setup(phba); |
| 4773 | if (rc) |
| 4774 | goto lpfc_sli_hba_setup_error; |
| 4775 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4776 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4778 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4779 | |
| 4780 | rc = lpfc_config_port_post(phba); |
| 4781 | if (rc) |
| 4782 | goto lpfc_sli_hba_setup_error; |
| 4783 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4784 | return rc; |
| 4785 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4786 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4787 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4789 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4790 | return rc; |
| 4791 | } |
| 4792 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4793 | /** |
| 4794 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4795 | * @phba: Pointer to HBA context object. |
| 4796 | * @mboxq: mailbox pointer. |
| 4797 | * This function issue a dump mailbox command to read config region |
| 4798 | * 23 and parse the records in the region and populate driver |
| 4799 | * data structure. |
| 4800 | **/ |
| 4801 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4802 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4803 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4804 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4805 | struct lpfc_dmabuf *mp; |
| 4806 | struct lpfc_mqe *mqe; |
| 4807 | uint32_t data_length; |
| 4808 | int rc; |
| 4809 | |
| 4810 | /* Program the default value of vlan_id and fc_map */ |
| 4811 | phba->valid_vlan = 0; |
| 4812 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4813 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4814 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4815 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4816 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4817 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4818 | return -ENOMEM; |
| 4819 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4820 | mqe = &mboxq->u.mqe; |
| 4821 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4822 | rc = -ENOMEM; |
| 4823 | goto out_free_mboxq; |
| 4824 | } |
| 4825 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4826 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4827 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4828 | |
| 4829 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4830 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4831 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4832 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4833 | "CQ: x%x x%x x%x x%x\n", |
| 4834 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4835 | bf_get(lpfc_mqe_command, mqe), |
| 4836 | bf_get(lpfc_mqe_status, mqe), |
| 4837 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4838 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4839 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4840 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4841 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4842 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4843 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4844 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4845 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4846 | mboxq->mcqe.word0, |
| 4847 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4848 | mboxq->mcqe.trailer); |
| 4849 | |
| 4850 | if (rc) { |
| 4851 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4852 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4853 | rc = -EIO; |
| 4854 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4855 | } |
| 4856 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4857 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4858 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4859 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4860 | rc = -EIO; |
| 4861 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4862 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4863 | |
| 4864 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4865 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4866 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4867 | rc = 0; |
| 4868 | |
| 4869 | out_free_mboxq: |
| 4870 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4871 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | /** |
| 4875 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4876 | * @phba: pointer to lpfc hba data structure. |
| 4877 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4878 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4879 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4880 | * On output, the number of data bytes in @vpd. |
| 4881 | * |
| 4882 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4883 | * addition, this routine gets the port vpd data. |
| 4884 | * |
| 4885 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4886 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4887 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4888 | **/ |
| 4889 | static int |
| 4890 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4891 | uint8_t *vpd, uint32_t *vpd_size) |
| 4892 | { |
| 4893 | int rc = 0; |
| 4894 | uint32_t dma_size; |
| 4895 | struct lpfc_dmabuf *dmabuf; |
| 4896 | struct lpfc_mqe *mqe; |
| 4897 | |
| 4898 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4899 | if (!dmabuf) |
| 4900 | return -ENOMEM; |
| 4901 | |
| 4902 | /* |
| 4903 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4904 | * mailbox command. |
| 4905 | */ |
| 4906 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 4907 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 4908 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4909 | if (!dmabuf->virt) { |
| 4910 | kfree(dmabuf); |
| 4911 | return -ENOMEM; |
| 4912 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | |
| 4914 | /* |
| 4915 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4916 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4917 | * in SLI3. This code corrects the conflicts. |
| 4918 | */ |
| 4919 | lpfc_read_rev(phba, mboxq); |
| 4920 | mqe = &mboxq->u.mqe; |
| 4921 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4922 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4923 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4924 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4925 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4926 | |
| 4927 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4928 | if (rc) { |
| 4929 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4930 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4931 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4932 | return -EIO; |
| 4933 | } |
| 4934 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4935 | /* |
| 4936 | * The available vpd length cannot be bigger than the |
| 4937 | * DMA buffer passed to the port. Catch the less than |
| 4938 | * case and update the caller's size. |
| 4939 | */ |
| 4940 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4941 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4942 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4943 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4944 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4945 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4946 | dmabuf->virt, dmabuf->phys); |
| 4947 | kfree(dmabuf); |
| 4948 | return 0; |
| 4949 | } |
| 4950 | |
| 4951 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4952 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4953 | * @phba: pointer to lpfc hba data structure. |
| 4954 | * |
| 4955 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4956 | * is attached to. |
| 4957 | * |
| 4958 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4959 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4960 | * otherwise - failed to retrieve physical port name |
| 4961 | **/ |
| 4962 | static int |
| 4963 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4964 | { |
| 4965 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4966 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4967 | struct lpfc_controller_attribute *cntl_attr; |
| 4968 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4969 | void *virtaddr = NULL; |
| 4970 | uint32_t alloclen, reqlen; |
| 4971 | uint32_t shdr_status, shdr_add_status; |
| 4972 | union lpfc_sli4_cfg_shdr *shdr; |
| 4973 | char cport_name = 0; |
| 4974 | int rc; |
| 4975 | |
| 4976 | /* We assume nothing at this point */ |
| 4977 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4978 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4979 | |
| 4980 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4981 | if (!mboxq) |
| 4982 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4983 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4984 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4985 | lpfc_sli4_read_config(phba); |
| 4986 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4987 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4988 | |
| 4989 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4990 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4991 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4992 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4993 | LPFC_SLI4_MBX_NEMBED); |
| 4994 | if (alloclen < reqlen) { |
| 4995 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4996 | "3084 Allocated DMA memory size (%d) is " |
| 4997 | "less than the requested DMA memory size " |
| 4998 | "(%d)\n", alloclen, reqlen); |
| 4999 | rc = -ENOMEM; |
| 5000 | goto out_free_mboxq; |
| 5001 | } |
| 5002 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5003 | virtaddr = mboxq->sge_array->addr[0]; |
| 5004 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5005 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5006 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5007 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5008 | if (shdr_status || shdr_add_status || rc) { |
| 5009 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5010 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5011 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5012 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5013 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5014 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5015 | rc, shdr_status, shdr_add_status); |
| 5016 | rc = -ENXIO; |
| 5017 | goto out_free_mboxq; |
| 5018 | } |
| 5019 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5020 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5021 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5022 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5023 | phba->sli4_hba.lnk_info.lnk_no = |
| 5024 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5025 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5026 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5027 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5028 | phba->sli4_hba.lnk_info.lnk_no); |
| 5029 | |
| 5030 | retrieve_ppname: |
| 5031 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5032 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5033 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5034 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5035 | LPFC_SLI4_MBX_EMBED); |
| 5036 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5037 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5038 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5039 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5040 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5041 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5042 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5043 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5044 | if (shdr_status || shdr_add_status || rc) { |
| 5045 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5046 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5047 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5048 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5049 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5050 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5051 | rc, shdr_status, shdr_add_status); |
| 5052 | rc = -ENXIO; |
| 5053 | goto out_free_mboxq; |
| 5054 | } |
| 5055 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5056 | case LPFC_LINK_NUMBER_0: |
| 5057 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5058 | &get_port_name->u.response); |
| 5059 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5060 | break; |
| 5061 | case LPFC_LINK_NUMBER_1: |
| 5062 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5063 | &get_port_name->u.response); |
| 5064 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5065 | break; |
| 5066 | case LPFC_LINK_NUMBER_2: |
| 5067 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5068 | &get_port_name->u.response); |
| 5069 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5070 | break; |
| 5071 | case LPFC_LINK_NUMBER_3: |
| 5072 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5073 | &get_port_name->u.response); |
| 5074 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5075 | break; |
| 5076 | default: |
| 5077 | break; |
| 5078 | } |
| 5079 | |
| 5080 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5081 | phba->Port[0] = cport_name; |
| 5082 | phba->Port[1] = '\0'; |
| 5083 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5084 | "3091 SLI get port name: %s\n", phba->Port); |
| 5085 | } |
| 5086 | |
| 5087 | out_free_mboxq: |
| 5088 | if (rc != MBX_TIMEOUT) { |
| 5089 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5090 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5091 | else |
| 5092 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5093 | } |
| 5094 | return rc; |
| 5095 | } |
| 5096 | |
| 5097 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5098 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5099 | * @phba: pointer to lpfc hba data structure. |
| 5100 | * |
| 5101 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5102 | * event queues |
| 5103 | **/ |
| 5104 | static void |
| 5105 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5106 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 5107 | int fcp_eqidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5108 | |
| 5109 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5110 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5111 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5112 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5113 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5114 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 5115 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5116 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5117 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5118 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5119 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5120 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5121 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5122 | if (phba->sli4_hba.hba_eq) { |
| 5123 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5124 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5125 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5126 | LPFC_QUEUE_REARM); |
| 5127 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5128 | |
| 5129 | if (phba->cfg_fof) |
| 5130 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5134 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5135 | * @phba: Pointer to HBA context object. |
| 5136 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5137 | * @extnt_count: buffer to hold port available extent count. |
| 5138 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5139 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5140 | * This function calls the port and retrievs the number of available |
| 5141 | * extents and their size for a particular extent type. |
| 5142 | * |
| 5143 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5144 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5145 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5146 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5147 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5148 | { |
| 5149 | int rc = 0; |
| 5150 | uint32_t length; |
| 5151 | uint32_t mbox_tmo; |
| 5152 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5153 | LPFC_MBOXQ_t *mbox; |
| 5154 | |
| 5155 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5156 | if (!mbox) |
| 5157 | return -ENOMEM; |
| 5158 | |
| 5159 | /* Find out how many extents are available for this resource type */ |
| 5160 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5161 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5162 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5163 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5164 | length, LPFC_SLI4_MBX_EMBED); |
| 5165 | |
| 5166 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5167 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5168 | LPFC_SLI4_MBX_EMBED); |
| 5169 | if (unlikely(rc)) { |
| 5170 | rc = -EIO; |
| 5171 | goto err_exit; |
| 5172 | } |
| 5173 | |
| 5174 | if (!phba->sli4_hba.intr_enable) |
| 5175 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5176 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5177 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5178 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5179 | } |
| 5180 | if (unlikely(rc)) { |
| 5181 | rc = -EIO; |
| 5182 | goto err_exit; |
| 5183 | } |
| 5184 | |
| 5185 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5186 | if (bf_get(lpfc_mbox_hdr_status, |
| 5187 | &rsrc_info->header.cfg_shdr.response)) { |
| 5188 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5189 | "2930 Failed to get resource extents " |
| 5190 | "Status 0x%x Add'l Status 0x%x\n", |
| 5191 | bf_get(lpfc_mbox_hdr_status, |
| 5192 | &rsrc_info->header.cfg_shdr.response), |
| 5193 | bf_get(lpfc_mbox_hdr_add_status, |
| 5194 | &rsrc_info->header.cfg_shdr.response)); |
| 5195 | rc = -EIO; |
| 5196 | goto err_exit; |
| 5197 | } |
| 5198 | |
| 5199 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5200 | &rsrc_info->u.rsp); |
| 5201 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5202 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5203 | |
| 5204 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5205 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5206 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5207 | |
| 5208 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5209 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5210 | return rc; |
| 5211 | } |
| 5212 | |
| 5213 | /** |
| 5214 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5215 | * @phba: Pointer to HBA context object. |
| 5216 | * @type: The extent type to check. |
| 5217 | * |
| 5218 | * This function reads the current available extents from the port and checks |
| 5219 | * if the extent count or extent size has changed since the last access. |
| 5220 | * Callers use this routine post port reset to understand if there is a |
| 5221 | * extent reprovisioning requirement. |
| 5222 | * |
| 5223 | * Returns: |
| 5224 | * -Error: error indicates problem. |
| 5225 | * 1: Extent count or size has changed. |
| 5226 | * 0: No changes. |
| 5227 | **/ |
| 5228 | static int |
| 5229 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5230 | { |
| 5231 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5232 | uint16_t size_diff, rsrc_ext_size; |
| 5233 | int rc = 0; |
| 5234 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5235 | struct list_head *rsrc_blk_list = NULL; |
| 5236 | |
| 5237 | size_diff = 0; |
| 5238 | curr_ext_cnt = 0; |
| 5239 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5240 | &rsrc_ext_cnt, |
| 5241 | &rsrc_ext_size); |
| 5242 | if (unlikely(rc)) |
| 5243 | return -EIO; |
| 5244 | |
| 5245 | switch (type) { |
| 5246 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5247 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5248 | break; |
| 5249 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5250 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5251 | break; |
| 5252 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5253 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5254 | break; |
| 5255 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5256 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5257 | break; |
| 5258 | default: |
| 5259 | break; |
| 5260 | } |
| 5261 | |
| 5262 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5263 | curr_ext_cnt++; |
| 5264 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5265 | size_diff++; |
| 5266 | } |
| 5267 | |
| 5268 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5269 | rc = 1; |
| 5270 | |
| 5271 | return rc; |
| 5272 | } |
| 5273 | |
| 5274 | /** |
| 5275 | * lpfc_sli4_cfg_post_extnts - |
| 5276 | * @phba: Pointer to HBA context object. |
| 5277 | * @extnt_cnt - number of available extents. |
| 5278 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5279 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5280 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5281 | * |
| 5282 | * This function executes the extents allocation request. It also |
| 5283 | * takes care of the amount of memory needed to allocate or get the |
| 5284 | * allocated extents. It is the caller's responsibility to evaluate |
| 5285 | * the response. |
| 5286 | * |
| 5287 | * Returns: |
| 5288 | * -Error: Error value describes the condition found. |
| 5289 | * 0: if successful |
| 5290 | **/ |
| 5291 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5292 | 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] | 5293 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5294 | { |
| 5295 | int rc = 0; |
| 5296 | uint32_t req_len; |
| 5297 | uint32_t emb_len; |
| 5298 | uint32_t alloc_len, mbox_tmo; |
| 5299 | |
| 5300 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5301 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5302 | |
| 5303 | /* |
| 5304 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5305 | * accounts for extents-specific word. |
| 5306 | */ |
| 5307 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5308 | sizeof(uint32_t); |
| 5309 | |
| 5310 | /* |
| 5311 | * Presume the allocation and response will fit into an embedded |
| 5312 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5313 | */ |
| 5314 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5315 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5316 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5317 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5318 | sizeof(uint32_t); |
| 5319 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5320 | } |
| 5321 | |
| 5322 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5323 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5324 | req_len, *emb); |
| 5325 | if (alloc_len < req_len) { |
| 5326 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5327 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5328 | "less than the requested DMA memory " |
| 5329 | "size (x%x)\n", alloc_len, req_len); |
| 5330 | return -ENOMEM; |
| 5331 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5332 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5333 | if (unlikely(rc)) |
| 5334 | return -EIO; |
| 5335 | |
| 5336 | if (!phba->sli4_hba.intr_enable) |
| 5337 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5338 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5339 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5340 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5341 | } |
| 5342 | |
| 5343 | if (unlikely(rc)) |
| 5344 | rc = -EIO; |
| 5345 | return rc; |
| 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5350 | * @phba: Pointer to HBA context object. |
| 5351 | * @type: The resource extent type to allocate. |
| 5352 | * |
| 5353 | * This function allocates the number of elements for the specified |
| 5354 | * resource type. |
| 5355 | **/ |
| 5356 | static int |
| 5357 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5358 | { |
| 5359 | bool emb = false; |
| 5360 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5361 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5362 | uint16_t *ids; |
| 5363 | int i, rc; |
| 5364 | unsigned long longs; |
| 5365 | unsigned long *bmask; |
| 5366 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5367 | LPFC_MBOXQ_t *mbox; |
| 5368 | uint32_t length; |
| 5369 | struct lpfc_id_range *id_array = NULL; |
| 5370 | void *virtaddr = NULL; |
| 5371 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5372 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5373 | struct list_head *ext_blk_list; |
| 5374 | |
| 5375 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5376 | &rsrc_cnt, |
| 5377 | &rsrc_size); |
| 5378 | if (unlikely(rc)) |
| 5379 | return -EIO; |
| 5380 | |
| 5381 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5382 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5383 | "3009 No available Resource Extents " |
| 5384 | "for resource type 0x%x: Count: 0x%x, " |
| 5385 | "Size 0x%x\n", type, rsrc_cnt, |
| 5386 | rsrc_size); |
| 5387 | return -ENOMEM; |
| 5388 | } |
| 5389 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5390 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5391 | "2903 Post resource extents type-0x%x: " |
| 5392 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5393 | |
| 5394 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5395 | if (!mbox) |
| 5396 | return -ENOMEM; |
| 5397 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5398 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5399 | if (unlikely(rc)) { |
| 5400 | rc = -EIO; |
| 5401 | goto err_exit; |
| 5402 | } |
| 5403 | |
| 5404 | /* |
| 5405 | * Figure out where the response is located. Then get local pointers |
| 5406 | * to the response data. The port does not guarantee to respond to |
| 5407 | * all extents counts request so update the local variable with the |
| 5408 | * allocated count from the port. |
| 5409 | */ |
| 5410 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5411 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5412 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5413 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5414 | } else { |
| 5415 | virtaddr = mbox->sge_array->addr[0]; |
| 5416 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5417 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5418 | id_array = &n_rsrc->id; |
| 5419 | } |
| 5420 | |
| 5421 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5422 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5423 | |
| 5424 | /* |
| 5425 | * Based on the resource size and count, correct the base and max |
| 5426 | * resource values. |
| 5427 | */ |
| 5428 | length = sizeof(struct lpfc_rsrc_blks); |
| 5429 | switch (type) { |
| 5430 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5431 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5432 | sizeof(unsigned long), |
| 5433 | GFP_KERNEL); |
| 5434 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5435 | rc = -ENOMEM; |
| 5436 | goto err_exit; |
| 5437 | } |
| 5438 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5439 | sizeof(uint16_t), |
| 5440 | GFP_KERNEL); |
| 5441 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5442 | kfree(phba->sli4_hba.rpi_bmask); |
| 5443 | rc = -ENOMEM; |
| 5444 | goto err_exit; |
| 5445 | } |
| 5446 | |
| 5447 | /* |
| 5448 | * The next_rpi was initialized with the maximum available |
| 5449 | * count but the port may allocate a smaller number. Catch |
| 5450 | * that case and update the next_rpi. |
| 5451 | */ |
| 5452 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5453 | |
| 5454 | /* Initialize local ptrs for common extent processing later. */ |
| 5455 | bmask = phba->sli4_hba.rpi_bmask; |
| 5456 | ids = phba->sli4_hba.rpi_ids; |
| 5457 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5458 | break; |
| 5459 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5460 | phba->vpi_bmask = kzalloc(longs * |
| 5461 | sizeof(unsigned long), |
| 5462 | GFP_KERNEL); |
| 5463 | if (unlikely(!phba->vpi_bmask)) { |
| 5464 | rc = -ENOMEM; |
| 5465 | goto err_exit; |
| 5466 | } |
| 5467 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5468 | sizeof(uint16_t), |
| 5469 | GFP_KERNEL); |
| 5470 | if (unlikely(!phba->vpi_ids)) { |
| 5471 | kfree(phba->vpi_bmask); |
| 5472 | rc = -ENOMEM; |
| 5473 | goto err_exit; |
| 5474 | } |
| 5475 | |
| 5476 | /* Initialize local ptrs for common extent processing later. */ |
| 5477 | bmask = phba->vpi_bmask; |
| 5478 | ids = phba->vpi_ids; |
| 5479 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5480 | break; |
| 5481 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5482 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5483 | sizeof(unsigned long), |
| 5484 | GFP_KERNEL); |
| 5485 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5486 | rc = -ENOMEM; |
| 5487 | goto err_exit; |
| 5488 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5489 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5490 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5491 | sizeof(uint16_t), |
| 5492 | GFP_KERNEL); |
| 5493 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5494 | kfree(phba->sli4_hba.xri_bmask); |
| 5495 | rc = -ENOMEM; |
| 5496 | goto err_exit; |
| 5497 | } |
| 5498 | |
| 5499 | /* Initialize local ptrs for common extent processing later. */ |
| 5500 | bmask = phba->sli4_hba.xri_bmask; |
| 5501 | ids = phba->sli4_hba.xri_ids; |
| 5502 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5503 | break; |
| 5504 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5505 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5506 | sizeof(unsigned long), |
| 5507 | GFP_KERNEL); |
| 5508 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5509 | rc = -ENOMEM; |
| 5510 | goto err_exit; |
| 5511 | } |
| 5512 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5513 | sizeof(uint16_t), |
| 5514 | GFP_KERNEL); |
| 5515 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5516 | kfree(phba->sli4_hba.vfi_bmask); |
| 5517 | rc = -ENOMEM; |
| 5518 | goto err_exit; |
| 5519 | } |
| 5520 | |
| 5521 | /* Initialize local ptrs for common extent processing later. */ |
| 5522 | bmask = phba->sli4_hba.vfi_bmask; |
| 5523 | ids = phba->sli4_hba.vfi_ids; |
| 5524 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5525 | break; |
| 5526 | default: |
| 5527 | /* Unsupported Opcode. Fail call. */ |
| 5528 | id_array = NULL; |
| 5529 | bmask = NULL; |
| 5530 | ids = NULL; |
| 5531 | ext_blk_list = NULL; |
| 5532 | goto err_exit; |
| 5533 | } |
| 5534 | |
| 5535 | /* |
| 5536 | * Complete initializing the extent configuration with the |
| 5537 | * allocated ids assigned to this function. The bitmask serves |
| 5538 | * as an index into the array and manages the available ids. The |
| 5539 | * array just stores the ids communicated to the port via the wqes. |
| 5540 | */ |
| 5541 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5542 | if ((i % 2) == 0) |
| 5543 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5544 | &id_array[k]); |
| 5545 | else |
| 5546 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5547 | &id_array[k]); |
| 5548 | |
| 5549 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5550 | if (unlikely(!rsrc_blks)) { |
| 5551 | rc = -ENOMEM; |
| 5552 | kfree(bmask); |
| 5553 | kfree(ids); |
| 5554 | goto err_exit; |
| 5555 | } |
| 5556 | rsrc_blks->rsrc_start = rsrc_id; |
| 5557 | rsrc_blks->rsrc_size = rsrc_size; |
| 5558 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5559 | rsrc_start = rsrc_id; |
| 5560 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5561 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5562 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5563 | |
| 5564 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5565 | ids[j] = rsrc_id; |
| 5566 | rsrc_id++; |
| 5567 | j++; |
| 5568 | } |
| 5569 | /* Entire word processed. Get next word.*/ |
| 5570 | if ((i % 2) == 1) |
| 5571 | k++; |
| 5572 | } |
| 5573 | err_exit: |
| 5574 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5575 | return rc; |
| 5576 | } |
| 5577 | |
| 5578 | /** |
| 5579 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5580 | * @phba: Pointer to HBA context object. |
| 5581 | * @type: the extent's type. |
| 5582 | * |
| 5583 | * This function deallocates all extents of a particular resource type. |
| 5584 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5585 | * is the caller's responsibility to release all kernel memory resources. |
| 5586 | **/ |
| 5587 | static int |
| 5588 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5589 | { |
| 5590 | int rc; |
| 5591 | uint32_t length, mbox_tmo = 0; |
| 5592 | LPFC_MBOXQ_t *mbox; |
| 5593 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5594 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5595 | |
| 5596 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5597 | if (!mbox) |
| 5598 | return -ENOMEM; |
| 5599 | |
| 5600 | /* |
| 5601 | * This function sends an embedded mailbox because it only sends the |
| 5602 | * the resource type. All extents of this type are released by the |
| 5603 | * port. |
| 5604 | */ |
| 5605 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5606 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5607 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5608 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5609 | length, LPFC_SLI4_MBX_EMBED); |
| 5610 | |
| 5611 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5612 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5613 | LPFC_SLI4_MBX_EMBED); |
| 5614 | if (unlikely(rc)) { |
| 5615 | rc = -EIO; |
| 5616 | goto out_free_mbox; |
| 5617 | } |
| 5618 | if (!phba->sli4_hba.intr_enable) |
| 5619 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5620 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5621 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5622 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5623 | } |
| 5624 | if (unlikely(rc)) { |
| 5625 | rc = -EIO; |
| 5626 | goto out_free_mbox; |
| 5627 | } |
| 5628 | |
| 5629 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5630 | if (bf_get(lpfc_mbox_hdr_status, |
| 5631 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5632 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5633 | "2919 Failed to release resource extents " |
| 5634 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5635 | "Resource memory not released.\n", |
| 5636 | type, |
| 5637 | bf_get(lpfc_mbox_hdr_status, |
| 5638 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5639 | bf_get(lpfc_mbox_hdr_add_status, |
| 5640 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5641 | rc = -EIO; |
| 5642 | goto out_free_mbox; |
| 5643 | } |
| 5644 | |
| 5645 | /* Release kernel memory resources for the specific type. */ |
| 5646 | switch (type) { |
| 5647 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5648 | kfree(phba->vpi_bmask); |
| 5649 | kfree(phba->vpi_ids); |
| 5650 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5651 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5652 | &phba->lpfc_vpi_blk_list, list) { |
| 5653 | list_del_init(&rsrc_blk->list); |
| 5654 | kfree(rsrc_blk); |
| 5655 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5656 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5657 | break; |
| 5658 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5659 | kfree(phba->sli4_hba.xri_bmask); |
| 5660 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5661 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5662 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5663 | list_del_init(&rsrc_blk->list); |
| 5664 | kfree(rsrc_blk); |
| 5665 | } |
| 5666 | break; |
| 5667 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5668 | kfree(phba->sli4_hba.vfi_bmask); |
| 5669 | kfree(phba->sli4_hba.vfi_ids); |
| 5670 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5671 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5672 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5673 | list_del_init(&rsrc_blk->list); |
| 5674 | kfree(rsrc_blk); |
| 5675 | } |
| 5676 | break; |
| 5677 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5678 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5679 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5680 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5681 | list_del_init(&rsrc_blk->list); |
| 5682 | kfree(rsrc_blk); |
| 5683 | } |
| 5684 | break; |
| 5685 | default: |
| 5686 | break; |
| 5687 | } |
| 5688 | |
| 5689 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5690 | |
| 5691 | out_free_mbox: |
| 5692 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5693 | return rc; |
| 5694 | } |
| 5695 | |
| 5696 | /** |
| 5697 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5698 | * @phba: Pointer to HBA context object. |
| 5699 | * |
| 5700 | * This function allocates all SLI4 resource identifiers. |
| 5701 | **/ |
| 5702 | int |
| 5703 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5704 | { |
| 5705 | int i, rc, error = 0; |
| 5706 | uint16_t count, base; |
| 5707 | unsigned long longs; |
| 5708 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5709 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5710 | 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] | 5711 | if (phba->sli4_hba.extents_in_use) { |
| 5712 | /* |
| 5713 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5714 | * resource extent count must be read and allocated before |
| 5715 | * provisioning the resource id arrays. |
| 5716 | */ |
| 5717 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5718 | LPFC_IDX_RSRC_RDY) { |
| 5719 | /* |
| 5720 | * Extent-based resources are set - the driver could |
| 5721 | * be in a port reset. Figure out if any corrective |
| 5722 | * actions need to be taken. |
| 5723 | */ |
| 5724 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5725 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5726 | if (rc != 0) |
| 5727 | error++; |
| 5728 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5729 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5730 | if (rc != 0) |
| 5731 | error++; |
| 5732 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5733 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5734 | if (rc != 0) |
| 5735 | error++; |
| 5736 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5737 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5738 | if (rc != 0) |
| 5739 | error++; |
| 5740 | |
| 5741 | /* |
| 5742 | * It's possible that the number of resources |
| 5743 | * provided to this port instance changed between |
| 5744 | * resets. Detect this condition and reallocate |
| 5745 | * resources. Otherwise, there is no action. |
| 5746 | */ |
| 5747 | if (error) { |
| 5748 | lpfc_printf_log(phba, KERN_INFO, |
| 5749 | LOG_MBOX | LOG_INIT, |
| 5750 | "2931 Detected extent resource " |
| 5751 | "change. Reallocating all " |
| 5752 | "extents.\n"); |
| 5753 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5754 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5755 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5756 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5757 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5758 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5759 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5760 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5761 | } else |
| 5762 | return 0; |
| 5763 | } |
| 5764 | |
| 5765 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5766 | if (unlikely(rc)) |
| 5767 | goto err_exit; |
| 5768 | |
| 5769 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5770 | if (unlikely(rc)) |
| 5771 | goto err_exit; |
| 5772 | |
| 5773 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5774 | if (unlikely(rc)) |
| 5775 | goto err_exit; |
| 5776 | |
| 5777 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5778 | if (unlikely(rc)) |
| 5779 | goto err_exit; |
| 5780 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5781 | LPFC_IDX_RSRC_RDY); |
| 5782 | return rc; |
| 5783 | } else { |
| 5784 | /* |
| 5785 | * The port does not support resource extents. The XRI, VPI, |
| 5786 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5787 | * Just allocate the bitmasks and provision the resource id |
| 5788 | * arrays. If a port reset is active, the resources don't |
| 5789 | * need any action - just exit. |
| 5790 | */ |
| 5791 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5792 | LPFC_IDX_RSRC_RDY) { |
| 5793 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5794 | lpfc_sli4_remove_rpis(phba); |
| 5795 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5796 | /* RPIs. */ |
| 5797 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5798 | if (count <= 0) { |
| 5799 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5800 | "3279 Invalid provisioning of " |
| 5801 | "rpi:%d\n", count); |
| 5802 | rc = -EINVAL; |
| 5803 | goto err_exit; |
| 5804 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5805 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5806 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5807 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5808 | sizeof(unsigned long), |
| 5809 | GFP_KERNEL); |
| 5810 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5811 | rc = -ENOMEM; |
| 5812 | goto err_exit; |
| 5813 | } |
| 5814 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5815 | sizeof(uint16_t), |
| 5816 | GFP_KERNEL); |
| 5817 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5818 | rc = -ENOMEM; |
| 5819 | goto free_rpi_bmask; |
| 5820 | } |
| 5821 | |
| 5822 | for (i = 0; i < count; i++) |
| 5823 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5824 | |
| 5825 | /* VPIs. */ |
| 5826 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5827 | if (count <= 0) { |
| 5828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5829 | "3280 Invalid provisioning of " |
| 5830 | "vpi:%d\n", count); |
| 5831 | rc = -EINVAL; |
| 5832 | goto free_rpi_ids; |
| 5833 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5834 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5835 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5836 | phba->vpi_bmask = kzalloc(longs * |
| 5837 | sizeof(unsigned long), |
| 5838 | GFP_KERNEL); |
| 5839 | if (unlikely(!phba->vpi_bmask)) { |
| 5840 | rc = -ENOMEM; |
| 5841 | goto free_rpi_ids; |
| 5842 | } |
| 5843 | phba->vpi_ids = kzalloc(count * |
| 5844 | sizeof(uint16_t), |
| 5845 | GFP_KERNEL); |
| 5846 | if (unlikely(!phba->vpi_ids)) { |
| 5847 | rc = -ENOMEM; |
| 5848 | goto free_vpi_bmask; |
| 5849 | } |
| 5850 | |
| 5851 | for (i = 0; i < count; i++) |
| 5852 | phba->vpi_ids[i] = base + i; |
| 5853 | |
| 5854 | /* XRIs. */ |
| 5855 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5856 | if (count <= 0) { |
| 5857 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5858 | "3281 Invalid provisioning of " |
| 5859 | "xri:%d\n", count); |
| 5860 | rc = -EINVAL; |
| 5861 | goto free_vpi_ids; |
| 5862 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5863 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5864 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5865 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5866 | sizeof(unsigned long), |
| 5867 | GFP_KERNEL); |
| 5868 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5869 | rc = -ENOMEM; |
| 5870 | goto free_vpi_ids; |
| 5871 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5872 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5873 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5874 | sizeof(uint16_t), |
| 5875 | GFP_KERNEL); |
| 5876 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5877 | rc = -ENOMEM; |
| 5878 | goto free_xri_bmask; |
| 5879 | } |
| 5880 | |
| 5881 | for (i = 0; i < count; i++) |
| 5882 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5883 | |
| 5884 | /* VFIs. */ |
| 5885 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5886 | if (count <= 0) { |
| 5887 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5888 | "3282 Invalid provisioning of " |
| 5889 | "vfi:%d\n", count); |
| 5890 | rc = -EINVAL; |
| 5891 | goto free_xri_ids; |
| 5892 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5893 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5894 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5895 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5896 | sizeof(unsigned long), |
| 5897 | GFP_KERNEL); |
| 5898 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5899 | rc = -ENOMEM; |
| 5900 | goto free_xri_ids; |
| 5901 | } |
| 5902 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5903 | sizeof(uint16_t), |
| 5904 | GFP_KERNEL); |
| 5905 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5906 | rc = -ENOMEM; |
| 5907 | goto free_vfi_bmask; |
| 5908 | } |
| 5909 | |
| 5910 | for (i = 0; i < count; i++) |
| 5911 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5912 | |
| 5913 | /* |
| 5914 | * Mark all resources ready. An HBA reset doesn't need |
| 5915 | * to reset the initialization. |
| 5916 | */ |
| 5917 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5918 | LPFC_IDX_RSRC_RDY); |
| 5919 | return 0; |
| 5920 | } |
| 5921 | |
| 5922 | free_vfi_bmask: |
| 5923 | kfree(phba->sli4_hba.vfi_bmask); |
| 5924 | free_xri_ids: |
| 5925 | kfree(phba->sli4_hba.xri_ids); |
| 5926 | free_xri_bmask: |
| 5927 | kfree(phba->sli4_hba.xri_bmask); |
| 5928 | free_vpi_ids: |
| 5929 | kfree(phba->vpi_ids); |
| 5930 | free_vpi_bmask: |
| 5931 | kfree(phba->vpi_bmask); |
| 5932 | free_rpi_ids: |
| 5933 | kfree(phba->sli4_hba.rpi_ids); |
| 5934 | free_rpi_bmask: |
| 5935 | kfree(phba->sli4_hba.rpi_bmask); |
| 5936 | err_exit: |
| 5937 | return rc; |
| 5938 | } |
| 5939 | |
| 5940 | /** |
| 5941 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5942 | * @phba: Pointer to HBA context object. |
| 5943 | * |
| 5944 | * This function allocates the number of elements for the specified |
| 5945 | * resource type. |
| 5946 | **/ |
| 5947 | int |
| 5948 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5949 | { |
| 5950 | if (phba->sli4_hba.extents_in_use) { |
| 5951 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5952 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5953 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5954 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5955 | } else { |
| 5956 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5957 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5958 | kfree(phba->vpi_ids); |
| 5959 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5960 | kfree(phba->sli4_hba.xri_bmask); |
| 5961 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5962 | kfree(phba->sli4_hba.vfi_bmask); |
| 5963 | kfree(phba->sli4_hba.vfi_ids); |
| 5964 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5965 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5966 | } |
| 5967 | |
| 5968 | return 0; |
| 5969 | } |
| 5970 | |
| 5971 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5972 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5973 | * @phba: Pointer to HBA context object. |
| 5974 | * @type: The resource extent type. |
| 5975 | * @extnt_count: buffer to hold port extent count response |
| 5976 | * @extnt_size: buffer to hold port extent size response. |
| 5977 | * |
| 5978 | * This function calls the port to read the host allocated extents |
| 5979 | * for a particular type. |
| 5980 | **/ |
| 5981 | int |
| 5982 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5983 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5984 | { |
| 5985 | bool emb; |
| 5986 | int rc = 0; |
| 5987 | uint16_t curr_blks = 0; |
| 5988 | uint32_t req_len, emb_len; |
| 5989 | uint32_t alloc_len, mbox_tmo; |
| 5990 | struct list_head *blk_list_head; |
| 5991 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5992 | LPFC_MBOXQ_t *mbox; |
| 5993 | void *virtaddr = NULL; |
| 5994 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5995 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5996 | union lpfc_sli4_cfg_shdr *shdr; |
| 5997 | |
| 5998 | switch (type) { |
| 5999 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6000 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6001 | break; |
| 6002 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6003 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6004 | break; |
| 6005 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6006 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6007 | break; |
| 6008 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6009 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6010 | break; |
| 6011 | default: |
| 6012 | return -EIO; |
| 6013 | } |
| 6014 | |
| 6015 | /* Count the number of extents currently allocatd for this type. */ |
| 6016 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6017 | if (curr_blks == 0) { |
| 6018 | /* |
| 6019 | * The GET_ALLOCATED mailbox does not return the size, |
| 6020 | * just the count. The size should be just the size |
| 6021 | * stored in the current allocated block and all sizes |
| 6022 | * for an extent type are the same so set the return |
| 6023 | * value now. |
| 6024 | */ |
| 6025 | *extnt_size = rsrc_blk->rsrc_size; |
| 6026 | } |
| 6027 | curr_blks++; |
| 6028 | } |
| 6029 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6030 | /* |
| 6031 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6032 | * accounts for extents-specific word. |
| 6033 | */ |
| 6034 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6035 | sizeof(uint32_t); |
| 6036 | |
| 6037 | /* |
| 6038 | * Presume the allocation and response will fit into an embedded |
| 6039 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6040 | */ |
| 6041 | emb = LPFC_SLI4_MBX_EMBED; |
| 6042 | req_len = emb_len; |
| 6043 | if (req_len > emb_len) { |
| 6044 | req_len = curr_blks * sizeof(uint16_t) + |
| 6045 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6046 | sizeof(uint32_t); |
| 6047 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6048 | } |
| 6049 | |
| 6050 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6051 | if (!mbox) |
| 6052 | return -ENOMEM; |
| 6053 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6054 | |
| 6055 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6056 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6057 | req_len, emb); |
| 6058 | if (alloc_len < req_len) { |
| 6059 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6060 | "2983 Allocated DMA memory size (x%x) is " |
| 6061 | "less than the requested DMA memory " |
| 6062 | "size (x%x)\n", alloc_len, req_len); |
| 6063 | rc = -ENOMEM; |
| 6064 | goto err_exit; |
| 6065 | } |
| 6066 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6067 | if (unlikely(rc)) { |
| 6068 | rc = -EIO; |
| 6069 | goto err_exit; |
| 6070 | } |
| 6071 | |
| 6072 | if (!phba->sli4_hba.intr_enable) |
| 6073 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6074 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6075 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6076 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6077 | } |
| 6078 | |
| 6079 | if (unlikely(rc)) { |
| 6080 | rc = -EIO; |
| 6081 | goto err_exit; |
| 6082 | } |
| 6083 | |
| 6084 | /* |
| 6085 | * Figure out where the response is located. Then get local pointers |
| 6086 | * to the response data. The port does not guarantee to respond to |
| 6087 | * all extents counts request so update the local variable with the |
| 6088 | * allocated count from the port. |
| 6089 | */ |
| 6090 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6091 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6092 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6093 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6094 | } else { |
| 6095 | virtaddr = mbox->sge_array->addr[0]; |
| 6096 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6097 | shdr = &n_rsrc->cfg_shdr; |
| 6098 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6099 | } |
| 6100 | |
| 6101 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6102 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6103 | "2984 Failed to read allocated resources " |
| 6104 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6105 | type, |
| 6106 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6107 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6108 | rc = -EIO; |
| 6109 | goto err_exit; |
| 6110 | } |
| 6111 | err_exit: |
| 6112 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6113 | return rc; |
| 6114 | } |
| 6115 | |
| 6116 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6117 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 6118 | * @phba: pointer to lpfc hba data structure. |
| 6119 | * |
| 6120 | * This routine walks the list of els buffers that have been allocated and |
| 6121 | * repost them to the port by using SGL block post. This is needed after a |
| 6122 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 6123 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 6124 | * SGL block post mailbox commands to post them to the port. For single els |
| 6125 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6126 | * mailbox command for posting. |
| 6127 | * |
| 6128 | * Returns: 0 = success, non-zero failure. |
| 6129 | **/ |
| 6130 | static int |
| 6131 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 6132 | { |
| 6133 | struct lpfc_sglq *sglq_entry = NULL; |
| 6134 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6135 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6136 | int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6137 | int last_xritag = NO_XRI; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6138 | struct lpfc_sli_ring *pring; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6139 | LIST_HEAD(prep_sgl_list); |
| 6140 | LIST_HEAD(blck_sgl_list); |
| 6141 | LIST_HEAD(allc_sgl_list); |
| 6142 | LIST_HEAD(post_sgl_list); |
| 6143 | LIST_HEAD(free_sgl_list); |
| 6144 | |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6145 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6146 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6147 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6148 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6149 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6150 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6151 | |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6152 | total_cnt = phba->sli4_hba.els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6153 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6154 | &allc_sgl_list, list) { |
| 6155 | list_del_init(&sglq_entry->list); |
| 6156 | block_cnt++; |
| 6157 | if ((last_xritag != NO_XRI) && |
| 6158 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6159 | /* a hole in xri block, form a sgl posting block */ |
| 6160 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6161 | post_cnt = block_cnt - 1; |
| 6162 | /* prepare list for next posting block */ |
| 6163 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6164 | block_cnt = 1; |
| 6165 | } else { |
| 6166 | /* prepare list for next posting block */ |
| 6167 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6168 | /* enough sgls for non-embed sgl mbox command */ |
| 6169 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6170 | list_splice_init(&prep_sgl_list, |
| 6171 | &blck_sgl_list); |
| 6172 | post_cnt = block_cnt; |
| 6173 | block_cnt = 0; |
| 6174 | } |
| 6175 | } |
| 6176 | num_posted++; |
| 6177 | |
| 6178 | /* keep track of last sgl's xritag */ |
| 6179 | last_xritag = sglq_entry->sli4_xritag; |
| 6180 | |
| 6181 | /* end of repost sgl list condition for els buffers */ |
| 6182 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 6183 | if (post_cnt == 0) { |
| 6184 | list_splice_init(&prep_sgl_list, |
| 6185 | &blck_sgl_list); |
| 6186 | post_cnt = block_cnt; |
| 6187 | } else if (block_cnt == 1) { |
| 6188 | status = lpfc_sli4_post_sgl(phba, |
| 6189 | sglq_entry->phys, 0, |
| 6190 | sglq_entry->sli4_xritag); |
| 6191 | if (!status) { |
| 6192 | /* successful, put sgl to posted list */ |
| 6193 | list_add_tail(&sglq_entry->list, |
| 6194 | &post_sgl_list); |
| 6195 | } else { |
| 6196 | /* Failure, put sgl to free list */ |
| 6197 | lpfc_printf_log(phba, KERN_WARNING, |
| 6198 | LOG_SLI, |
| 6199 | "3159 Failed to post els " |
| 6200 | "sgl, xritag:x%x\n", |
| 6201 | sglq_entry->sli4_xritag); |
| 6202 | list_add_tail(&sglq_entry->list, |
| 6203 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6204 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6205 | } |
| 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | /* continue until a nembed page worth of sgls */ |
| 6210 | if (post_cnt == 0) |
| 6211 | continue; |
| 6212 | |
| 6213 | /* post the els buffer list sgls as a block */ |
| 6214 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6215 | post_cnt); |
| 6216 | |
| 6217 | if (!status) { |
| 6218 | /* success, put sgl list to posted sgl list */ |
| 6219 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6220 | } else { |
| 6221 | /* Failure, put sgl list to free sgl list */ |
| 6222 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6223 | struct lpfc_sglq, |
| 6224 | list); |
| 6225 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6226 | "3160 Failed to post els sgl-list, " |
| 6227 | "xritag:x%x-x%x\n", |
| 6228 | sglq_entry_first->sli4_xritag, |
| 6229 | (sglq_entry_first->sli4_xritag + |
| 6230 | post_cnt - 1)); |
| 6231 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6232 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | /* don't reset xirtag due to hole in xri block */ |
| 6236 | if (block_cnt == 0) |
| 6237 | last_xritag = NO_XRI; |
| 6238 | |
| 6239 | /* reset els sgl post count for next round of posting */ |
| 6240 | post_cnt = 0; |
| 6241 | } |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6242 | /* update the number of XRIs posted for ELS */ |
| 6243 | phba->sli4_hba.els_xri_cnt = total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6244 | |
| 6245 | /* free the els sgls failed to post */ |
| 6246 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6247 | |
| 6248 | /* push els sgls posted to the availble list */ |
| 6249 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6250 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6251 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6252 | list_splice_init(&post_sgl_list, |
| 6253 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6254 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6255 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6256 | } else { |
| 6257 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6258 | "3161 Failure to post els sgl to port.\n"); |
| 6259 | return -EIO; |
| 6260 | } |
| 6261 | return 0; |
| 6262 | } |
| 6263 | |
| 6264 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6265 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6266 | * @phba: Pointer to HBA context object. |
| 6267 | * |
| 6268 | * This function is the main SLI4 device intialization PCI function. This |
| 6269 | * function is called by the HBA intialization code, HBA reset code and |
| 6270 | * HBA error attention handler code. Caller is not required to hold any |
| 6271 | * locks. |
| 6272 | **/ |
| 6273 | int |
| 6274 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6275 | { |
| 6276 | int rc; |
| 6277 | LPFC_MBOXQ_t *mboxq; |
| 6278 | struct lpfc_mqe *mqe; |
| 6279 | uint8_t *vpd; |
| 6280 | uint32_t vpd_size; |
| 6281 | uint32_t ftr_rsp = 0; |
| 6282 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6283 | struct lpfc_vport *vport = phba->pport; |
| 6284 | struct lpfc_dmabuf *mp; |
| 6285 | |
| 6286 | /* Perform a PCI function reset to start from clean */ |
| 6287 | rc = lpfc_pci_function_reset(phba); |
| 6288 | if (unlikely(rc)) |
| 6289 | return -ENODEV; |
| 6290 | |
| 6291 | /* Check the HBA Host Status Register for readyness */ |
| 6292 | rc = lpfc_sli4_post_status_check(phba); |
| 6293 | if (unlikely(rc)) |
| 6294 | return -ENODEV; |
| 6295 | else { |
| 6296 | spin_lock_irq(&phba->hbalock); |
| 6297 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6298 | spin_unlock_irq(&phba->hbalock); |
| 6299 | } |
| 6300 | |
| 6301 | /* |
| 6302 | * Allocate a single mailbox container for initializing the |
| 6303 | * port. |
| 6304 | */ |
| 6305 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6306 | if (!mboxq) |
| 6307 | return -ENOMEM; |
| 6308 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6309 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6310 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6311 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6312 | if (!vpd) { |
| 6313 | rc = -ENOMEM; |
| 6314 | goto out_free_mbox; |
| 6315 | } |
| 6316 | |
| 6317 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6318 | if (unlikely(rc)) { |
| 6319 | kfree(vpd); |
| 6320 | goto out_free_mbox; |
| 6321 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6322 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6323 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6324 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 6325 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6326 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 6327 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6328 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6329 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 6330 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6331 | |
| 6332 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6333 | LPFC_DCBX_CEE_MODE) |
| 6334 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6335 | else |
| 6336 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6337 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6338 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6339 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6340 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6341 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6342 | "0376 READ_REV Error. SLI Level %d " |
| 6343 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6344 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6345 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6346 | kfree(vpd); |
| 6347 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6348 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6349 | |
| 6350 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6351 | * Continue initialization with default values even if driver failed |
| 6352 | * to read FCoE param config regions, only read parameters if the |
| 6353 | * board is FCoE |
| 6354 | */ |
| 6355 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6356 | lpfc_sli4_read_fcoe_params(phba)) |
| 6357 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6358 | "2570 Failed to read FCoE parameters\n"); |
| 6359 | |
| 6360 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6361 | * Retrieve sli4 device physical port name, failure of doing it |
| 6362 | * is considered as non-fatal. |
| 6363 | */ |
| 6364 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6365 | if (!rc) |
| 6366 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6367 | "3080 Successful retrieving SLI4 device " |
| 6368 | "physical port name: %s.\n", phba->Port); |
| 6369 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6370 | /* |
| 6371 | * Evaluate the read rev and vpd data. Populate the driver |
| 6372 | * state with the results. If this routine fails, the failure |
| 6373 | * is not fatal as the driver will use generic values. |
| 6374 | */ |
| 6375 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6376 | if (unlikely(!rc)) { |
| 6377 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6378 | "0377 Error %d parsing vpd. " |
| 6379 | "Using defaults.\n", rc); |
| 6380 | rc = 0; |
| 6381 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6382 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6383 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6384 | /* Save information as VPD data */ |
| 6385 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6386 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6387 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6388 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6389 | &mqe->un.read_rev); |
| 6390 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6391 | &mqe->un.read_rev); |
| 6392 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6393 | &mqe->un.read_rev); |
| 6394 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6395 | &mqe->un.read_rev); |
| 6396 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6397 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6398 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6399 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6400 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6401 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6402 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6403 | "(%d):0380 READ_REV Status x%x " |
| 6404 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6405 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6406 | bf_get(lpfc_mqe_status, mqe), |
| 6407 | phba->vpd.rev.opFwName, |
| 6408 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6409 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6410 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6411 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6412 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6413 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6414 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6415 | "3362 LUN queue depth changed from %d to %d\n", |
| 6416 | phba->pport->cfg_lun_queue_depth, rc); |
| 6417 | phba->pport->cfg_lun_queue_depth = rc; |
| 6418 | } |
| 6419 | |
| 6420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6421 | /* |
| 6422 | * Discover the port's supported feature set and match it against the |
| 6423 | * hosts requests. |
| 6424 | */ |
| 6425 | lpfc_request_features(phba, mboxq); |
| 6426 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6427 | if (unlikely(rc)) { |
| 6428 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6429 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | /* |
| 6433 | * The port must support FCP initiator mode as this is the |
| 6434 | * only mode running in the host. |
| 6435 | */ |
| 6436 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6437 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6438 | "0378 No support for fcpi mode.\n"); |
| 6439 | ftr_rsp++; |
| 6440 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6441 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6442 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6443 | else |
| 6444 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6445 | /* |
| 6446 | * If the port cannot support the host's requested features |
| 6447 | * then turn off the global config parameters to disable the |
| 6448 | * feature in the driver. This is not a fatal error. |
| 6449 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6450 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6451 | if (phba->cfg_enable_bg) { |
| 6452 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6453 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6454 | else |
| 6455 | ftr_rsp++; |
| 6456 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6457 | |
| 6458 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6459 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6460 | ftr_rsp++; |
| 6461 | |
| 6462 | if (ftr_rsp) { |
| 6463 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6464 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6465 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6466 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6467 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6468 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6469 | phba->cfg_enable_bg = 0; |
| 6470 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6471 | phba->cfg_enable_npiv = 0; |
| 6472 | } |
| 6473 | |
| 6474 | /* These SLI3 features are assumed in SLI4 */ |
| 6475 | spin_lock_irq(&phba->hbalock); |
| 6476 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6477 | spin_unlock_irq(&phba->hbalock); |
| 6478 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6479 | /* |
| 6480 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6481 | * calls depends on these resources to complete port setup. |
| 6482 | */ |
| 6483 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6484 | if (rc) { |
| 6485 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6486 | "2920 Failed to alloc Resource IDs " |
| 6487 | "rc = x%x\n", rc); |
| 6488 | goto out_free_mbox; |
| 6489 | } |
| 6490 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6491 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6492 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6493 | if (rc) { |
| 6494 | phba->link_state = LPFC_HBA_ERROR; |
| 6495 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6496 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6497 | } |
| 6498 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6499 | mboxq->vport = vport; |
| 6500 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6501 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6502 | if (rc == MBX_SUCCESS) { |
| 6503 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6504 | rc = 0; |
| 6505 | } |
| 6506 | |
| 6507 | /* |
| 6508 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6509 | * it to the mbuf pool. |
| 6510 | */ |
| 6511 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6512 | kfree(mp); |
| 6513 | mboxq->context1 = NULL; |
| 6514 | if (unlikely(rc)) { |
| 6515 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6516 | "0382 READ_SPARAM command failed " |
| 6517 | "status %d, mbxStatus x%x\n", |
| 6518 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6519 | phba->link_state = LPFC_HBA_ERROR; |
| 6520 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6521 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6522 | } |
| 6523 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6524 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6525 | |
| 6526 | /* Update the fc_host data structures with new wwn. */ |
| 6527 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6528 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6529 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6530 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6531 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6532 | if (unlikely(rc)) { |
| 6533 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6534 | "1400 Failed to update xri-sgl size and " |
| 6535 | "mapping: %d\n", rc); |
| 6536 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6537 | } |
| 6538 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6539 | /* register the els sgl pool to the port */ |
| 6540 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6541 | if (unlikely(rc)) { |
| 6542 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6543 | "0582 Error %d during els sgl post " |
| 6544 | "operation\n", rc); |
| 6545 | rc = -ENODEV; |
| 6546 | goto out_free_mbox; |
| 6547 | } |
| 6548 | |
| 6549 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6550 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6551 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6552 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6553 | "0383 Error %d during scsi sgl post " |
| 6554 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6555 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6556 | /* A pci function reset will repost them */ |
| 6557 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6558 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6559 | } |
| 6560 | |
| 6561 | /* Post the rpi header region to the device. */ |
| 6562 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6563 | if (unlikely(rc)) { |
| 6564 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6565 | "0393 Error %d during rpi post operation\n", |
| 6566 | rc); |
| 6567 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6568 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6569 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6570 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6571 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6572 | /* Create all the SLI4 queues */ |
| 6573 | rc = lpfc_sli4_queue_create(phba); |
| 6574 | if (rc) { |
| 6575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6576 | "3089 Failed to allocate queues\n"); |
| 6577 | rc = -ENODEV; |
| 6578 | goto out_stop_timers; |
| 6579 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6580 | /* Set up all the queues to the device */ |
| 6581 | rc = lpfc_sli4_queue_setup(phba); |
| 6582 | if (unlikely(rc)) { |
| 6583 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6584 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6585 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | /* Arm the CQs and then EQs on device */ |
| 6589 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6590 | |
| 6591 | /* Indicate device interrupt mode */ |
| 6592 | phba->sli4_hba.intr_enable = 1; |
| 6593 | |
| 6594 | /* Allow asynchronous mailbox command to go through */ |
| 6595 | spin_lock_irq(&phba->hbalock); |
| 6596 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6597 | spin_unlock_irq(&phba->hbalock); |
| 6598 | |
| 6599 | /* Post receive buffers to the device */ |
| 6600 | lpfc_sli4_rb_setup(phba); |
| 6601 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6602 | /* Reset HBA FCF states after HBA reset */ |
| 6603 | phba->fcf.fcf_flag = 0; |
| 6604 | phba->fcf.current_rec.flag = 0; |
| 6605 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6606 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6607 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6608 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6609 | |
| 6610 | /* Start heart beat timer */ |
| 6611 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6612 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6613 | phba->hb_outstanding = 0; |
| 6614 | phba->last_completion_time = jiffies; |
| 6615 | |
| 6616 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6617 | mod_timer(&phba->eratt_poll, |
| 6618 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6619 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6620 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6621 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6622 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6623 | if (!rc) { |
| 6624 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6625 | "2829 This device supports " |
| 6626 | "Advanced Error Reporting (AER)\n"); |
| 6627 | spin_lock_irq(&phba->hbalock); |
| 6628 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6629 | spin_unlock_irq(&phba->hbalock); |
| 6630 | } else { |
| 6631 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6632 | "2830 This device does not support " |
| 6633 | "Advanced Error Reporting (AER)\n"); |
| 6634 | phba->cfg_aer_support = 0; |
| 6635 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6636 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6637 | } |
| 6638 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6639 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6640 | /* |
| 6641 | * The FC Port needs to register FCFI (index 0) |
| 6642 | */ |
| 6643 | lpfc_reg_fcfi(phba, mboxq); |
| 6644 | mboxq->vport = phba->pport; |
| 6645 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6646 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6647 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6648 | rc = 0; |
| 6649 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6650 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6651 | |
| 6652 | /* Check if the port is configured to be disabled */ |
| 6653 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6654 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6655 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6656 | /* |
| 6657 | * The port is ready, set the host's link state to LINK_DOWN |
| 6658 | * in preparation for link interrupts. |
| 6659 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6660 | spin_lock_irq(&phba->hbalock); |
| 6661 | phba->link_state = LPFC_LINK_DOWN; |
| 6662 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6663 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6664 | (phba->hba_flag & LINK_DISABLED)) { |
| 6665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6666 | "3103 Adapter Link is disabled.\n"); |
| 6667 | lpfc_down_link(phba, mboxq); |
| 6668 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6669 | if (rc != MBX_SUCCESS) { |
| 6670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6671 | "3104 Adapter failed to issue " |
| 6672 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6673 | goto out_unset_queue; |
| 6674 | } |
| 6675 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6676 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6677 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6678 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6679 | if (rc) |
| 6680 | goto out_unset_queue; |
| 6681 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6682 | } |
| 6683 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6684 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6685 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6686 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6687 | lpfc_sli4_queue_unset(phba); |
| 6688 | out_destroy_queue: |
| 6689 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6690 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6691 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6692 | out_free_mbox: |
| 6693 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6694 | return rc; |
| 6695 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6696 | |
| 6697 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6698 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6699 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6700 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6701 | * This is the callback function for mailbox timer. The mailbox |
| 6702 | * timer is armed when a new mailbox command is issued and the timer |
| 6703 | * is deleted when the mailbox complete. The function is called by |
| 6704 | * the kernel timer code when a mailbox does not complete within |
| 6705 | * expected time. This function wakes up the worker thread to |
| 6706 | * process the mailbox timeout and returns. All the processing is |
| 6707 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6708 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6709 | void |
| 6710 | lpfc_mbox_timeout(unsigned long ptr) |
| 6711 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6712 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6713 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6714 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6715 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6716 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6717 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6718 | if (!tmo_posted) |
| 6719 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6720 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6721 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6722 | if (!tmo_posted) |
| 6723 | lpfc_worker_wake_up(phba); |
| 6724 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6725 | } |
| 6726 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6727 | /** |
| 6728 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 6729 | * are pending |
| 6730 | * @phba: Pointer to HBA context object. |
| 6731 | * |
| 6732 | * This function checks if any mailbox completions are present on the mailbox |
| 6733 | * completion queue. |
| 6734 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 6735 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6736 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 6737 | { |
| 6738 | |
| 6739 | uint32_t idx; |
| 6740 | struct lpfc_queue *mcq; |
| 6741 | struct lpfc_mcqe *mcqe; |
| 6742 | bool pending_completions = false; |
| 6743 | |
| 6744 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6745 | return false; |
| 6746 | |
| 6747 | /* Check for completions on mailbox completion queue */ |
| 6748 | |
| 6749 | mcq = phba->sli4_hba.mbx_cq; |
| 6750 | idx = mcq->hba_index; |
| 6751 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 6752 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 6753 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 6754 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 6755 | pending_completions = true; |
| 6756 | break; |
| 6757 | } |
| 6758 | idx = (idx + 1) % mcq->entry_count; |
| 6759 | if (mcq->hba_index == idx) |
| 6760 | break; |
| 6761 | } |
| 6762 | return pending_completions; |
| 6763 | |
| 6764 | } |
| 6765 | |
| 6766 | /** |
| 6767 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 6768 | * that were missed. |
| 6769 | * @phba: Pointer to HBA context object. |
| 6770 | * |
| 6771 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 6772 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 6773 | * checks to see if mbox completions are on the mailbox completion queue |
| 6774 | * and will process all the completions associated with the eq for the |
| 6775 | * mailbox completion queue. |
| 6776 | **/ |
| 6777 | bool |
| 6778 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 6779 | { |
| 6780 | |
| 6781 | uint32_t eqidx; |
| 6782 | struct lpfc_queue *fpeq = NULL; |
| 6783 | struct lpfc_eqe *eqe; |
| 6784 | bool mbox_pending; |
| 6785 | |
| 6786 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6787 | return false; |
| 6788 | |
| 6789 | /* Find the eq associated with the mcq */ |
| 6790 | |
| 6791 | if (phba->sli4_hba.hba_eq) |
| 6792 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) |
| 6793 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 6794 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 6795 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 6796 | break; |
| 6797 | } |
| 6798 | if (!fpeq) |
| 6799 | return false; |
| 6800 | |
| 6801 | /* Turn off interrupts from this EQ */ |
| 6802 | |
| 6803 | lpfc_sli4_eq_clr_intr(fpeq); |
| 6804 | |
| 6805 | /* Check to see if a mbox completion is pending */ |
| 6806 | |
| 6807 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 6808 | |
| 6809 | /* |
| 6810 | * If a mbox completion is pending, process all the events on EQ |
| 6811 | * associated with the mbox completion queue (this could include |
| 6812 | * mailbox commands, async events, els commands, receive queue data |
| 6813 | * and fcp commands) |
| 6814 | */ |
| 6815 | |
| 6816 | if (mbox_pending) |
| 6817 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 6818 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 6819 | fpeq->EQ_processed++; |
| 6820 | } |
| 6821 | |
| 6822 | /* Always clear and re-arm the EQ */ |
| 6823 | |
| 6824 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 6825 | |
| 6826 | return mbox_pending; |
| 6827 | |
| 6828 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6829 | |
| 6830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6831 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6832 | * @phba: Pointer to HBA context object. |
| 6833 | * |
| 6834 | * This function is called from worker thread when a mailbox command times out. |
| 6835 | * The caller is not required to hold any locks. This function will reset the |
| 6836 | * HBA and recover all the pending commands. |
| 6837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6838 | void |
| 6839 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6840 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6841 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6842 | MAILBOX_t *mb = NULL; |
| 6843 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6844 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6845 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6846 | /* If the mailbox completed, process the completion and return */ |
| 6847 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 6848 | return; |
| 6849 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6850 | if (pmbox != NULL) |
| 6851 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6852 | /* Check the pmbox pointer first. There is a race condition |
| 6853 | * between the mbox timeout handler getting executed in the |
| 6854 | * worklist and the mailbox actually completing. When this |
| 6855 | * race condition occurs, the mbox_active will be NULL. |
| 6856 | */ |
| 6857 | spin_lock_irq(&phba->hbalock); |
| 6858 | if (pmbox == NULL) { |
| 6859 | lpfc_printf_log(phba, KERN_WARNING, |
| 6860 | LOG_MBOX | LOG_SLI, |
| 6861 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6862 | "exiting\n"); |
| 6863 | spin_unlock_irq(&phba->hbalock); |
| 6864 | return; |
| 6865 | } |
| 6866 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6867 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6868 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6869 | "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] | 6870 | mb->mbxCommand, |
| 6871 | phba->pport->port_state, |
| 6872 | phba->sli.sli_flag, |
| 6873 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6874 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6875 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6876 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6877 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6878 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6879 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6880 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6881 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6882 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6883 | spin_lock_irq(&phba->hbalock); |
| 6884 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6885 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6886 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6887 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 6888 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6889 | |
| 6890 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6891 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6892 | |
| 6893 | /* Reset the HBA device */ |
| 6894 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6895 | } |
| 6896 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6897 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6898 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6899 | * @phba: Pointer to HBA context object. |
| 6900 | * @pmbox: Pointer to mailbox object. |
| 6901 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6902 | * |
| 6903 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6904 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6905 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6906 | * The mailbox command can be submitted in polling mode, in which case |
| 6907 | * this function will wait in a polling loop for the completion of the |
| 6908 | * mailbox. |
| 6909 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6910 | * function will submit the command and returns immediately without waiting |
| 6911 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6912 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6913 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6914 | * mailbox is issued in polling mode and there is already a mailbox |
| 6915 | * pending, then the function will return an error. If the mailbox is issued |
| 6916 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6917 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6918 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6919 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6920 | * return codes the caller owns the mailbox command after the return of |
| 6921 | * the function. |
| 6922 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6923 | static int |
| 6924 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6925 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6926 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6927 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6928 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6929 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6930 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6931 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6932 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6933 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6934 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6935 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6936 | int processing_queue = 0; |
| 6937 | |
| 6938 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6939 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6940 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6941 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6942 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6943 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6944 | return MBX_SUCCESS; |
| 6945 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6946 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6947 | pmbox = lpfc_mbox_get(phba); |
| 6948 | if (!pmbox) { |
| 6949 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6950 | return MBX_SUCCESS; |
| 6951 | } |
| 6952 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6953 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6954 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6955 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6956 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6957 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6958 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6959 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6960 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6961 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6962 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6963 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6964 | } |
| 6965 | } |
| 6966 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6967 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6968 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6969 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6970 | goto out_not_finished; |
| 6971 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6972 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6973 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6974 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6975 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6976 | goto out_not_finished; |
| 6977 | } |
| 6978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6979 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6980 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6981 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6982 | status = MBX_SUCCESS; |
| 6983 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6984 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6985 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6986 | |
| 6987 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6988 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6989 | "(%d):0311 Mailbox command x%x cannot " |
| 6990 | "issue Data: x%x x%x\n", |
| 6991 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6992 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6993 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6994 | } |
| 6995 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6996 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6997 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6998 | !(hc_copy & HC_MBINT_ENA)) { |
| 6999 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7000 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7001 | "(%d):2528 Mailbox command x%x cannot " |
| 7002 | "issue Data: x%x x%x\n", |
| 7003 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7004 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7005 | goto out_not_finished; |
| 7006 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7007 | } |
| 7008 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7009 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7010 | /* Polling for a mbox command when another one is already active |
| 7011 | * is not allowed in SLI. Also, the driver must have established |
| 7012 | * SLI2 mode to queue and process multiple mbox commands. |
| 7013 | */ |
| 7014 | |
| 7015 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7016 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7017 | |
| 7018 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7019 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7020 | "(%d):2529 Mailbox command x%x " |
| 7021 | "cannot issue Data: x%x x%x\n", |
| 7022 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7023 | pmbox->u.mb.mbxCommand, |
| 7024 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7025 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7026 | } |
| 7027 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7028 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7029 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7030 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7031 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7032 | "(%d):2530 Mailbox command x%x " |
| 7033 | "cannot issue Data: x%x x%x\n", |
| 7034 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7035 | pmbox->u.mb.mbxCommand, |
| 7036 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7037 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7038 | } |
| 7039 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7040 | /* Another mailbox command is still being processed, queue this |
| 7041 | * command to be processed later. |
| 7042 | */ |
| 7043 | lpfc_mbox_put(phba, pmbox); |
| 7044 | |
| 7045 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7046 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7047 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7048 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7049 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7050 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7051 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7052 | |
| 7053 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7054 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7055 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7056 | if (pmbox->vport) { |
| 7057 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7058 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7059 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7060 | (uint32_t)mbx->mbxCommand, |
| 7061 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7062 | } |
| 7063 | else { |
| 7064 | lpfc_debugfs_disc_trc(phba->pport, |
| 7065 | LPFC_DISC_TRC_MBOX, |
| 7066 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7067 | (uint32_t)mbx->mbxCommand, |
| 7068 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7069 | } |
| 7070 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7071 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7072 | } |
| 7073 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7074 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7075 | |
| 7076 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7077 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7078 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7079 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7080 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7081 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7082 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7083 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7084 | "(%d):2531 Mailbox command x%x " |
| 7085 | "cannot issue Data: x%x x%x\n", |
| 7086 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7087 | pmbox->u.mb.mbxCommand, |
| 7088 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7089 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7090 | } |
| 7091 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7092 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7093 | 1000); |
| 7094 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7098 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7099 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7100 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7101 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7102 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7103 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7104 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7105 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7106 | if (pmbox->vport) { |
| 7107 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7108 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7109 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7110 | (uint32_t)mbx->mbxCommand, |
| 7111 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7112 | } |
| 7113 | else { |
| 7114 | lpfc_debugfs_disc_trc(phba->pport, |
| 7115 | LPFC_DISC_TRC_MBOX, |
| 7116 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7117 | (uint32_t)mbx->mbxCommand, |
| 7118 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7119 | } |
| 7120 | } |
| 7121 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7122 | psli->slistat.mbox_cmd++; |
| 7123 | evtctr = psli->slistat.mbox_event; |
| 7124 | |
| 7125 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7126 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7127 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7128 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7129 | /* Populate mbox extension offset word. */ |
| 7130 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7131 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7132 | = (uint8_t *)phba->mbox_ext |
| 7133 | - (uint8_t *)phba->mbox; |
| 7134 | } |
| 7135 | |
| 7136 | /* Copy the mailbox extension data */ |
| 7137 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7138 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7139 | (uint8_t *)phba->mbox_ext, |
| 7140 | pmbox->in_ext_byte_len); |
| 7141 | } |
| 7142 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7143 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7144 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7145 | /* Populate mbox extension offset word. */ |
| 7146 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7147 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7148 | = MAILBOX_HBA_EXT_OFFSET; |
| 7149 | |
| 7150 | /* Copy the mailbox extension data */ |
| 7151 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7152 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7153 | MAILBOX_HBA_EXT_OFFSET, |
| 7154 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7155 | |
| 7156 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7157 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7158 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7159 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7163 | word */ |
| 7164 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7165 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7166 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7167 | |
| 7168 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7169 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7170 | to_slim = phba->MBslimaddr; |
| 7171 | writel(ldata, to_slim); |
| 7172 | readl(to_slim); /* flush */ |
| 7173 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7174 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7175 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7176 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7177 | } |
| 7178 | } |
| 7179 | |
| 7180 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7181 | |
| 7182 | switch (flag) { |
| 7183 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7184 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7185 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7186 | /* Interrupt board to do it */ |
| 7187 | writel(CA_MBATT, phba->CAregaddr); |
| 7188 | readl(phba->CAregaddr); /* flush */ |
| 7189 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7190 | break; |
| 7191 | |
| 7192 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7193 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7194 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7195 | /* Interrupt board to do it */ |
| 7196 | writel(CA_MBATT, phba->CAregaddr); |
| 7197 | readl(phba->CAregaddr); /* flush */ |
| 7198 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7199 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7200 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7201 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7202 | word0 = le32_to_cpu(word0); |
| 7203 | } else { |
| 7204 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7205 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7206 | spin_unlock_irqrestore(&phba->hbalock, |
| 7207 | drvr_flag); |
| 7208 | goto out_not_finished; |
| 7209 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7213 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7214 | spin_unlock_irqrestore(&phba->hbalock, |
| 7215 | drvr_flag); |
| 7216 | goto out_not_finished; |
| 7217 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7218 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7219 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7220 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7221 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7222 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7223 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7224 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7225 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7226 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7227 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7228 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7229 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7230 | } |
| 7231 | |
| 7232 | /* Check if we took a mbox interrupt while we were |
| 7233 | polling */ |
| 7234 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7235 | && (evtctr != psli->slistat.mbox_event)) |
| 7236 | break; |
| 7237 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7238 | if (i++ > 10) { |
| 7239 | spin_unlock_irqrestore(&phba->hbalock, |
| 7240 | drvr_flag); |
| 7241 | msleep(1); |
| 7242 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7243 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7244 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7245 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7246 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7247 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7248 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7249 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7250 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7251 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7252 | /* Check real SLIM for any errors */ |
| 7253 | slimword0 = readl(phba->MBslimaddr); |
| 7254 | slimmb = (MAILBOX_t *) & slimword0; |
| 7255 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7256 | && slimmb->mbxStatus) { |
| 7257 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7258 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7259 | word0 = slimword0; |
| 7260 | } |
| 7261 | } |
| 7262 | } else { |
| 7263 | /* First copy command data */ |
| 7264 | word0 = readl(phba->MBslimaddr); |
| 7265 | } |
| 7266 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7267 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7268 | spin_unlock_irqrestore(&phba->hbalock, |
| 7269 | drvr_flag); |
| 7270 | goto out_not_finished; |
| 7271 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7272 | } |
| 7273 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7274 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7275 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7276 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7277 | /* Copy the mailbox extension data */ |
| 7278 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7279 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7280 | pmbox->context2, |
| 7281 | pmbox->out_ext_byte_len); |
| 7282 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7283 | } else { |
| 7284 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7285 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7286 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7287 | /* Copy the mailbox extension data */ |
| 7288 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7289 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7290 | phba->MBslimaddr + |
| 7291 | MAILBOX_HBA_EXT_OFFSET, |
| 7292 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | writel(HA_MBATT, phba->HAregaddr); |
| 7297 | readl(phba->HAregaddr); /* flush */ |
| 7298 | |
| 7299 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7300 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7301 | } |
| 7302 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7303 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7304 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7305 | |
| 7306 | out_not_finished: |
| 7307 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7308 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7309 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7310 | } |
| 7311 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7312 | } |
| 7313 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7314 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7315 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7316 | * @phba: Pointer to HBA context object. |
| 7317 | * |
| 7318 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7319 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7320 | * possible outstanding mailbox command before return. |
| 7321 | * |
| 7322 | * Returns: |
| 7323 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7324 | * the outstanding mailbox command timed out. |
| 7325 | **/ |
| 7326 | static int |
| 7327 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7328 | { |
| 7329 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7330 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7331 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7332 | |
| 7333 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7334 | spin_lock_irq(&phba->hbalock); |
| 7335 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7336 | /* Determine how long we might wait for the active mailbox |
| 7337 | * command to be gracefully completed by firmware. |
| 7338 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7339 | if (phba->sli.mbox_active) |
| 7340 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7341 | phba->sli.mbox_active) * |
| 7342 | 1000) + jiffies; |
| 7343 | spin_unlock_irq(&phba->hbalock); |
| 7344 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7345 | /* Make sure the mailbox is really active */ |
| 7346 | if (timeout) |
| 7347 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7348 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7349 | /* Wait for the outstnading mailbox command to complete */ |
| 7350 | while (phba->sli.mbox_active) { |
| 7351 | /* Check active mailbox complete status every 2ms */ |
| 7352 | msleep(2); |
| 7353 | if (time_after(jiffies, timeout)) { |
| 7354 | /* Timeout, marked the outstanding cmd not complete */ |
| 7355 | rc = 1; |
| 7356 | break; |
| 7357 | } |
| 7358 | } |
| 7359 | |
| 7360 | /* Can not cleanly block async mailbox command, fails it */ |
| 7361 | if (rc) { |
| 7362 | spin_lock_irq(&phba->hbalock); |
| 7363 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7364 | spin_unlock_irq(&phba->hbalock); |
| 7365 | } |
| 7366 | return rc; |
| 7367 | } |
| 7368 | |
| 7369 | /** |
| 7370 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7371 | * @phba: Pointer to HBA context object. |
| 7372 | * |
| 7373 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7374 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7375 | * that there is no outstanding mailbox command before resuming posting |
| 7376 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7377 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7378 | * mailbox command posting. |
| 7379 | **/ |
| 7380 | static void |
| 7381 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7382 | { |
| 7383 | struct lpfc_sli *psli = &phba->sli; |
| 7384 | |
| 7385 | spin_lock_irq(&phba->hbalock); |
| 7386 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7387 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7388 | spin_unlock_irq(&phba->hbalock); |
| 7389 | return; |
| 7390 | } |
| 7391 | |
| 7392 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7393 | * successful or timeout, after timing-out the outstanding mailbox |
| 7394 | * command shall always be removed, so just unblock posting async |
| 7395 | * mailbox command and resume |
| 7396 | */ |
| 7397 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7398 | spin_unlock_irq(&phba->hbalock); |
| 7399 | |
| 7400 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7401 | lpfc_worker_wake_up(phba); |
| 7402 | } |
| 7403 | |
| 7404 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7405 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7406 | * @phba: Pointer to HBA context object. |
| 7407 | * @mboxq: Pointer to mailbox object. |
| 7408 | * |
| 7409 | * The function waits for the bootstrap mailbox register ready bit from |
| 7410 | * port for twice the regular mailbox command timeout value. |
| 7411 | * |
| 7412 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7413 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7414 | **/ |
| 7415 | static int |
| 7416 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7417 | { |
| 7418 | uint32_t db_ready; |
| 7419 | unsigned long timeout; |
| 7420 | struct lpfc_register bmbx_reg; |
| 7421 | |
| 7422 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7423 | * 1000) + jiffies; |
| 7424 | |
| 7425 | do { |
| 7426 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7427 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7428 | if (!db_ready) |
| 7429 | msleep(2); |
| 7430 | |
| 7431 | if (time_after(jiffies, timeout)) |
| 7432 | return MBXERR_ERROR; |
| 7433 | } while (!db_ready); |
| 7434 | |
| 7435 | return 0; |
| 7436 | } |
| 7437 | |
| 7438 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7439 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7440 | * @phba: Pointer to HBA context object. |
| 7441 | * @mboxq: Pointer to mailbox object. |
| 7442 | * |
| 7443 | * The function posts a mailbox to the port. The mailbox is expected |
| 7444 | * to be comletely filled in and ready for the port to operate on it. |
| 7445 | * This routine executes a synchronous completion operation on the |
| 7446 | * mailbox by polling for its completion. |
| 7447 | * |
| 7448 | * The caller must not be holding any locks when calling this routine. |
| 7449 | * |
| 7450 | * Returns: |
| 7451 | * MBX_SUCCESS - mailbox posted successfully |
| 7452 | * Any of the MBX error values. |
| 7453 | **/ |
| 7454 | static int |
| 7455 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7456 | { |
| 7457 | int rc = MBX_SUCCESS; |
| 7458 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7459 | uint32_t mcqe_status; |
| 7460 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7461 | struct lpfc_sli *psli = &phba->sli; |
| 7462 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7463 | struct lpfc_bmbx_create *mbox_rgn; |
| 7464 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | |
| 7466 | /* |
| 7467 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7468 | * at a time and there is no queueing provided. |
| 7469 | */ |
| 7470 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7471 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7472 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7473 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7474 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7475 | "cannot issue Data: x%x x%x\n", |
| 7476 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7477 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7478 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7479 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7480 | psli->sli_flag, MBX_POLL); |
| 7481 | return MBXERR_ERROR; |
| 7482 | } |
| 7483 | /* The server grabs the token and owns it until release */ |
| 7484 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7485 | phba->sli.mbox_active = mboxq; |
| 7486 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7487 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7488 | /* wait for bootstrap mbox register for readyness */ |
| 7489 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7490 | if (rc) |
| 7491 | goto exit; |
| 7492 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7493 | /* |
| 7494 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7495 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7496 | * the bmbx mailbox region. |
| 7497 | */ |
| 7498 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7499 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7500 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7501 | sizeof(struct lpfc_mqe)); |
| 7502 | |
| 7503 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7504 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7505 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7506 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7507 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7508 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7509 | if (rc) |
| 7510 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7511 | |
| 7512 | /* Post the low mailbox dma address to the port. */ |
| 7513 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7514 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7515 | /* wait for bootstrap mbox register for low address write done */ |
| 7516 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7517 | if (rc) |
| 7518 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7519 | |
| 7520 | /* |
| 7521 | * Read the CQ to ensure the mailbox has completed. |
| 7522 | * If so, update the mailbox status so that the upper layers |
| 7523 | * can complete the request normally. |
| 7524 | */ |
| 7525 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7526 | sizeof(struct lpfc_mqe)); |
| 7527 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7528 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7529 | sizeof(struct lpfc_mcqe)); |
| 7530 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7531 | /* |
| 7532 | * When the CQE status indicates a failure and the mailbox status |
| 7533 | * indicates success then copy the CQE status into the mailbox status |
| 7534 | * (and prefix it with x4000). |
| 7535 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7536 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7537 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7538 | bf_set(lpfc_mqe_status, mb, |
| 7539 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7541 | } else |
| 7542 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7543 | |
| 7544 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7545 | "(%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] | 7546 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7547 | " 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] | 7548 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7549 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7550 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7551 | bf_get(lpfc_mqe_status, mb), |
| 7552 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7553 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7554 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7555 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7556 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7557 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7558 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7559 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7560 | mboxq->mcqe.trailer); |
| 7561 | exit: |
| 7562 | /* We are holding the token, no needed for lock when release */ |
| 7563 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7564 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7565 | phba->sli.mbox_active = NULL; |
| 7566 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7567 | return rc; |
| 7568 | } |
| 7569 | |
| 7570 | /** |
| 7571 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7572 | * @phba: Pointer to HBA context object. |
| 7573 | * @pmbox: Pointer to mailbox object. |
| 7574 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7575 | * |
| 7576 | * This function is called by discovery code and HBA management code to submit |
| 7577 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7578 | * |
| 7579 | * Return codes the caller owns the mailbox command after the return of the |
| 7580 | * function. |
| 7581 | **/ |
| 7582 | static int |
| 7583 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7584 | uint32_t flag) |
| 7585 | { |
| 7586 | struct lpfc_sli *psli = &phba->sli; |
| 7587 | unsigned long iflags; |
| 7588 | int rc; |
| 7589 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7590 | /* dump from issue mailbox command if setup */ |
| 7591 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7592 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7593 | rc = lpfc_mbox_dev_check(phba); |
| 7594 | if (unlikely(rc)) { |
| 7595 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7596 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7597 | "cannot issue Data: x%x x%x\n", |
| 7598 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7599 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7600 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7601 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7602 | psli->sli_flag, flag); |
| 7603 | goto out_not_finished; |
| 7604 | } |
| 7605 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7606 | /* Detect polling mode and jump to a handler */ |
| 7607 | if (!phba->sli4_hba.intr_enable) { |
| 7608 | if (flag == MBX_POLL) |
| 7609 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7610 | else |
| 7611 | rc = -EIO; |
| 7612 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7613 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7614 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7615 | "(x%x/x%x) failure: " |
| 7616 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7617 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7618 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7619 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7620 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7621 | mboxq), |
| 7622 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7623 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7624 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7625 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7626 | bf_get(lpfc_mcqe_ext_status, |
| 7627 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7628 | psli->sli_flag, flag); |
| 7629 | return rc; |
| 7630 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7631 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7632 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7633 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7634 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7635 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7636 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7637 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7638 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7639 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7640 | /* Try to block the asynchronous mailbox posting */ |
| 7641 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7642 | if (!rc) { |
| 7643 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7644 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7645 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7646 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7647 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7648 | "(%d):2597 Sync Mailbox command " |
| 7649 | "x%x (x%x/x%x) failure: " |
| 7650 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7651 | "Data: x%x x%x\n,", |
| 7652 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7653 | mboxq->u.mb.mbxCommand, |
| 7654 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7655 | mboxq), |
| 7656 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7657 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7658 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7659 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7660 | bf_get(lpfc_mcqe_ext_status, |
| 7661 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7662 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7663 | /* Unblock the async mailbox posting afterward */ |
| 7664 | lpfc_sli4_async_mbox_unblock(phba); |
| 7665 | } |
| 7666 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7670 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7671 | if (rc) { |
| 7672 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7673 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7674 | "cannot issue Data: x%x x%x\n", |
| 7675 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7676 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7677 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7678 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7679 | psli->sli_flag, flag); |
| 7680 | goto out_not_finished; |
| 7681 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7682 | |
| 7683 | /* Put the mailbox command to the driver internal FIFO */ |
| 7684 | psli->slistat.mbox_busy++; |
| 7685 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7686 | lpfc_mbox_put(phba, mboxq); |
| 7687 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7688 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7689 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7690 | "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] | 7691 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7692 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7693 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7694 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7695 | phba->pport->port_state, |
| 7696 | psli->sli_flag, MBX_NOWAIT); |
| 7697 | /* Wake up worker thread to transport mailbox command from head */ |
| 7698 | lpfc_worker_wake_up(phba); |
| 7699 | |
| 7700 | return MBX_BUSY; |
| 7701 | |
| 7702 | out_not_finished: |
| 7703 | return MBX_NOT_FINISHED; |
| 7704 | } |
| 7705 | |
| 7706 | /** |
| 7707 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7708 | * @phba: Pointer to HBA context object. |
| 7709 | * |
| 7710 | * This function is called by worker thread to send a mailbox command to |
| 7711 | * SLI4 HBA firmware. |
| 7712 | * |
| 7713 | **/ |
| 7714 | int |
| 7715 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7716 | { |
| 7717 | struct lpfc_sli *psli = &phba->sli; |
| 7718 | LPFC_MBOXQ_t *mboxq; |
| 7719 | int rc = MBX_SUCCESS; |
| 7720 | unsigned long iflags; |
| 7721 | struct lpfc_mqe *mqe; |
| 7722 | uint32_t mbx_cmnd; |
| 7723 | |
| 7724 | /* Check interrupt mode before post async mailbox command */ |
| 7725 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7726 | return MBX_NOT_FINISHED; |
| 7727 | |
| 7728 | /* Check for mailbox command service token */ |
| 7729 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7730 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7731 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7732 | return MBX_NOT_FINISHED; |
| 7733 | } |
| 7734 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7735 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7736 | return MBX_NOT_FINISHED; |
| 7737 | } |
| 7738 | if (unlikely(phba->sli.mbox_active)) { |
| 7739 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7740 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7741 | "0384 There is pending active mailbox cmd\n"); |
| 7742 | return MBX_NOT_FINISHED; |
| 7743 | } |
| 7744 | /* Take the mailbox command service token */ |
| 7745 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7746 | |
| 7747 | /* Get the next mailbox command from head of queue */ |
| 7748 | mboxq = lpfc_mbox_get(phba); |
| 7749 | |
| 7750 | /* If no more mailbox command waiting for post, we're done */ |
| 7751 | if (!mboxq) { |
| 7752 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7753 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7754 | return MBX_SUCCESS; |
| 7755 | } |
| 7756 | phba->sli.mbox_active = mboxq; |
| 7757 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7758 | |
| 7759 | /* Check device readiness for posting mailbox command */ |
| 7760 | rc = lpfc_mbox_dev_check(phba); |
| 7761 | if (unlikely(rc)) |
| 7762 | /* Driver clean routine will clean up pending mailbox */ |
| 7763 | goto out_not_finished; |
| 7764 | |
| 7765 | /* Prepare the mbox command to be posted */ |
| 7766 | mqe = &mboxq->u.mqe; |
| 7767 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7768 | |
| 7769 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7770 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7771 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7772 | |
| 7773 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7774 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7775 | "x%x x%x\n", |
| 7776 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7777 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7778 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7779 | phba->pport->port_state, psli->sli_flag); |
| 7780 | |
| 7781 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7782 | if (mboxq->vport) { |
| 7783 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7784 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7785 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7786 | mbx_cmnd, mqe->un.mb_words[0], |
| 7787 | mqe->un.mb_words[1]); |
| 7788 | } else { |
| 7789 | lpfc_debugfs_disc_trc(phba->pport, |
| 7790 | LPFC_DISC_TRC_MBOX, |
| 7791 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7792 | mbx_cmnd, mqe->un.mb_words[0], |
| 7793 | mqe->un.mb_words[1]); |
| 7794 | } |
| 7795 | } |
| 7796 | psli->slistat.mbox_cmd++; |
| 7797 | |
| 7798 | /* Post the mailbox command to the port */ |
| 7799 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7800 | if (rc != MBX_SUCCESS) { |
| 7801 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7802 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7803 | "cannot issue Data: x%x x%x\n", |
| 7804 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7805 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7806 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7807 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7808 | psli->sli_flag, MBX_NOWAIT); |
| 7809 | goto out_not_finished; |
| 7810 | } |
| 7811 | |
| 7812 | return rc; |
| 7813 | |
| 7814 | out_not_finished: |
| 7815 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7816 | if (phba->sli.mbox_active) { |
| 7817 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7818 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7819 | /* Release the token */ |
| 7820 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7821 | phba->sli.mbox_active = NULL; |
| 7822 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7823 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7824 | |
| 7825 | return MBX_NOT_FINISHED; |
| 7826 | } |
| 7827 | |
| 7828 | /** |
| 7829 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7830 | * @phba: Pointer to HBA context object. |
| 7831 | * @pmbox: Pointer to mailbox object. |
| 7832 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7833 | * |
| 7834 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7835 | * the API jump table function pointer from the lpfc_hba struct. |
| 7836 | * |
| 7837 | * Return codes the caller owns the mailbox command after the return of the |
| 7838 | * function. |
| 7839 | **/ |
| 7840 | int |
| 7841 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7842 | { |
| 7843 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7844 | } |
| 7845 | |
| 7846 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7847 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7848 | * @phba: The hba struct for which this call is being executed. |
| 7849 | * @dev_grp: The HBA PCI-Device group number. |
| 7850 | * |
| 7851 | * This routine sets up the mbox interface API function jump table in @phba |
| 7852 | * struct. |
| 7853 | * Returns: 0 - success, -ENODEV - failure. |
| 7854 | **/ |
| 7855 | int |
| 7856 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7857 | { |
| 7858 | |
| 7859 | switch (dev_grp) { |
| 7860 | case LPFC_PCI_DEV_LP: |
| 7861 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7862 | phba->lpfc_sli_handle_slow_ring_event = |
| 7863 | lpfc_sli_handle_slow_ring_event_s3; |
| 7864 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7865 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7866 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7867 | break; |
| 7868 | case LPFC_PCI_DEV_OC: |
| 7869 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7870 | phba->lpfc_sli_handle_slow_ring_event = |
| 7871 | lpfc_sli_handle_slow_ring_event_s4; |
| 7872 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7873 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7874 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7875 | break; |
| 7876 | default: |
| 7877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7878 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7879 | dev_grp); |
| 7880 | return -ENODEV; |
| 7881 | break; |
| 7882 | } |
| 7883 | return 0; |
| 7884 | } |
| 7885 | |
| 7886 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7887 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7888 | * @phba: Pointer to HBA context object. |
| 7889 | * @pring: Pointer to driver SLI ring object. |
| 7890 | * @piocb: Pointer to address of newly added command iocb. |
| 7891 | * |
| 7892 | * This function is called with hbalock held to add a command |
| 7893 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7894 | * to the ring. |
| 7895 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7896 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7897 | __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] | 7898 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7899 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7900 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7901 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7902 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7903 | } |
| 7904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7906 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7907 | * @phba: Pointer to HBA context object. |
| 7908 | * @pring: Pointer to driver SLI ring object. |
| 7909 | * @piocb: Pointer to address of newly added command iocb. |
| 7910 | * |
| 7911 | * This function is called with hbalock held before a new |
| 7912 | * iocb is submitted to the firmware. This function checks |
| 7913 | * txq to flush the iocbs in txq to Firmware before |
| 7914 | * submitting new iocbs to the Firmware. |
| 7915 | * If there are iocbs in the txq which need to be submitted |
| 7916 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7917 | * of the txq after dequeuing it from txq. |
| 7918 | * If there is no iocb in the txq then the function will return |
| 7919 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7920 | * *piocb to find if there are more commands in the txq. |
| 7921 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7922 | static struct lpfc_iocbq * |
| 7923 | 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] | 7924 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7925 | { |
| 7926 | struct lpfc_iocbq * nextiocb; |
| 7927 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7928 | lockdep_assert_held(&phba->hbalock); |
| 7929 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7930 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7931 | if (!nextiocb) { |
| 7932 | nextiocb = *piocb; |
| 7933 | *piocb = NULL; |
| 7934 | } |
| 7935 | |
| 7936 | return nextiocb; |
| 7937 | } |
| 7938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7939 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7940 | * __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] | 7941 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7942 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7943 | * @piocb: Pointer to command iocb. |
| 7944 | * @flag: Flag indicating if this command can be put into txq. |
| 7945 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7946 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7947 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7948 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7949 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7950 | * this function allows only iocbs for posting buffers. This function finds |
| 7951 | * next available slot in the command ring and posts the command to the |
| 7952 | * available slot and writes the port attention register to request HBA start |
| 7953 | * processing new iocb. If there is no slot available in the ring and |
| 7954 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7955 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7956 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7957 | * This function is called with hbalock held. The function will return success |
| 7958 | * after it successfully submit the iocb to firmware or after adding to the |
| 7959 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7960 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7961 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7962 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7963 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7964 | { |
| 7965 | struct lpfc_iocbq *nextiocb; |
| 7966 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7967 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7968 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7969 | lockdep_assert_held(&phba->hbalock); |
| 7970 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7971 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7972 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7973 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7974 | lpfc_printf_log(phba, KERN_ERR, |
| 7975 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7976 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7977 | piocb->iocb.ulpCommand); |
| 7978 | dump_stack(); |
| 7979 | return IOCB_ERROR; |
| 7980 | } |
| 7981 | |
| 7982 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7983 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7984 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7985 | return IOCB_ERROR; |
| 7986 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7987 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7988 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7989 | return IOCB_ERROR; |
| 7990 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7991 | /* |
| 7992 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7993 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7994 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7995 | return IOCB_ERROR; |
| 7996 | |
| 7997 | /* |
| 7998 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7999 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8000 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8001 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8002 | goto iocb_busy; |
| 8003 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8004 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8005 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8006 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8007 | * can be issued if the link is not up. |
| 8008 | */ |
| 8009 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8010 | case CMD_GEN_REQUEST64_CR: |
| 8011 | case CMD_GEN_REQUEST64_CX: |
| 8012 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8013 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8014 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8015 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8016 | MENLO_TRANSPORT_TYPE)) |
| 8017 | |
| 8018 | goto iocb_busy; |
| 8019 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8020 | case CMD_QUE_RING_BUF_CN: |
| 8021 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8022 | /* |
| 8023 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8024 | * completion, iocb_cmpl MUST be 0. |
| 8025 | */ |
| 8026 | if (piocb->iocb_cmpl) |
| 8027 | piocb->iocb_cmpl = NULL; |
| 8028 | /*FALLTHROUGH*/ |
| 8029 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8030 | case CMD_CLOSE_XRI_CN: |
| 8031 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8032 | break; |
| 8033 | default: |
| 8034 | goto iocb_busy; |
| 8035 | } |
| 8036 | |
| 8037 | /* |
| 8038 | * For FCP commands, we must be in a state where we can process link |
| 8039 | * attention events. |
| 8040 | */ |
| 8041 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8042 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8043 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8044 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8046 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8047 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8048 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8049 | |
| 8050 | if (iocb) |
| 8051 | lpfc_sli_update_ring(phba, pring); |
| 8052 | else |
| 8053 | lpfc_sli_update_full_ring(phba, pring); |
| 8054 | |
| 8055 | if (!piocb) |
| 8056 | return IOCB_SUCCESS; |
| 8057 | |
| 8058 | goto out_busy; |
| 8059 | |
| 8060 | iocb_busy: |
| 8061 | pring->stats.iocb_cmd_delay++; |
| 8062 | |
| 8063 | out_busy: |
| 8064 | |
| 8065 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8066 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8067 | return IOCB_SUCCESS; |
| 8068 | } |
| 8069 | |
| 8070 | return IOCB_BUSY; |
| 8071 | } |
| 8072 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8073 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8074 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8075 | * @phba: Pointer to HBA context object. |
| 8076 | * @piocb: Pointer to command iocb. |
| 8077 | * @sglq: Pointer to the scatter gather queue object. |
| 8078 | * |
| 8079 | * This routine converts the bpl or bde that is in the IOCB |
| 8080 | * to a sgl list for the sli4 hardware. The physical address |
| 8081 | * of the bpl/bde is converted back to a virtual address. |
| 8082 | * If the IOCB contains a BPL then the list of BDE's is |
| 8083 | * converted to sli4_sge's. If the IOCB contains a single |
| 8084 | * BDE then it is converted to a single sli_sge. |
| 8085 | * The IOCB is still in cpu endianess so the contents of |
| 8086 | * the bpl can be used without byte swapping. |
| 8087 | * |
| 8088 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8089 | **/ |
| 8090 | static uint16_t |
| 8091 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8092 | struct lpfc_sglq *sglq) |
| 8093 | { |
| 8094 | uint16_t xritag = NO_XRI; |
| 8095 | struct ulp_bde64 *bpl = NULL; |
| 8096 | struct ulp_bde64 bde; |
| 8097 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8098 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8099 | IOCB_t *icmd; |
| 8100 | int numBdes = 0; |
| 8101 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8102 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8103 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8104 | |
| 8105 | if (!piocbq || !sglq) |
| 8106 | return xritag; |
| 8107 | |
| 8108 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8109 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8110 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8111 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8112 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8113 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8114 | sizeof(struct ulp_bde64); |
| 8115 | /* The addrHigh and addrLow fields within the IOCB |
| 8116 | * have not been byteswapped yet so there is no |
| 8117 | * need to swap them back. |
| 8118 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8119 | if (piocbq->context3) |
| 8120 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8121 | else |
| 8122 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8123 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8124 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8125 | if (!bpl) |
| 8126 | return xritag; |
| 8127 | |
| 8128 | for (i = 0; i < numBdes; i++) { |
| 8129 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8130 | sgl->addr_hi = bpl->addrHigh; |
| 8131 | sgl->addr_lo = bpl->addrLow; |
| 8132 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8133 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8134 | if ((i+1) == numBdes) |
| 8135 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8136 | else |
| 8137 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8138 | /* swap the size field back to the cpu so we |
| 8139 | * can assign it to the sgl. |
| 8140 | */ |
| 8141 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8142 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8143 | /* The offsets in the sgl need to be accumulated |
| 8144 | * separately for the request and reply lists. |
| 8145 | * The request is always first, the reply follows. |
| 8146 | */ |
| 8147 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8148 | /* add up the reply sg entries */ |
| 8149 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8150 | inbound++; |
| 8151 | /* first inbound? reset the offset */ |
| 8152 | if (inbound == 1) |
| 8153 | offset = 0; |
| 8154 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8155 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8156 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8157 | offset += bde.tus.f.bdeSize; |
| 8158 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8159 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8160 | bpl++; |
| 8161 | sgl++; |
| 8162 | } |
| 8163 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8164 | /* The addrHigh and addrLow fields of the BDE have not |
| 8165 | * been byteswapped yet so they need to be swapped |
| 8166 | * before putting them in the sgl. |
| 8167 | */ |
| 8168 | sgl->addr_hi = |
| 8169 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8170 | sgl->addr_lo = |
| 8171 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8172 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8173 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8174 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8175 | sgl->sge_len = |
| 8176 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8177 | } |
| 8178 | return sglq->sli4_xritag; |
| 8179 | } |
| 8180 | |
| 8181 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8182 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8183 | * @phba: Pointer to HBA context object. |
| 8184 | * @piocb: Pointer to command iocb. |
| 8185 | * @wqe: Pointer to the work queue entry. |
| 8186 | * |
| 8187 | * This routine converts the iocb command to its Work Queue Entry |
| 8188 | * equivalent. The wqe pointer should not have any fields set when |
| 8189 | * this routine is called because it will memcpy over them. |
| 8190 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8191 | * wqe. |
| 8192 | * |
| 8193 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8194 | **/ |
| 8195 | static int |
| 8196 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8197 | union lpfc_wqe *wqe) |
| 8198 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8199 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8200 | uint8_t ct = 0; |
| 8201 | uint32_t fip; |
| 8202 | uint32_t abort_tag; |
| 8203 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8204 | uint8_t cmnd; |
| 8205 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8206 | uint16_t abrt_iotag; |
| 8207 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8208 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8209 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8210 | int numBdes, i; |
| 8211 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8212 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8213 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8214 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8215 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8216 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8217 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8218 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8219 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8220 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8221 | command_type = ELS_COMMAND_FIP; |
| 8222 | else |
| 8223 | command_type = ELS_COMMAND_NON_FIP; |
| 8224 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8225 | if (phba->fcp_embed_io) |
| 8226 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8227 | /* Some of the fields are in the right position already */ |
| 8228 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8229 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
James Smart | 28d7f3d | 2014-05-21 08:05:28 -0400 | [diff] [blame] | 8230 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8231 | |
| 8232 | abort_tag = (uint32_t) iocbq->iotag; |
| 8233 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8234 | /* words0-2 bpl convert bde */ |
| 8235 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8236 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8237 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8238 | bpl = (struct ulp_bde64 *) |
| 8239 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8240 | if (!bpl) |
| 8241 | return IOCB_ERROR; |
| 8242 | |
| 8243 | /* Should already be byte swapped. */ |
| 8244 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8245 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8246 | /* swap the size field back to the cpu so we |
| 8247 | * can assign it to the sgl. |
| 8248 | */ |
| 8249 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8250 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8251 | total_len = 0; |
| 8252 | for (i = 0; i < numBdes; i++) { |
| 8253 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8254 | total_len += bde.tus.f.bdeSize; |
| 8255 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8256 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8257 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8258 | |
| 8259 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8260 | cmnd = iocbq->iocb.ulpCommand; |
| 8261 | |
| 8262 | switch (iocbq->iocb.ulpCommand) { |
| 8263 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8264 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8265 | ndlp = iocbq->context_un.ndlp; |
| 8266 | else |
| 8267 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8268 | if (!iocbq->iocb.ulpLe) { |
| 8269 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8270 | "2007 Only Limited Edition cmd Format" |
| 8271 | " supported 0x%x\n", |
| 8272 | iocbq->iocb.ulpCommand); |
| 8273 | return IOCB_ERROR; |
| 8274 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8275 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8276 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8277 | /* Els_reguest64 has a TMO */ |
| 8278 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8279 | iocbq->iocb.ulpTimeout); |
| 8280 | /* Need a VF for word 4 set the vf bit*/ |
| 8281 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8282 | /* And a VFID for word 12 */ |
| 8283 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8284 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8285 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8286 | iocbq->iocb.ulpContext); |
| 8287 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8288 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8289 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8290 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8291 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8292 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8293 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8294 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8295 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8296 | &phba->sli4_hba.sli_intf); |
| 8297 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8298 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8299 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8300 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8301 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8302 | *pcmd == ELS_CMD_PLOGI)) { |
| 8303 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8304 | bf_set(els_req64_sid, &wqe->els_req, |
| 8305 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8306 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8307 | !(phba->fc_topology == |
| 8308 | LPFC_TOPOLOGY_LOOP)) |
| 8309 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8310 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8311 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8312 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8313 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8314 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8315 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8316 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8317 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8318 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8319 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8320 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8321 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8322 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8323 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8324 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8325 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8326 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8327 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8328 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8329 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8330 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8331 | iocbq->iocb.un.ulpWord[3]); |
| 8332 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8333 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8334 | /* The entire sequence is transmitted for this IOCB */ |
| 8335 | xmit_len = total_len; |
| 8336 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8337 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8338 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8339 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8340 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8341 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8342 | /* word4 relative_offset memcpy */ |
| 8343 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8344 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8345 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8346 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8347 | LPFC_WQE_IOD_WRITE); |
| 8348 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8349 | LPFC_WQE_LENLOC_WORD12); |
| 8350 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8351 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8352 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8353 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8354 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8355 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8356 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8357 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8358 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8359 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8360 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8361 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8362 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8363 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8364 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8365 | LPFC_WQE_LENLOC_WORD3); |
| 8366 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8367 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8368 | case CMD_FCP_IWRITE64_CR: |
| 8369 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8370 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8371 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8372 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8373 | xmit_len + sizeof(struct fcp_rsp)); |
| 8374 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8375 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8376 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8377 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8378 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8379 | iocbq->iocb.ulpFCP2Rcvy); |
| 8380 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8381 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8382 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8383 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8384 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8385 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8386 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8387 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8388 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
| 8389 | if (phba->cfg_XLanePriority) { |
| 8390 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8391 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8392 | (phba->cfg_XLanePriority << 1)); |
| 8393 | } |
| 8394 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8395 | /* Note, word 10 is already initialized to 0 */ |
| 8396 | |
| 8397 | if (phba->fcp_embed_io) { |
| 8398 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8399 | struct sli4_sge *sgl; |
| 8400 | union lpfc_wqe128 *wqe128; |
| 8401 | struct fcp_cmnd *fcp_cmnd; |
| 8402 | uint32_t *ptr; |
| 8403 | |
| 8404 | /* 128 byte wqe support here */ |
| 8405 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8406 | |
| 8407 | lpfc_cmd = iocbq->context1; |
| 8408 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8409 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8410 | |
| 8411 | /* Word 0-2 - FCP_CMND */ |
| 8412 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8413 | BUFF_TYPE_BDE_IMMED; |
| 8414 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8415 | wqe128->generic.bde.addrHigh = 0; |
| 8416 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8417 | |
| 8418 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8419 | |
| 8420 | /* Word 22-29 FCP CMND Payload */ |
| 8421 | ptr = &wqe128->words[22]; |
| 8422 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8423 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8424 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8425 | case CMD_FCP_IREAD64_CR: |
| 8426 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8427 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8428 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8429 | xmit_len + sizeof(struct fcp_rsp)); |
| 8430 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8431 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8432 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8433 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8434 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8435 | iocbq->iocb.ulpFCP2Rcvy); |
| 8436 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8437 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8438 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8439 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8440 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8441 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8442 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8443 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8444 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
| 8445 | if (phba->cfg_XLanePriority) { |
| 8446 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8447 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8448 | (phba->cfg_XLanePriority << 1)); |
| 8449 | } |
| 8450 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8451 | /* Note, word 10 is already initialized to 0 */ |
| 8452 | |
| 8453 | if (phba->fcp_embed_io) { |
| 8454 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8455 | struct sli4_sge *sgl; |
| 8456 | union lpfc_wqe128 *wqe128; |
| 8457 | struct fcp_cmnd *fcp_cmnd; |
| 8458 | uint32_t *ptr; |
| 8459 | |
| 8460 | /* 128 byte wqe support here */ |
| 8461 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8462 | |
| 8463 | lpfc_cmd = iocbq->context1; |
| 8464 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8465 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8466 | |
| 8467 | /* Word 0-2 - FCP_CMND */ |
| 8468 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8469 | BUFF_TYPE_BDE_IMMED; |
| 8470 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8471 | wqe128->generic.bde.addrHigh = 0; |
| 8472 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8473 | |
| 8474 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8475 | |
| 8476 | /* Word 22-29 FCP CMND Payload */ |
| 8477 | ptr = &wqe128->words[22]; |
| 8478 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8479 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8480 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8481 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8482 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8483 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8484 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8485 | xmit_len + sizeof(struct fcp_rsp)); |
| 8486 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8487 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8488 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8489 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8490 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8491 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8492 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8493 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8494 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8495 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8496 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8497 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8498 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8499 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
| 8500 | if (phba->cfg_XLanePriority) { |
| 8501 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8502 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8503 | (phba->cfg_XLanePriority << 1)); |
| 8504 | } |
| 8505 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8506 | /* Note, word 10 is already initialized to 0 */ |
| 8507 | |
| 8508 | if (phba->fcp_embed_io) { |
| 8509 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8510 | struct sli4_sge *sgl; |
| 8511 | union lpfc_wqe128 *wqe128; |
| 8512 | struct fcp_cmnd *fcp_cmnd; |
| 8513 | uint32_t *ptr; |
| 8514 | |
| 8515 | /* 128 byte wqe support here */ |
| 8516 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8517 | |
| 8518 | lpfc_cmd = iocbq->context1; |
| 8519 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8520 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8521 | |
| 8522 | /* Word 0-2 - FCP_CMND */ |
| 8523 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8524 | BUFF_TYPE_BDE_IMMED; |
| 8525 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8526 | wqe128->generic.bde.addrHigh = 0; |
| 8527 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8528 | |
| 8529 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 8530 | |
| 8531 | /* Word 22-29 FCP CMND Payload */ |
| 8532 | ptr = &wqe128->words[22]; |
| 8533 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8534 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8535 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8536 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8537 | /* For this command calculate the xmit length of the |
| 8538 | * request bde. |
| 8539 | */ |
| 8540 | xmit_len = 0; |
| 8541 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8542 | sizeof(struct ulp_bde64); |
| 8543 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8544 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8545 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8546 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8547 | xmit_len += bde.tus.f.bdeSize; |
| 8548 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8549 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8550 | wqe->gen_req.request_payload_len = xmit_len; |
| 8551 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8552 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8553 | /* word6 context tag copied in memcpy */ |
| 8554 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8555 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8557 | "2015 Invalid CT %x command 0x%x\n", |
| 8558 | ct, iocbq->iocb.ulpCommand); |
| 8559 | return IOCB_ERROR; |
| 8560 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8561 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8562 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8563 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8564 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8565 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8566 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8567 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8568 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8569 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8570 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8571 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8572 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8573 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8574 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8575 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8576 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8577 | /* word4 */ |
| 8578 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8579 | /* word5 iocb=rsvd wge=did */ |
| 8580 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8581 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8582 | |
| 8583 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8584 | &phba->sli4_hba.sli_intf); |
| 8585 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8586 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8587 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8588 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8589 | iocbq->vport->fc_myDID); |
| 8590 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8591 | bf_set(wqe_els_did, |
| 8592 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8593 | } |
| 8594 | } |
| 8595 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8596 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8597 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8598 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8599 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8600 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8601 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8602 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8603 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8604 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8605 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8606 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8607 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8608 | LPFC_WQE_LENLOC_WORD3); |
| 8609 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8610 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8611 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8612 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8613 | iocbq->context2)->virt); |
| 8614 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8615 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8616 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8617 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8618 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8619 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8620 | phba->vpi_ids[phba->pport->vpi]); |
| 8621 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8622 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8623 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8624 | case CMD_CLOSE_XRI_CN: |
| 8625 | case CMD_ABORT_XRI_CN: |
| 8626 | case CMD_ABORT_XRI_CX: |
| 8627 | /* words 0-2 memcpy should be 0 rserved */ |
| 8628 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8629 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8630 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8631 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8632 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8633 | } else |
| 8634 | fip = 0; |
| 8635 | |
| 8636 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8637 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8638 | * The link is down, or the command was ELS_FIP |
| 8639 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8640 | * on the wire. |
| 8641 | */ |
| 8642 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8643 | else |
| 8644 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8645 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8646 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8647 | wqe->abort_cmd.rsrvd5 = 0; |
| 8648 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8649 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8650 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8651 | /* |
| 8652 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8653 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8654 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8655 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8656 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8657 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8658 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8659 | cmnd = CMD_ABORT_XRI_CX; |
| 8660 | command_type = OTHER_COMMAND; |
| 8661 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8662 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8663 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8664 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8665 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8666 | * we re-construct this WQE here based on information in |
| 8667 | * iocbq from scratch. |
| 8668 | */ |
| 8669 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8670 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8671 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8672 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8673 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8674 | LPFC_ABTS_UNSOL_INT) { |
| 8675 | /* ABTS sent by initiator to CT exchange, the |
| 8676 | * RX_ID field will be filled with the newly |
| 8677 | * allocated responder XRI. |
| 8678 | */ |
| 8679 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8680 | iocbq->sli4_xritag); |
| 8681 | } else { |
| 8682 | /* ABTS sent by responder to CT exchange, the |
| 8683 | * RX_ID field will be filled with the responder |
| 8684 | * RX_ID from ABTS. |
| 8685 | */ |
| 8686 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8687 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8688 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8689 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8690 | 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] | 8691 | |
| 8692 | /* Use CT=VPI */ |
| 8693 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8694 | ndlp->nlp_DID); |
| 8695 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8696 | iocbq->iocb.ulpContext); |
| 8697 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8698 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8699 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8700 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8701 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8702 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8703 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8704 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8705 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8706 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8707 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8708 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8709 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8710 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8711 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8712 | } |
| 8713 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8714 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8715 | case CMD_XRI_ABORTED_CX: |
| 8716 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8717 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8718 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8719 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8720 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8721 | default: |
| 8722 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8723 | "2014 Invalid command 0x%x\n", |
| 8724 | iocbq->iocb.ulpCommand); |
| 8725 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8726 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8727 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8728 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8729 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8730 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8731 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8732 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8733 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8734 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8735 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8736 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8737 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8738 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8739 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8740 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8741 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8742 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8743 | 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] | 8744 | return 0; |
| 8745 | } |
| 8746 | |
| 8747 | /** |
| 8748 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8749 | * @phba: Pointer to HBA context object. |
| 8750 | * @ring_number: SLI ring number to issue iocb on. |
| 8751 | * @piocb: Pointer to command iocb. |
| 8752 | * @flag: Flag indicating if this command can be put into txq. |
| 8753 | * |
| 8754 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8755 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8756 | * |
| 8757 | * This function is called with hbalock held. The function will return success |
| 8758 | * after it successfully submit the iocb to firmware or after adding to the |
| 8759 | * txq. |
| 8760 | **/ |
| 8761 | static int |
| 8762 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8763 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8764 | { |
| 8765 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8766 | union lpfc_wqe *wqe; |
| 8767 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8768 | struct lpfc_queue *wq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8769 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8770 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8771 | lockdep_assert_held(&phba->hbalock); |
| 8772 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8773 | /* |
| 8774 | * The WQE can be either 64 or 128 bytes, |
| 8775 | * so allocate space on the stack assuming the largest. |
| 8776 | */ |
| 8777 | wqe = (union lpfc_wqe *)&wqe128; |
| 8778 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8779 | if (piocb->sli4_xritag == NO_XRI) { |
| 8780 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8781 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8782 | sglq = NULL; |
| 8783 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8784 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8785 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8786 | __lpfc_sli_ringtx_put(phba, |
| 8787 | pring, piocb); |
| 8788 | return IOCB_SUCCESS; |
| 8789 | } else { |
| 8790 | return IOCB_BUSY; |
| 8791 | } |
| 8792 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8793 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8794 | if (!sglq) { |
| 8795 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8796 | __lpfc_sli_ringtx_put(phba, |
| 8797 | pring, |
| 8798 | piocb); |
| 8799 | return IOCB_SUCCESS; |
| 8800 | } else |
| 8801 | return IOCB_BUSY; |
| 8802 | } |
| 8803 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8804 | } |
| 8805 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8806 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8807 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8808 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8809 | /* |
| 8810 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8811 | * sglq is on the active list |
| 8812 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8813 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8814 | if (!sglq) |
| 8815 | return IOCB_ERROR; |
| 8816 | } |
| 8817 | |
| 8818 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8819 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8820 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8821 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8822 | return IOCB_ERROR; |
| 8823 | } |
| 8824 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8825 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8826 | return IOCB_ERROR; |
| 8827 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8828 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8829 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 8830 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8831 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
| 8832 | } else { |
| 8833 | wq = phba->sli4_hba.oas_wq; |
| 8834 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8835 | if (lpfc_sli4_wq_put(wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8836 | return IOCB_ERROR; |
| 8837 | } else { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8838 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 8839 | return IOCB_ERROR; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8840 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8841 | return IOCB_ERROR; |
| 8842 | } |
| 8843 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8844 | |
| 8845 | return 0; |
| 8846 | } |
| 8847 | |
| 8848 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8849 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8850 | * |
| 8851 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8852 | * pointer from the lpfc_hba struct. |
| 8853 | * |
| 8854 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame^] | 8855 | * IOCB_ERROR - Error |
| 8856 | * IOCB_SUCCESS - Success |
| 8857 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8858 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8859 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8860 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8861 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8862 | { |
| 8863 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8864 | } |
| 8865 | |
| 8866 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8867 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8868 | * @phba: The hba struct for which this call is being executed. |
| 8869 | * @dev_grp: The HBA PCI-Device group number. |
| 8870 | * |
| 8871 | * This routine sets up the SLI interface API function jump table in @phba |
| 8872 | * struct. |
| 8873 | * Returns: 0 - success, -ENODEV - failure. |
| 8874 | **/ |
| 8875 | int |
| 8876 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8877 | { |
| 8878 | |
| 8879 | switch (dev_grp) { |
| 8880 | case LPFC_PCI_DEV_LP: |
| 8881 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8882 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8883 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8884 | case LPFC_PCI_DEV_OC: |
| 8885 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8886 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8887 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8888 | default: |
| 8889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8890 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8891 | dev_grp); |
| 8892 | return -ENODEV; |
| 8893 | break; |
| 8894 | } |
| 8895 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8896 | return 0; |
| 8897 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8898 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 8899 | /** |
| 8900 | * lpfc_sli_calc_ring - Calculates which ring to use |
| 8901 | * @phba: Pointer to HBA context object. |
| 8902 | * @ring_number: Initial ring |
| 8903 | * @piocb: Pointer to command iocb. |
| 8904 | * |
| 8905 | * For SLI4, FCP IO can deferred to one fo many WQs, based on |
| 8906 | * fcp_wqidx, thus we need to calculate the corresponding ring. |
| 8907 | * Since ABORTS must go on the same WQ of the command they are |
| 8908 | * aborting, we use command's fcp_wqidx. |
| 8909 | */ |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8910 | int |
| 8911 | lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number, |
| 8912 | struct lpfc_iocbq *piocb) |
| 8913 | { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 8914 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8915 | return ring_number; |
| 8916 | |
| 8917 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
| 8918 | if (!(phba->cfg_fof) || |
| 8919 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
| 8920 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8921 | return LPFC_HBA_ERROR; |
| 8922 | /* |
| 8923 | * for abort iocb fcp_wqidx should already |
| 8924 | * be setup based on what work queue we used. |
| 8925 | */ |
| 8926 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) |
| 8927 | piocb->fcp_wqidx = |
| 8928 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 8929 | piocb->context1); |
| 8930 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 8931 | piocb->fcp_wqidx; |
| 8932 | } else { |
| 8933 | if (unlikely(!phba->sli4_hba.oas_wq)) |
| 8934 | return LPFC_HBA_ERROR; |
| 8935 | piocb->fcp_wqidx = 0; |
| 8936 | ring_number = LPFC_FCP_OAS_RING; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8937 | } |
| 8938 | } |
| 8939 | return ring_number; |
| 8940 | } |
| 8941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8943 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8944 | * @phba: Pointer to HBA context object. |
| 8945 | * @pring: Pointer to driver SLI ring object. |
| 8946 | * @piocb: Pointer to command iocb. |
| 8947 | * @flag: Flag indicating if this command can be put into txq. |
| 8948 | * |
| 8949 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8950 | * function. This function gets the hbalock and calls |
| 8951 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8952 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8953 | * functions which do not hold hbalock. |
| 8954 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8955 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8956 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8957 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8958 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8959 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8960 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8961 | struct lpfc_queue *fpeq; |
| 8962 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8963 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8964 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8965 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8966 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8967 | ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb); |
| 8968 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 8969 | return IOCB_ERROR; |
| 8970 | idx = piocb->fcp_wqidx; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8971 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8972 | pring = &phba->sli.ring[ring_number]; |
| 8973 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8974 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8975 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8976 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8977 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
| 8978 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8979 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8980 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 8981 | fcp_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8982 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8983 | /* Get associated EQ with this index */ |
| 8984 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8985 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8986 | /* Turn off interrupts from this EQ */ |
| 8987 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8988 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8989 | /* |
| 8990 | * Process all the events on FCP EQ |
| 8991 | */ |
| 8992 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 8993 | lpfc_sli4_hba_handle_eqe(phba, |
| 8994 | eqe, idx); |
| 8995 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8996 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8997 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8998 | /* Always clear and re-arm the EQ */ |
| 8999 | lpfc_sli4_eq_release(fpeq, |
| 9000 | LPFC_QUEUE_REARM); |
| 9001 | } |
| 9002 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9003 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9004 | } else { |
| 9005 | /* For now, SLI2/3 will still use hbalock */ |
| 9006 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9007 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9008 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9009 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9010 | return rc; |
| 9011 | } |
| 9012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9014 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9015 | * @phba: Pointer to HBA context object. |
| 9016 | * |
| 9017 | * This function is called while driver attaches with the |
| 9018 | * HBA to setup the extra ring. The extra ring is used |
| 9019 | * only when driver needs to support target mode functionality |
| 9020 | * or IP over FC functionalities. |
| 9021 | * |
| 9022 | * This function is called with no lock held. |
| 9023 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9024 | static int |
| 9025 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9026 | { |
| 9027 | struct lpfc_sli *psli; |
| 9028 | struct lpfc_sli_ring *pring; |
| 9029 | |
| 9030 | psli = &phba->sli; |
| 9031 | |
| 9032 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9033 | |
| 9034 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9035 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9036 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9037 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9038 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9039 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9040 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9041 | /* and give them to the extra ring */ |
| 9042 | pring = &psli->ring[psli->extra_ring]; |
| 9043 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9044 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9045 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9046 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9047 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9048 | |
| 9049 | /* Setup default profile for this ring */ |
| 9050 | pring->iotag_max = 4096; |
| 9051 | pring->num_mask = 1; |
| 9052 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9053 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9054 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9055 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9056 | return 0; |
| 9057 | } |
| 9058 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9059 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9060 | * @phba: Pointer to HBA context object. |
| 9061 | * @iocbq: Pointer to iocb object. |
| 9062 | * |
| 9063 | * The async_event handler calls this routine when it receives |
| 9064 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9065 | * this event when an Abort Sequence request to an rport fails |
| 9066 | * twice in succession. The abort could be originated by the |
| 9067 | * driver or by the port. The ABTS could have been for an ELS |
| 9068 | * or FCP IO. The port only generates this event when an ABTS |
| 9069 | * fails to complete after one retry. |
| 9070 | */ |
| 9071 | static void |
| 9072 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9073 | struct lpfc_iocbq *iocbq) |
| 9074 | { |
| 9075 | struct lpfc_nodelist *ndlp = NULL; |
| 9076 | uint16_t rpi = 0, vpi = 0; |
| 9077 | struct lpfc_vport *vport = NULL; |
| 9078 | |
| 9079 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9080 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9081 | rpi = iocbq->iocb.ulpContext; |
| 9082 | |
| 9083 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9084 | "3092 Port generated ABTS async event " |
| 9085 | "on vpi %d rpi %d status 0x%x\n", |
| 9086 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9087 | |
| 9088 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9089 | if (!vport) |
| 9090 | goto err_exit; |
| 9091 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9092 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9093 | goto err_exit; |
| 9094 | |
| 9095 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9096 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9097 | return; |
| 9098 | |
| 9099 | err_exit: |
| 9100 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9101 | "3095 Event Context not found, no " |
| 9102 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9103 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9104 | vpi, rpi); |
| 9105 | } |
| 9106 | |
| 9107 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9108 | * @phba: pointer to HBA context object. |
| 9109 | * @ndlp: nodelist pointer for the impacted rport. |
| 9110 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9111 | * |
| 9112 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9113 | * port. The port generates this event when an abort exchange request to an |
| 9114 | * rport fails twice in succession with no reply. The abort could be originated |
| 9115 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9116 | */ |
| 9117 | void |
| 9118 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9119 | struct lpfc_nodelist *ndlp, |
| 9120 | struct sli4_wcqe_xri_aborted *axri) |
| 9121 | { |
| 9122 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9123 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9124 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9125 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9126 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9127 | "3115 Node Context not found, driver " |
| 9128 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9129 | return; |
| 9130 | } |
| 9131 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9132 | vport = ndlp->vport; |
| 9133 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9134 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9135 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 9136 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9137 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9138 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9139 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9140 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9141 | /* |
| 9142 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9143 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9144 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9145 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9146 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9147 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9148 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9149 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9150 | } |
| 9151 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9152 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9153 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9154 | * @phba: Pointer to HBA context object. |
| 9155 | * @pring: Pointer to driver SLI ring object. |
| 9156 | * @iocbq: Pointer to iocb object. |
| 9157 | * |
| 9158 | * This function is called by the slow ring event handler |
| 9159 | * function when there is an ASYNC event iocb in the ring. |
| 9160 | * This function is called with no lock held. |
| 9161 | * Currently this function handles only temperature related |
| 9162 | * ASYNC events. The function decodes the temperature sensor |
| 9163 | * event message and posts events for the management applications. |
| 9164 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9165 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9166 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9167 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9168 | { |
| 9169 | IOCB_t *icmd; |
| 9170 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9171 | struct temp_event temp_event_data; |
| 9172 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9173 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9174 | |
| 9175 | icmd = &iocbq->iocb; |
| 9176 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9177 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9178 | switch (evt_code) { |
| 9179 | case ASYNC_TEMP_WARN: |
| 9180 | case ASYNC_TEMP_SAFE: |
| 9181 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9182 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9183 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9184 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9185 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9186 | "0347 Adapter is very hot, please take " |
| 9187 | "corrective action. temperature : %d Celsius\n", |
| 9188 | (uint32_t) icmd->ulpContext); |
| 9189 | } else { |
| 9190 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9191 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9192 | "0340 Adapter temperature is OK now. " |
| 9193 | "temperature : %d Celsius\n", |
| 9194 | (uint32_t) icmd->ulpContext); |
| 9195 | } |
| 9196 | |
| 9197 | /* Send temperature change event to applications */ |
| 9198 | shost = lpfc_shost_from_vport(phba->pport); |
| 9199 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9200 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9201 | LPFC_NL_VENDOR_ID); |
| 9202 | break; |
| 9203 | case ASYNC_STATUS_CN: |
| 9204 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9205 | break; |
| 9206 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9207 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9208 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9209 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9210 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9211 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9212 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9213 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9214 | "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] | 9215 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9216 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9217 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9218 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9219 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9220 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9221 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9222 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9223 | } |
| 9224 | |
| 9225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9226 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9227 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9228 | * @phba: Pointer to HBA context object. |
| 9229 | * |
| 9230 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9231 | * number of iocbs per ring and iotags. This function is |
| 9232 | * called while driver attach to the HBA and before the |
| 9233 | * interrupts are enabled. So there is no need for locking. |
| 9234 | * |
| 9235 | * This function always returns 0. |
| 9236 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9237 | int |
| 9238 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9239 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9240 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9241 | struct lpfc_sli *psli = &phba->sli; |
| 9242 | struct lpfc_sli_ring *pring; |
| 9243 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9244 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 9245 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9246 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9247 | psli->sli_flag = 0; |
| 9248 | psli->fcp_ring = LPFC_FCP_RING; |
| 9249 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9250 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9251 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9252 | psli->iocbq_lookup = NULL; |
| 9253 | psli->iocbq_lookup_len = 0; |
| 9254 | psli->last_iotag = 0; |
| 9255 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9256 | for (i = 0; i < psli->num_rings; i++) { |
| 9257 | pring = &psli->ring[i]; |
| 9258 | switch (i) { |
| 9259 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9260 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9261 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9262 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9263 | pring->sli.sli3.numCiocb += |
| 9264 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9265 | pring->sli.sli3.numRiocb += |
| 9266 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9267 | pring->sli.sli3.numCiocb += |
| 9268 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9269 | pring->sli.sli3.numRiocb += |
| 9270 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9271 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9272 | SLI3_IOCB_CMD_SIZE : |
| 9273 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9274 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9275 | SLI3_IOCB_RSP_SIZE : |
| 9276 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9277 | pring->iotag_ctr = 0; |
| 9278 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9279 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9280 | pring->fast_iotag = pring->iotag_max; |
| 9281 | pring->num_mask = 0; |
| 9282 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9283 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9284 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9285 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9286 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9287 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9288 | SLI3_IOCB_CMD_SIZE : |
| 9289 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9290 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9291 | SLI3_IOCB_RSP_SIZE : |
| 9292 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9293 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9294 | pring->num_mask = 0; |
| 9295 | break; |
| 9296 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9297 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9298 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9299 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9300 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9301 | SLI3_IOCB_CMD_SIZE : |
| 9302 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9303 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9304 | SLI3_IOCB_RSP_SIZE : |
| 9305 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9306 | pring->fast_iotag = 0; |
| 9307 | pring->iotag_ctr = 0; |
| 9308 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9309 | pring->lpfc_sli_rcv_async_status = |
| 9310 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9311 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9312 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9313 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9314 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9315 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9316 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9317 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9318 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9319 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9320 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9321 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9322 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9323 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9324 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9325 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9326 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9327 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9328 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9329 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9330 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9331 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9332 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9333 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9334 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9335 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9336 | break; |
| 9337 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9338 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9339 | pring->sli.sli3.sizeCiocb) + |
| 9340 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9341 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9342 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9343 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9344 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9345 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9346 | phba->brd_no, totiocbsize, |
| 9347 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9348 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9349 | if (phba->cfg_multi_ring_support == 2) |
| 9350 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | |
| 9352 | return 0; |
| 9353 | } |
| 9354 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9355 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9356 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9357 | * @phba: Pointer to HBA context object. |
| 9358 | * |
| 9359 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 9360 | * ring. This function also initializes ring indices of each ring. |
| 9361 | * This function is called during the initialization of the SLI |
| 9362 | * interface of an HBA. |
| 9363 | * This function is called with no lock held and always returns |
| 9364 | * 1. |
| 9365 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9366 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9367 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9368 | { |
| 9369 | struct lpfc_sli *psli; |
| 9370 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9371 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9372 | |
| 9373 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9374 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9375 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9376 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9377 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9378 | for (i = 0; i < psli->num_rings; i++) { |
| 9379 | pring = &psli->ring[i]; |
| 9380 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9381 | pring->sli.sli3.next_cmdidx = 0; |
| 9382 | pring->sli.sli3.local_getidx = 0; |
| 9383 | pring->sli.sli3.cmdidx = 0; |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 9384 | pring->flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9385 | INIT_LIST_HEAD(&pring->txq); |
| 9386 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9387 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9388 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9389 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9390 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9391 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9392 | spin_unlock_irq(&phba->hbalock); |
| 9393 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9394 | } |
| 9395 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9396 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9397 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9398 | * @phba: Pointer to HBA context object. |
| 9399 | * |
| 9400 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9401 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9402 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9403 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9404 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9405 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9406 | * pending mailbox command queue from the various clients must be stopped; |
| 9407 | * either the HBA is in a state that it will never works on the outstanding |
| 9408 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9409 | * mailbox command has been completed. |
| 9410 | **/ |
| 9411 | static void |
| 9412 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 9413 | { |
| 9414 | LIST_HEAD(completions); |
| 9415 | struct lpfc_sli *psli = &phba->sli; |
| 9416 | LPFC_MBOXQ_t *pmb; |
| 9417 | unsigned long iflag; |
| 9418 | |
| 9419 | /* Flush all the mailbox commands in the mbox system */ |
| 9420 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9421 | /* The pending mailbox command queue */ |
| 9422 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9423 | /* The outstanding active mailbox command */ |
| 9424 | if (psli->mbox_active) { |
| 9425 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9426 | psli->mbox_active = NULL; |
| 9427 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9428 | } |
| 9429 | /* The completed mailbox command queue */ |
| 9430 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9431 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9432 | |
| 9433 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9434 | while (!list_empty(&completions)) { |
| 9435 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9436 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9437 | if (pmb->mbox_cmpl) |
| 9438 | pmb->mbox_cmpl(phba, pmb); |
| 9439 | } |
| 9440 | } |
| 9441 | |
| 9442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9443 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9444 | * @vport: Pointer to virtual port object. |
| 9445 | * |
| 9446 | * lpfc_sli_host_down is called to clean up the resources |
| 9447 | * associated with a vport before destroying virtual |
| 9448 | * port data structures. |
| 9449 | * This function does following operations: |
| 9450 | * - Free discovery resources associated with this virtual |
| 9451 | * port. |
| 9452 | * - Free iocbs associated with this virtual port in |
| 9453 | * the txq. |
| 9454 | * - Send abort for all iocb commands associated with this |
| 9455 | * vport in txcmplq. |
| 9456 | * |
| 9457 | * This function is called with no lock held and always returns 1. |
| 9458 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9459 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9460 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9461 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9462 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9463 | struct lpfc_hba *phba = vport->phba; |
| 9464 | struct lpfc_sli *psli = &phba->sli; |
| 9465 | struct lpfc_sli_ring *pring; |
| 9466 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9467 | int i; |
| 9468 | unsigned long flags = 0; |
| 9469 | uint16_t prev_pring_flag; |
| 9470 | |
| 9471 | lpfc_cleanup_discovery_resources(vport); |
| 9472 | |
| 9473 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9474 | for (i = 0; i < psli->num_rings; i++) { |
| 9475 | pring = &psli->ring[i]; |
| 9476 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9477 | /* Only slow rings */ |
| 9478 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9479 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9480 | /* Set the lpfc data pending flag */ |
| 9481 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9482 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9483 | /* |
| 9484 | * Error everything on the txq since these iocbs have not been |
| 9485 | * given to the FW yet. |
| 9486 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9487 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9488 | if (iocb->vport != vport) |
| 9489 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9490 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9491 | } |
| 9492 | |
| 9493 | /* Next issue ABTS for everything on the txcmplq */ |
| 9494 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9495 | list) { |
| 9496 | if (iocb->vport != vport) |
| 9497 | continue; |
| 9498 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9499 | } |
| 9500 | |
| 9501 | pring->flag = prev_pring_flag; |
| 9502 | } |
| 9503 | |
| 9504 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9505 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9506 | /* Cancel all the IOCBs from the completions list */ |
| 9507 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9508 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9509 | return 1; |
| 9510 | } |
| 9511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9513 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9514 | * @phba: Pointer to HBA context object. |
| 9515 | * |
| 9516 | * This function cleans up all iocb, buffers, mailbox commands |
| 9517 | * while shutting down the HBA. This function is called with no |
| 9518 | * lock held and always returns 1. |
| 9519 | * This function does the following to cleanup driver resources: |
| 9520 | * - Free discovery resources for each virtual port |
| 9521 | * - Cleanup any pending fabric iocbs |
| 9522 | * - Iterate through the iocb txq and free each entry |
| 9523 | * in the list. |
| 9524 | * - Free up any buffer posted to the HBA |
| 9525 | * - Free mailbox commands in the mailbox queue. |
| 9526 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9527 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9528 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9529 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9530 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9531 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9532 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9533 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9534 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9535 | int i; |
| 9536 | |
| 9537 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9538 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9540 | lpfc_hba_down_prep(phba); |
| 9541 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9542 | lpfc_fabric_abort_hba(phba); |
| 9543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9544 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9545 | for (i = 0; i < psli->num_rings; i++) { |
| 9546 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9547 | /* Only slow rings */ |
| 9548 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9549 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9550 | /* Set the lpfc data pending flag */ |
| 9551 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9552 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9553 | |
| 9554 | /* |
| 9555 | * Error everything on the txq since these iocbs have not been |
| 9556 | * given to the FW yet. |
| 9557 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9558 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9559 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9560 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9561 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9562 | /* Cancel all the IOCBs from the completions list */ |
| 9563 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9564 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9565 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9566 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9567 | list_splice_init(&phba->elsbuf, &completions); |
| 9568 | phba->elsbuf_cnt = 0; |
| 9569 | phba->elsbuf_prev_cnt = 0; |
| 9570 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9571 | |
| 9572 | while (!list_empty(&completions)) { |
| 9573 | list_remove_head(&completions, buf_ptr, |
| 9574 | struct lpfc_dmabuf, list); |
| 9575 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9576 | kfree(buf_ptr); |
| 9577 | } |
| 9578 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9579 | /* Return any active mbox cmds */ |
| 9580 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9581 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9582 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9583 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9584 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9585 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9586 | return 1; |
| 9587 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9588 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9590 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9591 | * @srcp: Source memory pointer. |
| 9592 | * @destp: Destination memory pointer. |
| 9593 | * @cnt: Number of words required to be copied. |
| 9594 | * |
| 9595 | * This function is used for copying data between driver memory |
| 9596 | * and the SLI memory. This function also changes the endianness |
| 9597 | * of each word if native endianness is different from SLI |
| 9598 | * endianness. This function can be called with or without |
| 9599 | * lock. |
| 9600 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9601 | void |
| 9602 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9603 | { |
| 9604 | uint32_t *src = srcp; |
| 9605 | uint32_t *dest = destp; |
| 9606 | uint32_t ldata; |
| 9607 | int i; |
| 9608 | |
| 9609 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9610 | ldata = *src; |
| 9611 | ldata = le32_to_cpu(ldata); |
| 9612 | *dest = ldata; |
| 9613 | src++; |
| 9614 | dest++; |
| 9615 | } |
| 9616 | } |
| 9617 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9618 | |
| 9619 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9620 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9621 | * @srcp: Source memory pointer. |
| 9622 | * @destp: Destination memory pointer. |
| 9623 | * @cnt: Number of words required to be copied. |
| 9624 | * |
| 9625 | * This function is used for copying data between a data structure |
| 9626 | * with big endian representation to local endianness. |
| 9627 | * This function can be called with or without lock. |
| 9628 | **/ |
| 9629 | void |
| 9630 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9631 | { |
| 9632 | uint32_t *src = srcp; |
| 9633 | uint32_t *dest = destp; |
| 9634 | uint32_t ldata; |
| 9635 | int i; |
| 9636 | |
| 9637 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9638 | ldata = *src; |
| 9639 | ldata = be32_to_cpu(ldata); |
| 9640 | *dest = ldata; |
| 9641 | src++; |
| 9642 | dest++; |
| 9643 | } |
| 9644 | } |
| 9645 | |
| 9646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9647 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9648 | * @phba: Pointer to HBA context object. |
| 9649 | * @pring: Pointer to driver SLI ring object. |
| 9650 | * @mp: Pointer to driver buffer object. |
| 9651 | * |
| 9652 | * This function is called with no lock held. |
| 9653 | * It always return zero after adding the buffer to the postbufq |
| 9654 | * buffer list. |
| 9655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9656 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9657 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9658 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9659 | { |
| 9660 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9661 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9662 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9663 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9664 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9665 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9666 | return 0; |
| 9667 | } |
| 9668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9670 | * 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] | 9671 | * @phba: Pointer to HBA context object. |
| 9672 | * |
| 9673 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9674 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9675 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9676 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9677 | * The function returns the allocated tag. The function is called with |
| 9678 | * no locks held. |
| 9679 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9680 | uint32_t |
| 9681 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9682 | { |
| 9683 | spin_lock_irq(&phba->hbalock); |
| 9684 | phba->buffer_tag_count++; |
| 9685 | /* |
| 9686 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9687 | * a tag assigned by HBQ. |
| 9688 | */ |
| 9689 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9690 | spin_unlock_irq(&phba->hbalock); |
| 9691 | return phba->buffer_tag_count; |
| 9692 | } |
| 9693 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9694 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9695 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9696 | * @phba: Pointer to HBA context object. |
| 9697 | * @pring: Pointer to driver SLI ring object. |
| 9698 | * @tag: Buffer tag. |
| 9699 | * |
| 9700 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9701 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9702 | * iocb is posted to the response ring with the tag of the buffer. |
| 9703 | * This function searches the pring->postbufq list using the tag |
| 9704 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9705 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9706 | * buffer is returned to the caller else NULL is returned. |
| 9707 | * This function is called with no lock held. |
| 9708 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9709 | struct lpfc_dmabuf * |
| 9710 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9711 | uint32_t tag) |
| 9712 | { |
| 9713 | struct lpfc_dmabuf *mp, *next_mp; |
| 9714 | struct list_head *slp = &pring->postbufq; |
| 9715 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9716 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9717 | spin_lock_irq(&phba->hbalock); |
| 9718 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9719 | if (mp->buffer_tag == tag) { |
| 9720 | list_del_init(&mp->list); |
| 9721 | pring->postbufq_cnt--; |
| 9722 | spin_unlock_irq(&phba->hbalock); |
| 9723 | return mp; |
| 9724 | } |
| 9725 | } |
| 9726 | |
| 9727 | spin_unlock_irq(&phba->hbalock); |
| 9728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9729 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9730 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9731 | pring->ringno, (unsigned long) tag, |
| 9732 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9733 | |
| 9734 | return NULL; |
| 9735 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9737 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9738 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9739 | * @phba: Pointer to HBA context object. |
| 9740 | * @pring: Pointer to driver SLI ring object. |
| 9741 | * @phys: DMA address of the buffer. |
| 9742 | * |
| 9743 | * This function searches the buffer list using the dma_address |
| 9744 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9745 | * corresponding to the dma_address. The function returns the |
| 9746 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9747 | * This function is called by the ct and els unsolicited event |
| 9748 | * handlers to get the buffer associated with the unsolicited |
| 9749 | * event. |
| 9750 | * |
| 9751 | * This function is called with no lock held. |
| 9752 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9753 | struct lpfc_dmabuf * |
| 9754 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9755 | dma_addr_t phys) |
| 9756 | { |
| 9757 | struct lpfc_dmabuf *mp, *next_mp; |
| 9758 | struct list_head *slp = &pring->postbufq; |
| 9759 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9760 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9761 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9762 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9763 | if (mp->phys == phys) { |
| 9764 | list_del_init(&mp->list); |
| 9765 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9766 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9767 | return mp; |
| 9768 | } |
| 9769 | } |
| 9770 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9771 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9772 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9773 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9774 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9775 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9776 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9777 | return NULL; |
| 9778 | } |
| 9779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9781 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9782 | * @phba: Pointer to HBA context object. |
| 9783 | * @cmdiocb: Pointer to driver command iocb object. |
| 9784 | * @rspiocb: Pointer to driver response iocb object. |
| 9785 | * |
| 9786 | * This function is the completion handler for the abort iocbs for |
| 9787 | * ELS commands. This function is called from the ELS ring event |
| 9788 | * handler with no lock held. This function frees memory resources |
| 9789 | * associated with the abort iocb. |
| 9790 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9791 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9792 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9793 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9794 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9795 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9796 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9797 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9798 | |
| 9799 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9800 | |
| 9801 | /* |
| 9802 | * Assume that the port already completed and returned, or |
| 9803 | * will return the iocb. Just Log the message. |
| 9804 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9805 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9806 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9807 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9808 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9809 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9810 | if (abort_iotag != 0 && |
| 9811 | abort_iotag <= phba->sli.last_iotag) |
| 9812 | abort_iocb = |
| 9813 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9814 | } else |
| 9815 | /* For sli4 the abort_tag is the XRI, |
| 9816 | * so the abort routine puts the iotag of the iocb |
| 9817 | * being aborted in the context field of the abort |
| 9818 | * IOCB. |
| 9819 | */ |
| 9820 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9821 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9822 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9823 | "0327 Cannot abort els iocb %p " |
| 9824 | "with tag %x context %x, abort status %x, " |
| 9825 | "abort code %x\n", |
| 9826 | abort_iocb, abort_iotag, abort_context, |
| 9827 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9828 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9829 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9830 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9831 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9832 | return; |
| 9833 | } |
| 9834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9836 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9837 | * @phba: Pointer to HBA context object. |
| 9838 | * @cmdiocb: Pointer to driver command iocb object. |
| 9839 | * @rspiocb: Pointer to driver response iocb object. |
| 9840 | * |
| 9841 | * The function is called from SLI ring event handler with no |
| 9842 | * lock held. This function is the completion handler for ELS commands |
| 9843 | * which are aborted. The function frees memory resources used for |
| 9844 | * the aborted ELS commands. |
| 9845 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9846 | static void |
| 9847 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9848 | struct lpfc_iocbq *rspiocb) |
| 9849 | { |
| 9850 | IOCB_t *irsp = &rspiocb->iocb; |
| 9851 | |
| 9852 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9853 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9854 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9855 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9856 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9857 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9858 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9859 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9860 | else |
| 9861 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9862 | return; |
| 9863 | } |
| 9864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9865 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9866 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9867 | * @phba: Pointer to HBA context object. |
| 9868 | * @pring: Pointer to driver SLI ring object. |
| 9869 | * @cmdiocb: Pointer to driver command iocb object. |
| 9870 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9871 | * This function issues an abort iocb for the provided command iocb down to |
| 9872 | * the port. Other than the case the outstanding command iocb is an abort |
| 9873 | * request, this function issues abort out unconditionally. This function is |
| 9874 | * called with hbalock held. The function returns 0 when it fails due to |
| 9875 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9876 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9877 | static int |
| 9878 | 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] | 9879 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9880 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9881 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9882 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9883 | IOCB_t *icmd = NULL; |
| 9884 | IOCB_t *iabt = NULL; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9885 | int ring_number; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9886 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9887 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9888 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9889 | lockdep_assert_held(&phba->hbalock); |
| 9890 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9891 | /* |
| 9892 | * There are certain command types we don't want to abort. And we |
| 9893 | * don't want to abort commands that are already in the process of |
| 9894 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9895 | */ |
| 9896 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9897 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9898 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9899 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9900 | return 0; |
| 9901 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9902 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9903 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9904 | if (abtsiocbp == NULL) |
| 9905 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9906 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9907 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9908 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9909 | */ |
| 9910 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9912 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9913 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9914 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9915 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9916 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9917 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9918 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9919 | else |
| 9920 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9921 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9922 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9923 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9924 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9925 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9926 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9927 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9928 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 9929 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9930 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9931 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9932 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9933 | else |
| 9934 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9935 | |
| 9936 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9937 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9938 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9939 | "0339 Abort xri x%x, original iotag x%x, " |
| 9940 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9941 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9942 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9943 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9944 | |
| 9945 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9946 | ring_number = |
| 9947 | lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp); |
| 9948 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 9949 | return 0; |
| 9950 | pring = &phba->sli.ring[ring_number]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9951 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9952 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9953 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9954 | abtsiocbp, 0); |
| 9955 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9956 | } else { |
| 9957 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9958 | abtsiocbp, 0); |
| 9959 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9960 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9961 | if (retval) |
| 9962 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9963 | |
| 9964 | /* |
| 9965 | * Caller to this routine should check for IOCB_ERROR |
| 9966 | * and handle it properly. This routine no longer removes |
| 9967 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9968 | */ |
| 9969 | return retval; |
| 9970 | } |
| 9971 | |
| 9972 | /** |
| 9973 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9974 | * @phba: Pointer to HBA context object. |
| 9975 | * @pring: Pointer to driver SLI ring object. |
| 9976 | * @cmdiocb: Pointer to driver command iocb object. |
| 9977 | * |
| 9978 | * This function issues an abort iocb for the provided command iocb. In case |
| 9979 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9980 | * ring. Instead, the callback function shall be changed to those commands |
| 9981 | * so that nothing happens when them finishes. This function is called with |
| 9982 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9983 | * request. |
| 9984 | **/ |
| 9985 | int |
| 9986 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9987 | struct lpfc_iocbq *cmdiocb) |
| 9988 | { |
| 9989 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9990 | int retval = IOCB_ERROR; |
| 9991 | IOCB_t *icmd = NULL; |
| 9992 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9993 | lockdep_assert_held(&phba->hbalock); |
| 9994 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9995 | /* |
| 9996 | * There are certain command types we don't want to abort. And we |
| 9997 | * don't want to abort commands that are already in the process of |
| 9998 | * being aborted. |
| 9999 | */ |
| 10000 | icmd = &cmdiocb->iocb; |
| 10001 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10002 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10003 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10004 | return 0; |
| 10005 | |
| 10006 | /* |
| 10007 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10008 | * the callback so that nothing happens when it finishes. |
| 10009 | */ |
| 10010 | if ((vport->load_flag & FC_UNLOADING) && |
| 10011 | (pring->ringno == LPFC_ELS_RING)) { |
| 10012 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10013 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10014 | else |
| 10015 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10016 | goto abort_iotag_exit; |
| 10017 | } |
| 10018 | |
| 10019 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10020 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10021 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10022 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10023 | /* |
| 10024 | * Caller to this routine should check for IOCB_ERROR |
| 10025 | * and handle it properly. This routine no longer removes |
| 10026 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10027 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10028 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10029 | } |
| 10030 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10031 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10032 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10033 | * @phba: pointer to lpfc HBA data structure. |
| 10034 | * |
| 10035 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10036 | **/ |
| 10037 | void |
| 10038 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10039 | { |
| 10040 | struct lpfc_sli *psli = &phba->sli; |
| 10041 | struct lpfc_sli_ring *pring; |
| 10042 | int i; |
| 10043 | |
| 10044 | for (i = 0; i < psli->num_rings; i++) { |
| 10045 | pring = &psli->ring[i]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10046 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10047 | } |
| 10048 | } |
| 10049 | |
| 10050 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10051 | * 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] | 10052 | * @iocbq: Pointer to driver iocb object. |
| 10053 | * @vport: Pointer to driver virtual port object. |
| 10054 | * @tgt_id: SCSI ID of the target. |
| 10055 | * @lun_id: LUN ID of the scsi device. |
| 10056 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10057 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10058 | * 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] | 10059 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10060 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10061 | * 1 if the filtering criteria is not met. |
| 10062 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10063 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10064 | * lun_id parameter. |
| 10065 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10066 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10067 | * parameters. |
| 10068 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10069 | * given iocb is for the SCSI host associated with the given vport. |
| 10070 | * This function is called with no locks held. |
| 10071 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10072 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10073 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10074 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10075 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10076 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10077 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10078 | int rc = 1; |
| 10079 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10080 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10081 | return rc; |
| 10082 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10083 | if (iocbq->vport != vport) |
| 10084 | return rc; |
| 10085 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10086 | 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] | 10087 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10088 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10089 | return rc; |
| 10090 | |
| 10091 | switch (ctx_cmd) { |
| 10092 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10093 | if ((lpfc_cmd->rdata->pnode) && |
| 10094 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10095 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10096 | rc = 0; |
| 10097 | break; |
| 10098 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10099 | if ((lpfc_cmd->rdata->pnode) && |
| 10100 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10101 | rc = 0; |
| 10102 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10103 | case LPFC_CTX_HOST: |
| 10104 | rc = 0; |
| 10105 | break; |
| 10106 | default: |
| 10107 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10108 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10109 | break; |
| 10110 | } |
| 10111 | |
| 10112 | return rc; |
| 10113 | } |
| 10114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10116 | * 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] | 10117 | * @vport: Pointer to virtual port. |
| 10118 | * @tgt_id: SCSI ID of the target. |
| 10119 | * @lun_id: LUN ID of the scsi device. |
| 10120 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10121 | * |
| 10122 | * This function returns number of FCP commands pending for the vport. |
| 10123 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10124 | * commands pending on the vport associated with SCSI device specified |
| 10125 | * by tgt_id and lun_id parameters. |
| 10126 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10127 | * commands pending on the vport associated with SCSI target specified |
| 10128 | * by tgt_id parameter. |
| 10129 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10130 | * commands pending on the vport. |
| 10131 | * This function returns the number of iocbs which satisfy the filter. |
| 10132 | * This function is called without any lock held. |
| 10133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10134 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10135 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10136 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10137 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10138 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10139 | struct lpfc_iocbq *iocbq; |
| 10140 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10141 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10142 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10143 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10144 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10145 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10146 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10147 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10148 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10149 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10150 | return sum; |
| 10151 | } |
| 10152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10153 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10154 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10155 | * @phba: Pointer to HBA context object |
| 10156 | * @cmdiocb: Pointer to command iocb object. |
| 10157 | * @rspiocb: Pointer to response iocb object. |
| 10158 | * |
| 10159 | * This function is called when an aborted FCP iocb completes. This |
| 10160 | * function is called by the ring event handler with no lock held. |
| 10161 | * This function frees the iocb. |
| 10162 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10163 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10164 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10165 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10166 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10167 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10168 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10169 | "original iotag x%x, abort cmd iotag x%x " |
| 10170 | "status 0x%x, reason 0x%x\n", |
| 10171 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10172 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10173 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10174 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10175 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10176 | return; |
| 10177 | } |
| 10178 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10179 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10180 | * 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] | 10181 | * @vport: Pointer to virtual port. |
| 10182 | * @pring: Pointer to driver SLI ring object. |
| 10183 | * @tgt_id: SCSI ID of the target. |
| 10184 | * @lun_id: LUN ID of the scsi device. |
| 10185 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10186 | * |
| 10187 | * This function sends an abort command for every SCSI command |
| 10188 | * associated with the given virtual port pending on the ring |
| 10189 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10190 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10191 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10192 | * parameters |
| 10193 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10194 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10195 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10196 | * FCP iocbs associated with virtual port. |
| 10197 | * This function returns number of iocbs it failed to abort. |
| 10198 | * This function is called with no locks held. |
| 10199 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10200 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10201 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10202 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10203 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10204 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10205 | struct lpfc_iocbq *iocbq; |
| 10206 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10207 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10208 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10209 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10210 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10211 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10212 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10213 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10214 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10215 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10216 | continue; |
| 10217 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10218 | /* |
| 10219 | * If the iocbq is already being aborted, don't take a second |
| 10220 | * action, but do count it. |
| 10221 | */ |
| 10222 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10223 | continue; |
| 10224 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10225 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10226 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10227 | if (abtsiocb == NULL) { |
| 10228 | errcnt++; |
| 10229 | continue; |
| 10230 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10231 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10232 | /* indicate the IO is being aborted by the driver. */ |
| 10233 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10234 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10235 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10236 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10237 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10238 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10239 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 10240 | else |
| 10241 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10242 | abtsiocb->iocb.ulpLe = 1; |
| 10243 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10244 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10245 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10246 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10247 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10248 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10249 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10250 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10251 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10252 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10253 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10254 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10255 | else |
| 10256 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10257 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10258 | /* Setup callback routine and issue the command. */ |
| 10259 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10260 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10261 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10262 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10263 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10264 | errcnt++; |
| 10265 | continue; |
| 10266 | } |
| 10267 | } |
| 10268 | |
| 10269 | return errcnt; |
| 10270 | } |
| 10271 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10272 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10273 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 10274 | * @vport: Pointer to virtual port. |
| 10275 | * @pring: Pointer to driver SLI ring object. |
| 10276 | * @tgt_id: SCSI ID of the target. |
| 10277 | * @lun_id: LUN ID of the scsi device. |
| 10278 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10279 | * |
| 10280 | * This function sends an abort command for every SCSI command |
| 10281 | * associated with the given virtual port pending on the ring |
| 10282 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10283 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10284 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10285 | * parameters |
| 10286 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10287 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10288 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10289 | * FCP iocbs associated with virtual port. |
| 10290 | * This function returns number of iocbs it aborted . |
| 10291 | * This function is called with no locks held right after a taskmgmt |
| 10292 | * command is sent. |
| 10293 | **/ |
| 10294 | int |
| 10295 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10296 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 10297 | { |
| 10298 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10299 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10300 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10301 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10302 | struct lpfc_iocbq *iocbq; |
| 10303 | IOCB_t *icmd; |
| 10304 | int sum, i, ret_val; |
| 10305 | unsigned long iflags; |
| 10306 | struct lpfc_sli_ring *pring_s4; |
| 10307 | uint32_t ring_number; |
| 10308 | |
| 10309 | spin_lock_irq(&phba->hbalock); |
| 10310 | |
| 10311 | /* all I/Os are in process of being flushed */ |
| 10312 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 10313 | spin_unlock_irq(&phba->hbalock); |
| 10314 | return 0; |
| 10315 | } |
| 10316 | sum = 0; |
| 10317 | |
| 10318 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10319 | iocbq = phba->sli.iocbq_lookup[i]; |
| 10320 | |
| 10321 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 10322 | cmd) != 0) |
| 10323 | continue; |
| 10324 | |
| 10325 | /* |
| 10326 | * If the iocbq is already being aborted, don't take a second |
| 10327 | * action, but do count it. |
| 10328 | */ |
| 10329 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10330 | continue; |
| 10331 | |
| 10332 | /* issue ABTS for this IOCB based on iotag */ |
| 10333 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 10334 | if (abtsiocbq == NULL) |
| 10335 | continue; |
| 10336 | |
| 10337 | icmd = &iocbq->iocb; |
| 10338 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10339 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 10340 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10341 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 10342 | iocbq->sli4_xritag; |
| 10343 | else |
| 10344 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 10345 | abtsiocbq->iocb.ulpLe = 1; |
| 10346 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 10347 | abtsiocbq->vport = vport; |
| 10348 | |
| 10349 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10350 | abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx; |
| 10351 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10352 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10353 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10354 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10355 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10356 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 10357 | ndlp = lpfc_cmd->rdata->pnode; |
| 10358 | |
| 10359 | if (lpfc_is_link_up(phba) && |
| 10360 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10361 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10362 | else |
| 10363 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10364 | |
| 10365 | /* Setup callback routine and issue the command. */ |
| 10366 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 10367 | |
| 10368 | /* |
| 10369 | * Indicate the IO is being aborted by the driver and set |
| 10370 | * the caller's flag into the aborted IO. |
| 10371 | */ |
| 10372 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10373 | |
| 10374 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 10375 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 10376 | iocbq->fcp_wqidx; |
| 10377 | pring_s4 = &phba->sli.ring[ring_number]; |
| 10378 | /* Note: both hbalock and ring_lock must be set here */ |
| 10379 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 10380 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 10381 | abtsiocbq, 0); |
| 10382 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 10383 | } else { |
| 10384 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10385 | abtsiocbq, 0); |
| 10386 | } |
| 10387 | |
| 10388 | |
| 10389 | if (ret_val == IOCB_ERROR) |
| 10390 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 10391 | else |
| 10392 | sum++; |
| 10393 | } |
| 10394 | spin_unlock_irq(&phba->hbalock); |
| 10395 | return sum; |
| 10396 | } |
| 10397 | |
| 10398 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10399 | * 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] | 10400 | * @phba: Pointer to HBA context object. |
| 10401 | * @cmdiocbq: Pointer to command iocb. |
| 10402 | * @rspiocbq: Pointer to response iocb. |
| 10403 | * |
| 10404 | * This function is the completion handler for iocbs issued using |
| 10405 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 10406 | * ring event handler function without any lock held. This function |
| 10407 | * can be called from both worker thread context and interrupt |
| 10408 | * context. This function also can be called from other thread which |
| 10409 | * cleans up the SLI layer objects. |
| 10410 | * This function copy the contents of the response iocb to the |
| 10411 | * response iocb memory object provided by the caller of |
| 10412 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 10413 | * sleeps for the iocb completion. |
| 10414 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10415 | static void |
| 10416 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 10417 | struct lpfc_iocbq *cmdiocbq, |
| 10418 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10419 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10420 | wait_queue_head_t *pdone_q; |
| 10421 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10422 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10423 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10424 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10425 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 10426 | |
| 10427 | /* |
| 10428 | * A time out has occurred for the iocb. If a time out |
| 10429 | * completion handler has been supplied, call it. Otherwise, |
| 10430 | * just free the iocbq. |
| 10431 | */ |
| 10432 | |
| 10433 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10434 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 10435 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 10436 | if (cmdiocbq->iocb_cmpl) |
| 10437 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 10438 | else |
| 10439 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 10440 | return; |
| 10441 | } |
| 10442 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10443 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 10444 | if (cmdiocbq->context2 && rspiocbq) |
| 10445 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 10446 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 10447 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10448 | /* Set the exchange busy flag for task management commands */ |
| 10449 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 10450 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 10451 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 10452 | cur_iocbq); |
| 10453 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 10454 | } |
| 10455 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10456 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10457 | if (pdone_q) |
| 10458 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10459 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10460 | return; |
| 10461 | } |
| 10462 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10463 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10464 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 10465 | * @phba: Pointer to HBA context object.. |
| 10466 | * @piocbq: Pointer to command iocb. |
| 10467 | * @flag: Flag to test. |
| 10468 | * |
| 10469 | * This routine grabs the hbalock and then test the iocb_flag to |
| 10470 | * see if the passed in flag is set. |
| 10471 | * Returns: |
| 10472 | * 1 if flag is set. |
| 10473 | * 0 if flag is not set. |
| 10474 | **/ |
| 10475 | static int |
| 10476 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 10477 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 10478 | { |
| 10479 | unsigned long iflags; |
| 10480 | int ret; |
| 10481 | |
| 10482 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10483 | ret = piocbq->iocb_flag & flag; |
| 10484 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10485 | return ret; |
| 10486 | |
| 10487 | } |
| 10488 | |
| 10489 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10490 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10491 | * @phba: Pointer to HBA context object.. |
| 10492 | * @pring: Pointer to sli ring. |
| 10493 | * @piocb: Pointer to command iocb. |
| 10494 | * @prspiocbq: Pointer to response iocb. |
| 10495 | * @timeout: Timeout in number of seconds. |
| 10496 | * |
| 10497 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10498 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 10499 | * to handle iocbs which time out. If the field is NULL, the |
| 10500 | * function shall free the iocbq structure. If more clean up is |
| 10501 | * needed, the caller is expected to provide a completion function |
| 10502 | * that will provide the needed clean up. If the iocb command is |
| 10503 | * not completed within timeout seconds, the function will either |
| 10504 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 10505 | * completion function set in the iocb_cmpl field and then return |
| 10506 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 10507 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10508 | * The function waits for the iocb completion using an |
| 10509 | * non-interruptible wait. |
| 10510 | * This function will sleep while waiting for iocb completion. |
| 10511 | * So, this function should not be called from any context which |
| 10512 | * does not allow sleeping. Due to the same reason, this function |
| 10513 | * cannot be called with interrupt disabled. |
| 10514 | * This function assumes that the iocb completions occur while |
| 10515 | * this function sleep. So, this function cannot be called from |
| 10516 | * the thread which process iocb completion for this ring. |
| 10517 | * This function clears the iocb_flag of the iocb object before |
| 10518 | * issuing the iocb and the iocb completion handler sets this |
| 10519 | * flag and wakes this thread when the iocb completes. |
| 10520 | * The contents of the response iocb will be copied to prspiocbq |
| 10521 | * by the completion handler when the command completes. |
| 10522 | * This function returns IOCB_SUCCESS when success. |
| 10523 | * This function is called with no lock held. |
| 10524 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10525 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10526 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10527 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10528 | struct lpfc_iocbq *piocb, |
| 10529 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10530 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10531 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10532 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10533 | long timeleft, timeout_req = 0; |
| 10534 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10535 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10536 | struct lpfc_iocbq *iocb; |
| 10537 | int txq_cnt = 0; |
| 10538 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10539 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10540 | unsigned long iflags; |
| 10541 | bool iocb_completed = true; |
| 10542 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10543 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10544 | * If the caller has provided a response iocbq buffer, then context2 |
| 10545 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10546 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10547 | if (prspiocbq) { |
| 10548 | if (piocb->context2) |
| 10549 | return IOCB_ERROR; |
| 10550 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10551 | } |
| 10552 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10553 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10554 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 10555 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10556 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10557 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10558 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10559 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10560 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10561 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 10562 | writel(creg_val, phba->HCregaddr); |
| 10563 | readl(phba->HCregaddr); /* flush */ |
| 10564 | } |
| 10565 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10566 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10567 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10568 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10569 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10570 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10571 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10572 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10573 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10574 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10575 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10576 | /* |
| 10577 | * IOCB timed out. Inform the wake iocb wait |
| 10578 | * completion function and set local status |
| 10579 | */ |
| 10580 | |
| 10581 | iocb_completed = false; |
| 10582 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 10583 | } |
| 10584 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10585 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10586 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10587 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 10588 | /* Note: we are not indicating if the IOCB has a success |
| 10589 | * status or not - that's for the caller to check. |
| 10590 | * IOCB_SUCCESS means just that the command was sent and |
| 10591 | * completed. Not that it completed successfully. |
| 10592 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10593 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10594 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10595 | "0338 IOCB wait timeout error - no " |
| 10596 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10597 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10598 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10599 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10600 | "0330 IOCB wake NOT set, " |
| 10601 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10602 | timeout, (timeleft / jiffies)); |
| 10603 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10604 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10605 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10606 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10607 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10608 | txq_cnt++; |
| 10609 | } |
| 10610 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10611 | txcmplq_cnt++; |
| 10612 | } |
| 10613 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10614 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10615 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10616 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10617 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10618 | } else { |
| 10619 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10620 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10621 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10622 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10623 | } |
| 10624 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10625 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10626 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10627 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10628 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10629 | writel(creg_val, phba->HCregaddr); |
| 10630 | readl(phba->HCregaddr); /* flush */ |
| 10631 | } |
| 10632 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10633 | if (prspiocbq) |
| 10634 | piocb->context2 = NULL; |
| 10635 | |
| 10636 | piocb->context_un.wait_queue = NULL; |
| 10637 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10638 | return retval; |
| 10639 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10640 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10641 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10642 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10643 | * @phba: Pointer to HBA context object. |
| 10644 | * @pmboxq: Pointer to driver mailbox object. |
| 10645 | * @timeout: Timeout in number of seconds. |
| 10646 | * |
| 10647 | * This function issues the mailbox to firmware and waits for the |
| 10648 | * mailbox command to complete. If the mailbox command is not |
| 10649 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10650 | * The function waits for the mailbox completion using an |
| 10651 | * interruptible wait. If the thread is woken up due to a |
| 10652 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10653 | * should not free the mailbox resources, if this function returns |
| 10654 | * MBX_TIMEOUT. |
| 10655 | * This function will sleep while waiting for mailbox completion. |
| 10656 | * So, this function should not be called from any context which |
| 10657 | * does not allow sleeping. Due to the same reason, this function |
| 10658 | * cannot be called with interrupt disabled. |
| 10659 | * This function assumes that the mailbox completion occurs while |
| 10660 | * this function sleep. So, this function cannot be called from |
| 10661 | * the worker thread which processes mailbox completion. |
| 10662 | * This function is called in the context of HBA management |
| 10663 | * applications. |
| 10664 | * This function returns MBX_SUCCESS when successful. |
| 10665 | * This function is called with no lock held. |
| 10666 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10667 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10668 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10669 | uint32_t timeout) |
| 10670 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10671 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10672 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10673 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10674 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10675 | |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10676 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10677 | if (pmboxq->context1) |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10678 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10679 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10680 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10681 | /* setup wake call as IOCB callback */ |
| 10682 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10683 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10684 | pmboxq->context1 = &done_q; |
| 10685 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10686 | /* now issue the command */ |
| 10687 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10688 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10689 | wait_event_interruptible_timeout(done_q, |
| 10690 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10691 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10692 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10693 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10694 | /* restore the possible extended buffer for free resource */ |
| 10695 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10696 | /* |
| 10697 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10698 | * else do not free the resources. |
| 10699 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10700 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10701 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10702 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10703 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10704 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10705 | } |
| 10706 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10707 | } else { |
| 10708 | /* restore the possible extended buffer for free resource */ |
| 10709 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10710 | } |
| 10711 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10712 | return retval; |
| 10713 | } |
| 10714 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10715 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10716 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10717 | * @phba: Pointer to HBA context. |
| 10718 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10719 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10720 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10721 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10722 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10723 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10724 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10725 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10726 | * as with offline or HBA function reset), this routine will wait for the |
| 10727 | * outstanding mailbox command to complete before invoking the mailbox |
| 10728 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10729 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10730 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10731 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10732 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10733 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10734 | unsigned long timeout; |
| 10735 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10736 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10737 | /* delay 100ms for port state */ |
| 10738 | msleep(100); |
| 10739 | lpfc_sli_mbox_sys_flush(phba); |
| 10740 | return; |
| 10741 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10742 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10743 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10744 | spin_lock_irq(&phba->hbalock); |
| 10745 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10746 | |
| 10747 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10748 | /* Determine how long we might wait for the active mailbox |
| 10749 | * command to be gracefully completed by firmware. |
| 10750 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10751 | if (phba->sli.mbox_active) |
| 10752 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10753 | phba->sli.mbox_active) * |
| 10754 | 1000) + jiffies; |
| 10755 | spin_unlock_irq(&phba->hbalock); |
| 10756 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10757 | while (phba->sli.mbox_active) { |
| 10758 | /* Check active mailbox complete status every 2ms */ |
| 10759 | msleep(2); |
| 10760 | if (time_after(jiffies, timeout)) |
| 10761 | /* Timeout, let the mailbox flush routine to |
| 10762 | * forcefully release active mailbox command |
| 10763 | */ |
| 10764 | break; |
| 10765 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10766 | } else |
| 10767 | spin_unlock_irq(&phba->hbalock); |
| 10768 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10769 | lpfc_sli_mbox_sys_flush(phba); |
| 10770 | } |
| 10771 | |
| 10772 | /** |
| 10773 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10774 | * @phba: Pointer to HBA context. |
| 10775 | * |
| 10776 | * This function is called to read the SLI3 device error attention registers |
| 10777 | * for possible error attention events. The caller must hold the hostlock |
| 10778 | * with spin_lock_irq(). |
| 10779 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10780 | * 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] | 10781 | * Register and returns 0 otherwise. |
| 10782 | **/ |
| 10783 | static int |
| 10784 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10785 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10786 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10788 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10789 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10790 | goto unplug_err; |
| 10791 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10792 | if (ha_copy & HA_ERATT) { |
| 10793 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10794 | if (lpfc_sli_read_hs(phba)) |
| 10795 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10796 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10797 | /* Check if there is a deferred error condition is active */ |
| 10798 | if ((HS_FFER1 & phba->work_hs) && |
| 10799 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10800 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10801 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10802 | /* Clear all interrupt enable conditions */ |
| 10803 | writel(0, phba->HCregaddr); |
| 10804 | readl(phba->HCregaddr); |
| 10805 | } |
| 10806 | |
| 10807 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10808 | phba->work_ha |= HA_ERATT; |
| 10809 | /* Indicate polling handles this ERATT */ |
| 10810 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10811 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10812 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10813 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10814 | |
| 10815 | unplug_err: |
| 10816 | /* Set the driver HS work bitmap */ |
| 10817 | phba->work_hs |= UNPLUG_ERR; |
| 10818 | /* Set the driver HA work bitmap */ |
| 10819 | phba->work_ha |= HA_ERATT; |
| 10820 | /* Indicate polling handles this ERATT */ |
| 10821 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10822 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10823 | } |
| 10824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10825 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10826 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10827 | * @phba: Pointer to HBA context. |
| 10828 | * |
| 10829 | * This function is called to read the SLI4 device error attention registers |
| 10830 | * for possible error attention events. The caller must hold the hostlock |
| 10831 | * with spin_lock_irq(). |
| 10832 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10833 | * 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] | 10834 | * Register and returns 0 otherwise. |
| 10835 | **/ |
| 10836 | static int |
| 10837 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10838 | { |
| 10839 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10840 | uint32_t if_type, portsmphr; |
| 10841 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10842 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10843 | /* |
| 10844 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10845 | * registers for error attention. This can be changed later. |
| 10846 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10847 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10848 | switch (if_type) { |
| 10849 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10850 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10851 | &uerr_sta_lo) || |
| 10852 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10853 | &uerr_sta_hi)) { |
| 10854 | phba->work_hs |= UNPLUG_ERR; |
| 10855 | phba->work_ha |= HA_ERATT; |
| 10856 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10857 | return 1; |
| 10858 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10859 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10860 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10862 | "1423 HBA Unrecoverable error: " |
| 10863 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10864 | "ue_mask_lo_reg=0x%x, " |
| 10865 | "ue_mask_hi_reg=0x%x\n", |
| 10866 | uerr_sta_lo, uerr_sta_hi, |
| 10867 | phba->sli4_hba.ue_mask_lo, |
| 10868 | phba->sli4_hba.ue_mask_hi); |
| 10869 | phba->work_status[0] = uerr_sta_lo; |
| 10870 | phba->work_status[1] = uerr_sta_hi; |
| 10871 | phba->work_ha |= HA_ERATT; |
| 10872 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10873 | return 1; |
| 10874 | } |
| 10875 | break; |
| 10876 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10877 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10878 | &portstat_reg.word0) || |
| 10879 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10880 | &portsmphr)){ |
| 10881 | phba->work_hs |= UNPLUG_ERR; |
| 10882 | phba->work_ha |= HA_ERATT; |
| 10883 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10884 | return 1; |
| 10885 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10886 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10887 | phba->work_status[0] = |
| 10888 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10889 | phba->work_status[1] = |
| 10890 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10892 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10893 | "port status reg 0x%x, " |
| 10894 | "port smphr reg 0x%x, " |
| 10895 | "error 1=0x%x, error 2=0x%x\n", |
| 10896 | portstat_reg.word0, |
| 10897 | portsmphr, |
| 10898 | phba->work_status[0], |
| 10899 | phba->work_status[1]); |
| 10900 | phba->work_ha |= HA_ERATT; |
| 10901 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10902 | return 1; |
| 10903 | } |
| 10904 | break; |
| 10905 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10906 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10907 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10908 | "2886 HBA Error Attention on unsupported " |
| 10909 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10910 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10911 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10912 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10913 | return 0; |
| 10914 | } |
| 10915 | |
| 10916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10917 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10918 | * @phba: Pointer to HBA context. |
| 10919 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10920 | * 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] | 10921 | * error attention register bit for error attention events. |
| 10922 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10923 | * 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] | 10924 | * Register and returns 0 otherwise. |
| 10925 | **/ |
| 10926 | int |
| 10927 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10928 | { |
| 10929 | uint32_t ha_copy; |
| 10930 | |
| 10931 | /* If somebody is waiting to handle an eratt, don't process it |
| 10932 | * here. The brdkill function will do this. |
| 10933 | */ |
| 10934 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10935 | return 0; |
| 10936 | |
| 10937 | /* Check if interrupt handler handles this ERATT */ |
| 10938 | spin_lock_irq(&phba->hbalock); |
| 10939 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10940 | /* Interrupt handler has handled ERATT */ |
| 10941 | spin_unlock_irq(&phba->hbalock); |
| 10942 | return 0; |
| 10943 | } |
| 10944 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10945 | /* |
| 10946 | * If there is deferred error attention, do not check for error |
| 10947 | * attention |
| 10948 | */ |
| 10949 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10950 | spin_unlock_irq(&phba->hbalock); |
| 10951 | return 0; |
| 10952 | } |
| 10953 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10954 | /* If PCI channel is offline, don't process it */ |
| 10955 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10956 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10957 | return 0; |
| 10958 | } |
| 10959 | |
| 10960 | switch (phba->sli_rev) { |
| 10961 | case LPFC_SLI_REV2: |
| 10962 | case LPFC_SLI_REV3: |
| 10963 | /* Read chip Host Attention (HA) register */ |
| 10964 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10965 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10966 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10967 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10968 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10969 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10970 | default: |
| 10971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10972 | "0299 Invalid SLI revision (%d)\n", |
| 10973 | phba->sli_rev); |
| 10974 | ha_copy = 0; |
| 10975 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10976 | } |
| 10977 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10978 | |
| 10979 | return ha_copy; |
| 10980 | } |
| 10981 | |
| 10982 | /** |
| 10983 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10984 | * @phba: Pointer to HBA context. |
| 10985 | * |
| 10986 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10987 | * that the interrupt should be handled. |
| 10988 | * |
| 10989 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10990 | * interrupt should be handled, otherwise -EIO. |
| 10991 | */ |
| 10992 | static inline int |
| 10993 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10994 | { |
| 10995 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10996 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10997 | return -EIO; |
| 10998 | |
| 10999 | /* Update device level interrupt statistics */ |
| 11000 | phba->sli.slistat.sli_intr++; |
| 11001 | |
| 11002 | /* Ignore all interrupts during initialization. */ |
| 11003 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11004 | return -EIO; |
| 11005 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11006 | return 0; |
| 11007 | } |
| 11008 | |
| 11009 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11010 | * 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] | 11011 | * @irq: Interrupt number. |
| 11012 | * @dev_id: The device context pointer. |
| 11013 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11014 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11015 | * service routine when device with SLI-3 interface spec is enabled with |
| 11016 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11017 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11018 | * interrupt mode, this function is called as part of the device-level |
| 11019 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11020 | * is undergoing initialization, the interrupt handler will not process |
| 11021 | * the interrupt. The link attention and ELS ring attention events are |
| 11022 | * handled by the worker thread. The interrupt handler signals the worker |
| 11023 | * thread and returns for these events. This function is called without |
| 11024 | * 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] | 11025 | * structures. |
| 11026 | * |
| 11027 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11028 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11029 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11030 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11031 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11032 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11033 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11034 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11035 | uint32_t work_ha_copy; |
| 11036 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11037 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11038 | uint32_t control; |
| 11039 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11040 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11041 | struct lpfc_vport *vport; |
| 11042 | struct lpfc_nodelist *ndlp; |
| 11043 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11044 | LPFC_MBOXQ_t *pmb; |
| 11045 | int rc; |
| 11046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11047 | /* |
| 11048 | * Get the driver's phba structure from the dev_id and |
| 11049 | * assume the HBA is not interrupting. |
| 11050 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11051 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11052 | |
| 11053 | if (unlikely(!phba)) |
| 11054 | return IRQ_NONE; |
| 11055 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11056 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11057 | * Stuff needs to be attented to when this function is invoked as an |
| 11058 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11059 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11060 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11061 | /* Check device state for handling interrupt */ |
| 11062 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11063 | return IRQ_NONE; |
| 11064 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11065 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11066 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11067 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11068 | /* If somebody is waiting to handle an eratt don't process it |
| 11069 | * here. The brdkill function will do this. |
| 11070 | */ |
| 11071 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11072 | ha_copy &= ~HA_ERATT; |
| 11073 | /* Check the need for handling ERATT in interrupt handler */ |
| 11074 | if (ha_copy & HA_ERATT) { |
| 11075 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11076 | /* ERATT polling has handled ERATT */ |
| 11077 | ha_copy &= ~HA_ERATT; |
| 11078 | else |
| 11079 | /* Indicate interrupt handler handles ERATT */ |
| 11080 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11081 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11082 | |
| 11083 | /* |
| 11084 | * If there is deferred error attention, do not check for any |
| 11085 | * interrupt. |
| 11086 | */ |
| 11087 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11088 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11089 | return IRQ_NONE; |
| 11090 | } |
| 11091 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11092 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11093 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11094 | goto unplug_error; |
| 11095 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11096 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11097 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11098 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11099 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11100 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11101 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11102 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11103 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11104 | } else |
| 11105 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11107 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11108 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11109 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11110 | if (work_ha_copy & HA_LATT) { |
| 11111 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11112 | /* |
| 11113 | * Turn off Link Attention interrupts |
| 11114 | * until CLEAR_LA done |
| 11115 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11116 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11117 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11118 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11119 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11120 | control &= ~HC_LAINT_ENA; |
| 11121 | writel(control, phba->HCregaddr); |
| 11122 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11123 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11124 | } |
| 11125 | else |
| 11126 | work_ha_copy &= ~HA_LATT; |
| 11127 | } |
| 11128 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11129 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11130 | /* |
| 11131 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11132 | * the only slow ring. |
| 11133 | */ |
| 11134 | status = (work_ha_copy & |
| 11135 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11136 | status >>= (4*LPFC_ELS_RING); |
| 11137 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11138 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11139 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11140 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11141 | |
| 11142 | lpfc_debugfs_slow_ring_trc(phba, |
| 11143 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11144 | control, status, |
| 11145 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11146 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11147 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11148 | lpfc_debugfs_slow_ring_trc(phba, |
| 11149 | "ISR Disable ring:" |
| 11150 | "pwork:x%x hawork:x%x wait:x%x", |
| 11151 | phba->work_ha, work_ha_copy, |
| 11152 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11153 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11154 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11155 | control &= |
| 11156 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11157 | writel(control, phba->HCregaddr); |
| 11158 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11159 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11160 | else { |
| 11161 | lpfc_debugfs_slow_ring_trc(phba, |
| 11162 | "ISR slow ring: pwork:" |
| 11163 | "x%x hawork:x%x wait:x%x", |
| 11164 | phba->work_ha, work_ha_copy, |
| 11165 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11166 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11167 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11168 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11169 | } |
| 11170 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11171 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11172 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11173 | if (lpfc_sli_read_hs(phba)) |
| 11174 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11175 | /* |
| 11176 | * Check if there is a deferred error condition |
| 11177 | * is active |
| 11178 | */ |
| 11179 | if ((HS_FFER1 & phba->work_hs) && |
| 11180 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11181 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11182 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11183 | phba->hba_flag |= DEFER_ERATT; |
| 11184 | /* Clear all interrupt enable conditions */ |
| 11185 | writel(0, phba->HCregaddr); |
| 11186 | readl(phba->HCregaddr); |
| 11187 | } |
| 11188 | } |
| 11189 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11190 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11191 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11192 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11193 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11194 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11195 | |
| 11196 | /* First check out the status word */ |
| 11197 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11198 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11199 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11200 | /* |
| 11201 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 11202 | * mbxStatus <status> |
| 11203 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11204 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11205 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11206 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11207 | "Interrupt mbxCommand x%x " |
| 11208 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11209 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11210 | pmbox->mbxCommand, |
| 11211 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11212 | /* clear mailbox attention bit */ |
| 11213 | work_ha_copy &= ~HA_MBATT; |
| 11214 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11215 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11216 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11217 | phba->last_completion_time = jiffies; |
| 11218 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11219 | if (pmb->mbox_cmpl) { |
| 11220 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 11221 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 11222 | if (pmb->out_ext_byte_len && |
| 11223 | pmb->context2) |
| 11224 | lpfc_sli_pcimem_bcopy( |
| 11225 | phba->mbox_ext, |
| 11226 | pmb->context2, |
| 11227 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11228 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11229 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11230 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11231 | |
| 11232 | lpfc_debugfs_disc_trc(vport, |
| 11233 | LPFC_DISC_TRC_MBOX_VPORT, |
| 11234 | "MBOX dflt rpi: : " |
| 11235 | "status:x%x rpi:x%x", |
| 11236 | (uint32_t)pmbox->mbxStatus, |
| 11237 | pmbox->un.varWords[0], 0); |
| 11238 | |
| 11239 | if (!pmbox->mbxStatus) { |
| 11240 | mp = (struct lpfc_dmabuf *) |
| 11241 | (pmb->context1); |
| 11242 | ndlp = (struct lpfc_nodelist *) |
| 11243 | pmb->context2; |
| 11244 | |
| 11245 | /* Reg_LOGIN of dflt RPI was |
| 11246 | * successful. new lets get |
| 11247 | * rid of the RPI using the |
| 11248 | * same mbox buffer. |
| 11249 | */ |
| 11250 | lpfc_unreg_login(phba, |
| 11251 | vport->vpi, |
| 11252 | pmbox->un.varWords[0], |
| 11253 | pmb); |
| 11254 | pmb->mbox_cmpl = |
| 11255 | lpfc_mbx_cmpl_dflt_rpi; |
| 11256 | pmb->context1 = mp; |
| 11257 | pmb->context2 = ndlp; |
| 11258 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11259 | rc = lpfc_sli_issue_mbox(phba, |
| 11260 | pmb, |
| 11261 | MBX_NOWAIT); |
| 11262 | if (rc != MBX_BUSY) |
| 11263 | lpfc_printf_log(phba, |
| 11264 | KERN_ERR, |
| 11265 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11266 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11267 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11268 | if (rc != MBX_NOT_FINISHED) |
| 11269 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11270 | } |
| 11271 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11272 | spin_lock_irqsave( |
| 11273 | &phba->pport->work_port_lock, |
| 11274 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11275 | phba->pport->work_port_events &= |
| 11276 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11277 | spin_unlock_irqrestore( |
| 11278 | &phba->pport->work_port_lock, |
| 11279 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11280 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11281 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11282 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11283 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11284 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11285 | if ((work_ha_copy & HA_MBATT) && |
| 11286 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11287 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11288 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11289 | do { |
| 11290 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 11291 | MBX_NOWAIT); |
| 11292 | } while (rc == MBX_NOT_FINISHED); |
| 11293 | if (rc != MBX_SUCCESS) |
| 11294 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11295 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11296 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11297 | } |
| 11298 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11299 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11300 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11301 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11302 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11303 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11304 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11305 | unplug_error: |
| 11306 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11307 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11308 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11309 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11310 | |
| 11311 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11312 | * 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] | 11313 | * @irq: Interrupt number. |
| 11314 | * @dev_id: The device context pointer. |
| 11315 | * |
| 11316 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11317 | * service routine when device with SLI-3 interface spec is enabled with |
| 11318 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11319 | * ring event in the HBA. However, when the device is enabled with either |
| 11320 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11321 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11322 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11323 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11324 | * the intrrupt context. This function is called without any lock held. |
| 11325 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11326 | * |
| 11327 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11328 | * returns IRQ_NONE. |
| 11329 | **/ |
| 11330 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11331 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11332 | { |
| 11333 | struct lpfc_hba *phba; |
| 11334 | uint32_t ha_copy; |
| 11335 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11336 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11337 | |
| 11338 | /* Get the driver's phba structure from the dev_id and |
| 11339 | * assume the HBA is not interrupting. |
| 11340 | */ |
| 11341 | phba = (struct lpfc_hba *) dev_id; |
| 11342 | |
| 11343 | if (unlikely(!phba)) |
| 11344 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11345 | |
| 11346 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11347 | * Stuff needs to be attented to when this function is invoked as an |
| 11348 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11349 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11350 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11351 | /* Check device state for handling interrupt */ |
| 11352 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11353 | return IRQ_NONE; |
| 11354 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11355 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11356 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11357 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11358 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11359 | /* |
| 11360 | * If there is deferred error attention, do not check for |
| 11361 | * any interrupt. |
| 11362 | */ |
| 11363 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11364 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11365 | return IRQ_NONE; |
| 11366 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11367 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 11368 | phba->HAregaddr); |
| 11369 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11370 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11371 | } else |
| 11372 | ha_copy = phba->ha_copy; |
| 11373 | |
| 11374 | /* |
| 11375 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 11376 | */ |
| 11377 | ha_copy &= ~(phba->work_ha_mask); |
| 11378 | |
| 11379 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11380 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11381 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11382 | lpfc_sli_handle_fast_ring_event(phba, |
| 11383 | &phba->sli.ring[LPFC_FCP_RING], |
| 11384 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11385 | |
| 11386 | if (phba->cfg_multi_ring_support == 2) { |
| 11387 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11388 | * Process all events on extra ring. Take the optimized path |
| 11389 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11390 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11391 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11392 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11393 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11394 | lpfc_sli_handle_fast_ring_event(phba, |
| 11395 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 11396 | status); |
| 11397 | } |
| 11398 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11399 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11400 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11401 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11402 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11403 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11404 | * @irq: Interrupt number. |
| 11405 | * @dev_id: The device context pointer. |
| 11406 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11407 | * This function is the HBA device-level interrupt handler to device with |
| 11408 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 11409 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 11410 | * requires driver attention. This function invokes the slow-path interrupt |
| 11411 | * attention handling function and fast-path interrupt attention handling |
| 11412 | * function in turn to process the relevant HBA attention events. This |
| 11413 | * function is called without any lock held. It gets the hbalock to access |
| 11414 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11415 | * |
| 11416 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11417 | * returns IRQ_NONE. |
| 11418 | **/ |
| 11419 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11420 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11421 | { |
| 11422 | struct lpfc_hba *phba; |
| 11423 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11424 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11425 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11426 | |
| 11427 | /* |
| 11428 | * Get the driver's phba structure from the dev_id and |
| 11429 | * assume the HBA is not interrupting. |
| 11430 | */ |
| 11431 | phba = (struct lpfc_hba *) dev_id; |
| 11432 | |
| 11433 | if (unlikely(!phba)) |
| 11434 | return IRQ_NONE; |
| 11435 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11436 | /* Check device state for handling interrupt */ |
| 11437 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11438 | return IRQ_NONE; |
| 11439 | |
| 11440 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11441 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 11442 | spin_unlock(&phba->hbalock); |
| 11443 | return IRQ_HANDLED; |
| 11444 | } |
| 11445 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11446 | if (unlikely(!phba->ha_copy)) { |
| 11447 | spin_unlock(&phba->hbalock); |
| 11448 | return IRQ_NONE; |
| 11449 | } else if (phba->ha_copy & HA_ERATT) { |
| 11450 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11451 | /* ERATT polling has handled ERATT */ |
| 11452 | phba->ha_copy &= ~HA_ERATT; |
| 11453 | else |
| 11454 | /* Indicate interrupt handler handles ERATT */ |
| 11455 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11456 | } |
| 11457 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11458 | /* |
| 11459 | * If there is deferred error attention, do not check for any interrupt. |
| 11460 | */ |
| 11461 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 11462 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11463 | return IRQ_NONE; |
| 11464 | } |
| 11465 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11466 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11467 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 11468 | spin_unlock(&phba->hbalock); |
| 11469 | return IRQ_HANDLED; |
| 11470 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11471 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 11472 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11473 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11474 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11475 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11476 | readl(phba->HAregaddr); /* flush */ |
| 11477 | spin_unlock(&phba->hbalock); |
| 11478 | |
| 11479 | /* |
| 11480 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11481 | */ |
| 11482 | |
| 11483 | /* status of events with mailbox and link attention */ |
| 11484 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 11485 | |
| 11486 | /* status of events with ELS ring */ |
| 11487 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11488 | status2 >>= (4*LPFC_ELS_RING); |
| 11489 | |
| 11490 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11491 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11492 | else |
| 11493 | sp_irq_rc = IRQ_NONE; |
| 11494 | |
| 11495 | /* |
| 11496 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11497 | */ |
| 11498 | |
| 11499 | /* status of events with FCP ring */ |
| 11500 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 11501 | status1 >>= (4*LPFC_FCP_RING); |
| 11502 | |
| 11503 | /* status of events with extra ring */ |
| 11504 | if (phba->cfg_multi_ring_support == 2) { |
| 11505 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 11506 | status2 >>= (4*LPFC_EXTRA_RING); |
| 11507 | } else |
| 11508 | status2 = 0; |
| 11509 | |
| 11510 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11511 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11512 | else |
| 11513 | fp_irq_rc = IRQ_NONE; |
| 11514 | |
| 11515 | /* Return device-level interrupt handling status */ |
| 11516 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11517 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11518 | |
| 11519 | /** |
| 11520 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 11521 | * @phba: pointer to lpfc hba data structure. |
| 11522 | * |
| 11523 | * This routine is invoked by the worker thread to process all the pending |
| 11524 | * SLI4 FCP abort XRI events. |
| 11525 | **/ |
| 11526 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11527 | { |
| 11528 | struct lpfc_cq_event *cq_event; |
| 11529 | |
| 11530 | /* First, declare the fcp xri abort event has been handled */ |
| 11531 | spin_lock_irq(&phba->hbalock); |
| 11532 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 11533 | spin_unlock_irq(&phba->hbalock); |
| 11534 | /* Now, handle all the fcp xri abort events */ |
| 11535 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 11536 | /* Get the first event from the head of the event queue */ |
| 11537 | spin_lock_irq(&phba->hbalock); |
| 11538 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 11539 | cq_event, struct lpfc_cq_event, list); |
| 11540 | spin_unlock_irq(&phba->hbalock); |
| 11541 | /* Notify aborted XRI for FCP work queue */ |
| 11542 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11543 | /* Free the event processed back to the free pool */ |
| 11544 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11545 | } |
| 11546 | } |
| 11547 | |
| 11548 | /** |
| 11549 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 11550 | * @phba: pointer to lpfc hba data structure. |
| 11551 | * |
| 11552 | * This routine is invoked by the worker thread to process all the pending |
| 11553 | * SLI4 els abort xri events. |
| 11554 | **/ |
| 11555 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11556 | { |
| 11557 | struct lpfc_cq_event *cq_event; |
| 11558 | |
| 11559 | /* First, declare the els xri abort event has been handled */ |
| 11560 | spin_lock_irq(&phba->hbalock); |
| 11561 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 11562 | spin_unlock_irq(&phba->hbalock); |
| 11563 | /* Now, handle all the els xri abort events */ |
| 11564 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 11565 | /* Get the first event from the head of the event queue */ |
| 11566 | spin_lock_irq(&phba->hbalock); |
| 11567 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11568 | cq_event, struct lpfc_cq_event, list); |
| 11569 | spin_unlock_irq(&phba->hbalock); |
| 11570 | /* Notify aborted XRI for ELS work queue */ |
| 11571 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11572 | /* Free the event processed back to the free pool */ |
| 11573 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11574 | } |
| 11575 | } |
| 11576 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11577 | /** |
| 11578 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 11579 | * @phba: pointer to lpfc hba data structure |
| 11580 | * @pIocbIn: pointer to the rspiocbq |
| 11581 | * @pIocbOut: pointer to the cmdiocbq |
| 11582 | * @wcqe: pointer to the complete wcqe |
| 11583 | * |
| 11584 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11585 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11586 | * completion status information from the complete wcqe. |
| 11587 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11588 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11589 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11590 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11591 | struct lpfc_iocbq *pIocbOut, |
| 11592 | struct lpfc_wcqe_complete *wcqe) |
| 11593 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11594 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11595 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11596 | uint32_t status, max_response; |
| 11597 | struct lpfc_dmabuf *dmabuf; |
| 11598 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11599 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11600 | |
| 11601 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11602 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11603 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11604 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11605 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11606 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11607 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11608 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11609 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11610 | wcqe->total_data_placed; |
| 11611 | else |
| 11612 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11613 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11614 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11615 | switch (pIocbOut->iocb.ulpCommand) { |
| 11616 | case CMD_ELS_REQUEST64_CR: |
| 11617 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11618 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11619 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 11620 | max_response = bde.tus.f.bdeSize; |
| 11621 | break; |
| 11622 | case CMD_GEN_REQUEST64_CR: |
| 11623 | max_response = 0; |
| 11624 | if (!pIocbOut->context3) |
| 11625 | break; |
| 11626 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 11627 | sizeof(struct ulp_bde64); |
| 11628 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11629 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11630 | for (i = 0; i < numBdes; i++) { |
| 11631 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 11632 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 11633 | max_response += bde.tus.f.bdeSize; |
| 11634 | } |
| 11635 | break; |
| 11636 | default: |
| 11637 | max_response = wcqe->total_data_placed; |
| 11638 | break; |
| 11639 | } |
| 11640 | if (max_response < wcqe->total_data_placed) |
| 11641 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 11642 | else |
| 11643 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 11644 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11645 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11646 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11647 | /* Convert BG errors for completion status */ |
| 11648 | if (status == CQE_STATUS_DI_ERROR) { |
| 11649 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11650 | |
| 11651 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11652 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11653 | else |
| 11654 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11655 | |
| 11656 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11657 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11658 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11659 | BGS_GUARD_ERR_MASK; |
| 11660 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11661 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11662 | BGS_APPTAG_ERR_MASK; |
| 11663 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11664 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11665 | BGS_REFTAG_ERR_MASK; |
| 11666 | |
| 11667 | /* Check to see if there was any good data before the error */ |
| 11668 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11669 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11670 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11671 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11672 | wcqe->total_data_placed; |
| 11673 | } |
| 11674 | |
| 11675 | /* |
| 11676 | * Set ALL the error bits to indicate we don't know what |
| 11677 | * type of error it is. |
| 11678 | */ |
| 11679 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11680 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11681 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11682 | BGS_GUARD_ERR_MASK); |
| 11683 | } |
| 11684 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11685 | /* Pick up HBA exchange busy condition */ |
| 11686 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11687 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11688 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11689 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11690 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11691 | } |
| 11692 | |
| 11693 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11694 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11695 | * @phba: Pointer to HBA context object. |
| 11696 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11697 | * |
| 11698 | * This routine handles an ELS work-queue completion event and construct |
| 11699 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11700 | * discovery engine to handle. |
| 11701 | * |
| 11702 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11703 | **/ |
| 11704 | static struct lpfc_iocbq * |
| 11705 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11706 | struct lpfc_iocbq *irspiocbq) |
| 11707 | { |
| 11708 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11709 | struct lpfc_iocbq *cmdiocbq; |
| 11710 | struct lpfc_wcqe_complete *wcqe; |
| 11711 | unsigned long iflags; |
| 11712 | |
| 11713 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11714 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11715 | pring->stats.iocb_event++; |
| 11716 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11717 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11718 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11719 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11720 | |
| 11721 | if (unlikely(!cmdiocbq)) { |
| 11722 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11723 | "0386 ELS complete with no corresponding " |
| 11724 | "cmdiocb: iotag (%d)\n", |
| 11725 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11726 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11727 | return NULL; |
| 11728 | } |
| 11729 | |
| 11730 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11731 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11732 | |
| 11733 | return irspiocbq; |
| 11734 | } |
| 11735 | |
| 11736 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11737 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11738 | * @phba: Pointer to HBA context object. |
| 11739 | * @cqe: Pointer to mailbox completion queue entry. |
| 11740 | * |
| 11741 | * This routine process a mailbox completion queue entry with asynchrous |
| 11742 | * event. |
| 11743 | * |
| 11744 | * Return: true if work posted to worker thread, otherwise false. |
| 11745 | **/ |
| 11746 | static bool |
| 11747 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11748 | { |
| 11749 | struct lpfc_cq_event *cq_event; |
| 11750 | unsigned long iflags; |
| 11751 | |
| 11752 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11753 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11754 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11755 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11756 | |
| 11757 | /* Allocate a new internal CQ_EVENT entry */ |
| 11758 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11759 | if (!cq_event) { |
| 11760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11761 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11762 | return false; |
| 11763 | } |
| 11764 | |
| 11765 | /* Move the CQE into an asynchronous event entry */ |
| 11766 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11767 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11768 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11769 | /* Set the async event flag */ |
| 11770 | phba->hba_flag |= ASYNC_EVENT; |
| 11771 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11772 | |
| 11773 | return true; |
| 11774 | } |
| 11775 | |
| 11776 | /** |
| 11777 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11778 | * @phba: Pointer to HBA context object. |
| 11779 | * @cqe: Pointer to mailbox completion queue entry. |
| 11780 | * |
| 11781 | * This routine process a mailbox completion queue entry with mailbox |
| 11782 | * completion event. |
| 11783 | * |
| 11784 | * Return: true if work posted to worker thread, otherwise false. |
| 11785 | **/ |
| 11786 | static bool |
| 11787 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11788 | { |
| 11789 | uint32_t mcqe_status; |
| 11790 | MAILBOX_t *mbox, *pmbox; |
| 11791 | struct lpfc_mqe *mqe; |
| 11792 | struct lpfc_vport *vport; |
| 11793 | struct lpfc_nodelist *ndlp; |
| 11794 | struct lpfc_dmabuf *mp; |
| 11795 | unsigned long iflags; |
| 11796 | LPFC_MBOXQ_t *pmb; |
| 11797 | bool workposted = false; |
| 11798 | int rc; |
| 11799 | |
| 11800 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11801 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11802 | goto out_no_mqe_complete; |
| 11803 | |
| 11804 | /* Get the reference to the active mbox command */ |
| 11805 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11806 | pmb = phba->sli.mbox_active; |
| 11807 | if (unlikely(!pmb)) { |
| 11808 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11809 | "1832 No pending MBOX command to handle\n"); |
| 11810 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11811 | goto out_no_mqe_complete; |
| 11812 | } |
| 11813 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11814 | mqe = &pmb->u.mqe; |
| 11815 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11816 | mbox = phba->mbox; |
| 11817 | vport = pmb->vport; |
| 11818 | |
| 11819 | /* Reset heartbeat timer */ |
| 11820 | phba->last_completion_time = jiffies; |
| 11821 | del_timer(&phba->sli.mbox_tmo); |
| 11822 | |
| 11823 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11824 | if (pmb->mbox_cmpl && mbox) |
| 11825 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11826 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11827 | /* |
| 11828 | * For mcqe errors, conditionally move a modified error code to |
| 11829 | * the mbox so that the error will not be missed. |
| 11830 | */ |
| 11831 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11832 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11833 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11834 | bf_set(lpfc_mqe_status, mqe, |
| 11835 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11836 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11837 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11838 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11840 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11841 | mcqe_status, |
| 11842 | pmbox->un.varWords[0], 0); |
| 11843 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11844 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11845 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11846 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11847 | * RID of the PPI using the same mbox buffer. |
| 11848 | */ |
| 11849 | lpfc_unreg_login(phba, vport->vpi, |
| 11850 | pmbox->un.varWords[0], pmb); |
| 11851 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11852 | pmb->context1 = mp; |
| 11853 | pmb->context2 = ndlp; |
| 11854 | pmb->vport = vport; |
| 11855 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11856 | if (rc != MBX_BUSY) |
| 11857 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11858 | LOG_SLI, "0385 rc should " |
| 11859 | "have been MBX_BUSY\n"); |
| 11860 | if (rc != MBX_NOT_FINISHED) |
| 11861 | goto send_current_mbox; |
| 11862 | } |
| 11863 | } |
| 11864 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11865 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11866 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11867 | |
| 11868 | /* There is mailbox completion work to do */ |
| 11869 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11870 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11871 | phba->work_ha |= HA_MBATT; |
| 11872 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11873 | workposted = true; |
| 11874 | |
| 11875 | send_current_mbox: |
| 11876 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11877 | /* Release the mailbox command posting token */ |
| 11878 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11879 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11880 | phba->sli.mbox_active = NULL; |
| 11881 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11882 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11883 | lpfc_worker_wake_up(phba); |
| 11884 | out_no_mqe_complete: |
| 11885 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11886 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11887 | return workposted; |
| 11888 | } |
| 11889 | |
| 11890 | /** |
| 11891 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11892 | * @phba: Pointer to HBA context object. |
| 11893 | * @cqe: Pointer to mailbox completion queue entry. |
| 11894 | * |
| 11895 | * This routine process a mailbox completion queue entry, it invokes the |
| 11896 | * proper mailbox complete handling or asynchrous event handling routine |
| 11897 | * according to the MCQE's async bit. |
| 11898 | * |
| 11899 | * Return: true if work posted to worker thread, otherwise false. |
| 11900 | **/ |
| 11901 | static bool |
| 11902 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11903 | { |
| 11904 | struct lpfc_mcqe mcqe; |
| 11905 | bool workposted; |
| 11906 | |
| 11907 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11908 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11909 | |
| 11910 | /* Invoke the proper event handling routine */ |
| 11911 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11912 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11913 | else |
| 11914 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11915 | return workposted; |
| 11916 | } |
| 11917 | |
| 11918 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11919 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11920 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11921 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11922 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11923 | * |
| 11924 | * This routine handles an ELS work-queue completion event. |
| 11925 | * |
| 11926 | * Return: true if work posted to worker thread, otherwise false. |
| 11927 | **/ |
| 11928 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11929 | 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] | 11930 | struct lpfc_wcqe_complete *wcqe) |
| 11931 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11932 | struct lpfc_iocbq *irspiocbq; |
| 11933 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11934 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11935 | int txq_cnt = 0; |
| 11936 | int txcmplq_cnt = 0; |
| 11937 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11938 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11939 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11940 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11941 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11942 | if (!list_empty(&pring->txq)) |
| 11943 | txq_cnt++; |
| 11944 | if (!list_empty(&pring->txcmplq)) |
| 11945 | txcmplq_cnt++; |
| 11946 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 11947 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11948 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11949 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11950 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11951 | txq_cnt, phba->iocb_cnt, |
| 11952 | fcp_txcmplq_cnt, |
| 11953 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11954 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11955 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11956 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11957 | /* Save off the slow-path queue event for work thread to process */ |
| 11958 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11959 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11960 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11961 | &phba->sli4_hba.sp_queue_event); |
| 11962 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11963 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11964 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11965 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11966 | } |
| 11967 | |
| 11968 | /** |
| 11969 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11970 | * @phba: Pointer to HBA context object. |
| 11971 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11972 | * |
| 11973 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11974 | * proper WQ release routine to the slow-path WQ. |
| 11975 | **/ |
| 11976 | static void |
| 11977 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11978 | struct lpfc_wcqe_release *wcqe) |
| 11979 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11980 | /* sanity check on queue memory */ |
| 11981 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11982 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11983 | /* Check for the slow-path ELS work queue */ |
| 11984 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11985 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11986 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11987 | else |
| 11988 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11989 | "2579 Slow-path wqe consume event carries " |
| 11990 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11991 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11992 | phba->sli4_hba.els_wq->queue_id); |
| 11993 | } |
| 11994 | |
| 11995 | /** |
| 11996 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11997 | * @phba: Pointer to HBA context object. |
| 11998 | * @cq: Pointer to a WQ completion queue. |
| 11999 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12000 | * |
| 12001 | * This routine handles an XRI abort event. |
| 12002 | * |
| 12003 | * Return: true if work posted to worker thread, otherwise false. |
| 12004 | **/ |
| 12005 | static bool |
| 12006 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12007 | struct lpfc_queue *cq, |
| 12008 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12009 | { |
| 12010 | bool workposted = false; |
| 12011 | struct lpfc_cq_event *cq_event; |
| 12012 | unsigned long iflags; |
| 12013 | |
| 12014 | /* Allocate a new internal CQ_EVENT entry */ |
| 12015 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12016 | if (!cq_event) { |
| 12017 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12018 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 12019 | return false; |
| 12020 | } |
| 12021 | |
| 12022 | /* Move the CQE into the proper xri abort event list */ |
| 12023 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12024 | switch (cq->subtype) { |
| 12025 | case LPFC_FCP: |
| 12026 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12027 | list_add_tail(&cq_event->list, |
| 12028 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12029 | /* Set the fcp xri abort event flag */ |
| 12030 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12031 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12032 | workposted = true; |
| 12033 | break; |
| 12034 | case LPFC_ELS: |
| 12035 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12036 | list_add_tail(&cq_event->list, |
| 12037 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12038 | /* Set the els xri abort event flag */ |
| 12039 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12040 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12041 | workposted = true; |
| 12042 | break; |
| 12043 | default: |
| 12044 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12045 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 12046 | cq->subtype); |
| 12047 | workposted = false; |
| 12048 | break; |
| 12049 | } |
| 12050 | return workposted; |
| 12051 | } |
| 12052 | |
| 12053 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12054 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12055 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12056 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12057 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12058 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12059 | * |
| 12060 | * Return: true if work posted to worker thread, otherwise false. |
| 12061 | **/ |
| 12062 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12063 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12064 | { |
| 12065 | bool workposted = false; |
| 12066 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12067 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 12068 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12069 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12070 | unsigned long iflags; |
| 12071 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12072 | /* sanity check on queue memory */ |
| 12073 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12074 | return workposted; |
| 12075 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12076 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12077 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12078 | else |
| 12079 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12080 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12081 | goto out; |
| 12082 | |
| 12083 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12084 | switch (status) { |
| 12085 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12086 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12087 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12088 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12089 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12090 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12091 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12092 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12093 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12094 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12095 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12096 | goto out; |
| 12097 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12098 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12099 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 12100 | /* save off the frame for the word thread to process */ |
| 12101 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12102 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12103 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12104 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12105 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12106 | workposted = true; |
| 12107 | break; |
| 12108 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 12109 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12110 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12111 | /* Post more buffers if possible */ |
| 12112 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12113 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12114 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12115 | workposted = true; |
| 12116 | break; |
| 12117 | } |
| 12118 | out: |
| 12119 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12120 | } |
| 12121 | |
| 12122 | /** |
| 12123 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12124 | * @phba: Pointer to HBA context object. |
| 12125 | * @cq: Pointer to the completion queue. |
| 12126 | * @wcqe: Pointer to a completion queue entry. |
| 12127 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12128 | * 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] | 12129 | * entry. |
| 12130 | * |
| 12131 | * Return: true if work posted to worker thread, otherwise false. |
| 12132 | **/ |
| 12133 | static bool |
| 12134 | 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] | 12135 | struct lpfc_cqe *cqe) |
| 12136 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12137 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12138 | bool workposted = false; |
| 12139 | |
| 12140 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12141 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12142 | |
| 12143 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12144 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12145 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12146 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12147 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12148 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12149 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12150 | break; |
| 12151 | case CQE_CODE_RELEASE_WQE: |
| 12152 | /* Process the WQ release event */ |
| 12153 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12154 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12155 | break; |
| 12156 | case CQE_CODE_XRI_ABORTED: |
| 12157 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12158 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12159 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12160 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12161 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12162 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12163 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12164 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12165 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12166 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12167 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12168 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12169 | default: |
| 12170 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12171 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12172 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12173 | break; |
| 12174 | } |
| 12175 | return workposted; |
| 12176 | } |
| 12177 | |
| 12178 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12179 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 12180 | * @phba: Pointer to HBA context object. |
| 12181 | * @eqe: Pointer to fast-path event queue entry. |
| 12182 | * |
| 12183 | * This routine process a event queue entry from the slow-path event queue. |
| 12184 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12185 | * completion event on a completion queue, if not, an error shall be logged |
| 12186 | * and just return. Otherwise, it will get to the corresponding completion |
| 12187 | * queue and process all the entries on that completion queue, rearm the |
| 12188 | * completion queue, and then return. |
| 12189 | * |
| 12190 | **/ |
| 12191 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12192 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12193 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12194 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12195 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12196 | struct lpfc_cqe *cqe; |
| 12197 | bool workposted = false; |
| 12198 | int ecount = 0; |
| 12199 | uint16_t cqid; |
| 12200 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12201 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12202 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12203 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12204 | list_for_each_entry(childq, &speq->child_list, list) { |
| 12205 | if (childq->queue_id == cqid) { |
| 12206 | cq = childq; |
| 12207 | break; |
| 12208 | } |
| 12209 | } |
| 12210 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12211 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12212 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12213 | "0365 Slow-path CQ identifier " |
| 12214 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12215 | return; |
| 12216 | } |
| 12217 | |
| 12218 | /* Process all the entries to the CQ */ |
| 12219 | switch (cq->type) { |
| 12220 | case LPFC_MCQ: |
| 12221 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12222 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12223 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12224 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12225 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12226 | } |
| 12227 | break; |
| 12228 | case LPFC_WCQ: |
| 12229 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12230 | if (cq->subtype == LPFC_FCP) |
| 12231 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 12232 | cqe); |
| 12233 | else |
| 12234 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 12235 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12236 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12237 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12238 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12239 | |
| 12240 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12241 | if (ecount > cq->CQ_max_cqe) |
| 12242 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12243 | break; |
| 12244 | default: |
| 12245 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12246 | "0370 Invalid completion queue type (%d)\n", |
| 12247 | cq->type); |
| 12248 | return; |
| 12249 | } |
| 12250 | |
| 12251 | /* Catch the no cq entry condition, log an error */ |
| 12252 | if (unlikely(ecount == 0)) |
| 12253 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12254 | "0371 No entry from the CQ: identifier " |
| 12255 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 12256 | |
| 12257 | /* In any case, flash and re-arm the RCQ */ |
| 12258 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12259 | |
| 12260 | /* wake up worker thread if there are works to be done */ |
| 12261 | if (workposted) |
| 12262 | lpfc_worker_wake_up(phba); |
| 12263 | } |
| 12264 | |
| 12265 | /** |
| 12266 | * 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] | 12267 | * @phba: Pointer to HBA context object. |
| 12268 | * @cq: Pointer to associated CQ |
| 12269 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12270 | * |
| 12271 | * This routine process a fast-path work queue completion entry from fast-path |
| 12272 | * event queue for FCP command response completion. |
| 12273 | **/ |
| 12274 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12275 | 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] | 12276 | struct lpfc_wcqe_complete *wcqe) |
| 12277 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12278 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12279 | struct lpfc_iocbq *cmdiocbq; |
| 12280 | struct lpfc_iocbq irspiocbq; |
| 12281 | unsigned long iflags; |
| 12282 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12283 | /* Check for response status */ |
| 12284 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 12285 | /* If resource errors reported from HBA, reduce queue |
| 12286 | * depth of the SCSI device. |
| 12287 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12288 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 12289 | IOSTAT_LOCAL_REJECT)) && |
| 12290 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 12291 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12292 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12293 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12294 | /* Log the error status */ |
| 12295 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12296 | "0373 FCP complete error: status=x%x, " |
| 12297 | "hw_status=x%x, total_data_specified=%d, " |
| 12298 | "parameter=x%x, word3=x%x\n", |
| 12299 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 12300 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 12301 | wcqe->total_data_placed, wcqe->parameter, |
| 12302 | wcqe->word3); |
| 12303 | } |
| 12304 | |
| 12305 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12306 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 12307 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12308 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12309 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12310 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12311 | if (unlikely(!cmdiocbq)) { |
| 12312 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12313 | "0374 FCP complete with no corresponding " |
| 12314 | "cmdiocb: iotag (%d)\n", |
| 12315 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12316 | return; |
| 12317 | } |
| 12318 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 12319 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12320 | "0375 FCP cmdiocb not callback function " |
| 12321 | "iotag: (%d)\n", |
| 12322 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12323 | return; |
| 12324 | } |
| 12325 | |
| 12326 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12327 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12328 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12329 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 12330 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12331 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 12332 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12333 | } |
| 12334 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12335 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 12336 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 12337 | } |
| 12338 | |
| 12339 | /** |
| 12340 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 12341 | * @phba: Pointer to HBA context object. |
| 12342 | * @cq: Pointer to completion queue. |
| 12343 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12344 | * |
| 12345 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 12346 | * proper WQ release routine to the slow-path WQ. |
| 12347 | **/ |
| 12348 | static void |
| 12349 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12350 | struct lpfc_wcqe_release *wcqe) |
| 12351 | { |
| 12352 | struct lpfc_queue *childwq; |
| 12353 | bool wqid_matched = false; |
| 12354 | uint16_t fcp_wqid; |
| 12355 | |
| 12356 | /* Check for fast-path FCP work queue release */ |
| 12357 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 12358 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 12359 | if (childwq->queue_id == fcp_wqid) { |
| 12360 | lpfc_sli4_wq_release(childwq, |
| 12361 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12362 | wqid_matched = true; |
| 12363 | break; |
| 12364 | } |
| 12365 | } |
| 12366 | /* Report warning log message if no match found */ |
| 12367 | if (wqid_matched != true) |
| 12368 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12369 | "2580 Fast-path wqe consume event carries " |
| 12370 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 12371 | } |
| 12372 | |
| 12373 | /** |
| 12374 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 12375 | * @cq: Pointer to the completion queue. |
| 12376 | * @eqe: Pointer to fast-path completion queue entry. |
| 12377 | * |
| 12378 | * This routine process a fast-path work queue completion entry from fast-path |
| 12379 | * event queue for FCP command response completion. |
| 12380 | **/ |
| 12381 | static int |
| 12382 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12383 | struct lpfc_cqe *cqe) |
| 12384 | { |
| 12385 | struct lpfc_wcqe_release wcqe; |
| 12386 | bool workposted = false; |
| 12387 | |
| 12388 | /* Copy the work queue CQE and convert endian order if needed */ |
| 12389 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 12390 | |
| 12391 | /* Check and process for different type of WCQE and dispatch */ |
| 12392 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 12393 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12394 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12395 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 12396 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12397 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12398 | (struct lpfc_wcqe_complete *)&wcqe); |
| 12399 | break; |
| 12400 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12401 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12402 | /* Process the WQ release event */ |
| 12403 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 12404 | (struct lpfc_wcqe_release *)&wcqe); |
| 12405 | break; |
| 12406 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12407 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12408 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12409 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12410 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 12411 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 12412 | break; |
| 12413 | default: |
| 12414 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12415 | "0144 Not a valid WCQE code: x%x\n", |
| 12416 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 12417 | break; |
| 12418 | } |
| 12419 | return workposted; |
| 12420 | } |
| 12421 | |
| 12422 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12423 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12424 | * @phba: Pointer to HBA context object. |
| 12425 | * @eqe: Pointer to fast-path event queue entry. |
| 12426 | * |
| 12427 | * This routine process a event queue entry from the fast-path event queue. |
| 12428 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12429 | * completion event on a completion queue, if not, an error shall be logged |
| 12430 | * and just return. Otherwise, it will get to the corresponding completion |
| 12431 | * queue and process all the entries on the completion queue, rearm the |
| 12432 | * completion queue, and then return. |
| 12433 | **/ |
| 12434 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12435 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12436 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12437 | { |
| 12438 | struct lpfc_queue *cq; |
| 12439 | struct lpfc_cqe *cqe; |
| 12440 | bool workposted = false; |
| 12441 | uint16_t cqid; |
| 12442 | int ecount = 0; |
| 12443 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12444 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12445 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12446 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12447 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12448 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12449 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12450 | return; |
| 12451 | } |
| 12452 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12453 | /* Get the reference to the corresponding CQ */ |
| 12454 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12455 | |
| 12456 | /* Check if this is a Slow path event */ |
| 12457 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 12458 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 12459 | phba->sli4_hba.hba_eq[qidx]); |
| 12460 | return; |
| 12461 | } |
| 12462 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12463 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 12464 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12465 | "3146 Fast-path completion queues " |
| 12466 | "does not exist\n"); |
| 12467 | return; |
| 12468 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12469 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12470 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12471 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12472 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12473 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12474 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12475 | return; |
| 12476 | } |
| 12477 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12478 | if (unlikely(cqid != cq->queue_id)) { |
| 12479 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12480 | "0368 Miss-matched fast-path completion " |
| 12481 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 12482 | cqid, cq->queue_id); |
| 12483 | return; |
| 12484 | } |
| 12485 | |
| 12486 | /* Process all the entries to the CQ */ |
| 12487 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12488 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12489 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12490 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12491 | } |
| 12492 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12493 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12494 | if (ecount > cq->CQ_max_cqe) |
| 12495 | cq->CQ_max_cqe = ecount; |
| 12496 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12497 | /* Catch the no cq entry condition */ |
| 12498 | if (unlikely(ecount == 0)) |
| 12499 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12500 | "0369 No entry from fast-path completion " |
| 12501 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12502 | |
| 12503 | /* In any case, flash and re-arm the CQ */ |
| 12504 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12505 | |
| 12506 | /* wake up worker thread if there are works to be done */ |
| 12507 | if (workposted) |
| 12508 | lpfc_worker_wake_up(phba); |
| 12509 | } |
| 12510 | |
| 12511 | static void |
| 12512 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12513 | { |
| 12514 | struct lpfc_eqe *eqe; |
| 12515 | |
| 12516 | /* walk all the EQ entries and drop on the floor */ |
| 12517 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 12518 | ; |
| 12519 | |
| 12520 | /* Clear and re-arm the EQ */ |
| 12521 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12522 | } |
| 12523 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12524 | |
| 12525 | /** |
| 12526 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 12527 | * entry |
| 12528 | * @phba: Pointer to HBA context object. |
| 12529 | * @eqe: Pointer to fast-path event queue entry. |
| 12530 | * |
| 12531 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 12532 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 12533 | * is for a completion event on a completion queue, if not, an error shall be |
| 12534 | * logged and just return. Otherwise, it will get to the corresponding |
| 12535 | * completion queue and process all the entries on the completion queue, rearm |
| 12536 | * the completion queue, and then return. |
| 12537 | **/ |
| 12538 | static void |
| 12539 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 12540 | { |
| 12541 | struct lpfc_queue *cq; |
| 12542 | struct lpfc_cqe *cqe; |
| 12543 | bool workposted = false; |
| 12544 | uint16_t cqid; |
| 12545 | int ecount = 0; |
| 12546 | |
| 12547 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 12548 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12549 | "9147 Not a valid completion " |
| 12550 | "event: majorcode=x%x, minorcode=x%x\n", |
| 12551 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12552 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 12553 | return; |
| 12554 | } |
| 12555 | |
| 12556 | /* Get the reference to the corresponding CQ */ |
| 12557 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12558 | |
| 12559 | /* Next check for OAS */ |
| 12560 | cq = phba->sli4_hba.oas_cq; |
| 12561 | if (unlikely(!cq)) { |
| 12562 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12563 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12564 | "9148 OAS completion queue " |
| 12565 | "does not exist\n"); |
| 12566 | return; |
| 12567 | } |
| 12568 | |
| 12569 | if (unlikely(cqid != cq->queue_id)) { |
| 12570 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12571 | "9149 Miss-matched fast-path compl " |
| 12572 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 12573 | cqid, cq->queue_id); |
| 12574 | return; |
| 12575 | } |
| 12576 | |
| 12577 | /* Process all the entries to the OAS CQ */ |
| 12578 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12579 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
| 12580 | if (!(++ecount % cq->entry_repost)) |
| 12581 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12582 | } |
| 12583 | |
| 12584 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12585 | if (ecount > cq->CQ_max_cqe) |
| 12586 | cq->CQ_max_cqe = ecount; |
| 12587 | |
| 12588 | /* Catch the no cq entry condition */ |
| 12589 | if (unlikely(ecount == 0)) |
| 12590 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12591 | "9153 No entry from fast-path completion " |
| 12592 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12593 | |
| 12594 | /* In any case, flash and re-arm the CQ */ |
| 12595 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12596 | |
| 12597 | /* wake up worker thread if there are works to be done */ |
| 12598 | if (workposted) |
| 12599 | lpfc_worker_wake_up(phba); |
| 12600 | } |
| 12601 | |
| 12602 | /** |
| 12603 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 12604 | * @irq: Interrupt number. |
| 12605 | * @dev_id: The device context pointer. |
| 12606 | * |
| 12607 | * This function is directly called from the PCI layer as an interrupt |
| 12608 | * service routine when device with SLI-4 interface spec is enabled with |
| 12609 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 12610 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 12611 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12612 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12613 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12614 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 12615 | * the intrrupt context. This function is called without any lock held. |
| 12616 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12617 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 12618 | * equal to that of CQ index. |
| 12619 | * |
| 12620 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12621 | * returns IRQ_NONE. |
| 12622 | **/ |
| 12623 | irqreturn_t |
| 12624 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 12625 | { |
| 12626 | struct lpfc_hba *phba; |
| 12627 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12628 | struct lpfc_queue *eq; |
| 12629 | struct lpfc_eqe *eqe; |
| 12630 | unsigned long iflag; |
| 12631 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12632 | |
| 12633 | /* Get the driver's phba structure from the dev_id */ |
| 12634 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12635 | phba = fcp_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12636 | |
| 12637 | if (unlikely(!phba)) |
| 12638 | return IRQ_NONE; |
| 12639 | |
| 12640 | /* Get to the EQ struct associated with this vector */ |
| 12641 | eq = phba->sli4_hba.fof_eq; |
| 12642 | if (unlikely(!eq)) |
| 12643 | return IRQ_NONE; |
| 12644 | |
| 12645 | /* Check device state for handling interrupt */ |
| 12646 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 12647 | eq->EQ_badstate++; |
| 12648 | /* Check again for link_state with lock held */ |
| 12649 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12650 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12651 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12652 | lpfc_sli4_eq_flush(phba, eq); |
| 12653 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12654 | return IRQ_NONE; |
| 12655 | } |
| 12656 | |
| 12657 | /* |
| 12658 | * Process all the event on FCP fast-path EQ |
| 12659 | */ |
| 12660 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 12661 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 12662 | if (!(++ecount % eq->entry_repost)) |
| 12663 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); |
| 12664 | eq->EQ_processed++; |
| 12665 | } |
| 12666 | |
| 12667 | /* Track the max number of EQEs processed in 1 intr */ |
| 12668 | if (ecount > eq->EQ_max_eqe) |
| 12669 | eq->EQ_max_eqe = ecount; |
| 12670 | |
| 12671 | |
| 12672 | if (unlikely(ecount == 0)) { |
| 12673 | eq->EQ_no_entry++; |
| 12674 | |
| 12675 | if (phba->intr_type == MSIX) |
| 12676 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12677 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12678 | "9145 MSI-X interrupt with no EQE\n"); |
| 12679 | else { |
| 12680 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12681 | "9146 ISR interrupt with no EQE\n"); |
| 12682 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12683 | return IRQ_NONE; |
| 12684 | } |
| 12685 | } |
| 12686 | /* Always clear and re-arm the fast-path EQ */ |
| 12687 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12688 | return IRQ_HANDLED; |
| 12689 | } |
| 12690 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12691 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12692 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12693 | * @irq: Interrupt number. |
| 12694 | * @dev_id: The device context pointer. |
| 12695 | * |
| 12696 | * This function is directly called from the PCI layer as an interrupt |
| 12697 | * service routine when device with SLI-4 interface spec is enabled with |
| 12698 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12699 | * ring event in the HBA. However, when the device is enabled with either |
| 12700 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12701 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12702 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12703 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12704 | * the intrrupt context. This function is called without any lock held. |
| 12705 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12706 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 12707 | * equal to that of FCP CQ index. |
| 12708 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12709 | * The link attention and ELS ring attention events are handled |
| 12710 | * by the worker thread. The interrupt handler signals the worker thread |
| 12711 | * and returns for these events. This function is called without any lock |
| 12712 | * held. It gets the hbalock to access and update SLI data structures. |
| 12713 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12714 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12715 | * returns IRQ_NONE. |
| 12716 | **/ |
| 12717 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12718 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12719 | { |
| 12720 | struct lpfc_hba *phba; |
| 12721 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12722 | struct lpfc_queue *fpeq; |
| 12723 | struct lpfc_eqe *eqe; |
| 12724 | unsigned long iflag; |
| 12725 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12726 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12727 | |
| 12728 | /* Get the driver's phba structure from the dev_id */ |
| 12729 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12730 | phba = fcp_eq_hdl->phba; |
| 12731 | fcp_eqidx = fcp_eq_hdl->idx; |
| 12732 | |
| 12733 | if (unlikely(!phba)) |
| 12734 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12735 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12736 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12737 | |
| 12738 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12739 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12740 | if (unlikely(!fpeq)) |
| 12741 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12742 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12743 | if (lpfc_fcp_look_ahead) { |
| 12744 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 12745 | lpfc_sli4_eq_clr_intr(fpeq); |
| 12746 | else { |
| 12747 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12748 | return IRQ_NONE; |
| 12749 | } |
| 12750 | } |
| 12751 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12752 | /* Check device state for handling interrupt */ |
| 12753 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12754 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12755 | /* Check again for link_state with lock held */ |
| 12756 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12757 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12758 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12759 | lpfc_sli4_eq_flush(phba, fpeq); |
| 12760 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12761 | if (lpfc_fcp_look_ahead) |
| 12762 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12763 | return IRQ_NONE; |
| 12764 | } |
| 12765 | |
| 12766 | /* |
| 12767 | * Process all the event on FCP fast-path EQ |
| 12768 | */ |
| 12769 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 12770 | if (eqe == NULL) |
| 12771 | break; |
| 12772 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12773 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12774 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12775 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12776 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12777 | } |
| 12778 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12779 | /* Track the max number of EQEs processed in 1 intr */ |
| 12780 | if (ecount > fpeq->EQ_max_eqe) |
| 12781 | fpeq->EQ_max_eqe = ecount; |
| 12782 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12783 | /* Always clear and re-arm the fast-path EQ */ |
| 12784 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 12785 | |
| 12786 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12787 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12788 | |
| 12789 | if (lpfc_fcp_look_ahead) { |
| 12790 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12791 | return IRQ_NONE; |
| 12792 | } |
| 12793 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12794 | if (phba->intr_type == MSIX) |
| 12795 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12796 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12797 | "0358 MSI-X interrupt with no EQE\n"); |
| 12798 | else |
| 12799 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12800 | return IRQ_NONE; |
| 12801 | } |
| 12802 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12803 | if (lpfc_fcp_look_ahead) |
| 12804 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12805 | return IRQ_HANDLED; |
| 12806 | } /* lpfc_sli4_fp_intr_handler */ |
| 12807 | |
| 12808 | /** |
| 12809 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12810 | * @irq: Interrupt number. |
| 12811 | * @dev_id: The device context pointer. |
| 12812 | * |
| 12813 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12814 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12815 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12816 | * driver attention. This function invokes the slow-path interrupt attention |
| 12817 | * handling function and fast-path interrupt attention handling function in |
| 12818 | * turn to process the relevant HBA attention events. This function is called |
| 12819 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12820 | * structures. |
| 12821 | * |
| 12822 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12823 | * returns IRQ_NONE. |
| 12824 | **/ |
| 12825 | irqreturn_t |
| 12826 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12827 | { |
| 12828 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12829 | irqreturn_t hba_irq_rc; |
| 12830 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12831 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12832 | |
| 12833 | /* Get the driver's phba structure from the dev_id */ |
| 12834 | phba = (struct lpfc_hba *)dev_id; |
| 12835 | |
| 12836 | if (unlikely(!phba)) |
| 12837 | return IRQ_NONE; |
| 12838 | |
| 12839 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12840 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12841 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12842 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12843 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12844 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12845 | if (hba_irq_rc == IRQ_HANDLED) |
| 12846 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12847 | } |
| 12848 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12849 | if (phba->cfg_fof) { |
| 12850 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
| 12851 | &phba->sli4_hba.fcp_eq_hdl[0]); |
| 12852 | if (hba_irq_rc == IRQ_HANDLED) |
| 12853 | hba_handled |= true; |
| 12854 | } |
| 12855 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12856 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12857 | } /* lpfc_sli4_intr_handler */ |
| 12858 | |
| 12859 | /** |
| 12860 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12861 | * @queue: The queue structure to free. |
| 12862 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12863 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12864 | * the host resident queue. This function must be called after destroying the |
| 12865 | * queue on the HBA. |
| 12866 | **/ |
| 12867 | void |
| 12868 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12869 | { |
| 12870 | struct lpfc_dmabuf *dmabuf; |
| 12871 | |
| 12872 | if (!queue) |
| 12873 | return; |
| 12874 | |
| 12875 | while (!list_empty(&queue->page_list)) { |
| 12876 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12877 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12878 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12879 | dmabuf->virt, dmabuf->phys); |
| 12880 | kfree(dmabuf); |
| 12881 | } |
| 12882 | kfree(queue); |
| 12883 | return; |
| 12884 | } |
| 12885 | |
| 12886 | /** |
| 12887 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12888 | * @phba: The HBA that this queue is being created on. |
| 12889 | * @entry_size: The size of each queue entry for this queue. |
| 12890 | * @entry count: The number of entries that this queue will handle. |
| 12891 | * |
| 12892 | * This function allocates a queue structure and the DMAable memory used for |
| 12893 | * the host resident queue. This function must be called before creating the |
| 12894 | * queue on the HBA. |
| 12895 | **/ |
| 12896 | struct lpfc_queue * |
| 12897 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12898 | uint32_t entry_count) |
| 12899 | { |
| 12900 | struct lpfc_queue *queue; |
| 12901 | struct lpfc_dmabuf *dmabuf; |
| 12902 | int x, total_qe_count; |
| 12903 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12904 | 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] | 12905 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12906 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12907 | hw_page_size = SLI4_PAGE_SIZE; |
| 12908 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12909 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12910 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12911 | if (!queue) |
| 12912 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12913 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12914 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12915 | INIT_LIST_HEAD(&queue->list); |
| 12916 | INIT_LIST_HEAD(&queue->page_list); |
| 12917 | INIT_LIST_HEAD(&queue->child_list); |
| 12918 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12919 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12920 | if (!dmabuf) |
| 12921 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 12922 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 12923 | hw_page_size, &dmabuf->phys, |
| 12924 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12925 | if (!dmabuf->virt) { |
| 12926 | kfree(dmabuf); |
| 12927 | goto out_fail; |
| 12928 | } |
| 12929 | dmabuf->buffer_tag = x; |
| 12930 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12931 | /* initialize queue's entry array */ |
| 12932 | dma_pointer = dmabuf->virt; |
| 12933 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12934 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12935 | total_qe_count++, dma_pointer += entry_size) { |
| 12936 | queue->qe[total_qe_count].address = dma_pointer; |
| 12937 | } |
| 12938 | } |
| 12939 | queue->entry_size = entry_size; |
| 12940 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12941 | |
| 12942 | /* |
| 12943 | * entry_repost is calculated based on the number of entries in the |
| 12944 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12945 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12946 | */ |
| 12947 | queue->entry_repost = (entry_count >> 3); |
| 12948 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12949 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12950 | queue->phba = phba; |
| 12951 | |
| 12952 | return queue; |
| 12953 | out_fail: |
| 12954 | lpfc_sli4_queue_free(queue); |
| 12955 | return NULL; |
| 12956 | } |
| 12957 | |
| 12958 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12959 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 12960 | * @phba: HBA structure that indicates port to create a queue on. |
| 12961 | * @pci_barset: PCI BAR set flag. |
| 12962 | * |
| 12963 | * This function shall perform iomap of the specified PCI BAR address to host |
| 12964 | * memory address if not already done so and return it. The returned host |
| 12965 | * memory address can be NULL. |
| 12966 | */ |
| 12967 | static void __iomem * |
| 12968 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 12969 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12970 | if (!phba->pcidev) |
| 12971 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12972 | |
| 12973 | switch (pci_barset) { |
| 12974 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12975 | return phba->pci_bar0_memmap_p; |
| 12976 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12977 | return phba->pci_bar2_memmap_p; |
| 12978 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12979 | return phba->pci_bar4_memmap_p; |
| 12980 | default: |
| 12981 | break; |
| 12982 | } |
| 12983 | return NULL; |
| 12984 | } |
| 12985 | |
| 12986 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12987 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12988 | * @phba: HBA structure that indicates port to create a queue on. |
| 12989 | * @startq: The starting FCP EQ to modify |
| 12990 | * |
| 12991 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12992 | * |
| 12993 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12994 | * is used to get the starting FCP EQ to change. |
| 12995 | * This function is asynchronous and will wait for the mailbox |
| 12996 | * command to finish before continuing. |
| 12997 | * |
| 12998 | * On success this function will return a zero. If unable to allocate enough |
| 12999 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13000 | * fails this function will return -ENXIO. |
| 13001 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13002 | int |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13003 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13004 | { |
| 13005 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 13006 | LPFC_MBOXQ_t *mbox; |
| 13007 | struct lpfc_queue *eq; |
| 13008 | int cnt, rc, length, status = 0; |
| 13009 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13010 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13011 | int fcp_eqidx; |
| 13012 | union lpfc_sli4_cfg_shdr *shdr; |
| 13013 | uint16_t dmult; |
| 13014 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13015 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13016 | return 0; |
| 13017 | |
| 13018 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13019 | if (!mbox) |
| 13020 | return -ENOMEM; |
| 13021 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 13022 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13023 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13024 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 13025 | length, LPFC_SLI4_MBX_EMBED); |
| 13026 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 13027 | |
| 13028 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13029 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 13030 | if (result > LPFC_DMULT_CONST) |
| 13031 | dmult = 0; |
| 13032 | else |
| 13033 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13034 | |
| 13035 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13036 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13037 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13038 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13039 | if (!eq) |
| 13040 | continue; |
| 13041 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 13042 | eq_delay->u.request.eq[cnt].phase = 0; |
| 13043 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 13044 | cnt++; |
| 13045 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 13046 | break; |
| 13047 | } |
| 13048 | eq_delay->u.request.num_eq = cnt; |
| 13049 | |
| 13050 | mbox->vport = phba->pport; |
| 13051 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13052 | mbox->context1 = NULL; |
| 13053 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13054 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 13055 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13056 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13057 | if (shdr_status || shdr_add_status || rc) { |
| 13058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13059 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 13060 | "status x%x add_status x%x, mbx status x%x\n", |
| 13061 | shdr_status, shdr_add_status, rc); |
| 13062 | status = -ENXIO; |
| 13063 | } |
| 13064 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13065 | return status; |
| 13066 | } |
| 13067 | |
| 13068 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13069 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 13070 | * @phba: HBA structure that indicates port to create a queue on. |
| 13071 | * @eq: The queue structure to use to create the event queue. |
| 13072 | * @imax: The maximum interrupt per second limit. |
| 13073 | * |
| 13074 | * This function creates an event queue, as detailed in @eq, on a port, |
| 13075 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 13076 | * |
| 13077 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 13078 | * is used to get the entry count and entry size that are necessary to |
| 13079 | * determine the number of pages to allocate and use for this queue. This |
| 13080 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 13081 | * event queue. This function is asynchronous and will wait for the mailbox |
| 13082 | * command to finish before continuing. |
| 13083 | * |
| 13084 | * 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] | 13085 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13086 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13087 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13088 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13089 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13090 | { |
| 13091 | struct lpfc_mbx_eq_create *eq_create; |
| 13092 | LPFC_MBOXQ_t *mbox; |
| 13093 | int rc, length, status = 0; |
| 13094 | struct lpfc_dmabuf *dmabuf; |
| 13095 | uint32_t shdr_status, shdr_add_status; |
| 13096 | union lpfc_sli4_cfg_shdr *shdr; |
| 13097 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13098 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13099 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13100 | /* sanity check on queue memory */ |
| 13101 | if (!eq) |
| 13102 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13103 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13104 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13105 | |
| 13106 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13107 | if (!mbox) |
| 13108 | return -ENOMEM; |
| 13109 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 13110 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13111 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13112 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 13113 | length, LPFC_SLI4_MBX_EMBED); |
| 13114 | eq_create = &mbox->u.mqe.un.eq_create; |
| 13115 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 13116 | eq->page_count); |
| 13117 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 13118 | LPFC_EQE_SIZE); |
| 13119 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13120 | /* don't setup delay multiplier using EQ_CREATE */ |
| 13121 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13122 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 13123 | dmult); |
| 13124 | switch (eq->entry_count) { |
| 13125 | default: |
| 13126 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13127 | "0360 Unsupported EQ count. (%d)\n", |
| 13128 | eq->entry_count); |
| 13129 | if (eq->entry_count < 256) |
| 13130 | return -EINVAL; |
| 13131 | /* otherwise default to smallest count (drop through) */ |
| 13132 | case 256: |
| 13133 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13134 | LPFC_EQ_CNT_256); |
| 13135 | break; |
| 13136 | case 512: |
| 13137 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13138 | LPFC_EQ_CNT_512); |
| 13139 | break; |
| 13140 | case 1024: |
| 13141 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13142 | LPFC_EQ_CNT_1024); |
| 13143 | break; |
| 13144 | case 2048: |
| 13145 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13146 | LPFC_EQ_CNT_2048); |
| 13147 | break; |
| 13148 | case 4096: |
| 13149 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13150 | LPFC_EQ_CNT_4096); |
| 13151 | break; |
| 13152 | } |
| 13153 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13154 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13155 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13156 | putPaddrLow(dmabuf->phys); |
| 13157 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13158 | putPaddrHigh(dmabuf->phys); |
| 13159 | } |
| 13160 | mbox->vport = phba->pport; |
| 13161 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13162 | mbox->context1 = NULL; |
| 13163 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13164 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 13165 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13166 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13167 | if (shdr_status || shdr_add_status || rc) { |
| 13168 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13169 | "2500 EQ_CREATE mailbox failed with " |
| 13170 | "status x%x add_status x%x, mbx status x%x\n", |
| 13171 | shdr_status, shdr_add_status, rc); |
| 13172 | status = -ENXIO; |
| 13173 | } |
| 13174 | eq->type = LPFC_EQ; |
| 13175 | eq->subtype = LPFC_NONE; |
| 13176 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 13177 | if (eq->queue_id == 0xFFFF) |
| 13178 | status = -ENXIO; |
| 13179 | eq->host_index = 0; |
| 13180 | eq->hba_index = 0; |
| 13181 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13182 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13183 | return status; |
| 13184 | } |
| 13185 | |
| 13186 | /** |
| 13187 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 13188 | * @phba: HBA structure that indicates port to create a queue on. |
| 13189 | * @cq: The queue structure to use to create the completion queue. |
| 13190 | * @eq: The event queue to bind this completion queue to. |
| 13191 | * |
| 13192 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 13193 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 13194 | * |
| 13195 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13196 | * is used to get the entry count and entry size that are necessary to |
| 13197 | * determine the number of pages to allocate and use for this queue. The @eq |
| 13198 | * is used to indicate which event queue to bind this completion queue to. This |
| 13199 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 13200 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 13201 | * command to finish before continuing. |
| 13202 | * |
| 13203 | * 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] | 13204 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13205 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13206 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13207 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13208 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13209 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 13210 | { |
| 13211 | struct lpfc_mbx_cq_create *cq_create; |
| 13212 | struct lpfc_dmabuf *dmabuf; |
| 13213 | LPFC_MBOXQ_t *mbox; |
| 13214 | int rc, length, status = 0; |
| 13215 | uint32_t shdr_status, shdr_add_status; |
| 13216 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13217 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13218 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13219 | /* sanity check on queue memory */ |
| 13220 | if (!cq || !eq) |
| 13221 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13222 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13223 | hw_page_size = SLI4_PAGE_SIZE; |
| 13224 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13225 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13226 | if (!mbox) |
| 13227 | return -ENOMEM; |
| 13228 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 13229 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13230 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13231 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 13232 | length, LPFC_SLI4_MBX_EMBED); |
| 13233 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13234 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13235 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 13236 | cq->page_count); |
| 13237 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 13238 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13239 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13240 | phba->sli4_hba.pc_sli4_params.cqv); |
| 13241 | 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] | 13242 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 13243 | 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] | 13244 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 13245 | eq->queue_id); |
| 13246 | } else { |
| 13247 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 13248 | eq->queue_id); |
| 13249 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13250 | switch (cq->entry_count) { |
| 13251 | default: |
| 13252 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13253 | "0361 Unsupported CQ count. (%d)\n", |
| 13254 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13255 | if (cq->entry_count < 256) { |
| 13256 | status = -EINVAL; |
| 13257 | goto out; |
| 13258 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13259 | /* otherwise default to smallest count (drop through) */ |
| 13260 | case 256: |
| 13261 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13262 | LPFC_CQ_CNT_256); |
| 13263 | break; |
| 13264 | case 512: |
| 13265 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13266 | LPFC_CQ_CNT_512); |
| 13267 | break; |
| 13268 | case 1024: |
| 13269 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13270 | LPFC_CQ_CNT_1024); |
| 13271 | break; |
| 13272 | } |
| 13273 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13274 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13275 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13276 | putPaddrLow(dmabuf->phys); |
| 13277 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13278 | putPaddrHigh(dmabuf->phys); |
| 13279 | } |
| 13280 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13281 | |
| 13282 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13283 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13284 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13285 | if (shdr_status || shdr_add_status || rc) { |
| 13286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13287 | "2501 CQ_CREATE mailbox failed with " |
| 13288 | "status x%x add_status x%x, mbx status x%x\n", |
| 13289 | shdr_status, shdr_add_status, rc); |
| 13290 | status = -ENXIO; |
| 13291 | goto out; |
| 13292 | } |
| 13293 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 13294 | if (cq->queue_id == 0xFFFF) { |
| 13295 | status = -ENXIO; |
| 13296 | goto out; |
| 13297 | } |
| 13298 | /* link the cq onto the parent eq child list */ |
| 13299 | list_add_tail(&cq->list, &eq->child_list); |
| 13300 | /* Set up completion queue's type and subtype */ |
| 13301 | cq->type = type; |
| 13302 | cq->subtype = subtype; |
| 13303 | 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] | 13304 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13305 | cq->host_index = 0; |
| 13306 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13307 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13308 | out: |
| 13309 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13310 | return status; |
| 13311 | } |
| 13312 | |
| 13313 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13314 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13315 | * @phba: HBA structure that indicates port to create a queue on. |
| 13316 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13317 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 13318 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13319 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13320 | * This function provides failback (fb) functionality when the |
| 13321 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 13322 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13323 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13324 | * This routine cannot fail as all attributes were previously accessed and |
| 13325 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13326 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13327 | static void |
| 13328 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13329 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13330 | { |
| 13331 | struct lpfc_mbx_mq_create *mq_create; |
| 13332 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13333 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13334 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13335 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 13336 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13337 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13338 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 13339 | length, LPFC_SLI4_MBX_EMBED); |
| 13340 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13341 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13342 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13343 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13344 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13345 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 13346 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13347 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13348 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13349 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13350 | break; |
| 13351 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13352 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13353 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13354 | break; |
| 13355 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13356 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13357 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13358 | break; |
| 13359 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13360 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13361 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13362 | break; |
| 13363 | } |
| 13364 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 13365 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13366 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13367 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13368 | putPaddrHigh(dmabuf->phys); |
| 13369 | } |
| 13370 | } |
| 13371 | |
| 13372 | /** |
| 13373 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 13374 | * @phba: HBA structure that indicates port to create a queue on. |
| 13375 | * @mq: The queue structure to use to create the mailbox queue. |
| 13376 | * @cq: The completion queue to associate with this cq. |
| 13377 | * @subtype: The queue's subtype. |
| 13378 | * |
| 13379 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 13380 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 13381 | * |
| 13382 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13383 | * is used to get the entry count and entry size that are necessary to |
| 13384 | * determine the number of pages to allocate and use for this queue. This |
| 13385 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 13386 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 13387 | * command to finish before continuing. |
| 13388 | * |
| 13389 | * 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] | 13390 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13391 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13392 | **/ |
| 13393 | int32_t |
| 13394 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13395 | struct lpfc_queue *cq, uint32_t subtype) |
| 13396 | { |
| 13397 | struct lpfc_mbx_mq_create *mq_create; |
| 13398 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 13399 | struct lpfc_dmabuf *dmabuf; |
| 13400 | LPFC_MBOXQ_t *mbox; |
| 13401 | int rc, length, status = 0; |
| 13402 | uint32_t shdr_status, shdr_add_status; |
| 13403 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13404 | 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] | 13405 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13406 | /* sanity check on queue memory */ |
| 13407 | if (!mq || !cq) |
| 13408 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13409 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13410 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13411 | |
| 13412 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13413 | if (!mbox) |
| 13414 | return -ENOMEM; |
| 13415 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 13416 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13417 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13418 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 13419 | length, LPFC_SLI4_MBX_EMBED); |
| 13420 | |
| 13421 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13422 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13423 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 13424 | &mq_create_ext->u.request, mq->page_count); |
| 13425 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 13426 | &mq_create_ext->u.request, 1); |
| 13427 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13428 | &mq_create_ext->u.request, 1); |
| 13429 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 13430 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13431 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 13432 | &mq_create_ext->u.request, 1); |
| 13433 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 13434 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13435 | 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] | 13436 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13437 | phba->sli4_hba.pc_sli4_params.mqv); |
| 13438 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 13439 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 13440 | cq->queue_id); |
| 13441 | else |
| 13442 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 13443 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13444 | switch (mq->entry_count) { |
| 13445 | default: |
| 13446 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13447 | "0362 Unsupported MQ count. (%d)\n", |
| 13448 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13449 | if (mq->entry_count < 16) { |
| 13450 | status = -EINVAL; |
| 13451 | goto out; |
| 13452 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13453 | /* otherwise default to smallest count (drop through) */ |
| 13454 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13455 | bf_set(lpfc_mq_context_ring_size, |
| 13456 | &mq_create_ext->u.request.context, |
| 13457 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13458 | break; |
| 13459 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13460 | bf_set(lpfc_mq_context_ring_size, |
| 13461 | &mq_create_ext->u.request.context, |
| 13462 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13463 | break; |
| 13464 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13465 | bf_set(lpfc_mq_context_ring_size, |
| 13466 | &mq_create_ext->u.request.context, |
| 13467 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13468 | break; |
| 13469 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13470 | bf_set(lpfc_mq_context_ring_size, |
| 13471 | &mq_create_ext->u.request.context, |
| 13472 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13473 | break; |
| 13474 | } |
| 13475 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13476 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13477 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13478 | putPaddrLow(dmabuf->phys); |
| 13479 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13480 | putPaddrHigh(dmabuf->phys); |
| 13481 | } |
| 13482 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13483 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13484 | &mq_create_ext->u.response); |
| 13485 | if (rc != MBX_SUCCESS) { |
| 13486 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13487 | "2795 MQ_CREATE_EXT failed with " |
| 13488 | "status x%x. Failback to MQ_CREATE.\n", |
| 13489 | rc); |
| 13490 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 13491 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13492 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13493 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 13494 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13495 | &mq_create->u.response); |
| 13496 | } |
| 13497 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13498 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13499 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13500 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13501 | if (shdr_status || shdr_add_status || rc) { |
| 13502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13503 | "2502 MQ_CREATE mailbox failed with " |
| 13504 | "status x%x add_status x%x, mbx status x%x\n", |
| 13505 | shdr_status, shdr_add_status, rc); |
| 13506 | status = -ENXIO; |
| 13507 | goto out; |
| 13508 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13509 | if (mq->queue_id == 0xFFFF) { |
| 13510 | status = -ENXIO; |
| 13511 | goto out; |
| 13512 | } |
| 13513 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13514 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13515 | mq->subtype = subtype; |
| 13516 | mq->host_index = 0; |
| 13517 | mq->hba_index = 0; |
| 13518 | |
| 13519 | /* link the mq onto the parent cq child list */ |
| 13520 | list_add_tail(&mq->list, &cq->child_list); |
| 13521 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13522 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13523 | return status; |
| 13524 | } |
| 13525 | |
| 13526 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13527 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 13528 | * @phba: HBA structure that indicates port to create a queue on. |
| 13529 | * @wq: The queue structure to use to create the work queue. |
| 13530 | * @cq: The completion queue to bind this work queue to. |
| 13531 | * @subtype: The subtype of the work queue indicating its functionality. |
| 13532 | * |
| 13533 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 13534 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 13535 | * |
| 13536 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 13537 | * is used to get the entry count and entry size that are necessary to |
| 13538 | * determine the number of pages to allocate and use for this queue. The @cq |
| 13539 | * is used to indicate which completion queue to bind this work queue to. This |
| 13540 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 13541 | * work queue. This function is asynchronous and will wait for the mailbox |
| 13542 | * command to finish before continuing. |
| 13543 | * |
| 13544 | * 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] | 13545 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13546 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13547 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13548 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13549 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 13550 | struct lpfc_queue *cq, uint32_t subtype) |
| 13551 | { |
| 13552 | struct lpfc_mbx_wq_create *wq_create; |
| 13553 | struct lpfc_dmabuf *dmabuf; |
| 13554 | LPFC_MBOXQ_t *mbox; |
| 13555 | int rc, length, status = 0; |
| 13556 | uint32_t shdr_status, shdr_add_status; |
| 13557 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13558 | 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] | 13559 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13560 | void __iomem *bar_memmap_p; |
| 13561 | uint32_t db_offset; |
| 13562 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13563 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13564 | /* sanity check on queue memory */ |
| 13565 | if (!wq || !cq) |
| 13566 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13567 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13568 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13569 | |
| 13570 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13571 | if (!mbox) |
| 13572 | return -ENOMEM; |
| 13573 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 13574 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13575 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13576 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 13577 | length, LPFC_SLI4_MBX_EMBED); |
| 13578 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13579 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13580 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 13581 | wq->page_count); |
| 13582 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 13583 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13584 | |
| 13585 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13586 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13587 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13588 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13589 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 13590 | case LPFC_Q_CREATE_VERSION_0: |
| 13591 | switch (wq->entry_size) { |
| 13592 | default: |
| 13593 | case 64: |
| 13594 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 13595 | page = wq_create->u.request.page; |
| 13596 | break; |
| 13597 | case 128: |
| 13598 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13599 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13600 | status = -ERANGE; |
| 13601 | goto out; |
| 13602 | } |
| 13603 | /* If we get here the HBA MUST also support V1 and |
| 13604 | * we MUST use it |
| 13605 | */ |
| 13606 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13607 | LPFC_Q_CREATE_VERSION_1); |
| 13608 | |
| 13609 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 13610 | &wq_create->u.request_1, wq->entry_count); |
| 13611 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13612 | &wq_create->u.request_1, |
| 13613 | LPFC_WQ_WQE_SIZE_128); |
| 13614 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13615 | &wq_create->u.request_1, |
| 13616 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13617 | page = wq_create->u.request_1.page; |
| 13618 | break; |
| 13619 | } |
| 13620 | break; |
| 13621 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13622 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 13623 | wq->entry_count); |
| 13624 | switch (wq->entry_size) { |
| 13625 | default: |
| 13626 | case 64: |
| 13627 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13628 | &wq_create->u.request_1, |
| 13629 | LPFC_WQ_WQE_SIZE_64); |
| 13630 | break; |
| 13631 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13632 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13633 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13634 | status = -ERANGE; |
| 13635 | goto out; |
| 13636 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13637 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13638 | &wq_create->u.request_1, |
| 13639 | LPFC_WQ_WQE_SIZE_128); |
| 13640 | break; |
| 13641 | } |
| 13642 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 13643 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13644 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13645 | break; |
| 13646 | default: |
| 13647 | status = -ERANGE; |
| 13648 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13649 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13650 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13651 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13652 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13653 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 13654 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13655 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13656 | |
| 13657 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13658 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 13659 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13660 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13661 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13662 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13663 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13664 | if (shdr_status || shdr_add_status || rc) { |
| 13665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13666 | "2503 WQ_CREATE mailbox failed with " |
| 13667 | "status x%x add_status x%x, mbx status x%x\n", |
| 13668 | shdr_status, shdr_add_status, rc); |
| 13669 | status = -ENXIO; |
| 13670 | goto out; |
| 13671 | } |
| 13672 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 13673 | if (wq->queue_id == 0xFFFF) { |
| 13674 | status = -ENXIO; |
| 13675 | goto out; |
| 13676 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13677 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13678 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 13679 | &wq_create->u.response); |
| 13680 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13681 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13683 | "3265 WQ[%d] doorbell format not " |
| 13684 | "supported: x%x\n", wq->queue_id, |
| 13685 | wq->db_format); |
| 13686 | status = -EINVAL; |
| 13687 | goto out; |
| 13688 | } |
| 13689 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 13690 | &wq_create->u.response); |
| 13691 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13692 | if (!bar_memmap_p) { |
| 13693 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13694 | "3263 WQ[%d] failed to memmap pci " |
| 13695 | "barset:x%x\n", wq->queue_id, |
| 13696 | pci_barset); |
| 13697 | status = -ENOMEM; |
| 13698 | goto out; |
| 13699 | } |
| 13700 | db_offset = wq_create->u.response.doorbell_offset; |
| 13701 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 13702 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 13703 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13704 | "3252 WQ[%d] doorbell offset not " |
| 13705 | "supported: x%x\n", wq->queue_id, |
| 13706 | db_offset); |
| 13707 | status = -EINVAL; |
| 13708 | goto out; |
| 13709 | } |
| 13710 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 13711 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13712 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 13713 | "format:x%x\n", wq->queue_id, pci_barset, |
| 13714 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13715 | } else { |
| 13716 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 13717 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 13718 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13719 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13720 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13721 | wq->subtype = subtype; |
| 13722 | wq->host_index = 0; |
| 13723 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 13724 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13725 | |
| 13726 | /* link the wq onto the parent cq child list */ |
| 13727 | list_add_tail(&wq->list, &cq->child_list); |
| 13728 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13729 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13730 | return status; |
| 13731 | } |
| 13732 | |
| 13733 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13734 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 13735 | * @phba: HBA structure that indicates port to create a queue on. |
| 13736 | * @rq: The queue structure to use for the receive queue. |
| 13737 | * @qno: The associated HBQ number |
| 13738 | * |
| 13739 | * |
| 13740 | * For SLI4 we need to adjust the RQ repost value based on |
| 13741 | * the number of buffers that are initially posted to the RQ. |
| 13742 | */ |
| 13743 | void |
| 13744 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 13745 | { |
| 13746 | uint32_t cnt; |
| 13747 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13748 | /* sanity check on queue memory */ |
| 13749 | if (!rq) |
| 13750 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13751 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 13752 | |
| 13753 | /* Recalc repost for RQs based on buffers initially posted */ |
| 13754 | cnt = (cnt >> 3); |
| 13755 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 13756 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 13757 | |
| 13758 | rq->entry_repost = cnt; |
| 13759 | } |
| 13760 | |
| 13761 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13762 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 13763 | * @phba: HBA structure that indicates port to create a queue on. |
| 13764 | * @hrq: The queue structure to use to create the header receive queue. |
| 13765 | * @drq: The queue structure to use to create the data receive queue. |
| 13766 | * @cq: The completion queue to bind this work queue to. |
| 13767 | * |
| 13768 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 13769 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 13770 | * to the HBA. |
| 13771 | * |
| 13772 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 13773 | * struct is used to get the entry count that is necessary to determine the |
| 13774 | * number of pages to use for this queue. The @cq is used to indicate which |
| 13775 | * completion queue to bind received buffers that are posted to these queues to. |
| 13776 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 13777 | * receive queue pair. This function is asynchronous and will wait for the |
| 13778 | * mailbox command to finish before continuing. |
| 13779 | * |
| 13780 | * 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] | 13781 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13782 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13783 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13784 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13785 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13786 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 13787 | { |
| 13788 | struct lpfc_mbx_rq_create *rq_create; |
| 13789 | struct lpfc_dmabuf *dmabuf; |
| 13790 | LPFC_MBOXQ_t *mbox; |
| 13791 | int rc, length, status = 0; |
| 13792 | uint32_t shdr_status, shdr_add_status; |
| 13793 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13794 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13795 | void __iomem *bar_memmap_p; |
| 13796 | uint32_t db_offset; |
| 13797 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13798 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13799 | /* sanity check on queue memory */ |
| 13800 | if (!hrq || !drq || !cq) |
| 13801 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13802 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13803 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13804 | |
| 13805 | if (hrq->entry_count != drq->entry_count) |
| 13806 | return -EINVAL; |
| 13807 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13808 | if (!mbox) |
| 13809 | return -ENOMEM; |
| 13810 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 13811 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13812 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13813 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13814 | length, LPFC_SLI4_MBX_EMBED); |
| 13815 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13816 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13817 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13818 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13819 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13820 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13821 | &rq_create->u.request.context, |
| 13822 | hrq->entry_count); |
| 13823 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13824 | bf_set(lpfc_rq_context_rqe_size, |
| 13825 | &rq_create->u.request.context, |
| 13826 | LPFC_RQE_SIZE_8); |
| 13827 | bf_set(lpfc_rq_context_page_size, |
| 13828 | &rq_create->u.request.context, |
| 13829 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13830 | } else { |
| 13831 | switch (hrq->entry_count) { |
| 13832 | default: |
| 13833 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13834 | "2535 Unsupported RQ count. (%d)\n", |
| 13835 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13836 | if (hrq->entry_count < 512) { |
| 13837 | status = -EINVAL; |
| 13838 | goto out; |
| 13839 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13840 | /* otherwise default to smallest count (drop through) */ |
| 13841 | case 512: |
| 13842 | bf_set(lpfc_rq_context_rqe_count, |
| 13843 | &rq_create->u.request.context, |
| 13844 | LPFC_RQ_RING_SIZE_512); |
| 13845 | break; |
| 13846 | case 1024: |
| 13847 | bf_set(lpfc_rq_context_rqe_count, |
| 13848 | &rq_create->u.request.context, |
| 13849 | LPFC_RQ_RING_SIZE_1024); |
| 13850 | break; |
| 13851 | case 2048: |
| 13852 | bf_set(lpfc_rq_context_rqe_count, |
| 13853 | &rq_create->u.request.context, |
| 13854 | LPFC_RQ_RING_SIZE_2048); |
| 13855 | break; |
| 13856 | case 4096: |
| 13857 | bf_set(lpfc_rq_context_rqe_count, |
| 13858 | &rq_create->u.request.context, |
| 13859 | LPFC_RQ_RING_SIZE_4096); |
| 13860 | break; |
| 13861 | } |
| 13862 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13863 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13864 | } |
| 13865 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13866 | cq->queue_id); |
| 13867 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13868 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13869 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13870 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13871 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13872 | putPaddrLow(dmabuf->phys); |
| 13873 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13874 | putPaddrHigh(dmabuf->phys); |
| 13875 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13876 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13877 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 13878 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13879 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13880 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13881 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13882 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13883 | if (shdr_status || shdr_add_status || rc) { |
| 13884 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13885 | "2504 RQ_CREATE mailbox failed with " |
| 13886 | "status x%x add_status x%x, mbx status x%x\n", |
| 13887 | shdr_status, shdr_add_status, rc); |
| 13888 | status = -ENXIO; |
| 13889 | goto out; |
| 13890 | } |
| 13891 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13892 | if (hrq->queue_id == 0xFFFF) { |
| 13893 | status = -ENXIO; |
| 13894 | goto out; |
| 13895 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13896 | |
| 13897 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13898 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13899 | &rq_create->u.response); |
| 13900 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13901 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13903 | "3262 RQ [%d] doorbell format not " |
| 13904 | "supported: x%x\n", hrq->queue_id, |
| 13905 | hrq->db_format); |
| 13906 | status = -EINVAL; |
| 13907 | goto out; |
| 13908 | } |
| 13909 | |
| 13910 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 13911 | &rq_create->u.response); |
| 13912 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13913 | if (!bar_memmap_p) { |
| 13914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13915 | "3269 RQ[%d] failed to memmap pci " |
| 13916 | "barset:x%x\n", hrq->queue_id, |
| 13917 | pci_barset); |
| 13918 | status = -ENOMEM; |
| 13919 | goto out; |
| 13920 | } |
| 13921 | |
| 13922 | db_offset = rq_create->u.response.doorbell_offset; |
| 13923 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 13924 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 13925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13926 | "3270 RQ[%d] doorbell offset not " |
| 13927 | "supported: x%x\n", hrq->queue_id, |
| 13928 | db_offset); |
| 13929 | status = -EINVAL; |
| 13930 | goto out; |
| 13931 | } |
| 13932 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 13933 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13934 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 13935 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 13936 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13937 | } else { |
| 13938 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 13939 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 13940 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13941 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13942 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13943 | hrq->subtype = subtype; |
| 13944 | hrq->host_index = 0; |
| 13945 | hrq->hba_index = 0; |
| 13946 | |
| 13947 | /* now create the data queue */ |
| 13948 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13949 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13950 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13951 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13952 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13953 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13954 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13955 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13956 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13957 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 13958 | LPFC_RQE_SIZE_8); |
| 13959 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 13960 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13961 | } else { |
| 13962 | switch (drq->entry_count) { |
| 13963 | default: |
| 13964 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13965 | "2536 Unsupported RQ count. (%d)\n", |
| 13966 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13967 | if (drq->entry_count < 512) { |
| 13968 | status = -EINVAL; |
| 13969 | goto out; |
| 13970 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13971 | /* otherwise default to smallest count (drop through) */ |
| 13972 | case 512: |
| 13973 | bf_set(lpfc_rq_context_rqe_count, |
| 13974 | &rq_create->u.request.context, |
| 13975 | LPFC_RQ_RING_SIZE_512); |
| 13976 | break; |
| 13977 | case 1024: |
| 13978 | bf_set(lpfc_rq_context_rqe_count, |
| 13979 | &rq_create->u.request.context, |
| 13980 | LPFC_RQ_RING_SIZE_1024); |
| 13981 | break; |
| 13982 | case 2048: |
| 13983 | bf_set(lpfc_rq_context_rqe_count, |
| 13984 | &rq_create->u.request.context, |
| 13985 | LPFC_RQ_RING_SIZE_2048); |
| 13986 | break; |
| 13987 | case 4096: |
| 13988 | bf_set(lpfc_rq_context_rqe_count, |
| 13989 | &rq_create->u.request.context, |
| 13990 | LPFC_RQ_RING_SIZE_4096); |
| 13991 | break; |
| 13992 | } |
| 13993 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13994 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13995 | } |
| 13996 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13997 | cq->queue_id); |
| 13998 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13999 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14000 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 14001 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14002 | putPaddrLow(dmabuf->phys); |
| 14003 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14004 | putPaddrHigh(dmabuf->phys); |
| 14005 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14006 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 14007 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14008 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14009 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14010 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 14011 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14012 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14013 | if (shdr_status || shdr_add_status || rc) { |
| 14014 | status = -ENXIO; |
| 14015 | goto out; |
| 14016 | } |
| 14017 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 14018 | if (drq->queue_id == 0xFFFF) { |
| 14019 | status = -ENXIO; |
| 14020 | goto out; |
| 14021 | } |
| 14022 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14023 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14024 | drq->subtype = subtype; |
| 14025 | drq->host_index = 0; |
| 14026 | drq->hba_index = 0; |
| 14027 | |
| 14028 | /* link the header and data RQs onto the parent cq child list */ |
| 14029 | list_add_tail(&hrq->list, &cq->child_list); |
| 14030 | list_add_tail(&drq->list, &cq->child_list); |
| 14031 | |
| 14032 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14033 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14034 | return status; |
| 14035 | } |
| 14036 | |
| 14037 | /** |
| 14038 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 14039 | * @eq: The queue structure associated with the queue to destroy. |
| 14040 | * |
| 14041 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 14042 | * command, specific to the type of queue, to the HBA. |
| 14043 | * |
| 14044 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 14045 | * |
| 14046 | * 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] | 14047 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14048 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14049 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14050 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 14051 | { |
| 14052 | LPFC_MBOXQ_t *mbox; |
| 14053 | int rc, length, status = 0; |
| 14054 | uint32_t shdr_status, shdr_add_status; |
| 14055 | union lpfc_sli4_cfg_shdr *shdr; |
| 14056 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14057 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14058 | if (!eq) |
| 14059 | return -ENODEV; |
| 14060 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14061 | if (!mbox) |
| 14062 | return -ENOMEM; |
| 14063 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 14064 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14065 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14066 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 14067 | length, LPFC_SLI4_MBX_EMBED); |
| 14068 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 14069 | eq->queue_id); |
| 14070 | mbox->vport = eq->phba->pport; |
| 14071 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14072 | |
| 14073 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 14074 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14075 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14076 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 14077 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14078 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14079 | if (shdr_status || shdr_add_status || rc) { |
| 14080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14081 | "2505 EQ_DESTROY mailbox failed with " |
| 14082 | "status x%x add_status x%x, mbx status x%x\n", |
| 14083 | shdr_status, shdr_add_status, rc); |
| 14084 | status = -ENXIO; |
| 14085 | } |
| 14086 | |
| 14087 | /* Remove eq from any list */ |
| 14088 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14089 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14090 | return status; |
| 14091 | } |
| 14092 | |
| 14093 | /** |
| 14094 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 14095 | * @cq: The queue structure associated with the queue to destroy. |
| 14096 | * |
| 14097 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 14098 | * command, specific to the type of queue, to the HBA. |
| 14099 | * |
| 14100 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 14101 | * |
| 14102 | * 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] | 14103 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14104 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14105 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14106 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 14107 | { |
| 14108 | LPFC_MBOXQ_t *mbox; |
| 14109 | int rc, length, status = 0; |
| 14110 | uint32_t shdr_status, shdr_add_status; |
| 14111 | union lpfc_sli4_cfg_shdr *shdr; |
| 14112 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14113 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14114 | if (!cq) |
| 14115 | return -ENODEV; |
| 14116 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14117 | if (!mbox) |
| 14118 | return -ENOMEM; |
| 14119 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 14120 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14121 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14122 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 14123 | length, LPFC_SLI4_MBX_EMBED); |
| 14124 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 14125 | cq->queue_id); |
| 14126 | mbox->vport = cq->phba->pport; |
| 14127 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14128 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 14129 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14130 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14131 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 14132 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14133 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14134 | if (shdr_status || shdr_add_status || rc) { |
| 14135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14136 | "2506 CQ_DESTROY mailbox failed with " |
| 14137 | "status x%x add_status x%x, mbx status x%x\n", |
| 14138 | shdr_status, shdr_add_status, rc); |
| 14139 | status = -ENXIO; |
| 14140 | } |
| 14141 | /* Remove cq from any list */ |
| 14142 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14143 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14144 | return status; |
| 14145 | } |
| 14146 | |
| 14147 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14148 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 14149 | * @qm: The queue structure associated with the queue to destroy. |
| 14150 | * |
| 14151 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 14152 | * command, specific to the type of queue, to the HBA. |
| 14153 | * |
| 14154 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 14155 | * |
| 14156 | * 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] | 14157 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14158 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14159 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14160 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 14161 | { |
| 14162 | LPFC_MBOXQ_t *mbox; |
| 14163 | int rc, length, status = 0; |
| 14164 | uint32_t shdr_status, shdr_add_status; |
| 14165 | union lpfc_sli4_cfg_shdr *shdr; |
| 14166 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14167 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14168 | if (!mq) |
| 14169 | return -ENODEV; |
| 14170 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14171 | if (!mbox) |
| 14172 | return -ENOMEM; |
| 14173 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 14174 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14175 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14176 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 14177 | length, LPFC_SLI4_MBX_EMBED); |
| 14178 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 14179 | mq->queue_id); |
| 14180 | mbox->vport = mq->phba->pport; |
| 14181 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14182 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 14183 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14184 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14185 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 14186 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14187 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14188 | if (shdr_status || shdr_add_status || rc) { |
| 14189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14190 | "2507 MQ_DESTROY mailbox failed with " |
| 14191 | "status x%x add_status x%x, mbx status x%x\n", |
| 14192 | shdr_status, shdr_add_status, rc); |
| 14193 | status = -ENXIO; |
| 14194 | } |
| 14195 | /* Remove mq from any list */ |
| 14196 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14197 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14198 | return status; |
| 14199 | } |
| 14200 | |
| 14201 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14202 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 14203 | * @wq: The queue structure associated with the queue to destroy. |
| 14204 | * |
| 14205 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 14206 | * command, specific to the type of queue, to the HBA. |
| 14207 | * |
| 14208 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 14209 | * |
| 14210 | * 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] | 14211 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14212 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14213 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14214 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 14215 | { |
| 14216 | LPFC_MBOXQ_t *mbox; |
| 14217 | int rc, length, status = 0; |
| 14218 | uint32_t shdr_status, shdr_add_status; |
| 14219 | union lpfc_sli4_cfg_shdr *shdr; |
| 14220 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14221 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14222 | if (!wq) |
| 14223 | return -ENODEV; |
| 14224 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14225 | if (!mbox) |
| 14226 | return -ENOMEM; |
| 14227 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 14228 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14229 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14230 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 14231 | length, LPFC_SLI4_MBX_EMBED); |
| 14232 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 14233 | wq->queue_id); |
| 14234 | mbox->vport = wq->phba->pport; |
| 14235 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14236 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 14237 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14238 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 14239 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14240 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14241 | if (shdr_status || shdr_add_status || rc) { |
| 14242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14243 | "2508 WQ_DESTROY mailbox failed with " |
| 14244 | "status x%x add_status x%x, mbx status x%x\n", |
| 14245 | shdr_status, shdr_add_status, rc); |
| 14246 | status = -ENXIO; |
| 14247 | } |
| 14248 | /* Remove wq from any list */ |
| 14249 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14250 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14251 | return status; |
| 14252 | } |
| 14253 | |
| 14254 | /** |
| 14255 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 14256 | * @rq: The queue structure associated with the queue to destroy. |
| 14257 | * |
| 14258 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 14259 | * command, specific to the type of queue, to the HBA. |
| 14260 | * |
| 14261 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 14262 | * |
| 14263 | * 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] | 14264 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14265 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14266 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14267 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 14268 | struct lpfc_queue *drq) |
| 14269 | { |
| 14270 | LPFC_MBOXQ_t *mbox; |
| 14271 | int rc, length, status = 0; |
| 14272 | uint32_t shdr_status, shdr_add_status; |
| 14273 | union lpfc_sli4_cfg_shdr *shdr; |
| 14274 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14275 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14276 | if (!hrq || !drq) |
| 14277 | return -ENODEV; |
| 14278 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14279 | if (!mbox) |
| 14280 | return -ENOMEM; |
| 14281 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14282 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14283 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14284 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 14285 | length, LPFC_SLI4_MBX_EMBED); |
| 14286 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14287 | hrq->queue_id); |
| 14288 | mbox->vport = hrq->phba->pport; |
| 14289 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14290 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 14291 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14292 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14293 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14294 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14295 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14296 | if (shdr_status || shdr_add_status || rc) { |
| 14297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14298 | "2509 RQ_DESTROY mailbox failed with " |
| 14299 | "status x%x add_status x%x, mbx status x%x\n", |
| 14300 | shdr_status, shdr_add_status, rc); |
| 14301 | if (rc != MBX_TIMEOUT) |
| 14302 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 14303 | return -ENXIO; |
| 14304 | } |
| 14305 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14306 | drq->queue_id); |
| 14307 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 14308 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14309 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14310 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14311 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14312 | if (shdr_status || shdr_add_status || rc) { |
| 14313 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14314 | "2510 RQ_DESTROY mailbox failed with " |
| 14315 | "status x%x add_status x%x, mbx status x%x\n", |
| 14316 | shdr_status, shdr_add_status, rc); |
| 14317 | status = -ENXIO; |
| 14318 | } |
| 14319 | list_del_init(&hrq->list); |
| 14320 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14321 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14322 | return status; |
| 14323 | } |
| 14324 | |
| 14325 | /** |
| 14326 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 14327 | * @phba: The virtual port for which this call being executed. |
| 14328 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 14329 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 14330 | * @xritag: the xritag that ties this io to the SGL pages. |
| 14331 | * |
| 14332 | * This routine will post the sgl pages for the IO that has the xritag |
| 14333 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 14334 | * creation and persists for as long as the driver is loaded. |
| 14335 | * if the caller has fewer than 256 scatter gather segments to map then |
| 14336 | * pdma_phys_addr1 should be 0. |
| 14337 | * If the caller needs to map more than 256 scatter gather segment then |
| 14338 | * pdma_phys_addr1 should be a valid physical address. |
| 14339 | * physical address for SGLs must be 64 byte aligned. |
| 14340 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 14341 | * the second sgl can have between 1 and 256 entries. |
| 14342 | * |
| 14343 | * Return codes: |
| 14344 | * 0 - Success |
| 14345 | * -ENXIO, -ENOMEM - Failure |
| 14346 | **/ |
| 14347 | int |
| 14348 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 14349 | dma_addr_t pdma_phys_addr0, |
| 14350 | dma_addr_t pdma_phys_addr1, |
| 14351 | uint16_t xritag) |
| 14352 | { |
| 14353 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 14354 | LPFC_MBOXQ_t *mbox; |
| 14355 | int rc; |
| 14356 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14357 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14358 | union lpfc_sli4_cfg_shdr *shdr; |
| 14359 | |
| 14360 | if (xritag == NO_XRI) { |
| 14361 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14362 | "0364 Invalid param:\n"); |
| 14363 | return -EINVAL; |
| 14364 | } |
| 14365 | |
| 14366 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14367 | if (!mbox) |
| 14368 | return -ENOMEM; |
| 14369 | |
| 14370 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14371 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 14372 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14373 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14374 | |
| 14375 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 14376 | &mbox->u.mqe.un.post_sgl_pages; |
| 14377 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 14378 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 14379 | |
| 14380 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 14381 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 14382 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 14383 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 14384 | |
| 14385 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 14386 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 14387 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 14388 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 14389 | if (!phba->sli4_hba.intr_enable) |
| 14390 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14391 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14392 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14393 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14394 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14395 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14396 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 14397 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14398 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14399 | if (rc != MBX_TIMEOUT) |
| 14400 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14401 | if (shdr_status || shdr_add_status || rc) { |
| 14402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14403 | "2511 POST_SGL mailbox failed with " |
| 14404 | "status x%x add_status x%x, mbx status x%x\n", |
| 14405 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14406 | } |
| 14407 | return 0; |
| 14408 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14409 | |
| 14410 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14411 | * 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] | 14412 | * @phba: pointer to lpfc hba data structure. |
| 14413 | * |
| 14414 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14415 | * HBA consistent with the SLI-4 interface spec. This routine |
| 14416 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14417 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14418 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14419 | * Returns |
| 14420 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 14421 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14422 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14423 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14424 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 14425 | { |
| 14426 | unsigned long xri; |
| 14427 | |
| 14428 | /* |
| 14429 | * Fetch the next logical xri. Because this index is logical, |
| 14430 | * the driver starts at 0 each time. |
| 14431 | */ |
| 14432 | spin_lock_irq(&phba->hbalock); |
| 14433 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 14434 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 14435 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 14436 | spin_unlock_irq(&phba->hbalock); |
| 14437 | return NO_XRI; |
| 14438 | } else { |
| 14439 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 14440 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14441 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14442 | spin_unlock_irq(&phba->hbalock); |
| 14443 | return xri; |
| 14444 | } |
| 14445 | |
| 14446 | /** |
| 14447 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14448 | * @phba: pointer to lpfc hba data structure. |
| 14449 | * |
| 14450 | * This routine is invoked to release an xri to the pool of |
| 14451 | * available rpis maintained by the driver. |
| 14452 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14453 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14454 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14455 | { |
| 14456 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14457 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 14458 | } |
| 14459 | } |
| 14460 | |
| 14461 | /** |
| 14462 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14463 | * @phba: pointer to lpfc hba data structure. |
| 14464 | * |
| 14465 | * This routine is invoked to release an xri to the pool of |
| 14466 | * available rpis maintained by the driver. |
| 14467 | **/ |
| 14468 | void |
| 14469 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14470 | { |
| 14471 | spin_lock_irq(&phba->hbalock); |
| 14472 | __lpfc_sli4_free_xri(phba, xri); |
| 14473 | spin_unlock_irq(&phba->hbalock); |
| 14474 | } |
| 14475 | |
| 14476 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14477 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 14478 | * @phba: Pointer to HBA context object. |
| 14479 | * |
| 14480 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 14481 | * it will return 0xffff. |
| 14482 | * The function returns the allocated xritag if successful, else returns zero. |
| 14483 | * Zero is not a valid xritag. |
| 14484 | * The caller is not required to hold any lock. |
| 14485 | **/ |
| 14486 | uint16_t |
| 14487 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 14488 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14489 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14490 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14491 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 14492 | if (xri_index == NO_XRI) |
| 14493 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14494 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 14495 | " Max XRI is %d, Used XRI is %d\n", |
| 14496 | xri_index, |
| 14497 | phba->sli4_hba.max_cfg_param.max_xri, |
| 14498 | phba->sli4_hba.max_cfg_param.xri_used); |
| 14499 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14500 | } |
| 14501 | |
| 14502 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14503 | * 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] | 14504 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14505 | * @post_sgl_list: pointer to els sgl entry list. |
| 14506 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14507 | * |
| 14508 | * This routine is invoked to post a block of driver's sgl pages to the |
| 14509 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 14510 | * is only called when the driver is loading and after all IO has been |
| 14511 | * stopped. |
| 14512 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14513 | static int |
| 14514 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 14515 | struct list_head *post_sgl_list, |
| 14516 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14517 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14518 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14519 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14520 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14521 | void *viraddr; |
| 14522 | LPFC_MBOXQ_t *mbox; |
| 14523 | uint32_t reqlen, alloclen, pg_pairs; |
| 14524 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14525 | uint16_t xritag_start = 0; |
| 14526 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14527 | uint32_t shdr_status, shdr_add_status; |
| 14528 | union lpfc_sli4_cfg_shdr *shdr; |
| 14529 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14530 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14531 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14532 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14533 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14534 | "2559 Block sgl registration required DMA " |
| 14535 | "size (%d) great than a page\n", reqlen); |
| 14536 | return -ENOMEM; |
| 14537 | } |
| 14538 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14539 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14540 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14541 | |
| 14542 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14543 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14544 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14545 | LPFC_SLI4_MBX_NEMBED); |
| 14546 | |
| 14547 | if (alloclen < reqlen) { |
| 14548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14549 | "0285 Allocated DMA memory size (%d) is " |
| 14550 | "less than the requested DMA memory " |
| 14551 | "size (%d)\n", alloclen, reqlen); |
| 14552 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14553 | return -ENOMEM; |
| 14554 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14555 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14556 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14557 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14558 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14559 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14560 | pg_pairs = 0; |
| 14561 | 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] | 14562 | /* Set up the sge entry */ |
| 14563 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14564 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 14565 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14566 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 14567 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14568 | cpu_to_le32(putPaddrLow(0)); |
| 14569 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14570 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14571 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14572 | /* Keep the first xritag on the list */ |
| 14573 | if (pg_pairs == 0) |
| 14574 | xritag_start = sglq_entry->sli4_xritag; |
| 14575 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14576 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14577 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14578 | |
| 14579 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14580 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14581 | 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] | 14582 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14583 | if (!phba->sli4_hba.intr_enable) |
| 14584 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14585 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14586 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14587 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14588 | } |
| 14589 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14590 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14591 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14592 | if (rc != MBX_TIMEOUT) |
| 14593 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14594 | if (shdr_status || shdr_add_status || rc) { |
| 14595 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14596 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 14597 | "status x%x add_status x%x mbx status x%x\n", |
| 14598 | shdr_status, shdr_add_status, rc); |
| 14599 | rc = -ENXIO; |
| 14600 | } |
| 14601 | return rc; |
| 14602 | } |
| 14603 | |
| 14604 | /** |
| 14605 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 14606 | * @phba: pointer to lpfc hba data structure. |
| 14607 | * @sblist: pointer to scsi buffer list. |
| 14608 | * @count: number of scsi buffers on the list. |
| 14609 | * |
| 14610 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 14611 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 14612 | * No Lock is held. |
| 14613 | * |
| 14614 | **/ |
| 14615 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14616 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 14617 | struct list_head *sblist, |
| 14618 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14619 | { |
| 14620 | struct lpfc_scsi_buf *psb; |
| 14621 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14622 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14623 | void *viraddr; |
| 14624 | LPFC_MBOXQ_t *mbox; |
| 14625 | uint32_t reqlen, alloclen, pg_pairs; |
| 14626 | uint32_t mbox_tmo; |
| 14627 | uint16_t xritag_start = 0; |
| 14628 | int rc = 0; |
| 14629 | uint32_t shdr_status, shdr_add_status; |
| 14630 | dma_addr_t pdma_phys_bpl1; |
| 14631 | union lpfc_sli4_cfg_shdr *shdr; |
| 14632 | |
| 14633 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14634 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14635 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14636 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14637 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14638 | "0217 Block sgl registration required DMA " |
| 14639 | "size (%d) great than a page\n", reqlen); |
| 14640 | return -ENOMEM; |
| 14641 | } |
| 14642 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14643 | if (!mbox) { |
| 14644 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14645 | "0283 Failed to allocate mbox cmd memory\n"); |
| 14646 | return -ENOMEM; |
| 14647 | } |
| 14648 | |
| 14649 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14650 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14651 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14652 | LPFC_SLI4_MBX_NEMBED); |
| 14653 | |
| 14654 | if (alloclen < reqlen) { |
| 14655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14656 | "2561 Allocated DMA memory size (%d) is " |
| 14657 | "less than the requested DMA memory " |
| 14658 | "size (%d)\n", alloclen, reqlen); |
| 14659 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14660 | return -ENOMEM; |
| 14661 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14662 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14663 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14664 | viraddr = mbox->sge_array->addr[0]; |
| 14665 | |
| 14666 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 14667 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14668 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14669 | |
| 14670 | pg_pairs = 0; |
| 14671 | list_for_each_entry(psb, sblist, list) { |
| 14672 | /* Set up the sge entry */ |
| 14673 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14674 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 14675 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14676 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 14677 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 14678 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 14679 | else |
| 14680 | pdma_phys_bpl1 = 0; |
| 14681 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14682 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 14683 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14684 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 14685 | /* Keep the first xritag on the list */ |
| 14686 | if (pg_pairs == 0) |
| 14687 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 14688 | sgl_pg_pairs++; |
| 14689 | pg_pairs++; |
| 14690 | } |
| 14691 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 14692 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 14693 | /* Perform endian conversion if necessary */ |
| 14694 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 14695 | |
| 14696 | if (!phba->sli4_hba.intr_enable) |
| 14697 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14698 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14699 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14700 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14701 | } |
| 14702 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14703 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14704 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14705 | if (rc != MBX_TIMEOUT) |
| 14706 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14707 | if (shdr_status || shdr_add_status || rc) { |
| 14708 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14709 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 14710 | "status x%x add_status x%x mbx status x%x\n", |
| 14711 | shdr_status, shdr_add_status, rc); |
| 14712 | rc = -ENXIO; |
| 14713 | } |
| 14714 | return rc; |
| 14715 | } |
| 14716 | |
| 14717 | /** |
| 14718 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 14719 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 14720 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14721 | * |
| 14722 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 14723 | * valid type of frame that the LPFC driver will handle. This function will |
| 14724 | * return a zero if the frame is a valid frame or a non zero value when the |
| 14725 | * frame does not pass the check. |
| 14726 | **/ |
| 14727 | static int |
| 14728 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 14729 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 14730 | /* make rctl_names static to save stack space */ |
| 14731 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14732 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 14733 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14734 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14735 | |
| 14736 | switch (fc_hdr->fh_r_ctl) { |
| 14737 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 14738 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 14739 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 14740 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 14741 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 14742 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 14743 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 14744 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 14745 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 14746 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 14747 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 14748 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 14749 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 14750 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 14751 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 14752 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 14753 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 14754 | case FC_RCTL_BA_PRMT: |
| 14755 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 14756 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 14757 | case FC_RCTL_P_RJT: /* port reject */ |
| 14758 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 14759 | case FC_RCTL_P_BSY: /* port busy */ |
| 14760 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 14761 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 14762 | case FC_RCTL_LCR: /* link credit reset */ |
| 14763 | case FC_RCTL_END: /* end */ |
| 14764 | break; |
| 14765 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 14766 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14767 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 14768 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 14769 | default: |
| 14770 | goto drop; |
| 14771 | } |
| 14772 | switch (fc_hdr->fh_type) { |
| 14773 | case FC_TYPE_BLS: |
| 14774 | case FC_TYPE_ELS: |
| 14775 | case FC_TYPE_FCP: |
| 14776 | case FC_TYPE_CT: |
| 14777 | break; |
| 14778 | case FC_TYPE_IP: |
| 14779 | case FC_TYPE_ILS: |
| 14780 | default: |
| 14781 | goto drop; |
| 14782 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14783 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14784 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14785 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
| 14786 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
| 14787 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, |
| 14788 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14789 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 14790 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14791 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 14792 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14793 | return 0; |
| 14794 | drop: |
| 14795 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14796 | "2539 Dropped frame rctl:%s type:%s\n", |
| 14797 | rctl_names[fc_hdr->fh_r_ctl], |
| 14798 | type_names[fc_hdr->fh_type]); |
| 14799 | return 1; |
| 14800 | } |
| 14801 | |
| 14802 | /** |
| 14803 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 14804 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14805 | * |
| 14806 | * This function processes the FC header to retrieve the VFI from the VF |
| 14807 | * header, if one exists. This function will return the VFI if one exists |
| 14808 | * or 0 if no VSAN Header exists. |
| 14809 | **/ |
| 14810 | static uint32_t |
| 14811 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 14812 | { |
| 14813 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14814 | |
| 14815 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14816 | return 0; |
| 14817 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14818 | } |
| 14819 | |
| 14820 | /** |
| 14821 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14822 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14823 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14824 | * @fcfi: The FC Fabric ID that the frame came from |
| 14825 | * |
| 14826 | * This function searches the @phba for a vport that matches the content of the |
| 14827 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14828 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14829 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14830 | * vport. |
| 14831 | **/ |
| 14832 | static struct lpfc_vport * |
| 14833 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14834 | uint16_t fcfi) |
| 14835 | { |
| 14836 | struct lpfc_vport **vports; |
| 14837 | struct lpfc_vport *vport = NULL; |
| 14838 | int i; |
| 14839 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14840 | fc_hdr->fh_d_id[1] << 8 | |
| 14841 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14842 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14843 | if (did == Fabric_DID) |
| 14844 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14845 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14846 | !(phba->link_state == LPFC_HBA_READY)) |
| 14847 | return phba->pport; |
| 14848 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14849 | vports = lpfc_create_vport_work_array(phba); |
| 14850 | if (vports != NULL) |
| 14851 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14852 | if (phba->fcf.fcfi == fcfi && |
| 14853 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14854 | vports[i]->fc_myDID == did) { |
| 14855 | vport = vports[i]; |
| 14856 | break; |
| 14857 | } |
| 14858 | } |
| 14859 | lpfc_destroy_vport_work_array(phba, vports); |
| 14860 | return vport; |
| 14861 | } |
| 14862 | |
| 14863 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14864 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14865 | * @vport: The vport to work on. |
| 14866 | * |
| 14867 | * This function updates the receive sequence time stamp for this vport. The |
| 14868 | * receive sequence time stamp indicates the time that the last frame of the |
| 14869 | * the sequence that has been idle for the longest amount of time was received. |
| 14870 | * the driver uses this time stamp to indicate if any received sequences have |
| 14871 | * timed out. |
| 14872 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14873 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14874 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14875 | { |
| 14876 | struct lpfc_dmabuf *h_buf; |
| 14877 | struct hbq_dmabuf *dmabuf = NULL; |
| 14878 | |
| 14879 | /* get the oldest sequence on the rcv list */ |
| 14880 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14881 | struct lpfc_dmabuf, list); |
| 14882 | if (!h_buf) |
| 14883 | return; |
| 14884 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14885 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14886 | } |
| 14887 | |
| 14888 | /** |
| 14889 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14890 | * @vport: The vport that the received sequences were sent to. |
| 14891 | * |
| 14892 | * This function cleans up all outstanding received sequences. This is called |
| 14893 | * by the driver when a link event or user action invalidates all the received |
| 14894 | * sequences. |
| 14895 | **/ |
| 14896 | void |
| 14897 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14898 | { |
| 14899 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14900 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14901 | struct hbq_dmabuf *dmabuf = NULL; |
| 14902 | |
| 14903 | /* start with the oldest sequence on the rcv list */ |
| 14904 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14905 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14906 | list_del_init(&dmabuf->hbuf.list); |
| 14907 | list_for_each_entry_safe(d_buf, dnext, |
| 14908 | &dmabuf->dbuf.list, list) { |
| 14909 | list_del_init(&d_buf->list); |
| 14910 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14911 | } |
| 14912 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14913 | } |
| 14914 | } |
| 14915 | |
| 14916 | /** |
| 14917 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 14918 | * @vport: The vport that the received sequences were sent to. |
| 14919 | * |
| 14920 | * This function determines whether any received sequences have timed out by |
| 14921 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 14922 | * indicates that there is at least one timed out sequence this routine will |
| 14923 | * go through the received sequences one at a time from most inactive to most |
| 14924 | * active to determine which ones need to be cleaned up. Once it has determined |
| 14925 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 14926 | * without sending an abort. |
| 14927 | **/ |
| 14928 | void |
| 14929 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 14930 | { |
| 14931 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14932 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14933 | struct hbq_dmabuf *dmabuf = NULL; |
| 14934 | unsigned long timeout; |
| 14935 | int abort_count = 0; |
| 14936 | |
| 14937 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14938 | vport->rcv_buffer_time_stamp); |
| 14939 | if (list_empty(&vport->rcv_buffer_list) || |
| 14940 | time_before(jiffies, timeout)) |
| 14941 | return; |
| 14942 | /* start with the oldest sequence on the rcv list */ |
| 14943 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14944 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14945 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14946 | dmabuf->time_stamp); |
| 14947 | if (time_before(jiffies, timeout)) |
| 14948 | break; |
| 14949 | abort_count++; |
| 14950 | list_del_init(&dmabuf->hbuf.list); |
| 14951 | list_for_each_entry_safe(d_buf, dnext, |
| 14952 | &dmabuf->dbuf.list, list) { |
| 14953 | list_del_init(&d_buf->list); |
| 14954 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14955 | } |
| 14956 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14957 | } |
| 14958 | if (abort_count) |
| 14959 | lpfc_update_rcv_time_stamp(vport); |
| 14960 | } |
| 14961 | |
| 14962 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14963 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 14964 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 14965 | * |
| 14966 | * This function searches through the existing incomplete sequences that have |
| 14967 | * been sent to this @vport. If the frame matches one of the incomplete |
| 14968 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 14969 | * make up that sequence. If no sequence is found that matches this frame then |
| 14970 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 14971 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 14972 | * the frame was linked to. |
| 14973 | **/ |
| 14974 | static struct hbq_dmabuf * |
| 14975 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14976 | { |
| 14977 | struct fc_frame_header *new_hdr; |
| 14978 | struct fc_frame_header *temp_hdr; |
| 14979 | struct lpfc_dmabuf *d_buf; |
| 14980 | struct lpfc_dmabuf *h_buf; |
| 14981 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14982 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 14983 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14984 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14985 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14986 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14987 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 14988 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14989 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 14990 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14991 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14992 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14993 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14994 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14995 | continue; |
| 14996 | /* found a pending sequence that matches this frame */ |
| 14997 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14998 | break; |
| 14999 | } |
| 15000 | if (!seq_dmabuf) { |
| 15001 | /* |
| 15002 | * This indicates first frame received for this sequence. |
| 15003 | * Queue the buffer on the vport's rcv_buffer_list. |
| 15004 | */ |
| 15005 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15006 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15007 | return dmabuf; |
| 15008 | } |
| 15009 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15010 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 15011 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15012 | list_del_init(&seq_dmabuf->hbuf.list); |
| 15013 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15014 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15015 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15016 | return dmabuf; |
| 15017 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15018 | /* move this sequence to the tail to indicate a young sequence */ |
| 15019 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15020 | seq_dmabuf->time_stamp = jiffies; |
| 15021 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15022 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 15023 | temp_hdr = dmabuf->hbuf.virt; |
| 15024 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 15025 | return seq_dmabuf; |
| 15026 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15027 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15028 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 15029 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15030 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15031 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 15032 | /* |
| 15033 | * If the frame's sequence count is greater than the frame on |
| 15034 | * the list then insert the frame right after this frame |
| 15035 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15036 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 15037 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15038 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15039 | found = 1; |
| 15040 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15041 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15042 | |
| 15043 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 15044 | break; |
| 15045 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15046 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15047 | |
| 15048 | if (found) |
| 15049 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15050 | return NULL; |
| 15051 | } |
| 15052 | |
| 15053 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15054 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 15055 | * @vport: pointer to a vitural port |
| 15056 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15057 | * |
| 15058 | * This function tries to abort from the partially assembed sequence, described |
| 15059 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 15060 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 15061 | * the frames from the partially assembled sequence. |
| 15062 | * |
| 15063 | * Return |
| 15064 | * true -- if there is matching partially assembled sequence present and all |
| 15065 | * the frames freed with the sequence; |
| 15066 | * false -- if there is no matching partially assembled sequence present so |
| 15067 | * nothing got aborted in the lower layer driver |
| 15068 | **/ |
| 15069 | static bool |
| 15070 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 15071 | struct hbq_dmabuf *dmabuf) |
| 15072 | { |
| 15073 | struct fc_frame_header *new_hdr; |
| 15074 | struct fc_frame_header *temp_hdr; |
| 15075 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 15076 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 15077 | |
| 15078 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 15079 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 15080 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 15081 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15082 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 15083 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 15084 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 15085 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 15086 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 15087 | continue; |
| 15088 | /* found a pending sequence that matches this frame */ |
| 15089 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15090 | break; |
| 15091 | } |
| 15092 | |
| 15093 | /* Free up all the frames from the partially assembled sequence */ |
| 15094 | if (seq_dmabuf) { |
| 15095 | list_for_each_entry_safe(d_buf, n_buf, |
| 15096 | &seq_dmabuf->dbuf.list, list) { |
| 15097 | list_del_init(&d_buf->list); |
| 15098 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15099 | } |
| 15100 | return true; |
| 15101 | } |
| 15102 | return false; |
| 15103 | } |
| 15104 | |
| 15105 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15106 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 15107 | * @vport: pointer to a vitural port |
| 15108 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15109 | * |
| 15110 | * This function tries to abort from the assembed sequence from upper level |
| 15111 | * protocol, described by the information from basic abbort @dmabuf. It |
| 15112 | * checks to see whether such pending context exists at upper level protocol. |
| 15113 | * If so, it shall clean up the pending context. |
| 15114 | * |
| 15115 | * Return |
| 15116 | * true -- if there is matching pending context of the sequence cleaned |
| 15117 | * at ulp; |
| 15118 | * false -- if there is no matching pending context of the sequence present |
| 15119 | * at ulp. |
| 15120 | **/ |
| 15121 | static bool |
| 15122 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 15123 | { |
| 15124 | struct lpfc_hba *phba = vport->phba; |
| 15125 | int handled; |
| 15126 | |
| 15127 | /* Accepting abort at ulp with SLI4 only */ |
| 15128 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15129 | return false; |
| 15130 | |
| 15131 | /* Register all caring upper level protocols to attend abort */ |
| 15132 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 15133 | if (handled) |
| 15134 | return true; |
| 15135 | |
| 15136 | return false; |
| 15137 | } |
| 15138 | |
| 15139 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15140 | * 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] | 15141 | * @phba: Pointer to HBA context object. |
| 15142 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 15143 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 15144 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15145 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15146 | * event. It properly releases the memory allocated to the sequence abort |
| 15147 | * accept iocb. |
| 15148 | **/ |
| 15149 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15150 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15151 | struct lpfc_iocbq *cmd_iocbq, |
| 15152 | struct lpfc_iocbq *rsp_iocbq) |
| 15153 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15154 | struct lpfc_nodelist *ndlp; |
| 15155 | |
| 15156 | if (cmd_iocbq) { |
| 15157 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 15158 | lpfc_nlp_put(ndlp); |
| 15159 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15160 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15161 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15162 | |
| 15163 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 15164 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 15165 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15166 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 15167 | rsp_iocbq->iocb.ulpStatus, |
| 15168 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15169 | } |
| 15170 | |
| 15171 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15172 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 15173 | * @phba: Pointer to HBA context object. |
| 15174 | * @xri: xri id in transaction. |
| 15175 | * |
| 15176 | * This function validates the xri maps to the known range of XRIs allocated an |
| 15177 | * used by the driver. |
| 15178 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15179 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15180 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 15181 | uint16_t xri) |
| 15182 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15183 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15184 | |
| 15185 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 15186 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 15187 | return i; |
| 15188 | } |
| 15189 | return NO_XRI; |
| 15190 | } |
| 15191 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15192 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15193 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15194 | * @phba: Pointer to HBA context object. |
| 15195 | * @fc_hdr: pointer to a FC frame header. |
| 15196 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15197 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15198 | * event after aborting the sequence handling. |
| 15199 | **/ |
| 15200 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15201 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 15202 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15203 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15204 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15205 | struct lpfc_iocbq *ctiocb = NULL; |
| 15206 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15207 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15208 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15209 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15210 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15211 | |
| 15212 | if (!lpfc_is_link_up(phba)) |
| 15213 | return; |
| 15214 | |
| 15215 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 15216 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15217 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15218 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15219 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15220 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15221 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 15222 | if (!ndlp) { |
| 15223 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15224 | "1268 Failed to allocate ndlp for " |
| 15225 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 15226 | return; |
| 15227 | } |
| 15228 | lpfc_nlp_init(vport, ndlp, sid); |
| 15229 | /* Put ndlp onto pport node list */ |
| 15230 | lpfc_enqueue_node(vport, ndlp); |
| 15231 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 15232 | /* re-setup ndlp without removing from node list */ |
| 15233 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 15234 | if (!ndlp) { |
| 15235 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15236 | "3275 Failed to active ndlp found " |
| 15237 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 15238 | return; |
| 15239 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15240 | } |
| 15241 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15242 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15243 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 15244 | if (!ctiocb) |
| 15245 | return; |
| 15246 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15247 | /* Extract the F_CTL field from FC_HDR */ |
| 15248 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 15249 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15250 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15251 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15252 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15253 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 15254 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 15255 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 15256 | |
| 15257 | /* Fill in the rest of iocb fields */ |
| 15258 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 15259 | icmd->ulpBdeCount = 0; |
| 15260 | icmd->ulpLe = 1; |
| 15261 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15262 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15263 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15264 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15265 | ctiocb->iocb_cmpl = NULL; |
| 15266 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15267 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15268 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15269 | ctiocb->sli4_xritag = NO_XRI; |
| 15270 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15271 | if (fctl & FC_FC_EX_CTX) |
| 15272 | /* Exchange responder sent the abort so we |
| 15273 | * own the oxid. |
| 15274 | */ |
| 15275 | xri = oxid; |
| 15276 | else |
| 15277 | xri = rxid; |
| 15278 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 15279 | if (lxri != NO_XRI) |
| 15280 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 15281 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15282 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 15283 | * the oxid maps to the FCP XRI range, the port no longer has |
| 15284 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 15285 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15286 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15287 | if ((fctl & FC_FC_EX_CTX) && |
| 15288 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 15289 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15290 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15291 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15292 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15293 | } |
| 15294 | |
| 15295 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 15296 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 15297 | * the IOCB for a BA_RJT. |
| 15298 | */ |
| 15299 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15300 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15301 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15302 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15303 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15304 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15305 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15306 | if (fctl & FC_FC_EX_CTX) { |
| 15307 | /* ABTS sent by responder to CT exchange, construction |
| 15308 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 15309 | * field and RX_ID from ABTS for RX_ID field. |
| 15310 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15311 | 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] | 15312 | } else { |
| 15313 | /* ABTS sent by initiator to CT exchange, construction |
| 15314 | * 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] | 15315 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15316 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15317 | 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] | 15318 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 15319 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15320 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15321 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15322 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 15324 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 15325 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15326 | |
| 15327 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 15328 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 15330 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 15331 | "xri x%x, Data x%x\n", |
| 15332 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 15333 | phba->link_state); |
| 15334 | lpfc_nlp_put(ndlp); |
| 15335 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15336 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 15337 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15338 | } |
| 15339 | |
| 15340 | /** |
| 15341 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 15342 | * @vport: Pointer to the vport on which this sequence was received |
| 15343 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15344 | * |
| 15345 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 15346 | * receive sequence is only partially assembed by the driver, it shall abort |
| 15347 | * the partially assembled frames for the sequence. Otherwise, if the |
| 15348 | * unsolicited receive sequence has been completely assembled and passed to |
| 15349 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 15350 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 15351 | * accept to accept the abort. |
| 15352 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15353 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15354 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 15355 | struct hbq_dmabuf *dmabuf) |
| 15356 | { |
| 15357 | struct lpfc_hba *phba = vport->phba; |
| 15358 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15359 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15360 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15361 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15362 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 15363 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15364 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15365 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15366 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15367 | /* ABTS by responder to exchange, no cleanup needed */ |
| 15368 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15369 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15370 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 15371 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 15372 | if (aborted == false) |
| 15373 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15374 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15375 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15376 | |
| 15377 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 15378 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15379 | } |
| 15380 | |
| 15381 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15382 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 15383 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15384 | * |
| 15385 | * This function checks the sequence, starting with the frame described by |
| 15386 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 15387 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 15388 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 15389 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 15390 | * set. 3) That there are no holes in the sequence count. The function will |
| 15391 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 15392 | **/ |
| 15393 | static int |
| 15394 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 15395 | { |
| 15396 | struct fc_frame_header *hdr; |
| 15397 | struct lpfc_dmabuf *d_buf; |
| 15398 | struct hbq_dmabuf *seq_dmabuf; |
| 15399 | uint32_t fctl; |
| 15400 | int seq_count = 0; |
| 15401 | |
| 15402 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15403 | /* make sure first fame of sequence has a sequence count of zero */ |
| 15404 | if (hdr->fh_seq_cnt != seq_count) |
| 15405 | return 0; |
| 15406 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15407 | hdr->fh_f_ctl[1] << 8 | |
| 15408 | hdr->fh_f_ctl[2]); |
| 15409 | /* If last frame of sequence we can return success. */ |
| 15410 | if (fctl & FC_FC_END_SEQ) |
| 15411 | return 1; |
| 15412 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 15413 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15414 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15415 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15416 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15417 | return 0; |
| 15418 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15419 | hdr->fh_f_ctl[1] << 8 | |
| 15420 | hdr->fh_f_ctl[2]); |
| 15421 | /* If last frame of sequence we can return success. */ |
| 15422 | if (fctl & FC_FC_END_SEQ) |
| 15423 | return 1; |
| 15424 | } |
| 15425 | return 0; |
| 15426 | } |
| 15427 | |
| 15428 | /** |
| 15429 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 15430 | * @vport: Pointer to the vport on which this sequence was received |
| 15431 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15432 | * |
| 15433 | * This function takes a sequence, described by a list of frames, and creates |
| 15434 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 15435 | * used to issue to the generic unsolicited sequence handler. This routine |
| 15436 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 15437 | * to allocate an iocbq then it throw out the received frames that were not |
| 15438 | * able to be described and return a pointer to the first iocbq. If unable to |
| 15439 | * allocate any iocbqs (including the first) this function will return NULL. |
| 15440 | **/ |
| 15441 | static struct lpfc_iocbq * |
| 15442 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 15443 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15444 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15445 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 15446 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 15447 | struct fc_frame_header *fc_hdr; |
| 15448 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15449 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15450 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15451 | |
| 15452 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15453 | /* remove from receive buffer list */ |
| 15454 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15455 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15456 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15457 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15458 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15459 | /* Get an iocbq struct to fill in. */ |
| 15460 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15461 | if (first_iocbq) { |
| 15462 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15463 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15464 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15465 | |
| 15466 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 15467 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 15468 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 15469 | first_iocbq->iocb.un.rcvels.parmRo = |
| 15470 | sli4_did_from_fc_hdr(fc_hdr); |
| 15471 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 15472 | } else |
| 15473 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15474 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 15475 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 15476 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 15477 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 15478 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 15479 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15480 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15481 | tot_len = bf_get(lpfc_rcqe_length, |
| 15482 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15483 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15484 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 15485 | first_iocbq->context3 = NULL; |
| 15486 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15487 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 15488 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15489 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15490 | else |
| 15491 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 15492 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15493 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15494 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15495 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15496 | } |
| 15497 | iocbq = first_iocbq; |
| 15498 | /* |
| 15499 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 15500 | * of buffers for this sequence and save two buffers in each IOCBq |
| 15501 | */ |
| 15502 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 15503 | if (!iocbq) { |
| 15504 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15505 | continue; |
| 15506 | } |
| 15507 | if (!iocbq->context3) { |
| 15508 | iocbq->context3 = d_buf; |
| 15509 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15510 | /* We need to get the size out of the right CQE */ |
| 15511 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15512 | len = bf_get(lpfc_rcqe_length, |
| 15513 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15514 | pbde = (struct ulp_bde64 *) |
| 15515 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 15516 | if (len > LPFC_DATA_BUF_SIZE) |
| 15517 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 15518 | else |
| 15519 | pbde->tus.f.bdeSize = len; |
| 15520 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15521 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 15522 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15523 | } else { |
| 15524 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15525 | if (!iocbq) { |
| 15526 | if (first_iocbq) { |
| 15527 | first_iocbq->iocb.ulpStatus = |
| 15528 | IOSTAT_FCP_RSP_ERROR; |
| 15529 | first_iocbq->iocb.un.ulpWord[4] = |
| 15530 | IOERR_NO_RESOURCES; |
| 15531 | } |
| 15532 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15533 | continue; |
| 15534 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15535 | /* We need to get the size out of the right CQE */ |
| 15536 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15537 | len = bf_get(lpfc_rcqe_length, |
| 15538 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15539 | iocbq->context2 = d_buf; |
| 15540 | iocbq->context3 = NULL; |
| 15541 | iocbq->iocb.ulpBdeCount = 1; |
| 15542 | if (len > LPFC_DATA_BUF_SIZE) |
| 15543 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 15544 | LPFC_DATA_BUF_SIZE; |
| 15545 | else |
| 15546 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 15547 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15548 | tot_len += len; |
| 15549 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 15550 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15551 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 15552 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 15553 | } |
| 15554 | } |
| 15555 | return first_iocbq; |
| 15556 | } |
| 15557 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15558 | static void |
| 15559 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 15560 | struct hbq_dmabuf *seq_dmabuf) |
| 15561 | { |
| 15562 | struct fc_frame_header *fc_hdr; |
| 15563 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 15564 | struct lpfc_hba *phba = vport->phba; |
| 15565 | |
| 15566 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15567 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 15568 | if (!iocbq) { |
| 15569 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15570 | "2707 Ring %d handler: Failed to allocate " |
| 15571 | "iocb Rctl x%x Type x%x received\n", |
| 15572 | LPFC_ELS_RING, |
| 15573 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15574 | return; |
| 15575 | } |
| 15576 | if (!lpfc_complete_unsol_iocb(phba, |
| 15577 | &phba->sli.ring[LPFC_ELS_RING], |
| 15578 | iocbq, fc_hdr->fh_r_ctl, |
| 15579 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15580 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15581 | "2540 Ring %d handler: unexpected Rctl " |
| 15582 | "x%x Type x%x received\n", |
| 15583 | LPFC_ELS_RING, |
| 15584 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15585 | |
| 15586 | /* Free iocb created in lpfc_prep_seq */ |
| 15587 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 15588 | &iocbq->list, list) { |
| 15589 | list_del_init(&curr_iocb->list); |
| 15590 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 15591 | } |
| 15592 | lpfc_sli_release_iocbq(phba, iocbq); |
| 15593 | } |
| 15594 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15595 | /** |
| 15596 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 15597 | * @phba: Pointer to HBA context object. |
| 15598 | * |
| 15599 | * This function is called with no lock held. This function processes all |
| 15600 | * the received buffers and gives it to upper layers when a received buffer |
| 15601 | * indicates that it is the final frame in the sequence. The interrupt |
| 15602 | * service routine processes received buffers at interrupt contexts and adds |
| 15603 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 15604 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 15605 | * appropriate receive function when the final frame in a sequence is received. |
| 15606 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15607 | void |
| 15608 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 15609 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15610 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15611 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15612 | struct fc_frame_header *fc_hdr; |
| 15613 | struct lpfc_vport *vport; |
| 15614 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15615 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15616 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15617 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15618 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15619 | /* check to see if this a valid type of frame */ |
| 15620 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 15621 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15622 | return; |
| 15623 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15624 | if ((bf_get(lpfc_cqe_code, |
| 15625 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 15626 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 15627 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15628 | else |
| 15629 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 15630 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15631 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15632 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15633 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15634 | /* throw out the frame */ |
| 15635 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15636 | return; |
| 15637 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15638 | |
| 15639 | /* d_id this frame is directed to */ |
| 15640 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 15641 | |
| 15642 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 15643 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 15644 | (did != Fabric_DID)) { |
| 15645 | /* |
| 15646 | * Throw out the frame if we are not pt2pt. |
| 15647 | * The pt2pt protocol allows for discovery frames |
| 15648 | * to be received without a registered VPI. |
| 15649 | */ |
| 15650 | if (!(vport->fc_flag & FC_PT2PT) || |
| 15651 | (phba->link_state == LPFC_HBA_READY)) { |
| 15652 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15653 | return; |
| 15654 | } |
| 15655 | } |
| 15656 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15657 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 15658 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 15659 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 15660 | return; |
| 15661 | } |
| 15662 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15663 | /* Link this frame */ |
| 15664 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 15665 | if (!seq_dmabuf) { |
| 15666 | /* unable to add frame to vport - throw it out */ |
| 15667 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15668 | return; |
| 15669 | } |
| 15670 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15671 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15672 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15673 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15674 | /* Send the complete sequence to the upper layer protocol */ |
| 15675 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15676 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15677 | |
| 15678 | /** |
| 15679 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 15680 | * @phba: pointer to lpfc hba data structure. |
| 15681 | * |
| 15682 | * This routine is invoked to post rpi header templates to the |
| 15683 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15684 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15685 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15686 | * |
| 15687 | * This routine does not require any locks. It's usage is expected |
| 15688 | * to be driver load or reset recovery when the driver is |
| 15689 | * sequential. |
| 15690 | * |
| 15691 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15692 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15693 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15694 | * When this error occurs, the driver is not guaranteed |
| 15695 | * to have any rpi regions posted to the device and |
| 15696 | * must either attempt to repost the regions or take a |
| 15697 | * fatal error. |
| 15698 | **/ |
| 15699 | int |
| 15700 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 15701 | { |
| 15702 | struct lpfc_rpi_hdr *rpi_page; |
| 15703 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15704 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15705 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15706 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15707 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15708 | goto exit; |
| 15709 | if (phba->sli4_hba.extents_in_use) |
| 15710 | return -EIO; |
| 15711 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15712 | 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] | 15713 | /* |
| 15714 | * Assign the rpi headers a physical rpi only if the driver |
| 15715 | * has not initialized those resources. A port reset only |
| 15716 | * needs the headers posted. |
| 15717 | */ |
| 15718 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 15719 | LPFC_RPI_RSRC_RDY) |
| 15720 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 15721 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15722 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 15723 | if (rc != MBX_SUCCESS) { |
| 15724 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15725 | "2008 Error %d posting all rpi " |
| 15726 | "headers\n", rc); |
| 15727 | rc = -EIO; |
| 15728 | break; |
| 15729 | } |
| 15730 | } |
| 15731 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15732 | exit: |
| 15733 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 15734 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15735 | return rc; |
| 15736 | } |
| 15737 | |
| 15738 | /** |
| 15739 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 15740 | * @phba: pointer to lpfc hba data structure. |
| 15741 | * @rpi_page: pointer to the rpi memory region. |
| 15742 | * |
| 15743 | * This routine is invoked to post a single rpi header to the |
| 15744 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 15745 | * maps up to 64 rpi context regions. |
| 15746 | * |
| 15747 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15748 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15749 | * -ENOMEM - No available memory |
| 15750 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15751 | **/ |
| 15752 | int |
| 15753 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 15754 | { |
| 15755 | LPFC_MBOXQ_t *mboxq; |
| 15756 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 15757 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15758 | uint32_t shdr_status, shdr_add_status; |
| 15759 | union lpfc_sli4_cfg_shdr *shdr; |
| 15760 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15761 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15762 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15763 | return rc; |
| 15764 | if (phba->sli4_hba.extents_in_use) |
| 15765 | return -EIO; |
| 15766 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15767 | /* The port is notified of the header region via a mailbox command. */ |
| 15768 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15769 | if (!mboxq) { |
| 15770 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15771 | "2001 Unable to allocate memory for issuing " |
| 15772 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 15773 | return -ENOMEM; |
| 15774 | } |
| 15775 | |
| 15776 | /* Post all rpi memory regions to the port. */ |
| 15777 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15778 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15779 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 15780 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15781 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 15782 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15783 | |
| 15784 | |
| 15785 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15786 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 15787 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15788 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 15789 | hdr_tmpl, rpi_page->page_count); |
| 15790 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15791 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 15792 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 15793 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15794 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 15795 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15796 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15797 | if (rc != MBX_TIMEOUT) |
| 15798 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15799 | if (shdr_status || shdr_add_status || rc) { |
| 15800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15801 | "2514 POST_RPI_HDR mailbox failed with " |
| 15802 | "status x%x add_status x%x, mbx status x%x\n", |
| 15803 | shdr_status, shdr_add_status, rc); |
| 15804 | rc = -ENXIO; |
| 15805 | } |
| 15806 | return rc; |
| 15807 | } |
| 15808 | |
| 15809 | /** |
| 15810 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 15811 | * @phba: pointer to lpfc hba data structure. |
| 15812 | * |
| 15813 | * This routine is invoked to post rpi header templates to the |
| 15814 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15815 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15816 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15817 | * |
| 15818 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15819 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15820 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15821 | **/ |
| 15822 | int |
| 15823 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 15824 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15825 | unsigned long rpi; |
| 15826 | uint16_t max_rpi, rpi_limit; |
| 15827 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15828 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15829 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15830 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15831 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15832 | * Fetch the next logical rpi. Because this index is logical, |
| 15833 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15834 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15835 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15836 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 15837 | rpi_limit = phba->sli4_hba.next_rpi; |
| 15838 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15839 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15840 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15841 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15842 | else { |
| 15843 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15844 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15845 | phba->sli4_hba.rpi_count++; |
| 15846 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15847 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 15848 | "0001 rpi:%x max:%x lim:%x\n", |
| 15849 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15850 | |
| 15851 | /* |
| 15852 | * 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] | 15853 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15854 | */ |
| 15855 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15856 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15857 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15858 | return rpi; |
| 15859 | } |
| 15860 | |
| 15861 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15862 | * RPI header postings are not required for SLI4 ports capable of |
| 15863 | * extents. |
| 15864 | */ |
| 15865 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15866 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15867 | return rpi; |
| 15868 | } |
| 15869 | |
| 15870 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15871 | * If the driver is running low on rpi resources, allocate another |
| 15872 | * page now. Note that the next_rpi value is used because |
| 15873 | * it represents how many are actually in use whereas max_rpi notes |
| 15874 | * how many are supported max by the device. |
| 15875 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15876 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15877 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15878 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15879 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15880 | if (!rpi_hdr) { |
| 15881 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15882 | "2002 Error Could not grow rpi " |
| 15883 | "count\n"); |
| 15884 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15885 | lrpi = rpi_hdr->start_rpi; |
| 15886 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15887 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15888 | } |
| 15889 | } |
| 15890 | |
| 15891 | return rpi; |
| 15892 | } |
| 15893 | |
| 15894 | /** |
| 15895 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15896 | * @phba: pointer to lpfc hba data structure. |
| 15897 | * |
| 15898 | * This routine is invoked to release an rpi to the pool of |
| 15899 | * available rpis maintained by the driver. |
| 15900 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15901 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15902 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15903 | { |
| 15904 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 15905 | phba->sli4_hba.rpi_count--; |
| 15906 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 15907 | } |
| 15908 | } |
| 15909 | |
| 15910 | /** |
| 15911 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15912 | * @phba: pointer to lpfc hba data structure. |
| 15913 | * |
| 15914 | * This routine is invoked to release an rpi to the pool of |
| 15915 | * available rpis maintained by the driver. |
| 15916 | **/ |
| 15917 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15918 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15919 | { |
| 15920 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15921 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15922 | spin_unlock_irq(&phba->hbalock); |
| 15923 | } |
| 15924 | |
| 15925 | /** |
| 15926 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 15927 | * @phba: pointer to lpfc hba data structure. |
| 15928 | * |
| 15929 | * This routine is invoked to remove the memory region that |
| 15930 | * provided rpi via a bitmask. |
| 15931 | **/ |
| 15932 | void |
| 15933 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 15934 | { |
| 15935 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15936 | kfree(phba->sli4_hba.rpi_ids); |
| 15937 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15938 | } |
| 15939 | |
| 15940 | /** |
| 15941 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 15942 | * @phba: pointer to lpfc hba data structure. |
| 15943 | * |
| 15944 | * This routine is invoked to remove the memory region that |
| 15945 | * provided rpi via a bitmask. |
| 15946 | **/ |
| 15947 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15948 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 15949 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15950 | { |
| 15951 | LPFC_MBOXQ_t *mboxq; |
| 15952 | struct lpfc_hba *phba = ndlp->phba; |
| 15953 | int rc; |
| 15954 | |
| 15955 | /* The port is notified of the header region via a mailbox command. */ |
| 15956 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15957 | if (!mboxq) |
| 15958 | return -ENOMEM; |
| 15959 | |
| 15960 | /* Post all rpi memory regions to the port. */ |
| 15961 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15962 | if (cmpl) { |
| 15963 | mboxq->mbox_cmpl = cmpl; |
| 15964 | mboxq->context1 = arg; |
| 15965 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 15966 | } else |
| 15967 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15968 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15969 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15970 | if (rc == MBX_NOT_FINISHED) { |
| 15971 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15972 | "2010 Resume RPI Mailbox failed " |
| 15973 | "status %d, mbxStatus x%x\n", rc, |
| 15974 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 15975 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15976 | return -EIO; |
| 15977 | } |
| 15978 | return 0; |
| 15979 | } |
| 15980 | |
| 15981 | /** |
| 15982 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15983 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15984 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15985 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15986 | * |
| 15987 | * Returns: |
| 15988 | * 0 success |
| 15989 | * -Evalue otherwise |
| 15990 | **/ |
| 15991 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15992 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15993 | { |
| 15994 | LPFC_MBOXQ_t *mboxq; |
| 15995 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15996 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15997 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15998 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15999 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16000 | if (!mboxq) |
| 16001 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16002 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16003 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16004 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16005 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16006 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16007 | "2022 INIT VPI Mailbox failed " |
| 16008 | "status %d, mbxStatus x%x\n", rc, |
| 16009 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16010 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16011 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16012 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16013 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16014 | |
| 16015 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16016 | } |
| 16017 | |
| 16018 | /** |
| 16019 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 16020 | * @phba: pointer to lpfc hba data structure. |
| 16021 | * @mboxq: Pointer to mailbox object. |
| 16022 | * |
| 16023 | * This routine is invoked to manually add a single FCF record. The caller |
| 16024 | * must pass a completely initialized FCF_Record. This routine takes |
| 16025 | * care of the nonembedded mailbox operations. |
| 16026 | **/ |
| 16027 | static void |
| 16028 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 16029 | { |
| 16030 | void *virt_addr; |
| 16031 | union lpfc_sli4_cfg_shdr *shdr; |
| 16032 | uint32_t shdr_status, shdr_add_status; |
| 16033 | |
| 16034 | virt_addr = mboxq->sge_array->addr[0]; |
| 16035 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16036 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 16037 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16038 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16039 | |
| 16040 | if ((shdr_status || shdr_add_status) && |
| 16041 | (shdr_status != STATUS_FCF_IN_USE)) |
| 16042 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16043 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 16044 | "status x%x add_status x%x\n", |
| 16045 | shdr_status, shdr_add_status); |
| 16046 | |
| 16047 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16048 | } |
| 16049 | |
| 16050 | /** |
| 16051 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 16052 | * @phba: pointer to lpfc hba data structure. |
| 16053 | * @fcf_record: pointer to the initialized fcf record to add. |
| 16054 | * |
| 16055 | * This routine is invoked to manually add a single FCF record. The caller |
| 16056 | * must pass a completely initialized FCF_Record. This routine takes |
| 16057 | * care of the nonembedded mailbox operations. |
| 16058 | **/ |
| 16059 | int |
| 16060 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 16061 | { |
| 16062 | int rc = 0; |
| 16063 | LPFC_MBOXQ_t *mboxq; |
| 16064 | uint8_t *bytep; |
| 16065 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16066 | struct lpfc_mbx_sge sge; |
| 16067 | uint32_t alloc_len, req_len; |
| 16068 | uint32_t fcfindex; |
| 16069 | |
| 16070 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16071 | if (!mboxq) { |
| 16072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16073 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 16074 | return -ENOMEM; |
| 16075 | } |
| 16076 | |
| 16077 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 16078 | sizeof(uint32_t); |
| 16079 | |
| 16080 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16081 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16082 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 16083 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 16084 | if (alloc_len < req_len) { |
| 16085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16086 | "2523 Allocated DMA memory size (x%x) is " |
| 16087 | "less than the requested DMA memory " |
| 16088 | "size (x%x)\n", alloc_len, req_len); |
| 16089 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16090 | return -ENOMEM; |
| 16091 | } |
| 16092 | |
| 16093 | /* |
| 16094 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 16095 | * routine only uses a single SGE. |
| 16096 | */ |
| 16097 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16098 | virt_addr = mboxq->sge_array->addr[0]; |
| 16099 | /* |
| 16100 | * Configure the FCF record for FCFI 0. This is the driver's |
| 16101 | * hardcoded default and gets used in nonFIP mode. |
| 16102 | */ |
| 16103 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 16104 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 16105 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 16106 | |
| 16107 | /* |
| 16108 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 16109 | * the FCoE header plus word10. The data copy needs to be endian |
| 16110 | * correct. |
| 16111 | */ |
| 16112 | bytep += sizeof(uint32_t); |
| 16113 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 16114 | mboxq->vport = phba->pport; |
| 16115 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 16116 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16117 | if (rc == MBX_NOT_FINISHED) { |
| 16118 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16119 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 16120 | "status 0x%x\n", rc); |
| 16121 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16122 | rc = -EIO; |
| 16123 | } else |
| 16124 | rc = 0; |
| 16125 | |
| 16126 | return rc; |
| 16127 | } |
| 16128 | |
| 16129 | /** |
| 16130 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 16131 | * @phba: pointer to lpfc hba data structure. |
| 16132 | * @fcf_record: pointer to the fcf record to write the default data. |
| 16133 | * @fcf_index: FCF table entry index. |
| 16134 | * |
| 16135 | * This routine is invoked to build the driver's default FCF record. The |
| 16136 | * values used are hardcoded. This routine handles memory initialization. |
| 16137 | * |
| 16138 | **/ |
| 16139 | void |
| 16140 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 16141 | struct fcf_record *fcf_record, |
| 16142 | uint16_t fcf_index) |
| 16143 | { |
| 16144 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 16145 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 16146 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 16147 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 16148 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 16149 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 16150 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 16151 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 16152 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 16153 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 16154 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 16155 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 16156 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 16157 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 16158 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16159 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 16160 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 16161 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 16162 | /* Set the VLAN bit map */ |
| 16163 | if (phba->valid_vlan) { |
| 16164 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 16165 | = 1 << (phba->vlan_id % 8); |
| 16166 | } |
| 16167 | } |
| 16168 | |
| 16169 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16170 | * 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] | 16171 | * @phba: pointer to lpfc hba data structure. |
| 16172 | * @fcf_index: FCF table entry offset. |
| 16173 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16174 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 16175 | * record and processing it one at a time starting from the @fcf_index |
| 16176 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 16177 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16178 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16179 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16180 | **/ |
| 16181 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16182 | 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] | 16183 | { |
| 16184 | int rc = 0, error; |
| 16185 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16186 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16187 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 16188 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16189 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16190 | if (!mboxq) { |
| 16191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16192 | "2000 Failed to allocate mbox for " |
| 16193 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16194 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16195 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16196 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16197 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16198 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16199 | if (rc) { |
| 16200 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16201 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16202 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16203 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16204 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16205 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16206 | |
| 16207 | spin_lock_irq(&phba->hbalock); |
| 16208 | phba->hba_flag |= FCF_TS_INPROG; |
| 16209 | spin_unlock_irq(&phba->hbalock); |
| 16210 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16211 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16212 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16213 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16214 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 16215 | /* Reset eligible FCF count for new scan */ |
| 16216 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 16217 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16218 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16219 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16220 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16221 | if (error) { |
| 16222 | if (mboxq) |
| 16223 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16224 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16225 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16226 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16227 | spin_unlock_irq(&phba->hbalock); |
| 16228 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16229 | return error; |
| 16230 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16231 | |
| 16232 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16233 | * 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] | 16234 | * @phba: pointer to lpfc hba data structure. |
| 16235 | * @fcf_index: FCF table entry offset. |
| 16236 | * |
| 16237 | * 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] | 16238 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16239 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16240 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16241 | * otherwise. |
| 16242 | **/ |
| 16243 | int |
| 16244 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16245 | { |
| 16246 | int rc = 0, error; |
| 16247 | LPFC_MBOXQ_t *mboxq; |
| 16248 | |
| 16249 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16250 | if (!mboxq) { |
| 16251 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16252 | "2763 Failed to allocate mbox for " |
| 16253 | "READ_FCF cmd\n"); |
| 16254 | error = -ENOMEM; |
| 16255 | goto fail_fcf_read; |
| 16256 | } |
| 16257 | /* Construct the read FCF record mailbox command */ |
| 16258 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16259 | if (rc) { |
| 16260 | error = -EINVAL; |
| 16261 | goto fail_fcf_read; |
| 16262 | } |
| 16263 | /* Issue the mailbox command asynchronously */ |
| 16264 | mboxq->vport = phba->pport; |
| 16265 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 16266 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16267 | if (rc == MBX_NOT_FINISHED) |
| 16268 | error = -EIO; |
| 16269 | else |
| 16270 | error = 0; |
| 16271 | |
| 16272 | fail_fcf_read: |
| 16273 | if (error && mboxq) |
| 16274 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16275 | return error; |
| 16276 | } |
| 16277 | |
| 16278 | /** |
| 16279 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 16280 | * @phba: pointer to lpfc hba data structure. |
| 16281 | * @fcf_index: FCF table entry offset. |
| 16282 | * |
| 16283 | * 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] | 16284 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16285 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16286 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16287 | * otherwise. |
| 16288 | **/ |
| 16289 | int |
| 16290 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16291 | { |
| 16292 | int rc = 0, error; |
| 16293 | LPFC_MBOXQ_t *mboxq; |
| 16294 | |
| 16295 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16296 | if (!mboxq) { |
| 16297 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16298 | "2758 Failed to allocate mbox for " |
| 16299 | "READ_FCF cmd\n"); |
| 16300 | error = -ENOMEM; |
| 16301 | goto fail_fcf_read; |
| 16302 | } |
| 16303 | /* Construct the read FCF record mailbox command */ |
| 16304 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16305 | if (rc) { |
| 16306 | error = -EINVAL; |
| 16307 | goto fail_fcf_read; |
| 16308 | } |
| 16309 | /* Issue the mailbox command asynchronously */ |
| 16310 | mboxq->vport = phba->pport; |
| 16311 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 16312 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16313 | if (rc == MBX_NOT_FINISHED) |
| 16314 | error = -EIO; |
| 16315 | else |
| 16316 | error = 0; |
| 16317 | |
| 16318 | fail_fcf_read: |
| 16319 | if (error && mboxq) |
| 16320 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16321 | return error; |
| 16322 | } |
| 16323 | |
| 16324 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16325 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16326 | * phba pointer to the lpfc_hba struct for this port. |
| 16327 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 16328 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 16329 | * rr_bmask based on their priority level. Starting from the highest priority |
| 16330 | * to the lowest. The most likely FCF candidate will be in the highest |
| 16331 | * priority group. When this routine is called it searches the fcf_pri list for |
| 16332 | * next lowest priority group and repopulates the rr_bmask with only those |
| 16333 | * fcf_indexes. |
| 16334 | * returns: |
| 16335 | * 1=success 0=failure |
| 16336 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16337 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16338 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 16339 | { |
| 16340 | uint16_t next_fcf_pri; |
| 16341 | uint16_t last_index; |
| 16342 | struct lpfc_fcf_pri *fcf_pri; |
| 16343 | int rc; |
| 16344 | int ret = 0; |
| 16345 | |
| 16346 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 16347 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16348 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 16349 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16350 | |
| 16351 | /* Verify the priority list has 2 or more entries */ |
| 16352 | spin_lock_irq(&phba->hbalock); |
| 16353 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 16354 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 16355 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16356 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 16357 | "3061 Last IDX %d\n", last_index); |
| 16358 | return 0; /* Empty rr list */ |
| 16359 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16360 | spin_unlock_irq(&phba->hbalock); |
| 16361 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16362 | next_fcf_pri = 0; |
| 16363 | /* |
| 16364 | * Clear the rr_bmask and set all of the bits that are at this |
| 16365 | * priority. |
| 16366 | */ |
| 16367 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 16368 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 16369 | spin_lock_irq(&phba->hbalock); |
| 16370 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16371 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 16372 | continue; |
| 16373 | /* |
| 16374 | * the 1st priority that has not FLOGI failed |
| 16375 | * will be the highest. |
| 16376 | */ |
| 16377 | if (!next_fcf_pri) |
| 16378 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16379 | spin_unlock_irq(&phba->hbalock); |
| 16380 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16381 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16382 | fcf_pri->fcf_rec.fcf_index); |
| 16383 | if (rc) |
| 16384 | return 0; |
| 16385 | } |
| 16386 | spin_lock_irq(&phba->hbalock); |
| 16387 | } |
| 16388 | /* |
| 16389 | * if next_fcf_pri was not set above and the list is not empty then |
| 16390 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 16391 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16392 | */ |
| 16393 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 16394 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16395 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 16396 | /* |
| 16397 | * the 1st priority that has not FLOGI failed |
| 16398 | * will be the highest. |
| 16399 | */ |
| 16400 | if (!next_fcf_pri) |
| 16401 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16402 | spin_unlock_irq(&phba->hbalock); |
| 16403 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16404 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16405 | fcf_pri->fcf_rec.fcf_index); |
| 16406 | if (rc) |
| 16407 | return 0; |
| 16408 | } |
| 16409 | spin_lock_irq(&phba->hbalock); |
| 16410 | } |
| 16411 | } else |
| 16412 | ret = 1; |
| 16413 | spin_unlock_irq(&phba->hbalock); |
| 16414 | |
| 16415 | return ret; |
| 16416 | } |
| 16417 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16418 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 16419 | * @phba: pointer to lpfc hba data structure. |
| 16420 | * |
| 16421 | * This routine is to get the next eligible FCF record index in a round |
| 16422 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16423 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16424 | * shall be returned, otherwise, the next eligible FCF record's index |
| 16425 | * shall be returned. |
| 16426 | **/ |
| 16427 | uint16_t |
| 16428 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 16429 | { |
| 16430 | uint16_t next_fcf_index; |
| 16431 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16432 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16433 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16434 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 16435 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16436 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16437 | /* Determine the next fcf index to check */ |
| 16438 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16439 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16440 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16441 | next_fcf_index); |
| 16442 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16443 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16444 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16445 | /* |
| 16446 | * If we have wrapped then we need to clear the bits that |
| 16447 | * have been tested so that we can detect when we should |
| 16448 | * change the priority level. |
| 16449 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16450 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16451 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16452 | } |
| 16453 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16454 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16455 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16456 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 16457 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 16458 | /* |
| 16459 | * If next fcf index is not found check if there are lower |
| 16460 | * Priority level fcf's in the fcf_priority list. |
| 16461 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 16462 | * at that level and continue the selection process. |
| 16463 | */ |
| 16464 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16465 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16466 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16467 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16468 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 16469 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16470 | else { |
| 16471 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16472 | "3063 Only FCF available idx %d, flag %x\n", |
| 16473 | next_fcf_index, |
| 16474 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 16475 | return next_fcf_index; |
| 16476 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16477 | } |
| 16478 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16479 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 16480 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16481 | LPFC_FCF_FLOGI_FAILED) { |
| 16482 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 16483 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16484 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16485 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16486 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16487 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16488 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16489 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 16490 | next_fcf_index); |
| 16491 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16492 | return next_fcf_index; |
| 16493 | } |
| 16494 | |
| 16495 | /** |
| 16496 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 16497 | * @phba: pointer to lpfc hba data structure. |
| 16498 | * |
| 16499 | * 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] | 16500 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16501 | * does not go beyond the range of the driver allocated bmask dimension |
| 16502 | * before setting the bit. |
| 16503 | * |
| 16504 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 16505 | * -EINVAL. |
| 16506 | **/ |
| 16507 | int |
| 16508 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16509 | { |
| 16510 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16511 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16512 | "2610 FCF (x%x) reached driver's book " |
| 16513 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16514 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16515 | return -EINVAL; |
| 16516 | } |
| 16517 | /* Set the eligible FCF record index bmask */ |
| 16518 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 16519 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16520 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16521 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16522 | "bmask\n", fcf_index); |
| 16523 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16524 | return 0; |
| 16525 | } |
| 16526 | |
| 16527 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16528 | * 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] | 16529 | * @phba: pointer to lpfc hba data structure. |
| 16530 | * |
| 16531 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16532 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16533 | * does not go beyond the range of the driver allocated bmask dimension |
| 16534 | * before clearing the bit. |
| 16535 | **/ |
| 16536 | void |
| 16537 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16538 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16539 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16540 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16541 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16542 | "2762 FCF (x%x) reached driver's book " |
| 16543 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16544 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16545 | return; |
| 16546 | } |
| 16547 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16548 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16549 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 16550 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16551 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 16552 | list_del_init(&fcf_pri->list); |
| 16553 | break; |
| 16554 | } |
| 16555 | } |
| 16556 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16557 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16558 | |
| 16559 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16560 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16561 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16562 | } |
| 16563 | |
| 16564 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16565 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 16566 | * @phba: pointer to lpfc hba data structure. |
| 16567 | * |
| 16568 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 16569 | * command. If the mailbox command returned failure, it will try to stop the |
| 16570 | * FCF rediscover wait timer. |
| 16571 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16572 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16573 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 16574 | { |
| 16575 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16576 | uint32_t shdr_status, shdr_add_status; |
| 16577 | |
| 16578 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16579 | |
| 16580 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 16581 | &redisc_fcf->header.cfg_shdr.response); |
| 16582 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 16583 | &redisc_fcf->header.cfg_shdr.response); |
| 16584 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16585 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16586 | "2746 Requesting for FCF rediscovery failed " |
| 16587 | "status x%x add_status x%x\n", |
| 16588 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16589 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16590 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16591 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16592 | spin_unlock_irq(&phba->hbalock); |
| 16593 | /* |
| 16594 | * CVL event triggered FCF rediscover request failed, |
| 16595 | * last resort to re-try current registered FCF entry. |
| 16596 | */ |
| 16597 | lpfc_retry_pport_discovery(phba); |
| 16598 | } else { |
| 16599 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16600 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16601 | spin_unlock_irq(&phba->hbalock); |
| 16602 | /* |
| 16603 | * DEAD FCF event triggered FCF rediscover request |
| 16604 | * failed, last resort to fail over as a link down |
| 16605 | * to FCF registration. |
| 16606 | */ |
| 16607 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 16608 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16609 | } else { |
| 16610 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16611 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16612 | /* |
| 16613 | * Start FCF rediscovery wait timer for pending FCF |
| 16614 | * before rescan FCF record table. |
| 16615 | */ |
| 16616 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16617 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16618 | |
| 16619 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16620 | } |
| 16621 | |
| 16622 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16623 | * 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] | 16624 | * @phba: pointer to lpfc hba data structure. |
| 16625 | * |
| 16626 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 16627 | * by the port. |
| 16628 | **/ |
| 16629 | int |
| 16630 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 16631 | { |
| 16632 | LPFC_MBOXQ_t *mbox; |
| 16633 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16634 | int rc, length; |
| 16635 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16636 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 16637 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 16638 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16639 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16640 | if (!mbox) { |
| 16641 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16642 | "2745 Failed to allocate mbox for " |
| 16643 | "requesting FCF rediscover.\n"); |
| 16644 | return -ENOMEM; |
| 16645 | } |
| 16646 | |
| 16647 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 16648 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16649 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16650 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 16651 | length, LPFC_SLI4_MBX_EMBED); |
| 16652 | |
| 16653 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16654 | /* Set count to 0 for invalidating the entire FCF database */ |
| 16655 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 16656 | |
| 16657 | /* Issue the mailbox command asynchronously */ |
| 16658 | mbox->vport = phba->pport; |
| 16659 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 16660 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 16661 | |
| 16662 | if (rc == MBX_NOT_FINISHED) { |
| 16663 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16664 | return -EIO; |
| 16665 | } |
| 16666 | return 0; |
| 16667 | } |
| 16668 | |
| 16669 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16670 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 16671 | * @phba: pointer to lpfc hba data structure. |
| 16672 | * |
| 16673 | * This function is the failover routine as a last resort to the FCF DEAD |
| 16674 | * event when driver failed to perform fast FCF failover. |
| 16675 | **/ |
| 16676 | void |
| 16677 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 16678 | { |
| 16679 | uint32_t link_state; |
| 16680 | |
| 16681 | /* |
| 16682 | * Last resort as FCF DEAD event failover will treat this as |
| 16683 | * a link down, but save the link state because we don't want |
| 16684 | * it to be changed to Link Down unless it is already down. |
| 16685 | */ |
| 16686 | link_state = phba->link_state; |
| 16687 | lpfc_linkdown(phba); |
| 16688 | phba->link_state = link_state; |
| 16689 | |
| 16690 | /* Unregister FCF if no devices connected to it */ |
| 16691 | lpfc_unregister_unused_fcf(phba); |
| 16692 | } |
| 16693 | |
| 16694 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16695 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16696 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16697 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16698 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16699 | * This function gets SLI3 port configure region 23 data through memory dump |
| 16700 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16701 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16702 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16703 | static uint32_t |
| 16704 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16705 | { |
| 16706 | LPFC_MBOXQ_t *pmb = NULL; |
| 16707 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16708 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16709 | int rc; |
| 16710 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16711 | if (!rgn23_data) |
| 16712 | return 0; |
| 16713 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16714 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16715 | if (!pmb) { |
| 16716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16717 | "2600 failed to allocate mailbox memory\n"); |
| 16718 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16719 | } |
| 16720 | mb = &pmb->u.mb; |
| 16721 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16722 | do { |
| 16723 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 16724 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 16725 | |
| 16726 | if (rc != MBX_SUCCESS) { |
| 16727 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16728 | "2601 failed to read config " |
| 16729 | "region 23, rc 0x%x Status 0x%x\n", |
| 16730 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16731 | mb->un.varDmp.word_cnt = 0; |
| 16732 | } |
| 16733 | /* |
| 16734 | * dump mem may return a zero when finished or we got a |
| 16735 | * mailbox error, either way we are done. |
| 16736 | */ |
| 16737 | if (mb->un.varDmp.word_cnt == 0) |
| 16738 | break; |
| 16739 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 16740 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 16741 | |
| 16742 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16743 | rgn23_data + offset, |
| 16744 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16745 | offset += mb->un.varDmp.word_cnt; |
| 16746 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 16747 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16748 | mempool_free(pmb, phba->mbox_mem_pool); |
| 16749 | return offset; |
| 16750 | } |
| 16751 | |
| 16752 | /** |
| 16753 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 16754 | * @phba: pointer to lpfc hba data structure. |
| 16755 | * @rgn23_data: pointer to configure region 23 data. |
| 16756 | * |
| 16757 | * This function gets SLI4 port configure region 23 data through memory dump |
| 16758 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16759 | * will be returned, otherwise, 0 will be returned. |
| 16760 | **/ |
| 16761 | static uint32_t |
| 16762 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 16763 | { |
| 16764 | LPFC_MBOXQ_t *mboxq = NULL; |
| 16765 | struct lpfc_dmabuf *mp = NULL; |
| 16766 | struct lpfc_mqe *mqe; |
| 16767 | uint32_t data_length = 0; |
| 16768 | int rc; |
| 16769 | |
| 16770 | if (!rgn23_data) |
| 16771 | return 0; |
| 16772 | |
| 16773 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16774 | if (!mboxq) { |
| 16775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16776 | "3105 failed to allocate mailbox memory\n"); |
| 16777 | return 0; |
| 16778 | } |
| 16779 | |
| 16780 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 16781 | goto out; |
| 16782 | mqe = &mboxq->u.mqe; |
| 16783 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 16784 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 16785 | if (rc) |
| 16786 | goto out; |
| 16787 | data_length = mqe->un.mb_words[5]; |
| 16788 | if (data_length == 0) |
| 16789 | goto out; |
| 16790 | if (data_length > DMP_RGN23_SIZE) { |
| 16791 | data_length = 0; |
| 16792 | goto out; |
| 16793 | } |
| 16794 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 16795 | out: |
| 16796 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16797 | if (mp) { |
| 16798 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16799 | kfree(mp); |
| 16800 | } |
| 16801 | return data_length; |
| 16802 | } |
| 16803 | |
| 16804 | /** |
| 16805 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 16806 | * @phba: pointer to lpfc hba data structure. |
| 16807 | * |
| 16808 | * This function read region 23 and parse TLV for port status to |
| 16809 | * decide if the user disaled the port. If the TLV indicates the |
| 16810 | * port is disabled, the hba_flag is set accordingly. |
| 16811 | **/ |
| 16812 | void |
| 16813 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 16814 | { |
| 16815 | uint8_t *rgn23_data = NULL; |
| 16816 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 16817 | uint32_t offset = 0; |
| 16818 | |
| 16819 | /* Get adapter Region 23 data */ |
| 16820 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 16821 | if (!rgn23_data) |
| 16822 | goto out; |
| 16823 | |
| 16824 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16825 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 16826 | else { |
| 16827 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 16828 | &phba->sli4_hba.sli_intf); |
| 16829 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 16830 | goto out; |
| 16831 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 16832 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16833 | |
| 16834 | if (!data_size) |
| 16835 | goto out; |
| 16836 | |
| 16837 | /* Check the region signature first */ |
| 16838 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 16839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16840 | "2619 Config region 23 has bad signature\n"); |
| 16841 | goto out; |
| 16842 | } |
| 16843 | offset += 4; |
| 16844 | |
| 16845 | /* Check the data structure version */ |
| 16846 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16848 | "2620 Config region 23 has bad version\n"); |
| 16849 | goto out; |
| 16850 | } |
| 16851 | offset += 4; |
| 16852 | |
| 16853 | /* Parse TLV entries in the region */ |
| 16854 | while (offset < data_size) { |
| 16855 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16856 | break; |
| 16857 | /* |
| 16858 | * If the TLV is not driver specific TLV or driver id is |
| 16859 | * not linux driver id, skip the record. |
| 16860 | */ |
| 16861 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16862 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16863 | (rgn23_data[offset + 3] != 0)) { |
| 16864 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16865 | continue; |
| 16866 | } |
| 16867 | |
| 16868 | /* Driver found a driver specific TLV in the config region */ |
| 16869 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16870 | offset += 4; |
| 16871 | tlv_offset = 0; |
| 16872 | |
| 16873 | /* |
| 16874 | * Search for configured port state sub-TLV. |
| 16875 | */ |
| 16876 | while ((offset < data_size) && |
| 16877 | (tlv_offset < sub_tlv_len)) { |
| 16878 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16879 | offset += 4; |
| 16880 | tlv_offset += 4; |
| 16881 | break; |
| 16882 | } |
| 16883 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16884 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16885 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16886 | continue; |
| 16887 | } |
| 16888 | |
| 16889 | /* This HBA contains PORT_STE configured */ |
| 16890 | if (!rgn23_data[offset + 2]) |
| 16891 | phba->hba_flag |= LINK_DISABLED; |
| 16892 | |
| 16893 | goto out; |
| 16894 | } |
| 16895 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16896 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16897 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16898 | kfree(rgn23_data); |
| 16899 | return; |
| 16900 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16901 | |
| 16902 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16903 | * lpfc_wr_object - write an object to the firmware |
| 16904 | * @phba: HBA structure that indicates port to create a queue on. |
| 16905 | * @dmabuf_list: list of dmabufs to write to the port. |
| 16906 | * @size: the total byte value of the objects to write to the port. |
| 16907 | * @offset: the current offset to be used to start the transfer. |
| 16908 | * |
| 16909 | * This routine will create a wr_object mailbox command to send to the port. |
| 16910 | * the mailbox command will be constructed using the dma buffers described in |
| 16911 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 16912 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 16913 | * used to indicate the starting offset of the transfer and will also return |
| 16914 | * the offset after the write object mailbox has completed. @size is used to |
| 16915 | * determine the end of the object and whether the eof bit should be set. |
| 16916 | * |
| 16917 | * Return 0 is successful and offset will contain the the new offset to use |
| 16918 | * for the next write. |
| 16919 | * Return negative value for error cases. |
| 16920 | **/ |
| 16921 | int |
| 16922 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 16923 | uint32_t size, uint32_t *offset) |
| 16924 | { |
| 16925 | struct lpfc_mbx_wr_object *wr_object; |
| 16926 | LPFC_MBOXQ_t *mbox; |
| 16927 | int rc = 0, i = 0; |
| 16928 | uint32_t shdr_status, shdr_add_status; |
| 16929 | uint32_t mbox_tmo; |
| 16930 | union lpfc_sli4_cfg_shdr *shdr; |
| 16931 | struct lpfc_dmabuf *dmabuf; |
| 16932 | uint32_t written = 0; |
| 16933 | |
| 16934 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16935 | if (!mbox) |
| 16936 | return -ENOMEM; |
| 16937 | |
| 16938 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16939 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 16940 | sizeof(struct lpfc_mbx_wr_object) - |
| 16941 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 16942 | |
| 16943 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 16944 | wr_object->u.request.write_offset = *offset; |
| 16945 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 16946 | wr_object->u.request.object_name[0] = |
| 16947 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 16948 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 16949 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 16950 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 16951 | break; |
| 16952 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 16953 | wr_object->u.request.bde[i].addrHigh = |
| 16954 | putPaddrHigh(dmabuf->phys); |
| 16955 | if (written + SLI4_PAGE_SIZE >= size) { |
| 16956 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16957 | (size - written); |
| 16958 | written += (size - written); |
| 16959 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 16960 | } else { |
| 16961 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16962 | SLI4_PAGE_SIZE; |
| 16963 | written += SLI4_PAGE_SIZE; |
| 16964 | } |
| 16965 | i++; |
| 16966 | } |
| 16967 | wr_object->u.request.bde_count = i; |
| 16968 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 16969 | if (!phba->sli4_hba.intr_enable) |
| 16970 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16971 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16972 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16973 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16974 | } |
| 16975 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16976 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 16977 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16978 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16979 | if (rc != MBX_TIMEOUT) |
| 16980 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16981 | if (shdr_status || shdr_add_status || rc) { |
| 16982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16983 | "3025 Write Object mailbox failed with " |
| 16984 | "status x%x add_status x%x, mbx status x%x\n", |
| 16985 | shdr_status, shdr_add_status, rc); |
| 16986 | rc = -ENXIO; |
| 16987 | } else |
| 16988 | *offset += wr_object->u.response.actual_write_length; |
| 16989 | return rc; |
| 16990 | } |
| 16991 | |
| 16992 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16993 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 16994 | * @vport: pointer to vport data structure. |
| 16995 | * |
| 16996 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 16997 | * and REG_VPI mailbox commands associated with the vport. This function |
| 16998 | * is called when driver want to restart discovery of the vport due to |
| 16999 | * a Clear Virtual Link event. |
| 17000 | **/ |
| 17001 | void |
| 17002 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 17003 | { |
| 17004 | struct lpfc_hba *phba = vport->phba; |
| 17005 | LPFC_MBOXQ_t *mb, *nextmb; |
| 17006 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17007 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17008 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17009 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17010 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17011 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17012 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17013 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17014 | spin_lock_irq(&phba->hbalock); |
| 17015 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 17016 | if (mb->vport != vport) |
| 17017 | continue; |
| 17018 | |
| 17019 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17020 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17021 | continue; |
| 17022 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17023 | list_del(&mb->list); |
| 17024 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 17025 | } |
| 17026 | /* Clean up active mailbox command with the vport */ |
| 17027 | mb = phba->sli.mbox_active; |
| 17028 | if (mb && (mb->vport == vport)) { |
| 17029 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 17030 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 17031 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17032 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17033 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17034 | /* Put reference count for delayed processing */ |
| 17035 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 17036 | /* Unregister the RPI when mailbox complete */ |
| 17037 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17038 | } |
| 17039 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17040 | /* Cleanup any mailbox completions which are not yet processed */ |
| 17041 | do { |
| 17042 | restart_loop = 0; |
| 17043 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 17044 | /* |
| 17045 | * If this mailox is already processed or it is |
| 17046 | * for another vport ignore it. |
| 17047 | */ |
| 17048 | if ((mb->vport != vport) || |
| 17049 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 17050 | continue; |
| 17051 | |
| 17052 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17053 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17054 | continue; |
| 17055 | |
| 17056 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17057 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17058 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17059 | /* Unregister the RPI when mailbox complete */ |
| 17060 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17061 | restart_loop = 1; |
| 17062 | spin_unlock_irq(&phba->hbalock); |
| 17063 | spin_lock(shost->host_lock); |
| 17064 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17065 | spin_unlock(shost->host_lock); |
| 17066 | spin_lock_irq(&phba->hbalock); |
| 17067 | break; |
| 17068 | } |
| 17069 | } |
| 17070 | } while (restart_loop); |
| 17071 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17072 | spin_unlock_irq(&phba->hbalock); |
| 17073 | |
| 17074 | /* Release the cleaned-up mailbox commands */ |
| 17075 | while (!list_empty(&mbox_cmd_list)) { |
| 17076 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17077 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17078 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 17079 | if (mp) { |
| 17080 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 17081 | kfree(mp); |
| 17082 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17083 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17084 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17085 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17086 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17087 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17088 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17089 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17090 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17091 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17092 | mempool_free(mb, phba->mbox_mem_pool); |
| 17093 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17094 | |
| 17095 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 17096 | if (act_mbx_ndlp) { |
| 17097 | spin_lock(shost->host_lock); |
| 17098 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17099 | spin_unlock(shost->host_lock); |
| 17100 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17101 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17102 | } |
| 17103 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17104 | /** |
| 17105 | * lpfc_drain_txq - Drain the txq |
| 17106 | * @phba: Pointer to HBA context object. |
| 17107 | * |
| 17108 | * This function attempt to submit IOCBs on the txq |
| 17109 | * to the adapter. For SLI4 adapters, the txq contains |
| 17110 | * ELS IOCBs that have been deferred because the there |
| 17111 | * are no SGLs. This congestion can occur with large |
| 17112 | * vport counts during node discovery. |
| 17113 | **/ |
| 17114 | |
| 17115 | uint32_t |
| 17116 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 17117 | { |
| 17118 | LIST_HEAD(completions); |
| 17119 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 17120 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17121 | unsigned long iflags = 0; |
| 17122 | char *fail_msg = NULL; |
| 17123 | struct lpfc_sglq *sglq; |
| 17124 | union lpfc_wqe wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17125 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17126 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17127 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17128 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 17129 | txq_cnt++; |
| 17130 | } |
| 17131 | |
| 17132 | if (txq_cnt > pring->txq_max) |
| 17133 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17134 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17135 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17136 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17137 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17138 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17139 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17140 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17141 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17142 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17143 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17144 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17145 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17146 | break; |
| 17147 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17148 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17149 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17150 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17151 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17152 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17153 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17154 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17155 | |
| 17156 | /* The xri and iocb resources secured, |
| 17157 | * attempt to issue request |
| 17158 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17159 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17160 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 17161 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 17162 | fail_msg = "to convert bpl to sgl"; |
| 17163 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 17164 | fail_msg = "to convert iocb to wqe"; |
| 17165 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 17166 | fail_msg = " - Wq is full"; |
| 17167 | else |
| 17168 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 17169 | |
| 17170 | if (fail_msg) { |
| 17171 | /* Failed means we can't issue and need to cancel */ |
| 17172 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17173 | "2822 IOCB failed %s iotag 0x%x " |
| 17174 | "xri 0x%x\n", |
| 17175 | fail_msg, |
| 17176 | piocbq->iotag, piocbq->sli4_xritag); |
| 17177 | list_add_tail(&piocbq->list, &completions); |
| 17178 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17179 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17180 | } |
| 17181 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17182 | /* Cancel all the IOCBs that cannot be issued */ |
| 17183 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 17184 | IOERR_SLI_ABORTED); |
| 17185 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17186 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17187 | } |