| 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 | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2016 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" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 50 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 51 | |
| 52 | /* There are only four IOCB completion types. */ |
| 53 | typedef enum _lpfc_iocb_type { |
| 54 | LPFC_UNKNOWN_IOCB, |
| 55 | LPFC_UNSOL_IOCB, |
| 56 | LPFC_SOL_IOCB, |
| 57 | LPFC_ABORT_IOCB |
| 58 | } lpfc_iocb_type; |
| 59 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 60 | |
| 61 | /* Provide function prototypes local to this module. */ |
| 62 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 63 | uint32_t); |
| 64 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 65 | uint8_t *, uint32_t *); |
| 66 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 67 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 68 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 69 | struct hbq_dmabuf *); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 70 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
| 71 | struct lpfc_cqe *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 72 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
| 73 | int); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 74 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
| 75 | uint32_t); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 76 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 77 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 78 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 79 | static IOCB_t * |
| 80 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 81 | { |
| 82 | return &iocbq->iocb; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 87 | * @q: The Work Queue to operate on. |
| 88 | * @wqe: The work Queue Entry to put on the Work queue. |
| 89 | * |
| 90 | * This routine will copy the contents of @wqe to the next available entry on |
| 91 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 92 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 93 | * successful. If no entries are available on @q then this function will return |
| 94 | * -ENOMEM. |
| 95 | * The caller is expected to hold the hbalock when calling this routine. |
| 96 | **/ |
| 97 | static uint32_t |
| 98 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 99 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 100 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 101 | struct lpfc_register doorbell; |
| 102 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 103 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 104 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 105 | /* sanity check on queue memory */ |
| 106 | if (unlikely(!q)) |
| 107 | return -ENOMEM; |
| 108 | temp_wqe = q->qe[q->host_index].wqe; |
| 109 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 110 | /* 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] | 111 | idx = ((q->host_index + 1) % q->entry_count); |
| 112 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 113 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 114 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 115 | } |
| 116 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 117 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 118 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 119 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 120 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 121 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 122 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 123 | |
| 124 | /* Update the host index before invoking device */ |
| 125 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 126 | |
| 127 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 128 | |
| 129 | /* Ring Doorbell */ |
| 130 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 131 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 132 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 133 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 134 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 135 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 136 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 137 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 138 | } else { |
| 139 | return -EINVAL; |
| 140 | } |
| 141 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 148 | * @q: The Work Queue to operate on. |
| 149 | * @index: The index to advance the hba index to. |
| 150 | * |
| 151 | * This routine will update the HBA index of a queue to reflect consumption of |
| 152 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 153 | * an entry the host calls this function to update the queue's internal |
| 154 | * pointers. This routine returns the number of entries that were consumed by |
| 155 | * the HBA. |
| 156 | **/ |
| 157 | static uint32_t |
| 158 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 159 | { |
| 160 | uint32_t released = 0; |
| 161 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 162 | /* sanity check on queue memory */ |
| 163 | if (unlikely(!q)) |
| 164 | return 0; |
| 165 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 166 | if (q->hba_index == index) |
| 167 | return 0; |
| 168 | do { |
| 169 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 170 | released++; |
| 171 | } while (q->hba_index != index); |
| 172 | return released; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 177 | * @q: The Mailbox Queue to operate on. |
| 178 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 179 | * |
| 180 | * This routine will copy the contents of @mqe to the next available entry on |
| 181 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 182 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 183 | * successful. If no entries are available on @q then this function will return |
| 184 | * -ENOMEM. |
| 185 | * The caller is expected to hold the hbalock when calling this routine. |
| 186 | **/ |
| 187 | static uint32_t |
| 188 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 189 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 190 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 191 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 192 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 193 | /* sanity check on queue memory */ |
| 194 | if (unlikely(!q)) |
| 195 | return -ENOMEM; |
| 196 | temp_mqe = q->qe[q->host_index].mqe; |
| 197 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 198 | /* If the host has not yet processed the next entry then we are done */ |
| 199 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 200 | return -ENOMEM; |
| 201 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 202 | /* Save off the mailbox pointer for completion */ |
| 203 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 204 | |
| 205 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 206 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 207 | |
| 208 | /* Ring Doorbell */ |
| 209 | doorbell.word0 = 0; |
| 210 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 211 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 212 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 218 | * @q: The Mailbox Queue to operate on. |
| 219 | * |
| 220 | * This routine will update the HBA index of a queue to reflect consumption of |
| 221 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 222 | * an entry the host calls this function to update the queue's internal |
| 223 | * pointers. This routine returns the number of entries that were consumed by |
| 224 | * the HBA. |
| 225 | **/ |
| 226 | static uint32_t |
| 227 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 228 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 229 | /* sanity check on queue memory */ |
| 230 | if (unlikely(!q)) |
| 231 | return 0; |
| 232 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 233 | /* Clear the mailbox pointer for completion */ |
| 234 | q->phba->mbox = NULL; |
| 235 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 241 | * @q: The Event Queue to get the first valid EQE from |
| 242 | * |
| 243 | * This routine will get the first valid Event Queue Entry from @q, update |
| 244 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 245 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 246 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 247 | **/ |
| 248 | static struct lpfc_eqe * |
| 249 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 250 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 251 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 252 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 253 | |
| 254 | /* sanity check on queue memory */ |
| 255 | if (unlikely(!q)) |
| 256 | return NULL; |
| 257 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 258 | |
| 259 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 260 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 261 | return NULL; |
| 262 | /* 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] | 263 | idx = ((q->hba_index + 1) % q->entry_count); |
| 264 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 265 | return NULL; |
| 266 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 267 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 268 | |
| 269 | /* |
| 270 | * insert barrier for instruction interlock : data from the hardware |
| 271 | * must have the valid bit checked before it can be copied and acted |
| 272 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 273 | * instructions allowing action on content before valid bit checked, |
| 274 | * add barrier here as well. May not be needed as "content" is a |
| 275 | * single 32-bit entity here (vs multi word structure for cq's). |
| 276 | */ |
| 277 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 278 | return eqe; |
| 279 | } |
| 280 | |
| 281 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 282 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 283 | * @q: The Event Queue to disable interrupts |
| 284 | * |
| 285 | **/ |
| 286 | static inline void |
| 287 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 288 | { |
| 289 | struct lpfc_register doorbell; |
| 290 | |
| 291 | doorbell.word0 = 0; |
| 292 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 293 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 294 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 295 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 296 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 297 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 298 | } |
| 299 | |
| 300 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 301 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 302 | * @q: The Event Queue that the host has completed processing for. |
| 303 | * @arm: Indicates whether the host wants to arms this CQ. |
| 304 | * |
| 305 | * This routine will mark all Event Queue Entries on @q, from the last |
| 306 | * known completed entry to the last entry that was processed, as completed |
| 307 | * by clearing the valid bit for each completion queue entry. Then it will |
| 308 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 309 | * The internal host index in the @q will be updated by this routine to indicate |
| 310 | * that the host has finished processing the entries. The @arm parameter |
| 311 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 312 | * |
| 313 | * This function will return the number of EQEs that were popped. |
| 314 | **/ |
| 315 | uint32_t |
| 316 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 317 | { |
| 318 | uint32_t released = 0; |
| 319 | struct lpfc_eqe *temp_eqe; |
| 320 | struct lpfc_register doorbell; |
| 321 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 322 | /* sanity check on queue memory */ |
| 323 | if (unlikely(!q)) |
| 324 | return 0; |
| 325 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 326 | /* while there are valid entries */ |
| 327 | while (q->hba_index != q->host_index) { |
| 328 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 329 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 330 | released++; |
| 331 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 332 | } |
| 333 | if (unlikely(released == 0 && !arm)) |
| 334 | return 0; |
| 335 | |
| 336 | /* ring doorbell for number popped */ |
| 337 | doorbell.word0 = 0; |
| 338 | if (arm) { |
| 339 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 340 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 341 | } |
| 342 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 343 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 344 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 345 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 346 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 347 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 348 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 349 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 350 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 351 | return released; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 356 | * @q: The Completion Queue to get the first valid CQE from |
| 357 | * |
| 358 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 359 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 360 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 361 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 362 | **/ |
| 363 | static struct lpfc_cqe * |
| 364 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 365 | { |
| 366 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 367 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 368 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 369 | /* sanity check on queue memory */ |
| 370 | if (unlikely(!q)) |
| 371 | return NULL; |
| 372 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 373 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 374 | 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] | 375 | return NULL; |
| 376 | /* 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] | 377 | idx = ((q->hba_index + 1) % q->entry_count); |
| 378 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 379 | return NULL; |
| 380 | |
| 381 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 382 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * insert barrier for instruction interlock : data from the hardware |
| 386 | * must have the valid bit checked before it can be copied and acted |
| 387 | * upon. Speculative instructions were allowing a bcopy at the start |
| 388 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 389 | * after our return, to copy data before the valid bit check above |
| 390 | * was done. As such, some of the copied data was stale. The barrier |
| 391 | * ensures the check is before any data is copied. |
| 392 | */ |
| 393 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 394 | return cqe; |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 399 | * @q: The Completion Queue that the host has completed processing for. |
| 400 | * @arm: Indicates whether the host wants to arms this CQ. |
| 401 | * |
| 402 | * This routine will mark all Completion queue entries on @q, from the last |
| 403 | * known completed entry to the last entry that was processed, as completed |
| 404 | * by clearing the valid bit for each completion queue entry. Then it will |
| 405 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 406 | * The internal host index in the @q will be updated by this routine to indicate |
| 407 | * that the host has finished processing the entries. The @arm parameter |
| 408 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 409 | * |
| 410 | * This function will return the number of CQEs that were released. |
| 411 | **/ |
| 412 | uint32_t |
| 413 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 414 | { |
| 415 | uint32_t released = 0; |
| 416 | struct lpfc_cqe *temp_qe; |
| 417 | struct lpfc_register doorbell; |
| 418 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 419 | /* sanity check on queue memory */ |
| 420 | if (unlikely(!q)) |
| 421 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 422 | /* while there are valid entries */ |
| 423 | while (q->hba_index != q->host_index) { |
| 424 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 425 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 426 | released++; |
| 427 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 428 | } |
| 429 | if (unlikely(released == 0 && !arm)) |
| 430 | return 0; |
| 431 | |
| 432 | /* ring doorbell for number popped */ |
| 433 | doorbell.word0 = 0; |
| 434 | if (arm) |
| 435 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 436 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 437 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 438 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 439 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 440 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 441 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 442 | return released; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 447 | * @q: The Header Receive Queue to operate on. |
| 448 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 449 | * |
| 450 | * This routine will copy the contents of @wqe to the next available entry on |
| 451 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 452 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 453 | * index that the rqe was copied to if successful. If no entries are available |
| 454 | * on @q then this function will return -ENOMEM. |
| 455 | * The caller is expected to hold the hbalock when calling this routine. |
| 456 | **/ |
| 457 | static int |
| 458 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 459 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 460 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 461 | struct lpfc_rqe *temp_hrqe; |
| 462 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 463 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 464 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 465 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 466 | /* sanity check on queue memory */ |
| 467 | if (unlikely(!hq) || unlikely(!dq)) |
| 468 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 469 | put_index = hq->host_index; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 470 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 471 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 472 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 473 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 474 | return -EINVAL; |
| 475 | if (hq->host_index != dq->host_index) |
| 476 | return -EINVAL; |
| 477 | /* If the host has not yet processed the next entry then we are done */ |
| 478 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 479 | return -EBUSY; |
| 480 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 481 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 482 | |
| 483 | /* Update the host index to point to the next slot */ |
| 484 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 485 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 486 | |
| 487 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 488 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 489 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 490 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 491 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 492 | hq->entry_repost); |
| 493 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 494 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 495 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 496 | hq->entry_repost); |
| 497 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 498 | hq->host_index); |
| 499 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 500 | } else { |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 504 | } |
| 505 | return put_index; |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 510 | * @q: The Header Receive Queue to operate on. |
| 511 | * |
| 512 | * This routine will update the HBA index of a queue to reflect consumption of |
| 513 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 514 | * consumed an entry the host calls this function to update the queue's |
| 515 | * internal pointers. This routine returns the number of entries that were |
| 516 | * consumed by the HBA. |
| 517 | **/ |
| 518 | static uint32_t |
| 519 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 520 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 521 | /* sanity check on queue memory */ |
| 522 | if (unlikely(!hq) || unlikely(!dq)) |
| 523 | return 0; |
| 524 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 525 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 526 | return 0; |
| 527 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 528 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 529 | return 1; |
| 530 | } |
| 531 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 532 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 533 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 534 | * @phba: Pointer to HBA context object. |
| 535 | * @pring: Pointer to driver SLI ring object. |
| 536 | * |
| 537 | * This function returns pointer to next command iocb entry |
| 538 | * in the command ring. The caller must hold hbalock to prevent |
| 539 | * other threads consume the next command iocb. |
| 540 | * SLI-2/SLI-3 provide different sized iocbs. |
| 541 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 542 | static inline IOCB_t * |
| 543 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 544 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 545 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 546 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 547 | } |
| 548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 550 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 551 | * @phba: Pointer to HBA context object. |
| 552 | * @pring: Pointer to driver SLI ring object. |
| 553 | * |
| 554 | * This function returns pointer to next response iocb entry |
| 555 | * in the response ring. The caller must hold hbalock to make sure |
| 556 | * that no other thread consume the next response iocb. |
| 557 | * SLI-2/SLI-3 provide different sized iocbs. |
| 558 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 559 | static inline IOCB_t * |
| 560 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 561 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 562 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 563 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 564 | } |
| 565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 567 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 568 | * @phba: Pointer to HBA context object. |
| 569 | * |
| 570 | * This function is called with hbalock held. This function |
| 571 | * allocates a new driver iocb object from the iocb pool. If the |
| 572 | * allocation is successful, it returns pointer to the newly |
| 573 | * allocated iocb object else it returns NULL. |
| 574 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 575 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 576 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 577 | { |
| 578 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 579 | struct lpfc_iocbq * iocbq = NULL; |
| 580 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 581 | lockdep_assert_held(&phba->hbalock); |
| 582 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 583 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 584 | if (iocbq) |
| 585 | phba->iocb_cnt++; |
| 586 | if (phba->iocb_cnt > phba->iocb_max) |
| 587 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 588 | return iocbq; |
| 589 | } |
| 590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 591 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 592 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 593 | * @phba: Pointer to HBA context object. |
| 594 | * @xritag: XRI value. |
| 595 | * |
| 596 | * This function clears the sglq pointer from the array of acive |
| 597 | * sglq's. The xritag that is passed in is used to index into the |
| 598 | * array. Before the xritag can be used it needs to be adjusted |
| 599 | * by subtracting the xribase. |
| 600 | * |
| 601 | * Returns sglq ponter = success, NULL = Failure. |
| 602 | **/ |
| 603 | static struct lpfc_sglq * |
| 604 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 605 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 606 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 607 | |
| 608 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 609 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 610 | return sglq; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 615 | * @phba: Pointer to HBA context object. |
| 616 | * @xritag: XRI value. |
| 617 | * |
| 618 | * This function returns the sglq pointer from the array of acive |
| 619 | * sglq's. The xritag that is passed in is used to index into the |
| 620 | * array. Before the xritag can be used it needs to be adjusted |
| 621 | * by subtracting the xribase. |
| 622 | * |
| 623 | * Returns sglq ponter = success, NULL = Failure. |
| 624 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 625 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 626 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 627 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 628 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 629 | |
| 630 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 631 | return sglq; |
| 632 | } |
| 633 | |
| 634 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 635 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 636 | * @phba: Pointer to HBA context object. |
| 637 | * @xritag: xri used in this exchange. |
| 638 | * @rrq: The RRQ to be cleared. |
| 639 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 640 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 641 | void |
| 642 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 643 | uint16_t xritag, |
| 644 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 645 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 646 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 647 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 648 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 649 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 650 | |
| 651 | /* The target DID could have been swapped (cable swap) |
| 652 | * we should use the ndlp from the findnode if it is |
| 653 | * available. |
| 654 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 655 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 656 | ndlp = rrq->ndlp; |
| 657 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 658 | if (!ndlp) |
| 659 | goto out; |
| 660 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 661 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 662 | rrq->send_rrq = 0; |
| 663 | rrq->xritag = 0; |
| 664 | rrq->rrq_stop_time = 0; |
| 665 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 666 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 667 | mempool_free(rrq, phba->rrq_pool); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 672 | * @phba: Pointer to HBA context object. |
| 673 | * |
| 674 | * This function is called with hbalock held. This function |
| 675 | * Checks if stop_time (ratov from setting rrq active) has |
| 676 | * been reached, if it has and the send_rrq flag is set then |
| 677 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 678 | * then it will just call the routine to clear the rrq and |
| 679 | * free the rrq resource. |
| 680 | * The timer is set to the next rrq that is going to expire before |
| 681 | * leaving the routine. |
| 682 | * |
| 683 | **/ |
| 684 | void |
| 685 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 686 | { |
| 687 | struct lpfc_node_rrq *rrq; |
| 688 | struct lpfc_node_rrq *nextrrq; |
| 689 | unsigned long next_time; |
| 690 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 691 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 692 | |
| 693 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 694 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 695 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 696 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 697 | &phba->active_rrq_list, list) { |
| 698 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 699 | list_move(&rrq->list, &send_rrq); |
| 700 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 701 | next_time = rrq->rrq_stop_time; |
| 702 | } |
| 703 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 704 | if ((!list_empty(&phba->active_rrq_list)) && |
| 705 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 706 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 707 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 708 | list_del(&rrq->list); |
| 709 | if (!rrq->send_rrq) |
| 710 | /* this call will free the rrq */ |
| 711 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 712 | else if (lpfc_send_rrq(phba, rrq)) { |
| 713 | /* if we send the rrq then the completion handler |
| 714 | * will clear the bit in the xribitmap. |
| 715 | */ |
| 716 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 717 | rrq); |
| 718 | } |
| 719 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /** |
| 723 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 724 | * @vport: Pointer to vport context object. |
| 725 | * @xri: The xri used in the exchange. |
| 726 | * @did: The targets DID for this exchange. |
| 727 | * |
| 728 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 729 | * rrq = rrq for this xri and target. |
| 730 | **/ |
| 731 | struct lpfc_node_rrq * |
| 732 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 733 | { |
| 734 | struct lpfc_hba *phba = vport->phba; |
| 735 | struct lpfc_node_rrq *rrq; |
| 736 | struct lpfc_node_rrq *nextrrq; |
| 737 | unsigned long iflags; |
| 738 | |
| 739 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 740 | return NULL; |
| 741 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 742 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 743 | if (rrq->vport == vport && rrq->xritag == xri && |
| 744 | rrq->nlp_DID == did){ |
| 745 | list_del(&rrq->list); |
| 746 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 747 | return rrq; |
| 748 | } |
| 749 | } |
| 750 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 751 | return NULL; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 756 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 757 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 758 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 759 | * phba->active_rrq_list and clear the rrq. |
| 760 | * 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] | 761 | **/ |
| 762 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 763 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 764 | |
| 765 | { |
| 766 | struct lpfc_hba *phba = vport->phba; |
| 767 | struct lpfc_node_rrq *rrq; |
| 768 | struct lpfc_node_rrq *nextrrq; |
| 769 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 770 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 771 | |
| 772 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 773 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 774 | if (!ndlp) { |
| 775 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 776 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 777 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 778 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 779 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 780 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 781 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 782 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 783 | |
| 784 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 785 | list_del(&rrq->list); |
| 786 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 787 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 791 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 792 | * @phba: Pointer to HBA context object. |
| 793 | * @ndlp: Targets nodelist pointer for this exchange. |
| 794 | * @xritag the xri in the bitmap to test. |
| 795 | * |
| 796 | * This function is called with hbalock held. This function |
| 797 | * returns 0 = rrq not active for this xri |
| 798 | * 1 = rrq is valid for this xri. |
| 799 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 800 | int |
| 801 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 802 | uint16_t xritag) |
| 803 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 804 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 805 | if (!ndlp) |
| 806 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 807 | if (!ndlp->active_rrqs_xri_bitmap) |
| 808 | return 0; |
| 809 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 810 | return 1; |
| 811 | else |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 817 | * @phba: Pointer to HBA context object. |
| 818 | * @ndlp: nodelist pointer for this target. |
| 819 | * @xritag: xri used in this exchange. |
| 820 | * @rxid: Remote Exchange ID. |
| 821 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 822 | * |
| 823 | * This function takes the hbalock. |
| 824 | * The active bit is always set in the active rrq xri_bitmap even |
| 825 | * if there is no slot avaiable for the other rrq information. |
| 826 | * |
| 827 | * returns 0 rrq actived for this xri |
| 828 | * < 0 No memory or invalid ndlp. |
| 829 | **/ |
| 830 | int |
| 831 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 832 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 833 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 834 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 835 | struct lpfc_node_rrq *rrq; |
| 836 | int empty; |
| 837 | |
| 838 | if (!ndlp) |
| 839 | return -EINVAL; |
| 840 | |
| 841 | if (!phba->cfg_enable_rrq) |
| 842 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 843 | |
| 844 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 845 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 846 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 847 | goto out; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * set the active bit even if there is no mem available. |
| 852 | */ |
| 853 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 854 | goto out; |
| 855 | |
| 856 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 857 | goto out; |
| 858 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 859 | if (!ndlp->active_rrqs_xri_bitmap) |
| 860 | goto out; |
| 861 | |
| 862 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 863 | goto out; |
| 864 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 866 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 867 | if (!rrq) { |
| 868 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 869 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 870 | " DID:0x%x Send:%d\n", |
| 871 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 872 | return -EINVAL; |
| 873 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 874 | if (phba->cfg_enable_rrq == 1) |
| 875 | rrq->send_rrq = send_rrq; |
| 876 | else |
| 877 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 878 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 879 | rrq->rrq_stop_time = jiffies + |
| 880 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 881 | rrq->ndlp = ndlp; |
| 882 | rrq->nlp_DID = ndlp->nlp_DID; |
| 883 | rrq->vport = ndlp->vport; |
| 884 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 885 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 886 | empty = list_empty(&phba->active_rrq_list); |
| 887 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 888 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 889 | if (empty) |
| 890 | lpfc_worker_wake_up(phba); |
| 891 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 892 | return 0; |
| 893 | out: |
| 894 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 895 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 896 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 897 | " DID:0x%x Send:%d\n", |
| 898 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 899 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 903 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 904 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 905 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 906 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 907 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 908 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 909 | * list is not empty then it is successful, it returns pointer to the newly |
| 910 | * allocated sglq object else it returns NULL. |
| 911 | **/ |
| 912 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 913 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 914 | { |
| 915 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 916 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 917 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 918 | struct lpfc_scsi_buf *lpfc_cmd; |
| 919 | struct lpfc_nodelist *ndlp; |
| 920 | int found = 0; |
| 921 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 922 | lockdep_assert_held(&phba->hbalock); |
| 923 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 924 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 925 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 926 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 927 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 928 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 929 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 930 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 931 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 932 | ndlp = NULL; |
| 933 | else |
| 934 | ndlp = piocbq->context_un.ndlp; |
| 935 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 936 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 937 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 938 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 939 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 940 | start_sglq = sglq; |
| 941 | while (!found) { |
| 942 | if (!sglq) |
| 943 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 944 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 945 | /* This xri has an rrq outstanding for this DID. |
| 946 | * put it back in the list and get another xri. |
| 947 | */ |
| 948 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 949 | sglq = NULL; |
| 950 | list_remove_head(lpfc_sgl_list, sglq, |
| 951 | struct lpfc_sglq, list); |
| 952 | if (sglq == start_sglq) { |
| 953 | sglq = NULL; |
| 954 | break; |
| 955 | } else |
| 956 | continue; |
| 957 | } |
| 958 | sglq->ndlp = ndlp; |
| 959 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 960 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 961 | sglq->state = SGL_ALLOCATED; |
| 962 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 963 | return sglq; |
| 964 | } |
| 965 | |
| 966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 967 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 968 | * @phba: Pointer to HBA context object. |
| 969 | * |
| 970 | * This function is called with no lock held. This function |
| 971 | * allocates a new driver iocb object from the iocb pool. If the |
| 972 | * allocation is successful, it returns pointer to the newly |
| 973 | * allocated iocb object else it returns NULL. |
| 974 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 975 | struct lpfc_iocbq * |
| 976 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 977 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | struct lpfc_iocbq * iocbq = NULL; |
| 979 | unsigned long iflags; |
| 980 | |
| 981 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 982 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 983 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 984 | return iocbq; |
| 985 | } |
| 986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 987 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 988 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 989 | * @phba: Pointer to HBA context object. |
| 990 | * @iocbq: Pointer to driver iocb object. |
| 991 | * |
| 992 | * This function is called with hbalock held to release driver |
| 993 | * iocb object to the iocb pool. The iotag in the iocb object |
| 994 | * does not change for each use of the iocb object. This function |
| 995 | * clears all other fields of the iocb object when it is freed. |
| 996 | * The sqlq structure that holds the xritag and phys and virtual |
| 997 | * mappings for the scatter gather list is retrieved from the |
| 998 | * active array of sglq. The get of the sglq pointer also clears |
| 999 | * the entry in the array. If the status of the IO indiactes that |
| 1000 | * this IO was aborted then the sglq entry it put on the |
| 1001 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1002 | * IO has good status or fails for any other reason then the sglq |
| 1003 | * entry is added to the free list (lpfc_sgl_list). |
| 1004 | **/ |
| 1005 | static void |
| 1006 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1007 | { |
| 1008 | struct lpfc_sglq *sglq; |
| 1009 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1010 | unsigned long iflag = 0; |
| 1011 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1012 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1013 | lockdep_assert_held(&phba->hbalock); |
| 1014 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1015 | if (iocbq->sli4_xritag == NO_XRI) |
| 1016 | sglq = NULL; |
| 1017 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1018 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1019 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1020 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1021 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1022 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1023 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1024 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 1025 | iflag); |
| 1026 | list_add(&sglq->list, |
| 1027 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1028 | spin_unlock_irqrestore( |
| 1029 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1030 | } else { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1031 | spin_lock_irqsave(&pring->ring_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1032 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1033 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1034 | list_add_tail(&sglq->list, |
| 1035 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1036 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1037 | |
| 1038 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1039 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1040 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1041 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | /* |
| 1046 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1047 | */ |
| 1048 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1049 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1050 | iocbq->sli4_xritag = NO_XRI; |
| 1051 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1052 | } |
| 1053 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1054 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1055 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1056 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1057 | * @phba: Pointer to HBA context object. |
| 1058 | * @iocbq: Pointer to driver iocb object. |
| 1059 | * |
| 1060 | * This function is called with hbalock held to release driver |
| 1061 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1062 | * does not change for each use of the iocb object. This function |
| 1063 | * clears all other fields of the iocb object when it is freed. |
| 1064 | **/ |
| 1065 | static void |
| 1066 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1067 | { |
| 1068 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1069 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1070 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1071 | |
| 1072 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1073 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1074 | */ |
| 1075 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1076 | iocbq->sli4_xritag = NO_XRI; |
| 1077 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1078 | } |
| 1079 | |
| 1080 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1081 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1082 | * @phba: Pointer to HBA context object. |
| 1083 | * @iocbq: Pointer to driver iocb object. |
| 1084 | * |
| 1085 | * This function is called with hbalock held to release driver |
| 1086 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1087 | * does not change for each use of the iocb object. This function |
| 1088 | * clears all other fields of the iocb object when it is freed. |
| 1089 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1090 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1091 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1092 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1093 | lockdep_assert_held(&phba->hbalock); |
| 1094 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1095 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1096 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1097 | } |
| 1098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1099 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1100 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1101 | * @phba: Pointer to HBA context object. |
| 1102 | * @iocbq: Pointer to driver iocb object. |
| 1103 | * |
| 1104 | * This function is called with no lock held to release the iocb to |
| 1105 | * iocb pool. |
| 1106 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1107 | void |
| 1108 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1109 | { |
| 1110 | unsigned long iflags; |
| 1111 | |
| 1112 | /* |
| 1113 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1114 | */ |
| 1115 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1116 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1117 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1118 | } |
| 1119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1120 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1121 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1122 | * @phba: Pointer to HBA context object. |
| 1123 | * @iocblist: List of IOCBs. |
| 1124 | * @ulpstatus: ULP status in IOCB command field. |
| 1125 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1126 | * |
| 1127 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1128 | * on the list by invoking the complete callback function associated with the |
| 1129 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1130 | * fields. |
| 1131 | **/ |
| 1132 | void |
| 1133 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1134 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1135 | { |
| 1136 | struct lpfc_iocbq *piocb; |
| 1137 | |
| 1138 | while (!list_empty(iocblist)) { |
| 1139 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1140 | if (!piocb->iocb_cmpl) |
| 1141 | lpfc_sli_release_iocbq(phba, piocb); |
| 1142 | else { |
| 1143 | piocb->iocb.ulpStatus = ulpstatus; |
| 1144 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1145 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1146 | } |
| 1147 | } |
| 1148 | return; |
| 1149 | } |
| 1150 | |
| 1151 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1152 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1153 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1154 | * |
| 1155 | * This function is called by ring event handler function to get the iocb type. |
| 1156 | * This function translates the iocb command to an iocb command type used to |
| 1157 | * decide the final disposition of each completed IOCB. |
| 1158 | * The function returns |
| 1159 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1160 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1161 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1162 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1163 | * |
| 1164 | * The caller is not required to hold any lock. |
| 1165 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | static lpfc_iocb_type |
| 1167 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1168 | { |
| 1169 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1170 | |
| 1171 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1172 | return 0; |
| 1173 | |
| 1174 | switch (iocb_cmnd) { |
| 1175 | case CMD_XMIT_SEQUENCE_CR: |
| 1176 | case CMD_XMIT_SEQUENCE_CX: |
| 1177 | case CMD_XMIT_BCAST_CN: |
| 1178 | case CMD_XMIT_BCAST_CX: |
| 1179 | case CMD_ELS_REQUEST_CR: |
| 1180 | case CMD_ELS_REQUEST_CX: |
| 1181 | case CMD_CREATE_XRI_CR: |
| 1182 | case CMD_CREATE_XRI_CX: |
| 1183 | case CMD_GET_RPI_CN: |
| 1184 | case CMD_XMIT_ELS_RSP_CX: |
| 1185 | case CMD_GET_RPI_CR: |
| 1186 | case CMD_FCP_IWRITE_CR: |
| 1187 | case CMD_FCP_IWRITE_CX: |
| 1188 | case CMD_FCP_IREAD_CR: |
| 1189 | case CMD_FCP_IREAD_CX: |
| 1190 | case CMD_FCP_ICMND_CR: |
| 1191 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1192 | case CMD_FCP_TSEND_CX: |
| 1193 | case CMD_FCP_TRSP_CX: |
| 1194 | case CMD_FCP_TRECEIVE_CX: |
| 1195 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | case CMD_ADAPTER_MSG: |
| 1197 | case CMD_ADAPTER_DUMP: |
| 1198 | case CMD_XMIT_SEQUENCE64_CR: |
| 1199 | case CMD_XMIT_SEQUENCE64_CX: |
| 1200 | case CMD_XMIT_BCAST64_CN: |
| 1201 | case CMD_XMIT_BCAST64_CX: |
| 1202 | case CMD_ELS_REQUEST64_CR: |
| 1203 | case CMD_ELS_REQUEST64_CX: |
| 1204 | case CMD_FCP_IWRITE64_CR: |
| 1205 | case CMD_FCP_IWRITE64_CX: |
| 1206 | case CMD_FCP_IREAD64_CR: |
| 1207 | case CMD_FCP_IREAD64_CX: |
| 1208 | case CMD_FCP_ICMND64_CR: |
| 1209 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1210 | case CMD_FCP_TSEND64_CX: |
| 1211 | case CMD_FCP_TRSP64_CX: |
| 1212 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | case CMD_GEN_REQUEST64_CR: |
| 1214 | case CMD_GEN_REQUEST64_CX: |
| 1215 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1216 | case DSSCMD_IWRITE64_CR: |
| 1217 | case DSSCMD_IWRITE64_CX: |
| 1218 | case DSSCMD_IREAD64_CR: |
| 1219 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | type = LPFC_SOL_IOCB; |
| 1221 | break; |
| 1222 | case CMD_ABORT_XRI_CN: |
| 1223 | case CMD_ABORT_XRI_CX: |
| 1224 | case CMD_CLOSE_XRI_CN: |
| 1225 | case CMD_CLOSE_XRI_CX: |
| 1226 | case CMD_XRI_ABORTED_CX: |
| 1227 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1228 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | type = LPFC_ABORT_IOCB; |
| 1230 | break; |
| 1231 | case CMD_RCV_SEQUENCE_CX: |
| 1232 | case CMD_RCV_ELS_REQ_CX: |
| 1233 | case CMD_RCV_SEQUENCE64_CX: |
| 1234 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1235 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1236 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1237 | case CMD_IOCB_RCV_ELS64_CX: |
| 1238 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1239 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1240 | type = LPFC_UNSOL_IOCB; |
| 1241 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1242 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1243 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1244 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1245 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1246 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1247 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1248 | case CMD_IOCB_RET_HBQE64_CN: |
| 1249 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1250 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1251 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1252 | case CMD_IOCB_LOGENTRY_CN: |
| 1253 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1254 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1255 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1256 | type = LPFC_UNKNOWN_IOCB; |
| 1257 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | default: |
| 1259 | type = LPFC_UNKNOWN_IOCB; |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | return type; |
| 1264 | } |
| 1265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1267 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1268 | * @phba: Pointer to HBA context object. |
| 1269 | * |
| 1270 | * This function is called from SLI initialization code |
| 1271 | * to configure every ring of the HBA's SLI interface. The |
| 1272 | * caller is not required to hold any lock. This function issues |
| 1273 | * a config_ring mailbox command for each ring. |
| 1274 | * This function returns zero if successful else returns a negative |
| 1275 | * error code. |
| 1276 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1278 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | { |
| 1280 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1281 | LPFC_MBOXQ_t *pmb; |
| 1282 | MAILBOX_t *pmbox; |
| 1283 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1285 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1286 | if (!pmb) |
| 1287 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1288 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1289 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1291 | lpfc_config_ring(phba, i, pmb); |
| 1292 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1293 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1294 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1295 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1297 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1298 | rc, pmbox->mbxCommand, |
| 1299 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1300 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1301 | ret = -ENXIO; |
| 1302 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | } |
| 1304 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1305 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1306 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | } |
| 1308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1310 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1311 | * @phba: Pointer to HBA context object. |
| 1312 | * @pring: Pointer to driver SLI ring object. |
| 1313 | * @piocb: Pointer to the driver iocb object. |
| 1314 | * |
| 1315 | * This function is called with hbalock held. The function adds the |
| 1316 | * new iocb to txcmplq of the given ring. This function always returns |
| 1317 | * 0. If this function is called for ELS ring, this function checks if |
| 1318 | * there is a vport associated with the ELS command. This function also |
| 1319 | * starts els_tmofunc timer if this is an ELS command. |
| 1320 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1322 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1323 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1325 | lockdep_assert_held(&phba->hbalock); |
| 1326 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1327 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1329 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1330 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1331 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1332 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1333 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1334 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1335 | BUG_ON(!piocb->vport); |
| 1336 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1337 | mod_timer(&piocb->vport->els_tmofunc, |
| 1338 | jiffies + |
| 1339 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 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 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2003 | * This function searches for the hbq buffer associated with the given tag in |
| 2004 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2005 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2006 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2007 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2008 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2009 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2010 | struct lpfc_dmabuf *d_buf; |
| 2011 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2012 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2013 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2014 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2015 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2016 | return NULL; |
| 2017 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2018 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2019 | 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] | 2020 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2021 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2022 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2023 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2024 | } |
| 2025 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2026 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2027 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2028 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2029 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2030 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2031 | } |
| 2032 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2033 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2034 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2035 | * @phba: Pointer to HBA context object. |
| 2036 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2037 | * |
| 2038 | * This function is called with hbalock. This function gives back |
| 2039 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2040 | * post the buffer, it will free the buffer. |
| 2041 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2042 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2043 | 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] | 2044 | { |
| 2045 | uint32_t hbqno; |
| 2046 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2047 | if (hbq_buffer) { |
| 2048 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2049 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2050 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2054 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2055 | * 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] | 2056 | * @mbxCommand: mailbox command code. |
| 2057 | * |
| 2058 | * This function is called by the mailbox event handler function to verify |
| 2059 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2060 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2061 | * and the mailbox event handler will take the HBA offline. |
| 2062 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | static int |
| 2064 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2065 | { |
| 2066 | uint8_t ret; |
| 2067 | |
| 2068 | switch (mbxCommand) { |
| 2069 | case MBX_LOAD_SM: |
| 2070 | case MBX_READ_NV: |
| 2071 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2072 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | case MBX_RUN_BIU_DIAG: |
| 2074 | case MBX_INIT_LINK: |
| 2075 | case MBX_DOWN_LINK: |
| 2076 | case MBX_CONFIG_LINK: |
| 2077 | case MBX_CONFIG_RING: |
| 2078 | case MBX_RESET_RING: |
| 2079 | case MBX_READ_CONFIG: |
| 2080 | case MBX_READ_RCONFIG: |
| 2081 | case MBX_READ_SPARM: |
| 2082 | case MBX_READ_STATUS: |
| 2083 | case MBX_READ_RPI: |
| 2084 | case MBX_READ_XRI: |
| 2085 | case MBX_READ_REV: |
| 2086 | case MBX_READ_LNK_STAT: |
| 2087 | case MBX_REG_LOGIN: |
| 2088 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | case MBX_CLEAR_LA: |
| 2090 | case MBX_DUMP_MEMORY: |
| 2091 | case MBX_DUMP_CONTEXT: |
| 2092 | case MBX_RUN_DIAGS: |
| 2093 | case MBX_RESTART: |
| 2094 | case MBX_UPDATE_CFG: |
| 2095 | case MBX_DOWN_LOAD: |
| 2096 | case MBX_DEL_LD_ENTRY: |
| 2097 | case MBX_RUN_PROGRAM: |
| 2098 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2099 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2100 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2101 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2103 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | case MBX_LOAD_AREA: |
| 2105 | case MBX_RUN_BIU_DIAG64: |
| 2106 | case MBX_CONFIG_PORT: |
| 2107 | case MBX_READ_SPARM64: |
| 2108 | case MBX_READ_RPI64: |
| 2109 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2110 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2111 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | case MBX_SET_DEBUG: |
| 2113 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2114 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2115 | case MBX_REG_VPI: |
| 2116 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2117 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2118 | case MBX_PORT_CAPABILITIES: |
| 2119 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2120 | case MBX_SLI4_CONFIG: |
| 2121 | case MBX_SLI4_REQ_FTRS: |
| 2122 | case MBX_REG_FCFI: |
| 2123 | case MBX_UNREG_FCFI: |
| 2124 | case MBX_REG_VFI: |
| 2125 | case MBX_UNREG_VFI: |
| 2126 | case MBX_INIT_VPI: |
| 2127 | case MBX_INIT_VFI: |
| 2128 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2129 | case MBX_READ_EVENT_LOG_STATUS: |
| 2130 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2131 | case MBX_SECURITY_MGMT: |
| 2132 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2133 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | ret = mbxCommand; |
| 2135 | break; |
| 2136 | default: |
| 2137 | ret = MBX_SHUTDOWN; |
| 2138 | break; |
| 2139 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2140 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2142 | |
| 2143 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2144 | * 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] | 2145 | * @phba: Pointer to HBA context object. |
| 2146 | * @pmboxq: Pointer to mailbox command. |
| 2147 | * |
| 2148 | * This is completion handler function for mailbox commands issued from |
| 2149 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2150 | * mailbox event handler function with no lock held. This function |
| 2151 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2152 | * of the mailbox. |
| 2153 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2154 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2155 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | { |
| 2157 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2158 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | |
| 2160 | /* |
| 2161 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2162 | * continued running. |
| 2163 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2164 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2165 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2167 | if (pdone_q) |
| 2168 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2169 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | return; |
| 2171 | } |
| 2172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2173 | |
| 2174 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2175 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | * @phba: Pointer to HBA context object. |
| 2177 | * @pmb: Pointer to mailbox object. |
| 2178 | * |
| 2179 | * This function is the default mailbox completion handler. It |
| 2180 | * frees the memory resources associated with the completed mailbox |
| 2181 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2182 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2183 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2185 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2187 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2189 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2190 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2191 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2192 | int rc; |
| 2193 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | if (mp) { |
| 2197 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2198 | kfree(mp); |
| 2199 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2200 | |
| 2201 | /* |
| 2202 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2203 | * is in re-discovery driver need to cleanup the RPI. |
| 2204 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2205 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2206 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2207 | !pmb->u.mb.mbxStatus) { |
| 2208 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2209 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2210 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2211 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2212 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2213 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2214 | if (rc != MBX_NOT_FINISHED) |
| 2215 | return; |
| 2216 | } |
| 2217 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2218 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2219 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2220 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2221 | shost = lpfc_shost_from_vport(vport); |
| 2222 | spin_lock_irq(shost->host_lock); |
| 2223 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2224 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2225 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2226 | } |
| 2227 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2228 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2229 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2230 | lpfc_nlp_put(ndlp); |
| 2231 | pmb->context2 = NULL; |
| 2232 | } |
| 2233 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2234 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2235 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2236 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2237 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2238 | "2860 SLI authentication is required " |
| 2239 | "for INIT_LINK but has not done yet\n"); |
| 2240 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2241 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2242 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2243 | else |
| 2244 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2246 | /** |
| 2247 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2248 | * @phba: Pointer to HBA context object. |
| 2249 | * @pmb: Pointer to mailbox object. |
| 2250 | * |
| 2251 | * This function is the unreg rpi mailbox completion handler. It |
| 2252 | * frees the memory resources associated with the completed mailbox |
| 2253 | * command. An additional refrenece is put on the ndlp to prevent |
| 2254 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2255 | * the unreg mailbox command completes, this routine puts the |
| 2256 | * reference back. |
| 2257 | * |
| 2258 | **/ |
| 2259 | void |
| 2260 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2261 | { |
| 2262 | struct lpfc_vport *vport = pmb->vport; |
| 2263 | struct lpfc_nodelist *ndlp; |
| 2264 | |
| 2265 | ndlp = pmb->context1; |
| 2266 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2267 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2268 | (bf_get(lpfc_sli_intf_if_type, |
| 2269 | &phba->sli4_hba.sli_intf) == |
| 2270 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2271 | if (ndlp) { |
| 2272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2273 | "0010 UNREG_LOGIN vpi:%x " |
| 2274 | "rpi:%x DID:%x map:%x %p\n", |
| 2275 | vport->vpi, ndlp->nlp_rpi, |
| 2276 | ndlp->nlp_DID, |
| 2277 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2278 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2279 | lpfc_nlp_put(ndlp); |
| 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2285 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2288 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2289 | * @phba: Pointer to HBA context object. |
| 2290 | * |
| 2291 | * This function is called with no lock held. This function processes all |
| 2292 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2293 | * service routine processes mailbox completion interrupt and adds completed |
| 2294 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2295 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2296 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2297 | * function returns the mailbox commands to the upper layer by calling the |
| 2298 | * completion handler function of each mailbox. |
| 2299 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2301 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2303 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | int rc; |
| 2306 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | |
| 2308 | phba->sli.slistat.mbox_event++; |
| 2309 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2310 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2311 | spin_lock_irq(&phba->hbalock); |
| 2312 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2313 | spin_unlock_irq(&phba->hbalock); |
| 2314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | do { |
| 2317 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2318 | if (pmb == NULL) |
| 2319 | break; |
| 2320 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2321 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2323 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2324 | if (pmb->vport) { |
| 2325 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2326 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2327 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2328 | (uint32_t)pmbox->mbxCommand, |
| 2329 | pmbox->un.varWords[0], |
| 2330 | pmbox->un.varWords[1]); |
| 2331 | } |
| 2332 | else { |
| 2333 | lpfc_debugfs_disc_trc(phba->pport, |
| 2334 | LPFC_DISC_TRC_MBOX, |
| 2335 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2336 | (uint32_t)pmbox->mbxCommand, |
| 2337 | pmbox->un.varWords[0], |
| 2338 | pmbox->un.varWords[1]); |
| 2339 | } |
| 2340 | } |
| 2341 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | /* |
| 2343 | * It is a fatal error if unknown mbox command completion. |
| 2344 | */ |
| 2345 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2346 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2347 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2348 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2349 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2350 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2351 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2352 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2353 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2354 | pmb), |
| 2355 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2356 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | phba->work_hs = HS_FFER3; |
| 2359 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2360 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | } |
| 2362 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | if (pmbox->mbxStatus) { |
| 2364 | phba->sli.slistat.mbox_stat_err++; |
| 2365 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2366 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2367 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2368 | LOG_MBOX | LOG_SLI, |
| 2369 | "(%d):0305 Mbox cmd cmpl " |
| 2370 | "error - RETRYing Data: x%x " |
| 2371 | "(x%x/x%x) x%x x%x x%x\n", |
| 2372 | pmb->vport ? pmb->vport->vpi : 0, |
| 2373 | pmbox->mbxCommand, |
| 2374 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2375 | pmb), |
| 2376 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2377 | pmb), |
| 2378 | pmbox->mbxStatus, |
| 2379 | pmbox->un.varWords[0], |
| 2380 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | pmbox->mbxStatus = 0; |
| 2382 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2384 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2385 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2390 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2391 | "(%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] | 2392 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2393 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2394 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2395 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2396 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2397 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | pmb->mbox_cmpl, |
| 2399 | *((uint32_t *) pmbox), |
| 2400 | pmbox->un.varWords[0], |
| 2401 | pmbox->un.varWords[1], |
| 2402 | pmbox->un.varWords[2], |
| 2403 | pmbox->un.varWords[3], |
| 2404 | pmbox->un.varWords[4], |
| 2405 | pmbox->un.varWords[5], |
| 2406 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2407 | pmbox->un.varWords[7], |
| 2408 | pmbox->un.varWords[8], |
| 2409 | pmbox->un.varWords[9], |
| 2410 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2412 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2415 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2419 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2420 | * @phba: Pointer to HBA context object. |
| 2421 | * @pring: Pointer to driver SLI ring object. |
| 2422 | * @tag: buffer tag. |
| 2423 | * |
| 2424 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2425 | * is set in the tag the buffer is posted for a particular exchange, |
| 2426 | * the function will return the buffer without replacing the buffer. |
| 2427 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2428 | * returns the buffer and also posts another buffer to the firmware. |
| 2429 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2430 | static struct lpfc_dmabuf * |
| 2431 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2432 | struct lpfc_sli_ring *pring, |
| 2433 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2434 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2435 | struct hbq_dmabuf *hbq_entry; |
| 2436 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2437 | if (tag & QUE_BUFTAG_BIT) |
| 2438 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2439 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2440 | if (!hbq_entry) |
| 2441 | return NULL; |
| 2442 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2443 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2444 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2445 | /** |
| 2446 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2447 | * @phba: Pointer to HBA context object. |
| 2448 | * @pring: Pointer to driver SLI ring object. |
| 2449 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2450 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2451 | * @fch_type: the type for the first frame of the sequence. |
| 2452 | * |
| 2453 | * This function is called with no lock held. This function uses the r_ctl and |
| 2454 | * type of the received sequence to find the correct callback function to call |
| 2455 | * to process the sequence. |
| 2456 | **/ |
| 2457 | static int |
| 2458 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2459 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2460 | uint32_t fch_type) |
| 2461 | { |
| 2462 | int i; |
| 2463 | |
| 2464 | /* unSolicited Responses */ |
| 2465 | if (pring->prt[0].profile) { |
| 2466 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2467 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2468 | saveq); |
| 2469 | return 1; |
| 2470 | } |
| 2471 | /* We must search, based on rctl / type |
| 2472 | for the right routine */ |
| 2473 | for (i = 0; i < pring->num_mask; i++) { |
| 2474 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2475 | (pring->prt[i].type == fch_type)) { |
| 2476 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2477 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2478 | (phba, pring, saveq); |
| 2479 | return 1; |
| 2480 | } |
| 2481 | } |
| 2482 | return 0; |
| 2483 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2484 | |
| 2485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2486 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2487 | * @phba: Pointer to HBA context object. |
| 2488 | * @pring: Pointer to driver SLI ring object. |
| 2489 | * @saveq: Pointer to the unsolicited iocb. |
| 2490 | * |
| 2491 | * This function is called with no lock held by the ring event handler |
| 2492 | * when there is an unsolicited iocb posted to the response ring by the |
| 2493 | * firmware. This function gets the buffer associated with the iocbs |
| 2494 | * and calls the event handler for the ring. This function handles both |
| 2495 | * qring buffers and hbq buffers. |
| 2496 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2497 | * upper layer functions will free the iocb objects. |
| 2498 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | static int |
| 2500 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2501 | struct lpfc_iocbq *saveq) |
| 2502 | { |
| 2503 | IOCB_t * irsp; |
| 2504 | WORD5 * w5p; |
| 2505 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2506 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2507 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2510 | |
| 2511 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2512 | if (pring->lpfc_sli_rcv_async_status) |
| 2513 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2514 | else |
| 2515 | lpfc_printf_log(phba, |
| 2516 | KERN_WARNING, |
| 2517 | LOG_SLI, |
| 2518 | "0316 Ring %d handler: unexpected " |
| 2519 | "ASYNC_STATUS iocb received evt_code " |
| 2520 | "0x%x\n", |
| 2521 | pring->ringno, |
| 2522 | irsp->un.asyncstat.evt_code); |
| 2523 | return 1; |
| 2524 | } |
| 2525 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2526 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2527 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2528 | if (irsp->ulpBdeCount > 0) { |
| 2529 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2530 | irsp->un.ulpWord[3]); |
| 2531 | lpfc_in_buf_free(phba, dmzbuf); |
| 2532 | } |
| 2533 | |
| 2534 | if (irsp->ulpBdeCount > 1) { |
| 2535 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2536 | irsp->unsli3.sli3Words[3]); |
| 2537 | lpfc_in_buf_free(phba, dmzbuf); |
| 2538 | } |
| 2539 | |
| 2540 | if (irsp->ulpBdeCount > 2) { |
| 2541 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2542 | irsp->unsli3.sli3Words[7]); |
| 2543 | lpfc_in_buf_free(phba, dmzbuf); |
| 2544 | } |
| 2545 | |
| 2546 | return 1; |
| 2547 | } |
| 2548 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2549 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2550 | if (irsp->ulpBdeCount != 0) { |
| 2551 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2553 | if (!saveq->context2) |
| 2554 | lpfc_printf_log(phba, |
| 2555 | KERN_ERR, |
| 2556 | LOG_SLI, |
| 2557 | "0341 Ring %d Cannot find buffer for " |
| 2558 | "an unsolicited iocb. tag 0x%x\n", |
| 2559 | pring->ringno, |
| 2560 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2561 | } |
| 2562 | if (irsp->ulpBdeCount == 2) { |
| 2563 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2564 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2565 | if (!saveq->context3) |
| 2566 | lpfc_printf_log(phba, |
| 2567 | KERN_ERR, |
| 2568 | LOG_SLI, |
| 2569 | "0342 Ring %d Cannot find buffer for an" |
| 2570 | " unsolicited iocb. tag 0x%x\n", |
| 2571 | pring->ringno, |
| 2572 | irsp->unsli3.sli3Words[7]); |
| 2573 | } |
| 2574 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2575 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2576 | if (irsp->ulpBdeCount != 0) { |
| 2577 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2578 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2579 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2580 | lpfc_printf_log(phba, |
| 2581 | KERN_ERR, |
| 2582 | LOG_SLI, |
| 2583 | "0343 Ring %d Cannot find " |
| 2584 | "buffer for an unsolicited iocb" |
| 2585 | ". tag 0x%x\n", pring->ringno, |
| 2586 | irsp->un.ulpWord[3]); |
| 2587 | } |
| 2588 | if (irsp->ulpBdeCount == 2) { |
| 2589 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2590 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2591 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2592 | lpfc_printf_log(phba, |
| 2593 | KERN_ERR, |
| 2594 | LOG_SLI, |
| 2595 | "0344 Ring %d Cannot find " |
| 2596 | "buffer for an unsolicited " |
| 2597 | "iocb. tag 0x%x\n", |
| 2598 | pring->ringno, |
| 2599 | irsp->unsli3.sli3Words[7]); |
| 2600 | } |
| 2601 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2602 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2603 | if (irsp->ulpBdeCount != 0 && |
| 2604 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2605 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2606 | int found = 0; |
| 2607 | |
| 2608 | /* search continue save q for same XRI */ |
| 2609 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2610 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2611 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2612 | list_add_tail(&saveq->list, &iocbq->list); |
| 2613 | found = 1; |
| 2614 | break; |
| 2615 | } |
| 2616 | } |
| 2617 | if (!found) |
| 2618 | list_add_tail(&saveq->clist, |
| 2619 | &pring->iocb_continue_saveq); |
| 2620 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2621 | list_del_init(&iocbq->clist); |
| 2622 | saveq = iocbq; |
| 2623 | irsp = &(saveq->iocb); |
| 2624 | } else |
| 2625 | return 0; |
| 2626 | } |
| 2627 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2628 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2629 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2630 | Rctl = FC_RCTL_ELS_REQ; |
| 2631 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2632 | } else { |
| 2633 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2634 | Rctl = w5p->hcsw.Rctl; |
| 2635 | Type = w5p->hcsw.Type; |
| 2636 | |
| 2637 | /* Firmware Workaround */ |
| 2638 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2639 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2640 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2641 | Rctl = FC_RCTL_ELS_REQ; |
| 2642 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2643 | w5p->hcsw.Rctl = Rctl; |
| 2644 | w5p->hcsw.Type = Type; |
| 2645 | } |
| 2646 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2647 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2648 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2649 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2650 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2651 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2652 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2653 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2654 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | } |
| 2656 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2657 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2658 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2659 | * @phba: Pointer to HBA context object. |
| 2660 | * @pring: Pointer to driver SLI ring object. |
| 2661 | * @prspiocb: Pointer to response iocb object. |
| 2662 | * |
| 2663 | * This function looks up the iocb_lookup table to get the command iocb |
| 2664 | * corresponding to the given response iocb using the iotag of the |
| 2665 | * response iocb. This function is called with the hbalock held. |
| 2666 | * This function returns the command iocb object if it finds the command |
| 2667 | * iocb else returns NULL. |
| 2668 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2671 | struct lpfc_sli_ring *pring, |
| 2672 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2675 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2676 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2678 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2680 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2681 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2682 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2683 | /* remove from txcmpl queue list */ |
| 2684 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2685 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2686 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2687 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | } |
| 2689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2691 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2692 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2693 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2694 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | return NULL; |
| 2696 | } |
| 2697 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2698 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2699 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2700 | * @phba: Pointer to HBA context object. |
| 2701 | * @pring: Pointer to driver SLI ring object. |
| 2702 | * @iotag: IOCB tag. |
| 2703 | * |
| 2704 | * This function looks up the iocb_lookup table to get the command iocb |
| 2705 | * corresponding to the given iotag. This function is called with the |
| 2706 | * hbalock held. |
| 2707 | * This function returns the command iocb object if it finds the command |
| 2708 | * iocb else returns NULL. |
| 2709 | **/ |
| 2710 | static struct lpfc_iocbq * |
| 2711 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2712 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2713 | { |
| 2714 | struct lpfc_iocbq *cmd_iocb; |
| 2715 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2716 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2717 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2718 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2719 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2720 | /* remove from txcmpl queue list */ |
| 2721 | list_del_init(&cmd_iocb->list); |
| 2722 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2723 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2724 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2725 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2726 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2727 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2728 | "0372 iotag x%x is out of range: max iotag (x%x)\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2729 | iotag, phba->sli.last_iotag); |
| 2730 | return NULL; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2734 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2735 | * @phba: Pointer to HBA context object. |
| 2736 | * @pring: Pointer to driver SLI ring object. |
| 2737 | * @saveq: Pointer to the response iocb to be processed. |
| 2738 | * |
| 2739 | * This function is called by the ring event handler for non-fcp |
| 2740 | * rings when there is a new response iocb in the response ring. |
| 2741 | * The caller is not required to hold any locks. This function |
| 2742 | * gets the command iocb associated with the response iocb and |
| 2743 | * calls the completion handler for the command iocb. If there |
| 2744 | * is no completion handler, the function will free the resources |
| 2745 | * associated with command iocb. If the response iocb is for |
| 2746 | * an already aborted command iocb, the status of the completion |
| 2747 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2748 | * This function always returns 1. |
| 2749 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2751 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | struct lpfc_iocbq *saveq) |
| 2753 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | int rc = 1; |
| 2756 | unsigned long iflag; |
| 2757 | |
| 2758 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2759 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2760 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2761 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2762 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | if (cmdiocbp) { |
| 2764 | if (cmdiocbp->iocb_cmpl) { |
| 2765 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2766 | * If an ELS command failed send an event to mgmt |
| 2767 | * application. |
| 2768 | */ |
| 2769 | if (saveq->iocb.ulpStatus && |
| 2770 | (pring->ringno == LPFC_ELS_RING) && |
| 2771 | (cmdiocbp->iocb.ulpCommand == |
| 2772 | CMD_ELS_REQUEST64_CR)) |
| 2773 | lpfc_send_els_failure_event(phba, |
| 2774 | cmdiocbp, saveq); |
| 2775 | |
| 2776 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2777 | * Post all ELS completions to the worker thread. |
| 2778 | * All other are passed to the completion callback. |
| 2779 | */ |
| 2780 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2781 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2782 | (cmdiocbp->iocb_flag & |
| 2783 | LPFC_DRIVER_ABORTED)) { |
| 2784 | spin_lock_irqsave(&phba->hbalock, |
| 2785 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2786 | cmdiocbp->iocb_flag &= |
| 2787 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2788 | spin_unlock_irqrestore(&phba->hbalock, |
| 2789 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2790 | saveq->iocb.ulpStatus = |
| 2791 | IOSTAT_LOCAL_REJECT; |
| 2792 | saveq->iocb.un.ulpWord[4] = |
| 2793 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2794 | |
| 2795 | /* Firmware could still be in progress |
| 2796 | * of DMAing payload, so don't free data |
| 2797 | * buffer till after a hbeat. |
| 2798 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2799 | spin_lock_irqsave(&phba->hbalock, |
| 2800 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2801 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2802 | spin_unlock_irqrestore(&phba->hbalock, |
| 2803 | iflag); |
| 2804 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2805 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2806 | if (saveq->iocb_flag & |
| 2807 | LPFC_EXCHANGE_BUSY) { |
| 2808 | /* Set cmdiocb flag for the |
| 2809 | * exchange busy so sgl (xri) |
| 2810 | * will not be released until |
| 2811 | * the abort xri is received |
| 2812 | * from hba. |
| 2813 | */ |
| 2814 | spin_lock_irqsave( |
| 2815 | &phba->hbalock, iflag); |
| 2816 | cmdiocbp->iocb_flag |= |
| 2817 | LPFC_EXCHANGE_BUSY; |
| 2818 | spin_unlock_irqrestore( |
| 2819 | &phba->hbalock, iflag); |
| 2820 | } |
| 2821 | if (cmdiocbp->iocb_flag & |
| 2822 | LPFC_DRIVER_ABORTED) { |
| 2823 | /* |
| 2824 | * Clear LPFC_DRIVER_ABORTED |
| 2825 | * bit in case it was driver |
| 2826 | * initiated abort. |
| 2827 | */ |
| 2828 | spin_lock_irqsave( |
| 2829 | &phba->hbalock, iflag); |
| 2830 | cmdiocbp->iocb_flag &= |
| 2831 | ~LPFC_DRIVER_ABORTED; |
| 2832 | spin_unlock_irqrestore( |
| 2833 | &phba->hbalock, iflag); |
| 2834 | cmdiocbp->iocb.ulpStatus = |
| 2835 | IOSTAT_LOCAL_REJECT; |
| 2836 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2837 | IOERR_ABORT_REQUESTED; |
| 2838 | /* |
| 2839 | * For SLI4, irsiocb contains |
| 2840 | * NO_XRI in sli_xritag, it |
| 2841 | * shall not affect releasing |
| 2842 | * sgl (xri) process. |
| 2843 | */ |
| 2844 | saveq->iocb.ulpStatus = |
| 2845 | IOSTAT_LOCAL_REJECT; |
| 2846 | saveq->iocb.un.ulpWord[4] = |
| 2847 | IOERR_SLI_ABORTED; |
| 2848 | spin_lock_irqsave( |
| 2849 | &phba->hbalock, iflag); |
| 2850 | saveq->iocb_flag |= |
| 2851 | LPFC_DELAY_MEM_FREE; |
| 2852 | spin_unlock_irqrestore( |
| 2853 | &phba->hbalock, iflag); |
| 2854 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2855 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2858 | } else |
| 2859 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | } else { |
| 2861 | /* |
| 2862 | * Unknown initiating command based on the response iotag. |
| 2863 | * This could be the case on the ELS ring because of |
| 2864 | * lpfc_els_abort(). |
| 2865 | */ |
| 2866 | if (pring->ringno != LPFC_ELS_RING) { |
| 2867 | /* |
| 2868 | * Ring <ringno> handler: unexpected completion IoTag |
| 2869 | * <IoTag> |
| 2870 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2871 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2872 | "0322 Ring %d handler: " |
| 2873 | "unexpected completion IoTag x%x " |
| 2874 | "Data: x%x x%x x%x x%x\n", |
| 2875 | pring->ringno, |
| 2876 | saveq->iocb.ulpIoTag, |
| 2877 | saveq->iocb.ulpStatus, |
| 2878 | saveq->iocb.un.ulpWord[4], |
| 2879 | saveq->iocb.ulpCommand, |
| 2880 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | } |
| 2882 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2883 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | return rc; |
| 2885 | } |
| 2886 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2888 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2889 | * @phba: Pointer to HBA context object. |
| 2890 | * @pring: Pointer to driver SLI ring object. |
| 2891 | * |
| 2892 | * This function is called from the iocb ring event handlers when |
| 2893 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2894 | * an error attention condition to the worker thread and the worker |
| 2895 | * thread will transition the HBA to offline state. |
| 2896 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2897 | static void |
| 2898 | 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] | 2899 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2900 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2901 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2902 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2903 | * rsp ring <portRspMax> |
| 2904 | */ |
| 2905 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2906 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2907 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2908 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2909 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2910 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2911 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2912 | |
| 2913 | /* |
| 2914 | * All error attention handlers are posted to |
| 2915 | * worker thread |
| 2916 | */ |
| 2917 | phba->work_ha |= HA_ERATT; |
| 2918 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2919 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2920 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2921 | |
| 2922 | return; |
| 2923 | } |
| 2924 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2925 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2926 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2927 | * @ptr: Pointer to address of HBA context object. |
| 2928 | * |
| 2929 | * This function is invoked by the Error Attention polling timer when the |
| 2930 | * timer times out. It will check the SLI Error Attention register for |
| 2931 | * possible attention events. If so, it will post an Error Attention event |
| 2932 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2933 | * Error Attention polling timer for the next poll. |
| 2934 | **/ |
| 2935 | void lpfc_poll_eratt(unsigned long ptr) |
| 2936 | { |
| 2937 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2938 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2939 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2940 | |
| 2941 | phba = (struct lpfc_hba *)ptr; |
| 2942 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2943 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2944 | sli_intr = phba->sli.slistat.sli_intr; |
| 2945 | |
| 2946 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2947 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2948 | sli_intr); |
| 2949 | else |
| 2950 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2951 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2952 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 2953 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2954 | phba->sli.slistat.sli_ips = cnt; |
| 2955 | |
| 2956 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2957 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2958 | /* Check chip HA register for error event */ |
| 2959 | eratt = lpfc_sli_check_eratt(phba); |
| 2960 | |
| 2961 | if (eratt) |
| 2962 | /* Tell the worker thread there is work to do */ |
| 2963 | lpfc_worker_wake_up(phba); |
| 2964 | else |
| 2965 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 2966 | mod_timer(&phba->eratt_poll, |
| 2967 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2968 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2969 | return; |
| 2970 | } |
| 2971 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2972 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2973 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2974 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2975 | * @phba: Pointer to HBA context object. |
| 2976 | * @pring: Pointer to driver SLI ring object. |
| 2977 | * @mask: Host attention register mask for this ring. |
| 2978 | * |
| 2979 | * This function is called from the interrupt context when there is a ring |
| 2980 | * event for the fcp ring. The caller does not hold any lock. |
| 2981 | * 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] | 2982 | * 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] | 2983 | * LE bit set. The function will call the completion handler of the command iocb |
| 2984 | * if the response iocb indicates a completion for a command iocb or it is |
| 2985 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2986 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2987 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2988 | * to check it explicitly. |
| 2989 | */ |
| 2990 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2991 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2992 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2994 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2996 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2998 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | uint32_t status; |
| 3000 | uint32_t portRspPut, portRspMax; |
| 3001 | int rc = 1; |
| 3002 | lpfc_iocb_type type; |
| 3003 | unsigned long iflag; |
| 3004 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3006 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3007 | pring->stats.iocb_event++; |
| 3008 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | /* |
| 3010 | * The next available response entry should never exceed the maximum |
| 3011 | * entries. If it does, treat it as an adapter hardware error. |
| 3012 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3013 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3015 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3016 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3017 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3018 | return 1; |
| 3019 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3020 | if (phba->fcp_ring_in_use) { |
| 3021 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3022 | return 1; |
| 3023 | } else |
| 3024 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | |
| 3026 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3027 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3028 | /* |
| 3029 | * Fetch an entry off the ring and copy it into a local data |
| 3030 | * structure. The copy involves a byte-swap since the |
| 3031 | * network byte order and pci byte orders are different. |
| 3032 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3033 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3034 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3035 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3036 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3037 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3038 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3039 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3040 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3041 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3042 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3043 | irsp = &rspiocbq.iocb; |
| 3044 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3046 | pring->stats.iocb_rsp++; |
| 3047 | rsp_cmpl++; |
| 3048 | |
| 3049 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3050 | /* |
| 3051 | * If resource errors reported from HBA, reduce |
| 3052 | * queuedepths of the SCSI device. |
| 3053 | */ |
| 3054 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3055 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3056 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3057 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3058 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3059 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3060 | } |
| 3061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | /* Rsp ring <ringno> error: IOCB */ |
| 3063 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3064 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3065 | "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] | 3066 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3067 | irsp->un.ulpWord[0], |
| 3068 | irsp->un.ulpWord[1], |
| 3069 | irsp->un.ulpWord[2], |
| 3070 | irsp->un.ulpWord[3], |
| 3071 | irsp->un.ulpWord[4], |
| 3072 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3073 | *(uint32_t *)&irsp->un1, |
| 3074 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | switch (type) { |
| 3078 | case LPFC_ABORT_IOCB: |
| 3079 | case LPFC_SOL_IOCB: |
| 3080 | /* |
| 3081 | * Idle exchange closed via ABTS from port. No iocb |
| 3082 | * resources need to be recovered. |
| 3083 | */ |
| 3084 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3085 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3086 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3087 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3088 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3089 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | break; |
| 3091 | } |
| 3092 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3093 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3094 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3095 | if (unlikely(!cmdiocbq)) |
| 3096 | break; |
| 3097 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3098 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3099 | if (cmdiocbq->iocb_cmpl) { |
| 3100 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3101 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3102 | &rspiocbq); |
| 3103 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3104 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3106 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3107 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3108 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3110 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3111 | default: |
| 3112 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3113 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3114 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3115 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3116 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3117 | dev_warn(&((phba->pcidev)->dev), |
| 3118 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | phba->brd_no, adaptermsg); |
| 3120 | } else { |
| 3121 | /* Unknown IOCB command */ |
| 3122 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3123 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3125 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3126 | irsp->ulpStatus, |
| 3127 | irsp->ulpIoTag, |
| 3128 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3129 | } |
| 3130 | break; |
| 3131 | } |
| 3132 | |
| 3133 | /* |
| 3134 | * The response IOCB has been processed. Update the ring |
| 3135 | * pointer in SLIM. If the port response put pointer has not |
| 3136 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3137 | * response put pointer. |
| 3138 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3139 | writel(pring->sli.sli3.rspidx, |
| 3140 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3142 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3144 | } |
| 3145 | |
| 3146 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3147 | pring->stats.iocb_rsp_full++; |
| 3148 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3149 | writel(status, phba->CAregaddr); |
| 3150 | readl(phba->CAregaddr); |
| 3151 | } |
| 3152 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3153 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3154 | pring->stats.iocb_cmd_empty++; |
| 3155 | |
| 3156 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3157 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3158 | lpfc_sli_resume_iocb(phba, pring); |
| 3159 | |
| 3160 | if ((pring->lpfc_sli_cmd_available)) |
| 3161 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3162 | |
| 3163 | } |
| 3164 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3165 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3166 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | return rc; |
| 3168 | } |
| 3169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3170 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3171 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3172 | * @phba: Pointer to HBA context object. |
| 3173 | * @pring: Pointer to driver SLI ring object. |
| 3174 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3175 | * |
| 3176 | * This function is called from the worker thread when there is a slow-path |
| 3177 | * response IOCB to process. This function chains all the response iocbs until |
| 3178 | * seeing the iocb with the LE bit set. The function will call |
| 3179 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3180 | * completion of a command iocb. The function will call the |
| 3181 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3182 | * The function frees the resources or calls the completion handler if this |
| 3183 | * iocb is an abort completion. The function returns NULL when the response |
| 3184 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3185 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3186 | * response iocb passed in. |
| 3187 | **/ |
| 3188 | static struct lpfc_iocbq * |
| 3189 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3190 | struct lpfc_iocbq *rspiocbp) |
| 3191 | { |
| 3192 | struct lpfc_iocbq *saveq; |
| 3193 | struct lpfc_iocbq *cmdiocbp; |
| 3194 | struct lpfc_iocbq *next_iocb; |
| 3195 | IOCB_t *irsp = NULL; |
| 3196 | uint32_t free_saveq; |
| 3197 | uint8_t iocb_cmd_type; |
| 3198 | lpfc_iocb_type type; |
| 3199 | unsigned long iflag; |
| 3200 | int rc; |
| 3201 | |
| 3202 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3203 | /* First add the response iocb to the countinueq list */ |
| 3204 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3205 | pring->iocb_continueq_cnt++; |
| 3206 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3207 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3208 | irsp = &rspiocbp->iocb; |
| 3209 | if (irsp->ulpLe) { |
| 3210 | /* |
| 3211 | * By default, the driver expects to free all resources |
| 3212 | * associated with this iocb completion. |
| 3213 | */ |
| 3214 | free_saveq = 1; |
| 3215 | saveq = list_get_first(&pring->iocb_continueq, |
| 3216 | struct lpfc_iocbq, list); |
| 3217 | irsp = &(saveq->iocb); |
| 3218 | list_del_init(&pring->iocb_continueq); |
| 3219 | pring->iocb_continueq_cnt = 0; |
| 3220 | |
| 3221 | pring->stats.iocb_rsp++; |
| 3222 | |
| 3223 | /* |
| 3224 | * If resource errors reported from HBA, reduce |
| 3225 | * queuedepths of the SCSI device. |
| 3226 | */ |
| 3227 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3228 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3229 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3230 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3231 | phba->lpfc_rampdown_queue_depth(phba); |
| 3232 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3233 | } |
| 3234 | |
| 3235 | if (irsp->ulpStatus) { |
| 3236 | /* Rsp ring <ringno> error: IOCB */ |
| 3237 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3238 | "0328 Rsp Ring %d error: " |
| 3239 | "IOCB Data: " |
| 3240 | "x%x x%x x%x x%x " |
| 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\n", |
| 3244 | pring->ringno, |
| 3245 | irsp->un.ulpWord[0], |
| 3246 | irsp->un.ulpWord[1], |
| 3247 | irsp->un.ulpWord[2], |
| 3248 | irsp->un.ulpWord[3], |
| 3249 | irsp->un.ulpWord[4], |
| 3250 | irsp->un.ulpWord[5], |
| 3251 | *(((uint32_t *) irsp) + 6), |
| 3252 | *(((uint32_t *) irsp) + 7), |
| 3253 | *(((uint32_t *) irsp) + 8), |
| 3254 | *(((uint32_t *) irsp) + 9), |
| 3255 | *(((uint32_t *) irsp) + 10), |
| 3256 | *(((uint32_t *) irsp) + 11), |
| 3257 | *(((uint32_t *) irsp) + 12), |
| 3258 | *(((uint32_t *) irsp) + 13), |
| 3259 | *(((uint32_t *) irsp) + 14), |
| 3260 | *(((uint32_t *) irsp) + 15)); |
| 3261 | } |
| 3262 | |
| 3263 | /* |
| 3264 | * Fetch the IOCB command type and call the correct completion |
| 3265 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3266 | * get freed back to the lpfc_iocb_list by the discovery |
| 3267 | * kernel thread. |
| 3268 | */ |
| 3269 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3270 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3271 | switch (type) { |
| 3272 | case LPFC_SOL_IOCB: |
| 3273 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3274 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3275 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3276 | break; |
| 3277 | |
| 3278 | case LPFC_UNSOL_IOCB: |
| 3279 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3280 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3281 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3282 | if (!rc) |
| 3283 | free_saveq = 0; |
| 3284 | break; |
| 3285 | |
| 3286 | case LPFC_ABORT_IOCB: |
| 3287 | cmdiocbp = NULL; |
| 3288 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3289 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3290 | saveq); |
| 3291 | if (cmdiocbp) { |
| 3292 | /* Call the specified completion routine */ |
| 3293 | if (cmdiocbp->iocb_cmpl) { |
| 3294 | spin_unlock_irqrestore(&phba->hbalock, |
| 3295 | iflag); |
| 3296 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3297 | saveq); |
| 3298 | spin_lock_irqsave(&phba->hbalock, |
| 3299 | iflag); |
| 3300 | } else |
| 3301 | __lpfc_sli_release_iocbq(phba, |
| 3302 | cmdiocbp); |
| 3303 | } |
| 3304 | break; |
| 3305 | |
| 3306 | case LPFC_UNKNOWN_IOCB: |
| 3307 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3308 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3309 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3310 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3311 | MAX_MSG_DATA); |
| 3312 | dev_warn(&((phba->pcidev)->dev), |
| 3313 | "lpfc%d: %s\n", |
| 3314 | phba->brd_no, adaptermsg); |
| 3315 | } else { |
| 3316 | /* Unknown IOCB command */ |
| 3317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3318 | "0335 Unknown IOCB " |
| 3319 | "command Data: x%x " |
| 3320 | "x%x x%x x%x\n", |
| 3321 | irsp->ulpCommand, |
| 3322 | irsp->ulpStatus, |
| 3323 | irsp->ulpIoTag, |
| 3324 | irsp->ulpContext); |
| 3325 | } |
| 3326 | break; |
| 3327 | } |
| 3328 | |
| 3329 | if (free_saveq) { |
| 3330 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3331 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3332 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3333 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3334 | } |
| 3335 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3336 | } |
| 3337 | rspiocbp = NULL; |
| 3338 | } |
| 3339 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3340 | return rspiocbp; |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * 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] | 3345 | * @phba: Pointer to HBA context object. |
| 3346 | * @pring: Pointer to driver SLI ring object. |
| 3347 | * @mask: Host attention register mask for this ring. |
| 3348 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3349 | * This routine wraps the actual slow_ring event process routine from the |
| 3350 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3351 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3352 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3353 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3354 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3356 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3357 | } |
| 3358 | |
| 3359 | /** |
| 3360 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3361 | * @phba: Pointer to HBA context object. |
| 3362 | * @pring: Pointer to driver SLI ring object. |
| 3363 | * @mask: Host attention register mask for this ring. |
| 3364 | * |
| 3365 | * This function is called from the worker thread when there is a ring event |
| 3366 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3367 | * remove each response iocb in the response ring and calls the handle |
| 3368 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3369 | **/ |
| 3370 | static void |
| 3371 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3372 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3373 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3374 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | IOCB_t *entry; |
| 3376 | IOCB_t *irsp = NULL; |
| 3377 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3380 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3382 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3383 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | pring->stats.iocb_event++; |
| 3385 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | /* |
| 3387 | * The next available response entry should never exceed the maximum |
| 3388 | * entries. If it does, treat it as an adapter hardware error. |
| 3389 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3390 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3392 | if (portRspPut >= portRspMax) { |
| 3393 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3394 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | * rsp ring <portRspMax> |
| 3396 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3397 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3398 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3399 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3400 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | phba->link_state = LPFC_HBA_ERROR; |
| 3403 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | |
| 3405 | phba->work_hs = HS_FFER3; |
| 3406 | lpfc_handle_eratt(phba); |
| 3407 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3408 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3412 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | /* |
| 3414 | * Build a completion list and call the appropriate handler. |
| 3415 | * The process is to get the next available response iocb, get |
| 3416 | * a free iocb from the list, copy the response data into the |
| 3417 | * free iocb, insert to the continuation list, and update the |
| 3418 | * next response index to slim. This process makes response |
| 3419 | * iocb's in the ring available to DMA as fast as possible but |
| 3420 | * pays a penalty for a copy operation. Since the iocb is |
| 3421 | * only 32 bytes, this penalty is considered small relative to |
| 3422 | * the PCI reads for register values and a slim write. When |
| 3423 | * the ulpLe field is set, the entire Command has been |
| 3424 | * received. |
| 3425 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3426 | entry = lpfc_resp_iocb(phba, pring); |
| 3427 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3428 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3429 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | if (rspiocbp == NULL) { |
| 3431 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3432 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3436 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3437 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | irsp = &rspiocbp->iocb; |
| 3439 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3440 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3441 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3443 | if (pring->ringno == LPFC_ELS_RING) { |
| 3444 | lpfc_debugfs_slow_ring_trc(phba, |
| 3445 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3446 | *(((uint32_t *) irsp) + 4), |
| 3447 | *(((uint32_t *) irsp) + 6), |
| 3448 | *(((uint32_t *) irsp) + 7)); |
| 3449 | } |
| 3450 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3451 | writel(pring->sli.sli3.rspidx, |
| 3452 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3454 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3455 | /* Handle the response IOCB */ |
| 3456 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3457 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | |
| 3459 | /* |
| 3460 | * If the port response put pointer has not been updated, sync |
| 3461 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3462 | * response put pointer. |
| 3463 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3464 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3466 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3467 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3469 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | /* At least one response entry has been freed */ |
| 3471 | pring->stats.iocb_rsp_full++; |
| 3472 | /* SET RxRE_RSP in Chip Att register */ |
| 3473 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3474 | writel(status, phba->CAregaddr); |
| 3475 | readl(phba->CAregaddr); /* flush */ |
| 3476 | } |
| 3477 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3478 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3479 | pring->stats.iocb_cmd_empty++; |
| 3480 | |
| 3481 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3482 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | lpfc_sli_resume_iocb(phba, pring); |
| 3484 | |
| 3485 | if ((pring->lpfc_sli_cmd_available)) |
| 3486 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3487 | |
| 3488 | } |
| 3489 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3490 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3491 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3492 | } |
| 3493 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3494 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3495 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3496 | * @phba: Pointer to HBA context object. |
| 3497 | * @pring: Pointer to driver SLI ring object. |
| 3498 | * @mask: Host attention register mask for this ring. |
| 3499 | * |
| 3500 | * This function is called from the worker thread when there is a pending |
| 3501 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3502 | * queue. The caller does not hold any lock. The function will remove each |
| 3503 | * response iocb from the response worker queue and calls the handle |
| 3504 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3505 | **/ |
| 3506 | static void |
| 3507 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3508 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3509 | { |
| 3510 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3511 | struct hbq_dmabuf *dmabuf; |
| 3512 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3513 | unsigned long iflag; |
| 3514 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3515 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3516 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3517 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3518 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3519 | /* Get the response iocb from the head of work queue */ |
| 3520 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3521 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3522 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3523 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3524 | |
| 3525 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3526 | case CQE_CODE_COMPL_WQE: |
| 3527 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3528 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3529 | /* Translate ELS WCQE to response IOCBQ */ |
| 3530 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3531 | irspiocbq); |
| 3532 | if (irspiocbq) |
| 3533 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3534 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3535 | break; |
| 3536 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3537 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3538 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3539 | cq_event); |
| 3540 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3541 | break; |
| 3542 | default: |
| 3543 | break; |
| 3544 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3549 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3550 | * @phba: Pointer to HBA context object. |
| 3551 | * @pring: Pointer to driver SLI ring object. |
| 3552 | * |
| 3553 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3554 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3555 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3556 | * the return of this function. The caller is not required to hold any locks. |
| 3557 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3558 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3560 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3561 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3564 | if (pring->ringno == LPFC_ELS_RING) { |
| 3565 | lpfc_fabric_abort_hba(phba); |
| 3566 | } |
| 3567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | /* Error everything on txq and txcmplq |
| 3569 | * First do the txq. |
| 3570 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3571 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3572 | spin_lock_irq(&pring->ring_lock); |
| 3573 | list_splice_init(&pring->txq, &completions); |
| 3574 | pring->txq_cnt = 0; |
| 3575 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3577 | spin_lock_irq(&phba->hbalock); |
| 3578 | /* Next issue ABTS for everything on the txcmplq */ |
| 3579 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3580 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3581 | spin_unlock_irq(&phba->hbalock); |
| 3582 | } else { |
| 3583 | spin_lock_irq(&phba->hbalock); |
| 3584 | list_splice_init(&pring->txq, &completions); |
| 3585 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3586 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3587 | /* Next issue ABTS for everything on the txcmplq */ |
| 3588 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3589 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3590 | spin_unlock_irq(&phba->hbalock); |
| 3591 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3592 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3593 | /* Cancel all the IOCBs from the completions list */ |
| 3594 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3595 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | } |
| 3597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3598 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3599 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3600 | * @phba: Pointer to HBA context object. |
| 3601 | * @pring: Pointer to driver SLI ring object. |
| 3602 | * |
| 3603 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3604 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3605 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3606 | * the return of this function. The caller is not required to hold any locks. |
| 3607 | **/ |
| 3608 | void |
| 3609 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3610 | { |
| 3611 | struct lpfc_sli *psli = &phba->sli; |
| 3612 | struct lpfc_sli_ring *pring; |
| 3613 | uint32_t i; |
| 3614 | |
| 3615 | /* Look on all the FCP Rings for the iotag */ |
| 3616 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3617 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3618 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
| 3619 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3620 | } |
| 3621 | } else { |
| 3622 | pring = &psli->ring[psli->fcp_ring]; |
| 3623 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | |
| 3628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3629 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3630 | * @phba: Pointer to HBA context object. |
| 3631 | * |
| 3632 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3633 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3634 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3635 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3636 | * slot has been permanently disabled. |
| 3637 | **/ |
| 3638 | void |
| 3639 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3640 | { |
| 3641 | LIST_HEAD(txq); |
| 3642 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3643 | struct lpfc_sli *psli = &phba->sli; |
| 3644 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3645 | uint32_t i; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3646 | |
| 3647 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3648 | /* Indicate the I/O queues are flushed */ |
| 3649 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3650 | spin_unlock_irq(&phba->hbalock); |
| 3651 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3652 | /* Look on all the FCP Rings for the iotag */ |
| 3653 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3654 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3655 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3656 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3657 | spin_lock_irq(&pring->ring_lock); |
| 3658 | /* Retrieve everything on txq */ |
| 3659 | list_splice_init(&pring->txq, &txq); |
| 3660 | /* Retrieve everything on the txcmplq */ |
| 3661 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3662 | pring->txq_cnt = 0; |
| 3663 | pring->txcmplq_cnt = 0; |
| 3664 | spin_unlock_irq(&pring->ring_lock); |
| 3665 | |
| 3666 | /* Flush the txq */ |
| 3667 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3668 | IOSTAT_LOCAL_REJECT, |
| 3669 | IOERR_SLI_DOWN); |
| 3670 | /* Flush the txcmpq */ |
| 3671 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3672 | IOSTAT_LOCAL_REJECT, |
| 3673 | IOERR_SLI_DOWN); |
| 3674 | } |
| 3675 | } else { |
| 3676 | pring = &psli->ring[psli->fcp_ring]; |
| 3677 | |
| 3678 | spin_lock_irq(&phba->hbalock); |
| 3679 | /* Retrieve everything on txq */ |
| 3680 | list_splice_init(&pring->txq, &txq); |
| 3681 | /* Retrieve everything on the txcmplq */ |
| 3682 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3683 | pring->txq_cnt = 0; |
| 3684 | pring->txcmplq_cnt = 0; |
| 3685 | spin_unlock_irq(&phba->hbalock); |
| 3686 | |
| 3687 | /* Flush the txq */ |
| 3688 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3689 | IOERR_SLI_DOWN); |
| 3690 | /* Flush the txcmpq */ |
| 3691 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3692 | IOERR_SLI_DOWN); |
| 3693 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3697 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3698 | * @phba: Pointer to HBA context object. |
| 3699 | * @mask: Bit mask to be checked. |
| 3700 | * |
| 3701 | * This function reads the host status register and compares |
| 3702 | * with the provided bit mask to check if HBA completed |
| 3703 | * the restart. This function will wait in a loop for the |
| 3704 | * HBA to complete restart. If the HBA does not restart within |
| 3705 | * 15 iterations, the function will reset the HBA again. The |
| 3706 | * function returns 1 when HBA fail to restart otherwise returns |
| 3707 | * zero. |
| 3708 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3709 | static int |
| 3710 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3712 | uint32_t status; |
| 3713 | int i = 0; |
| 3714 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3715 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3716 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3717 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3718 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3720 | /* |
| 3721 | * Check status register every 100ms for 5 retries, then every |
| 3722 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3723 | * every 2.5 sec for 4. |
| 3724 | * Break our of the loop if errors occurred during init. |
| 3725 | */ |
| 3726 | while (((status & mask) != mask) && |
| 3727 | !(status & HS_FFERM) && |
| 3728 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3729 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3730 | if (i <= 5) |
| 3731 | msleep(10); |
| 3732 | else if (i <= 10) |
| 3733 | msleep(500); |
| 3734 | else |
| 3735 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3737 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3738 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3739 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3740 | lpfc_sli_brdrestart(phba); |
| 3741 | } |
| 3742 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3743 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3744 | retval = 1; |
| 3745 | break; |
| 3746 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3749 | /* Check to see if any errors occurred during init */ |
| 3750 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3752 | "2751 Adapter failed to restart, " |
| 3753 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3754 | status, |
| 3755 | readl(phba->MBslimaddr + 0xa8), |
| 3756 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3758 | retval = 1; |
| 3759 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3761 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | } |
| 3763 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3764 | /** |
| 3765 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3766 | * @phba: Pointer to HBA context object. |
| 3767 | * @mask: Bit mask to be checked. |
| 3768 | * |
| 3769 | * This function checks the host status register to check if HBA is |
| 3770 | * ready. This function will wait in a loop for the HBA to be ready |
| 3771 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3772 | * function again. The function returns 1 when HBA fail to be ready |
| 3773 | * otherwise returns zero. |
| 3774 | **/ |
| 3775 | static int |
| 3776 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3777 | { |
| 3778 | uint32_t status; |
| 3779 | int retval = 0; |
| 3780 | |
| 3781 | /* Read the HBA Host Status Register */ |
| 3782 | status = lpfc_sli4_post_status_check(phba); |
| 3783 | |
| 3784 | if (status) { |
| 3785 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3786 | lpfc_sli_brdrestart(phba); |
| 3787 | status = lpfc_sli4_post_status_check(phba); |
| 3788 | } |
| 3789 | |
| 3790 | /* Check to see if any errors occurred during init */ |
| 3791 | if (status) { |
| 3792 | phba->link_state = LPFC_HBA_ERROR; |
| 3793 | retval = 1; |
| 3794 | } else |
| 3795 | phba->sli4_hba.intr_enable = 0; |
| 3796 | |
| 3797 | return retval; |
| 3798 | } |
| 3799 | |
| 3800 | /** |
| 3801 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3802 | * @phba: Pointer to HBA context object. |
| 3803 | * @mask: Bit mask to be checked. |
| 3804 | * |
| 3805 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3806 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3807 | **/ |
| 3808 | int |
| 3809 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3810 | { |
| 3811 | return phba->lpfc_sli_brdready(phba, mask); |
| 3812 | } |
| 3813 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3814 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3815 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3817 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3818 | * @phba: Pointer to HBA context object. |
| 3819 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3820 | * This function is called before resetting an HBA. This function is called |
| 3821 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3822 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3823 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3824 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3825 | uint32_t __iomem *resp_buf; |
| 3826 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3827 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3828 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3829 | int i; |
| 3830 | uint8_t hdrtype; |
| 3831 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3832 | lockdep_assert_held(&phba->hbalock); |
| 3833 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3834 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3835 | if (hdrtype != 0x80 || |
| 3836 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3837 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3838 | return; |
| 3839 | |
| 3840 | /* |
| 3841 | * Tell the other part of the chip to suspend temporarily all |
| 3842 | * its DMA activity. |
| 3843 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3844 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3845 | |
| 3846 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3847 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3848 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3849 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3850 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3852 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3853 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3854 | return; |
| 3855 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3856 | /* Clear Chip error bit */ |
| 3857 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | mbox = 0; |
| 3862 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3863 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3864 | |
| 3865 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3866 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3867 | writel(mbox, mbox_buf); |
| 3868 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3869 | for (i = 0; i < 50; i++) { |
| 3870 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3871 | return; |
| 3872 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3873 | mdelay(1); |
| 3874 | else |
| 3875 | break; |
| 3876 | } |
| 3877 | resp_data = 0; |
| 3878 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3879 | return; |
| 3880 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3881 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3883 | goto restore_hc; |
| 3884 | else |
| 3885 | goto clear_errat; |
| 3886 | } |
| 3887 | |
| 3888 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3889 | resp_data = 0; |
| 3890 | for (i = 0; i < 500; i++) { |
| 3891 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3892 | return; |
| 3893 | if (resp_data != mbox) |
| 3894 | mdelay(1); |
| 3895 | else |
| 3896 | break; |
| 3897 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3898 | |
| 3899 | clear_errat: |
| 3900 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3901 | while (++i < 500) { |
| 3902 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3903 | return; |
| 3904 | if (!(ha_copy & HA_ERATT)) |
| 3905 | mdelay(1); |
| 3906 | else |
| 3907 | break; |
| 3908 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3909 | |
| 3910 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3911 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3916 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3917 | writel(hc_copy, phba->HCregaddr); |
| 3918 | readl(phba->HCregaddr); /* flush */ |
| 3919 | } |
| 3920 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3922 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3923 | * @phba: Pointer to HBA context object. |
| 3924 | * |
| 3925 | * This function issues a kill_board mailbox command and waits for |
| 3926 | * the error attention interrupt. This function is called for stopping |
| 3927 | * the firmware processing. The caller is not required to hold any |
| 3928 | * locks. This function calls lpfc_hba_down_post function to free |
| 3929 | * any pending commands after the kill. The function will return 1 when it |
| 3930 | * fails to kill the board else will return 0. |
| 3931 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3932 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3933 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3935 | struct lpfc_sli *psli; |
| 3936 | LPFC_MBOXQ_t *pmb; |
| 3937 | uint32_t status; |
| 3938 | uint32_t ha_copy; |
| 3939 | int retval; |
| 3940 | int i = 0; |
| 3941 | |
| 3942 | psli = &phba->sli; |
| 3943 | |
| 3944 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3945 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3946 | "0329 Kill HBA Data: x%x x%x\n", |
| 3947 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3948 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3949 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3950 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3951 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3952 | |
| 3953 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3954 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3955 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3956 | spin_unlock_irq(&phba->hbalock); |
| 3957 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3958 | return 1; |
| 3959 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3960 | status &= ~HC_ERINT_ENA; |
| 3961 | writel(status, phba->HCregaddr); |
| 3962 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3963 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3964 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3965 | |
| 3966 | lpfc_kill_board(phba, pmb); |
| 3967 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3968 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3969 | |
| 3970 | if (retval != MBX_SUCCESS) { |
| 3971 | if (retval != MBX_BUSY) |
| 3972 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3973 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3974 | "2752 KILL_BOARD command failed retval %d\n", |
| 3975 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | spin_lock_irq(&phba->hbalock); |
| 3977 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3978 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3979 | return 1; |
| 3980 | } |
| 3981 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3982 | spin_lock_irq(&phba->hbalock); |
| 3983 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3984 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3985 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3986 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3987 | |
| 3988 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3989 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3990 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3991 | * board is now undefined. |
| 3992 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3993 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3994 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3995 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3996 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3997 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3998 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4002 | if (ha_copy & HA_ERATT) { |
| 4003 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4004 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4005 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4006 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4007 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4008 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4010 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4011 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4012 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4015 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4016 | } |
| 4017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4018 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4019 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4020 | * @phba: Pointer to HBA context object. |
| 4021 | * |
| 4022 | * This function resets the HBA by writing HC_INITFF to the control |
| 4023 | * register. After the HBA resets, this function resets all the iocb ring |
| 4024 | * indices. This function disables PCI layer parity checking during |
| 4025 | * the reset. |
| 4026 | * This function returns 0 always. |
| 4027 | * The caller is not required to hold any locks. |
| 4028 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4029 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4030 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4031 | { |
| 4032 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4034 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4035 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4037 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4039 | /* Reset HBA */ |
| 4040 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4041 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4042 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | |
| 4044 | /* perform board reset */ |
| 4045 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4046 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | phba->pport->fc_myDID = 0; |
| 4048 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4050 | /* Turn off parity checking and serr during the physical reset */ |
| 4051 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4052 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4053 | (cfg_value & |
| 4054 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4055 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4056 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4057 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4058 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4059 | writel(HC_INITFF, phba->HCregaddr); |
| 4060 | mdelay(1); |
| 4061 | readl(phba->HCregaddr); /* flush */ |
| 4062 | writel(0, phba->HCregaddr); |
| 4063 | readl(phba->HCregaddr); /* flush */ |
| 4064 | |
| 4065 | /* Restore PCI cmd register */ |
| 4066 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | |
| 4068 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4069 | for (i = 0; i < psli->num_rings; i++) { |
| 4070 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4072 | pring->sli.sli3.rspidx = 0; |
| 4073 | pring->sli.sli3.next_cmdidx = 0; |
| 4074 | pring->sli.sli3.local_getidx = 0; |
| 4075 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | pring->missbufcnt = 0; |
| 4077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4079 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4080 | return 0; |
| 4081 | } |
| 4082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4083 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4084 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4085 | * @phba: Pointer to HBA context object. |
| 4086 | * |
| 4087 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4088 | * checking during resets the device. The caller is not required to hold |
| 4089 | * any locks. |
| 4090 | * |
| 4091 | * This function returns 0 always. |
| 4092 | **/ |
| 4093 | int |
| 4094 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4095 | { |
| 4096 | struct lpfc_sli *psli = &phba->sli; |
| 4097 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4098 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4099 | |
| 4100 | /* Reset HBA */ |
| 4101 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4102 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4103 | phba->pport->port_state, psli->sli_flag, |
| 4104 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4105 | |
| 4106 | /* perform board reset */ |
| 4107 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4108 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4109 | phba->pport->fc_myDID = 0; |
| 4110 | phba->pport->fc_prevDID = 0; |
| 4111 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4112 | spin_lock_irq(&phba->hbalock); |
| 4113 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4114 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4115 | spin_unlock_irq(&phba->hbalock); |
| 4116 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4117 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4118 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4119 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4120 | return rc; |
| 4121 | } |
| 4122 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4123 | /* Now physically reset the device */ |
| 4124 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4125 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4126 | |
| 4127 | /* Turn off parity checking and serr during the physical reset */ |
| 4128 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4129 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4130 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4131 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4132 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4133 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4134 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4135 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4136 | /* Restore PCI cmd register */ |
| 4137 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4138 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4139 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | /** |
| 4143 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4144 | * @phba: Pointer to HBA context object. |
| 4145 | * |
| 4146 | * This function is called in the SLI initialization code path to |
| 4147 | * restart the HBA. The caller is not required to hold any lock. |
| 4148 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4149 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4150 | * function to free any pending commands. The function enables |
| 4151 | * POST only during the first initialization. The function returns zero. |
| 4152 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4153 | * command before the return of this function. |
| 4154 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4155 | static int |
| 4156 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4157 | { |
| 4158 | MAILBOX_t *mb; |
| 4159 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4160 | volatile uint32_t word0; |
| 4161 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4162 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4164 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4165 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4166 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4167 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4168 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4169 | psli = &phba->sli; |
| 4170 | |
| 4171 | /* Restart HBA */ |
| 4172 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4173 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4175 | |
| 4176 | word0 = 0; |
| 4177 | mb = (MAILBOX_t *) &word0; |
| 4178 | mb->mbxCommand = MBX_RESTART; |
| 4179 | mb->mbxHc = 1; |
| 4180 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4181 | lpfc_reset_barrier(phba); |
| 4182 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4183 | to_slim = phba->MBslimaddr; |
| 4184 | writel(*(uint32_t *) mb, to_slim); |
| 4185 | readl(to_slim); /* flush */ |
| 4186 | |
| 4187 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4188 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4189 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4190 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4191 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4192 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4193 | writel(*(uint32_t *) mb, to_slim); |
| 4194 | readl(to_slim); /* flush */ |
| 4195 | |
| 4196 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4197 | phba->pport->stopped = 0; |
| 4198 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4199 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4200 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4201 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4202 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4203 | psli->stats_start = get_seconds(); |
| 4204 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4205 | /* Give the INITFF and Post time to settle. */ |
| 4206 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4208 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4209 | if (hba_aer_enabled) |
| 4210 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4211 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4212 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | |
| 4214 | return 0; |
| 4215 | } |
| 4216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4217 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4218 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4219 | * @phba: Pointer to HBA context object. |
| 4220 | * |
| 4221 | * This function is called in the SLI initialization code path to restart |
| 4222 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4223 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4224 | * free any pending commands. |
| 4225 | **/ |
| 4226 | static int |
| 4227 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4228 | { |
| 4229 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4230 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4231 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4232 | |
| 4233 | /* Restart HBA */ |
| 4234 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4235 | "0296 Restart HBA Data: x%x x%x\n", |
| 4236 | phba->pport->port_state, psli->sli_flag); |
| 4237 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4238 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4239 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4240 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4241 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4242 | |
| 4243 | spin_lock_irq(&phba->hbalock); |
| 4244 | phba->pport->stopped = 0; |
| 4245 | phba->link_state = LPFC_INIT_START; |
| 4246 | phba->hba_flag = 0; |
| 4247 | spin_unlock_irq(&phba->hbalock); |
| 4248 | |
| 4249 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4250 | psli->stats_start = get_seconds(); |
| 4251 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4252 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4253 | if (hba_aer_enabled) |
| 4254 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4255 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4256 | lpfc_hba_down_post(phba); |
| 4257 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4258 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4263 | * @phba: Pointer to HBA context object. |
| 4264 | * |
| 4265 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4266 | * API jump table function pointer from the lpfc_hba struct. |
| 4267 | **/ |
| 4268 | int |
| 4269 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4270 | { |
| 4271 | return phba->lpfc_sli_brdrestart(phba); |
| 4272 | } |
| 4273 | |
| 4274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4275 | * 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] | 4276 | * @phba: Pointer to HBA context object. |
| 4277 | * |
| 4278 | * This function is called after a HBA restart to wait for successful |
| 4279 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4280 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4281 | * iteration, the function will restart the HBA again. The function returns |
| 4282 | * zero if HBA successfully restarted else returns negative error code. |
| 4283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4284 | static int |
| 4285 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4286 | { |
| 4287 | uint32_t status, i = 0; |
| 4288 | |
| 4289 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4290 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4291 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4292 | |
| 4293 | /* Check status register to see what current state is */ |
| 4294 | i = 0; |
| 4295 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4296 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4297 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4298 | * retries, then every 1 sec for 50 retires for a total of |
| 4299 | * ~60 seconds before reset the board again and check every |
| 4300 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4301 | * board ready is required by the Falcon FIPS zeroization |
| 4302 | * complete, and any reset the board in between shall cause |
| 4303 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4304 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4305 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4306 | /* Adapter failed to init, timeout, status reg |
| 4307 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4308 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4309 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4310 | "timeout, status reg x%x, " |
| 4311 | "FW Data: A8 x%x AC x%x\n", status, |
| 4312 | readl(phba->MBslimaddr + 0xa8), |
| 4313 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4314 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4315 | return -ETIMEDOUT; |
| 4316 | } |
| 4317 | |
| 4318 | /* Check to see if any errors occurred during init */ |
| 4319 | if (status & HS_FFERM) { |
| 4320 | /* ERROR: During chipset initialization */ |
| 4321 | /* Adapter failed to init, chipset, status reg |
| 4322 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4324 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4325 | "chipset, status reg x%x, " |
| 4326 | "FW Data: A8 x%x AC x%x\n", status, |
| 4327 | readl(phba->MBslimaddr + 0xa8), |
| 4328 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4329 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | return -EIO; |
| 4331 | } |
| 4332 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4333 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4335 | else if (i <= 100) |
| 4336 | msleep(100); |
| 4337 | else |
| 4338 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4340 | if (i == 150) { |
| 4341 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4342 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4343 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4344 | } |
| 4345 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4346 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4347 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | /* Check to see if any errors occurred during init */ |
| 4351 | if (status & HS_FFERM) { |
| 4352 | /* ERROR: During chipset initialization */ |
| 4353 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4355 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4356 | "status reg x%x, " |
| 4357 | "FW Data: A8 x%x AC x%x\n", status, |
| 4358 | readl(phba->MBslimaddr + 0xa8), |
| 4359 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4361 | return -EIO; |
| 4362 | } |
| 4363 | |
| 4364 | /* Clear all interrupt enable conditions */ |
| 4365 | writel(0, phba->HCregaddr); |
| 4366 | readl(phba->HCregaddr); /* flush */ |
| 4367 | |
| 4368 | /* setup host attn register */ |
| 4369 | writel(0xffffffff, phba->HAregaddr); |
| 4370 | readl(phba->HAregaddr); /* flush */ |
| 4371 | return 0; |
| 4372 | } |
| 4373 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4374 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4375 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4376 | * |
| 4377 | * This function calculates and returns the number of HBQs required to be |
| 4378 | * configured. |
| 4379 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4380 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4381 | lpfc_sli_hbq_count(void) |
| 4382 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4383 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4384 | } |
| 4385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4387 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4388 | * |
| 4389 | * This function adds the number of hbq entries in every HBQ to get |
| 4390 | * the total number of hbq entries required for the HBA and returns |
| 4391 | * the total count. |
| 4392 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4393 | static int |
| 4394 | lpfc_sli_hbq_entry_count(void) |
| 4395 | { |
| 4396 | int hbq_count = lpfc_sli_hbq_count(); |
| 4397 | int count = 0; |
| 4398 | int i; |
| 4399 | |
| 4400 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4401 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4402 | return count; |
| 4403 | } |
| 4404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4406 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4407 | * |
| 4408 | * This function calculates amount of memory required for all hbq entries |
| 4409 | * to be configured and returns the total memory required. |
| 4410 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4411 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4412 | lpfc_sli_hbq_size(void) |
| 4413 | { |
| 4414 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4415 | } |
| 4416 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4417 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4418 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4419 | * @phba: Pointer to HBA context object. |
| 4420 | * |
| 4421 | * This function is called during the SLI initialization to configure |
| 4422 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4423 | * required to hold any locks. This function will return zero if successful |
| 4424 | * else it will return negative error code. |
| 4425 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4426 | static int |
| 4427 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4428 | { |
| 4429 | int hbq_count = lpfc_sli_hbq_count(); |
| 4430 | LPFC_MBOXQ_t *pmb; |
| 4431 | MAILBOX_t *pmbox; |
| 4432 | uint32_t hbqno; |
| 4433 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4434 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4435 | /* Get a Mailbox buffer to setup mailbox |
| 4436 | * commands for HBA initialization |
| 4437 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4438 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4439 | |
| 4440 | if (!pmb) |
| 4441 | return -ENOMEM; |
| 4442 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4443 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4444 | |
| 4445 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4446 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4447 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4448 | |
| 4449 | hbq_entry_index = 0; |
| 4450 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4451 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4452 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4453 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4454 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4455 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4456 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4457 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4458 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4459 | |
| 4460 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4461 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4462 | mbxStatus <status>, ring <num> */ |
| 4463 | |
| 4464 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4465 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4466 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4467 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4468 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4469 | pmbox->mbxStatus, hbqno); |
| 4470 | |
| 4471 | phba->link_state = LPFC_HBA_ERROR; |
| 4472 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4473 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4474 | } |
| 4475 | } |
| 4476 | phba->hbq_count = hbq_count; |
| 4477 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4478 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4479 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4480 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4481 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4482 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4483 | return 0; |
| 4484 | } |
| 4485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4486 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4487 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4488 | * @phba: Pointer to HBA context object. |
| 4489 | * |
| 4490 | * This function is called during the SLI initialization to configure |
| 4491 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4492 | * required to hold any locks. This function will return zero if successful |
| 4493 | * else it will return negative error code. |
| 4494 | **/ |
| 4495 | static int |
| 4496 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4497 | { |
| 4498 | phba->hbq_in_use = 1; |
| 4499 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4500 | phba->hbq_count = 1; |
| 4501 | /* Initially populate or replenish the HBQs */ |
| 4502 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4503 | return 0; |
| 4504 | } |
| 4505 | |
| 4506 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4507 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4508 | * @phba: Pointer to HBA context object. |
| 4509 | * @sli_mode: sli mode - 2/3 |
| 4510 | * |
| 4511 | * This function is called by the sli intialization code path |
| 4512 | * to issue config_port mailbox command. This function restarts the |
| 4513 | * HBA firmware and issues a config_port mailbox command to configure |
| 4514 | * the SLI interface in the sli mode specified by sli_mode |
| 4515 | * variable. The caller is not required to hold any locks. |
| 4516 | * The function returns 0 if successful, else returns negative error |
| 4517 | * code. |
| 4518 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4519 | int |
| 4520 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | { |
| 4522 | LPFC_MBOXQ_t *pmb; |
| 4523 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4524 | |
| 4525 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4526 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4527 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4528 | return -ENOMEM; |
| 4529 | } |
| 4530 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4531 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4532 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4534 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4535 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4536 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4537 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4538 | rc = lpfc_sli_chipset_init(phba); |
| 4539 | if (rc) |
| 4540 | break; |
| 4541 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4543 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4544 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | resetcount++; |
| 4546 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4547 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4548 | * value of 0 means the call was successful. Any other |
| 4549 | * nonzero value is a failure, but if ERESTART is returned, |
| 4550 | * the driver may reset the HBA and try again. |
| 4551 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4552 | rc = lpfc_config_port_prep(phba); |
| 4553 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4554 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4556 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4558 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4560 | lpfc_config_port(phba, pmb); |
| 4561 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4562 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4563 | LPFC_SLI3_HBQ_ENABLED | |
| 4564 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4565 | LPFC_SLI3_BG_ENABLED | |
| 4566 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4567 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4569 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4570 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4571 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4572 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4573 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4574 | spin_unlock_irq(&phba->hbalock); |
| 4575 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4576 | } else { |
| 4577 | /* Allow asynchronous mailbox command to go through */ |
| 4578 | spin_lock_irq(&phba->hbalock); |
| 4579 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4580 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4581 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4582 | |
| 4583 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4584 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4585 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4586 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4587 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4588 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4589 | if (!done) { |
| 4590 | rc = -EINVAL; |
| 4591 | goto do_prep_failed; |
| 4592 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4593 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4594 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4595 | rc = -ENXIO; |
| 4596 | goto do_prep_failed; |
| 4597 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4598 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4599 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4600 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4601 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4602 | phba->max_vpi : phba->max_vports; |
| 4603 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4604 | } else |
| 4605 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4606 | phba->fips_level = 0; |
| 4607 | phba->fips_spec_rev = 0; |
| 4608 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4609 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4610 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4611 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4612 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4613 | "2850 Security Crypto Active. FIPS x%d " |
| 4614 | "(Spec Rev: x%d)", |
| 4615 | phba->fips_level, phba->fips_spec_rev); |
| 4616 | } |
| 4617 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4618 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4619 | "2856 Config Port Security Crypto " |
| 4620 | "Error: x%x ", |
| 4621 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4622 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4623 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4624 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4625 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4626 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4627 | |
| 4628 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4629 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4630 | |
| 4631 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4632 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4633 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4634 | else |
| 4635 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4636 | "0443 Adapter did not grant " |
| 4637 | "BlockGuard\n"); |
| 4638 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4639 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4640 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4641 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4642 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4643 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4644 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4645 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4646 | return rc; |
| 4647 | } |
| 4648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4649 | |
| 4650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4651 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4652 | * @phba: Pointer to HBA context object. |
| 4653 | * |
| 4654 | * This function is the main SLI intialization function. This function |
| 4655 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4656 | * error attention handler code. Caller is not required to hold any |
| 4657 | * locks. This function issues config_port mailbox command to configure |
| 4658 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4659 | * calls the config_port_post function to issue init_link mailbox |
| 4660 | * command and to start the discovery. The function will return zero |
| 4661 | * if successful, else it will return negative error code. |
| 4662 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4663 | int |
| 4664 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4665 | { |
| 4666 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4667 | int mode = 3, i; |
| 4668 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4669 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4670 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4671 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4672 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4673 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4674 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4675 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4676 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4677 | break; |
| 4678 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4679 | mode = 2; |
| 4680 | break; |
| 4681 | case 0: |
| 4682 | case 3: |
| 4683 | break; |
| 4684 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4685 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4686 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 4687 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4688 | |
| 4689 | break; |
| 4690 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 4691 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4692 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4693 | rc = lpfc_sli_config_port(phba, mode); |
| 4694 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4695 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4697 | "1820 Unable to select SLI-3. " |
| 4698 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4699 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4700 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 4701 | else if (rc && mode == 2) |
| 4702 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4703 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | goto lpfc_sli_hba_setup_error; |
| 4705 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4706 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4707 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4708 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4709 | if (!rc) { |
| 4710 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4711 | "2709 This device supports " |
| 4712 | "Advanced Error Reporting (AER)\n"); |
| 4713 | spin_lock_irq(&phba->hbalock); |
| 4714 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4715 | spin_unlock_irq(&phba->hbalock); |
| 4716 | } else { |
| 4717 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4718 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4719 | "Advanced Error Reporting (AER): %d\n", |
| 4720 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4721 | phba->cfg_aer_support = 0; |
| 4722 | } |
| 4723 | } |
| 4724 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4725 | if (phba->sli_rev == 3) { |
| 4726 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4727 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4728 | } else { |
| 4729 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4730 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4731 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4735 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4736 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4737 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | |
| 4739 | if (rc) |
| 4740 | goto lpfc_sli_hba_setup_error; |
| 4741 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4742 | /* Initialize VPIs. */ |
| 4743 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4744 | /* |
| 4745 | * The VPI bitmask and physical ID array are allocated |
| 4746 | * and initialized once only - at driver load. A port |
| 4747 | * reset doesn't need to reinitialize this memory. |
| 4748 | */ |
| 4749 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4750 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4751 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4752 | GFP_KERNEL); |
| 4753 | if (!phba->vpi_bmask) { |
| 4754 | rc = -ENOMEM; |
| 4755 | goto lpfc_sli_hba_setup_error; |
| 4756 | } |
| 4757 | |
| 4758 | phba->vpi_ids = kzalloc( |
| 4759 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4760 | GFP_KERNEL); |
| 4761 | if (!phba->vpi_ids) { |
| 4762 | kfree(phba->vpi_bmask); |
| 4763 | rc = -ENOMEM; |
| 4764 | goto lpfc_sli_hba_setup_error; |
| 4765 | } |
| 4766 | for (i = 0; i < phba->max_vpi; i++) |
| 4767 | phba->vpi_ids[i] = i; |
| 4768 | } |
| 4769 | } |
| 4770 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4771 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4772 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4773 | rc = lpfc_sli_hbq_setup(phba); |
| 4774 | if (rc) |
| 4775 | goto lpfc_sli_hba_setup_error; |
| 4776 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4777 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4778 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4779 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4780 | |
| 4781 | rc = lpfc_config_port_post(phba); |
| 4782 | if (rc) |
| 4783 | goto lpfc_sli_hba_setup_error; |
| 4784 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4785 | return rc; |
| 4786 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4787 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4788 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4790 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | return rc; |
| 4792 | } |
| 4793 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4794 | /** |
| 4795 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4796 | * @phba: Pointer to HBA context object. |
| 4797 | * @mboxq: mailbox pointer. |
| 4798 | * This function issue a dump mailbox command to read config region |
| 4799 | * 23 and parse the records in the region and populate driver |
| 4800 | * data structure. |
| 4801 | **/ |
| 4802 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4803 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4804 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4805 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4806 | struct lpfc_dmabuf *mp; |
| 4807 | struct lpfc_mqe *mqe; |
| 4808 | uint32_t data_length; |
| 4809 | int rc; |
| 4810 | |
| 4811 | /* Program the default value of vlan_id and fc_map */ |
| 4812 | phba->valid_vlan = 0; |
| 4813 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4814 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4815 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4816 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4817 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4818 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4819 | return -ENOMEM; |
| 4820 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4821 | mqe = &mboxq->u.mqe; |
| 4822 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4823 | rc = -ENOMEM; |
| 4824 | goto out_free_mboxq; |
| 4825 | } |
| 4826 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4827 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4828 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4829 | |
| 4830 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4831 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4832 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4833 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4834 | "CQ: x%x x%x x%x x%x\n", |
| 4835 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4836 | bf_get(lpfc_mqe_command, mqe), |
| 4837 | bf_get(lpfc_mqe_status, mqe), |
| 4838 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4839 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4840 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4841 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4842 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4843 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4844 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4845 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4846 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4847 | mboxq->mcqe.word0, |
| 4848 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4849 | mboxq->mcqe.trailer); |
| 4850 | |
| 4851 | if (rc) { |
| 4852 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4853 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4854 | rc = -EIO; |
| 4855 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4856 | } |
| 4857 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4858 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4859 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4860 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4861 | rc = -EIO; |
| 4862 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4863 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4864 | |
| 4865 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4866 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4867 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4868 | rc = 0; |
| 4869 | |
| 4870 | out_free_mboxq: |
| 4871 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4872 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4877 | * @phba: pointer to lpfc hba data structure. |
| 4878 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4879 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4880 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4881 | * On output, the number of data bytes in @vpd. |
| 4882 | * |
| 4883 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4884 | * addition, this routine gets the port vpd data. |
| 4885 | * |
| 4886 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4887 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4888 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4889 | **/ |
| 4890 | static int |
| 4891 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4892 | uint8_t *vpd, uint32_t *vpd_size) |
| 4893 | { |
| 4894 | int rc = 0; |
| 4895 | uint32_t dma_size; |
| 4896 | struct lpfc_dmabuf *dmabuf; |
| 4897 | struct lpfc_mqe *mqe; |
| 4898 | |
| 4899 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4900 | if (!dmabuf) |
| 4901 | return -ENOMEM; |
| 4902 | |
| 4903 | /* |
| 4904 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4905 | * mailbox command. |
| 4906 | */ |
| 4907 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 4908 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 4909 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4910 | if (!dmabuf->virt) { |
| 4911 | kfree(dmabuf); |
| 4912 | return -ENOMEM; |
| 4913 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4914 | |
| 4915 | /* |
| 4916 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4917 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4918 | * in SLI3. This code corrects the conflicts. |
| 4919 | */ |
| 4920 | lpfc_read_rev(phba, mboxq); |
| 4921 | mqe = &mboxq->u.mqe; |
| 4922 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4923 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4924 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4925 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4926 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4927 | |
| 4928 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4929 | if (rc) { |
| 4930 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4931 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4932 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4933 | return -EIO; |
| 4934 | } |
| 4935 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4936 | /* |
| 4937 | * The available vpd length cannot be bigger than the |
| 4938 | * DMA buffer passed to the port. Catch the less than |
| 4939 | * case and update the caller's size. |
| 4940 | */ |
| 4941 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4942 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4943 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4944 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4945 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4946 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4947 | dmabuf->virt, dmabuf->phys); |
| 4948 | kfree(dmabuf); |
| 4949 | return 0; |
| 4950 | } |
| 4951 | |
| 4952 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4953 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4954 | * @phba: pointer to lpfc hba data structure. |
| 4955 | * |
| 4956 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4957 | * is attached to. |
| 4958 | * |
| 4959 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4960 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4961 | * otherwise - failed to retrieve physical port name |
| 4962 | **/ |
| 4963 | static int |
| 4964 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4965 | { |
| 4966 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4967 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4968 | struct lpfc_controller_attribute *cntl_attr; |
| 4969 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4970 | void *virtaddr = NULL; |
| 4971 | uint32_t alloclen, reqlen; |
| 4972 | uint32_t shdr_status, shdr_add_status; |
| 4973 | union lpfc_sli4_cfg_shdr *shdr; |
| 4974 | char cport_name = 0; |
| 4975 | int rc; |
| 4976 | |
| 4977 | /* We assume nothing at this point */ |
| 4978 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4979 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4980 | |
| 4981 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4982 | if (!mboxq) |
| 4983 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4984 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4985 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4986 | lpfc_sli4_read_config(phba); |
| 4987 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4988 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4989 | |
| 4990 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4991 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4992 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4993 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4994 | LPFC_SLI4_MBX_NEMBED); |
| 4995 | if (alloclen < reqlen) { |
| 4996 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4997 | "3084 Allocated DMA memory size (%d) is " |
| 4998 | "less than the requested DMA memory size " |
| 4999 | "(%d)\n", alloclen, reqlen); |
| 5000 | rc = -ENOMEM; |
| 5001 | goto out_free_mboxq; |
| 5002 | } |
| 5003 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5004 | virtaddr = mboxq->sge_array->addr[0]; |
| 5005 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5006 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5007 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5008 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5009 | if (shdr_status || shdr_add_status || rc) { |
| 5010 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5011 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5012 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5013 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5014 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5015 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5016 | rc, shdr_status, shdr_add_status); |
| 5017 | rc = -ENXIO; |
| 5018 | goto out_free_mboxq; |
| 5019 | } |
| 5020 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5021 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5022 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5023 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5024 | phba->sli4_hba.lnk_info.lnk_no = |
| 5025 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5026 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5027 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5028 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5029 | phba->sli4_hba.lnk_info.lnk_no); |
| 5030 | |
| 5031 | retrieve_ppname: |
| 5032 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5033 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5034 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5035 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5036 | LPFC_SLI4_MBX_EMBED); |
| 5037 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5038 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5039 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5040 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5041 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5042 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5043 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5044 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5045 | if (shdr_status || shdr_add_status || rc) { |
| 5046 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5047 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5048 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5049 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5050 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5051 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5052 | rc, shdr_status, shdr_add_status); |
| 5053 | rc = -ENXIO; |
| 5054 | goto out_free_mboxq; |
| 5055 | } |
| 5056 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5057 | case LPFC_LINK_NUMBER_0: |
| 5058 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5059 | &get_port_name->u.response); |
| 5060 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5061 | break; |
| 5062 | case LPFC_LINK_NUMBER_1: |
| 5063 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5064 | &get_port_name->u.response); |
| 5065 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5066 | break; |
| 5067 | case LPFC_LINK_NUMBER_2: |
| 5068 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5069 | &get_port_name->u.response); |
| 5070 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5071 | break; |
| 5072 | case LPFC_LINK_NUMBER_3: |
| 5073 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5074 | &get_port_name->u.response); |
| 5075 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5076 | break; |
| 5077 | default: |
| 5078 | break; |
| 5079 | } |
| 5080 | |
| 5081 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5082 | phba->Port[0] = cport_name; |
| 5083 | phba->Port[1] = '\0'; |
| 5084 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5085 | "3091 SLI get port name: %s\n", phba->Port); |
| 5086 | } |
| 5087 | |
| 5088 | out_free_mboxq: |
| 5089 | if (rc != MBX_TIMEOUT) { |
| 5090 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5091 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5092 | else |
| 5093 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5094 | } |
| 5095 | return rc; |
| 5096 | } |
| 5097 | |
| 5098 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5099 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5100 | * @phba: pointer to lpfc hba data structure. |
| 5101 | * |
| 5102 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5103 | * event queues |
| 5104 | **/ |
| 5105 | static void |
| 5106 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5107 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 5108 | int fcp_eqidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5109 | |
| 5110 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5111 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5112 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5113 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5114 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5115 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 5116 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5117 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5118 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5119 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5120 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5121 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5122 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5123 | if (phba->sli4_hba.hba_eq) { |
| 5124 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5125 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5126 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5127 | LPFC_QUEUE_REARM); |
| 5128 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5129 | |
| 5130 | if (phba->cfg_fof) |
| 5131 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5135 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5136 | * @phba: Pointer to HBA context object. |
| 5137 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5138 | * @extnt_count: buffer to hold port available extent count. |
| 5139 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5140 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5141 | * This function calls the port and retrievs the number of available |
| 5142 | * extents and their size for a particular extent type. |
| 5143 | * |
| 5144 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5145 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5146 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5147 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5148 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5149 | { |
| 5150 | int rc = 0; |
| 5151 | uint32_t length; |
| 5152 | uint32_t mbox_tmo; |
| 5153 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5154 | LPFC_MBOXQ_t *mbox; |
| 5155 | |
| 5156 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5157 | if (!mbox) |
| 5158 | return -ENOMEM; |
| 5159 | |
| 5160 | /* Find out how many extents are available for this resource type */ |
| 5161 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5162 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5163 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5164 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5165 | length, LPFC_SLI4_MBX_EMBED); |
| 5166 | |
| 5167 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5168 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5169 | LPFC_SLI4_MBX_EMBED); |
| 5170 | if (unlikely(rc)) { |
| 5171 | rc = -EIO; |
| 5172 | goto err_exit; |
| 5173 | } |
| 5174 | |
| 5175 | if (!phba->sli4_hba.intr_enable) |
| 5176 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5177 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5178 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5179 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5180 | } |
| 5181 | if (unlikely(rc)) { |
| 5182 | rc = -EIO; |
| 5183 | goto err_exit; |
| 5184 | } |
| 5185 | |
| 5186 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5187 | if (bf_get(lpfc_mbox_hdr_status, |
| 5188 | &rsrc_info->header.cfg_shdr.response)) { |
| 5189 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5190 | "2930 Failed to get resource extents " |
| 5191 | "Status 0x%x Add'l Status 0x%x\n", |
| 5192 | bf_get(lpfc_mbox_hdr_status, |
| 5193 | &rsrc_info->header.cfg_shdr.response), |
| 5194 | bf_get(lpfc_mbox_hdr_add_status, |
| 5195 | &rsrc_info->header.cfg_shdr.response)); |
| 5196 | rc = -EIO; |
| 5197 | goto err_exit; |
| 5198 | } |
| 5199 | |
| 5200 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5201 | &rsrc_info->u.rsp); |
| 5202 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5203 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5204 | |
| 5205 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5206 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5207 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5208 | |
| 5209 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5210 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5211 | return rc; |
| 5212 | } |
| 5213 | |
| 5214 | /** |
| 5215 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5216 | * @phba: Pointer to HBA context object. |
| 5217 | * @type: The extent type to check. |
| 5218 | * |
| 5219 | * This function reads the current available extents from the port and checks |
| 5220 | * if the extent count or extent size has changed since the last access. |
| 5221 | * Callers use this routine post port reset to understand if there is a |
| 5222 | * extent reprovisioning requirement. |
| 5223 | * |
| 5224 | * Returns: |
| 5225 | * -Error: error indicates problem. |
| 5226 | * 1: Extent count or size has changed. |
| 5227 | * 0: No changes. |
| 5228 | **/ |
| 5229 | static int |
| 5230 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5231 | { |
| 5232 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5233 | uint16_t size_diff, rsrc_ext_size; |
| 5234 | int rc = 0; |
| 5235 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5236 | struct list_head *rsrc_blk_list = NULL; |
| 5237 | |
| 5238 | size_diff = 0; |
| 5239 | curr_ext_cnt = 0; |
| 5240 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5241 | &rsrc_ext_cnt, |
| 5242 | &rsrc_ext_size); |
| 5243 | if (unlikely(rc)) |
| 5244 | return -EIO; |
| 5245 | |
| 5246 | switch (type) { |
| 5247 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5248 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5249 | break; |
| 5250 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5251 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5252 | break; |
| 5253 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5254 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5255 | break; |
| 5256 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5257 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5258 | break; |
| 5259 | default: |
| 5260 | break; |
| 5261 | } |
| 5262 | |
| 5263 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5264 | curr_ext_cnt++; |
| 5265 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5266 | size_diff++; |
| 5267 | } |
| 5268 | |
| 5269 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5270 | rc = 1; |
| 5271 | |
| 5272 | return rc; |
| 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * lpfc_sli4_cfg_post_extnts - |
| 5277 | * @phba: Pointer to HBA context object. |
| 5278 | * @extnt_cnt - number of available extents. |
| 5279 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5280 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5281 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5282 | * |
| 5283 | * This function executes the extents allocation request. It also |
| 5284 | * takes care of the amount of memory needed to allocate or get the |
| 5285 | * allocated extents. It is the caller's responsibility to evaluate |
| 5286 | * the response. |
| 5287 | * |
| 5288 | * Returns: |
| 5289 | * -Error: Error value describes the condition found. |
| 5290 | * 0: if successful |
| 5291 | **/ |
| 5292 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5293 | 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] | 5294 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5295 | { |
| 5296 | int rc = 0; |
| 5297 | uint32_t req_len; |
| 5298 | uint32_t emb_len; |
| 5299 | uint32_t alloc_len, mbox_tmo; |
| 5300 | |
| 5301 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5302 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5303 | |
| 5304 | /* |
| 5305 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5306 | * accounts for extents-specific word. |
| 5307 | */ |
| 5308 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5309 | sizeof(uint32_t); |
| 5310 | |
| 5311 | /* |
| 5312 | * Presume the allocation and response will fit into an embedded |
| 5313 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5314 | */ |
| 5315 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5316 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5317 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5318 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5319 | sizeof(uint32_t); |
| 5320 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5321 | } |
| 5322 | |
| 5323 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5324 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5325 | req_len, *emb); |
| 5326 | if (alloc_len < req_len) { |
| 5327 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5328 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5329 | "less than the requested DMA memory " |
| 5330 | "size (x%x)\n", alloc_len, req_len); |
| 5331 | return -ENOMEM; |
| 5332 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5333 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5334 | if (unlikely(rc)) |
| 5335 | return -EIO; |
| 5336 | |
| 5337 | if (!phba->sli4_hba.intr_enable) |
| 5338 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5339 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5340 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5341 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5342 | } |
| 5343 | |
| 5344 | if (unlikely(rc)) |
| 5345 | rc = -EIO; |
| 5346 | return rc; |
| 5347 | } |
| 5348 | |
| 5349 | /** |
| 5350 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5351 | * @phba: Pointer to HBA context object. |
| 5352 | * @type: The resource extent type to allocate. |
| 5353 | * |
| 5354 | * This function allocates the number of elements for the specified |
| 5355 | * resource type. |
| 5356 | **/ |
| 5357 | static int |
| 5358 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5359 | { |
| 5360 | bool emb = false; |
| 5361 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5362 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5363 | uint16_t *ids; |
| 5364 | int i, rc; |
| 5365 | unsigned long longs; |
| 5366 | unsigned long *bmask; |
| 5367 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5368 | LPFC_MBOXQ_t *mbox; |
| 5369 | uint32_t length; |
| 5370 | struct lpfc_id_range *id_array = NULL; |
| 5371 | void *virtaddr = NULL; |
| 5372 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5373 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5374 | struct list_head *ext_blk_list; |
| 5375 | |
| 5376 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5377 | &rsrc_cnt, |
| 5378 | &rsrc_size); |
| 5379 | if (unlikely(rc)) |
| 5380 | return -EIO; |
| 5381 | |
| 5382 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5383 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5384 | "3009 No available Resource Extents " |
| 5385 | "for resource type 0x%x: Count: 0x%x, " |
| 5386 | "Size 0x%x\n", type, rsrc_cnt, |
| 5387 | rsrc_size); |
| 5388 | return -ENOMEM; |
| 5389 | } |
| 5390 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5391 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5392 | "2903 Post resource extents type-0x%x: " |
| 5393 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5394 | |
| 5395 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5396 | if (!mbox) |
| 5397 | return -ENOMEM; |
| 5398 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5399 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5400 | if (unlikely(rc)) { |
| 5401 | rc = -EIO; |
| 5402 | goto err_exit; |
| 5403 | } |
| 5404 | |
| 5405 | /* |
| 5406 | * Figure out where the response is located. Then get local pointers |
| 5407 | * to the response data. The port does not guarantee to respond to |
| 5408 | * all extents counts request so update the local variable with the |
| 5409 | * allocated count from the port. |
| 5410 | */ |
| 5411 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5412 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5413 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5414 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5415 | } else { |
| 5416 | virtaddr = mbox->sge_array->addr[0]; |
| 5417 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5418 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5419 | id_array = &n_rsrc->id; |
| 5420 | } |
| 5421 | |
| 5422 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5423 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5424 | |
| 5425 | /* |
| 5426 | * Based on the resource size and count, correct the base and max |
| 5427 | * resource values. |
| 5428 | */ |
| 5429 | length = sizeof(struct lpfc_rsrc_blks); |
| 5430 | switch (type) { |
| 5431 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5432 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5433 | sizeof(unsigned long), |
| 5434 | GFP_KERNEL); |
| 5435 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5436 | rc = -ENOMEM; |
| 5437 | goto err_exit; |
| 5438 | } |
| 5439 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5440 | sizeof(uint16_t), |
| 5441 | GFP_KERNEL); |
| 5442 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5443 | kfree(phba->sli4_hba.rpi_bmask); |
| 5444 | rc = -ENOMEM; |
| 5445 | goto err_exit; |
| 5446 | } |
| 5447 | |
| 5448 | /* |
| 5449 | * The next_rpi was initialized with the maximum available |
| 5450 | * count but the port may allocate a smaller number. Catch |
| 5451 | * that case and update the next_rpi. |
| 5452 | */ |
| 5453 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5454 | |
| 5455 | /* Initialize local ptrs for common extent processing later. */ |
| 5456 | bmask = phba->sli4_hba.rpi_bmask; |
| 5457 | ids = phba->sli4_hba.rpi_ids; |
| 5458 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5459 | break; |
| 5460 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5461 | phba->vpi_bmask = kzalloc(longs * |
| 5462 | sizeof(unsigned long), |
| 5463 | GFP_KERNEL); |
| 5464 | if (unlikely(!phba->vpi_bmask)) { |
| 5465 | rc = -ENOMEM; |
| 5466 | goto err_exit; |
| 5467 | } |
| 5468 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5469 | sizeof(uint16_t), |
| 5470 | GFP_KERNEL); |
| 5471 | if (unlikely(!phba->vpi_ids)) { |
| 5472 | kfree(phba->vpi_bmask); |
| 5473 | rc = -ENOMEM; |
| 5474 | goto err_exit; |
| 5475 | } |
| 5476 | |
| 5477 | /* Initialize local ptrs for common extent processing later. */ |
| 5478 | bmask = phba->vpi_bmask; |
| 5479 | ids = phba->vpi_ids; |
| 5480 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5481 | break; |
| 5482 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5483 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5484 | sizeof(unsigned long), |
| 5485 | GFP_KERNEL); |
| 5486 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5487 | rc = -ENOMEM; |
| 5488 | goto err_exit; |
| 5489 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5490 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5491 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5492 | sizeof(uint16_t), |
| 5493 | GFP_KERNEL); |
| 5494 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5495 | kfree(phba->sli4_hba.xri_bmask); |
| 5496 | rc = -ENOMEM; |
| 5497 | goto err_exit; |
| 5498 | } |
| 5499 | |
| 5500 | /* Initialize local ptrs for common extent processing later. */ |
| 5501 | bmask = phba->sli4_hba.xri_bmask; |
| 5502 | ids = phba->sli4_hba.xri_ids; |
| 5503 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5504 | break; |
| 5505 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5506 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5507 | sizeof(unsigned long), |
| 5508 | GFP_KERNEL); |
| 5509 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5510 | rc = -ENOMEM; |
| 5511 | goto err_exit; |
| 5512 | } |
| 5513 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5514 | sizeof(uint16_t), |
| 5515 | GFP_KERNEL); |
| 5516 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5517 | kfree(phba->sli4_hba.vfi_bmask); |
| 5518 | rc = -ENOMEM; |
| 5519 | goto err_exit; |
| 5520 | } |
| 5521 | |
| 5522 | /* Initialize local ptrs for common extent processing later. */ |
| 5523 | bmask = phba->sli4_hba.vfi_bmask; |
| 5524 | ids = phba->sli4_hba.vfi_ids; |
| 5525 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5526 | break; |
| 5527 | default: |
| 5528 | /* Unsupported Opcode. Fail call. */ |
| 5529 | id_array = NULL; |
| 5530 | bmask = NULL; |
| 5531 | ids = NULL; |
| 5532 | ext_blk_list = NULL; |
| 5533 | goto err_exit; |
| 5534 | } |
| 5535 | |
| 5536 | /* |
| 5537 | * Complete initializing the extent configuration with the |
| 5538 | * allocated ids assigned to this function. The bitmask serves |
| 5539 | * as an index into the array and manages the available ids. The |
| 5540 | * array just stores the ids communicated to the port via the wqes. |
| 5541 | */ |
| 5542 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5543 | if ((i % 2) == 0) |
| 5544 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5545 | &id_array[k]); |
| 5546 | else |
| 5547 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5548 | &id_array[k]); |
| 5549 | |
| 5550 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5551 | if (unlikely(!rsrc_blks)) { |
| 5552 | rc = -ENOMEM; |
| 5553 | kfree(bmask); |
| 5554 | kfree(ids); |
| 5555 | goto err_exit; |
| 5556 | } |
| 5557 | rsrc_blks->rsrc_start = rsrc_id; |
| 5558 | rsrc_blks->rsrc_size = rsrc_size; |
| 5559 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5560 | rsrc_start = rsrc_id; |
| 5561 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5562 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5563 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5564 | |
| 5565 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5566 | ids[j] = rsrc_id; |
| 5567 | rsrc_id++; |
| 5568 | j++; |
| 5569 | } |
| 5570 | /* Entire word processed. Get next word.*/ |
| 5571 | if ((i % 2) == 1) |
| 5572 | k++; |
| 5573 | } |
| 5574 | err_exit: |
| 5575 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5576 | return rc; |
| 5577 | } |
| 5578 | |
| 5579 | /** |
| 5580 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5581 | * @phba: Pointer to HBA context object. |
| 5582 | * @type: the extent's type. |
| 5583 | * |
| 5584 | * This function deallocates all extents of a particular resource type. |
| 5585 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5586 | * is the caller's responsibility to release all kernel memory resources. |
| 5587 | **/ |
| 5588 | static int |
| 5589 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5590 | { |
| 5591 | int rc; |
| 5592 | uint32_t length, mbox_tmo = 0; |
| 5593 | LPFC_MBOXQ_t *mbox; |
| 5594 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5595 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5596 | |
| 5597 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5598 | if (!mbox) |
| 5599 | return -ENOMEM; |
| 5600 | |
| 5601 | /* |
| 5602 | * This function sends an embedded mailbox because it only sends the |
| 5603 | * the resource type. All extents of this type are released by the |
| 5604 | * port. |
| 5605 | */ |
| 5606 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5607 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5608 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5609 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5610 | length, LPFC_SLI4_MBX_EMBED); |
| 5611 | |
| 5612 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5613 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5614 | LPFC_SLI4_MBX_EMBED); |
| 5615 | if (unlikely(rc)) { |
| 5616 | rc = -EIO; |
| 5617 | goto out_free_mbox; |
| 5618 | } |
| 5619 | if (!phba->sli4_hba.intr_enable) |
| 5620 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5621 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5622 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5623 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5624 | } |
| 5625 | if (unlikely(rc)) { |
| 5626 | rc = -EIO; |
| 5627 | goto out_free_mbox; |
| 5628 | } |
| 5629 | |
| 5630 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5631 | if (bf_get(lpfc_mbox_hdr_status, |
| 5632 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5633 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5634 | "2919 Failed to release resource extents " |
| 5635 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5636 | "Resource memory not released.\n", |
| 5637 | type, |
| 5638 | bf_get(lpfc_mbox_hdr_status, |
| 5639 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5640 | bf_get(lpfc_mbox_hdr_add_status, |
| 5641 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5642 | rc = -EIO; |
| 5643 | goto out_free_mbox; |
| 5644 | } |
| 5645 | |
| 5646 | /* Release kernel memory resources for the specific type. */ |
| 5647 | switch (type) { |
| 5648 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5649 | kfree(phba->vpi_bmask); |
| 5650 | kfree(phba->vpi_ids); |
| 5651 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5652 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5653 | &phba->lpfc_vpi_blk_list, list) { |
| 5654 | list_del_init(&rsrc_blk->list); |
| 5655 | kfree(rsrc_blk); |
| 5656 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5657 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5658 | break; |
| 5659 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5660 | kfree(phba->sli4_hba.xri_bmask); |
| 5661 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5662 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5663 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5664 | list_del_init(&rsrc_blk->list); |
| 5665 | kfree(rsrc_blk); |
| 5666 | } |
| 5667 | break; |
| 5668 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5669 | kfree(phba->sli4_hba.vfi_bmask); |
| 5670 | kfree(phba->sli4_hba.vfi_ids); |
| 5671 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5672 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5673 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5674 | list_del_init(&rsrc_blk->list); |
| 5675 | kfree(rsrc_blk); |
| 5676 | } |
| 5677 | break; |
| 5678 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5679 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5680 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5681 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5682 | list_del_init(&rsrc_blk->list); |
| 5683 | kfree(rsrc_blk); |
| 5684 | } |
| 5685 | break; |
| 5686 | default: |
| 5687 | break; |
| 5688 | } |
| 5689 | |
| 5690 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5691 | |
| 5692 | out_free_mbox: |
| 5693 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5694 | return rc; |
| 5695 | } |
| 5696 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5697 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5698 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 5699 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5700 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5701 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5702 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5703 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 5704 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5705 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5706 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 5707 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5708 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5709 | switch (feature) { |
| 5710 | case LPFC_SET_UE_RECOVERY: |
| 5711 | bf_set(lpfc_mbx_set_feature_UER, |
| 5712 | &mbox->u.mqe.un.set_feature, 1); |
| 5713 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 5714 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5715 | break; |
| 5716 | case LPFC_SET_MDS_DIAGS: |
| 5717 | bf_set(lpfc_mbx_set_feature_mds, |
| 5718 | &mbox->u.mqe.un.set_feature, 1); |
| 5719 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
| 5720 | &mbox->u.mqe.un.set_feature, 0); |
| 5721 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 5722 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5723 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5724 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5725 | |
| 5726 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5727 | } |
| 5728 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5729 | /** |
| 5730 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5731 | * @phba: Pointer to HBA context object. |
| 5732 | * |
| 5733 | * This function allocates all SLI4 resource identifiers. |
| 5734 | **/ |
| 5735 | int |
| 5736 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5737 | { |
| 5738 | int i, rc, error = 0; |
| 5739 | uint16_t count, base; |
| 5740 | unsigned long longs; |
| 5741 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5742 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5743 | 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] | 5744 | if (phba->sli4_hba.extents_in_use) { |
| 5745 | /* |
| 5746 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5747 | * resource extent count must be read and allocated before |
| 5748 | * provisioning the resource id arrays. |
| 5749 | */ |
| 5750 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5751 | LPFC_IDX_RSRC_RDY) { |
| 5752 | /* |
| 5753 | * Extent-based resources are set - the driver could |
| 5754 | * be in a port reset. Figure out if any corrective |
| 5755 | * actions need to be taken. |
| 5756 | */ |
| 5757 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5758 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5759 | if (rc != 0) |
| 5760 | error++; |
| 5761 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5762 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5763 | if (rc != 0) |
| 5764 | error++; |
| 5765 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5766 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5767 | if (rc != 0) |
| 5768 | error++; |
| 5769 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5770 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5771 | if (rc != 0) |
| 5772 | error++; |
| 5773 | |
| 5774 | /* |
| 5775 | * It's possible that the number of resources |
| 5776 | * provided to this port instance changed between |
| 5777 | * resets. Detect this condition and reallocate |
| 5778 | * resources. Otherwise, there is no action. |
| 5779 | */ |
| 5780 | if (error) { |
| 5781 | lpfc_printf_log(phba, KERN_INFO, |
| 5782 | LOG_MBOX | LOG_INIT, |
| 5783 | "2931 Detected extent resource " |
| 5784 | "change. Reallocating all " |
| 5785 | "extents.\n"); |
| 5786 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5787 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5788 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5789 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5790 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5791 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5792 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5793 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5794 | } else |
| 5795 | return 0; |
| 5796 | } |
| 5797 | |
| 5798 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5799 | if (unlikely(rc)) |
| 5800 | goto err_exit; |
| 5801 | |
| 5802 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5803 | if (unlikely(rc)) |
| 5804 | goto err_exit; |
| 5805 | |
| 5806 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5807 | if (unlikely(rc)) |
| 5808 | goto err_exit; |
| 5809 | |
| 5810 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5811 | if (unlikely(rc)) |
| 5812 | goto err_exit; |
| 5813 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5814 | LPFC_IDX_RSRC_RDY); |
| 5815 | return rc; |
| 5816 | } else { |
| 5817 | /* |
| 5818 | * The port does not support resource extents. The XRI, VPI, |
| 5819 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5820 | * Just allocate the bitmasks and provision the resource id |
| 5821 | * arrays. If a port reset is active, the resources don't |
| 5822 | * need any action - just exit. |
| 5823 | */ |
| 5824 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5825 | LPFC_IDX_RSRC_RDY) { |
| 5826 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5827 | lpfc_sli4_remove_rpis(phba); |
| 5828 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5829 | /* RPIs. */ |
| 5830 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5831 | if (count <= 0) { |
| 5832 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5833 | "3279 Invalid provisioning of " |
| 5834 | "rpi:%d\n", count); |
| 5835 | rc = -EINVAL; |
| 5836 | goto err_exit; |
| 5837 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5838 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5839 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5840 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5841 | sizeof(unsigned long), |
| 5842 | GFP_KERNEL); |
| 5843 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5844 | rc = -ENOMEM; |
| 5845 | goto err_exit; |
| 5846 | } |
| 5847 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5848 | sizeof(uint16_t), |
| 5849 | GFP_KERNEL); |
| 5850 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5851 | rc = -ENOMEM; |
| 5852 | goto free_rpi_bmask; |
| 5853 | } |
| 5854 | |
| 5855 | for (i = 0; i < count; i++) |
| 5856 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5857 | |
| 5858 | /* VPIs. */ |
| 5859 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5860 | if (count <= 0) { |
| 5861 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5862 | "3280 Invalid provisioning of " |
| 5863 | "vpi:%d\n", count); |
| 5864 | rc = -EINVAL; |
| 5865 | goto free_rpi_ids; |
| 5866 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5867 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5868 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5869 | phba->vpi_bmask = kzalloc(longs * |
| 5870 | sizeof(unsigned long), |
| 5871 | GFP_KERNEL); |
| 5872 | if (unlikely(!phba->vpi_bmask)) { |
| 5873 | rc = -ENOMEM; |
| 5874 | goto free_rpi_ids; |
| 5875 | } |
| 5876 | phba->vpi_ids = kzalloc(count * |
| 5877 | sizeof(uint16_t), |
| 5878 | GFP_KERNEL); |
| 5879 | if (unlikely(!phba->vpi_ids)) { |
| 5880 | rc = -ENOMEM; |
| 5881 | goto free_vpi_bmask; |
| 5882 | } |
| 5883 | |
| 5884 | for (i = 0; i < count; i++) |
| 5885 | phba->vpi_ids[i] = base + i; |
| 5886 | |
| 5887 | /* XRIs. */ |
| 5888 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5889 | if (count <= 0) { |
| 5890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5891 | "3281 Invalid provisioning of " |
| 5892 | "xri:%d\n", count); |
| 5893 | rc = -EINVAL; |
| 5894 | goto free_vpi_ids; |
| 5895 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5896 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5897 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5898 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5899 | sizeof(unsigned long), |
| 5900 | GFP_KERNEL); |
| 5901 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5902 | rc = -ENOMEM; |
| 5903 | goto free_vpi_ids; |
| 5904 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5905 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5906 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5907 | sizeof(uint16_t), |
| 5908 | GFP_KERNEL); |
| 5909 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5910 | rc = -ENOMEM; |
| 5911 | goto free_xri_bmask; |
| 5912 | } |
| 5913 | |
| 5914 | for (i = 0; i < count; i++) |
| 5915 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5916 | |
| 5917 | /* VFIs. */ |
| 5918 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5919 | if (count <= 0) { |
| 5920 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5921 | "3282 Invalid provisioning of " |
| 5922 | "vfi:%d\n", count); |
| 5923 | rc = -EINVAL; |
| 5924 | goto free_xri_ids; |
| 5925 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5926 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5927 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5928 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5929 | sizeof(unsigned long), |
| 5930 | GFP_KERNEL); |
| 5931 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5932 | rc = -ENOMEM; |
| 5933 | goto free_xri_ids; |
| 5934 | } |
| 5935 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5936 | sizeof(uint16_t), |
| 5937 | GFP_KERNEL); |
| 5938 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5939 | rc = -ENOMEM; |
| 5940 | goto free_vfi_bmask; |
| 5941 | } |
| 5942 | |
| 5943 | for (i = 0; i < count; i++) |
| 5944 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5945 | |
| 5946 | /* |
| 5947 | * Mark all resources ready. An HBA reset doesn't need |
| 5948 | * to reset the initialization. |
| 5949 | */ |
| 5950 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5951 | LPFC_IDX_RSRC_RDY); |
| 5952 | return 0; |
| 5953 | } |
| 5954 | |
| 5955 | free_vfi_bmask: |
| 5956 | kfree(phba->sli4_hba.vfi_bmask); |
| 5957 | free_xri_ids: |
| 5958 | kfree(phba->sli4_hba.xri_ids); |
| 5959 | free_xri_bmask: |
| 5960 | kfree(phba->sli4_hba.xri_bmask); |
| 5961 | free_vpi_ids: |
| 5962 | kfree(phba->vpi_ids); |
| 5963 | free_vpi_bmask: |
| 5964 | kfree(phba->vpi_bmask); |
| 5965 | free_rpi_ids: |
| 5966 | kfree(phba->sli4_hba.rpi_ids); |
| 5967 | free_rpi_bmask: |
| 5968 | kfree(phba->sli4_hba.rpi_bmask); |
| 5969 | err_exit: |
| 5970 | return rc; |
| 5971 | } |
| 5972 | |
| 5973 | /** |
| 5974 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5975 | * @phba: Pointer to HBA context object. |
| 5976 | * |
| 5977 | * This function allocates the number of elements for the specified |
| 5978 | * resource type. |
| 5979 | **/ |
| 5980 | int |
| 5981 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5982 | { |
| 5983 | if (phba->sli4_hba.extents_in_use) { |
| 5984 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5985 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5986 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5987 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5988 | } else { |
| 5989 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5990 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5991 | kfree(phba->vpi_ids); |
| 5992 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5993 | kfree(phba->sli4_hba.xri_bmask); |
| 5994 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5995 | kfree(phba->sli4_hba.vfi_bmask); |
| 5996 | kfree(phba->sli4_hba.vfi_ids); |
| 5997 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5998 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5999 | } |
| 6000 | |
| 6001 | return 0; |
| 6002 | } |
| 6003 | |
| 6004 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6005 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6006 | * @phba: Pointer to HBA context object. |
| 6007 | * @type: The resource extent type. |
| 6008 | * @extnt_count: buffer to hold port extent count response |
| 6009 | * @extnt_size: buffer to hold port extent size response. |
| 6010 | * |
| 6011 | * This function calls the port to read the host allocated extents |
| 6012 | * for a particular type. |
| 6013 | **/ |
| 6014 | int |
| 6015 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6016 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6017 | { |
| 6018 | bool emb; |
| 6019 | int rc = 0; |
| 6020 | uint16_t curr_blks = 0; |
| 6021 | uint32_t req_len, emb_len; |
| 6022 | uint32_t alloc_len, mbox_tmo; |
| 6023 | struct list_head *blk_list_head; |
| 6024 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6025 | LPFC_MBOXQ_t *mbox; |
| 6026 | void *virtaddr = NULL; |
| 6027 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6028 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6029 | union lpfc_sli4_cfg_shdr *shdr; |
| 6030 | |
| 6031 | switch (type) { |
| 6032 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6033 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6034 | break; |
| 6035 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6036 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6037 | break; |
| 6038 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6039 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6040 | break; |
| 6041 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6042 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6043 | break; |
| 6044 | default: |
| 6045 | return -EIO; |
| 6046 | } |
| 6047 | |
| 6048 | /* Count the number of extents currently allocatd for this type. */ |
| 6049 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6050 | if (curr_blks == 0) { |
| 6051 | /* |
| 6052 | * The GET_ALLOCATED mailbox does not return the size, |
| 6053 | * just the count. The size should be just the size |
| 6054 | * stored in the current allocated block and all sizes |
| 6055 | * for an extent type are the same so set the return |
| 6056 | * value now. |
| 6057 | */ |
| 6058 | *extnt_size = rsrc_blk->rsrc_size; |
| 6059 | } |
| 6060 | curr_blks++; |
| 6061 | } |
| 6062 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6063 | /* |
| 6064 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6065 | * accounts for extents-specific word. |
| 6066 | */ |
| 6067 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6068 | sizeof(uint32_t); |
| 6069 | |
| 6070 | /* |
| 6071 | * Presume the allocation and response will fit into an embedded |
| 6072 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6073 | */ |
| 6074 | emb = LPFC_SLI4_MBX_EMBED; |
| 6075 | req_len = emb_len; |
| 6076 | if (req_len > emb_len) { |
| 6077 | req_len = curr_blks * sizeof(uint16_t) + |
| 6078 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6079 | sizeof(uint32_t); |
| 6080 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6081 | } |
| 6082 | |
| 6083 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6084 | if (!mbox) |
| 6085 | return -ENOMEM; |
| 6086 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6087 | |
| 6088 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6089 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6090 | req_len, emb); |
| 6091 | if (alloc_len < req_len) { |
| 6092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6093 | "2983 Allocated DMA memory size (x%x) is " |
| 6094 | "less than the requested DMA memory " |
| 6095 | "size (x%x)\n", alloc_len, req_len); |
| 6096 | rc = -ENOMEM; |
| 6097 | goto err_exit; |
| 6098 | } |
| 6099 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6100 | if (unlikely(rc)) { |
| 6101 | rc = -EIO; |
| 6102 | goto err_exit; |
| 6103 | } |
| 6104 | |
| 6105 | if (!phba->sli4_hba.intr_enable) |
| 6106 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6107 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6108 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6109 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6110 | } |
| 6111 | |
| 6112 | if (unlikely(rc)) { |
| 6113 | rc = -EIO; |
| 6114 | goto err_exit; |
| 6115 | } |
| 6116 | |
| 6117 | /* |
| 6118 | * Figure out where the response is located. Then get local pointers |
| 6119 | * to the response data. The port does not guarantee to respond to |
| 6120 | * all extents counts request so update the local variable with the |
| 6121 | * allocated count from the port. |
| 6122 | */ |
| 6123 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6124 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6125 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6126 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6127 | } else { |
| 6128 | virtaddr = mbox->sge_array->addr[0]; |
| 6129 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6130 | shdr = &n_rsrc->cfg_shdr; |
| 6131 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6132 | } |
| 6133 | |
| 6134 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6135 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6136 | "2984 Failed to read allocated resources " |
| 6137 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6138 | type, |
| 6139 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6140 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6141 | rc = -EIO; |
| 6142 | goto err_exit; |
| 6143 | } |
| 6144 | err_exit: |
| 6145 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6146 | return rc; |
| 6147 | } |
| 6148 | |
| 6149 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6150 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 6151 | * @phba: pointer to lpfc hba data structure. |
| 6152 | * |
| 6153 | * This routine walks the list of els buffers that have been allocated and |
| 6154 | * repost them to the port by using SGL block post. This is needed after a |
| 6155 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 6156 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 6157 | * SGL block post mailbox commands to post them to the port. For single els |
| 6158 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6159 | * mailbox command for posting. |
| 6160 | * |
| 6161 | * Returns: 0 = success, non-zero failure. |
| 6162 | **/ |
| 6163 | static int |
| 6164 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 6165 | { |
| 6166 | struct lpfc_sglq *sglq_entry = NULL; |
| 6167 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6168 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6169 | 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] | 6170 | int last_xritag = NO_XRI; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6171 | struct lpfc_sli_ring *pring; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6172 | LIST_HEAD(prep_sgl_list); |
| 6173 | LIST_HEAD(blck_sgl_list); |
| 6174 | LIST_HEAD(allc_sgl_list); |
| 6175 | LIST_HEAD(post_sgl_list); |
| 6176 | LIST_HEAD(free_sgl_list); |
| 6177 | |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6178 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6179 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6180 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6181 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6182 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6183 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6184 | |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6185 | total_cnt = phba->sli4_hba.els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6186 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6187 | &allc_sgl_list, list) { |
| 6188 | list_del_init(&sglq_entry->list); |
| 6189 | block_cnt++; |
| 6190 | if ((last_xritag != NO_XRI) && |
| 6191 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6192 | /* a hole in xri block, form a sgl posting block */ |
| 6193 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6194 | post_cnt = block_cnt - 1; |
| 6195 | /* prepare list for next posting block */ |
| 6196 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6197 | block_cnt = 1; |
| 6198 | } else { |
| 6199 | /* prepare list for next posting block */ |
| 6200 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6201 | /* enough sgls for non-embed sgl mbox command */ |
| 6202 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6203 | list_splice_init(&prep_sgl_list, |
| 6204 | &blck_sgl_list); |
| 6205 | post_cnt = block_cnt; |
| 6206 | block_cnt = 0; |
| 6207 | } |
| 6208 | } |
| 6209 | num_posted++; |
| 6210 | |
| 6211 | /* keep track of last sgl's xritag */ |
| 6212 | last_xritag = sglq_entry->sli4_xritag; |
| 6213 | |
| 6214 | /* end of repost sgl list condition for els buffers */ |
| 6215 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 6216 | if (post_cnt == 0) { |
| 6217 | list_splice_init(&prep_sgl_list, |
| 6218 | &blck_sgl_list); |
| 6219 | post_cnt = block_cnt; |
| 6220 | } else if (block_cnt == 1) { |
| 6221 | status = lpfc_sli4_post_sgl(phba, |
| 6222 | sglq_entry->phys, 0, |
| 6223 | sglq_entry->sli4_xritag); |
| 6224 | if (!status) { |
| 6225 | /* successful, put sgl to posted list */ |
| 6226 | list_add_tail(&sglq_entry->list, |
| 6227 | &post_sgl_list); |
| 6228 | } else { |
| 6229 | /* Failure, put sgl to free list */ |
| 6230 | lpfc_printf_log(phba, KERN_WARNING, |
| 6231 | LOG_SLI, |
| 6232 | "3159 Failed to post els " |
| 6233 | "sgl, xritag:x%x\n", |
| 6234 | sglq_entry->sli4_xritag); |
| 6235 | list_add_tail(&sglq_entry->list, |
| 6236 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6237 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | /* continue until a nembed page worth of sgls */ |
| 6243 | if (post_cnt == 0) |
| 6244 | continue; |
| 6245 | |
| 6246 | /* post the els buffer list sgls as a block */ |
| 6247 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6248 | post_cnt); |
| 6249 | |
| 6250 | if (!status) { |
| 6251 | /* success, put sgl list to posted sgl list */ |
| 6252 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6253 | } else { |
| 6254 | /* Failure, put sgl list to free sgl list */ |
| 6255 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6256 | struct lpfc_sglq, |
| 6257 | list); |
| 6258 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6259 | "3160 Failed to post els sgl-list, " |
| 6260 | "xritag:x%x-x%x\n", |
| 6261 | sglq_entry_first->sli4_xritag, |
| 6262 | (sglq_entry_first->sli4_xritag + |
| 6263 | post_cnt - 1)); |
| 6264 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6265 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | /* don't reset xirtag due to hole in xri block */ |
| 6269 | if (block_cnt == 0) |
| 6270 | last_xritag = NO_XRI; |
| 6271 | |
| 6272 | /* reset els sgl post count for next round of posting */ |
| 6273 | post_cnt = 0; |
| 6274 | } |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6275 | /* update the number of XRIs posted for ELS */ |
| 6276 | phba->sli4_hba.els_xri_cnt = total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6277 | |
| 6278 | /* free the els sgls failed to post */ |
| 6279 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6280 | |
| 6281 | /* push els sgls posted to the availble list */ |
| 6282 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6283 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6284 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6285 | list_splice_init(&post_sgl_list, |
| 6286 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6287 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6288 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6289 | } else { |
| 6290 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6291 | "3161 Failure to post els sgl to port.\n"); |
| 6292 | return -EIO; |
| 6293 | } |
| 6294 | return 0; |
| 6295 | } |
| 6296 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6297 | void |
| 6298 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 6299 | { |
| 6300 | uint32_t len; |
| 6301 | |
| 6302 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 6303 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6304 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6305 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 6306 | LPFC_SLI4_MBX_EMBED); |
| 6307 | |
| 6308 | mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION; |
James Smart | b2fd103 | 2016-12-19 15:07:21 -0800 | [diff] [blame^] | 6309 | mbox->u.mqe.un.set_host_data.param_len = |
| 6310 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6311 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 6312 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 6313 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 6314 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 6315 | } |
| 6316 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6317 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6318 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6319 | * @phba: Pointer to HBA context object. |
| 6320 | * |
| 6321 | * This function is the main SLI4 device intialization PCI function. This |
| 6322 | * function is called by the HBA intialization code, HBA reset code and |
| 6323 | * HBA error attention handler code. Caller is not required to hold any |
| 6324 | * locks. |
| 6325 | **/ |
| 6326 | int |
| 6327 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6328 | { |
| 6329 | int rc; |
| 6330 | LPFC_MBOXQ_t *mboxq; |
| 6331 | struct lpfc_mqe *mqe; |
| 6332 | uint8_t *vpd; |
| 6333 | uint32_t vpd_size; |
| 6334 | uint32_t ftr_rsp = 0; |
| 6335 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6336 | struct lpfc_vport *vport = phba->pport; |
| 6337 | struct lpfc_dmabuf *mp; |
| 6338 | |
| 6339 | /* Perform a PCI function reset to start from clean */ |
| 6340 | rc = lpfc_pci_function_reset(phba); |
| 6341 | if (unlikely(rc)) |
| 6342 | return -ENODEV; |
| 6343 | |
| 6344 | /* Check the HBA Host Status Register for readyness */ |
| 6345 | rc = lpfc_sli4_post_status_check(phba); |
| 6346 | if (unlikely(rc)) |
| 6347 | return -ENODEV; |
| 6348 | else { |
| 6349 | spin_lock_irq(&phba->hbalock); |
| 6350 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6351 | spin_unlock_irq(&phba->hbalock); |
| 6352 | } |
| 6353 | |
| 6354 | /* |
| 6355 | * Allocate a single mailbox container for initializing the |
| 6356 | * port. |
| 6357 | */ |
| 6358 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6359 | if (!mboxq) |
| 6360 | return -ENOMEM; |
| 6361 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6362 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6363 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6364 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6365 | if (!vpd) { |
| 6366 | rc = -ENOMEM; |
| 6367 | goto out_free_mbox; |
| 6368 | } |
| 6369 | |
| 6370 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6371 | if (unlikely(rc)) { |
| 6372 | kfree(vpd); |
| 6373 | goto out_free_mbox; |
| 6374 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6375 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6376 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6377 | 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] | 6378 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6379 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6380 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6381 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6382 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6383 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6384 | |
| 6385 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6386 | LPFC_DCBX_CEE_MODE) |
| 6387 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6388 | else |
| 6389 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6390 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6391 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6392 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6393 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6394 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6395 | "0376 READ_REV Error. SLI Level %d " |
| 6396 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6397 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6398 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6399 | kfree(vpd); |
| 6400 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6401 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6402 | |
| 6403 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6404 | * Continue initialization with default values even if driver failed |
| 6405 | * to read FCoE param config regions, only read parameters if the |
| 6406 | * board is FCoE |
| 6407 | */ |
| 6408 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6409 | lpfc_sli4_read_fcoe_params(phba)) |
| 6410 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6411 | "2570 Failed to read FCoE parameters\n"); |
| 6412 | |
| 6413 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6414 | * Retrieve sli4 device physical port name, failure of doing it |
| 6415 | * is considered as non-fatal. |
| 6416 | */ |
| 6417 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6418 | if (!rc) |
| 6419 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6420 | "3080 Successful retrieving SLI4 device " |
| 6421 | "physical port name: %s.\n", phba->Port); |
| 6422 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6423 | /* |
| 6424 | * Evaluate the read rev and vpd data. Populate the driver |
| 6425 | * state with the results. If this routine fails, the failure |
| 6426 | * is not fatal as the driver will use generic values. |
| 6427 | */ |
| 6428 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6429 | if (unlikely(!rc)) { |
| 6430 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6431 | "0377 Error %d parsing vpd. " |
| 6432 | "Using defaults.\n", rc); |
| 6433 | rc = 0; |
| 6434 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6435 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6436 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6437 | /* Save information as VPD data */ |
| 6438 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6439 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6440 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6441 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6442 | &mqe->un.read_rev); |
| 6443 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6444 | &mqe->un.read_rev); |
| 6445 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6446 | &mqe->un.read_rev); |
| 6447 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6448 | &mqe->un.read_rev); |
| 6449 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6450 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6451 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6452 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6453 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6454 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6455 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6456 | "(%d):0380 READ_REV Status x%x " |
| 6457 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6458 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6459 | bf_get(lpfc_mqe_status, mqe), |
| 6460 | phba->vpd.rev.opFwName, |
| 6461 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6462 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6463 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6464 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6465 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6466 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6467 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6468 | "3362 LUN queue depth changed from %d to %d\n", |
| 6469 | phba->pport->cfg_lun_queue_depth, rc); |
| 6470 | phba->pport->cfg_lun_queue_depth = rc; |
| 6471 | } |
| 6472 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6473 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6474 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6475 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6476 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6477 | if (rc == MBX_SUCCESS) { |
| 6478 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6479 | /* Set 1Sec interval to detect UE */ |
| 6480 | phba->eratt_poll_interval = 1; |
| 6481 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6482 | lpfc_mbx_set_feature_UESR, |
| 6483 | &mboxq->u.mqe.un.set_feature); |
| 6484 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6485 | lpfc_mbx_set_feature_UERP, |
| 6486 | &mboxq->u.mqe.un.set_feature); |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6491 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6492 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6493 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6494 | if (rc != MBX_SUCCESS) |
| 6495 | phba->mds_diags_support = 0; |
| 6496 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6497 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6498 | /* |
| 6499 | * Discover the port's supported feature set and match it against the |
| 6500 | * hosts requests. |
| 6501 | */ |
| 6502 | lpfc_request_features(phba, mboxq); |
| 6503 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6504 | if (unlikely(rc)) { |
| 6505 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6506 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6507 | } |
| 6508 | |
| 6509 | /* |
| 6510 | * The port must support FCP initiator mode as this is the |
| 6511 | * only mode running in the host. |
| 6512 | */ |
| 6513 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6514 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6515 | "0378 No support for fcpi mode.\n"); |
| 6516 | ftr_rsp++; |
| 6517 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6518 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6519 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6520 | else |
| 6521 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6522 | /* |
| 6523 | * If the port cannot support the host's requested features |
| 6524 | * then turn off the global config parameters to disable the |
| 6525 | * feature in the driver. This is not a fatal error. |
| 6526 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6527 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6528 | if (phba->cfg_enable_bg) { |
| 6529 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6530 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6531 | else |
| 6532 | ftr_rsp++; |
| 6533 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6534 | |
| 6535 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6536 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6537 | ftr_rsp++; |
| 6538 | |
| 6539 | if (ftr_rsp) { |
| 6540 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6541 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6542 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6543 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6544 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6545 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6546 | phba->cfg_enable_bg = 0; |
| 6547 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6548 | phba->cfg_enable_npiv = 0; |
| 6549 | } |
| 6550 | |
| 6551 | /* These SLI3 features are assumed in SLI4 */ |
| 6552 | spin_lock_irq(&phba->hbalock); |
| 6553 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6554 | spin_unlock_irq(&phba->hbalock); |
| 6555 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6556 | /* |
| 6557 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6558 | * calls depends on these resources to complete port setup. |
| 6559 | */ |
| 6560 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6561 | if (rc) { |
| 6562 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6563 | "2920 Failed to alloc Resource IDs " |
| 6564 | "rc = x%x\n", rc); |
| 6565 | goto out_free_mbox; |
| 6566 | } |
| 6567 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6568 | lpfc_set_host_data(phba, mboxq); |
| 6569 | |
| 6570 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6571 | if (rc) { |
| 6572 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6573 | "2134 Failed to set host os driver version %x", |
| 6574 | rc); |
| 6575 | } |
| 6576 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6577 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6578 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6579 | if (rc) { |
| 6580 | phba->link_state = LPFC_HBA_ERROR; |
| 6581 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6582 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6583 | } |
| 6584 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6585 | mboxq->vport = vport; |
| 6586 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6587 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6588 | if (rc == MBX_SUCCESS) { |
| 6589 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6590 | rc = 0; |
| 6591 | } |
| 6592 | |
| 6593 | /* |
| 6594 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6595 | * it to the mbuf pool. |
| 6596 | */ |
| 6597 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6598 | kfree(mp); |
| 6599 | mboxq->context1 = NULL; |
| 6600 | if (unlikely(rc)) { |
| 6601 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6602 | "0382 READ_SPARAM command failed " |
| 6603 | "status %d, mbxStatus x%x\n", |
| 6604 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6605 | phba->link_state = LPFC_HBA_ERROR; |
| 6606 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6607 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6608 | } |
| 6609 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6610 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6611 | |
| 6612 | /* Update the fc_host data structures with new wwn. */ |
| 6613 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6614 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6615 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6616 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6617 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6618 | if (unlikely(rc)) { |
| 6619 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6620 | "1400 Failed to update xri-sgl size and " |
| 6621 | "mapping: %d\n", rc); |
| 6622 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6623 | } |
| 6624 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6625 | /* register the els sgl pool to the port */ |
| 6626 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6627 | if (unlikely(rc)) { |
| 6628 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6629 | "0582 Error %d during els sgl post " |
| 6630 | "operation\n", rc); |
| 6631 | rc = -ENODEV; |
| 6632 | goto out_free_mbox; |
| 6633 | } |
| 6634 | |
| 6635 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6636 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6637 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6638 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6639 | "0383 Error %d during scsi sgl post " |
| 6640 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6641 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6642 | /* A pci function reset will repost them */ |
| 6643 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6644 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | /* Post the rpi header region to the device. */ |
| 6648 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6649 | if (unlikely(rc)) { |
| 6650 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6651 | "0393 Error %d during rpi post operation\n", |
| 6652 | rc); |
| 6653 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6654 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6655 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6656 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6657 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6658 | /* Create all the SLI4 queues */ |
| 6659 | rc = lpfc_sli4_queue_create(phba); |
| 6660 | if (rc) { |
| 6661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6662 | "3089 Failed to allocate queues\n"); |
| 6663 | rc = -ENODEV; |
| 6664 | goto out_stop_timers; |
| 6665 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6666 | /* Set up all the queues to the device */ |
| 6667 | rc = lpfc_sli4_queue_setup(phba); |
| 6668 | if (unlikely(rc)) { |
| 6669 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6670 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6671 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | /* Arm the CQs and then EQs on device */ |
| 6675 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6676 | |
| 6677 | /* Indicate device interrupt mode */ |
| 6678 | phba->sli4_hba.intr_enable = 1; |
| 6679 | |
| 6680 | /* Allow asynchronous mailbox command to go through */ |
| 6681 | spin_lock_irq(&phba->hbalock); |
| 6682 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6683 | spin_unlock_irq(&phba->hbalock); |
| 6684 | |
| 6685 | /* Post receive buffers to the device */ |
| 6686 | lpfc_sli4_rb_setup(phba); |
| 6687 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6688 | /* Reset HBA FCF states after HBA reset */ |
| 6689 | phba->fcf.fcf_flag = 0; |
| 6690 | phba->fcf.current_rec.flag = 0; |
| 6691 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6692 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6693 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6694 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6695 | |
| 6696 | /* Start heart beat timer */ |
| 6697 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6698 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6699 | phba->hb_outstanding = 0; |
| 6700 | phba->last_completion_time = jiffies; |
| 6701 | |
| 6702 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6703 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6704 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6705 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6706 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6707 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6708 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6709 | if (!rc) { |
| 6710 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6711 | "2829 This device supports " |
| 6712 | "Advanced Error Reporting (AER)\n"); |
| 6713 | spin_lock_irq(&phba->hbalock); |
| 6714 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6715 | spin_unlock_irq(&phba->hbalock); |
| 6716 | } else { |
| 6717 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6718 | "2830 This device does not support " |
| 6719 | "Advanced Error Reporting (AER)\n"); |
| 6720 | phba->cfg_aer_support = 0; |
| 6721 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6722 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6723 | } |
| 6724 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6725 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6726 | /* |
| 6727 | * The FC Port needs to register FCFI (index 0) |
| 6728 | */ |
| 6729 | lpfc_reg_fcfi(phba, mboxq); |
| 6730 | mboxq->vport = phba->pport; |
| 6731 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6732 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6733 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6734 | rc = 0; |
| 6735 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6736 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6737 | |
| 6738 | /* Check if the port is configured to be disabled */ |
| 6739 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6740 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6741 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6742 | /* |
| 6743 | * The port is ready, set the host's link state to LINK_DOWN |
| 6744 | * in preparation for link interrupts. |
| 6745 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6746 | spin_lock_irq(&phba->hbalock); |
| 6747 | phba->link_state = LPFC_LINK_DOWN; |
| 6748 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6749 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6750 | (phba->hba_flag & LINK_DISABLED)) { |
| 6751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6752 | "3103 Adapter Link is disabled.\n"); |
| 6753 | lpfc_down_link(phba, mboxq); |
| 6754 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6755 | if (rc != MBX_SUCCESS) { |
| 6756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6757 | "3104 Adapter failed to issue " |
| 6758 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6759 | goto out_unset_queue; |
| 6760 | } |
| 6761 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6762 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6763 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6764 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6765 | if (rc) |
| 6766 | goto out_unset_queue; |
| 6767 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6768 | } |
| 6769 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6770 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6771 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6772 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6773 | lpfc_sli4_queue_unset(phba); |
| 6774 | out_destroy_queue: |
| 6775 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6776 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6777 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6778 | out_free_mbox: |
| 6779 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6780 | return rc; |
| 6781 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6782 | |
| 6783 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6784 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6785 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6786 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6787 | * This is the callback function for mailbox timer. The mailbox |
| 6788 | * timer is armed when a new mailbox command is issued and the timer |
| 6789 | * is deleted when the mailbox complete. The function is called by |
| 6790 | * the kernel timer code when a mailbox does not complete within |
| 6791 | * expected time. This function wakes up the worker thread to |
| 6792 | * process the mailbox timeout and returns. All the processing is |
| 6793 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6794 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6795 | void |
| 6796 | lpfc_mbox_timeout(unsigned long ptr) |
| 6797 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6798 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6799 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6800 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6801 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6802 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6803 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6804 | if (!tmo_posted) |
| 6805 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6806 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6807 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6808 | if (!tmo_posted) |
| 6809 | lpfc_worker_wake_up(phba); |
| 6810 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6811 | } |
| 6812 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6813 | /** |
| 6814 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 6815 | * are pending |
| 6816 | * @phba: Pointer to HBA context object. |
| 6817 | * |
| 6818 | * This function checks if any mailbox completions are present on the mailbox |
| 6819 | * completion queue. |
| 6820 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 6821 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6822 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 6823 | { |
| 6824 | |
| 6825 | uint32_t idx; |
| 6826 | struct lpfc_queue *mcq; |
| 6827 | struct lpfc_mcqe *mcqe; |
| 6828 | bool pending_completions = false; |
| 6829 | |
| 6830 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6831 | return false; |
| 6832 | |
| 6833 | /* Check for completions on mailbox completion queue */ |
| 6834 | |
| 6835 | mcq = phba->sli4_hba.mbx_cq; |
| 6836 | idx = mcq->hba_index; |
| 6837 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 6838 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 6839 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 6840 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 6841 | pending_completions = true; |
| 6842 | break; |
| 6843 | } |
| 6844 | idx = (idx + 1) % mcq->entry_count; |
| 6845 | if (mcq->hba_index == idx) |
| 6846 | break; |
| 6847 | } |
| 6848 | return pending_completions; |
| 6849 | |
| 6850 | } |
| 6851 | |
| 6852 | /** |
| 6853 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 6854 | * that were missed. |
| 6855 | * @phba: Pointer to HBA context object. |
| 6856 | * |
| 6857 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 6858 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 6859 | * checks to see if mbox completions are on the mailbox completion queue |
| 6860 | * and will process all the completions associated with the eq for the |
| 6861 | * mailbox completion queue. |
| 6862 | **/ |
| 6863 | bool |
| 6864 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 6865 | { |
| 6866 | |
| 6867 | uint32_t eqidx; |
| 6868 | struct lpfc_queue *fpeq = NULL; |
| 6869 | struct lpfc_eqe *eqe; |
| 6870 | bool mbox_pending; |
| 6871 | |
| 6872 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6873 | return false; |
| 6874 | |
| 6875 | /* Find the eq associated with the mcq */ |
| 6876 | |
| 6877 | if (phba->sli4_hba.hba_eq) |
| 6878 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) |
| 6879 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 6880 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 6881 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 6882 | break; |
| 6883 | } |
| 6884 | if (!fpeq) |
| 6885 | return false; |
| 6886 | |
| 6887 | /* Turn off interrupts from this EQ */ |
| 6888 | |
| 6889 | lpfc_sli4_eq_clr_intr(fpeq); |
| 6890 | |
| 6891 | /* Check to see if a mbox completion is pending */ |
| 6892 | |
| 6893 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 6894 | |
| 6895 | /* |
| 6896 | * If a mbox completion is pending, process all the events on EQ |
| 6897 | * associated with the mbox completion queue (this could include |
| 6898 | * mailbox commands, async events, els commands, receive queue data |
| 6899 | * and fcp commands) |
| 6900 | */ |
| 6901 | |
| 6902 | if (mbox_pending) |
| 6903 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 6904 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 6905 | fpeq->EQ_processed++; |
| 6906 | } |
| 6907 | |
| 6908 | /* Always clear and re-arm the EQ */ |
| 6909 | |
| 6910 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 6911 | |
| 6912 | return mbox_pending; |
| 6913 | |
| 6914 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6915 | |
| 6916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6917 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6918 | * @phba: Pointer to HBA context object. |
| 6919 | * |
| 6920 | * This function is called from worker thread when a mailbox command times out. |
| 6921 | * The caller is not required to hold any locks. This function will reset the |
| 6922 | * HBA and recover all the pending commands. |
| 6923 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6924 | void |
| 6925 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6926 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6927 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6928 | MAILBOX_t *mb = NULL; |
| 6929 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6930 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6931 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6932 | /* If the mailbox completed, process the completion and return */ |
| 6933 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 6934 | return; |
| 6935 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6936 | if (pmbox != NULL) |
| 6937 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6938 | /* Check the pmbox pointer first. There is a race condition |
| 6939 | * between the mbox timeout handler getting executed in the |
| 6940 | * worklist and the mailbox actually completing. When this |
| 6941 | * race condition occurs, the mbox_active will be NULL. |
| 6942 | */ |
| 6943 | spin_lock_irq(&phba->hbalock); |
| 6944 | if (pmbox == NULL) { |
| 6945 | lpfc_printf_log(phba, KERN_WARNING, |
| 6946 | LOG_MBOX | LOG_SLI, |
| 6947 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6948 | "exiting\n"); |
| 6949 | spin_unlock_irq(&phba->hbalock); |
| 6950 | return; |
| 6951 | } |
| 6952 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6953 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6954 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6955 | "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] | 6956 | mb->mbxCommand, |
| 6957 | phba->pport->port_state, |
| 6958 | phba->sli.sli_flag, |
| 6959 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6960 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6961 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6962 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6963 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6964 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6965 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6966 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6967 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6968 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6969 | spin_lock_irq(&phba->hbalock); |
| 6970 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6971 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6972 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6973 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 6974 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6975 | |
| 6976 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6977 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6978 | |
| 6979 | /* Reset the HBA device */ |
| 6980 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6981 | } |
| 6982 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6983 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6984 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6985 | * @phba: Pointer to HBA context object. |
| 6986 | * @pmbox: Pointer to mailbox object. |
| 6987 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6988 | * |
| 6989 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6990 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6991 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6992 | * The mailbox command can be submitted in polling mode, in which case |
| 6993 | * this function will wait in a polling loop for the completion of the |
| 6994 | * mailbox. |
| 6995 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6996 | * function will submit the command and returns immediately without waiting |
| 6997 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6998 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6999 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7000 | * mailbox is issued in polling mode and there is already a mailbox |
| 7001 | * pending, then the function will return an error. If the mailbox is issued |
| 7002 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7003 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7004 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7005 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7006 | * return codes the caller owns the mailbox command after the return of |
| 7007 | * the function. |
| 7008 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7009 | static int |
| 7010 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7011 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7012 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7013 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7014 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7015 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7016 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7017 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7018 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7019 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7020 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7021 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7022 | int processing_queue = 0; |
| 7023 | |
| 7024 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7025 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7026 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7027 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7028 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7029 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7030 | return MBX_SUCCESS; |
| 7031 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7032 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7033 | pmbox = lpfc_mbox_get(phba); |
| 7034 | if (!pmbox) { |
| 7035 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7036 | return MBX_SUCCESS; |
| 7037 | } |
| 7038 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7039 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7040 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7041 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7042 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7043 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7044 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7045 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7046 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7047 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7048 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7049 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7050 | } |
| 7051 | } |
| 7052 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7053 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7054 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7055 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7056 | goto out_not_finished; |
| 7057 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7058 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7059 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7060 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7061 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7062 | goto out_not_finished; |
| 7063 | } |
| 7064 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7065 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7066 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7067 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7068 | status = MBX_SUCCESS; |
| 7069 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7070 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7071 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7072 | |
| 7073 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7074 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7075 | "(%d):0311 Mailbox command x%x cannot " |
| 7076 | "issue Data: x%x x%x\n", |
| 7077 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7078 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7079 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7080 | } |
| 7081 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7082 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7083 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7084 | !(hc_copy & HC_MBINT_ENA)) { |
| 7085 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7086 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7087 | "(%d):2528 Mailbox command x%x cannot " |
| 7088 | "issue Data: x%x x%x\n", |
| 7089 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7090 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7091 | goto out_not_finished; |
| 7092 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7093 | } |
| 7094 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7095 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7096 | /* Polling for a mbox command when another one is already active |
| 7097 | * is not allowed in SLI. Also, the driver must have established |
| 7098 | * SLI2 mode to queue and process multiple mbox commands. |
| 7099 | */ |
| 7100 | |
| 7101 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7102 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7103 | |
| 7104 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7105 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7106 | "(%d):2529 Mailbox command x%x " |
| 7107 | "cannot issue Data: x%x x%x\n", |
| 7108 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7109 | pmbox->u.mb.mbxCommand, |
| 7110 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7111 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7112 | } |
| 7113 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7114 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7115 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7116 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7117 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7118 | "(%d):2530 Mailbox command x%x " |
| 7119 | "cannot issue Data: x%x x%x\n", |
| 7120 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7121 | pmbox->u.mb.mbxCommand, |
| 7122 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7123 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7124 | } |
| 7125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7126 | /* Another mailbox command is still being processed, queue this |
| 7127 | * command to be processed later. |
| 7128 | */ |
| 7129 | lpfc_mbox_put(phba, pmbox); |
| 7130 | |
| 7131 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7132 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7133 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7134 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7135 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7136 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7137 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7138 | |
| 7139 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7140 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7141 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7142 | if (pmbox->vport) { |
| 7143 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7144 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7145 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7146 | (uint32_t)mbx->mbxCommand, |
| 7147 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7148 | } |
| 7149 | else { |
| 7150 | lpfc_debugfs_disc_trc(phba->pport, |
| 7151 | LPFC_DISC_TRC_MBOX, |
| 7152 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7153 | (uint32_t)mbx->mbxCommand, |
| 7154 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7155 | } |
| 7156 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7157 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7158 | } |
| 7159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7161 | |
| 7162 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7163 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7164 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7165 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7166 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7167 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7168 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7169 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7170 | "(%d):2531 Mailbox command x%x " |
| 7171 | "cannot issue Data: x%x x%x\n", |
| 7172 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7173 | pmbox->u.mb.mbxCommand, |
| 7174 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7175 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7176 | } |
| 7177 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7178 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7179 | 1000); |
| 7180 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7184 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7185 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7186 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7187 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7188 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7189 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7190 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7191 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7192 | if (pmbox->vport) { |
| 7193 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7194 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7195 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7196 | (uint32_t)mbx->mbxCommand, |
| 7197 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7198 | } |
| 7199 | else { |
| 7200 | lpfc_debugfs_disc_trc(phba->pport, |
| 7201 | LPFC_DISC_TRC_MBOX, |
| 7202 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7203 | (uint32_t)mbx->mbxCommand, |
| 7204 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7205 | } |
| 7206 | } |
| 7207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7208 | psli->slistat.mbox_cmd++; |
| 7209 | evtctr = psli->slistat.mbox_event; |
| 7210 | |
| 7211 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7212 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7213 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7214 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7215 | /* Populate mbox extension offset word. */ |
| 7216 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7217 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7218 | = (uint8_t *)phba->mbox_ext |
| 7219 | - (uint8_t *)phba->mbox; |
| 7220 | } |
| 7221 | |
| 7222 | /* Copy the mailbox extension data */ |
| 7223 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7224 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7225 | (uint8_t *)phba->mbox_ext, |
| 7226 | pmbox->in_ext_byte_len); |
| 7227 | } |
| 7228 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7229 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7230 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7231 | /* Populate mbox extension offset word. */ |
| 7232 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7233 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7234 | = MAILBOX_HBA_EXT_OFFSET; |
| 7235 | |
| 7236 | /* Copy the mailbox extension data */ |
| 7237 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7238 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7239 | MAILBOX_HBA_EXT_OFFSET, |
| 7240 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7241 | |
| 7242 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7243 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7244 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7245 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7249 | word */ |
| 7250 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7251 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7252 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7253 | |
| 7254 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7255 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7256 | to_slim = phba->MBslimaddr; |
| 7257 | writel(ldata, to_slim); |
| 7258 | readl(to_slim); /* flush */ |
| 7259 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7260 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7261 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7262 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7267 | |
| 7268 | switch (flag) { |
| 7269 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7270 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7271 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7272 | /* Interrupt board to do it */ |
| 7273 | writel(CA_MBATT, phba->CAregaddr); |
| 7274 | readl(phba->CAregaddr); /* flush */ |
| 7275 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7276 | break; |
| 7277 | |
| 7278 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7279 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7280 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7281 | /* Interrupt board to do it */ |
| 7282 | writel(CA_MBATT, phba->CAregaddr); |
| 7283 | readl(phba->CAregaddr); /* flush */ |
| 7284 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7285 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7286 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7287 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7288 | word0 = le32_to_cpu(word0); |
| 7289 | } else { |
| 7290 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7291 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7292 | spin_unlock_irqrestore(&phba->hbalock, |
| 7293 | drvr_flag); |
| 7294 | goto out_not_finished; |
| 7295 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7296 | } |
| 7297 | |
| 7298 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7299 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7300 | spin_unlock_irqrestore(&phba->hbalock, |
| 7301 | drvr_flag); |
| 7302 | goto out_not_finished; |
| 7303 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7304 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7305 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7306 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7307 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7308 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7309 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7310 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7311 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7312 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7313 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7314 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7315 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | /* Check if we took a mbox interrupt while we were |
| 7319 | polling */ |
| 7320 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7321 | && (evtctr != psli->slistat.mbox_event)) |
| 7322 | break; |
| 7323 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7324 | if (i++ > 10) { |
| 7325 | spin_unlock_irqrestore(&phba->hbalock, |
| 7326 | drvr_flag); |
| 7327 | msleep(1); |
| 7328 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7329 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7330 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7331 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7332 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7333 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7334 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7335 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7336 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7337 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7338 | /* Check real SLIM for any errors */ |
| 7339 | slimword0 = readl(phba->MBslimaddr); |
| 7340 | slimmb = (MAILBOX_t *) & slimword0; |
| 7341 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7342 | && slimmb->mbxStatus) { |
| 7343 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7344 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7345 | word0 = slimword0; |
| 7346 | } |
| 7347 | } |
| 7348 | } else { |
| 7349 | /* First copy command data */ |
| 7350 | word0 = readl(phba->MBslimaddr); |
| 7351 | } |
| 7352 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7353 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7354 | spin_unlock_irqrestore(&phba->hbalock, |
| 7355 | drvr_flag); |
| 7356 | goto out_not_finished; |
| 7357 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7358 | } |
| 7359 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7360 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7361 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7362 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7363 | /* Copy the mailbox extension data */ |
| 7364 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7365 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7366 | pmbox->context2, |
| 7367 | pmbox->out_ext_byte_len); |
| 7368 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7369 | } else { |
| 7370 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7371 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7372 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7373 | /* Copy the mailbox extension data */ |
| 7374 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7375 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7376 | phba->MBslimaddr + |
| 7377 | MAILBOX_HBA_EXT_OFFSET, |
| 7378 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7379 | } |
| 7380 | } |
| 7381 | |
| 7382 | writel(HA_MBATT, phba->HAregaddr); |
| 7383 | readl(phba->HAregaddr); /* flush */ |
| 7384 | |
| 7385 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7386 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7387 | } |
| 7388 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7389 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7390 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7391 | |
| 7392 | out_not_finished: |
| 7393 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7394 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7395 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7396 | } |
| 7397 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7398 | } |
| 7399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7400 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7401 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7402 | * @phba: Pointer to HBA context object. |
| 7403 | * |
| 7404 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7405 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7406 | * possible outstanding mailbox command before return. |
| 7407 | * |
| 7408 | * Returns: |
| 7409 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7410 | * the outstanding mailbox command timed out. |
| 7411 | **/ |
| 7412 | static int |
| 7413 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7414 | { |
| 7415 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7416 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7417 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7418 | |
| 7419 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7420 | spin_lock_irq(&phba->hbalock); |
| 7421 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7422 | /* Determine how long we might wait for the active mailbox |
| 7423 | * command to be gracefully completed by firmware. |
| 7424 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7425 | if (phba->sli.mbox_active) |
| 7426 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7427 | phba->sli.mbox_active) * |
| 7428 | 1000) + jiffies; |
| 7429 | spin_unlock_irq(&phba->hbalock); |
| 7430 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7431 | /* Make sure the mailbox is really active */ |
| 7432 | if (timeout) |
| 7433 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7434 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7435 | /* Wait for the outstnading mailbox command to complete */ |
| 7436 | while (phba->sli.mbox_active) { |
| 7437 | /* Check active mailbox complete status every 2ms */ |
| 7438 | msleep(2); |
| 7439 | if (time_after(jiffies, timeout)) { |
| 7440 | /* Timeout, marked the outstanding cmd not complete */ |
| 7441 | rc = 1; |
| 7442 | break; |
| 7443 | } |
| 7444 | } |
| 7445 | |
| 7446 | /* Can not cleanly block async mailbox command, fails it */ |
| 7447 | if (rc) { |
| 7448 | spin_lock_irq(&phba->hbalock); |
| 7449 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7450 | spin_unlock_irq(&phba->hbalock); |
| 7451 | } |
| 7452 | return rc; |
| 7453 | } |
| 7454 | |
| 7455 | /** |
| 7456 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7457 | * @phba: Pointer to HBA context object. |
| 7458 | * |
| 7459 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7460 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7461 | * that there is no outstanding mailbox command before resuming posting |
| 7462 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7463 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7464 | * mailbox command posting. |
| 7465 | **/ |
| 7466 | static void |
| 7467 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7468 | { |
| 7469 | struct lpfc_sli *psli = &phba->sli; |
| 7470 | |
| 7471 | spin_lock_irq(&phba->hbalock); |
| 7472 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7473 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7474 | spin_unlock_irq(&phba->hbalock); |
| 7475 | return; |
| 7476 | } |
| 7477 | |
| 7478 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7479 | * successful or timeout, after timing-out the outstanding mailbox |
| 7480 | * command shall always be removed, so just unblock posting async |
| 7481 | * mailbox command and resume |
| 7482 | */ |
| 7483 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7484 | spin_unlock_irq(&phba->hbalock); |
| 7485 | |
| 7486 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7487 | lpfc_worker_wake_up(phba); |
| 7488 | } |
| 7489 | |
| 7490 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7491 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7492 | * @phba: Pointer to HBA context object. |
| 7493 | * @mboxq: Pointer to mailbox object. |
| 7494 | * |
| 7495 | * The function waits for the bootstrap mailbox register ready bit from |
| 7496 | * port for twice the regular mailbox command timeout value. |
| 7497 | * |
| 7498 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7499 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7500 | **/ |
| 7501 | static int |
| 7502 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7503 | { |
| 7504 | uint32_t db_ready; |
| 7505 | unsigned long timeout; |
| 7506 | struct lpfc_register bmbx_reg; |
| 7507 | |
| 7508 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7509 | * 1000) + jiffies; |
| 7510 | |
| 7511 | do { |
| 7512 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7513 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7514 | if (!db_ready) |
| 7515 | msleep(2); |
| 7516 | |
| 7517 | if (time_after(jiffies, timeout)) |
| 7518 | return MBXERR_ERROR; |
| 7519 | } while (!db_ready); |
| 7520 | |
| 7521 | return 0; |
| 7522 | } |
| 7523 | |
| 7524 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7525 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7526 | * @phba: Pointer to HBA context object. |
| 7527 | * @mboxq: Pointer to mailbox object. |
| 7528 | * |
| 7529 | * The function posts a mailbox to the port. The mailbox is expected |
| 7530 | * to be comletely filled in and ready for the port to operate on it. |
| 7531 | * This routine executes a synchronous completion operation on the |
| 7532 | * mailbox by polling for its completion. |
| 7533 | * |
| 7534 | * The caller must not be holding any locks when calling this routine. |
| 7535 | * |
| 7536 | * Returns: |
| 7537 | * MBX_SUCCESS - mailbox posted successfully |
| 7538 | * Any of the MBX error values. |
| 7539 | **/ |
| 7540 | static int |
| 7541 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7542 | { |
| 7543 | int rc = MBX_SUCCESS; |
| 7544 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7545 | uint32_t mcqe_status; |
| 7546 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7547 | struct lpfc_sli *psli = &phba->sli; |
| 7548 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7549 | struct lpfc_bmbx_create *mbox_rgn; |
| 7550 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7551 | |
| 7552 | /* |
| 7553 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7554 | * at a time and there is no queueing provided. |
| 7555 | */ |
| 7556 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7557 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7558 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7559 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7560 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7561 | "cannot issue Data: x%x x%x\n", |
| 7562 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7563 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7564 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7565 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7566 | psli->sli_flag, MBX_POLL); |
| 7567 | return MBXERR_ERROR; |
| 7568 | } |
| 7569 | /* The server grabs the token and owns it until release */ |
| 7570 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7571 | phba->sli.mbox_active = mboxq; |
| 7572 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7573 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7574 | /* wait for bootstrap mbox register for readyness */ |
| 7575 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7576 | if (rc) |
| 7577 | goto exit; |
| 7578 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7579 | /* |
| 7580 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7581 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7582 | * the bmbx mailbox region. |
| 7583 | */ |
| 7584 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7585 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7586 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7587 | sizeof(struct lpfc_mqe)); |
| 7588 | |
| 7589 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7590 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7591 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7592 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7593 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7594 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7595 | if (rc) |
| 7596 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7597 | |
| 7598 | /* Post the low mailbox dma address to the port. */ |
| 7599 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7600 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7601 | /* wait for bootstrap mbox register for low address write done */ |
| 7602 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7603 | if (rc) |
| 7604 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7605 | |
| 7606 | /* |
| 7607 | * Read the CQ to ensure the mailbox has completed. |
| 7608 | * If so, update the mailbox status so that the upper layers |
| 7609 | * can complete the request normally. |
| 7610 | */ |
| 7611 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7612 | sizeof(struct lpfc_mqe)); |
| 7613 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7614 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7615 | sizeof(struct lpfc_mcqe)); |
| 7616 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7617 | /* |
| 7618 | * When the CQE status indicates a failure and the mailbox status |
| 7619 | * indicates success then copy the CQE status into the mailbox status |
| 7620 | * (and prefix it with x4000). |
| 7621 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7622 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7623 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7624 | bf_set(lpfc_mqe_status, mb, |
| 7625 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7626 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7627 | } else |
| 7628 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7629 | |
| 7630 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7631 | "(%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] | 7632 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7633 | " 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] | 7634 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7635 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7636 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7637 | bf_get(lpfc_mqe_status, mb), |
| 7638 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7639 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7640 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7641 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7642 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7643 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7644 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7645 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7646 | mboxq->mcqe.trailer); |
| 7647 | exit: |
| 7648 | /* We are holding the token, no needed for lock when release */ |
| 7649 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7650 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7651 | phba->sli.mbox_active = NULL; |
| 7652 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7653 | return rc; |
| 7654 | } |
| 7655 | |
| 7656 | /** |
| 7657 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7658 | * @phba: Pointer to HBA context object. |
| 7659 | * @pmbox: Pointer to mailbox object. |
| 7660 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7661 | * |
| 7662 | * This function is called by discovery code and HBA management code to submit |
| 7663 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7664 | * |
| 7665 | * Return codes the caller owns the mailbox command after the return of the |
| 7666 | * function. |
| 7667 | **/ |
| 7668 | static int |
| 7669 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7670 | uint32_t flag) |
| 7671 | { |
| 7672 | struct lpfc_sli *psli = &phba->sli; |
| 7673 | unsigned long iflags; |
| 7674 | int rc; |
| 7675 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7676 | /* dump from issue mailbox command if setup */ |
| 7677 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7678 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7679 | rc = lpfc_mbox_dev_check(phba); |
| 7680 | if (unlikely(rc)) { |
| 7681 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7682 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7683 | "cannot issue Data: x%x x%x\n", |
| 7684 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7685 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7686 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7687 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7688 | psli->sli_flag, flag); |
| 7689 | goto out_not_finished; |
| 7690 | } |
| 7691 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7692 | /* Detect polling mode and jump to a handler */ |
| 7693 | if (!phba->sli4_hba.intr_enable) { |
| 7694 | if (flag == MBX_POLL) |
| 7695 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7696 | else |
| 7697 | rc = -EIO; |
| 7698 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7699 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7700 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7701 | "(x%x/x%x) failure: " |
| 7702 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7703 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7704 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7705 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7706 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7707 | mboxq), |
| 7708 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7709 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7710 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7711 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7712 | bf_get(lpfc_mcqe_ext_status, |
| 7713 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7714 | psli->sli_flag, flag); |
| 7715 | return rc; |
| 7716 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7717 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7718 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7719 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7720 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7721 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7722 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7723 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7724 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7725 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7726 | /* Try to block the asynchronous mailbox posting */ |
| 7727 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7728 | if (!rc) { |
| 7729 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7730 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7731 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7732 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7733 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7734 | "(%d):2597 Sync Mailbox command " |
| 7735 | "x%x (x%x/x%x) failure: " |
| 7736 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7737 | "Data: x%x x%x\n,", |
| 7738 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7739 | mboxq->u.mb.mbxCommand, |
| 7740 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7741 | mboxq), |
| 7742 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7743 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7744 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7745 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7746 | bf_get(lpfc_mcqe_ext_status, |
| 7747 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7748 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7749 | /* Unblock the async mailbox posting afterward */ |
| 7750 | lpfc_sli4_async_mbox_unblock(phba); |
| 7751 | } |
| 7752 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7753 | } |
| 7754 | |
| 7755 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7756 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7757 | if (rc) { |
| 7758 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7759 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7760 | "cannot issue Data: x%x x%x\n", |
| 7761 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7762 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7763 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7764 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7765 | psli->sli_flag, flag); |
| 7766 | goto out_not_finished; |
| 7767 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7768 | |
| 7769 | /* Put the mailbox command to the driver internal FIFO */ |
| 7770 | psli->slistat.mbox_busy++; |
| 7771 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7772 | lpfc_mbox_put(phba, mboxq); |
| 7773 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7774 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7775 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7776 | "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] | 7777 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7778 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7779 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7780 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7781 | phba->pport->port_state, |
| 7782 | psli->sli_flag, MBX_NOWAIT); |
| 7783 | /* Wake up worker thread to transport mailbox command from head */ |
| 7784 | lpfc_worker_wake_up(phba); |
| 7785 | |
| 7786 | return MBX_BUSY; |
| 7787 | |
| 7788 | out_not_finished: |
| 7789 | return MBX_NOT_FINISHED; |
| 7790 | } |
| 7791 | |
| 7792 | /** |
| 7793 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7794 | * @phba: Pointer to HBA context object. |
| 7795 | * |
| 7796 | * This function is called by worker thread to send a mailbox command to |
| 7797 | * SLI4 HBA firmware. |
| 7798 | * |
| 7799 | **/ |
| 7800 | int |
| 7801 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7802 | { |
| 7803 | struct lpfc_sli *psli = &phba->sli; |
| 7804 | LPFC_MBOXQ_t *mboxq; |
| 7805 | int rc = MBX_SUCCESS; |
| 7806 | unsigned long iflags; |
| 7807 | struct lpfc_mqe *mqe; |
| 7808 | uint32_t mbx_cmnd; |
| 7809 | |
| 7810 | /* Check interrupt mode before post async mailbox command */ |
| 7811 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7812 | return MBX_NOT_FINISHED; |
| 7813 | |
| 7814 | /* Check for mailbox command service token */ |
| 7815 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7816 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7817 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7818 | return MBX_NOT_FINISHED; |
| 7819 | } |
| 7820 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7821 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7822 | return MBX_NOT_FINISHED; |
| 7823 | } |
| 7824 | if (unlikely(phba->sli.mbox_active)) { |
| 7825 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7826 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7827 | "0384 There is pending active mailbox cmd\n"); |
| 7828 | return MBX_NOT_FINISHED; |
| 7829 | } |
| 7830 | /* Take the mailbox command service token */ |
| 7831 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7832 | |
| 7833 | /* Get the next mailbox command from head of queue */ |
| 7834 | mboxq = lpfc_mbox_get(phba); |
| 7835 | |
| 7836 | /* If no more mailbox command waiting for post, we're done */ |
| 7837 | if (!mboxq) { |
| 7838 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7839 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7840 | return MBX_SUCCESS; |
| 7841 | } |
| 7842 | phba->sli.mbox_active = mboxq; |
| 7843 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7844 | |
| 7845 | /* Check device readiness for posting mailbox command */ |
| 7846 | rc = lpfc_mbox_dev_check(phba); |
| 7847 | if (unlikely(rc)) |
| 7848 | /* Driver clean routine will clean up pending mailbox */ |
| 7849 | goto out_not_finished; |
| 7850 | |
| 7851 | /* Prepare the mbox command to be posted */ |
| 7852 | mqe = &mboxq->u.mqe; |
| 7853 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7854 | |
| 7855 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7856 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7857 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7858 | |
| 7859 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7860 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7861 | "x%x x%x\n", |
| 7862 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7863 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7864 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7865 | phba->pport->port_state, psli->sli_flag); |
| 7866 | |
| 7867 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7868 | if (mboxq->vport) { |
| 7869 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7870 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7871 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7872 | mbx_cmnd, mqe->un.mb_words[0], |
| 7873 | mqe->un.mb_words[1]); |
| 7874 | } else { |
| 7875 | lpfc_debugfs_disc_trc(phba->pport, |
| 7876 | LPFC_DISC_TRC_MBOX, |
| 7877 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7878 | mbx_cmnd, mqe->un.mb_words[0], |
| 7879 | mqe->un.mb_words[1]); |
| 7880 | } |
| 7881 | } |
| 7882 | psli->slistat.mbox_cmd++; |
| 7883 | |
| 7884 | /* Post the mailbox command to the port */ |
| 7885 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7886 | if (rc != MBX_SUCCESS) { |
| 7887 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7888 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7889 | "cannot issue Data: x%x x%x\n", |
| 7890 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7891 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7892 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7893 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7894 | psli->sli_flag, MBX_NOWAIT); |
| 7895 | goto out_not_finished; |
| 7896 | } |
| 7897 | |
| 7898 | return rc; |
| 7899 | |
| 7900 | out_not_finished: |
| 7901 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7902 | if (phba->sli.mbox_active) { |
| 7903 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7904 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7905 | /* Release the token */ |
| 7906 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7907 | phba->sli.mbox_active = NULL; |
| 7908 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7910 | |
| 7911 | return MBX_NOT_FINISHED; |
| 7912 | } |
| 7913 | |
| 7914 | /** |
| 7915 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7916 | * @phba: Pointer to HBA context object. |
| 7917 | * @pmbox: Pointer to mailbox object. |
| 7918 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7919 | * |
| 7920 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7921 | * the API jump table function pointer from the lpfc_hba struct. |
| 7922 | * |
| 7923 | * Return codes the caller owns the mailbox command after the return of the |
| 7924 | * function. |
| 7925 | **/ |
| 7926 | int |
| 7927 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7928 | { |
| 7929 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7930 | } |
| 7931 | |
| 7932 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7933 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7934 | * @phba: The hba struct for which this call is being executed. |
| 7935 | * @dev_grp: The HBA PCI-Device group number. |
| 7936 | * |
| 7937 | * This routine sets up the mbox interface API function jump table in @phba |
| 7938 | * struct. |
| 7939 | * Returns: 0 - success, -ENODEV - failure. |
| 7940 | **/ |
| 7941 | int |
| 7942 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7943 | { |
| 7944 | |
| 7945 | switch (dev_grp) { |
| 7946 | case LPFC_PCI_DEV_LP: |
| 7947 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7948 | phba->lpfc_sli_handle_slow_ring_event = |
| 7949 | lpfc_sli_handle_slow_ring_event_s3; |
| 7950 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7951 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7952 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7953 | break; |
| 7954 | case LPFC_PCI_DEV_OC: |
| 7955 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7956 | phba->lpfc_sli_handle_slow_ring_event = |
| 7957 | lpfc_sli_handle_slow_ring_event_s4; |
| 7958 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7959 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7960 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7961 | break; |
| 7962 | default: |
| 7963 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7964 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7965 | dev_grp); |
| 7966 | return -ENODEV; |
| 7967 | break; |
| 7968 | } |
| 7969 | return 0; |
| 7970 | } |
| 7971 | |
| 7972 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7973 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7974 | * @phba: Pointer to HBA context object. |
| 7975 | * @pring: Pointer to driver SLI ring object. |
| 7976 | * @piocb: Pointer to address of newly added command iocb. |
| 7977 | * |
| 7978 | * This function is called with hbalock held to add a command |
| 7979 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7980 | * to the ring. |
| 7981 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7982 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7983 | __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] | 7984 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7985 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7986 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7987 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7988 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7989 | } |
| 7990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7991 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7992 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7993 | * @phba: Pointer to HBA context object. |
| 7994 | * @pring: Pointer to driver SLI ring object. |
| 7995 | * @piocb: Pointer to address of newly added command iocb. |
| 7996 | * |
| 7997 | * This function is called with hbalock held before a new |
| 7998 | * iocb is submitted to the firmware. This function checks |
| 7999 | * txq to flush the iocbs in txq to Firmware before |
| 8000 | * submitting new iocbs to the Firmware. |
| 8001 | * If there are iocbs in the txq which need to be submitted |
| 8002 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8003 | * of the txq after dequeuing it from txq. |
| 8004 | * If there is no iocb in the txq then the function will return |
| 8005 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8006 | * *piocb to find if there are more commands in the txq. |
| 8007 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8008 | static struct lpfc_iocbq * |
| 8009 | 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] | 8010 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8011 | { |
| 8012 | struct lpfc_iocbq * nextiocb; |
| 8013 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8014 | lockdep_assert_held(&phba->hbalock); |
| 8015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8016 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 8017 | if (!nextiocb) { |
| 8018 | nextiocb = *piocb; |
| 8019 | *piocb = NULL; |
| 8020 | } |
| 8021 | |
| 8022 | return nextiocb; |
| 8023 | } |
| 8024 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8025 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8026 | * __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] | 8027 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8028 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8029 | * @piocb: Pointer to command iocb. |
| 8030 | * @flag: Flag indicating if this command can be put into txq. |
| 8031 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8032 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8033 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8034 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8035 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8036 | * this function allows only iocbs for posting buffers. This function finds |
| 8037 | * next available slot in the command ring and posts the command to the |
| 8038 | * available slot and writes the port attention register to request HBA start |
| 8039 | * processing new iocb. If there is no slot available in the ring and |
| 8040 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8041 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8042 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8043 | * This function is called with hbalock held. The function will return success |
| 8044 | * after it successfully submit the iocb to firmware or after adding to the |
| 8045 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8046 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8047 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8048 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8049 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8050 | { |
| 8051 | struct lpfc_iocbq *nextiocb; |
| 8052 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8053 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8054 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8055 | lockdep_assert_held(&phba->hbalock); |
| 8056 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8057 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8058 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8059 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8060 | lpfc_printf_log(phba, KERN_ERR, |
| 8061 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8062 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8063 | piocb->iocb.ulpCommand); |
| 8064 | dump_stack(); |
| 8065 | return IOCB_ERROR; |
| 8066 | } |
| 8067 | |
| 8068 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8069 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8070 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8071 | return IOCB_ERROR; |
| 8072 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8073 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8074 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8075 | return IOCB_ERROR; |
| 8076 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8077 | /* |
| 8078 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8079 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8080 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8081 | return IOCB_ERROR; |
| 8082 | |
| 8083 | /* |
| 8084 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8085 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8086 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8087 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8088 | goto iocb_busy; |
| 8089 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8090 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8091 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8092 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8093 | * can be issued if the link is not up. |
| 8094 | */ |
| 8095 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8096 | case CMD_GEN_REQUEST64_CR: |
| 8097 | case CMD_GEN_REQUEST64_CX: |
| 8098 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8099 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8100 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8101 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8102 | MENLO_TRANSPORT_TYPE)) |
| 8103 | |
| 8104 | goto iocb_busy; |
| 8105 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8106 | case CMD_QUE_RING_BUF_CN: |
| 8107 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8108 | /* |
| 8109 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8110 | * completion, iocb_cmpl MUST be 0. |
| 8111 | */ |
| 8112 | if (piocb->iocb_cmpl) |
| 8113 | piocb->iocb_cmpl = NULL; |
| 8114 | /*FALLTHROUGH*/ |
| 8115 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8116 | case CMD_CLOSE_XRI_CN: |
| 8117 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8118 | break; |
| 8119 | default: |
| 8120 | goto iocb_busy; |
| 8121 | } |
| 8122 | |
| 8123 | /* |
| 8124 | * For FCP commands, we must be in a state where we can process link |
| 8125 | * attention events. |
| 8126 | */ |
| 8127 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8128 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8129 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8130 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8132 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8133 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8134 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8135 | |
| 8136 | if (iocb) |
| 8137 | lpfc_sli_update_ring(phba, pring); |
| 8138 | else |
| 8139 | lpfc_sli_update_full_ring(phba, pring); |
| 8140 | |
| 8141 | if (!piocb) |
| 8142 | return IOCB_SUCCESS; |
| 8143 | |
| 8144 | goto out_busy; |
| 8145 | |
| 8146 | iocb_busy: |
| 8147 | pring->stats.iocb_cmd_delay++; |
| 8148 | |
| 8149 | out_busy: |
| 8150 | |
| 8151 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8152 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8153 | return IOCB_SUCCESS; |
| 8154 | } |
| 8155 | |
| 8156 | return IOCB_BUSY; |
| 8157 | } |
| 8158 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8159 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8160 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8161 | * @phba: Pointer to HBA context object. |
| 8162 | * @piocb: Pointer to command iocb. |
| 8163 | * @sglq: Pointer to the scatter gather queue object. |
| 8164 | * |
| 8165 | * This routine converts the bpl or bde that is in the IOCB |
| 8166 | * to a sgl list for the sli4 hardware. The physical address |
| 8167 | * of the bpl/bde is converted back to a virtual address. |
| 8168 | * If the IOCB contains a BPL then the list of BDE's is |
| 8169 | * converted to sli4_sge's. If the IOCB contains a single |
| 8170 | * BDE then it is converted to a single sli_sge. |
| 8171 | * The IOCB is still in cpu endianess so the contents of |
| 8172 | * the bpl can be used without byte swapping. |
| 8173 | * |
| 8174 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8175 | **/ |
| 8176 | static uint16_t |
| 8177 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8178 | struct lpfc_sglq *sglq) |
| 8179 | { |
| 8180 | uint16_t xritag = NO_XRI; |
| 8181 | struct ulp_bde64 *bpl = NULL; |
| 8182 | struct ulp_bde64 bde; |
| 8183 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8184 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8185 | IOCB_t *icmd; |
| 8186 | int numBdes = 0; |
| 8187 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8188 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8189 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8190 | |
| 8191 | if (!piocbq || !sglq) |
| 8192 | return xritag; |
| 8193 | |
| 8194 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8195 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8196 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8197 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8198 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8199 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8200 | sizeof(struct ulp_bde64); |
| 8201 | /* The addrHigh and addrLow fields within the IOCB |
| 8202 | * have not been byteswapped yet so there is no |
| 8203 | * need to swap them back. |
| 8204 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8205 | if (piocbq->context3) |
| 8206 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8207 | else |
| 8208 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8209 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8210 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8211 | if (!bpl) |
| 8212 | return xritag; |
| 8213 | |
| 8214 | for (i = 0; i < numBdes; i++) { |
| 8215 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8216 | sgl->addr_hi = bpl->addrHigh; |
| 8217 | sgl->addr_lo = bpl->addrLow; |
| 8218 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8219 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8220 | if ((i+1) == numBdes) |
| 8221 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8222 | else |
| 8223 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8224 | /* swap the size field back to the cpu so we |
| 8225 | * can assign it to the sgl. |
| 8226 | */ |
| 8227 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8228 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8229 | /* The offsets in the sgl need to be accumulated |
| 8230 | * separately for the request and reply lists. |
| 8231 | * The request is always first, the reply follows. |
| 8232 | */ |
| 8233 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8234 | /* add up the reply sg entries */ |
| 8235 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8236 | inbound++; |
| 8237 | /* first inbound? reset the offset */ |
| 8238 | if (inbound == 1) |
| 8239 | offset = 0; |
| 8240 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8241 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8242 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8243 | offset += bde.tus.f.bdeSize; |
| 8244 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8245 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8246 | bpl++; |
| 8247 | sgl++; |
| 8248 | } |
| 8249 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8250 | /* The addrHigh and addrLow fields of the BDE have not |
| 8251 | * been byteswapped yet so they need to be swapped |
| 8252 | * before putting them in the sgl. |
| 8253 | */ |
| 8254 | sgl->addr_hi = |
| 8255 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8256 | sgl->addr_lo = |
| 8257 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8258 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8259 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8260 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8261 | sgl->sge_len = |
| 8262 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8263 | } |
| 8264 | return sglq->sli4_xritag; |
| 8265 | } |
| 8266 | |
| 8267 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8268 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8269 | * @phba: Pointer to HBA context object. |
| 8270 | * @piocb: Pointer to command iocb. |
| 8271 | * @wqe: Pointer to the work queue entry. |
| 8272 | * |
| 8273 | * This routine converts the iocb command to its Work Queue Entry |
| 8274 | * equivalent. The wqe pointer should not have any fields set when |
| 8275 | * this routine is called because it will memcpy over them. |
| 8276 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8277 | * wqe. |
| 8278 | * |
| 8279 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8280 | **/ |
| 8281 | static int |
| 8282 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8283 | union lpfc_wqe *wqe) |
| 8284 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8285 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8286 | uint8_t ct = 0; |
| 8287 | uint32_t fip; |
| 8288 | uint32_t abort_tag; |
| 8289 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8290 | uint8_t cmnd; |
| 8291 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8292 | uint16_t abrt_iotag; |
| 8293 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8294 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8295 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8296 | int numBdes, i; |
| 8297 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8298 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8299 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8300 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8301 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8302 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8303 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8304 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8305 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8306 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8307 | command_type = ELS_COMMAND_FIP; |
| 8308 | else |
| 8309 | command_type = ELS_COMMAND_NON_FIP; |
| 8310 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8311 | if (phba->fcp_embed_io) |
| 8312 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8313 | /* Some of the fields are in the right position already */ |
| 8314 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8315 | 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] | 8316 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8317 | |
| 8318 | abort_tag = (uint32_t) iocbq->iotag; |
| 8319 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8320 | /* words0-2 bpl convert bde */ |
| 8321 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8322 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8323 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8324 | bpl = (struct ulp_bde64 *) |
| 8325 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8326 | if (!bpl) |
| 8327 | return IOCB_ERROR; |
| 8328 | |
| 8329 | /* Should already be byte swapped. */ |
| 8330 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8331 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8332 | /* swap the size field back to the cpu so we |
| 8333 | * can assign it to the sgl. |
| 8334 | */ |
| 8335 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8336 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8337 | total_len = 0; |
| 8338 | for (i = 0; i < numBdes; i++) { |
| 8339 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8340 | total_len += bde.tus.f.bdeSize; |
| 8341 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8342 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8343 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8344 | |
| 8345 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8346 | cmnd = iocbq->iocb.ulpCommand; |
| 8347 | |
| 8348 | switch (iocbq->iocb.ulpCommand) { |
| 8349 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8350 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8351 | ndlp = iocbq->context_un.ndlp; |
| 8352 | else |
| 8353 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8354 | if (!iocbq->iocb.ulpLe) { |
| 8355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8356 | "2007 Only Limited Edition cmd Format" |
| 8357 | " supported 0x%x\n", |
| 8358 | iocbq->iocb.ulpCommand); |
| 8359 | return IOCB_ERROR; |
| 8360 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8361 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8362 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8363 | /* Els_reguest64 has a TMO */ |
| 8364 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8365 | iocbq->iocb.ulpTimeout); |
| 8366 | /* Need a VF for word 4 set the vf bit*/ |
| 8367 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8368 | /* And a VFID for word 12 */ |
| 8369 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8370 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8371 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8372 | iocbq->iocb.ulpContext); |
| 8373 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8374 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8375 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8376 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8377 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8378 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8379 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8380 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8381 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8382 | &phba->sli4_hba.sli_intf); |
| 8383 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8384 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8385 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8386 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8387 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8388 | *pcmd == ELS_CMD_PLOGI)) { |
| 8389 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8390 | bf_set(els_req64_sid, &wqe->els_req, |
| 8391 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8392 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8393 | !(phba->fc_topology == |
| 8394 | LPFC_TOPOLOGY_LOOP)) |
| 8395 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8396 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8397 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8398 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8399 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8400 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8401 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8402 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8403 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8404 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8405 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8406 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8407 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8408 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8409 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8410 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8411 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8412 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8413 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8414 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8415 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8416 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8417 | iocbq->iocb.un.ulpWord[3]); |
| 8418 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8419 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8420 | /* The entire sequence is transmitted for this IOCB */ |
| 8421 | xmit_len = total_len; |
| 8422 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8423 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8424 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8425 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8426 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8427 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8428 | /* word4 relative_offset memcpy */ |
| 8429 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8430 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8431 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8432 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8433 | LPFC_WQE_IOD_WRITE); |
| 8434 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8435 | LPFC_WQE_LENLOC_WORD12); |
| 8436 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8437 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8438 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8439 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8440 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8441 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8442 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8443 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8444 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8445 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8446 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8447 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8448 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8449 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8450 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8451 | LPFC_WQE_LENLOC_WORD3); |
| 8452 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8453 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8454 | case CMD_FCP_IWRITE64_CR: |
| 8455 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8456 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8457 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8458 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8459 | xmit_len + sizeof(struct fcp_rsp)); |
| 8460 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8461 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8462 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8463 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8464 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8465 | iocbq->iocb.ulpFCP2Rcvy); |
| 8466 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8467 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8468 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8469 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8470 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8471 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8472 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8473 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8474 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8475 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8476 | if (iocbq->priority) { |
| 8477 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8478 | (iocbq->priority << 1)); |
| 8479 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8480 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8481 | (phba->cfg_XLanePriority << 1)); |
| 8482 | } |
| 8483 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8484 | /* Note, word 10 is already initialized to 0 */ |
| 8485 | |
| 8486 | if (phba->fcp_embed_io) { |
| 8487 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8488 | struct sli4_sge *sgl; |
| 8489 | union lpfc_wqe128 *wqe128; |
| 8490 | struct fcp_cmnd *fcp_cmnd; |
| 8491 | uint32_t *ptr; |
| 8492 | |
| 8493 | /* 128 byte wqe support here */ |
| 8494 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8495 | |
| 8496 | lpfc_cmd = iocbq->context1; |
| 8497 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8498 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8499 | |
| 8500 | /* Word 0-2 - FCP_CMND */ |
| 8501 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8502 | BUFF_TYPE_BDE_IMMED; |
| 8503 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8504 | wqe128->generic.bde.addrHigh = 0; |
| 8505 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8506 | |
| 8507 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8508 | |
| 8509 | /* Word 22-29 FCP CMND Payload */ |
| 8510 | ptr = &wqe128->words[22]; |
| 8511 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8512 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8513 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8514 | case CMD_FCP_IREAD64_CR: |
| 8515 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8516 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8517 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8518 | xmit_len + sizeof(struct fcp_rsp)); |
| 8519 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8520 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8521 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8522 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8523 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8524 | iocbq->iocb.ulpFCP2Rcvy); |
| 8525 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8526 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8527 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8528 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8529 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8530 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8531 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8532 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8533 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8534 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8535 | if (iocbq->priority) { |
| 8536 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8537 | (iocbq->priority << 1)); |
| 8538 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8539 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8540 | (phba->cfg_XLanePriority << 1)); |
| 8541 | } |
| 8542 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8543 | /* Note, word 10 is already initialized to 0 */ |
| 8544 | |
| 8545 | if (phba->fcp_embed_io) { |
| 8546 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8547 | struct sli4_sge *sgl; |
| 8548 | union lpfc_wqe128 *wqe128; |
| 8549 | struct fcp_cmnd *fcp_cmnd; |
| 8550 | uint32_t *ptr; |
| 8551 | |
| 8552 | /* 128 byte wqe support here */ |
| 8553 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8554 | |
| 8555 | lpfc_cmd = iocbq->context1; |
| 8556 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8557 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8558 | |
| 8559 | /* Word 0-2 - FCP_CMND */ |
| 8560 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8561 | BUFF_TYPE_BDE_IMMED; |
| 8562 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8563 | wqe128->generic.bde.addrHigh = 0; |
| 8564 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8565 | |
| 8566 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8567 | |
| 8568 | /* Word 22-29 FCP CMND Payload */ |
| 8569 | ptr = &wqe128->words[22]; |
| 8570 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8571 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8572 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8573 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8574 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8575 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8576 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8577 | xmit_len + sizeof(struct fcp_rsp)); |
| 8578 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8579 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8580 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8581 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8582 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8583 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8584 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8585 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8586 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8587 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8588 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8589 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8590 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8591 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8592 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8593 | if (iocbq->priority) { |
| 8594 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8595 | (iocbq->priority << 1)); |
| 8596 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8597 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8598 | (phba->cfg_XLanePriority << 1)); |
| 8599 | } |
| 8600 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8601 | /* Note, word 10 is already initialized to 0 */ |
| 8602 | |
| 8603 | if (phba->fcp_embed_io) { |
| 8604 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8605 | struct sli4_sge *sgl; |
| 8606 | union lpfc_wqe128 *wqe128; |
| 8607 | struct fcp_cmnd *fcp_cmnd; |
| 8608 | uint32_t *ptr; |
| 8609 | |
| 8610 | /* 128 byte wqe support here */ |
| 8611 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8612 | |
| 8613 | lpfc_cmd = iocbq->context1; |
| 8614 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8615 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8616 | |
| 8617 | /* Word 0-2 - FCP_CMND */ |
| 8618 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8619 | BUFF_TYPE_BDE_IMMED; |
| 8620 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8621 | wqe128->generic.bde.addrHigh = 0; |
| 8622 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8623 | |
| 8624 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 8625 | |
| 8626 | /* Word 22-29 FCP CMND Payload */ |
| 8627 | ptr = &wqe128->words[22]; |
| 8628 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8629 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8630 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8631 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8632 | /* For this command calculate the xmit length of the |
| 8633 | * request bde. |
| 8634 | */ |
| 8635 | xmit_len = 0; |
| 8636 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8637 | sizeof(struct ulp_bde64); |
| 8638 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8639 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8640 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8641 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8642 | xmit_len += bde.tus.f.bdeSize; |
| 8643 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8644 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8645 | wqe->gen_req.request_payload_len = xmit_len; |
| 8646 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8647 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8648 | /* word6 context tag copied in memcpy */ |
| 8649 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8650 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8651 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8652 | "2015 Invalid CT %x command 0x%x\n", |
| 8653 | ct, iocbq->iocb.ulpCommand); |
| 8654 | return IOCB_ERROR; |
| 8655 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8656 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8657 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8658 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8659 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8660 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8661 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8662 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8663 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8664 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8665 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8666 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8667 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8668 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8669 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8670 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8671 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8672 | /* word4 */ |
| 8673 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8674 | /* word5 iocb=rsvd wge=did */ |
| 8675 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8676 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8677 | |
| 8678 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8679 | &phba->sli4_hba.sli_intf); |
| 8680 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8681 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8682 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8683 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8684 | iocbq->vport->fc_myDID); |
| 8685 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8686 | bf_set(wqe_els_did, |
| 8687 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8688 | } |
| 8689 | } |
| 8690 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8691 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8692 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8693 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8694 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8695 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8696 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8697 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8698 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8699 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8700 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8701 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8702 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8703 | LPFC_WQE_LENLOC_WORD3); |
| 8704 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8705 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8706 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8707 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8708 | iocbq->context2)->virt); |
| 8709 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8710 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8711 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8712 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8713 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8714 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8715 | phba->vpi_ids[phba->pport->vpi]); |
| 8716 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8717 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8718 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8719 | case CMD_CLOSE_XRI_CN: |
| 8720 | case CMD_ABORT_XRI_CN: |
| 8721 | case CMD_ABORT_XRI_CX: |
| 8722 | /* words 0-2 memcpy should be 0 rserved */ |
| 8723 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8724 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8725 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8726 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8727 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8728 | } else |
| 8729 | fip = 0; |
| 8730 | |
| 8731 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8732 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8733 | * The link is down, or the command was ELS_FIP |
| 8734 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8735 | * on the wire. |
| 8736 | */ |
| 8737 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8738 | else |
| 8739 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8740 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8741 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8742 | wqe->abort_cmd.rsrvd5 = 0; |
| 8743 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8744 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8745 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8746 | /* |
| 8747 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8748 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8749 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8750 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8751 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8752 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8753 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8754 | cmnd = CMD_ABORT_XRI_CX; |
| 8755 | command_type = OTHER_COMMAND; |
| 8756 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8757 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8758 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8759 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8760 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8761 | * we re-construct this WQE here based on information in |
| 8762 | * iocbq from scratch. |
| 8763 | */ |
| 8764 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8765 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8766 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8767 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8768 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8769 | LPFC_ABTS_UNSOL_INT) { |
| 8770 | /* ABTS sent by initiator to CT exchange, the |
| 8771 | * RX_ID field will be filled with the newly |
| 8772 | * allocated responder XRI. |
| 8773 | */ |
| 8774 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8775 | iocbq->sli4_xritag); |
| 8776 | } else { |
| 8777 | /* ABTS sent by responder to CT exchange, the |
| 8778 | * RX_ID field will be filled with the responder |
| 8779 | * RX_ID from ABTS. |
| 8780 | */ |
| 8781 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8782 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8783 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8784 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8785 | 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] | 8786 | |
| 8787 | /* Use CT=VPI */ |
| 8788 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8789 | ndlp->nlp_DID); |
| 8790 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8791 | iocbq->iocb.ulpContext); |
| 8792 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8793 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8794 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8795 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8796 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8797 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8798 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8799 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8800 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8801 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8802 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8803 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8804 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8805 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8806 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8807 | } |
| 8808 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8809 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8810 | case CMD_XRI_ABORTED_CX: |
| 8811 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8812 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8813 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8814 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8815 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8816 | default: |
| 8817 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8818 | "2014 Invalid command 0x%x\n", |
| 8819 | iocbq->iocb.ulpCommand); |
| 8820 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8821 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8822 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8823 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8824 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8825 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8826 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8827 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8828 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8829 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8830 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8831 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8832 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8833 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8834 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8835 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8836 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8837 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8838 | 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] | 8839 | return 0; |
| 8840 | } |
| 8841 | |
| 8842 | /** |
| 8843 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8844 | * @phba: Pointer to HBA context object. |
| 8845 | * @ring_number: SLI ring number to issue iocb on. |
| 8846 | * @piocb: Pointer to command iocb. |
| 8847 | * @flag: Flag indicating if this command can be put into txq. |
| 8848 | * |
| 8849 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8850 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8851 | * |
| 8852 | * This function is called with hbalock held. The function will return success |
| 8853 | * after it successfully submit the iocb to firmware or after adding to the |
| 8854 | * txq. |
| 8855 | **/ |
| 8856 | static int |
| 8857 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8858 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8859 | { |
| 8860 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8861 | union lpfc_wqe *wqe; |
| 8862 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8863 | struct lpfc_queue *wq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8864 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8865 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8866 | lockdep_assert_held(&phba->hbalock); |
| 8867 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8868 | /* |
| 8869 | * The WQE can be either 64 or 128 bytes, |
| 8870 | * so allocate space on the stack assuming the largest. |
| 8871 | */ |
| 8872 | wqe = (union lpfc_wqe *)&wqe128; |
| 8873 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8874 | if (piocb->sli4_xritag == NO_XRI) { |
| 8875 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8876 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8877 | sglq = NULL; |
| 8878 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8879 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8880 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8881 | __lpfc_sli_ringtx_put(phba, |
| 8882 | pring, piocb); |
| 8883 | return IOCB_SUCCESS; |
| 8884 | } else { |
| 8885 | return IOCB_BUSY; |
| 8886 | } |
| 8887 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8888 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8889 | if (!sglq) { |
| 8890 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8891 | __lpfc_sli_ringtx_put(phba, |
| 8892 | pring, |
| 8893 | piocb); |
| 8894 | return IOCB_SUCCESS; |
| 8895 | } else |
| 8896 | return IOCB_BUSY; |
| 8897 | } |
| 8898 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8899 | } |
| 8900 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8901 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8902 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8903 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8904 | /* |
| 8905 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8906 | * sglq is on the active list |
| 8907 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8908 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8909 | if (!sglq) |
| 8910 | return IOCB_ERROR; |
| 8911 | } |
| 8912 | |
| 8913 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8914 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8915 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8916 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8917 | return IOCB_ERROR; |
| 8918 | } |
| 8919 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8920 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8921 | return IOCB_ERROR; |
| 8922 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8923 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8924 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 8925 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8926 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
| 8927 | } else { |
| 8928 | wq = phba->sli4_hba.oas_wq; |
| 8929 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8930 | if (lpfc_sli4_wq_put(wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8931 | return IOCB_ERROR; |
| 8932 | } else { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8933 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 8934 | return IOCB_ERROR; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8935 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8936 | return IOCB_ERROR; |
| 8937 | } |
| 8938 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8939 | |
| 8940 | return 0; |
| 8941 | } |
| 8942 | |
| 8943 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8944 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8945 | * |
| 8946 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8947 | * pointer from the lpfc_hba struct. |
| 8948 | * |
| 8949 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8950 | * IOCB_ERROR - Error |
| 8951 | * IOCB_SUCCESS - Success |
| 8952 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8953 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8954 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8955 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8956 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8957 | { |
| 8958 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8959 | } |
| 8960 | |
| 8961 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8962 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8963 | * @phba: The hba struct for which this call is being executed. |
| 8964 | * @dev_grp: The HBA PCI-Device group number. |
| 8965 | * |
| 8966 | * This routine sets up the SLI interface API function jump table in @phba |
| 8967 | * struct. |
| 8968 | * Returns: 0 - success, -ENODEV - failure. |
| 8969 | **/ |
| 8970 | int |
| 8971 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8972 | { |
| 8973 | |
| 8974 | switch (dev_grp) { |
| 8975 | case LPFC_PCI_DEV_LP: |
| 8976 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8977 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8978 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8979 | case LPFC_PCI_DEV_OC: |
| 8980 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8981 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8982 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8983 | default: |
| 8984 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8985 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8986 | dev_grp); |
| 8987 | return -ENODEV; |
| 8988 | break; |
| 8989 | } |
| 8990 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8991 | return 0; |
| 8992 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8993 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 8994 | /** |
| 8995 | * lpfc_sli_calc_ring - Calculates which ring to use |
| 8996 | * @phba: Pointer to HBA context object. |
| 8997 | * @ring_number: Initial ring |
| 8998 | * @piocb: Pointer to command iocb. |
| 8999 | * |
| 9000 | * For SLI4, FCP IO can deferred to one fo many WQs, based on |
| 9001 | * fcp_wqidx, thus we need to calculate the corresponding ring. |
| 9002 | * Since ABORTS must go on the same WQ of the command they are |
| 9003 | * aborting, we use command's fcp_wqidx. |
| 9004 | */ |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 9005 | static int |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9006 | lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number, |
| 9007 | struct lpfc_iocbq *piocb) |
| 9008 | { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9009 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 9010 | return ring_number; |
| 9011 | |
| 9012 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
| 9013 | if (!(phba->cfg_fof) || |
| 9014 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
| 9015 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 9016 | return LPFC_HBA_ERROR; |
| 9017 | /* |
| 9018 | * for abort iocb fcp_wqidx should already |
| 9019 | * be setup based on what work queue we used. |
| 9020 | */ |
| 9021 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) |
| 9022 | piocb->fcp_wqidx = |
| 9023 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9024 | piocb->context1); |
| 9025 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 9026 | piocb->fcp_wqidx; |
| 9027 | } else { |
| 9028 | if (unlikely(!phba->sli4_hba.oas_wq)) |
| 9029 | return LPFC_HBA_ERROR; |
| 9030 | piocb->fcp_wqidx = 0; |
| 9031 | ring_number = LPFC_FCP_OAS_RING; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9032 | } |
| 9033 | } |
| 9034 | return ring_number; |
| 9035 | } |
| 9036 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9037 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9038 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9039 | * @phba: Pointer to HBA context object. |
| 9040 | * @pring: Pointer to driver SLI ring object. |
| 9041 | * @piocb: Pointer to command iocb. |
| 9042 | * @flag: Flag indicating if this command can be put into txq. |
| 9043 | * |
| 9044 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9045 | * function. This function gets the hbalock and calls |
| 9046 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9047 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9048 | * functions which do not hold hbalock. |
| 9049 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9050 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9051 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9052 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9053 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9054 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9055 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9056 | struct lpfc_queue *fpeq; |
| 9057 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9058 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9059 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9060 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9061 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9062 | ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb); |
| 9063 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 9064 | return IOCB_ERROR; |
| 9065 | idx = piocb->fcp_wqidx; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9066 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9067 | pring = &phba->sli.ring[ring_number]; |
| 9068 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9069 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9070 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9071 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9072 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
| 9073 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9074 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9075 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 9076 | fcp_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9077 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9078 | /* Get associated EQ with this index */ |
| 9079 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9080 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9081 | /* Turn off interrupts from this EQ */ |
| 9082 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9083 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9084 | /* |
| 9085 | * Process all the events on FCP EQ |
| 9086 | */ |
| 9087 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9088 | lpfc_sli4_hba_handle_eqe(phba, |
| 9089 | eqe, idx); |
| 9090 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9091 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9092 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9093 | /* Always clear and re-arm the EQ */ |
| 9094 | lpfc_sli4_eq_release(fpeq, |
| 9095 | LPFC_QUEUE_REARM); |
| 9096 | } |
| 9097 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9098 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9099 | } else { |
| 9100 | /* For now, SLI2/3 will still use hbalock */ |
| 9101 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9102 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9103 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9104 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9105 | return rc; |
| 9106 | } |
| 9107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9109 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9110 | * @phba: Pointer to HBA context object. |
| 9111 | * |
| 9112 | * This function is called while driver attaches with the |
| 9113 | * HBA to setup the extra ring. The extra ring is used |
| 9114 | * only when driver needs to support target mode functionality |
| 9115 | * or IP over FC functionalities. |
| 9116 | * |
| 9117 | * This function is called with no lock held. |
| 9118 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9119 | static int |
| 9120 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9121 | { |
| 9122 | struct lpfc_sli *psli; |
| 9123 | struct lpfc_sli_ring *pring; |
| 9124 | |
| 9125 | psli = &phba->sli; |
| 9126 | |
| 9127 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9128 | |
| 9129 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9130 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9131 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9132 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9133 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9134 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9135 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9136 | /* and give them to the extra ring */ |
| 9137 | pring = &psli->ring[psli->extra_ring]; |
| 9138 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9139 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9140 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9141 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9142 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9143 | |
| 9144 | /* Setup default profile for this ring */ |
| 9145 | pring->iotag_max = 4096; |
| 9146 | pring->num_mask = 1; |
| 9147 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9148 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9149 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9150 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9151 | return 0; |
| 9152 | } |
| 9153 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9154 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9155 | * @phba: Pointer to HBA context object. |
| 9156 | * @iocbq: Pointer to iocb object. |
| 9157 | * |
| 9158 | * The async_event handler calls this routine when it receives |
| 9159 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9160 | * this event when an Abort Sequence request to an rport fails |
| 9161 | * twice in succession. The abort could be originated by the |
| 9162 | * driver or by the port. The ABTS could have been for an ELS |
| 9163 | * or FCP IO. The port only generates this event when an ABTS |
| 9164 | * fails to complete after one retry. |
| 9165 | */ |
| 9166 | static void |
| 9167 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9168 | struct lpfc_iocbq *iocbq) |
| 9169 | { |
| 9170 | struct lpfc_nodelist *ndlp = NULL; |
| 9171 | uint16_t rpi = 0, vpi = 0; |
| 9172 | struct lpfc_vport *vport = NULL; |
| 9173 | |
| 9174 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9175 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9176 | rpi = iocbq->iocb.ulpContext; |
| 9177 | |
| 9178 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9179 | "3092 Port generated ABTS async event " |
| 9180 | "on vpi %d rpi %d status 0x%x\n", |
| 9181 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9182 | |
| 9183 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9184 | if (!vport) |
| 9185 | goto err_exit; |
| 9186 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9187 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9188 | goto err_exit; |
| 9189 | |
| 9190 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9191 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9192 | return; |
| 9193 | |
| 9194 | err_exit: |
| 9195 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9196 | "3095 Event Context not found, no " |
| 9197 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9198 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9199 | vpi, rpi); |
| 9200 | } |
| 9201 | |
| 9202 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9203 | * @phba: pointer to HBA context object. |
| 9204 | * @ndlp: nodelist pointer for the impacted rport. |
| 9205 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9206 | * |
| 9207 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9208 | * port. The port generates this event when an abort exchange request to an |
| 9209 | * rport fails twice in succession with no reply. The abort could be originated |
| 9210 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9211 | */ |
| 9212 | void |
| 9213 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9214 | struct lpfc_nodelist *ndlp, |
| 9215 | struct sli4_wcqe_xri_aborted *axri) |
| 9216 | { |
| 9217 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9218 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9219 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9220 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9221 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9222 | "3115 Node Context not found, driver " |
| 9223 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9224 | return; |
| 9225 | } |
| 9226 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9227 | vport = ndlp->vport; |
| 9228 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9229 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9230 | "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] | 9231 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9232 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9233 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9234 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9235 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9236 | /* |
| 9237 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9238 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9239 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9240 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9241 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9242 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9243 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9244 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9245 | } |
| 9246 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9248 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9249 | * @phba: Pointer to HBA context object. |
| 9250 | * @pring: Pointer to driver SLI ring object. |
| 9251 | * @iocbq: Pointer to iocb object. |
| 9252 | * |
| 9253 | * This function is called by the slow ring event handler |
| 9254 | * function when there is an ASYNC event iocb in the ring. |
| 9255 | * This function is called with no lock held. |
| 9256 | * Currently this function handles only temperature related |
| 9257 | * ASYNC events. The function decodes the temperature sensor |
| 9258 | * event message and posts events for the management applications. |
| 9259 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9260 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9261 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9262 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9263 | { |
| 9264 | IOCB_t *icmd; |
| 9265 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9266 | struct temp_event temp_event_data; |
| 9267 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9268 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9269 | |
| 9270 | icmd = &iocbq->iocb; |
| 9271 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9272 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9273 | switch (evt_code) { |
| 9274 | case ASYNC_TEMP_WARN: |
| 9275 | case ASYNC_TEMP_SAFE: |
| 9276 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9277 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9278 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9279 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9280 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9281 | "0347 Adapter is very hot, please take " |
| 9282 | "corrective action. temperature : %d Celsius\n", |
| 9283 | (uint32_t) icmd->ulpContext); |
| 9284 | } else { |
| 9285 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9286 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9287 | "0340 Adapter temperature is OK now. " |
| 9288 | "temperature : %d Celsius\n", |
| 9289 | (uint32_t) icmd->ulpContext); |
| 9290 | } |
| 9291 | |
| 9292 | /* Send temperature change event to applications */ |
| 9293 | shost = lpfc_shost_from_vport(phba->pport); |
| 9294 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9295 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9296 | LPFC_NL_VENDOR_ID); |
| 9297 | break; |
| 9298 | case ASYNC_STATUS_CN: |
| 9299 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9300 | break; |
| 9301 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9302 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9303 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9304 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9305 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9306 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9307 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9308 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9309 | "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] | 9310 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9311 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9312 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9313 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9314 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9315 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9316 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9317 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9318 | } |
| 9319 | |
| 9320 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9321 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9322 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9323 | * @phba: Pointer to HBA context object. |
| 9324 | * |
| 9325 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9326 | * number of iocbs per ring and iotags. This function is |
| 9327 | * called while driver attach to the HBA and before the |
| 9328 | * interrupts are enabled. So there is no need for locking. |
| 9329 | * |
| 9330 | * This function always returns 0. |
| 9331 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9332 | int |
| 9333 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9334 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9335 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9336 | struct lpfc_sli *psli = &phba->sli; |
| 9337 | struct lpfc_sli_ring *pring; |
| 9338 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9339 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 9340 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9341 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9342 | psli->sli_flag = 0; |
| 9343 | psli->fcp_ring = LPFC_FCP_RING; |
| 9344 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9345 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9346 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9347 | psli->iocbq_lookup = NULL; |
| 9348 | psli->iocbq_lookup_len = 0; |
| 9349 | psli->last_iotag = 0; |
| 9350 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | for (i = 0; i < psli->num_rings; i++) { |
| 9352 | pring = &psli->ring[i]; |
| 9353 | switch (i) { |
| 9354 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9355 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9356 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9357 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9358 | pring->sli.sli3.numCiocb += |
| 9359 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9360 | pring->sli.sli3.numRiocb += |
| 9361 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9362 | pring->sli.sli3.numCiocb += |
| 9363 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9364 | pring->sli.sli3.numRiocb += |
| 9365 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9366 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9367 | SLI3_IOCB_CMD_SIZE : |
| 9368 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9369 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9370 | SLI3_IOCB_RSP_SIZE : |
| 9371 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9372 | pring->iotag_ctr = 0; |
| 9373 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9374 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9375 | pring->fast_iotag = pring->iotag_max; |
| 9376 | pring->num_mask = 0; |
| 9377 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9378 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9379 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9380 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9381 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9382 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9383 | SLI3_IOCB_CMD_SIZE : |
| 9384 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9385 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9386 | SLI3_IOCB_RSP_SIZE : |
| 9387 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9388 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9389 | pring->num_mask = 0; |
| 9390 | break; |
| 9391 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9392 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9393 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9394 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9395 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9396 | SLI3_IOCB_CMD_SIZE : |
| 9397 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9398 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9399 | SLI3_IOCB_RSP_SIZE : |
| 9400 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9401 | pring->fast_iotag = 0; |
| 9402 | pring->iotag_ctr = 0; |
| 9403 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9404 | pring->lpfc_sli_rcv_async_status = |
| 9405 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9406 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9407 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9408 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9409 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9410 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9411 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9412 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9413 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9414 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9415 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9416 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9417 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9418 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9419 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9420 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9421 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9422 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9423 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9424 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9425 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9426 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9427 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9428 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9429 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9430 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9431 | break; |
| 9432 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9433 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9434 | pring->sli.sli3.sizeCiocb) + |
| 9435 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9436 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9437 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9438 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9439 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9440 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9441 | phba->brd_no, totiocbsize, |
| 9442 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9443 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9444 | if (phba->cfg_multi_ring_support == 2) |
| 9445 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9446 | |
| 9447 | return 0; |
| 9448 | } |
| 9449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9451 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9452 | * @phba: Pointer to HBA context object. |
| 9453 | * |
| 9454 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 9455 | * ring. This function also initializes ring indices of each ring. |
| 9456 | * This function is called during the initialization of the SLI |
| 9457 | * interface of an HBA. |
| 9458 | * This function is called with no lock held and always returns |
| 9459 | * 1. |
| 9460 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9461 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9462 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9463 | { |
| 9464 | struct lpfc_sli *psli; |
| 9465 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9466 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9467 | |
| 9468 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9469 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9470 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9471 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9472 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9473 | for (i = 0; i < psli->num_rings; i++) { |
| 9474 | pring = &psli->ring[i]; |
| 9475 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9476 | pring->sli.sli3.next_cmdidx = 0; |
| 9477 | pring->sli.sli3.local_getidx = 0; |
| 9478 | pring->sli.sli3.cmdidx = 0; |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 9479 | pring->flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9480 | INIT_LIST_HEAD(&pring->txq); |
| 9481 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9482 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9483 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9484 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9485 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9486 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9487 | spin_unlock_irq(&phba->hbalock); |
| 9488 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9489 | } |
| 9490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9491 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9492 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9493 | * @phba: Pointer to HBA context object. |
| 9494 | * |
| 9495 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9496 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9497 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9498 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9499 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9500 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9501 | * pending mailbox command queue from the various clients must be stopped; |
| 9502 | * either the HBA is in a state that it will never works on the outstanding |
| 9503 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9504 | * mailbox command has been completed. |
| 9505 | **/ |
| 9506 | static void |
| 9507 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 9508 | { |
| 9509 | LIST_HEAD(completions); |
| 9510 | struct lpfc_sli *psli = &phba->sli; |
| 9511 | LPFC_MBOXQ_t *pmb; |
| 9512 | unsigned long iflag; |
| 9513 | |
| 9514 | /* Flush all the mailbox commands in the mbox system */ |
| 9515 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9516 | /* The pending mailbox command queue */ |
| 9517 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9518 | /* The outstanding active mailbox command */ |
| 9519 | if (psli->mbox_active) { |
| 9520 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9521 | psli->mbox_active = NULL; |
| 9522 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9523 | } |
| 9524 | /* The completed mailbox command queue */ |
| 9525 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9526 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9527 | |
| 9528 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9529 | while (!list_empty(&completions)) { |
| 9530 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9531 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9532 | if (pmb->mbox_cmpl) |
| 9533 | pmb->mbox_cmpl(phba, pmb); |
| 9534 | } |
| 9535 | } |
| 9536 | |
| 9537 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9538 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9539 | * @vport: Pointer to virtual port object. |
| 9540 | * |
| 9541 | * lpfc_sli_host_down is called to clean up the resources |
| 9542 | * associated with a vport before destroying virtual |
| 9543 | * port data structures. |
| 9544 | * This function does following operations: |
| 9545 | * - Free discovery resources associated with this virtual |
| 9546 | * port. |
| 9547 | * - Free iocbs associated with this virtual port in |
| 9548 | * the txq. |
| 9549 | * - Send abort for all iocb commands associated with this |
| 9550 | * vport in txcmplq. |
| 9551 | * |
| 9552 | * This function is called with no lock held and always returns 1. |
| 9553 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9554 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9555 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9556 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9557 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9558 | struct lpfc_hba *phba = vport->phba; |
| 9559 | struct lpfc_sli *psli = &phba->sli; |
| 9560 | struct lpfc_sli_ring *pring; |
| 9561 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9562 | int i; |
| 9563 | unsigned long flags = 0; |
| 9564 | uint16_t prev_pring_flag; |
| 9565 | |
| 9566 | lpfc_cleanup_discovery_resources(vport); |
| 9567 | |
| 9568 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9569 | for (i = 0; i < psli->num_rings; i++) { |
| 9570 | pring = &psli->ring[i]; |
| 9571 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9572 | /* Only slow rings */ |
| 9573 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9574 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9575 | /* Set the lpfc data pending flag */ |
| 9576 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9577 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9578 | /* |
| 9579 | * Error everything on the txq since these iocbs have not been |
| 9580 | * given to the FW yet. |
| 9581 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9582 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9583 | if (iocb->vport != vport) |
| 9584 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9585 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9586 | } |
| 9587 | |
| 9588 | /* Next issue ABTS for everything on the txcmplq */ |
| 9589 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9590 | list) { |
| 9591 | if (iocb->vport != vport) |
| 9592 | continue; |
| 9593 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9594 | } |
| 9595 | |
| 9596 | pring->flag = prev_pring_flag; |
| 9597 | } |
| 9598 | |
| 9599 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9600 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9601 | /* Cancel all the IOCBs from the completions list */ |
| 9602 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9603 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9604 | return 1; |
| 9605 | } |
| 9606 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9607 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9608 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9609 | * @phba: Pointer to HBA context object. |
| 9610 | * |
| 9611 | * This function cleans up all iocb, buffers, mailbox commands |
| 9612 | * while shutting down the HBA. This function is called with no |
| 9613 | * lock held and always returns 1. |
| 9614 | * This function does the following to cleanup driver resources: |
| 9615 | * - Free discovery resources for each virtual port |
| 9616 | * - Cleanup any pending fabric iocbs |
| 9617 | * - Iterate through the iocb txq and free each entry |
| 9618 | * in the list. |
| 9619 | * - Free up any buffer posted to the HBA |
| 9620 | * - Free mailbox commands in the mailbox queue. |
| 9621 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9622 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9623 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9624 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9625 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9626 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9627 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9628 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9629 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9630 | int i; |
| 9631 | |
| 9632 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9633 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9634 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9635 | lpfc_hba_down_prep(phba); |
| 9636 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9637 | lpfc_fabric_abort_hba(phba); |
| 9638 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9639 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9640 | for (i = 0; i < psli->num_rings; i++) { |
| 9641 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9642 | /* Only slow rings */ |
| 9643 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9644 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9645 | /* Set the lpfc data pending flag */ |
| 9646 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9647 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9648 | |
| 9649 | /* |
| 9650 | * Error everything on the txq since these iocbs have not been |
| 9651 | * given to the FW yet. |
| 9652 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9653 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9654 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9655 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9656 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9657 | /* Cancel all the IOCBs from the completions list */ |
| 9658 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9659 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9660 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9661 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9662 | list_splice_init(&phba->elsbuf, &completions); |
| 9663 | phba->elsbuf_cnt = 0; |
| 9664 | phba->elsbuf_prev_cnt = 0; |
| 9665 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9666 | |
| 9667 | while (!list_empty(&completions)) { |
| 9668 | list_remove_head(&completions, buf_ptr, |
| 9669 | struct lpfc_dmabuf, list); |
| 9670 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9671 | kfree(buf_ptr); |
| 9672 | } |
| 9673 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9674 | /* Return any active mbox cmds */ |
| 9675 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9676 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9677 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9678 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9679 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9680 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9681 | return 1; |
| 9682 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9683 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9684 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9685 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9686 | * @srcp: Source memory pointer. |
| 9687 | * @destp: Destination memory pointer. |
| 9688 | * @cnt: Number of words required to be copied. |
| 9689 | * |
| 9690 | * This function is used for copying data between driver memory |
| 9691 | * and the SLI memory. This function also changes the endianness |
| 9692 | * of each word if native endianness is different from SLI |
| 9693 | * endianness. This function can be called with or without |
| 9694 | * lock. |
| 9695 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9696 | void |
| 9697 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9698 | { |
| 9699 | uint32_t *src = srcp; |
| 9700 | uint32_t *dest = destp; |
| 9701 | uint32_t ldata; |
| 9702 | int i; |
| 9703 | |
| 9704 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9705 | ldata = *src; |
| 9706 | ldata = le32_to_cpu(ldata); |
| 9707 | *dest = ldata; |
| 9708 | src++; |
| 9709 | dest++; |
| 9710 | } |
| 9711 | } |
| 9712 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9713 | |
| 9714 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9715 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9716 | * @srcp: Source memory pointer. |
| 9717 | * @destp: Destination memory pointer. |
| 9718 | * @cnt: Number of words required to be copied. |
| 9719 | * |
| 9720 | * This function is used for copying data between a data structure |
| 9721 | * with big endian representation to local endianness. |
| 9722 | * This function can be called with or without lock. |
| 9723 | **/ |
| 9724 | void |
| 9725 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9726 | { |
| 9727 | uint32_t *src = srcp; |
| 9728 | uint32_t *dest = destp; |
| 9729 | uint32_t ldata; |
| 9730 | int i; |
| 9731 | |
| 9732 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9733 | ldata = *src; |
| 9734 | ldata = be32_to_cpu(ldata); |
| 9735 | *dest = ldata; |
| 9736 | src++; |
| 9737 | dest++; |
| 9738 | } |
| 9739 | } |
| 9740 | |
| 9741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9742 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9743 | * @phba: Pointer to HBA context object. |
| 9744 | * @pring: Pointer to driver SLI ring object. |
| 9745 | * @mp: Pointer to driver buffer object. |
| 9746 | * |
| 9747 | * This function is called with no lock held. |
| 9748 | * It always return zero after adding the buffer to the postbufq |
| 9749 | * buffer list. |
| 9750 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9751 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9752 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9753 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9754 | { |
| 9755 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9756 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9757 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9758 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9759 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9760 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9761 | return 0; |
| 9762 | } |
| 9763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9765 | * 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] | 9766 | * @phba: Pointer to HBA context object. |
| 9767 | * |
| 9768 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9769 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9770 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9771 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9772 | * The function returns the allocated tag. The function is called with |
| 9773 | * no locks held. |
| 9774 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9775 | uint32_t |
| 9776 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9777 | { |
| 9778 | spin_lock_irq(&phba->hbalock); |
| 9779 | phba->buffer_tag_count++; |
| 9780 | /* |
| 9781 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9782 | * a tag assigned by HBQ. |
| 9783 | */ |
| 9784 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9785 | spin_unlock_irq(&phba->hbalock); |
| 9786 | return phba->buffer_tag_count; |
| 9787 | } |
| 9788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9790 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9791 | * @phba: Pointer to HBA context object. |
| 9792 | * @pring: Pointer to driver SLI ring object. |
| 9793 | * @tag: Buffer tag. |
| 9794 | * |
| 9795 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9796 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9797 | * iocb is posted to the response ring with the tag of the buffer. |
| 9798 | * This function searches the pring->postbufq list using the tag |
| 9799 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9800 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9801 | * buffer is returned to the caller else NULL is returned. |
| 9802 | * This function is called with no lock held. |
| 9803 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9804 | struct lpfc_dmabuf * |
| 9805 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9806 | uint32_t tag) |
| 9807 | { |
| 9808 | struct lpfc_dmabuf *mp, *next_mp; |
| 9809 | struct list_head *slp = &pring->postbufq; |
| 9810 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9811 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9812 | spin_lock_irq(&phba->hbalock); |
| 9813 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9814 | if (mp->buffer_tag == tag) { |
| 9815 | list_del_init(&mp->list); |
| 9816 | pring->postbufq_cnt--; |
| 9817 | spin_unlock_irq(&phba->hbalock); |
| 9818 | return mp; |
| 9819 | } |
| 9820 | } |
| 9821 | |
| 9822 | spin_unlock_irq(&phba->hbalock); |
| 9823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9824 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9825 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9826 | pring->ringno, (unsigned long) tag, |
| 9827 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9828 | |
| 9829 | return NULL; |
| 9830 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9831 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9832 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9833 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9834 | * @phba: Pointer to HBA context object. |
| 9835 | * @pring: Pointer to driver SLI ring object. |
| 9836 | * @phys: DMA address of the buffer. |
| 9837 | * |
| 9838 | * This function searches the buffer list using the dma_address |
| 9839 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9840 | * corresponding to the dma_address. The function returns the |
| 9841 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9842 | * This function is called by the ct and els unsolicited event |
| 9843 | * handlers to get the buffer associated with the unsolicited |
| 9844 | * event. |
| 9845 | * |
| 9846 | * This function is called with no lock held. |
| 9847 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9848 | struct lpfc_dmabuf * |
| 9849 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9850 | dma_addr_t phys) |
| 9851 | { |
| 9852 | struct lpfc_dmabuf *mp, *next_mp; |
| 9853 | struct list_head *slp = &pring->postbufq; |
| 9854 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9855 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9856 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9857 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9858 | if (mp->phys == phys) { |
| 9859 | list_del_init(&mp->list); |
| 9860 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9861 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9862 | return mp; |
| 9863 | } |
| 9864 | } |
| 9865 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9866 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9867 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9868 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9869 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9870 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9871 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9872 | return NULL; |
| 9873 | } |
| 9874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9876 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9877 | * @phba: Pointer to HBA context object. |
| 9878 | * @cmdiocb: Pointer to driver command iocb object. |
| 9879 | * @rspiocb: Pointer to driver response iocb object. |
| 9880 | * |
| 9881 | * This function is the completion handler for the abort iocbs for |
| 9882 | * ELS commands. This function is called from the ELS ring event |
| 9883 | * handler with no lock held. This function frees memory resources |
| 9884 | * associated with the abort iocb. |
| 9885 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9886 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9887 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9888 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9889 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9890 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9891 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9892 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9893 | |
| 9894 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9895 | |
| 9896 | /* |
| 9897 | * Assume that the port already completed and returned, or |
| 9898 | * will return the iocb. Just Log the message. |
| 9899 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9900 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9901 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9902 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9903 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9904 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9905 | if (abort_iotag != 0 && |
| 9906 | abort_iotag <= phba->sli.last_iotag) |
| 9907 | abort_iocb = |
| 9908 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9909 | } else |
| 9910 | /* For sli4 the abort_tag is the XRI, |
| 9911 | * so the abort routine puts the iotag of the iocb |
| 9912 | * being aborted in the context field of the abort |
| 9913 | * IOCB. |
| 9914 | */ |
| 9915 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9916 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9917 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9918 | "0327 Cannot abort els iocb %p " |
| 9919 | "with tag %x context %x, abort status %x, " |
| 9920 | "abort code %x\n", |
| 9921 | abort_iocb, abort_iotag, abort_context, |
| 9922 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9923 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9924 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9925 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9926 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9927 | return; |
| 9928 | } |
| 9929 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9930 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9931 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9932 | * @phba: Pointer to HBA context object. |
| 9933 | * @cmdiocb: Pointer to driver command iocb object. |
| 9934 | * @rspiocb: Pointer to driver response iocb object. |
| 9935 | * |
| 9936 | * The function is called from SLI ring event handler with no |
| 9937 | * lock held. This function is the completion handler for ELS commands |
| 9938 | * which are aborted. The function frees memory resources used for |
| 9939 | * the aborted ELS commands. |
| 9940 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9941 | static void |
| 9942 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9943 | struct lpfc_iocbq *rspiocb) |
| 9944 | { |
| 9945 | IOCB_t *irsp = &rspiocb->iocb; |
| 9946 | |
| 9947 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9948 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9949 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9950 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9951 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9952 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9953 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9954 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9955 | else |
| 9956 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9957 | return; |
| 9958 | } |
| 9959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9960 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9961 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9962 | * @phba: Pointer to HBA context object. |
| 9963 | * @pring: Pointer to driver SLI ring object. |
| 9964 | * @cmdiocb: Pointer to driver command iocb object. |
| 9965 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9966 | * This function issues an abort iocb for the provided command iocb down to |
| 9967 | * the port. Other than the case the outstanding command iocb is an abort |
| 9968 | * request, this function issues abort out unconditionally. This function is |
| 9969 | * called with hbalock held. The function returns 0 when it fails due to |
| 9970 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9971 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9972 | static int |
| 9973 | 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] | 9974 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9975 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9976 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9977 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9978 | IOCB_t *icmd = NULL; |
| 9979 | IOCB_t *iabt = NULL; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9980 | int ring_number; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9981 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9982 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9983 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9984 | lockdep_assert_held(&phba->hbalock); |
| 9985 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9986 | /* |
| 9987 | * There are certain command types we don't want to abort. And we |
| 9988 | * don't want to abort commands that are already in the process of |
| 9989 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9990 | */ |
| 9991 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9992 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9993 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9994 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9995 | return 0; |
| 9996 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9997 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9998 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9999 | if (abtsiocbp == NULL) |
| 10000 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10001 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10002 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10003 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10004 | */ |
| 10005 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10006 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10007 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10008 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10009 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10010 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10011 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10012 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 10013 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10014 | else |
| 10015 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10016 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10017 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10018 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10019 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10020 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10021 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10022 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10023 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10024 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10025 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10026 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10027 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10028 | else |
| 10029 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10030 | |
| 10031 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10032 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10033 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10034 | "0339 Abort xri x%x, original iotag x%x, " |
| 10035 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10036 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10037 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10038 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10039 | |
| 10040 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10041 | ring_number = |
| 10042 | lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp); |
| 10043 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 10044 | return 0; |
| 10045 | pring = &phba->sli.ring[ring_number]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10046 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10047 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10048 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10049 | abtsiocbp, 0); |
| 10050 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10051 | } else { |
| 10052 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10053 | abtsiocbp, 0); |
| 10054 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10055 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10056 | if (retval) |
| 10057 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10058 | |
| 10059 | /* |
| 10060 | * Caller to this routine should check for IOCB_ERROR |
| 10061 | * and handle it properly. This routine no longer removes |
| 10062 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10063 | */ |
| 10064 | return retval; |
| 10065 | } |
| 10066 | |
| 10067 | /** |
| 10068 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10069 | * @phba: Pointer to HBA context object. |
| 10070 | * @pring: Pointer to driver SLI ring object. |
| 10071 | * @cmdiocb: Pointer to driver command iocb object. |
| 10072 | * |
| 10073 | * This function issues an abort iocb for the provided command iocb. In case |
| 10074 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10075 | * ring. Instead, the callback function shall be changed to those commands |
| 10076 | * so that nothing happens when them finishes. This function is called with |
| 10077 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10078 | * request. |
| 10079 | **/ |
| 10080 | int |
| 10081 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10082 | struct lpfc_iocbq *cmdiocb) |
| 10083 | { |
| 10084 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10085 | int retval = IOCB_ERROR; |
| 10086 | IOCB_t *icmd = NULL; |
| 10087 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10088 | lockdep_assert_held(&phba->hbalock); |
| 10089 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10090 | /* |
| 10091 | * There are certain command types we don't want to abort. And we |
| 10092 | * don't want to abort commands that are already in the process of |
| 10093 | * being aborted. |
| 10094 | */ |
| 10095 | icmd = &cmdiocb->iocb; |
| 10096 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10097 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10098 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10099 | return 0; |
| 10100 | |
| 10101 | /* |
| 10102 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10103 | * the callback so that nothing happens when it finishes. |
| 10104 | */ |
| 10105 | if ((vport->load_flag & FC_UNLOADING) && |
| 10106 | (pring->ringno == LPFC_ELS_RING)) { |
| 10107 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10108 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10109 | else |
| 10110 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10111 | goto abort_iotag_exit; |
| 10112 | } |
| 10113 | |
| 10114 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10115 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10116 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10117 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10118 | /* |
| 10119 | * Caller to this routine should check for IOCB_ERROR |
| 10120 | * and handle it properly. This routine no longer removes |
| 10121 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10122 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10123 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10124 | } |
| 10125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10126 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10127 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10128 | * @phba: pointer to lpfc HBA data structure. |
| 10129 | * |
| 10130 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10131 | **/ |
| 10132 | void |
| 10133 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10134 | { |
| 10135 | struct lpfc_sli *psli = &phba->sli; |
| 10136 | struct lpfc_sli_ring *pring; |
| 10137 | int i; |
| 10138 | |
| 10139 | for (i = 0; i < psli->num_rings; i++) { |
| 10140 | pring = &psli->ring[i]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10141 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10142 | } |
| 10143 | } |
| 10144 | |
| 10145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10146 | * 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] | 10147 | * @iocbq: Pointer to driver iocb object. |
| 10148 | * @vport: Pointer to driver virtual port object. |
| 10149 | * @tgt_id: SCSI ID of the target. |
| 10150 | * @lun_id: LUN ID of the scsi device. |
| 10151 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10152 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10153 | * 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] | 10154 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10155 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10156 | * 1 if the filtering criteria is not met. |
| 10157 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10158 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10159 | * lun_id parameter. |
| 10160 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10161 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10162 | * parameters. |
| 10163 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10164 | * given iocb is for the SCSI host associated with the given vport. |
| 10165 | * This function is called with no locks held. |
| 10166 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10167 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10168 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10169 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10170 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10171 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10172 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10173 | int rc = 1; |
| 10174 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10175 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10176 | return rc; |
| 10177 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10178 | if (iocbq->vport != vport) |
| 10179 | return rc; |
| 10180 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10181 | 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] | 10182 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10183 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10184 | return rc; |
| 10185 | |
| 10186 | switch (ctx_cmd) { |
| 10187 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10188 | if ((lpfc_cmd->rdata->pnode) && |
| 10189 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10190 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10191 | rc = 0; |
| 10192 | break; |
| 10193 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10194 | if ((lpfc_cmd->rdata->pnode) && |
| 10195 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10196 | rc = 0; |
| 10197 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10198 | case LPFC_CTX_HOST: |
| 10199 | rc = 0; |
| 10200 | break; |
| 10201 | default: |
| 10202 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10203 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10204 | break; |
| 10205 | } |
| 10206 | |
| 10207 | return rc; |
| 10208 | } |
| 10209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10211 | * 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] | 10212 | * @vport: Pointer to virtual port. |
| 10213 | * @tgt_id: SCSI ID of the target. |
| 10214 | * @lun_id: LUN ID of the scsi device. |
| 10215 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10216 | * |
| 10217 | * This function returns number of FCP commands pending for the vport. |
| 10218 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10219 | * commands pending on the vport associated with SCSI device specified |
| 10220 | * by tgt_id and lun_id parameters. |
| 10221 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10222 | * commands pending on the vport associated with SCSI target specified |
| 10223 | * by tgt_id parameter. |
| 10224 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10225 | * commands pending on the vport. |
| 10226 | * This function returns the number of iocbs which satisfy the filter. |
| 10227 | * This function is called without any lock held. |
| 10228 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10229 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10230 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10231 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10232 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10233 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10234 | struct lpfc_iocbq *iocbq; |
| 10235 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10236 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10237 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10238 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10239 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10240 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10241 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10242 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10243 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10244 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10245 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10246 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10247 | return sum; |
| 10248 | } |
| 10249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10251 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10252 | * @phba: Pointer to HBA context object |
| 10253 | * @cmdiocb: Pointer to command iocb object. |
| 10254 | * @rspiocb: Pointer to response iocb object. |
| 10255 | * |
| 10256 | * This function is called when an aborted FCP iocb completes. This |
| 10257 | * function is called by the ring event handler with no lock held. |
| 10258 | * This function frees the iocb. |
| 10259 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10260 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10261 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10262 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10263 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10264 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10265 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10266 | "original iotag x%x, abort cmd iotag x%x " |
| 10267 | "status 0x%x, reason 0x%x\n", |
| 10268 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10269 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10270 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10271 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10272 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10273 | return; |
| 10274 | } |
| 10275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10276 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10277 | * 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] | 10278 | * @vport: Pointer to virtual port. |
| 10279 | * @pring: Pointer to driver SLI ring object. |
| 10280 | * @tgt_id: SCSI ID of the target. |
| 10281 | * @lun_id: LUN ID of the scsi device. |
| 10282 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10283 | * |
| 10284 | * This function sends an abort command for every SCSI command |
| 10285 | * associated with the given virtual port pending on the ring |
| 10286 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10287 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10288 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10289 | * parameters |
| 10290 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10291 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10292 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10293 | * FCP iocbs associated with virtual port. |
| 10294 | * This function returns number of iocbs it failed to abort. |
| 10295 | * This function is called with no locks held. |
| 10296 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10297 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10298 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10299 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10300 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10301 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10302 | struct lpfc_iocbq *iocbq; |
| 10303 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10304 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10305 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10306 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10307 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10308 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10309 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10310 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10311 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10312 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10313 | continue; |
| 10314 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10315 | /* |
| 10316 | * If the iocbq is already being aborted, don't take a second |
| 10317 | * action, but do count it. |
| 10318 | */ |
| 10319 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10320 | continue; |
| 10321 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10322 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10323 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10324 | if (abtsiocb == NULL) { |
| 10325 | errcnt++; |
| 10326 | continue; |
| 10327 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10328 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10329 | /* indicate the IO is being aborted by the driver. */ |
| 10330 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10331 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10332 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10333 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10334 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10335 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10336 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 10337 | else |
| 10338 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10339 | abtsiocb->iocb.ulpLe = 1; |
| 10340 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10341 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10342 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10343 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10344 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10345 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10346 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10347 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10348 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10349 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10350 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10351 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10352 | else |
| 10353 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10354 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10355 | /* Setup callback routine and issue the command. */ |
| 10356 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10357 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10358 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10359 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10360 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10361 | errcnt++; |
| 10362 | continue; |
| 10363 | } |
| 10364 | } |
| 10365 | |
| 10366 | return errcnt; |
| 10367 | } |
| 10368 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10369 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10370 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 10371 | * @vport: Pointer to virtual port. |
| 10372 | * @pring: Pointer to driver SLI ring object. |
| 10373 | * @tgt_id: SCSI ID of the target. |
| 10374 | * @lun_id: LUN ID of the scsi device. |
| 10375 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10376 | * |
| 10377 | * This function sends an abort command for every SCSI command |
| 10378 | * associated with the given virtual port pending on the ring |
| 10379 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10380 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10381 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10382 | * parameters |
| 10383 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10384 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10385 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10386 | * FCP iocbs associated with virtual port. |
| 10387 | * This function returns number of iocbs it aborted . |
| 10388 | * This function is called with no locks held right after a taskmgmt |
| 10389 | * command is sent. |
| 10390 | **/ |
| 10391 | int |
| 10392 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10393 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 10394 | { |
| 10395 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10396 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10397 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10398 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10399 | struct lpfc_iocbq *iocbq; |
| 10400 | IOCB_t *icmd; |
| 10401 | int sum, i, ret_val; |
| 10402 | unsigned long iflags; |
| 10403 | struct lpfc_sli_ring *pring_s4; |
| 10404 | uint32_t ring_number; |
| 10405 | |
| 10406 | spin_lock_irq(&phba->hbalock); |
| 10407 | |
| 10408 | /* all I/Os are in process of being flushed */ |
| 10409 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 10410 | spin_unlock_irq(&phba->hbalock); |
| 10411 | return 0; |
| 10412 | } |
| 10413 | sum = 0; |
| 10414 | |
| 10415 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10416 | iocbq = phba->sli.iocbq_lookup[i]; |
| 10417 | |
| 10418 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 10419 | cmd) != 0) |
| 10420 | continue; |
| 10421 | |
| 10422 | /* |
| 10423 | * If the iocbq is already being aborted, don't take a second |
| 10424 | * action, but do count it. |
| 10425 | */ |
| 10426 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10427 | continue; |
| 10428 | |
| 10429 | /* issue ABTS for this IOCB based on iotag */ |
| 10430 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 10431 | if (abtsiocbq == NULL) |
| 10432 | continue; |
| 10433 | |
| 10434 | icmd = &iocbq->iocb; |
| 10435 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10436 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 10437 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10438 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 10439 | iocbq->sli4_xritag; |
| 10440 | else |
| 10441 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 10442 | abtsiocbq->iocb.ulpLe = 1; |
| 10443 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 10444 | abtsiocbq->vport = vport; |
| 10445 | |
| 10446 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10447 | abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx; |
| 10448 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10449 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10450 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10451 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10452 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10453 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 10454 | ndlp = lpfc_cmd->rdata->pnode; |
| 10455 | |
| 10456 | if (lpfc_is_link_up(phba) && |
| 10457 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10458 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10459 | else |
| 10460 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10461 | |
| 10462 | /* Setup callback routine and issue the command. */ |
| 10463 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 10464 | |
| 10465 | /* |
| 10466 | * Indicate the IO is being aborted by the driver and set |
| 10467 | * the caller's flag into the aborted IO. |
| 10468 | */ |
| 10469 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10470 | |
| 10471 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 10472 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 10473 | iocbq->fcp_wqidx; |
| 10474 | pring_s4 = &phba->sli.ring[ring_number]; |
| 10475 | /* Note: both hbalock and ring_lock must be set here */ |
| 10476 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 10477 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 10478 | abtsiocbq, 0); |
| 10479 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 10480 | } else { |
| 10481 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10482 | abtsiocbq, 0); |
| 10483 | } |
| 10484 | |
| 10485 | |
| 10486 | if (ret_val == IOCB_ERROR) |
| 10487 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 10488 | else |
| 10489 | sum++; |
| 10490 | } |
| 10491 | spin_unlock_irq(&phba->hbalock); |
| 10492 | return sum; |
| 10493 | } |
| 10494 | |
| 10495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10496 | * 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] | 10497 | * @phba: Pointer to HBA context object. |
| 10498 | * @cmdiocbq: Pointer to command iocb. |
| 10499 | * @rspiocbq: Pointer to response iocb. |
| 10500 | * |
| 10501 | * This function is the completion handler for iocbs issued using |
| 10502 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 10503 | * ring event handler function without any lock held. This function |
| 10504 | * can be called from both worker thread context and interrupt |
| 10505 | * context. This function also can be called from other thread which |
| 10506 | * cleans up the SLI layer objects. |
| 10507 | * This function copy the contents of the response iocb to the |
| 10508 | * response iocb memory object provided by the caller of |
| 10509 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 10510 | * sleeps for the iocb completion. |
| 10511 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10512 | static void |
| 10513 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 10514 | struct lpfc_iocbq *cmdiocbq, |
| 10515 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10516 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10517 | wait_queue_head_t *pdone_q; |
| 10518 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10519 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10520 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10521 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10522 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 10523 | |
| 10524 | /* |
| 10525 | * A time out has occurred for the iocb. If a time out |
| 10526 | * completion handler has been supplied, call it. Otherwise, |
| 10527 | * just free the iocbq. |
| 10528 | */ |
| 10529 | |
| 10530 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10531 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 10532 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 10533 | if (cmdiocbq->iocb_cmpl) |
| 10534 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 10535 | else |
| 10536 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 10537 | return; |
| 10538 | } |
| 10539 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10540 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 10541 | if (cmdiocbq->context2 && rspiocbq) |
| 10542 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 10543 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 10544 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10545 | /* Set the exchange busy flag for task management commands */ |
| 10546 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 10547 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 10548 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 10549 | cur_iocbq); |
| 10550 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 10551 | } |
| 10552 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10553 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10554 | if (pdone_q) |
| 10555 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10556 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10557 | return; |
| 10558 | } |
| 10559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10560 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10561 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 10562 | * @phba: Pointer to HBA context object.. |
| 10563 | * @piocbq: Pointer to command iocb. |
| 10564 | * @flag: Flag to test. |
| 10565 | * |
| 10566 | * This routine grabs the hbalock and then test the iocb_flag to |
| 10567 | * see if the passed in flag is set. |
| 10568 | * Returns: |
| 10569 | * 1 if flag is set. |
| 10570 | * 0 if flag is not set. |
| 10571 | **/ |
| 10572 | static int |
| 10573 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 10574 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 10575 | { |
| 10576 | unsigned long iflags; |
| 10577 | int ret; |
| 10578 | |
| 10579 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10580 | ret = piocbq->iocb_flag & flag; |
| 10581 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10582 | return ret; |
| 10583 | |
| 10584 | } |
| 10585 | |
| 10586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10587 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10588 | * @phba: Pointer to HBA context object.. |
| 10589 | * @pring: Pointer to sli ring. |
| 10590 | * @piocb: Pointer to command iocb. |
| 10591 | * @prspiocbq: Pointer to response iocb. |
| 10592 | * @timeout: Timeout in number of seconds. |
| 10593 | * |
| 10594 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10595 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 10596 | * to handle iocbs which time out. If the field is NULL, the |
| 10597 | * function shall free the iocbq structure. If more clean up is |
| 10598 | * needed, the caller is expected to provide a completion function |
| 10599 | * that will provide the needed clean up. If the iocb command is |
| 10600 | * not completed within timeout seconds, the function will either |
| 10601 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 10602 | * completion function set in the iocb_cmpl field and then return |
| 10603 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 10604 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10605 | * The function waits for the iocb completion using an |
| 10606 | * non-interruptible wait. |
| 10607 | * This function will sleep while waiting for iocb completion. |
| 10608 | * So, this function should not be called from any context which |
| 10609 | * does not allow sleeping. Due to the same reason, this function |
| 10610 | * cannot be called with interrupt disabled. |
| 10611 | * This function assumes that the iocb completions occur while |
| 10612 | * this function sleep. So, this function cannot be called from |
| 10613 | * the thread which process iocb completion for this ring. |
| 10614 | * This function clears the iocb_flag of the iocb object before |
| 10615 | * issuing the iocb and the iocb completion handler sets this |
| 10616 | * flag and wakes this thread when the iocb completes. |
| 10617 | * The contents of the response iocb will be copied to prspiocbq |
| 10618 | * by the completion handler when the command completes. |
| 10619 | * This function returns IOCB_SUCCESS when success. |
| 10620 | * This function is called with no lock held. |
| 10621 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10622 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10623 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10624 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10625 | struct lpfc_iocbq *piocb, |
| 10626 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10627 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10628 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10629 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10630 | long timeleft, timeout_req = 0; |
| 10631 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10632 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10633 | struct lpfc_iocbq *iocb; |
| 10634 | int txq_cnt = 0; |
| 10635 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10636 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10637 | unsigned long iflags; |
| 10638 | bool iocb_completed = true; |
| 10639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10640 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10641 | * If the caller has provided a response iocbq buffer, then context2 |
| 10642 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10643 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10644 | if (prspiocbq) { |
| 10645 | if (piocb->context2) |
| 10646 | return IOCB_ERROR; |
| 10647 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10648 | } |
| 10649 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10650 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10651 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 10652 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10653 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10654 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10655 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10656 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10657 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10658 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 10659 | writel(creg_val, phba->HCregaddr); |
| 10660 | readl(phba->HCregaddr); /* flush */ |
| 10661 | } |
| 10662 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10663 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10664 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10665 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10666 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10667 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10668 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10669 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10670 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10671 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10672 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10673 | /* |
| 10674 | * IOCB timed out. Inform the wake iocb wait |
| 10675 | * completion function and set local status |
| 10676 | */ |
| 10677 | |
| 10678 | iocb_completed = false; |
| 10679 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 10680 | } |
| 10681 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10682 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10683 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10684 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 10685 | /* Note: we are not indicating if the IOCB has a success |
| 10686 | * status or not - that's for the caller to check. |
| 10687 | * IOCB_SUCCESS means just that the command was sent and |
| 10688 | * completed. Not that it completed successfully. |
| 10689 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10690 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10691 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10692 | "0338 IOCB wait timeout error - no " |
| 10693 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10694 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10695 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10697 | "0330 IOCB wake NOT set, " |
| 10698 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10699 | timeout, (timeleft / jiffies)); |
| 10700 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10701 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10702 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10703 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10704 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10705 | txq_cnt++; |
| 10706 | } |
| 10707 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10708 | txcmplq_cnt++; |
| 10709 | } |
| 10710 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10711 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10712 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10713 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10714 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10715 | } else { |
| 10716 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10717 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10718 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10719 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10720 | } |
| 10721 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10722 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10723 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10724 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10725 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10726 | writel(creg_val, phba->HCregaddr); |
| 10727 | readl(phba->HCregaddr); /* flush */ |
| 10728 | } |
| 10729 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10730 | if (prspiocbq) |
| 10731 | piocb->context2 = NULL; |
| 10732 | |
| 10733 | piocb->context_un.wait_queue = NULL; |
| 10734 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10735 | return retval; |
| 10736 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10737 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10738 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10739 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10740 | * @phba: Pointer to HBA context object. |
| 10741 | * @pmboxq: Pointer to driver mailbox object. |
| 10742 | * @timeout: Timeout in number of seconds. |
| 10743 | * |
| 10744 | * This function issues the mailbox to firmware and waits for the |
| 10745 | * mailbox command to complete. If the mailbox command is not |
| 10746 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10747 | * The function waits for the mailbox completion using an |
| 10748 | * interruptible wait. If the thread is woken up due to a |
| 10749 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10750 | * should not free the mailbox resources, if this function returns |
| 10751 | * MBX_TIMEOUT. |
| 10752 | * This function will sleep while waiting for mailbox completion. |
| 10753 | * So, this function should not be called from any context which |
| 10754 | * does not allow sleeping. Due to the same reason, this function |
| 10755 | * cannot be called with interrupt disabled. |
| 10756 | * This function assumes that the mailbox completion occurs while |
| 10757 | * this function sleep. So, this function cannot be called from |
| 10758 | * the worker thread which processes mailbox completion. |
| 10759 | * This function is called in the context of HBA management |
| 10760 | * applications. |
| 10761 | * This function returns MBX_SUCCESS when successful. |
| 10762 | * This function is called with no lock held. |
| 10763 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10764 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10765 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10766 | uint32_t timeout) |
| 10767 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10768 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10769 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10770 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10771 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10772 | |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10773 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10774 | if (pmboxq->context1) |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10775 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10776 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10777 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10778 | /* setup wake call as IOCB callback */ |
| 10779 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10780 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10781 | pmboxq->context1 = &done_q; |
| 10782 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10783 | /* now issue the command */ |
| 10784 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10785 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10786 | wait_event_interruptible_timeout(done_q, |
| 10787 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10788 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10789 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10790 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10791 | /* restore the possible extended buffer for free resource */ |
| 10792 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10793 | /* |
| 10794 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10795 | * else do not free the resources. |
| 10796 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10797 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10798 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10799 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10800 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10801 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10802 | } |
| 10803 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10804 | } else { |
| 10805 | /* restore the possible extended buffer for free resource */ |
| 10806 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10807 | } |
| 10808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10809 | return retval; |
| 10810 | } |
| 10811 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10812 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10813 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10814 | * @phba: Pointer to HBA context. |
| 10815 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10816 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10817 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10818 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10819 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10820 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10821 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10822 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10823 | * as with offline or HBA function reset), this routine will wait for the |
| 10824 | * outstanding mailbox command to complete before invoking the mailbox |
| 10825 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10826 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10827 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10828 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10829 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10830 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10831 | unsigned long timeout; |
| 10832 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10833 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10834 | /* delay 100ms for port state */ |
| 10835 | msleep(100); |
| 10836 | lpfc_sli_mbox_sys_flush(phba); |
| 10837 | return; |
| 10838 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10839 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10840 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10841 | spin_lock_irq(&phba->hbalock); |
| 10842 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10843 | |
| 10844 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10845 | /* Determine how long we might wait for the active mailbox |
| 10846 | * command to be gracefully completed by firmware. |
| 10847 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10848 | if (phba->sli.mbox_active) |
| 10849 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10850 | phba->sli.mbox_active) * |
| 10851 | 1000) + jiffies; |
| 10852 | spin_unlock_irq(&phba->hbalock); |
| 10853 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10854 | while (phba->sli.mbox_active) { |
| 10855 | /* Check active mailbox complete status every 2ms */ |
| 10856 | msleep(2); |
| 10857 | if (time_after(jiffies, timeout)) |
| 10858 | /* Timeout, let the mailbox flush routine to |
| 10859 | * forcefully release active mailbox command |
| 10860 | */ |
| 10861 | break; |
| 10862 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10863 | } else |
| 10864 | spin_unlock_irq(&phba->hbalock); |
| 10865 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10866 | lpfc_sli_mbox_sys_flush(phba); |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10871 | * @phba: Pointer to HBA context. |
| 10872 | * |
| 10873 | * This function is called to read the SLI3 device error attention registers |
| 10874 | * for possible error attention events. The caller must hold the hostlock |
| 10875 | * with spin_lock_irq(). |
| 10876 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10877 | * 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] | 10878 | * Register and returns 0 otherwise. |
| 10879 | **/ |
| 10880 | static int |
| 10881 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10882 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10883 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10884 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10885 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10886 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10887 | goto unplug_err; |
| 10888 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10889 | if (ha_copy & HA_ERATT) { |
| 10890 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10891 | if (lpfc_sli_read_hs(phba)) |
| 10892 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10893 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10894 | /* Check if there is a deferred error condition is active */ |
| 10895 | if ((HS_FFER1 & phba->work_hs) && |
| 10896 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10897 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10898 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10899 | /* Clear all interrupt enable conditions */ |
| 10900 | writel(0, phba->HCregaddr); |
| 10901 | readl(phba->HCregaddr); |
| 10902 | } |
| 10903 | |
| 10904 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10905 | phba->work_ha |= HA_ERATT; |
| 10906 | /* Indicate polling handles this ERATT */ |
| 10907 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10908 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10909 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10910 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10911 | |
| 10912 | unplug_err: |
| 10913 | /* Set the driver HS work bitmap */ |
| 10914 | phba->work_hs |= UNPLUG_ERR; |
| 10915 | /* Set the driver HA work bitmap */ |
| 10916 | phba->work_ha |= HA_ERATT; |
| 10917 | /* Indicate polling handles this ERATT */ |
| 10918 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10919 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10920 | } |
| 10921 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10922 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10923 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10924 | * @phba: Pointer to HBA context. |
| 10925 | * |
| 10926 | * This function is called to read the SLI4 device error attention registers |
| 10927 | * for possible error attention events. The caller must hold the hostlock |
| 10928 | * with spin_lock_irq(). |
| 10929 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10930 | * 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] | 10931 | * Register and returns 0 otherwise. |
| 10932 | **/ |
| 10933 | static int |
| 10934 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10935 | { |
| 10936 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10937 | uint32_t if_type, portsmphr; |
| 10938 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10939 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10940 | /* |
| 10941 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10942 | * registers for error attention. This can be changed later. |
| 10943 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10944 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10945 | switch (if_type) { |
| 10946 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10947 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10948 | &uerr_sta_lo) || |
| 10949 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10950 | &uerr_sta_hi)) { |
| 10951 | phba->work_hs |= UNPLUG_ERR; |
| 10952 | phba->work_ha |= HA_ERATT; |
| 10953 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10954 | return 1; |
| 10955 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10956 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10957 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10959 | "1423 HBA Unrecoverable error: " |
| 10960 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10961 | "ue_mask_lo_reg=0x%x, " |
| 10962 | "ue_mask_hi_reg=0x%x\n", |
| 10963 | uerr_sta_lo, uerr_sta_hi, |
| 10964 | phba->sli4_hba.ue_mask_lo, |
| 10965 | phba->sli4_hba.ue_mask_hi); |
| 10966 | phba->work_status[0] = uerr_sta_lo; |
| 10967 | phba->work_status[1] = uerr_sta_hi; |
| 10968 | phba->work_ha |= HA_ERATT; |
| 10969 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10970 | return 1; |
| 10971 | } |
| 10972 | break; |
| 10973 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10974 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10975 | &portstat_reg.word0) || |
| 10976 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10977 | &portsmphr)){ |
| 10978 | phba->work_hs |= UNPLUG_ERR; |
| 10979 | phba->work_ha |= HA_ERATT; |
| 10980 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10981 | return 1; |
| 10982 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10983 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10984 | phba->work_status[0] = |
| 10985 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10986 | phba->work_status[1] = |
| 10987 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10989 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10990 | "port status reg 0x%x, " |
| 10991 | "port smphr reg 0x%x, " |
| 10992 | "error 1=0x%x, error 2=0x%x\n", |
| 10993 | portstat_reg.word0, |
| 10994 | portsmphr, |
| 10995 | phba->work_status[0], |
| 10996 | phba->work_status[1]); |
| 10997 | phba->work_ha |= HA_ERATT; |
| 10998 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10999 | return 1; |
| 11000 | } |
| 11001 | break; |
| 11002 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11003 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11005 | "2886 HBA Error Attention on unsupported " |
| 11006 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11007 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11008 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11009 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11010 | return 0; |
| 11011 | } |
| 11012 | |
| 11013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11014 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11015 | * @phba: Pointer to HBA context. |
| 11016 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11017 | * 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] | 11018 | * error attention register bit for error attention events. |
| 11019 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11020 | * 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] | 11021 | * Register and returns 0 otherwise. |
| 11022 | **/ |
| 11023 | int |
| 11024 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11025 | { |
| 11026 | uint32_t ha_copy; |
| 11027 | |
| 11028 | /* If somebody is waiting to handle an eratt, don't process it |
| 11029 | * here. The brdkill function will do this. |
| 11030 | */ |
| 11031 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11032 | return 0; |
| 11033 | |
| 11034 | /* Check if interrupt handler handles this ERATT */ |
| 11035 | spin_lock_irq(&phba->hbalock); |
| 11036 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11037 | /* Interrupt handler has handled ERATT */ |
| 11038 | spin_unlock_irq(&phba->hbalock); |
| 11039 | return 0; |
| 11040 | } |
| 11041 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11042 | /* |
| 11043 | * If there is deferred error attention, do not check for error |
| 11044 | * attention |
| 11045 | */ |
| 11046 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11047 | spin_unlock_irq(&phba->hbalock); |
| 11048 | return 0; |
| 11049 | } |
| 11050 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11051 | /* If PCI channel is offline, don't process it */ |
| 11052 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11053 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11054 | return 0; |
| 11055 | } |
| 11056 | |
| 11057 | switch (phba->sli_rev) { |
| 11058 | case LPFC_SLI_REV2: |
| 11059 | case LPFC_SLI_REV3: |
| 11060 | /* Read chip Host Attention (HA) register */ |
| 11061 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11062 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11063 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11064 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11065 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11066 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11067 | default: |
| 11068 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11069 | "0299 Invalid SLI revision (%d)\n", |
| 11070 | phba->sli_rev); |
| 11071 | ha_copy = 0; |
| 11072 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11073 | } |
| 11074 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11075 | |
| 11076 | return ha_copy; |
| 11077 | } |
| 11078 | |
| 11079 | /** |
| 11080 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 11081 | * @phba: Pointer to HBA context. |
| 11082 | * |
| 11083 | * This inline routine checks whether a device or its PCI slot is in a state |
| 11084 | * that the interrupt should be handled. |
| 11085 | * |
| 11086 | * This function returns 0 if the device or the PCI slot is in a state that |
| 11087 | * interrupt should be handled, otherwise -EIO. |
| 11088 | */ |
| 11089 | static inline int |
| 11090 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 11091 | { |
| 11092 | /* If the pci channel is offline, ignore all the interrupts */ |
| 11093 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 11094 | return -EIO; |
| 11095 | |
| 11096 | /* Update device level interrupt statistics */ |
| 11097 | phba->sli.slistat.sli_intr++; |
| 11098 | |
| 11099 | /* Ignore all interrupts during initialization. */ |
| 11100 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11101 | return -EIO; |
| 11102 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11103 | return 0; |
| 11104 | } |
| 11105 | |
| 11106 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11107 | * 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] | 11108 | * @irq: Interrupt number. |
| 11109 | * @dev_id: The device context pointer. |
| 11110 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11111 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11112 | * service routine when device with SLI-3 interface spec is enabled with |
| 11113 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11114 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11115 | * interrupt mode, this function is called as part of the device-level |
| 11116 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11117 | * is undergoing initialization, the interrupt handler will not process |
| 11118 | * the interrupt. The link attention and ELS ring attention events are |
| 11119 | * handled by the worker thread. The interrupt handler signals the worker |
| 11120 | * thread and returns for these events. This function is called without |
| 11121 | * 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] | 11122 | * structures. |
| 11123 | * |
| 11124 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11125 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11126 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11127 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11128 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11129 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11130 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11131 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11132 | uint32_t work_ha_copy; |
| 11133 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11134 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11135 | uint32_t control; |
| 11136 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11137 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11138 | struct lpfc_vport *vport; |
| 11139 | struct lpfc_nodelist *ndlp; |
| 11140 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11141 | LPFC_MBOXQ_t *pmb; |
| 11142 | int rc; |
| 11143 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11144 | /* |
| 11145 | * Get the driver's phba structure from the dev_id and |
| 11146 | * assume the HBA is not interrupting. |
| 11147 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11148 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11149 | |
| 11150 | if (unlikely(!phba)) |
| 11151 | return IRQ_NONE; |
| 11152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11153 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11154 | * Stuff needs to be attented to when this function is invoked as an |
| 11155 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11156 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11157 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11158 | /* Check device state for handling interrupt */ |
| 11159 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11160 | return IRQ_NONE; |
| 11161 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11162 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11163 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11164 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11165 | /* If somebody is waiting to handle an eratt don't process it |
| 11166 | * here. The brdkill function will do this. |
| 11167 | */ |
| 11168 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11169 | ha_copy &= ~HA_ERATT; |
| 11170 | /* Check the need for handling ERATT in interrupt handler */ |
| 11171 | if (ha_copy & HA_ERATT) { |
| 11172 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11173 | /* ERATT polling has handled ERATT */ |
| 11174 | ha_copy &= ~HA_ERATT; |
| 11175 | else |
| 11176 | /* Indicate interrupt handler handles ERATT */ |
| 11177 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11178 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11179 | |
| 11180 | /* |
| 11181 | * If there is deferred error attention, do not check for any |
| 11182 | * interrupt. |
| 11183 | */ |
| 11184 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11185 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11186 | return IRQ_NONE; |
| 11187 | } |
| 11188 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11189 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11190 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11191 | goto unplug_error; |
| 11192 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11193 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11194 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11195 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11196 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11197 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11198 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11199 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11200 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11201 | } else |
| 11202 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11204 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11205 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11206 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11207 | if (work_ha_copy & HA_LATT) { |
| 11208 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11209 | /* |
| 11210 | * Turn off Link Attention interrupts |
| 11211 | * until CLEAR_LA done |
| 11212 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11213 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11214 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11215 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11216 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11217 | control &= ~HC_LAINT_ENA; |
| 11218 | writel(control, phba->HCregaddr); |
| 11219 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11220 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11221 | } |
| 11222 | else |
| 11223 | work_ha_copy &= ~HA_LATT; |
| 11224 | } |
| 11225 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11226 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11227 | /* |
| 11228 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11229 | * the only slow ring. |
| 11230 | */ |
| 11231 | status = (work_ha_copy & |
| 11232 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11233 | status >>= (4*LPFC_ELS_RING); |
| 11234 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11235 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11236 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11237 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11238 | |
| 11239 | lpfc_debugfs_slow_ring_trc(phba, |
| 11240 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11241 | control, status, |
| 11242 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11243 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11244 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11245 | lpfc_debugfs_slow_ring_trc(phba, |
| 11246 | "ISR Disable ring:" |
| 11247 | "pwork:x%x hawork:x%x wait:x%x", |
| 11248 | phba->work_ha, work_ha_copy, |
| 11249 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11250 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11251 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11252 | control &= |
| 11253 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11254 | writel(control, phba->HCregaddr); |
| 11255 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11256 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11257 | else { |
| 11258 | lpfc_debugfs_slow_ring_trc(phba, |
| 11259 | "ISR slow ring: pwork:" |
| 11260 | "x%x hawork:x%x wait:x%x", |
| 11261 | phba->work_ha, work_ha_copy, |
| 11262 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11263 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11264 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11265 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11266 | } |
| 11267 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11268 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11269 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11270 | if (lpfc_sli_read_hs(phba)) |
| 11271 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11272 | /* |
| 11273 | * Check if there is a deferred error condition |
| 11274 | * is active |
| 11275 | */ |
| 11276 | if ((HS_FFER1 & phba->work_hs) && |
| 11277 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11278 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11279 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11280 | phba->hba_flag |= DEFER_ERATT; |
| 11281 | /* Clear all interrupt enable conditions */ |
| 11282 | writel(0, phba->HCregaddr); |
| 11283 | readl(phba->HCregaddr); |
| 11284 | } |
| 11285 | } |
| 11286 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11287 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11288 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11289 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11290 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11291 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11292 | |
| 11293 | /* First check out the status word */ |
| 11294 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11295 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11296 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11297 | /* |
| 11298 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 11299 | * mbxStatus <status> |
| 11300 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11301 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11302 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11303 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11304 | "Interrupt mbxCommand x%x " |
| 11305 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11306 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11307 | pmbox->mbxCommand, |
| 11308 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11309 | /* clear mailbox attention bit */ |
| 11310 | work_ha_copy &= ~HA_MBATT; |
| 11311 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11312 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11313 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11314 | phba->last_completion_time = jiffies; |
| 11315 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11316 | if (pmb->mbox_cmpl) { |
| 11317 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 11318 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 11319 | if (pmb->out_ext_byte_len && |
| 11320 | pmb->context2) |
| 11321 | lpfc_sli_pcimem_bcopy( |
| 11322 | phba->mbox_ext, |
| 11323 | pmb->context2, |
| 11324 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11325 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11326 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11327 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11328 | |
| 11329 | lpfc_debugfs_disc_trc(vport, |
| 11330 | LPFC_DISC_TRC_MBOX_VPORT, |
| 11331 | "MBOX dflt rpi: : " |
| 11332 | "status:x%x rpi:x%x", |
| 11333 | (uint32_t)pmbox->mbxStatus, |
| 11334 | pmbox->un.varWords[0], 0); |
| 11335 | |
| 11336 | if (!pmbox->mbxStatus) { |
| 11337 | mp = (struct lpfc_dmabuf *) |
| 11338 | (pmb->context1); |
| 11339 | ndlp = (struct lpfc_nodelist *) |
| 11340 | pmb->context2; |
| 11341 | |
| 11342 | /* Reg_LOGIN of dflt RPI was |
| 11343 | * successful. new lets get |
| 11344 | * rid of the RPI using the |
| 11345 | * same mbox buffer. |
| 11346 | */ |
| 11347 | lpfc_unreg_login(phba, |
| 11348 | vport->vpi, |
| 11349 | pmbox->un.varWords[0], |
| 11350 | pmb); |
| 11351 | pmb->mbox_cmpl = |
| 11352 | lpfc_mbx_cmpl_dflt_rpi; |
| 11353 | pmb->context1 = mp; |
| 11354 | pmb->context2 = ndlp; |
| 11355 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11356 | rc = lpfc_sli_issue_mbox(phba, |
| 11357 | pmb, |
| 11358 | MBX_NOWAIT); |
| 11359 | if (rc != MBX_BUSY) |
| 11360 | lpfc_printf_log(phba, |
| 11361 | KERN_ERR, |
| 11362 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11363 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11364 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11365 | if (rc != MBX_NOT_FINISHED) |
| 11366 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11367 | } |
| 11368 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11369 | spin_lock_irqsave( |
| 11370 | &phba->pport->work_port_lock, |
| 11371 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11372 | phba->pport->work_port_events &= |
| 11373 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11374 | spin_unlock_irqrestore( |
| 11375 | &phba->pport->work_port_lock, |
| 11376 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11377 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11378 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11379 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11380 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11381 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11382 | if ((work_ha_copy & HA_MBATT) && |
| 11383 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11384 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11385 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11386 | do { |
| 11387 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 11388 | MBX_NOWAIT); |
| 11389 | } while (rc == MBX_NOT_FINISHED); |
| 11390 | if (rc != MBX_SUCCESS) |
| 11391 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11392 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11393 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11394 | } |
| 11395 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11396 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11397 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11398 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11399 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11400 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11401 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11402 | unplug_error: |
| 11403 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11404 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11405 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11406 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11407 | |
| 11408 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11409 | * 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] | 11410 | * @irq: Interrupt number. |
| 11411 | * @dev_id: The device context pointer. |
| 11412 | * |
| 11413 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11414 | * service routine when device with SLI-3 interface spec is enabled with |
| 11415 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11416 | * ring event in the HBA. However, when the device is enabled with either |
| 11417 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11418 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11419 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11420 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11421 | * the intrrupt context. This function is called without any lock held. |
| 11422 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11423 | * |
| 11424 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11425 | * returns IRQ_NONE. |
| 11426 | **/ |
| 11427 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11428 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11429 | { |
| 11430 | struct lpfc_hba *phba; |
| 11431 | uint32_t ha_copy; |
| 11432 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11433 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11434 | |
| 11435 | /* Get the driver's phba structure from the dev_id and |
| 11436 | * assume the HBA is not interrupting. |
| 11437 | */ |
| 11438 | phba = (struct lpfc_hba *) dev_id; |
| 11439 | |
| 11440 | if (unlikely(!phba)) |
| 11441 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11442 | |
| 11443 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11444 | * Stuff needs to be attented to when this function is invoked as an |
| 11445 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11446 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11447 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11448 | /* Check device state for handling interrupt */ |
| 11449 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11450 | return IRQ_NONE; |
| 11451 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11452 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11453 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11454 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11455 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11456 | /* |
| 11457 | * If there is deferred error attention, do not check for |
| 11458 | * any interrupt. |
| 11459 | */ |
| 11460 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11461 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11462 | return IRQ_NONE; |
| 11463 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11464 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 11465 | phba->HAregaddr); |
| 11466 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11467 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11468 | } else |
| 11469 | ha_copy = phba->ha_copy; |
| 11470 | |
| 11471 | /* |
| 11472 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 11473 | */ |
| 11474 | ha_copy &= ~(phba->work_ha_mask); |
| 11475 | |
| 11476 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11477 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11478 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11479 | lpfc_sli_handle_fast_ring_event(phba, |
| 11480 | &phba->sli.ring[LPFC_FCP_RING], |
| 11481 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11482 | |
| 11483 | if (phba->cfg_multi_ring_support == 2) { |
| 11484 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11485 | * Process all events on extra ring. Take the optimized path |
| 11486 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11487 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11488 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11489 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11490 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11491 | lpfc_sli_handle_fast_ring_event(phba, |
| 11492 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 11493 | status); |
| 11494 | } |
| 11495 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11496 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11497 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11498 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11499 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11500 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11501 | * @irq: Interrupt number. |
| 11502 | * @dev_id: The device context pointer. |
| 11503 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11504 | * This function is the HBA device-level interrupt handler to device with |
| 11505 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 11506 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 11507 | * requires driver attention. This function invokes the slow-path interrupt |
| 11508 | * attention handling function and fast-path interrupt attention handling |
| 11509 | * function in turn to process the relevant HBA attention events. This |
| 11510 | * function is called without any lock held. It gets the hbalock to access |
| 11511 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11512 | * |
| 11513 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11514 | * returns IRQ_NONE. |
| 11515 | **/ |
| 11516 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11517 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11518 | { |
| 11519 | struct lpfc_hba *phba; |
| 11520 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11521 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11522 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11523 | |
| 11524 | /* |
| 11525 | * Get the driver's phba structure from the dev_id and |
| 11526 | * assume the HBA is not interrupting. |
| 11527 | */ |
| 11528 | phba = (struct lpfc_hba *) dev_id; |
| 11529 | |
| 11530 | if (unlikely(!phba)) |
| 11531 | return IRQ_NONE; |
| 11532 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11533 | /* Check device state for handling interrupt */ |
| 11534 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11535 | return IRQ_NONE; |
| 11536 | |
| 11537 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11538 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 11539 | spin_unlock(&phba->hbalock); |
| 11540 | return IRQ_HANDLED; |
| 11541 | } |
| 11542 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11543 | if (unlikely(!phba->ha_copy)) { |
| 11544 | spin_unlock(&phba->hbalock); |
| 11545 | return IRQ_NONE; |
| 11546 | } else if (phba->ha_copy & HA_ERATT) { |
| 11547 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11548 | /* ERATT polling has handled ERATT */ |
| 11549 | phba->ha_copy &= ~HA_ERATT; |
| 11550 | else |
| 11551 | /* Indicate interrupt handler handles ERATT */ |
| 11552 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11553 | } |
| 11554 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11555 | /* |
| 11556 | * If there is deferred error attention, do not check for any interrupt. |
| 11557 | */ |
| 11558 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 11559 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11560 | return IRQ_NONE; |
| 11561 | } |
| 11562 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11563 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11564 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 11565 | spin_unlock(&phba->hbalock); |
| 11566 | return IRQ_HANDLED; |
| 11567 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11568 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 11569 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11570 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11571 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11572 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11573 | readl(phba->HAregaddr); /* flush */ |
| 11574 | spin_unlock(&phba->hbalock); |
| 11575 | |
| 11576 | /* |
| 11577 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11578 | */ |
| 11579 | |
| 11580 | /* status of events with mailbox and link attention */ |
| 11581 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 11582 | |
| 11583 | /* status of events with ELS ring */ |
| 11584 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11585 | status2 >>= (4*LPFC_ELS_RING); |
| 11586 | |
| 11587 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11588 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11589 | else |
| 11590 | sp_irq_rc = IRQ_NONE; |
| 11591 | |
| 11592 | /* |
| 11593 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11594 | */ |
| 11595 | |
| 11596 | /* status of events with FCP ring */ |
| 11597 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 11598 | status1 >>= (4*LPFC_FCP_RING); |
| 11599 | |
| 11600 | /* status of events with extra ring */ |
| 11601 | if (phba->cfg_multi_ring_support == 2) { |
| 11602 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 11603 | status2 >>= (4*LPFC_EXTRA_RING); |
| 11604 | } else |
| 11605 | status2 = 0; |
| 11606 | |
| 11607 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11608 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11609 | else |
| 11610 | fp_irq_rc = IRQ_NONE; |
| 11611 | |
| 11612 | /* Return device-level interrupt handling status */ |
| 11613 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11614 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11615 | |
| 11616 | /** |
| 11617 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 11618 | * @phba: pointer to lpfc hba data structure. |
| 11619 | * |
| 11620 | * This routine is invoked by the worker thread to process all the pending |
| 11621 | * SLI4 FCP abort XRI events. |
| 11622 | **/ |
| 11623 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11624 | { |
| 11625 | struct lpfc_cq_event *cq_event; |
| 11626 | |
| 11627 | /* First, declare the fcp xri abort event has been handled */ |
| 11628 | spin_lock_irq(&phba->hbalock); |
| 11629 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 11630 | spin_unlock_irq(&phba->hbalock); |
| 11631 | /* Now, handle all the fcp xri abort events */ |
| 11632 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 11633 | /* Get the first event from the head of the event queue */ |
| 11634 | spin_lock_irq(&phba->hbalock); |
| 11635 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 11636 | cq_event, struct lpfc_cq_event, list); |
| 11637 | spin_unlock_irq(&phba->hbalock); |
| 11638 | /* Notify aborted XRI for FCP work queue */ |
| 11639 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11640 | /* Free the event processed back to the free pool */ |
| 11641 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11642 | } |
| 11643 | } |
| 11644 | |
| 11645 | /** |
| 11646 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 11647 | * @phba: pointer to lpfc hba data structure. |
| 11648 | * |
| 11649 | * This routine is invoked by the worker thread to process all the pending |
| 11650 | * SLI4 els abort xri events. |
| 11651 | **/ |
| 11652 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11653 | { |
| 11654 | struct lpfc_cq_event *cq_event; |
| 11655 | |
| 11656 | /* First, declare the els xri abort event has been handled */ |
| 11657 | spin_lock_irq(&phba->hbalock); |
| 11658 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 11659 | spin_unlock_irq(&phba->hbalock); |
| 11660 | /* Now, handle all the els xri abort events */ |
| 11661 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 11662 | /* Get the first event from the head of the event queue */ |
| 11663 | spin_lock_irq(&phba->hbalock); |
| 11664 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11665 | cq_event, struct lpfc_cq_event, list); |
| 11666 | spin_unlock_irq(&phba->hbalock); |
| 11667 | /* Notify aborted XRI for ELS work queue */ |
| 11668 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11669 | /* Free the event processed back to the free pool */ |
| 11670 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11671 | } |
| 11672 | } |
| 11673 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11674 | /** |
| 11675 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 11676 | * @phba: pointer to lpfc hba data structure |
| 11677 | * @pIocbIn: pointer to the rspiocbq |
| 11678 | * @pIocbOut: pointer to the cmdiocbq |
| 11679 | * @wcqe: pointer to the complete wcqe |
| 11680 | * |
| 11681 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11682 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11683 | * completion status information from the complete wcqe. |
| 11684 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11685 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11686 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11687 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11688 | struct lpfc_iocbq *pIocbOut, |
| 11689 | struct lpfc_wcqe_complete *wcqe) |
| 11690 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11691 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11692 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11693 | uint32_t status, max_response; |
| 11694 | struct lpfc_dmabuf *dmabuf; |
| 11695 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11696 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11697 | |
| 11698 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11699 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11700 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11701 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11702 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11703 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11704 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11705 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11706 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11707 | wcqe->total_data_placed; |
| 11708 | else |
| 11709 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11710 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11711 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11712 | switch (pIocbOut->iocb.ulpCommand) { |
| 11713 | case CMD_ELS_REQUEST64_CR: |
| 11714 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11715 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11716 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 11717 | max_response = bde.tus.f.bdeSize; |
| 11718 | break; |
| 11719 | case CMD_GEN_REQUEST64_CR: |
| 11720 | max_response = 0; |
| 11721 | if (!pIocbOut->context3) |
| 11722 | break; |
| 11723 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 11724 | sizeof(struct ulp_bde64); |
| 11725 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11726 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11727 | for (i = 0; i < numBdes; i++) { |
| 11728 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 11729 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 11730 | max_response += bde.tus.f.bdeSize; |
| 11731 | } |
| 11732 | break; |
| 11733 | default: |
| 11734 | max_response = wcqe->total_data_placed; |
| 11735 | break; |
| 11736 | } |
| 11737 | if (max_response < wcqe->total_data_placed) |
| 11738 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 11739 | else |
| 11740 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 11741 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11742 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11743 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11744 | /* Convert BG errors for completion status */ |
| 11745 | if (status == CQE_STATUS_DI_ERROR) { |
| 11746 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11747 | |
| 11748 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11749 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11750 | else |
| 11751 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11752 | |
| 11753 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11754 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11755 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11756 | BGS_GUARD_ERR_MASK; |
| 11757 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11758 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11759 | BGS_APPTAG_ERR_MASK; |
| 11760 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11761 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11762 | BGS_REFTAG_ERR_MASK; |
| 11763 | |
| 11764 | /* Check to see if there was any good data before the error */ |
| 11765 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11766 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11767 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11768 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11769 | wcqe->total_data_placed; |
| 11770 | } |
| 11771 | |
| 11772 | /* |
| 11773 | * Set ALL the error bits to indicate we don't know what |
| 11774 | * type of error it is. |
| 11775 | */ |
| 11776 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11777 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11778 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11779 | BGS_GUARD_ERR_MASK); |
| 11780 | } |
| 11781 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11782 | /* Pick up HBA exchange busy condition */ |
| 11783 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11784 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11785 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11786 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11787 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11788 | } |
| 11789 | |
| 11790 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11791 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11792 | * @phba: Pointer to HBA context object. |
| 11793 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11794 | * |
| 11795 | * This routine handles an ELS work-queue completion event and construct |
| 11796 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11797 | * discovery engine to handle. |
| 11798 | * |
| 11799 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11800 | **/ |
| 11801 | static struct lpfc_iocbq * |
| 11802 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11803 | struct lpfc_iocbq *irspiocbq) |
| 11804 | { |
| 11805 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11806 | struct lpfc_iocbq *cmdiocbq; |
| 11807 | struct lpfc_wcqe_complete *wcqe; |
| 11808 | unsigned long iflags; |
| 11809 | |
| 11810 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11811 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11812 | pring->stats.iocb_event++; |
| 11813 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11814 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11815 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 11816 | /* Put the iocb back on the txcmplq */ |
| 11817 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11818 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11819 | |
| 11820 | if (unlikely(!cmdiocbq)) { |
| 11821 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11822 | "0386 ELS complete with no corresponding " |
| 11823 | "cmdiocb: iotag (%d)\n", |
| 11824 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11825 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11826 | return NULL; |
| 11827 | } |
| 11828 | |
| 11829 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11830 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11831 | |
| 11832 | return irspiocbq; |
| 11833 | } |
| 11834 | |
| 11835 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11836 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11837 | * @phba: Pointer to HBA context object. |
| 11838 | * @cqe: Pointer to mailbox completion queue entry. |
| 11839 | * |
| 11840 | * This routine process a mailbox completion queue entry with asynchrous |
| 11841 | * event. |
| 11842 | * |
| 11843 | * Return: true if work posted to worker thread, otherwise false. |
| 11844 | **/ |
| 11845 | static bool |
| 11846 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11847 | { |
| 11848 | struct lpfc_cq_event *cq_event; |
| 11849 | unsigned long iflags; |
| 11850 | |
| 11851 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11852 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11853 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11854 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11855 | |
| 11856 | /* Allocate a new internal CQ_EVENT entry */ |
| 11857 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11858 | if (!cq_event) { |
| 11859 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11860 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11861 | return false; |
| 11862 | } |
| 11863 | |
| 11864 | /* Move the CQE into an asynchronous event entry */ |
| 11865 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11866 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11867 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11868 | /* Set the async event flag */ |
| 11869 | phba->hba_flag |= ASYNC_EVENT; |
| 11870 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11871 | |
| 11872 | return true; |
| 11873 | } |
| 11874 | |
| 11875 | /** |
| 11876 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11877 | * @phba: Pointer to HBA context object. |
| 11878 | * @cqe: Pointer to mailbox completion queue entry. |
| 11879 | * |
| 11880 | * This routine process a mailbox completion queue entry with mailbox |
| 11881 | * completion event. |
| 11882 | * |
| 11883 | * Return: true if work posted to worker thread, otherwise false. |
| 11884 | **/ |
| 11885 | static bool |
| 11886 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11887 | { |
| 11888 | uint32_t mcqe_status; |
| 11889 | MAILBOX_t *mbox, *pmbox; |
| 11890 | struct lpfc_mqe *mqe; |
| 11891 | struct lpfc_vport *vport; |
| 11892 | struct lpfc_nodelist *ndlp; |
| 11893 | struct lpfc_dmabuf *mp; |
| 11894 | unsigned long iflags; |
| 11895 | LPFC_MBOXQ_t *pmb; |
| 11896 | bool workposted = false; |
| 11897 | int rc; |
| 11898 | |
| 11899 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11900 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11901 | goto out_no_mqe_complete; |
| 11902 | |
| 11903 | /* Get the reference to the active mbox command */ |
| 11904 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11905 | pmb = phba->sli.mbox_active; |
| 11906 | if (unlikely(!pmb)) { |
| 11907 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11908 | "1832 No pending MBOX command to handle\n"); |
| 11909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11910 | goto out_no_mqe_complete; |
| 11911 | } |
| 11912 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11913 | mqe = &pmb->u.mqe; |
| 11914 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11915 | mbox = phba->mbox; |
| 11916 | vport = pmb->vport; |
| 11917 | |
| 11918 | /* Reset heartbeat timer */ |
| 11919 | phba->last_completion_time = jiffies; |
| 11920 | del_timer(&phba->sli.mbox_tmo); |
| 11921 | |
| 11922 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11923 | if (pmb->mbox_cmpl && mbox) |
| 11924 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11925 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11926 | /* |
| 11927 | * For mcqe errors, conditionally move a modified error code to |
| 11928 | * the mbox so that the error will not be missed. |
| 11929 | */ |
| 11930 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11931 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11932 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11933 | bf_set(lpfc_mqe_status, mqe, |
| 11934 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11935 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11936 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11937 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11938 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11939 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11940 | mcqe_status, |
| 11941 | pmbox->un.varWords[0], 0); |
| 11942 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11943 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11944 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11945 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11946 | * RID of the PPI using the same mbox buffer. |
| 11947 | */ |
| 11948 | lpfc_unreg_login(phba, vport->vpi, |
| 11949 | pmbox->un.varWords[0], pmb); |
| 11950 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11951 | pmb->context1 = mp; |
| 11952 | pmb->context2 = ndlp; |
| 11953 | pmb->vport = vport; |
| 11954 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11955 | if (rc != MBX_BUSY) |
| 11956 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11957 | LOG_SLI, "0385 rc should " |
| 11958 | "have been MBX_BUSY\n"); |
| 11959 | if (rc != MBX_NOT_FINISHED) |
| 11960 | goto send_current_mbox; |
| 11961 | } |
| 11962 | } |
| 11963 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11964 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11965 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11966 | |
| 11967 | /* There is mailbox completion work to do */ |
| 11968 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11969 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11970 | phba->work_ha |= HA_MBATT; |
| 11971 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11972 | workposted = true; |
| 11973 | |
| 11974 | send_current_mbox: |
| 11975 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11976 | /* Release the mailbox command posting token */ |
| 11977 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11978 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11979 | phba->sli.mbox_active = NULL; |
| 11980 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11981 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11982 | lpfc_worker_wake_up(phba); |
| 11983 | out_no_mqe_complete: |
| 11984 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11985 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11986 | return workposted; |
| 11987 | } |
| 11988 | |
| 11989 | /** |
| 11990 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11991 | * @phba: Pointer to HBA context object. |
| 11992 | * @cqe: Pointer to mailbox completion queue entry. |
| 11993 | * |
| 11994 | * This routine process a mailbox completion queue entry, it invokes the |
| 11995 | * proper mailbox complete handling or asynchrous event handling routine |
| 11996 | * according to the MCQE's async bit. |
| 11997 | * |
| 11998 | * Return: true if work posted to worker thread, otherwise false. |
| 11999 | **/ |
| 12000 | static bool |
| 12001 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 12002 | { |
| 12003 | struct lpfc_mcqe mcqe; |
| 12004 | bool workposted; |
| 12005 | |
| 12006 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 12007 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 12008 | |
| 12009 | /* Invoke the proper event handling routine */ |
| 12010 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 12011 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 12012 | else |
| 12013 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 12014 | return workposted; |
| 12015 | } |
| 12016 | |
| 12017 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12018 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 12019 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12020 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12021 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12022 | * |
| 12023 | * This routine handles an ELS work-queue completion event. |
| 12024 | * |
| 12025 | * Return: true if work posted to worker thread, otherwise false. |
| 12026 | **/ |
| 12027 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12028 | 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] | 12029 | struct lpfc_wcqe_complete *wcqe) |
| 12030 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12031 | struct lpfc_iocbq *irspiocbq; |
| 12032 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12033 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12034 | int txq_cnt = 0; |
| 12035 | int txcmplq_cnt = 0; |
| 12036 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12037 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12038 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12039 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12040 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12041 | if (!list_empty(&pring->txq)) |
| 12042 | txq_cnt++; |
| 12043 | if (!list_empty(&pring->txcmplq)) |
| 12044 | txcmplq_cnt++; |
| 12045 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 12046 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12047 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12048 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12049 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12050 | txq_cnt, phba->iocb_cnt, |
| 12051 | fcp_txcmplq_cnt, |
| 12052 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12053 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12054 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12055 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12056 | /* Save off the slow-path queue event for work thread to process */ |
| 12057 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12058 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12059 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12060 | &phba->sli4_hba.sp_queue_event); |
| 12061 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12062 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12063 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12064 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12065 | } |
| 12066 | |
| 12067 | /** |
| 12068 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 12069 | * @phba: Pointer to HBA context object. |
| 12070 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12071 | * |
| 12072 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 12073 | * proper WQ release routine to the slow-path WQ. |
| 12074 | **/ |
| 12075 | static void |
| 12076 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 12077 | struct lpfc_wcqe_release *wcqe) |
| 12078 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12079 | /* sanity check on queue memory */ |
| 12080 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 12081 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12082 | /* Check for the slow-path ELS work queue */ |
| 12083 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 12084 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 12085 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12086 | else |
| 12087 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12088 | "2579 Slow-path wqe consume event carries " |
| 12089 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 12090 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 12091 | phba->sli4_hba.els_wq->queue_id); |
| 12092 | } |
| 12093 | |
| 12094 | /** |
| 12095 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 12096 | * @phba: Pointer to HBA context object. |
| 12097 | * @cq: Pointer to a WQ completion queue. |
| 12098 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12099 | * |
| 12100 | * This routine handles an XRI abort event. |
| 12101 | * |
| 12102 | * Return: true if work posted to worker thread, otherwise false. |
| 12103 | **/ |
| 12104 | static bool |
| 12105 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12106 | struct lpfc_queue *cq, |
| 12107 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12108 | { |
| 12109 | bool workposted = false; |
| 12110 | struct lpfc_cq_event *cq_event; |
| 12111 | unsigned long iflags; |
| 12112 | |
| 12113 | /* Allocate a new internal CQ_EVENT entry */ |
| 12114 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12115 | if (!cq_event) { |
| 12116 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12117 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 12118 | return false; |
| 12119 | } |
| 12120 | |
| 12121 | /* Move the CQE into the proper xri abort event list */ |
| 12122 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12123 | switch (cq->subtype) { |
| 12124 | case LPFC_FCP: |
| 12125 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12126 | list_add_tail(&cq_event->list, |
| 12127 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12128 | /* Set the fcp xri abort event flag */ |
| 12129 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12130 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12131 | workposted = true; |
| 12132 | break; |
| 12133 | case LPFC_ELS: |
| 12134 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12135 | list_add_tail(&cq_event->list, |
| 12136 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12137 | /* Set the els xri abort event flag */ |
| 12138 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12139 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12140 | workposted = true; |
| 12141 | break; |
| 12142 | default: |
| 12143 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12144 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 12145 | cq->subtype); |
| 12146 | workposted = false; |
| 12147 | break; |
| 12148 | } |
| 12149 | return workposted; |
| 12150 | } |
| 12151 | |
| 12152 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12153 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12154 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12155 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12156 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12157 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12158 | * |
| 12159 | * Return: true if work posted to worker thread, otherwise false. |
| 12160 | **/ |
| 12161 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12162 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12163 | { |
| 12164 | bool workposted = false; |
| 12165 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12166 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 12167 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12168 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12169 | unsigned long iflags; |
| 12170 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12171 | /* sanity check on queue memory */ |
| 12172 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12173 | return workposted; |
| 12174 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12175 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12176 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12177 | else |
| 12178 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12179 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12180 | goto out; |
| 12181 | |
| 12182 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12183 | switch (status) { |
| 12184 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12185 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12186 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12187 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12188 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12189 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12190 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12191 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12192 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12193 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12194 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12195 | goto out; |
| 12196 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12197 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12198 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 12199 | /* save off the frame for the word thread to process */ |
| 12200 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12201 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12202 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12203 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12204 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12205 | workposted = true; |
| 12206 | break; |
| 12207 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 12208 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12209 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12210 | /* Post more buffers if possible */ |
| 12211 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12212 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12213 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12214 | workposted = true; |
| 12215 | break; |
| 12216 | } |
| 12217 | out: |
| 12218 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12219 | } |
| 12220 | |
| 12221 | /** |
| 12222 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12223 | * @phba: Pointer to HBA context object. |
| 12224 | * @cq: Pointer to the completion queue. |
| 12225 | * @wcqe: Pointer to a completion queue entry. |
| 12226 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12227 | * 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] | 12228 | * entry. |
| 12229 | * |
| 12230 | * Return: true if work posted to worker thread, otherwise false. |
| 12231 | **/ |
| 12232 | static bool |
| 12233 | 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] | 12234 | struct lpfc_cqe *cqe) |
| 12235 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12236 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12237 | bool workposted = false; |
| 12238 | |
| 12239 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12240 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12241 | |
| 12242 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12243 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12244 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12245 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12246 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12247 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12248 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12249 | break; |
| 12250 | case CQE_CODE_RELEASE_WQE: |
| 12251 | /* Process the WQ release event */ |
| 12252 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12253 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12254 | break; |
| 12255 | case CQE_CODE_XRI_ABORTED: |
| 12256 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12257 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12258 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12259 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12260 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12261 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12262 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12263 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12264 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12265 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12266 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12267 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12268 | default: |
| 12269 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12270 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12271 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12272 | break; |
| 12273 | } |
| 12274 | return workposted; |
| 12275 | } |
| 12276 | |
| 12277 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12278 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 12279 | * @phba: Pointer to HBA context object. |
| 12280 | * @eqe: Pointer to fast-path event queue entry. |
| 12281 | * |
| 12282 | * This routine process a event queue entry from the slow-path event queue. |
| 12283 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12284 | * completion event on a completion queue, if not, an error shall be logged |
| 12285 | * and just return. Otherwise, it will get to the corresponding completion |
| 12286 | * queue and process all the entries on that completion queue, rearm the |
| 12287 | * completion queue, and then return. |
| 12288 | * |
| 12289 | **/ |
| 12290 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12291 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12292 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12293 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12294 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12295 | struct lpfc_cqe *cqe; |
| 12296 | bool workposted = false; |
| 12297 | int ecount = 0; |
| 12298 | uint16_t cqid; |
| 12299 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12300 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12301 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12302 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12303 | list_for_each_entry(childq, &speq->child_list, list) { |
| 12304 | if (childq->queue_id == cqid) { |
| 12305 | cq = childq; |
| 12306 | break; |
| 12307 | } |
| 12308 | } |
| 12309 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12310 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12311 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12312 | "0365 Slow-path CQ identifier " |
| 12313 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12314 | return; |
| 12315 | } |
| 12316 | |
| 12317 | /* Process all the entries to the CQ */ |
| 12318 | switch (cq->type) { |
| 12319 | case LPFC_MCQ: |
| 12320 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12321 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12322 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12323 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12324 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12325 | } |
| 12326 | break; |
| 12327 | case LPFC_WCQ: |
| 12328 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12329 | if (cq->subtype == LPFC_FCP) |
| 12330 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 12331 | cqe); |
| 12332 | else |
| 12333 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 12334 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12335 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12336 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12337 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12338 | |
| 12339 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12340 | if (ecount > cq->CQ_max_cqe) |
| 12341 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12342 | break; |
| 12343 | default: |
| 12344 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12345 | "0370 Invalid completion queue type (%d)\n", |
| 12346 | cq->type); |
| 12347 | return; |
| 12348 | } |
| 12349 | |
| 12350 | /* Catch the no cq entry condition, log an error */ |
| 12351 | if (unlikely(ecount == 0)) |
| 12352 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12353 | "0371 No entry from the CQ: identifier " |
| 12354 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 12355 | |
| 12356 | /* In any case, flash and re-arm the RCQ */ |
| 12357 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12358 | |
| 12359 | /* wake up worker thread if there are works to be done */ |
| 12360 | if (workposted) |
| 12361 | lpfc_worker_wake_up(phba); |
| 12362 | } |
| 12363 | |
| 12364 | /** |
| 12365 | * 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] | 12366 | * @phba: Pointer to HBA context object. |
| 12367 | * @cq: Pointer to associated CQ |
| 12368 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12369 | * |
| 12370 | * This routine process a fast-path work queue completion entry from fast-path |
| 12371 | * event queue for FCP command response completion. |
| 12372 | **/ |
| 12373 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12374 | 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] | 12375 | struct lpfc_wcqe_complete *wcqe) |
| 12376 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12377 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12378 | struct lpfc_iocbq *cmdiocbq; |
| 12379 | struct lpfc_iocbq irspiocbq; |
| 12380 | unsigned long iflags; |
| 12381 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12382 | /* Check for response status */ |
| 12383 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 12384 | /* If resource errors reported from HBA, reduce queue |
| 12385 | * depth of the SCSI device. |
| 12386 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12387 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 12388 | IOSTAT_LOCAL_REJECT)) && |
| 12389 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 12390 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12391 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12392 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12393 | /* Log the error status */ |
| 12394 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12395 | "0373 FCP complete error: status=x%x, " |
| 12396 | "hw_status=x%x, total_data_specified=%d, " |
| 12397 | "parameter=x%x, word3=x%x\n", |
| 12398 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 12399 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 12400 | wcqe->total_data_placed, wcqe->parameter, |
| 12401 | wcqe->word3); |
| 12402 | } |
| 12403 | |
| 12404 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12405 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 12406 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12407 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12408 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12409 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12410 | if (unlikely(!cmdiocbq)) { |
| 12411 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12412 | "0374 FCP complete with no corresponding " |
| 12413 | "cmdiocb: iotag (%d)\n", |
| 12414 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12415 | return; |
| 12416 | } |
| 12417 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 12418 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12419 | "0375 FCP cmdiocb not callback function " |
| 12420 | "iotag: (%d)\n", |
| 12421 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12422 | return; |
| 12423 | } |
| 12424 | |
| 12425 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12426 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12427 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12428 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 12429 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12430 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 12431 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12432 | } |
| 12433 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12434 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 12435 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 12436 | } |
| 12437 | |
| 12438 | /** |
| 12439 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 12440 | * @phba: Pointer to HBA context object. |
| 12441 | * @cq: Pointer to completion queue. |
| 12442 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12443 | * |
| 12444 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 12445 | * proper WQ release routine to the slow-path WQ. |
| 12446 | **/ |
| 12447 | static void |
| 12448 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12449 | struct lpfc_wcqe_release *wcqe) |
| 12450 | { |
| 12451 | struct lpfc_queue *childwq; |
| 12452 | bool wqid_matched = false; |
| 12453 | uint16_t fcp_wqid; |
| 12454 | |
| 12455 | /* Check for fast-path FCP work queue release */ |
| 12456 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 12457 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 12458 | if (childwq->queue_id == fcp_wqid) { |
| 12459 | lpfc_sli4_wq_release(childwq, |
| 12460 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12461 | wqid_matched = true; |
| 12462 | break; |
| 12463 | } |
| 12464 | } |
| 12465 | /* Report warning log message if no match found */ |
| 12466 | if (wqid_matched != true) |
| 12467 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12468 | "2580 Fast-path wqe consume event carries " |
| 12469 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 12470 | } |
| 12471 | |
| 12472 | /** |
| 12473 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 12474 | * @cq: Pointer to the completion queue. |
| 12475 | * @eqe: Pointer to fast-path completion queue entry. |
| 12476 | * |
| 12477 | * This routine process a fast-path work queue completion entry from fast-path |
| 12478 | * event queue for FCP command response completion. |
| 12479 | **/ |
| 12480 | static int |
| 12481 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12482 | struct lpfc_cqe *cqe) |
| 12483 | { |
| 12484 | struct lpfc_wcqe_release wcqe; |
| 12485 | bool workposted = false; |
| 12486 | |
| 12487 | /* Copy the work queue CQE and convert endian order if needed */ |
| 12488 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 12489 | |
| 12490 | /* Check and process for different type of WCQE and dispatch */ |
| 12491 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 12492 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12493 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12494 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 12495 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12496 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12497 | (struct lpfc_wcqe_complete *)&wcqe); |
| 12498 | break; |
| 12499 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12500 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12501 | /* Process the WQ release event */ |
| 12502 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 12503 | (struct lpfc_wcqe_release *)&wcqe); |
| 12504 | break; |
| 12505 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12506 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12507 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12508 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12509 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 12510 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 12511 | break; |
| 12512 | default: |
| 12513 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12514 | "0144 Not a valid WCQE code: x%x\n", |
| 12515 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 12516 | break; |
| 12517 | } |
| 12518 | return workposted; |
| 12519 | } |
| 12520 | |
| 12521 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12522 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12523 | * @phba: Pointer to HBA context object. |
| 12524 | * @eqe: Pointer to fast-path event queue entry. |
| 12525 | * |
| 12526 | * This routine process a event queue entry from the fast-path event queue. |
| 12527 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12528 | * completion event on a completion queue, if not, an error shall be logged |
| 12529 | * and just return. Otherwise, it will get to the corresponding completion |
| 12530 | * queue and process all the entries on the completion queue, rearm the |
| 12531 | * completion queue, and then return. |
| 12532 | **/ |
| 12533 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12534 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12535 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12536 | { |
| 12537 | struct lpfc_queue *cq; |
| 12538 | struct lpfc_cqe *cqe; |
| 12539 | bool workposted = false; |
| 12540 | uint16_t cqid; |
| 12541 | int ecount = 0; |
| 12542 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12543 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12544 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12545 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12546 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12547 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12548 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12549 | return; |
| 12550 | } |
| 12551 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12552 | /* Get the reference to the corresponding CQ */ |
| 12553 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12554 | |
| 12555 | /* Check if this is a Slow path event */ |
| 12556 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 12557 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 12558 | phba->sli4_hba.hba_eq[qidx]); |
| 12559 | return; |
| 12560 | } |
| 12561 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12562 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 12563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12564 | "3146 Fast-path completion queues " |
| 12565 | "does not exist\n"); |
| 12566 | return; |
| 12567 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12568 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12569 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12570 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12571 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12572 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12573 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12574 | return; |
| 12575 | } |
| 12576 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12577 | if (unlikely(cqid != cq->queue_id)) { |
| 12578 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12579 | "0368 Miss-matched fast-path completion " |
| 12580 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 12581 | cqid, cq->queue_id); |
| 12582 | return; |
| 12583 | } |
| 12584 | |
| 12585 | /* Process all the entries to the CQ */ |
| 12586 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12587 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12588 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12589 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12590 | } |
| 12591 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12592 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12593 | if (ecount > cq->CQ_max_cqe) |
| 12594 | cq->CQ_max_cqe = ecount; |
| 12595 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12596 | /* Catch the no cq entry condition */ |
| 12597 | if (unlikely(ecount == 0)) |
| 12598 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12599 | "0369 No entry from fast-path completion " |
| 12600 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12601 | |
| 12602 | /* In any case, flash and re-arm the CQ */ |
| 12603 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12604 | |
| 12605 | /* wake up worker thread if there are works to be done */ |
| 12606 | if (workposted) |
| 12607 | lpfc_worker_wake_up(phba); |
| 12608 | } |
| 12609 | |
| 12610 | static void |
| 12611 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12612 | { |
| 12613 | struct lpfc_eqe *eqe; |
| 12614 | |
| 12615 | /* walk all the EQ entries and drop on the floor */ |
| 12616 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 12617 | ; |
| 12618 | |
| 12619 | /* Clear and re-arm the EQ */ |
| 12620 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12621 | } |
| 12622 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12623 | |
| 12624 | /** |
| 12625 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 12626 | * entry |
| 12627 | * @phba: Pointer to HBA context object. |
| 12628 | * @eqe: Pointer to fast-path event queue entry. |
| 12629 | * |
| 12630 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 12631 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 12632 | * is for a completion event on a completion queue, if not, an error shall be |
| 12633 | * logged and just return. Otherwise, it will get to the corresponding |
| 12634 | * completion queue and process all the entries on the completion queue, rearm |
| 12635 | * the completion queue, and then return. |
| 12636 | **/ |
| 12637 | static void |
| 12638 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 12639 | { |
| 12640 | struct lpfc_queue *cq; |
| 12641 | struct lpfc_cqe *cqe; |
| 12642 | bool workposted = false; |
| 12643 | uint16_t cqid; |
| 12644 | int ecount = 0; |
| 12645 | |
| 12646 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 12647 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12648 | "9147 Not a valid completion " |
| 12649 | "event: majorcode=x%x, minorcode=x%x\n", |
| 12650 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12651 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 12652 | return; |
| 12653 | } |
| 12654 | |
| 12655 | /* Get the reference to the corresponding CQ */ |
| 12656 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12657 | |
| 12658 | /* Next check for OAS */ |
| 12659 | cq = phba->sli4_hba.oas_cq; |
| 12660 | if (unlikely(!cq)) { |
| 12661 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12662 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12663 | "9148 OAS completion queue " |
| 12664 | "does not exist\n"); |
| 12665 | return; |
| 12666 | } |
| 12667 | |
| 12668 | if (unlikely(cqid != cq->queue_id)) { |
| 12669 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12670 | "9149 Miss-matched fast-path compl " |
| 12671 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 12672 | cqid, cq->queue_id); |
| 12673 | return; |
| 12674 | } |
| 12675 | |
| 12676 | /* Process all the entries to the OAS CQ */ |
| 12677 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12678 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
| 12679 | if (!(++ecount % cq->entry_repost)) |
| 12680 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12681 | } |
| 12682 | |
| 12683 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12684 | if (ecount > cq->CQ_max_cqe) |
| 12685 | cq->CQ_max_cqe = ecount; |
| 12686 | |
| 12687 | /* Catch the no cq entry condition */ |
| 12688 | if (unlikely(ecount == 0)) |
| 12689 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12690 | "9153 No entry from fast-path completion " |
| 12691 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12692 | |
| 12693 | /* In any case, flash and re-arm the CQ */ |
| 12694 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12695 | |
| 12696 | /* wake up worker thread if there are works to be done */ |
| 12697 | if (workposted) |
| 12698 | lpfc_worker_wake_up(phba); |
| 12699 | } |
| 12700 | |
| 12701 | /** |
| 12702 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 12703 | * @irq: Interrupt number. |
| 12704 | * @dev_id: The device context pointer. |
| 12705 | * |
| 12706 | * This function is directly called from the PCI layer as an interrupt |
| 12707 | * service routine when device with SLI-4 interface spec is enabled with |
| 12708 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 12709 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 12710 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12711 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12712 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12713 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 12714 | * the intrrupt context. This function is called without any lock held. |
| 12715 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12716 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 12717 | * equal to that of CQ index. |
| 12718 | * |
| 12719 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12720 | * returns IRQ_NONE. |
| 12721 | **/ |
| 12722 | irqreturn_t |
| 12723 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 12724 | { |
| 12725 | struct lpfc_hba *phba; |
| 12726 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12727 | struct lpfc_queue *eq; |
| 12728 | struct lpfc_eqe *eqe; |
| 12729 | unsigned long iflag; |
| 12730 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12731 | |
| 12732 | /* Get the driver's phba structure from the dev_id */ |
| 12733 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12734 | phba = fcp_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12735 | |
| 12736 | if (unlikely(!phba)) |
| 12737 | return IRQ_NONE; |
| 12738 | |
| 12739 | /* Get to the EQ struct associated with this vector */ |
| 12740 | eq = phba->sli4_hba.fof_eq; |
| 12741 | if (unlikely(!eq)) |
| 12742 | return IRQ_NONE; |
| 12743 | |
| 12744 | /* Check device state for handling interrupt */ |
| 12745 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 12746 | eq->EQ_badstate++; |
| 12747 | /* Check again for link_state with lock held */ |
| 12748 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12749 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12750 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12751 | lpfc_sli4_eq_flush(phba, eq); |
| 12752 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12753 | return IRQ_NONE; |
| 12754 | } |
| 12755 | |
| 12756 | /* |
| 12757 | * Process all the event on FCP fast-path EQ |
| 12758 | */ |
| 12759 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 12760 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 12761 | if (!(++ecount % eq->entry_repost)) |
| 12762 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); |
| 12763 | eq->EQ_processed++; |
| 12764 | } |
| 12765 | |
| 12766 | /* Track the max number of EQEs processed in 1 intr */ |
| 12767 | if (ecount > eq->EQ_max_eqe) |
| 12768 | eq->EQ_max_eqe = ecount; |
| 12769 | |
| 12770 | |
| 12771 | if (unlikely(ecount == 0)) { |
| 12772 | eq->EQ_no_entry++; |
| 12773 | |
| 12774 | if (phba->intr_type == MSIX) |
| 12775 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12776 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12777 | "9145 MSI-X interrupt with no EQE\n"); |
| 12778 | else { |
| 12779 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12780 | "9146 ISR interrupt with no EQE\n"); |
| 12781 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12782 | return IRQ_NONE; |
| 12783 | } |
| 12784 | } |
| 12785 | /* Always clear and re-arm the fast-path EQ */ |
| 12786 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12787 | return IRQ_HANDLED; |
| 12788 | } |
| 12789 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12790 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12791 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12792 | * @irq: Interrupt number. |
| 12793 | * @dev_id: The device context pointer. |
| 12794 | * |
| 12795 | * This function is directly called from the PCI layer as an interrupt |
| 12796 | * service routine when device with SLI-4 interface spec is enabled with |
| 12797 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12798 | * ring event in the HBA. However, when the device is enabled with either |
| 12799 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12800 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12801 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12802 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12803 | * the intrrupt context. This function is called without any lock held. |
| 12804 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12805 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 12806 | * equal to that of FCP CQ index. |
| 12807 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12808 | * The link attention and ELS ring attention events are handled |
| 12809 | * by the worker thread. The interrupt handler signals the worker thread |
| 12810 | * and returns for these events. This function is called without any lock |
| 12811 | * held. It gets the hbalock to access and update SLI data structures. |
| 12812 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12813 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12814 | * returns IRQ_NONE. |
| 12815 | **/ |
| 12816 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12817 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12818 | { |
| 12819 | struct lpfc_hba *phba; |
| 12820 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12821 | struct lpfc_queue *fpeq; |
| 12822 | struct lpfc_eqe *eqe; |
| 12823 | unsigned long iflag; |
| 12824 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12825 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12826 | |
| 12827 | /* Get the driver's phba structure from the dev_id */ |
| 12828 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12829 | phba = fcp_eq_hdl->phba; |
| 12830 | fcp_eqidx = fcp_eq_hdl->idx; |
| 12831 | |
| 12832 | if (unlikely(!phba)) |
| 12833 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12834 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12835 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12836 | |
| 12837 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12838 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12839 | if (unlikely(!fpeq)) |
| 12840 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12841 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12842 | if (lpfc_fcp_look_ahead) { |
| 12843 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 12844 | lpfc_sli4_eq_clr_intr(fpeq); |
| 12845 | else { |
| 12846 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12847 | return IRQ_NONE; |
| 12848 | } |
| 12849 | } |
| 12850 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12851 | /* Check device state for handling interrupt */ |
| 12852 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12853 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12854 | /* Check again for link_state with lock held */ |
| 12855 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12856 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12857 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12858 | lpfc_sli4_eq_flush(phba, fpeq); |
| 12859 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12860 | if (lpfc_fcp_look_ahead) |
| 12861 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12862 | return IRQ_NONE; |
| 12863 | } |
| 12864 | |
| 12865 | /* |
| 12866 | * Process all the event on FCP fast-path EQ |
| 12867 | */ |
| 12868 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 12869 | if (eqe == NULL) |
| 12870 | break; |
| 12871 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12872 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12873 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12874 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12875 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12876 | } |
| 12877 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12878 | /* Track the max number of EQEs processed in 1 intr */ |
| 12879 | if (ecount > fpeq->EQ_max_eqe) |
| 12880 | fpeq->EQ_max_eqe = ecount; |
| 12881 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12882 | /* Always clear and re-arm the fast-path EQ */ |
| 12883 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 12884 | |
| 12885 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12886 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12887 | |
| 12888 | if (lpfc_fcp_look_ahead) { |
| 12889 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12890 | return IRQ_NONE; |
| 12891 | } |
| 12892 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12893 | if (phba->intr_type == MSIX) |
| 12894 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12895 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12896 | "0358 MSI-X interrupt with no EQE\n"); |
| 12897 | else |
| 12898 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12899 | return IRQ_NONE; |
| 12900 | } |
| 12901 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12902 | if (lpfc_fcp_look_ahead) |
| 12903 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12904 | return IRQ_HANDLED; |
| 12905 | } /* lpfc_sli4_fp_intr_handler */ |
| 12906 | |
| 12907 | /** |
| 12908 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12909 | * @irq: Interrupt number. |
| 12910 | * @dev_id: The device context pointer. |
| 12911 | * |
| 12912 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12913 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12914 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12915 | * driver attention. This function invokes the slow-path interrupt attention |
| 12916 | * handling function and fast-path interrupt attention handling function in |
| 12917 | * turn to process the relevant HBA attention events. This function is called |
| 12918 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12919 | * structures. |
| 12920 | * |
| 12921 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12922 | * returns IRQ_NONE. |
| 12923 | **/ |
| 12924 | irqreturn_t |
| 12925 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12926 | { |
| 12927 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12928 | irqreturn_t hba_irq_rc; |
| 12929 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12930 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12931 | |
| 12932 | /* Get the driver's phba structure from the dev_id */ |
| 12933 | phba = (struct lpfc_hba *)dev_id; |
| 12934 | |
| 12935 | if (unlikely(!phba)) |
| 12936 | return IRQ_NONE; |
| 12937 | |
| 12938 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12939 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12940 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12941 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12942 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12943 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12944 | if (hba_irq_rc == IRQ_HANDLED) |
| 12945 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12946 | } |
| 12947 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12948 | if (phba->cfg_fof) { |
| 12949 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
| 12950 | &phba->sli4_hba.fcp_eq_hdl[0]); |
| 12951 | if (hba_irq_rc == IRQ_HANDLED) |
| 12952 | hba_handled |= true; |
| 12953 | } |
| 12954 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12955 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12956 | } /* lpfc_sli4_intr_handler */ |
| 12957 | |
| 12958 | /** |
| 12959 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12960 | * @queue: The queue structure to free. |
| 12961 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12962 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12963 | * the host resident queue. This function must be called after destroying the |
| 12964 | * queue on the HBA. |
| 12965 | **/ |
| 12966 | void |
| 12967 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12968 | { |
| 12969 | struct lpfc_dmabuf *dmabuf; |
| 12970 | |
| 12971 | if (!queue) |
| 12972 | return; |
| 12973 | |
| 12974 | while (!list_empty(&queue->page_list)) { |
| 12975 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12976 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12977 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12978 | dmabuf->virt, dmabuf->phys); |
| 12979 | kfree(dmabuf); |
| 12980 | } |
| 12981 | kfree(queue); |
| 12982 | return; |
| 12983 | } |
| 12984 | |
| 12985 | /** |
| 12986 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12987 | * @phba: The HBA that this queue is being created on. |
| 12988 | * @entry_size: The size of each queue entry for this queue. |
| 12989 | * @entry count: The number of entries that this queue will handle. |
| 12990 | * |
| 12991 | * This function allocates a queue structure and the DMAable memory used for |
| 12992 | * the host resident queue. This function must be called before creating the |
| 12993 | * queue on the HBA. |
| 12994 | **/ |
| 12995 | struct lpfc_queue * |
| 12996 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12997 | uint32_t entry_count) |
| 12998 | { |
| 12999 | struct lpfc_queue *queue; |
| 13000 | struct lpfc_dmabuf *dmabuf; |
| 13001 | int x, total_qe_count; |
| 13002 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13003 | 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] | 13004 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13005 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13006 | hw_page_size = SLI4_PAGE_SIZE; |
| 13007 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13008 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 13009 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 13010 | if (!queue) |
| 13011 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13012 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 13013 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13014 | INIT_LIST_HEAD(&queue->list); |
| 13015 | INIT_LIST_HEAD(&queue->page_list); |
| 13016 | INIT_LIST_HEAD(&queue->child_list); |
| 13017 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 13018 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 13019 | if (!dmabuf) |
| 13020 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 13021 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 13022 | hw_page_size, &dmabuf->phys, |
| 13023 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13024 | if (!dmabuf->virt) { |
| 13025 | kfree(dmabuf); |
| 13026 | goto out_fail; |
| 13027 | } |
| 13028 | dmabuf->buffer_tag = x; |
| 13029 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 13030 | /* initialize queue's entry array */ |
| 13031 | dma_pointer = dmabuf->virt; |
| 13032 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13033 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13034 | total_qe_count++, dma_pointer += entry_size) { |
| 13035 | queue->qe[total_qe_count].address = dma_pointer; |
| 13036 | } |
| 13037 | } |
| 13038 | queue->entry_size = entry_size; |
| 13039 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13040 | |
| 13041 | /* |
| 13042 | * entry_repost is calculated based on the number of entries in the |
| 13043 | * queue. This works out except for RQs. If buffers are NOT initially |
| 13044 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 13045 | */ |
| 13046 | queue->entry_repost = (entry_count >> 3); |
| 13047 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 13048 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13049 | queue->phba = phba; |
| 13050 | |
| 13051 | return queue; |
| 13052 | out_fail: |
| 13053 | lpfc_sli4_queue_free(queue); |
| 13054 | return NULL; |
| 13055 | } |
| 13056 | |
| 13057 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13058 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 13059 | * @phba: HBA structure that indicates port to create a queue on. |
| 13060 | * @pci_barset: PCI BAR set flag. |
| 13061 | * |
| 13062 | * This function shall perform iomap of the specified PCI BAR address to host |
| 13063 | * memory address if not already done so and return it. The returned host |
| 13064 | * memory address can be NULL. |
| 13065 | */ |
| 13066 | static void __iomem * |
| 13067 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 13068 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13069 | if (!phba->pcidev) |
| 13070 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13071 | |
| 13072 | switch (pci_barset) { |
| 13073 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13074 | return phba->pci_bar0_memmap_p; |
| 13075 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13076 | return phba->pci_bar2_memmap_p; |
| 13077 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13078 | return phba->pci_bar4_memmap_p; |
| 13079 | default: |
| 13080 | break; |
| 13081 | } |
| 13082 | return NULL; |
| 13083 | } |
| 13084 | |
| 13085 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13086 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 13087 | * @phba: HBA structure that indicates port to create a queue on. |
| 13088 | * @startq: The starting FCP EQ to modify |
| 13089 | * |
| 13090 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 13091 | * |
| 13092 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 13093 | * is used to get the starting FCP EQ to change. |
| 13094 | * This function is asynchronous and will wait for the mailbox |
| 13095 | * command to finish before continuing. |
| 13096 | * |
| 13097 | * On success this function will return a zero. If unable to allocate enough |
| 13098 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13099 | * fails this function will return -ENXIO. |
| 13100 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13101 | int |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13102 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13103 | { |
| 13104 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 13105 | LPFC_MBOXQ_t *mbox; |
| 13106 | struct lpfc_queue *eq; |
| 13107 | int cnt, rc, length, status = 0; |
| 13108 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13109 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13110 | int fcp_eqidx; |
| 13111 | union lpfc_sli4_cfg_shdr *shdr; |
| 13112 | uint16_t dmult; |
| 13113 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13114 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13115 | return 0; |
| 13116 | |
| 13117 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13118 | if (!mbox) |
| 13119 | return -ENOMEM; |
| 13120 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 13121 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13122 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13123 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 13124 | length, LPFC_SLI4_MBX_EMBED); |
| 13125 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 13126 | |
| 13127 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13128 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 13129 | if (result > LPFC_DMULT_CONST) |
| 13130 | dmult = 0; |
| 13131 | else |
| 13132 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13133 | |
| 13134 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13135 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13136 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13137 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13138 | if (!eq) |
| 13139 | continue; |
| 13140 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 13141 | eq_delay->u.request.eq[cnt].phase = 0; |
| 13142 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 13143 | cnt++; |
| 13144 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 13145 | break; |
| 13146 | } |
| 13147 | eq_delay->u.request.num_eq = cnt; |
| 13148 | |
| 13149 | mbox->vport = phba->pport; |
| 13150 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13151 | mbox->context1 = NULL; |
| 13152 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13153 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 13154 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13155 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13156 | if (shdr_status || shdr_add_status || rc) { |
| 13157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13158 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 13159 | "status x%x add_status x%x, mbx status x%x\n", |
| 13160 | shdr_status, shdr_add_status, rc); |
| 13161 | status = -ENXIO; |
| 13162 | } |
| 13163 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13164 | return status; |
| 13165 | } |
| 13166 | |
| 13167 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13168 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 13169 | * @phba: HBA structure that indicates port to create a queue on. |
| 13170 | * @eq: The queue structure to use to create the event queue. |
| 13171 | * @imax: The maximum interrupt per second limit. |
| 13172 | * |
| 13173 | * This function creates an event queue, as detailed in @eq, on a port, |
| 13174 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 13175 | * |
| 13176 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 13177 | * is used to get the entry count and entry size that are necessary to |
| 13178 | * determine the number of pages to allocate and use for this queue. This |
| 13179 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 13180 | * event queue. This function is asynchronous and will wait for the mailbox |
| 13181 | * command to finish before continuing. |
| 13182 | * |
| 13183 | * 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] | 13184 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13185 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13186 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13187 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13188 | 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] | 13189 | { |
| 13190 | struct lpfc_mbx_eq_create *eq_create; |
| 13191 | LPFC_MBOXQ_t *mbox; |
| 13192 | int rc, length, status = 0; |
| 13193 | struct lpfc_dmabuf *dmabuf; |
| 13194 | uint32_t shdr_status, shdr_add_status; |
| 13195 | union lpfc_sli4_cfg_shdr *shdr; |
| 13196 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13197 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13198 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13199 | /* sanity check on queue memory */ |
| 13200 | if (!eq) |
| 13201 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13202 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13203 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13204 | |
| 13205 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13206 | if (!mbox) |
| 13207 | return -ENOMEM; |
| 13208 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 13209 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13210 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13211 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 13212 | length, LPFC_SLI4_MBX_EMBED); |
| 13213 | eq_create = &mbox->u.mqe.un.eq_create; |
| 13214 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 13215 | eq->page_count); |
| 13216 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 13217 | LPFC_EQE_SIZE); |
| 13218 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13219 | /* don't setup delay multiplier using EQ_CREATE */ |
| 13220 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13221 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 13222 | dmult); |
| 13223 | switch (eq->entry_count) { |
| 13224 | default: |
| 13225 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13226 | "0360 Unsupported EQ count. (%d)\n", |
| 13227 | eq->entry_count); |
| 13228 | if (eq->entry_count < 256) |
| 13229 | return -EINVAL; |
| 13230 | /* otherwise default to smallest count (drop through) */ |
| 13231 | case 256: |
| 13232 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13233 | LPFC_EQ_CNT_256); |
| 13234 | break; |
| 13235 | case 512: |
| 13236 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13237 | LPFC_EQ_CNT_512); |
| 13238 | break; |
| 13239 | case 1024: |
| 13240 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13241 | LPFC_EQ_CNT_1024); |
| 13242 | break; |
| 13243 | case 2048: |
| 13244 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13245 | LPFC_EQ_CNT_2048); |
| 13246 | break; |
| 13247 | case 4096: |
| 13248 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13249 | LPFC_EQ_CNT_4096); |
| 13250 | break; |
| 13251 | } |
| 13252 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13253 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13254 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13255 | putPaddrLow(dmabuf->phys); |
| 13256 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13257 | putPaddrHigh(dmabuf->phys); |
| 13258 | } |
| 13259 | mbox->vport = phba->pport; |
| 13260 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13261 | mbox->context1 = NULL; |
| 13262 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13263 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 13264 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13265 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13266 | if (shdr_status || shdr_add_status || rc) { |
| 13267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13268 | "2500 EQ_CREATE mailbox failed with " |
| 13269 | "status x%x add_status x%x, mbx status x%x\n", |
| 13270 | shdr_status, shdr_add_status, rc); |
| 13271 | status = -ENXIO; |
| 13272 | } |
| 13273 | eq->type = LPFC_EQ; |
| 13274 | eq->subtype = LPFC_NONE; |
| 13275 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 13276 | if (eq->queue_id == 0xFFFF) |
| 13277 | status = -ENXIO; |
| 13278 | eq->host_index = 0; |
| 13279 | eq->hba_index = 0; |
| 13280 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13281 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13282 | return status; |
| 13283 | } |
| 13284 | |
| 13285 | /** |
| 13286 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 13287 | * @phba: HBA structure that indicates port to create a queue on. |
| 13288 | * @cq: The queue structure to use to create the completion queue. |
| 13289 | * @eq: The event queue to bind this completion queue to. |
| 13290 | * |
| 13291 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 13292 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 13293 | * |
| 13294 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13295 | * is used to get the entry count and entry size that are necessary to |
| 13296 | * determine the number of pages to allocate and use for this queue. The @eq |
| 13297 | * is used to indicate which event queue to bind this completion queue to. This |
| 13298 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 13299 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 13300 | * command to finish before continuing. |
| 13301 | * |
| 13302 | * 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] | 13303 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13304 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13305 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13306 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13307 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13308 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 13309 | { |
| 13310 | struct lpfc_mbx_cq_create *cq_create; |
| 13311 | struct lpfc_dmabuf *dmabuf; |
| 13312 | LPFC_MBOXQ_t *mbox; |
| 13313 | int rc, length, status = 0; |
| 13314 | uint32_t shdr_status, shdr_add_status; |
| 13315 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13316 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13317 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13318 | /* sanity check on queue memory */ |
| 13319 | if (!cq || !eq) |
| 13320 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13321 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13322 | hw_page_size = SLI4_PAGE_SIZE; |
| 13323 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13324 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13325 | if (!mbox) |
| 13326 | return -ENOMEM; |
| 13327 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 13328 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13329 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13330 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 13331 | length, LPFC_SLI4_MBX_EMBED); |
| 13332 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13333 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13334 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 13335 | cq->page_count); |
| 13336 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 13337 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13338 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13339 | phba->sli4_hba.pc_sli4_params.cqv); |
| 13340 | 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] | 13341 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 13342 | 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] | 13343 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 13344 | eq->queue_id); |
| 13345 | } else { |
| 13346 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 13347 | eq->queue_id); |
| 13348 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13349 | switch (cq->entry_count) { |
| 13350 | default: |
| 13351 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13352 | "0361 Unsupported CQ count. (%d)\n", |
| 13353 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13354 | if (cq->entry_count < 256) { |
| 13355 | status = -EINVAL; |
| 13356 | goto out; |
| 13357 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13358 | /* otherwise default to smallest count (drop through) */ |
| 13359 | case 256: |
| 13360 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13361 | LPFC_CQ_CNT_256); |
| 13362 | break; |
| 13363 | case 512: |
| 13364 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13365 | LPFC_CQ_CNT_512); |
| 13366 | break; |
| 13367 | case 1024: |
| 13368 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13369 | LPFC_CQ_CNT_1024); |
| 13370 | break; |
| 13371 | } |
| 13372 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13373 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13374 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13375 | putPaddrLow(dmabuf->phys); |
| 13376 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13377 | putPaddrHigh(dmabuf->phys); |
| 13378 | } |
| 13379 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13380 | |
| 13381 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13382 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13383 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13384 | if (shdr_status || shdr_add_status || rc) { |
| 13385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13386 | "2501 CQ_CREATE mailbox failed with " |
| 13387 | "status x%x add_status x%x, mbx status x%x\n", |
| 13388 | shdr_status, shdr_add_status, rc); |
| 13389 | status = -ENXIO; |
| 13390 | goto out; |
| 13391 | } |
| 13392 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 13393 | if (cq->queue_id == 0xFFFF) { |
| 13394 | status = -ENXIO; |
| 13395 | goto out; |
| 13396 | } |
| 13397 | /* link the cq onto the parent eq child list */ |
| 13398 | list_add_tail(&cq->list, &eq->child_list); |
| 13399 | /* Set up completion queue's type and subtype */ |
| 13400 | cq->type = type; |
| 13401 | cq->subtype = subtype; |
| 13402 | 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] | 13403 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13404 | cq->host_index = 0; |
| 13405 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13406 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13407 | out: |
| 13408 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13409 | return status; |
| 13410 | } |
| 13411 | |
| 13412 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13413 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13414 | * @phba: HBA structure that indicates port to create a queue on. |
| 13415 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13416 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 13417 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13418 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13419 | * This function provides failback (fb) functionality when the |
| 13420 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 13421 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13422 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13423 | * This routine cannot fail as all attributes were previously accessed and |
| 13424 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13425 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13426 | static void |
| 13427 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13428 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13429 | { |
| 13430 | struct lpfc_mbx_mq_create *mq_create; |
| 13431 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13432 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13433 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13434 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 13435 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13436 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13437 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 13438 | length, LPFC_SLI4_MBX_EMBED); |
| 13439 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13440 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13441 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13442 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13443 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13444 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 13445 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13446 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13447 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13448 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13449 | break; |
| 13450 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13451 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13452 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13453 | break; |
| 13454 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13455 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13456 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13457 | break; |
| 13458 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13459 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13460 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13461 | break; |
| 13462 | } |
| 13463 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 13464 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13465 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13466 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13467 | putPaddrHigh(dmabuf->phys); |
| 13468 | } |
| 13469 | } |
| 13470 | |
| 13471 | /** |
| 13472 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 13473 | * @phba: HBA structure that indicates port to create a queue on. |
| 13474 | * @mq: The queue structure to use to create the mailbox queue. |
| 13475 | * @cq: The completion queue to associate with this cq. |
| 13476 | * @subtype: The queue's subtype. |
| 13477 | * |
| 13478 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 13479 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 13480 | * |
| 13481 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13482 | * is used to get the entry count and entry size that are necessary to |
| 13483 | * determine the number of pages to allocate and use for this queue. This |
| 13484 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 13485 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 13486 | * command to finish before continuing. |
| 13487 | * |
| 13488 | * 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] | 13489 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13490 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13491 | **/ |
| 13492 | int32_t |
| 13493 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13494 | struct lpfc_queue *cq, uint32_t subtype) |
| 13495 | { |
| 13496 | struct lpfc_mbx_mq_create *mq_create; |
| 13497 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 13498 | struct lpfc_dmabuf *dmabuf; |
| 13499 | LPFC_MBOXQ_t *mbox; |
| 13500 | int rc, length, status = 0; |
| 13501 | uint32_t shdr_status, shdr_add_status; |
| 13502 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13503 | 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] | 13504 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13505 | /* sanity check on queue memory */ |
| 13506 | if (!mq || !cq) |
| 13507 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13508 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13509 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13510 | |
| 13511 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13512 | if (!mbox) |
| 13513 | return -ENOMEM; |
| 13514 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 13515 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13516 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13517 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 13518 | length, LPFC_SLI4_MBX_EMBED); |
| 13519 | |
| 13520 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13521 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13522 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 13523 | &mq_create_ext->u.request, mq->page_count); |
| 13524 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 13525 | &mq_create_ext->u.request, 1); |
| 13526 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13527 | &mq_create_ext->u.request, 1); |
| 13528 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 13529 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13530 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 13531 | &mq_create_ext->u.request, 1); |
| 13532 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 13533 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13534 | 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] | 13535 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13536 | phba->sli4_hba.pc_sli4_params.mqv); |
| 13537 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 13538 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 13539 | cq->queue_id); |
| 13540 | else |
| 13541 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 13542 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13543 | switch (mq->entry_count) { |
| 13544 | default: |
| 13545 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13546 | "0362 Unsupported MQ count. (%d)\n", |
| 13547 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13548 | if (mq->entry_count < 16) { |
| 13549 | status = -EINVAL; |
| 13550 | goto out; |
| 13551 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13552 | /* otherwise default to smallest count (drop through) */ |
| 13553 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13554 | bf_set(lpfc_mq_context_ring_size, |
| 13555 | &mq_create_ext->u.request.context, |
| 13556 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13557 | break; |
| 13558 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13559 | bf_set(lpfc_mq_context_ring_size, |
| 13560 | &mq_create_ext->u.request.context, |
| 13561 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13562 | break; |
| 13563 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13564 | bf_set(lpfc_mq_context_ring_size, |
| 13565 | &mq_create_ext->u.request.context, |
| 13566 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13567 | break; |
| 13568 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13569 | bf_set(lpfc_mq_context_ring_size, |
| 13570 | &mq_create_ext->u.request.context, |
| 13571 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13572 | break; |
| 13573 | } |
| 13574 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13575 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13576 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13577 | putPaddrLow(dmabuf->phys); |
| 13578 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13579 | putPaddrHigh(dmabuf->phys); |
| 13580 | } |
| 13581 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13582 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13583 | &mq_create_ext->u.response); |
| 13584 | if (rc != MBX_SUCCESS) { |
| 13585 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13586 | "2795 MQ_CREATE_EXT failed with " |
| 13587 | "status x%x. Failback to MQ_CREATE.\n", |
| 13588 | rc); |
| 13589 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 13590 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13591 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13592 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 13593 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13594 | &mq_create->u.response); |
| 13595 | } |
| 13596 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13597 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13598 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13599 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13600 | if (shdr_status || shdr_add_status || rc) { |
| 13601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13602 | "2502 MQ_CREATE mailbox failed with " |
| 13603 | "status x%x add_status x%x, mbx status x%x\n", |
| 13604 | shdr_status, shdr_add_status, rc); |
| 13605 | status = -ENXIO; |
| 13606 | goto out; |
| 13607 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13608 | if (mq->queue_id == 0xFFFF) { |
| 13609 | status = -ENXIO; |
| 13610 | goto out; |
| 13611 | } |
| 13612 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13613 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13614 | mq->subtype = subtype; |
| 13615 | mq->host_index = 0; |
| 13616 | mq->hba_index = 0; |
| 13617 | |
| 13618 | /* link the mq onto the parent cq child list */ |
| 13619 | list_add_tail(&mq->list, &cq->child_list); |
| 13620 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13621 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13622 | return status; |
| 13623 | } |
| 13624 | |
| 13625 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13626 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 13627 | * @phba: HBA structure that indicates port to create a queue on. |
| 13628 | * @wq: The queue structure to use to create the work queue. |
| 13629 | * @cq: The completion queue to bind this work queue to. |
| 13630 | * @subtype: The subtype of the work queue indicating its functionality. |
| 13631 | * |
| 13632 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 13633 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 13634 | * |
| 13635 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 13636 | * is used to get the entry count and entry size that are necessary to |
| 13637 | * determine the number of pages to allocate and use for this queue. The @cq |
| 13638 | * is used to indicate which completion queue to bind this work queue to. This |
| 13639 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 13640 | * work queue. This function is asynchronous and will wait for the mailbox |
| 13641 | * command to finish before continuing. |
| 13642 | * |
| 13643 | * 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] | 13644 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13645 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13646 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13647 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13648 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 13649 | struct lpfc_queue *cq, uint32_t subtype) |
| 13650 | { |
| 13651 | struct lpfc_mbx_wq_create *wq_create; |
| 13652 | struct lpfc_dmabuf *dmabuf; |
| 13653 | LPFC_MBOXQ_t *mbox; |
| 13654 | int rc, length, status = 0; |
| 13655 | uint32_t shdr_status, shdr_add_status; |
| 13656 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13657 | 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] | 13658 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13659 | void __iomem *bar_memmap_p; |
| 13660 | uint32_t db_offset; |
| 13661 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13662 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13663 | /* sanity check on queue memory */ |
| 13664 | if (!wq || !cq) |
| 13665 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13666 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13667 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13668 | |
| 13669 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13670 | if (!mbox) |
| 13671 | return -ENOMEM; |
| 13672 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 13673 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13674 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13675 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 13676 | length, LPFC_SLI4_MBX_EMBED); |
| 13677 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13678 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13679 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 13680 | wq->page_count); |
| 13681 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 13682 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13683 | |
| 13684 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13685 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13686 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13687 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13688 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 13689 | case LPFC_Q_CREATE_VERSION_0: |
| 13690 | switch (wq->entry_size) { |
| 13691 | default: |
| 13692 | case 64: |
| 13693 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 13694 | page = wq_create->u.request.page; |
| 13695 | break; |
| 13696 | case 128: |
| 13697 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13698 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13699 | status = -ERANGE; |
| 13700 | goto out; |
| 13701 | } |
| 13702 | /* If we get here the HBA MUST also support V1 and |
| 13703 | * we MUST use it |
| 13704 | */ |
| 13705 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13706 | LPFC_Q_CREATE_VERSION_1); |
| 13707 | |
| 13708 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 13709 | &wq_create->u.request_1, wq->entry_count); |
| 13710 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13711 | &wq_create->u.request_1, |
| 13712 | LPFC_WQ_WQE_SIZE_128); |
| 13713 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13714 | &wq_create->u.request_1, |
| 13715 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13716 | page = wq_create->u.request_1.page; |
| 13717 | break; |
| 13718 | } |
| 13719 | break; |
| 13720 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13721 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 13722 | wq->entry_count); |
| 13723 | switch (wq->entry_size) { |
| 13724 | default: |
| 13725 | case 64: |
| 13726 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13727 | &wq_create->u.request_1, |
| 13728 | LPFC_WQ_WQE_SIZE_64); |
| 13729 | break; |
| 13730 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13731 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13732 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13733 | status = -ERANGE; |
| 13734 | goto out; |
| 13735 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13736 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13737 | &wq_create->u.request_1, |
| 13738 | LPFC_WQ_WQE_SIZE_128); |
| 13739 | break; |
| 13740 | } |
| 13741 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 13742 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13743 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13744 | break; |
| 13745 | default: |
| 13746 | status = -ERANGE; |
| 13747 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13748 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13749 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13750 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13751 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13752 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 13753 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13754 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13755 | |
| 13756 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13757 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 13758 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13759 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13760 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13761 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13762 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13763 | if (shdr_status || shdr_add_status || rc) { |
| 13764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13765 | "2503 WQ_CREATE mailbox failed with " |
| 13766 | "status x%x add_status x%x, mbx status x%x\n", |
| 13767 | shdr_status, shdr_add_status, rc); |
| 13768 | status = -ENXIO; |
| 13769 | goto out; |
| 13770 | } |
| 13771 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 13772 | if (wq->queue_id == 0xFFFF) { |
| 13773 | status = -ENXIO; |
| 13774 | goto out; |
| 13775 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13776 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13777 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 13778 | &wq_create->u.response); |
| 13779 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13780 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13781 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13782 | "3265 WQ[%d] doorbell format not " |
| 13783 | "supported: x%x\n", wq->queue_id, |
| 13784 | wq->db_format); |
| 13785 | status = -EINVAL; |
| 13786 | goto out; |
| 13787 | } |
| 13788 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 13789 | &wq_create->u.response); |
| 13790 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13791 | if (!bar_memmap_p) { |
| 13792 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13793 | "3263 WQ[%d] failed to memmap pci " |
| 13794 | "barset:x%x\n", wq->queue_id, |
| 13795 | pci_barset); |
| 13796 | status = -ENOMEM; |
| 13797 | goto out; |
| 13798 | } |
| 13799 | db_offset = wq_create->u.response.doorbell_offset; |
| 13800 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 13801 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 13802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13803 | "3252 WQ[%d] doorbell offset not " |
| 13804 | "supported: x%x\n", wq->queue_id, |
| 13805 | db_offset); |
| 13806 | status = -EINVAL; |
| 13807 | goto out; |
| 13808 | } |
| 13809 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 13810 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13811 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 13812 | "format:x%x\n", wq->queue_id, pci_barset, |
| 13813 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13814 | } else { |
| 13815 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 13816 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 13817 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13818 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13819 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13820 | wq->subtype = subtype; |
| 13821 | wq->host_index = 0; |
| 13822 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 13823 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13824 | |
| 13825 | /* link the wq onto the parent cq child list */ |
| 13826 | list_add_tail(&wq->list, &cq->child_list); |
| 13827 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13828 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13829 | return status; |
| 13830 | } |
| 13831 | |
| 13832 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13833 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 13834 | * @phba: HBA structure that indicates port to create a queue on. |
| 13835 | * @rq: The queue structure to use for the receive queue. |
| 13836 | * @qno: The associated HBQ number |
| 13837 | * |
| 13838 | * |
| 13839 | * For SLI4 we need to adjust the RQ repost value based on |
| 13840 | * the number of buffers that are initially posted to the RQ. |
| 13841 | */ |
| 13842 | void |
| 13843 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 13844 | { |
| 13845 | uint32_t cnt; |
| 13846 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13847 | /* sanity check on queue memory */ |
| 13848 | if (!rq) |
| 13849 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13850 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 13851 | |
| 13852 | /* Recalc repost for RQs based on buffers initially posted */ |
| 13853 | cnt = (cnt >> 3); |
| 13854 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 13855 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 13856 | |
| 13857 | rq->entry_repost = cnt; |
| 13858 | } |
| 13859 | |
| 13860 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13861 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 13862 | * @phba: HBA structure that indicates port to create a queue on. |
| 13863 | * @hrq: The queue structure to use to create the header receive queue. |
| 13864 | * @drq: The queue structure to use to create the data receive queue. |
| 13865 | * @cq: The completion queue to bind this work queue to. |
| 13866 | * |
| 13867 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 13868 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 13869 | * to the HBA. |
| 13870 | * |
| 13871 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 13872 | * struct is used to get the entry count that is necessary to determine the |
| 13873 | * number of pages to use for this queue. The @cq is used to indicate which |
| 13874 | * completion queue to bind received buffers that are posted to these queues to. |
| 13875 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 13876 | * receive queue pair. This function is asynchronous and will wait for the |
| 13877 | * mailbox command to finish before continuing. |
| 13878 | * |
| 13879 | * 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] | 13880 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13881 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13882 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13883 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13884 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13885 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 13886 | { |
| 13887 | struct lpfc_mbx_rq_create *rq_create; |
| 13888 | struct lpfc_dmabuf *dmabuf; |
| 13889 | LPFC_MBOXQ_t *mbox; |
| 13890 | int rc, length, status = 0; |
| 13891 | uint32_t shdr_status, shdr_add_status; |
| 13892 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13893 | 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] | 13894 | void __iomem *bar_memmap_p; |
| 13895 | uint32_t db_offset; |
| 13896 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13897 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13898 | /* sanity check on queue memory */ |
| 13899 | if (!hrq || !drq || !cq) |
| 13900 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13901 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13902 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13903 | |
| 13904 | if (hrq->entry_count != drq->entry_count) |
| 13905 | return -EINVAL; |
| 13906 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13907 | if (!mbox) |
| 13908 | return -ENOMEM; |
| 13909 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 13910 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13911 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13912 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13913 | length, LPFC_SLI4_MBX_EMBED); |
| 13914 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13915 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13916 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13917 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13918 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13919 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13920 | &rq_create->u.request.context, |
| 13921 | hrq->entry_count); |
| 13922 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13923 | bf_set(lpfc_rq_context_rqe_size, |
| 13924 | &rq_create->u.request.context, |
| 13925 | LPFC_RQE_SIZE_8); |
| 13926 | bf_set(lpfc_rq_context_page_size, |
| 13927 | &rq_create->u.request.context, |
| 13928 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13929 | } else { |
| 13930 | switch (hrq->entry_count) { |
| 13931 | default: |
| 13932 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13933 | "2535 Unsupported RQ count. (%d)\n", |
| 13934 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13935 | if (hrq->entry_count < 512) { |
| 13936 | status = -EINVAL; |
| 13937 | goto out; |
| 13938 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13939 | /* otherwise default to smallest count (drop through) */ |
| 13940 | case 512: |
| 13941 | bf_set(lpfc_rq_context_rqe_count, |
| 13942 | &rq_create->u.request.context, |
| 13943 | LPFC_RQ_RING_SIZE_512); |
| 13944 | break; |
| 13945 | case 1024: |
| 13946 | bf_set(lpfc_rq_context_rqe_count, |
| 13947 | &rq_create->u.request.context, |
| 13948 | LPFC_RQ_RING_SIZE_1024); |
| 13949 | break; |
| 13950 | case 2048: |
| 13951 | bf_set(lpfc_rq_context_rqe_count, |
| 13952 | &rq_create->u.request.context, |
| 13953 | LPFC_RQ_RING_SIZE_2048); |
| 13954 | break; |
| 13955 | case 4096: |
| 13956 | bf_set(lpfc_rq_context_rqe_count, |
| 13957 | &rq_create->u.request.context, |
| 13958 | LPFC_RQ_RING_SIZE_4096); |
| 13959 | break; |
| 13960 | } |
| 13961 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13962 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13963 | } |
| 13964 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13965 | cq->queue_id); |
| 13966 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13967 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13968 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13969 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13970 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13971 | putPaddrLow(dmabuf->phys); |
| 13972 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13973 | putPaddrHigh(dmabuf->phys); |
| 13974 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13975 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13976 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 13977 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13978 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13979 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13980 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13981 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13982 | if (shdr_status || shdr_add_status || rc) { |
| 13983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13984 | "2504 RQ_CREATE mailbox failed with " |
| 13985 | "status x%x add_status x%x, mbx status x%x\n", |
| 13986 | shdr_status, shdr_add_status, rc); |
| 13987 | status = -ENXIO; |
| 13988 | goto out; |
| 13989 | } |
| 13990 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13991 | if (hrq->queue_id == 0xFFFF) { |
| 13992 | status = -ENXIO; |
| 13993 | goto out; |
| 13994 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13995 | |
| 13996 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13997 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13998 | &rq_create->u.response); |
| 13999 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 14000 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 14001 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14002 | "3262 RQ [%d] doorbell format not " |
| 14003 | "supported: x%x\n", hrq->queue_id, |
| 14004 | hrq->db_format); |
| 14005 | status = -EINVAL; |
| 14006 | goto out; |
| 14007 | } |
| 14008 | |
| 14009 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 14010 | &rq_create->u.response); |
| 14011 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 14012 | if (!bar_memmap_p) { |
| 14013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14014 | "3269 RQ[%d] failed to memmap pci " |
| 14015 | "barset:x%x\n", hrq->queue_id, |
| 14016 | pci_barset); |
| 14017 | status = -ENOMEM; |
| 14018 | goto out; |
| 14019 | } |
| 14020 | |
| 14021 | db_offset = rq_create->u.response.doorbell_offset; |
| 14022 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 14023 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 14024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14025 | "3270 RQ[%d] doorbell offset not " |
| 14026 | "supported: x%x\n", hrq->queue_id, |
| 14027 | db_offset); |
| 14028 | status = -EINVAL; |
| 14029 | goto out; |
| 14030 | } |
| 14031 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 14032 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 14033 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 14034 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 14035 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14036 | } else { |
| 14037 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 14038 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 14039 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14040 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14041 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14042 | hrq->subtype = subtype; |
| 14043 | hrq->host_index = 0; |
| 14044 | hrq->hba_index = 0; |
| 14045 | |
| 14046 | /* now create the data queue */ |
| 14047 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14048 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 14049 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14050 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14051 | phba->sli4_hba.pc_sli4_params.rqv); |
| 14052 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 14053 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 14054 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14055 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 14056 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 14057 | LPFC_RQE_SIZE_8); |
| 14058 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 14059 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14060 | } else { |
| 14061 | switch (drq->entry_count) { |
| 14062 | default: |
| 14063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14064 | "2536 Unsupported RQ count. (%d)\n", |
| 14065 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14066 | if (drq->entry_count < 512) { |
| 14067 | status = -EINVAL; |
| 14068 | goto out; |
| 14069 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14070 | /* otherwise default to smallest count (drop through) */ |
| 14071 | case 512: |
| 14072 | bf_set(lpfc_rq_context_rqe_count, |
| 14073 | &rq_create->u.request.context, |
| 14074 | LPFC_RQ_RING_SIZE_512); |
| 14075 | break; |
| 14076 | case 1024: |
| 14077 | bf_set(lpfc_rq_context_rqe_count, |
| 14078 | &rq_create->u.request.context, |
| 14079 | LPFC_RQ_RING_SIZE_1024); |
| 14080 | break; |
| 14081 | case 2048: |
| 14082 | bf_set(lpfc_rq_context_rqe_count, |
| 14083 | &rq_create->u.request.context, |
| 14084 | LPFC_RQ_RING_SIZE_2048); |
| 14085 | break; |
| 14086 | case 4096: |
| 14087 | bf_set(lpfc_rq_context_rqe_count, |
| 14088 | &rq_create->u.request.context, |
| 14089 | LPFC_RQ_RING_SIZE_4096); |
| 14090 | break; |
| 14091 | } |
| 14092 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 14093 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14094 | } |
| 14095 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 14096 | cq->queue_id); |
| 14097 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 14098 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14099 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 14100 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14101 | putPaddrLow(dmabuf->phys); |
| 14102 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14103 | putPaddrHigh(dmabuf->phys); |
| 14104 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14105 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 14106 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14107 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14108 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14109 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 14110 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14111 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14112 | if (shdr_status || shdr_add_status || rc) { |
| 14113 | status = -ENXIO; |
| 14114 | goto out; |
| 14115 | } |
| 14116 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 14117 | if (drq->queue_id == 0xFFFF) { |
| 14118 | status = -ENXIO; |
| 14119 | goto out; |
| 14120 | } |
| 14121 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14122 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14123 | drq->subtype = subtype; |
| 14124 | drq->host_index = 0; |
| 14125 | drq->hba_index = 0; |
| 14126 | |
| 14127 | /* link the header and data RQs onto the parent cq child list */ |
| 14128 | list_add_tail(&hrq->list, &cq->child_list); |
| 14129 | list_add_tail(&drq->list, &cq->child_list); |
| 14130 | |
| 14131 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14132 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14133 | return status; |
| 14134 | } |
| 14135 | |
| 14136 | /** |
| 14137 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 14138 | * @eq: The queue structure associated with the queue to destroy. |
| 14139 | * |
| 14140 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 14141 | * command, specific to the type of queue, to the HBA. |
| 14142 | * |
| 14143 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 14144 | * |
| 14145 | * 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] | 14146 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14147 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14148 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14149 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 14150 | { |
| 14151 | LPFC_MBOXQ_t *mbox; |
| 14152 | int rc, length, status = 0; |
| 14153 | uint32_t shdr_status, shdr_add_status; |
| 14154 | union lpfc_sli4_cfg_shdr *shdr; |
| 14155 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14156 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14157 | if (!eq) |
| 14158 | return -ENODEV; |
| 14159 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14160 | if (!mbox) |
| 14161 | return -ENOMEM; |
| 14162 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 14163 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14164 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14165 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 14166 | length, LPFC_SLI4_MBX_EMBED); |
| 14167 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 14168 | eq->queue_id); |
| 14169 | mbox->vport = eq->phba->pport; |
| 14170 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14171 | |
| 14172 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 14173 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14174 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14175 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 14176 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14177 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14178 | if (shdr_status || shdr_add_status || rc) { |
| 14179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14180 | "2505 EQ_DESTROY mailbox failed with " |
| 14181 | "status x%x add_status x%x, mbx status x%x\n", |
| 14182 | shdr_status, shdr_add_status, rc); |
| 14183 | status = -ENXIO; |
| 14184 | } |
| 14185 | |
| 14186 | /* Remove eq from any list */ |
| 14187 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14188 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14189 | return status; |
| 14190 | } |
| 14191 | |
| 14192 | /** |
| 14193 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 14194 | * @cq: The queue structure associated with the queue to destroy. |
| 14195 | * |
| 14196 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 14197 | * command, specific to the type of queue, to the HBA. |
| 14198 | * |
| 14199 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 14200 | * |
| 14201 | * 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] | 14202 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14203 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14204 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14205 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 14206 | { |
| 14207 | LPFC_MBOXQ_t *mbox; |
| 14208 | int rc, length, status = 0; |
| 14209 | uint32_t shdr_status, shdr_add_status; |
| 14210 | union lpfc_sli4_cfg_shdr *shdr; |
| 14211 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14212 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14213 | if (!cq) |
| 14214 | return -ENODEV; |
| 14215 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14216 | if (!mbox) |
| 14217 | return -ENOMEM; |
| 14218 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 14219 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14220 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14221 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 14222 | length, LPFC_SLI4_MBX_EMBED); |
| 14223 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 14224 | cq->queue_id); |
| 14225 | mbox->vport = cq->phba->pport; |
| 14226 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14227 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 14228 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14229 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14230 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 14231 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14232 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14233 | if (shdr_status || shdr_add_status || rc) { |
| 14234 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14235 | "2506 CQ_DESTROY mailbox failed with " |
| 14236 | "status x%x add_status x%x, mbx status x%x\n", |
| 14237 | shdr_status, shdr_add_status, rc); |
| 14238 | status = -ENXIO; |
| 14239 | } |
| 14240 | /* Remove cq from any list */ |
| 14241 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14242 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14243 | return status; |
| 14244 | } |
| 14245 | |
| 14246 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14247 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 14248 | * @qm: The queue structure associated with the queue to destroy. |
| 14249 | * |
| 14250 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 14251 | * command, specific to the type of queue, to the HBA. |
| 14252 | * |
| 14253 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 14254 | * |
| 14255 | * 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] | 14256 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14257 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14258 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14259 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 14260 | { |
| 14261 | LPFC_MBOXQ_t *mbox; |
| 14262 | int rc, length, status = 0; |
| 14263 | uint32_t shdr_status, shdr_add_status; |
| 14264 | union lpfc_sli4_cfg_shdr *shdr; |
| 14265 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14266 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14267 | if (!mq) |
| 14268 | return -ENODEV; |
| 14269 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14270 | if (!mbox) |
| 14271 | return -ENOMEM; |
| 14272 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 14273 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14274 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14275 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 14276 | length, LPFC_SLI4_MBX_EMBED); |
| 14277 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 14278 | mq->queue_id); |
| 14279 | mbox->vport = mq->phba->pport; |
| 14280 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14281 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 14282 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14283 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14284 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 14285 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14286 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14287 | if (shdr_status || shdr_add_status || rc) { |
| 14288 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14289 | "2507 MQ_DESTROY mailbox failed with " |
| 14290 | "status x%x add_status x%x, mbx status x%x\n", |
| 14291 | shdr_status, shdr_add_status, rc); |
| 14292 | status = -ENXIO; |
| 14293 | } |
| 14294 | /* Remove mq from any list */ |
| 14295 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14296 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14297 | return status; |
| 14298 | } |
| 14299 | |
| 14300 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14301 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 14302 | * @wq: The queue structure associated with the queue to destroy. |
| 14303 | * |
| 14304 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 14305 | * command, specific to the type of queue, to the HBA. |
| 14306 | * |
| 14307 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 14308 | * |
| 14309 | * 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] | 14310 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14311 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14312 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14313 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 14314 | { |
| 14315 | LPFC_MBOXQ_t *mbox; |
| 14316 | int rc, length, status = 0; |
| 14317 | uint32_t shdr_status, shdr_add_status; |
| 14318 | union lpfc_sli4_cfg_shdr *shdr; |
| 14319 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14320 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14321 | if (!wq) |
| 14322 | return -ENODEV; |
| 14323 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14324 | if (!mbox) |
| 14325 | return -ENOMEM; |
| 14326 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 14327 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14328 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14329 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 14330 | length, LPFC_SLI4_MBX_EMBED); |
| 14331 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 14332 | wq->queue_id); |
| 14333 | mbox->vport = wq->phba->pport; |
| 14334 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14335 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 14336 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14337 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 14338 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14339 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14340 | if (shdr_status || shdr_add_status || rc) { |
| 14341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14342 | "2508 WQ_DESTROY mailbox failed with " |
| 14343 | "status x%x add_status x%x, mbx status x%x\n", |
| 14344 | shdr_status, shdr_add_status, rc); |
| 14345 | status = -ENXIO; |
| 14346 | } |
| 14347 | /* Remove wq from any list */ |
| 14348 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14349 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14350 | return status; |
| 14351 | } |
| 14352 | |
| 14353 | /** |
| 14354 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 14355 | * @rq: The queue structure associated with the queue to destroy. |
| 14356 | * |
| 14357 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 14358 | * command, specific to the type of queue, to the HBA. |
| 14359 | * |
| 14360 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 14361 | * |
| 14362 | * 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] | 14363 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14364 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14365 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14366 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 14367 | struct lpfc_queue *drq) |
| 14368 | { |
| 14369 | LPFC_MBOXQ_t *mbox; |
| 14370 | int rc, length, status = 0; |
| 14371 | uint32_t shdr_status, shdr_add_status; |
| 14372 | union lpfc_sli4_cfg_shdr *shdr; |
| 14373 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14374 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14375 | if (!hrq || !drq) |
| 14376 | return -ENODEV; |
| 14377 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14378 | if (!mbox) |
| 14379 | return -ENOMEM; |
| 14380 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14381 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14382 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14383 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 14384 | length, LPFC_SLI4_MBX_EMBED); |
| 14385 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14386 | hrq->queue_id); |
| 14387 | mbox->vport = hrq->phba->pport; |
| 14388 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14389 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 14390 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14391 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14392 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14393 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14394 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14395 | if (shdr_status || shdr_add_status || rc) { |
| 14396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14397 | "2509 RQ_DESTROY mailbox failed with " |
| 14398 | "status x%x add_status x%x, mbx status x%x\n", |
| 14399 | shdr_status, shdr_add_status, rc); |
| 14400 | if (rc != MBX_TIMEOUT) |
| 14401 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 14402 | return -ENXIO; |
| 14403 | } |
| 14404 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14405 | drq->queue_id); |
| 14406 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 14407 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14408 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14409 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14410 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14411 | if (shdr_status || shdr_add_status || rc) { |
| 14412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14413 | "2510 RQ_DESTROY mailbox failed with " |
| 14414 | "status x%x add_status x%x, mbx status x%x\n", |
| 14415 | shdr_status, shdr_add_status, rc); |
| 14416 | status = -ENXIO; |
| 14417 | } |
| 14418 | list_del_init(&hrq->list); |
| 14419 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14420 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14421 | return status; |
| 14422 | } |
| 14423 | |
| 14424 | /** |
| 14425 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 14426 | * @phba: The virtual port for which this call being executed. |
| 14427 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 14428 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 14429 | * @xritag: the xritag that ties this io to the SGL pages. |
| 14430 | * |
| 14431 | * This routine will post the sgl pages for the IO that has the xritag |
| 14432 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 14433 | * creation and persists for as long as the driver is loaded. |
| 14434 | * if the caller has fewer than 256 scatter gather segments to map then |
| 14435 | * pdma_phys_addr1 should be 0. |
| 14436 | * If the caller needs to map more than 256 scatter gather segment then |
| 14437 | * pdma_phys_addr1 should be a valid physical address. |
| 14438 | * physical address for SGLs must be 64 byte aligned. |
| 14439 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 14440 | * the second sgl can have between 1 and 256 entries. |
| 14441 | * |
| 14442 | * Return codes: |
| 14443 | * 0 - Success |
| 14444 | * -ENXIO, -ENOMEM - Failure |
| 14445 | **/ |
| 14446 | int |
| 14447 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 14448 | dma_addr_t pdma_phys_addr0, |
| 14449 | dma_addr_t pdma_phys_addr1, |
| 14450 | uint16_t xritag) |
| 14451 | { |
| 14452 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 14453 | LPFC_MBOXQ_t *mbox; |
| 14454 | int rc; |
| 14455 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14456 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14457 | union lpfc_sli4_cfg_shdr *shdr; |
| 14458 | |
| 14459 | if (xritag == NO_XRI) { |
| 14460 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14461 | "0364 Invalid param:\n"); |
| 14462 | return -EINVAL; |
| 14463 | } |
| 14464 | |
| 14465 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14466 | if (!mbox) |
| 14467 | return -ENOMEM; |
| 14468 | |
| 14469 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14470 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 14471 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14472 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14473 | |
| 14474 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 14475 | &mbox->u.mqe.un.post_sgl_pages; |
| 14476 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 14477 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 14478 | |
| 14479 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 14480 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 14481 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 14482 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 14483 | |
| 14484 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 14485 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 14486 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 14487 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 14488 | if (!phba->sli4_hba.intr_enable) |
| 14489 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14490 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14491 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14492 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14493 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14494 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14495 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 14496 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14497 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14498 | if (rc != MBX_TIMEOUT) |
| 14499 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14500 | if (shdr_status || shdr_add_status || rc) { |
| 14501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14502 | "2511 POST_SGL mailbox failed with " |
| 14503 | "status x%x add_status x%x, mbx status x%x\n", |
| 14504 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14505 | } |
| 14506 | return 0; |
| 14507 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14508 | |
| 14509 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14510 | * 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] | 14511 | * @phba: pointer to lpfc hba data structure. |
| 14512 | * |
| 14513 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14514 | * HBA consistent with the SLI-4 interface spec. This routine |
| 14515 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14516 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14517 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14518 | * Returns |
| 14519 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 14520 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14521 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14522 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14523 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 14524 | { |
| 14525 | unsigned long xri; |
| 14526 | |
| 14527 | /* |
| 14528 | * Fetch the next logical xri. Because this index is logical, |
| 14529 | * the driver starts at 0 each time. |
| 14530 | */ |
| 14531 | spin_lock_irq(&phba->hbalock); |
| 14532 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 14533 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 14534 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 14535 | spin_unlock_irq(&phba->hbalock); |
| 14536 | return NO_XRI; |
| 14537 | } else { |
| 14538 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 14539 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14540 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14541 | spin_unlock_irq(&phba->hbalock); |
| 14542 | return xri; |
| 14543 | } |
| 14544 | |
| 14545 | /** |
| 14546 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14547 | * @phba: pointer to lpfc hba data structure. |
| 14548 | * |
| 14549 | * This routine is invoked to release an xri to the pool of |
| 14550 | * available rpis maintained by the driver. |
| 14551 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14552 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14553 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14554 | { |
| 14555 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14556 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 14557 | } |
| 14558 | } |
| 14559 | |
| 14560 | /** |
| 14561 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14562 | * @phba: pointer to lpfc hba data structure. |
| 14563 | * |
| 14564 | * This routine is invoked to release an xri to the pool of |
| 14565 | * available rpis maintained by the driver. |
| 14566 | **/ |
| 14567 | void |
| 14568 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14569 | { |
| 14570 | spin_lock_irq(&phba->hbalock); |
| 14571 | __lpfc_sli4_free_xri(phba, xri); |
| 14572 | spin_unlock_irq(&phba->hbalock); |
| 14573 | } |
| 14574 | |
| 14575 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14576 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 14577 | * @phba: Pointer to HBA context object. |
| 14578 | * |
| 14579 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 14580 | * it will return 0xffff. |
| 14581 | * The function returns the allocated xritag if successful, else returns zero. |
| 14582 | * Zero is not a valid xritag. |
| 14583 | * The caller is not required to hold any lock. |
| 14584 | **/ |
| 14585 | uint16_t |
| 14586 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 14587 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14588 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14589 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14590 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 14591 | if (xri_index == NO_XRI) |
| 14592 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14593 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 14594 | " Max XRI is %d, Used XRI is %d\n", |
| 14595 | xri_index, |
| 14596 | phba->sli4_hba.max_cfg_param.max_xri, |
| 14597 | phba->sli4_hba.max_cfg_param.xri_used); |
| 14598 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14599 | } |
| 14600 | |
| 14601 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14602 | * 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] | 14603 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14604 | * @post_sgl_list: pointer to els sgl entry list. |
| 14605 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14606 | * |
| 14607 | * This routine is invoked to post a block of driver's sgl pages to the |
| 14608 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 14609 | * is only called when the driver is loading and after all IO has been |
| 14610 | * stopped. |
| 14611 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14612 | static int |
| 14613 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 14614 | struct list_head *post_sgl_list, |
| 14615 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14616 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14617 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14618 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14619 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14620 | void *viraddr; |
| 14621 | LPFC_MBOXQ_t *mbox; |
| 14622 | uint32_t reqlen, alloclen, pg_pairs; |
| 14623 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14624 | uint16_t xritag_start = 0; |
| 14625 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14626 | uint32_t shdr_status, shdr_add_status; |
| 14627 | union lpfc_sli4_cfg_shdr *shdr; |
| 14628 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14629 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14630 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14631 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14632 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14633 | "2559 Block sgl registration required DMA " |
| 14634 | "size (%d) great than a page\n", reqlen); |
| 14635 | return -ENOMEM; |
| 14636 | } |
| 14637 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14638 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14639 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14640 | |
| 14641 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14642 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14643 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14644 | LPFC_SLI4_MBX_NEMBED); |
| 14645 | |
| 14646 | if (alloclen < reqlen) { |
| 14647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14648 | "0285 Allocated DMA memory size (%d) is " |
| 14649 | "less than the requested DMA memory " |
| 14650 | "size (%d)\n", alloclen, reqlen); |
| 14651 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14652 | return -ENOMEM; |
| 14653 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14654 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14655 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14656 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14657 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14658 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14659 | pg_pairs = 0; |
| 14660 | 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] | 14661 | /* Set up the sge entry */ |
| 14662 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14663 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 14664 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14665 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 14666 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14667 | cpu_to_le32(putPaddrLow(0)); |
| 14668 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14669 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14670 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14671 | /* Keep the first xritag on the list */ |
| 14672 | if (pg_pairs == 0) |
| 14673 | xritag_start = sglq_entry->sli4_xritag; |
| 14674 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14675 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14676 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14677 | |
| 14678 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14679 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14680 | 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] | 14681 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14682 | if (!phba->sli4_hba.intr_enable) |
| 14683 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14684 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14685 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14686 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14687 | } |
| 14688 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14689 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14690 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14691 | if (rc != MBX_TIMEOUT) |
| 14692 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14693 | if (shdr_status || shdr_add_status || rc) { |
| 14694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14695 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 14696 | "status x%x add_status x%x mbx status x%x\n", |
| 14697 | shdr_status, shdr_add_status, rc); |
| 14698 | rc = -ENXIO; |
| 14699 | } |
| 14700 | return rc; |
| 14701 | } |
| 14702 | |
| 14703 | /** |
| 14704 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 14705 | * @phba: pointer to lpfc hba data structure. |
| 14706 | * @sblist: pointer to scsi buffer list. |
| 14707 | * @count: number of scsi buffers on the list. |
| 14708 | * |
| 14709 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 14710 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 14711 | * No Lock is held. |
| 14712 | * |
| 14713 | **/ |
| 14714 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14715 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 14716 | struct list_head *sblist, |
| 14717 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14718 | { |
| 14719 | struct lpfc_scsi_buf *psb; |
| 14720 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14721 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14722 | void *viraddr; |
| 14723 | LPFC_MBOXQ_t *mbox; |
| 14724 | uint32_t reqlen, alloclen, pg_pairs; |
| 14725 | uint32_t mbox_tmo; |
| 14726 | uint16_t xritag_start = 0; |
| 14727 | int rc = 0; |
| 14728 | uint32_t shdr_status, shdr_add_status; |
| 14729 | dma_addr_t pdma_phys_bpl1; |
| 14730 | union lpfc_sli4_cfg_shdr *shdr; |
| 14731 | |
| 14732 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14733 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14734 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14735 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14736 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14737 | "0217 Block sgl registration required DMA " |
| 14738 | "size (%d) great than a page\n", reqlen); |
| 14739 | return -ENOMEM; |
| 14740 | } |
| 14741 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14742 | if (!mbox) { |
| 14743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14744 | "0283 Failed to allocate mbox cmd memory\n"); |
| 14745 | return -ENOMEM; |
| 14746 | } |
| 14747 | |
| 14748 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14749 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14750 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14751 | LPFC_SLI4_MBX_NEMBED); |
| 14752 | |
| 14753 | if (alloclen < reqlen) { |
| 14754 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14755 | "2561 Allocated DMA memory size (%d) is " |
| 14756 | "less than the requested DMA memory " |
| 14757 | "size (%d)\n", alloclen, reqlen); |
| 14758 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14759 | return -ENOMEM; |
| 14760 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14761 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14762 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14763 | viraddr = mbox->sge_array->addr[0]; |
| 14764 | |
| 14765 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 14766 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14767 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14768 | |
| 14769 | pg_pairs = 0; |
| 14770 | list_for_each_entry(psb, sblist, list) { |
| 14771 | /* Set up the sge entry */ |
| 14772 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14773 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 14774 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14775 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 14776 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 14777 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 14778 | else |
| 14779 | pdma_phys_bpl1 = 0; |
| 14780 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14781 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 14782 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14783 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 14784 | /* Keep the first xritag on the list */ |
| 14785 | if (pg_pairs == 0) |
| 14786 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 14787 | sgl_pg_pairs++; |
| 14788 | pg_pairs++; |
| 14789 | } |
| 14790 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 14791 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 14792 | /* Perform endian conversion if necessary */ |
| 14793 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 14794 | |
| 14795 | if (!phba->sli4_hba.intr_enable) |
| 14796 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14797 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14798 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14799 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14800 | } |
| 14801 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14802 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14803 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14804 | if (rc != MBX_TIMEOUT) |
| 14805 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14806 | if (shdr_status || shdr_add_status || rc) { |
| 14807 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14808 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 14809 | "status x%x add_status x%x mbx status x%x\n", |
| 14810 | shdr_status, shdr_add_status, rc); |
| 14811 | rc = -ENXIO; |
| 14812 | } |
| 14813 | return rc; |
| 14814 | } |
| 14815 | |
| 14816 | /** |
| 14817 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 14818 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 14819 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14820 | * |
| 14821 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 14822 | * valid type of frame that the LPFC driver will handle. This function will |
| 14823 | * return a zero if the frame is a valid frame or a non zero value when the |
| 14824 | * frame does not pass the check. |
| 14825 | **/ |
| 14826 | static int |
| 14827 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 14828 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 14829 | /* make rctl_names static to save stack space */ |
| 14830 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14831 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 14832 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14833 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14834 | |
| 14835 | switch (fc_hdr->fh_r_ctl) { |
| 14836 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 14837 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 14838 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 14839 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 14840 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 14841 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 14842 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 14843 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 14844 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 14845 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 14846 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 14847 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 14848 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 14849 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 14850 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 14851 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 14852 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 14853 | case FC_RCTL_BA_PRMT: |
| 14854 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 14855 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 14856 | case FC_RCTL_P_RJT: /* port reject */ |
| 14857 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 14858 | case FC_RCTL_P_BSY: /* port busy */ |
| 14859 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 14860 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 14861 | case FC_RCTL_LCR: /* link credit reset */ |
| 14862 | case FC_RCTL_END: /* end */ |
| 14863 | break; |
| 14864 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 14865 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14866 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 14867 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 14868 | default: |
| 14869 | goto drop; |
| 14870 | } |
| 14871 | switch (fc_hdr->fh_type) { |
| 14872 | case FC_TYPE_BLS: |
| 14873 | case FC_TYPE_ELS: |
| 14874 | case FC_TYPE_FCP: |
| 14875 | case FC_TYPE_CT: |
| 14876 | break; |
| 14877 | case FC_TYPE_IP: |
| 14878 | case FC_TYPE_ILS: |
| 14879 | default: |
| 14880 | goto drop; |
| 14881 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14882 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14883 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14884 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
| 14885 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
| 14886 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, |
| 14887 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14888 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 14889 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14890 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 14891 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14892 | return 0; |
| 14893 | drop: |
| 14894 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14895 | "2539 Dropped frame rctl:%s type:%s\n", |
| 14896 | rctl_names[fc_hdr->fh_r_ctl], |
| 14897 | type_names[fc_hdr->fh_type]); |
| 14898 | return 1; |
| 14899 | } |
| 14900 | |
| 14901 | /** |
| 14902 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 14903 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14904 | * |
| 14905 | * This function processes the FC header to retrieve the VFI from the VF |
| 14906 | * header, if one exists. This function will return the VFI if one exists |
| 14907 | * or 0 if no VSAN Header exists. |
| 14908 | **/ |
| 14909 | static uint32_t |
| 14910 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 14911 | { |
| 14912 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14913 | |
| 14914 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14915 | return 0; |
| 14916 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14917 | } |
| 14918 | |
| 14919 | /** |
| 14920 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14921 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14922 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14923 | * @fcfi: The FC Fabric ID that the frame came from |
| 14924 | * |
| 14925 | * This function searches the @phba for a vport that matches the content of the |
| 14926 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14927 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14928 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14929 | * vport. |
| 14930 | **/ |
| 14931 | static struct lpfc_vport * |
| 14932 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14933 | uint16_t fcfi) |
| 14934 | { |
| 14935 | struct lpfc_vport **vports; |
| 14936 | struct lpfc_vport *vport = NULL; |
| 14937 | int i; |
| 14938 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14939 | fc_hdr->fh_d_id[1] << 8 | |
| 14940 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14941 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14942 | if (did == Fabric_DID) |
| 14943 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14944 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14945 | !(phba->link_state == LPFC_HBA_READY)) |
| 14946 | return phba->pport; |
| 14947 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14948 | vports = lpfc_create_vport_work_array(phba); |
| 14949 | if (vports != NULL) |
| 14950 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14951 | if (phba->fcf.fcfi == fcfi && |
| 14952 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14953 | vports[i]->fc_myDID == did) { |
| 14954 | vport = vports[i]; |
| 14955 | break; |
| 14956 | } |
| 14957 | } |
| 14958 | lpfc_destroy_vport_work_array(phba, vports); |
| 14959 | return vport; |
| 14960 | } |
| 14961 | |
| 14962 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14963 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14964 | * @vport: The vport to work on. |
| 14965 | * |
| 14966 | * This function updates the receive sequence time stamp for this vport. The |
| 14967 | * receive sequence time stamp indicates the time that the last frame of the |
| 14968 | * the sequence that has been idle for the longest amount of time was received. |
| 14969 | * the driver uses this time stamp to indicate if any received sequences have |
| 14970 | * timed out. |
| 14971 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14972 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14973 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14974 | { |
| 14975 | struct lpfc_dmabuf *h_buf; |
| 14976 | struct hbq_dmabuf *dmabuf = NULL; |
| 14977 | |
| 14978 | /* get the oldest sequence on the rcv list */ |
| 14979 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14980 | struct lpfc_dmabuf, list); |
| 14981 | if (!h_buf) |
| 14982 | return; |
| 14983 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14984 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14985 | } |
| 14986 | |
| 14987 | /** |
| 14988 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14989 | * @vport: The vport that the received sequences were sent to. |
| 14990 | * |
| 14991 | * This function cleans up all outstanding received sequences. This is called |
| 14992 | * by the driver when a link event or user action invalidates all the received |
| 14993 | * sequences. |
| 14994 | **/ |
| 14995 | void |
| 14996 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14997 | { |
| 14998 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14999 | struct lpfc_dmabuf *d_buf, *dnext; |
| 15000 | struct hbq_dmabuf *dmabuf = NULL; |
| 15001 | |
| 15002 | /* start with the oldest sequence on the rcv list */ |
| 15003 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 15004 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15005 | list_del_init(&dmabuf->hbuf.list); |
| 15006 | list_for_each_entry_safe(d_buf, dnext, |
| 15007 | &dmabuf->dbuf.list, list) { |
| 15008 | list_del_init(&d_buf->list); |
| 15009 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15010 | } |
| 15011 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 15012 | } |
| 15013 | } |
| 15014 | |
| 15015 | /** |
| 15016 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 15017 | * @vport: The vport that the received sequences were sent to. |
| 15018 | * |
| 15019 | * This function determines whether any received sequences have timed out by |
| 15020 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 15021 | * indicates that there is at least one timed out sequence this routine will |
| 15022 | * go through the received sequences one at a time from most inactive to most |
| 15023 | * active to determine which ones need to be cleaned up. Once it has determined |
| 15024 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 15025 | * without sending an abort. |
| 15026 | **/ |
| 15027 | void |
| 15028 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 15029 | { |
| 15030 | struct lpfc_dmabuf *h_buf, *hnext; |
| 15031 | struct lpfc_dmabuf *d_buf, *dnext; |
| 15032 | struct hbq_dmabuf *dmabuf = NULL; |
| 15033 | unsigned long timeout; |
| 15034 | int abort_count = 0; |
| 15035 | |
| 15036 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 15037 | vport->rcv_buffer_time_stamp); |
| 15038 | if (list_empty(&vport->rcv_buffer_list) || |
| 15039 | time_before(jiffies, timeout)) |
| 15040 | return; |
| 15041 | /* start with the oldest sequence on the rcv list */ |
| 15042 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 15043 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15044 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 15045 | dmabuf->time_stamp); |
| 15046 | if (time_before(jiffies, timeout)) |
| 15047 | break; |
| 15048 | abort_count++; |
| 15049 | list_del_init(&dmabuf->hbuf.list); |
| 15050 | list_for_each_entry_safe(d_buf, dnext, |
| 15051 | &dmabuf->dbuf.list, list) { |
| 15052 | list_del_init(&d_buf->list); |
| 15053 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15054 | } |
| 15055 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 15056 | } |
| 15057 | if (abort_count) |
| 15058 | lpfc_update_rcv_time_stamp(vport); |
| 15059 | } |
| 15060 | |
| 15061 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15062 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 15063 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 15064 | * |
| 15065 | * This function searches through the existing incomplete sequences that have |
| 15066 | * been sent to this @vport. If the frame matches one of the incomplete |
| 15067 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 15068 | * make up that sequence. If no sequence is found that matches this frame then |
| 15069 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 15070 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 15071 | * the frame was linked to. |
| 15072 | **/ |
| 15073 | static struct hbq_dmabuf * |
| 15074 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 15075 | { |
| 15076 | struct fc_frame_header *new_hdr; |
| 15077 | struct fc_frame_header *temp_hdr; |
| 15078 | struct lpfc_dmabuf *d_buf; |
| 15079 | struct lpfc_dmabuf *h_buf; |
| 15080 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 15081 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15082 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15083 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15084 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15085 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15086 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15087 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15088 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 15089 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 15090 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 15091 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 15092 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 15093 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 15094 | continue; |
| 15095 | /* found a pending sequence that matches this frame */ |
| 15096 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15097 | break; |
| 15098 | } |
| 15099 | if (!seq_dmabuf) { |
| 15100 | /* |
| 15101 | * This indicates first frame received for this sequence. |
| 15102 | * Queue the buffer on the vport's rcv_buffer_list. |
| 15103 | */ |
| 15104 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15105 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15106 | return dmabuf; |
| 15107 | } |
| 15108 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15109 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 15110 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15111 | list_del_init(&seq_dmabuf->hbuf.list); |
| 15112 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15113 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15114 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15115 | return dmabuf; |
| 15116 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15117 | /* move this sequence to the tail to indicate a young sequence */ |
| 15118 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15119 | seq_dmabuf->time_stamp = jiffies; |
| 15120 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15121 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 15122 | temp_hdr = dmabuf->hbuf.virt; |
| 15123 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 15124 | return seq_dmabuf; |
| 15125 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15126 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15127 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 15128 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15129 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15130 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 15131 | /* |
| 15132 | * If the frame's sequence count is greater than the frame on |
| 15133 | * the list then insert the frame right after this frame |
| 15134 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15135 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 15136 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15137 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15138 | found = 1; |
| 15139 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15140 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15141 | |
| 15142 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 15143 | break; |
| 15144 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15145 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15146 | |
| 15147 | if (found) |
| 15148 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15149 | return NULL; |
| 15150 | } |
| 15151 | |
| 15152 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15153 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 15154 | * @vport: pointer to a vitural port |
| 15155 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15156 | * |
| 15157 | * This function tries to abort from the partially assembed sequence, described |
| 15158 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 15159 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 15160 | * the frames from the partially assembled sequence. |
| 15161 | * |
| 15162 | * Return |
| 15163 | * true -- if there is matching partially assembled sequence present and all |
| 15164 | * the frames freed with the sequence; |
| 15165 | * false -- if there is no matching partially assembled sequence present so |
| 15166 | * nothing got aborted in the lower layer driver |
| 15167 | **/ |
| 15168 | static bool |
| 15169 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 15170 | struct hbq_dmabuf *dmabuf) |
| 15171 | { |
| 15172 | struct fc_frame_header *new_hdr; |
| 15173 | struct fc_frame_header *temp_hdr; |
| 15174 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 15175 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 15176 | |
| 15177 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 15178 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 15179 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 15180 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15181 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 15182 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 15183 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 15184 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 15185 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 15186 | continue; |
| 15187 | /* found a pending sequence that matches this frame */ |
| 15188 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15189 | break; |
| 15190 | } |
| 15191 | |
| 15192 | /* Free up all the frames from the partially assembled sequence */ |
| 15193 | if (seq_dmabuf) { |
| 15194 | list_for_each_entry_safe(d_buf, n_buf, |
| 15195 | &seq_dmabuf->dbuf.list, list) { |
| 15196 | list_del_init(&d_buf->list); |
| 15197 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15198 | } |
| 15199 | return true; |
| 15200 | } |
| 15201 | return false; |
| 15202 | } |
| 15203 | |
| 15204 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15205 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 15206 | * @vport: pointer to a vitural port |
| 15207 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15208 | * |
| 15209 | * This function tries to abort from the assembed sequence from upper level |
| 15210 | * protocol, described by the information from basic abbort @dmabuf. It |
| 15211 | * checks to see whether such pending context exists at upper level protocol. |
| 15212 | * If so, it shall clean up the pending context. |
| 15213 | * |
| 15214 | * Return |
| 15215 | * true -- if there is matching pending context of the sequence cleaned |
| 15216 | * at ulp; |
| 15217 | * false -- if there is no matching pending context of the sequence present |
| 15218 | * at ulp. |
| 15219 | **/ |
| 15220 | static bool |
| 15221 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 15222 | { |
| 15223 | struct lpfc_hba *phba = vport->phba; |
| 15224 | int handled; |
| 15225 | |
| 15226 | /* Accepting abort at ulp with SLI4 only */ |
| 15227 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15228 | return false; |
| 15229 | |
| 15230 | /* Register all caring upper level protocols to attend abort */ |
| 15231 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 15232 | if (handled) |
| 15233 | return true; |
| 15234 | |
| 15235 | return false; |
| 15236 | } |
| 15237 | |
| 15238 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15239 | * 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] | 15240 | * @phba: Pointer to HBA context object. |
| 15241 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 15242 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 15243 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15244 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15245 | * event. It properly releases the memory allocated to the sequence abort |
| 15246 | * accept iocb. |
| 15247 | **/ |
| 15248 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15249 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15250 | struct lpfc_iocbq *cmd_iocbq, |
| 15251 | struct lpfc_iocbq *rsp_iocbq) |
| 15252 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15253 | struct lpfc_nodelist *ndlp; |
| 15254 | |
| 15255 | if (cmd_iocbq) { |
| 15256 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 15257 | lpfc_nlp_put(ndlp); |
| 15258 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15259 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15260 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15261 | |
| 15262 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 15263 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 15264 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15265 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 15266 | rsp_iocbq->iocb.ulpStatus, |
| 15267 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15268 | } |
| 15269 | |
| 15270 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15271 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 15272 | * @phba: Pointer to HBA context object. |
| 15273 | * @xri: xri id in transaction. |
| 15274 | * |
| 15275 | * This function validates the xri maps to the known range of XRIs allocated an |
| 15276 | * used by the driver. |
| 15277 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15278 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15279 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 15280 | uint16_t xri) |
| 15281 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15282 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15283 | |
| 15284 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 15285 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 15286 | return i; |
| 15287 | } |
| 15288 | return NO_XRI; |
| 15289 | } |
| 15290 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15291 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15292 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15293 | * @phba: Pointer to HBA context object. |
| 15294 | * @fc_hdr: pointer to a FC frame header. |
| 15295 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15296 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15297 | * event after aborting the sequence handling. |
| 15298 | **/ |
| 15299 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15300 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 15301 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15302 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15303 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15304 | struct lpfc_iocbq *ctiocb = NULL; |
| 15305 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15306 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15307 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15308 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15309 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15310 | |
| 15311 | if (!lpfc_is_link_up(phba)) |
| 15312 | return; |
| 15313 | |
| 15314 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 15315 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15316 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15317 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15318 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15319 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15320 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 15321 | if (!ndlp) { |
| 15322 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15323 | "1268 Failed to allocate ndlp for " |
| 15324 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 15325 | return; |
| 15326 | } |
| 15327 | lpfc_nlp_init(vport, ndlp, sid); |
| 15328 | /* Put ndlp onto pport node list */ |
| 15329 | lpfc_enqueue_node(vport, ndlp); |
| 15330 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 15331 | /* re-setup ndlp without removing from node list */ |
| 15332 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 15333 | if (!ndlp) { |
| 15334 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15335 | "3275 Failed to active ndlp found " |
| 15336 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 15337 | return; |
| 15338 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15339 | } |
| 15340 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15341 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15342 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 15343 | if (!ctiocb) |
| 15344 | return; |
| 15345 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15346 | /* Extract the F_CTL field from FC_HDR */ |
| 15347 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 15348 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15349 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15350 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15351 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15352 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 15353 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 15354 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 15355 | |
| 15356 | /* Fill in the rest of iocb fields */ |
| 15357 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 15358 | icmd->ulpBdeCount = 0; |
| 15359 | icmd->ulpLe = 1; |
| 15360 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15361 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15362 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15363 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15364 | ctiocb->iocb_cmpl = NULL; |
| 15365 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15366 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15367 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15368 | ctiocb->sli4_xritag = NO_XRI; |
| 15369 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15370 | if (fctl & FC_FC_EX_CTX) |
| 15371 | /* Exchange responder sent the abort so we |
| 15372 | * own the oxid. |
| 15373 | */ |
| 15374 | xri = oxid; |
| 15375 | else |
| 15376 | xri = rxid; |
| 15377 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 15378 | if (lxri != NO_XRI) |
| 15379 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 15380 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15381 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 15382 | * the oxid maps to the FCP XRI range, the port no longer has |
| 15383 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 15384 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15385 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15386 | if ((fctl & FC_FC_EX_CTX) && |
| 15387 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 15388 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15389 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15390 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15391 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15392 | } |
| 15393 | |
| 15394 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 15395 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 15396 | * the IOCB for a BA_RJT. |
| 15397 | */ |
| 15398 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15399 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15400 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15401 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15402 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15403 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15404 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15405 | if (fctl & FC_FC_EX_CTX) { |
| 15406 | /* ABTS sent by responder to CT exchange, construction |
| 15407 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 15408 | * field and RX_ID from ABTS for RX_ID field. |
| 15409 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15410 | 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] | 15411 | } else { |
| 15412 | /* ABTS sent by initiator to CT exchange, construction |
| 15413 | * 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] | 15414 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15415 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15416 | 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] | 15417 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 15418 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15419 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15420 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15421 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15422 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 15423 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 15424 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15425 | |
| 15426 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 15427 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15428 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 15429 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 15430 | "xri x%x, Data x%x\n", |
| 15431 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 15432 | phba->link_state); |
| 15433 | lpfc_nlp_put(ndlp); |
| 15434 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15435 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 15436 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15437 | } |
| 15438 | |
| 15439 | /** |
| 15440 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 15441 | * @vport: Pointer to the vport on which this sequence was received |
| 15442 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15443 | * |
| 15444 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 15445 | * receive sequence is only partially assembed by the driver, it shall abort |
| 15446 | * the partially assembled frames for the sequence. Otherwise, if the |
| 15447 | * unsolicited receive sequence has been completely assembled and passed to |
| 15448 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 15449 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 15450 | * accept to accept the abort. |
| 15451 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15452 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15453 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 15454 | struct hbq_dmabuf *dmabuf) |
| 15455 | { |
| 15456 | struct lpfc_hba *phba = vport->phba; |
| 15457 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15458 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15459 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15460 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15461 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 15462 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15463 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15464 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15465 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15466 | /* ABTS by responder to exchange, no cleanup needed */ |
| 15467 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15468 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15469 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 15470 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 15471 | if (aborted == false) |
| 15472 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15473 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15474 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15475 | |
| 15476 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 15477 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15478 | } |
| 15479 | |
| 15480 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15481 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 15482 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15483 | * |
| 15484 | * This function checks the sequence, starting with the frame described by |
| 15485 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 15486 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 15487 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 15488 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 15489 | * set. 3) That there are no holes in the sequence count. The function will |
| 15490 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 15491 | **/ |
| 15492 | static int |
| 15493 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 15494 | { |
| 15495 | struct fc_frame_header *hdr; |
| 15496 | struct lpfc_dmabuf *d_buf; |
| 15497 | struct hbq_dmabuf *seq_dmabuf; |
| 15498 | uint32_t fctl; |
| 15499 | int seq_count = 0; |
| 15500 | |
| 15501 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15502 | /* make sure first fame of sequence has a sequence count of zero */ |
| 15503 | if (hdr->fh_seq_cnt != seq_count) |
| 15504 | return 0; |
| 15505 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15506 | hdr->fh_f_ctl[1] << 8 | |
| 15507 | hdr->fh_f_ctl[2]); |
| 15508 | /* If last frame of sequence we can return success. */ |
| 15509 | if (fctl & FC_FC_END_SEQ) |
| 15510 | return 1; |
| 15511 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 15512 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15513 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15514 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15515 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15516 | return 0; |
| 15517 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15518 | hdr->fh_f_ctl[1] << 8 | |
| 15519 | hdr->fh_f_ctl[2]); |
| 15520 | /* If last frame of sequence we can return success. */ |
| 15521 | if (fctl & FC_FC_END_SEQ) |
| 15522 | return 1; |
| 15523 | } |
| 15524 | return 0; |
| 15525 | } |
| 15526 | |
| 15527 | /** |
| 15528 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 15529 | * @vport: Pointer to the vport on which this sequence was received |
| 15530 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15531 | * |
| 15532 | * This function takes a sequence, described by a list of frames, and creates |
| 15533 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 15534 | * used to issue to the generic unsolicited sequence handler. This routine |
| 15535 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 15536 | * to allocate an iocbq then it throw out the received frames that were not |
| 15537 | * able to be described and return a pointer to the first iocbq. If unable to |
| 15538 | * allocate any iocbqs (including the first) this function will return NULL. |
| 15539 | **/ |
| 15540 | static struct lpfc_iocbq * |
| 15541 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 15542 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15543 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15544 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 15545 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 15546 | struct fc_frame_header *fc_hdr; |
| 15547 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15548 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15549 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15550 | |
| 15551 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15552 | /* remove from receive buffer list */ |
| 15553 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15554 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15555 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15556 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15557 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15558 | /* Get an iocbq struct to fill in. */ |
| 15559 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15560 | if (first_iocbq) { |
| 15561 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15562 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15563 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15564 | |
| 15565 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 15566 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 15567 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 15568 | first_iocbq->iocb.un.rcvels.parmRo = |
| 15569 | sli4_did_from_fc_hdr(fc_hdr); |
| 15570 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 15571 | } else |
| 15572 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15573 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 15574 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 15575 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 15576 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 15577 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 15578 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15579 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15580 | tot_len = bf_get(lpfc_rcqe_length, |
| 15581 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15582 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15583 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 15584 | first_iocbq->context3 = NULL; |
| 15585 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15586 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 15587 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15588 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15589 | else |
| 15590 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 15591 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15592 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15593 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15594 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15595 | } |
| 15596 | iocbq = first_iocbq; |
| 15597 | /* |
| 15598 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 15599 | * of buffers for this sequence and save two buffers in each IOCBq |
| 15600 | */ |
| 15601 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 15602 | if (!iocbq) { |
| 15603 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15604 | continue; |
| 15605 | } |
| 15606 | if (!iocbq->context3) { |
| 15607 | iocbq->context3 = d_buf; |
| 15608 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15609 | /* We need to get the size out of the right CQE */ |
| 15610 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15611 | len = bf_get(lpfc_rcqe_length, |
| 15612 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15613 | pbde = (struct ulp_bde64 *) |
| 15614 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 15615 | if (len > LPFC_DATA_BUF_SIZE) |
| 15616 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 15617 | else |
| 15618 | pbde->tus.f.bdeSize = len; |
| 15619 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15620 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 15621 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15622 | } else { |
| 15623 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15624 | if (!iocbq) { |
| 15625 | if (first_iocbq) { |
| 15626 | first_iocbq->iocb.ulpStatus = |
| 15627 | IOSTAT_FCP_RSP_ERROR; |
| 15628 | first_iocbq->iocb.un.ulpWord[4] = |
| 15629 | IOERR_NO_RESOURCES; |
| 15630 | } |
| 15631 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15632 | continue; |
| 15633 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15634 | /* We need to get the size out of the right CQE */ |
| 15635 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15636 | len = bf_get(lpfc_rcqe_length, |
| 15637 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15638 | iocbq->context2 = d_buf; |
| 15639 | iocbq->context3 = NULL; |
| 15640 | iocbq->iocb.ulpBdeCount = 1; |
| 15641 | if (len > LPFC_DATA_BUF_SIZE) |
| 15642 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 15643 | LPFC_DATA_BUF_SIZE; |
| 15644 | else |
| 15645 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 15646 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15647 | tot_len += len; |
| 15648 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 15649 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15650 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 15651 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 15652 | } |
| 15653 | } |
| 15654 | return first_iocbq; |
| 15655 | } |
| 15656 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15657 | static void |
| 15658 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 15659 | struct hbq_dmabuf *seq_dmabuf) |
| 15660 | { |
| 15661 | struct fc_frame_header *fc_hdr; |
| 15662 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 15663 | struct lpfc_hba *phba = vport->phba; |
| 15664 | |
| 15665 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15666 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 15667 | if (!iocbq) { |
| 15668 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15669 | "2707 Ring %d handler: Failed to allocate " |
| 15670 | "iocb Rctl x%x Type x%x received\n", |
| 15671 | LPFC_ELS_RING, |
| 15672 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15673 | return; |
| 15674 | } |
| 15675 | if (!lpfc_complete_unsol_iocb(phba, |
| 15676 | &phba->sli.ring[LPFC_ELS_RING], |
| 15677 | iocbq, fc_hdr->fh_r_ctl, |
| 15678 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15679 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15680 | "2540 Ring %d handler: unexpected Rctl " |
| 15681 | "x%x Type x%x received\n", |
| 15682 | LPFC_ELS_RING, |
| 15683 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15684 | |
| 15685 | /* Free iocb created in lpfc_prep_seq */ |
| 15686 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 15687 | &iocbq->list, list) { |
| 15688 | list_del_init(&curr_iocb->list); |
| 15689 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 15690 | } |
| 15691 | lpfc_sli_release_iocbq(phba, iocbq); |
| 15692 | } |
| 15693 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15694 | /** |
| 15695 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 15696 | * @phba: Pointer to HBA context object. |
| 15697 | * |
| 15698 | * This function is called with no lock held. This function processes all |
| 15699 | * the received buffers and gives it to upper layers when a received buffer |
| 15700 | * indicates that it is the final frame in the sequence. The interrupt |
| 15701 | * service routine processes received buffers at interrupt contexts and adds |
| 15702 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 15703 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 15704 | * appropriate receive function when the final frame in a sequence is received. |
| 15705 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15706 | void |
| 15707 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 15708 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15709 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15710 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15711 | struct fc_frame_header *fc_hdr; |
| 15712 | struct lpfc_vport *vport; |
| 15713 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15714 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15715 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15716 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15717 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15718 | /* check to see if this a valid type of frame */ |
| 15719 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 15720 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15721 | return; |
| 15722 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15723 | if ((bf_get(lpfc_cqe_code, |
| 15724 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 15725 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 15726 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15727 | else |
| 15728 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 15729 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15730 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15731 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15732 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15733 | /* throw out the frame */ |
| 15734 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15735 | return; |
| 15736 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15737 | |
| 15738 | /* d_id this frame is directed to */ |
| 15739 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 15740 | |
| 15741 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 15742 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 15743 | (did != Fabric_DID)) { |
| 15744 | /* |
| 15745 | * Throw out the frame if we are not pt2pt. |
| 15746 | * The pt2pt protocol allows for discovery frames |
| 15747 | * to be received without a registered VPI. |
| 15748 | */ |
| 15749 | if (!(vport->fc_flag & FC_PT2PT) || |
| 15750 | (phba->link_state == LPFC_HBA_READY)) { |
| 15751 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15752 | return; |
| 15753 | } |
| 15754 | } |
| 15755 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15756 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 15757 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 15758 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 15759 | return; |
| 15760 | } |
| 15761 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15762 | /* Link this frame */ |
| 15763 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 15764 | if (!seq_dmabuf) { |
| 15765 | /* unable to add frame to vport - throw it out */ |
| 15766 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15767 | return; |
| 15768 | } |
| 15769 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15770 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15771 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15772 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15773 | /* Send the complete sequence to the upper layer protocol */ |
| 15774 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15775 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15776 | |
| 15777 | /** |
| 15778 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 15779 | * @phba: pointer to lpfc hba data structure. |
| 15780 | * |
| 15781 | * This routine is invoked to post rpi header templates to the |
| 15782 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15783 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15784 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15785 | * |
| 15786 | * This routine does not require any locks. It's usage is expected |
| 15787 | * to be driver load or reset recovery when the driver is |
| 15788 | * sequential. |
| 15789 | * |
| 15790 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15791 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15792 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15793 | * When this error occurs, the driver is not guaranteed |
| 15794 | * to have any rpi regions posted to the device and |
| 15795 | * must either attempt to repost the regions or take a |
| 15796 | * fatal error. |
| 15797 | **/ |
| 15798 | int |
| 15799 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 15800 | { |
| 15801 | struct lpfc_rpi_hdr *rpi_page; |
| 15802 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15803 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15804 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15805 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15806 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15807 | goto exit; |
| 15808 | if (phba->sli4_hba.extents_in_use) |
| 15809 | return -EIO; |
| 15810 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15811 | 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] | 15812 | /* |
| 15813 | * Assign the rpi headers a physical rpi only if the driver |
| 15814 | * has not initialized those resources. A port reset only |
| 15815 | * needs the headers posted. |
| 15816 | */ |
| 15817 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 15818 | LPFC_RPI_RSRC_RDY) |
| 15819 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 15820 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15821 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 15822 | if (rc != MBX_SUCCESS) { |
| 15823 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15824 | "2008 Error %d posting all rpi " |
| 15825 | "headers\n", rc); |
| 15826 | rc = -EIO; |
| 15827 | break; |
| 15828 | } |
| 15829 | } |
| 15830 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15831 | exit: |
| 15832 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 15833 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15834 | return rc; |
| 15835 | } |
| 15836 | |
| 15837 | /** |
| 15838 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 15839 | * @phba: pointer to lpfc hba data structure. |
| 15840 | * @rpi_page: pointer to the rpi memory region. |
| 15841 | * |
| 15842 | * This routine is invoked to post a single rpi header to the |
| 15843 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 15844 | * maps up to 64 rpi context regions. |
| 15845 | * |
| 15846 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15847 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15848 | * -ENOMEM - No available memory |
| 15849 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15850 | **/ |
| 15851 | int |
| 15852 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 15853 | { |
| 15854 | LPFC_MBOXQ_t *mboxq; |
| 15855 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 15856 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15857 | uint32_t shdr_status, shdr_add_status; |
| 15858 | union lpfc_sli4_cfg_shdr *shdr; |
| 15859 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15860 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15861 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15862 | return rc; |
| 15863 | if (phba->sli4_hba.extents_in_use) |
| 15864 | return -EIO; |
| 15865 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15866 | /* The port is notified of the header region via a mailbox command. */ |
| 15867 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15868 | if (!mboxq) { |
| 15869 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15870 | "2001 Unable to allocate memory for issuing " |
| 15871 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 15872 | return -ENOMEM; |
| 15873 | } |
| 15874 | |
| 15875 | /* Post all rpi memory regions to the port. */ |
| 15876 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15877 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15878 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 15879 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15880 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 15881 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15882 | |
| 15883 | |
| 15884 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15885 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 15886 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15887 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 15888 | hdr_tmpl, rpi_page->page_count); |
| 15889 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15890 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 15891 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 15892 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15893 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 15894 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15895 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15896 | if (rc != MBX_TIMEOUT) |
| 15897 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15898 | if (shdr_status || shdr_add_status || rc) { |
| 15899 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15900 | "2514 POST_RPI_HDR mailbox failed with " |
| 15901 | "status x%x add_status x%x, mbx status x%x\n", |
| 15902 | shdr_status, shdr_add_status, rc); |
| 15903 | rc = -ENXIO; |
| 15904 | } |
| 15905 | return rc; |
| 15906 | } |
| 15907 | |
| 15908 | /** |
| 15909 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 15910 | * @phba: pointer to lpfc hba data structure. |
| 15911 | * |
| 15912 | * This routine is invoked to post rpi header templates to the |
| 15913 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15914 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15915 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15916 | * |
| 15917 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15918 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15919 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15920 | **/ |
| 15921 | int |
| 15922 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 15923 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15924 | unsigned long rpi; |
| 15925 | uint16_t max_rpi, rpi_limit; |
| 15926 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15927 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15928 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15929 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15930 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15931 | * Fetch the next logical rpi. Because this index is logical, |
| 15932 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15933 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15934 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15935 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 15936 | rpi_limit = phba->sli4_hba.next_rpi; |
| 15937 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15938 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15939 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15940 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15941 | else { |
| 15942 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15943 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15944 | phba->sli4_hba.rpi_count++; |
| 15945 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15946 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 15947 | "0001 rpi:%x max:%x lim:%x\n", |
| 15948 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15949 | |
| 15950 | /* |
| 15951 | * 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] | 15952 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15953 | */ |
| 15954 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15955 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15956 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15957 | return rpi; |
| 15958 | } |
| 15959 | |
| 15960 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15961 | * RPI header postings are not required for SLI4 ports capable of |
| 15962 | * extents. |
| 15963 | */ |
| 15964 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15965 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15966 | return rpi; |
| 15967 | } |
| 15968 | |
| 15969 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15970 | * If the driver is running low on rpi resources, allocate another |
| 15971 | * page now. Note that the next_rpi value is used because |
| 15972 | * it represents how many are actually in use whereas max_rpi notes |
| 15973 | * how many are supported max by the device. |
| 15974 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15975 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15976 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15977 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15978 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15979 | if (!rpi_hdr) { |
| 15980 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15981 | "2002 Error Could not grow rpi " |
| 15982 | "count\n"); |
| 15983 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15984 | lrpi = rpi_hdr->start_rpi; |
| 15985 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15986 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15987 | } |
| 15988 | } |
| 15989 | |
| 15990 | return rpi; |
| 15991 | } |
| 15992 | |
| 15993 | /** |
| 15994 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15995 | * @phba: pointer to lpfc hba data structure. |
| 15996 | * |
| 15997 | * This routine is invoked to release an rpi to the pool of |
| 15998 | * available rpis maintained by the driver. |
| 15999 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16000 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 16001 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 16002 | { |
| 16003 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 16004 | phba->sli4_hba.rpi_count--; |
| 16005 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 16006 | } |
| 16007 | } |
| 16008 | |
| 16009 | /** |
| 16010 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 16011 | * @phba: pointer to lpfc hba data structure. |
| 16012 | * |
| 16013 | * This routine is invoked to release an rpi to the pool of |
| 16014 | * available rpis maintained by the driver. |
| 16015 | **/ |
| 16016 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16017 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 16018 | { |
| 16019 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 16020 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16021 | spin_unlock_irq(&phba->hbalock); |
| 16022 | } |
| 16023 | |
| 16024 | /** |
| 16025 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 16026 | * @phba: pointer to lpfc hba data structure. |
| 16027 | * |
| 16028 | * This routine is invoked to remove the memory region that |
| 16029 | * provided rpi via a bitmask. |
| 16030 | **/ |
| 16031 | void |
| 16032 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 16033 | { |
| 16034 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16035 | kfree(phba->sli4_hba.rpi_ids); |
| 16036 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16037 | } |
| 16038 | |
| 16039 | /** |
| 16040 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 16041 | * @phba: pointer to lpfc hba data structure. |
| 16042 | * |
| 16043 | * This routine is invoked to remove the memory region that |
| 16044 | * provided rpi via a bitmask. |
| 16045 | **/ |
| 16046 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16047 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 16048 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16049 | { |
| 16050 | LPFC_MBOXQ_t *mboxq; |
| 16051 | struct lpfc_hba *phba = ndlp->phba; |
| 16052 | int rc; |
| 16053 | |
| 16054 | /* The port is notified of the header region via a mailbox command. */ |
| 16055 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16056 | if (!mboxq) |
| 16057 | return -ENOMEM; |
| 16058 | |
| 16059 | /* Post all rpi memory regions to the port. */ |
| 16060 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16061 | if (cmpl) { |
| 16062 | mboxq->mbox_cmpl = cmpl; |
| 16063 | mboxq->context1 = arg; |
| 16064 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 16065 | } else |
| 16066 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16067 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16068 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16069 | if (rc == MBX_NOT_FINISHED) { |
| 16070 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16071 | "2010 Resume RPI Mailbox failed " |
| 16072 | "status %d, mbxStatus x%x\n", rc, |
| 16073 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 16074 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16075 | return -EIO; |
| 16076 | } |
| 16077 | return 0; |
| 16078 | } |
| 16079 | |
| 16080 | /** |
| 16081 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16082 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16083 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16084 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16085 | * |
| 16086 | * Returns: |
| 16087 | * 0 success |
| 16088 | * -Evalue otherwise |
| 16089 | **/ |
| 16090 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16091 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16092 | { |
| 16093 | LPFC_MBOXQ_t *mboxq; |
| 16094 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16095 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16096 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16097 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16098 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16099 | if (!mboxq) |
| 16100 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16101 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16102 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16103 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16104 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16105 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16106 | "2022 INIT VPI Mailbox failed " |
| 16107 | "status %d, mbxStatus x%x\n", rc, |
| 16108 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16109 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16110 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16111 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16112 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16113 | |
| 16114 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16115 | } |
| 16116 | |
| 16117 | /** |
| 16118 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 16119 | * @phba: pointer to lpfc hba data structure. |
| 16120 | * @mboxq: Pointer to mailbox object. |
| 16121 | * |
| 16122 | * This routine is invoked to manually add a single FCF record. The caller |
| 16123 | * must pass a completely initialized FCF_Record. This routine takes |
| 16124 | * care of the nonembedded mailbox operations. |
| 16125 | **/ |
| 16126 | static void |
| 16127 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 16128 | { |
| 16129 | void *virt_addr; |
| 16130 | union lpfc_sli4_cfg_shdr *shdr; |
| 16131 | uint32_t shdr_status, shdr_add_status; |
| 16132 | |
| 16133 | virt_addr = mboxq->sge_array->addr[0]; |
| 16134 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16135 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 16136 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16137 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16138 | |
| 16139 | if ((shdr_status || shdr_add_status) && |
| 16140 | (shdr_status != STATUS_FCF_IN_USE)) |
| 16141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16142 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 16143 | "status x%x add_status x%x\n", |
| 16144 | shdr_status, shdr_add_status); |
| 16145 | |
| 16146 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16147 | } |
| 16148 | |
| 16149 | /** |
| 16150 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 16151 | * @phba: pointer to lpfc hba data structure. |
| 16152 | * @fcf_record: pointer to the initialized fcf record to add. |
| 16153 | * |
| 16154 | * This routine is invoked to manually add a single FCF record. The caller |
| 16155 | * must pass a completely initialized FCF_Record. This routine takes |
| 16156 | * care of the nonembedded mailbox operations. |
| 16157 | **/ |
| 16158 | int |
| 16159 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 16160 | { |
| 16161 | int rc = 0; |
| 16162 | LPFC_MBOXQ_t *mboxq; |
| 16163 | uint8_t *bytep; |
| 16164 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16165 | struct lpfc_mbx_sge sge; |
| 16166 | uint32_t alloc_len, req_len; |
| 16167 | uint32_t fcfindex; |
| 16168 | |
| 16169 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16170 | if (!mboxq) { |
| 16171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16172 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 16173 | return -ENOMEM; |
| 16174 | } |
| 16175 | |
| 16176 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 16177 | sizeof(uint32_t); |
| 16178 | |
| 16179 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16180 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16181 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 16182 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 16183 | if (alloc_len < req_len) { |
| 16184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16185 | "2523 Allocated DMA memory size (x%x) is " |
| 16186 | "less than the requested DMA memory " |
| 16187 | "size (x%x)\n", alloc_len, req_len); |
| 16188 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16189 | return -ENOMEM; |
| 16190 | } |
| 16191 | |
| 16192 | /* |
| 16193 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 16194 | * routine only uses a single SGE. |
| 16195 | */ |
| 16196 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16197 | virt_addr = mboxq->sge_array->addr[0]; |
| 16198 | /* |
| 16199 | * Configure the FCF record for FCFI 0. This is the driver's |
| 16200 | * hardcoded default and gets used in nonFIP mode. |
| 16201 | */ |
| 16202 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 16203 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 16204 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 16205 | |
| 16206 | /* |
| 16207 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 16208 | * the FCoE header plus word10. The data copy needs to be endian |
| 16209 | * correct. |
| 16210 | */ |
| 16211 | bytep += sizeof(uint32_t); |
| 16212 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 16213 | mboxq->vport = phba->pport; |
| 16214 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 16215 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16216 | if (rc == MBX_NOT_FINISHED) { |
| 16217 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16218 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 16219 | "status 0x%x\n", rc); |
| 16220 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16221 | rc = -EIO; |
| 16222 | } else |
| 16223 | rc = 0; |
| 16224 | |
| 16225 | return rc; |
| 16226 | } |
| 16227 | |
| 16228 | /** |
| 16229 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 16230 | * @phba: pointer to lpfc hba data structure. |
| 16231 | * @fcf_record: pointer to the fcf record to write the default data. |
| 16232 | * @fcf_index: FCF table entry index. |
| 16233 | * |
| 16234 | * This routine is invoked to build the driver's default FCF record. The |
| 16235 | * values used are hardcoded. This routine handles memory initialization. |
| 16236 | * |
| 16237 | **/ |
| 16238 | void |
| 16239 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 16240 | struct fcf_record *fcf_record, |
| 16241 | uint16_t fcf_index) |
| 16242 | { |
| 16243 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 16244 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 16245 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 16246 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 16247 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 16248 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 16249 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 16250 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 16251 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 16252 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 16253 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 16254 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 16255 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 16256 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 16257 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16258 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 16259 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 16260 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 16261 | /* Set the VLAN bit map */ |
| 16262 | if (phba->valid_vlan) { |
| 16263 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 16264 | = 1 << (phba->vlan_id % 8); |
| 16265 | } |
| 16266 | } |
| 16267 | |
| 16268 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16269 | * 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] | 16270 | * @phba: pointer to lpfc hba data structure. |
| 16271 | * @fcf_index: FCF table entry offset. |
| 16272 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16273 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 16274 | * record and processing it one at a time starting from the @fcf_index |
| 16275 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 16276 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16277 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16278 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16279 | **/ |
| 16280 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16281 | 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] | 16282 | { |
| 16283 | int rc = 0, error; |
| 16284 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16285 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16286 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 16287 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16288 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16289 | if (!mboxq) { |
| 16290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16291 | "2000 Failed to allocate mbox for " |
| 16292 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16293 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16294 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16295 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16296 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16297 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16298 | if (rc) { |
| 16299 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16300 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16301 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16302 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16303 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16304 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16305 | |
| 16306 | spin_lock_irq(&phba->hbalock); |
| 16307 | phba->hba_flag |= FCF_TS_INPROG; |
| 16308 | spin_unlock_irq(&phba->hbalock); |
| 16309 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16310 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16311 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16312 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16313 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 16314 | /* Reset eligible FCF count for new scan */ |
| 16315 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 16316 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16317 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16318 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16319 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16320 | if (error) { |
| 16321 | if (mboxq) |
| 16322 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16323 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16324 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16325 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16326 | spin_unlock_irq(&phba->hbalock); |
| 16327 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16328 | return error; |
| 16329 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16330 | |
| 16331 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16332 | * 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] | 16333 | * @phba: pointer to lpfc hba data structure. |
| 16334 | * @fcf_index: FCF table entry offset. |
| 16335 | * |
| 16336 | * 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] | 16337 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16338 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16339 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16340 | * otherwise. |
| 16341 | **/ |
| 16342 | int |
| 16343 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16344 | { |
| 16345 | int rc = 0, error; |
| 16346 | LPFC_MBOXQ_t *mboxq; |
| 16347 | |
| 16348 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16349 | if (!mboxq) { |
| 16350 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16351 | "2763 Failed to allocate mbox for " |
| 16352 | "READ_FCF cmd\n"); |
| 16353 | error = -ENOMEM; |
| 16354 | goto fail_fcf_read; |
| 16355 | } |
| 16356 | /* Construct the read FCF record mailbox command */ |
| 16357 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16358 | if (rc) { |
| 16359 | error = -EINVAL; |
| 16360 | goto fail_fcf_read; |
| 16361 | } |
| 16362 | /* Issue the mailbox command asynchronously */ |
| 16363 | mboxq->vport = phba->pport; |
| 16364 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 16365 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16366 | if (rc == MBX_NOT_FINISHED) |
| 16367 | error = -EIO; |
| 16368 | else |
| 16369 | error = 0; |
| 16370 | |
| 16371 | fail_fcf_read: |
| 16372 | if (error && mboxq) |
| 16373 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16374 | return error; |
| 16375 | } |
| 16376 | |
| 16377 | /** |
| 16378 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 16379 | * @phba: pointer to lpfc hba data structure. |
| 16380 | * @fcf_index: FCF table entry offset. |
| 16381 | * |
| 16382 | * 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] | 16383 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16384 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16385 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16386 | * otherwise. |
| 16387 | **/ |
| 16388 | int |
| 16389 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16390 | { |
| 16391 | int rc = 0, error; |
| 16392 | LPFC_MBOXQ_t *mboxq; |
| 16393 | |
| 16394 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16395 | if (!mboxq) { |
| 16396 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16397 | "2758 Failed to allocate mbox for " |
| 16398 | "READ_FCF cmd\n"); |
| 16399 | error = -ENOMEM; |
| 16400 | goto fail_fcf_read; |
| 16401 | } |
| 16402 | /* Construct the read FCF record mailbox command */ |
| 16403 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16404 | if (rc) { |
| 16405 | error = -EINVAL; |
| 16406 | goto fail_fcf_read; |
| 16407 | } |
| 16408 | /* Issue the mailbox command asynchronously */ |
| 16409 | mboxq->vport = phba->pport; |
| 16410 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 16411 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16412 | if (rc == MBX_NOT_FINISHED) |
| 16413 | error = -EIO; |
| 16414 | else |
| 16415 | error = 0; |
| 16416 | |
| 16417 | fail_fcf_read: |
| 16418 | if (error && mboxq) |
| 16419 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16420 | return error; |
| 16421 | } |
| 16422 | |
| 16423 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16424 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16425 | * phba pointer to the lpfc_hba struct for this port. |
| 16426 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 16427 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 16428 | * rr_bmask based on their priority level. Starting from the highest priority |
| 16429 | * to the lowest. The most likely FCF candidate will be in the highest |
| 16430 | * priority group. When this routine is called it searches the fcf_pri list for |
| 16431 | * next lowest priority group and repopulates the rr_bmask with only those |
| 16432 | * fcf_indexes. |
| 16433 | * returns: |
| 16434 | * 1=success 0=failure |
| 16435 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16436 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16437 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 16438 | { |
| 16439 | uint16_t next_fcf_pri; |
| 16440 | uint16_t last_index; |
| 16441 | struct lpfc_fcf_pri *fcf_pri; |
| 16442 | int rc; |
| 16443 | int ret = 0; |
| 16444 | |
| 16445 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 16446 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16447 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 16448 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16449 | |
| 16450 | /* Verify the priority list has 2 or more entries */ |
| 16451 | spin_lock_irq(&phba->hbalock); |
| 16452 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 16453 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 16454 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16455 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 16456 | "3061 Last IDX %d\n", last_index); |
| 16457 | return 0; /* Empty rr list */ |
| 16458 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16459 | spin_unlock_irq(&phba->hbalock); |
| 16460 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16461 | next_fcf_pri = 0; |
| 16462 | /* |
| 16463 | * Clear the rr_bmask and set all of the bits that are at this |
| 16464 | * priority. |
| 16465 | */ |
| 16466 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 16467 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 16468 | spin_lock_irq(&phba->hbalock); |
| 16469 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16470 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 16471 | continue; |
| 16472 | /* |
| 16473 | * the 1st priority that has not FLOGI failed |
| 16474 | * will be the highest. |
| 16475 | */ |
| 16476 | if (!next_fcf_pri) |
| 16477 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16478 | spin_unlock_irq(&phba->hbalock); |
| 16479 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16480 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16481 | fcf_pri->fcf_rec.fcf_index); |
| 16482 | if (rc) |
| 16483 | return 0; |
| 16484 | } |
| 16485 | spin_lock_irq(&phba->hbalock); |
| 16486 | } |
| 16487 | /* |
| 16488 | * if next_fcf_pri was not set above and the list is not empty then |
| 16489 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 16490 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16491 | */ |
| 16492 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 16493 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16494 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 16495 | /* |
| 16496 | * the 1st priority that has not FLOGI failed |
| 16497 | * will be the highest. |
| 16498 | */ |
| 16499 | if (!next_fcf_pri) |
| 16500 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16501 | spin_unlock_irq(&phba->hbalock); |
| 16502 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16503 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16504 | fcf_pri->fcf_rec.fcf_index); |
| 16505 | if (rc) |
| 16506 | return 0; |
| 16507 | } |
| 16508 | spin_lock_irq(&phba->hbalock); |
| 16509 | } |
| 16510 | } else |
| 16511 | ret = 1; |
| 16512 | spin_unlock_irq(&phba->hbalock); |
| 16513 | |
| 16514 | return ret; |
| 16515 | } |
| 16516 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16517 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 16518 | * @phba: pointer to lpfc hba data structure. |
| 16519 | * |
| 16520 | * This routine is to get the next eligible FCF record index in a round |
| 16521 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16522 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16523 | * shall be returned, otherwise, the next eligible FCF record's index |
| 16524 | * shall be returned. |
| 16525 | **/ |
| 16526 | uint16_t |
| 16527 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 16528 | { |
| 16529 | uint16_t next_fcf_index; |
| 16530 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16531 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16532 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16533 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 16534 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16535 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16536 | /* Determine the next fcf index to check */ |
| 16537 | 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] | 16538 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16539 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16540 | next_fcf_index); |
| 16541 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16542 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16543 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16544 | /* |
| 16545 | * If we have wrapped then we need to clear the bits that |
| 16546 | * have been tested so that we can detect when we should |
| 16547 | * change the priority level. |
| 16548 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16549 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16550 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16551 | } |
| 16552 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16553 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16554 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16555 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 16556 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 16557 | /* |
| 16558 | * If next fcf index is not found check if there are lower |
| 16559 | * Priority level fcf's in the fcf_priority list. |
| 16560 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 16561 | * at that level and continue the selection process. |
| 16562 | */ |
| 16563 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16564 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16565 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16566 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16567 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 16568 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16569 | else { |
| 16570 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16571 | "3063 Only FCF available idx %d, flag %x\n", |
| 16572 | next_fcf_index, |
| 16573 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 16574 | return next_fcf_index; |
| 16575 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16576 | } |
| 16577 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16578 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 16579 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16580 | LPFC_FCF_FLOGI_FAILED) { |
| 16581 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 16582 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16583 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16584 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16585 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16586 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16587 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16588 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 16589 | next_fcf_index); |
| 16590 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16591 | return next_fcf_index; |
| 16592 | } |
| 16593 | |
| 16594 | /** |
| 16595 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 16596 | * @phba: pointer to lpfc hba data structure. |
| 16597 | * |
| 16598 | * 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] | 16599 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16600 | * does not go beyond the range of the driver allocated bmask dimension |
| 16601 | * before setting the bit. |
| 16602 | * |
| 16603 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 16604 | * -EINVAL. |
| 16605 | **/ |
| 16606 | int |
| 16607 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16608 | { |
| 16609 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16610 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16611 | "2610 FCF (x%x) reached driver's book " |
| 16612 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16613 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16614 | return -EINVAL; |
| 16615 | } |
| 16616 | /* Set the eligible FCF record index bmask */ |
| 16617 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 16618 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16619 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16620 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16621 | "bmask\n", fcf_index); |
| 16622 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16623 | return 0; |
| 16624 | } |
| 16625 | |
| 16626 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16627 | * 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] | 16628 | * @phba: pointer to lpfc hba data structure. |
| 16629 | * |
| 16630 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16631 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16632 | * does not go beyond the range of the driver allocated bmask dimension |
| 16633 | * before clearing the bit. |
| 16634 | **/ |
| 16635 | void |
| 16636 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16637 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16638 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16639 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16640 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16641 | "2762 FCF (x%x) reached driver's book " |
| 16642 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16643 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16644 | return; |
| 16645 | } |
| 16646 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16647 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16648 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 16649 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16650 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 16651 | list_del_init(&fcf_pri->list); |
| 16652 | break; |
| 16653 | } |
| 16654 | } |
| 16655 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16656 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16657 | |
| 16658 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16659 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16660 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16661 | } |
| 16662 | |
| 16663 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16664 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 16665 | * @phba: pointer to lpfc hba data structure. |
| 16666 | * |
| 16667 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 16668 | * command. If the mailbox command returned failure, it will try to stop the |
| 16669 | * FCF rediscover wait timer. |
| 16670 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16671 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16672 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 16673 | { |
| 16674 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16675 | uint32_t shdr_status, shdr_add_status; |
| 16676 | |
| 16677 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16678 | |
| 16679 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 16680 | &redisc_fcf->header.cfg_shdr.response); |
| 16681 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 16682 | &redisc_fcf->header.cfg_shdr.response); |
| 16683 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16684 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16685 | "2746 Requesting for FCF rediscovery failed " |
| 16686 | "status x%x add_status x%x\n", |
| 16687 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16688 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16689 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16690 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16691 | spin_unlock_irq(&phba->hbalock); |
| 16692 | /* |
| 16693 | * CVL event triggered FCF rediscover request failed, |
| 16694 | * last resort to re-try current registered FCF entry. |
| 16695 | */ |
| 16696 | lpfc_retry_pport_discovery(phba); |
| 16697 | } else { |
| 16698 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16699 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16700 | spin_unlock_irq(&phba->hbalock); |
| 16701 | /* |
| 16702 | * DEAD FCF event triggered FCF rediscover request |
| 16703 | * failed, last resort to fail over as a link down |
| 16704 | * to FCF registration. |
| 16705 | */ |
| 16706 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 16707 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16708 | } else { |
| 16709 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16710 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16711 | /* |
| 16712 | * Start FCF rediscovery wait timer for pending FCF |
| 16713 | * before rescan FCF record table. |
| 16714 | */ |
| 16715 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16716 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16717 | |
| 16718 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16719 | } |
| 16720 | |
| 16721 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16722 | * 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] | 16723 | * @phba: pointer to lpfc hba data structure. |
| 16724 | * |
| 16725 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 16726 | * by the port. |
| 16727 | **/ |
| 16728 | int |
| 16729 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 16730 | { |
| 16731 | LPFC_MBOXQ_t *mbox; |
| 16732 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16733 | int rc, length; |
| 16734 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16735 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 16736 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 16737 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16738 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16739 | if (!mbox) { |
| 16740 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16741 | "2745 Failed to allocate mbox for " |
| 16742 | "requesting FCF rediscover.\n"); |
| 16743 | return -ENOMEM; |
| 16744 | } |
| 16745 | |
| 16746 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 16747 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16748 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16749 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 16750 | length, LPFC_SLI4_MBX_EMBED); |
| 16751 | |
| 16752 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16753 | /* Set count to 0 for invalidating the entire FCF database */ |
| 16754 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 16755 | |
| 16756 | /* Issue the mailbox command asynchronously */ |
| 16757 | mbox->vport = phba->pport; |
| 16758 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 16759 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 16760 | |
| 16761 | if (rc == MBX_NOT_FINISHED) { |
| 16762 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16763 | return -EIO; |
| 16764 | } |
| 16765 | return 0; |
| 16766 | } |
| 16767 | |
| 16768 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16769 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 16770 | * @phba: pointer to lpfc hba data structure. |
| 16771 | * |
| 16772 | * This function is the failover routine as a last resort to the FCF DEAD |
| 16773 | * event when driver failed to perform fast FCF failover. |
| 16774 | **/ |
| 16775 | void |
| 16776 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 16777 | { |
| 16778 | uint32_t link_state; |
| 16779 | |
| 16780 | /* |
| 16781 | * Last resort as FCF DEAD event failover will treat this as |
| 16782 | * a link down, but save the link state because we don't want |
| 16783 | * it to be changed to Link Down unless it is already down. |
| 16784 | */ |
| 16785 | link_state = phba->link_state; |
| 16786 | lpfc_linkdown(phba); |
| 16787 | phba->link_state = link_state; |
| 16788 | |
| 16789 | /* Unregister FCF if no devices connected to it */ |
| 16790 | lpfc_unregister_unused_fcf(phba); |
| 16791 | } |
| 16792 | |
| 16793 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16794 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16795 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16796 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16797 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16798 | * This function gets SLI3 port configure region 23 data through memory dump |
| 16799 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16800 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16801 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16802 | static uint32_t |
| 16803 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16804 | { |
| 16805 | LPFC_MBOXQ_t *pmb = NULL; |
| 16806 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16807 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16808 | int rc; |
| 16809 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16810 | if (!rgn23_data) |
| 16811 | return 0; |
| 16812 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16813 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16814 | if (!pmb) { |
| 16815 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16816 | "2600 failed to allocate mailbox memory\n"); |
| 16817 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16818 | } |
| 16819 | mb = &pmb->u.mb; |
| 16820 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16821 | do { |
| 16822 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 16823 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 16824 | |
| 16825 | if (rc != MBX_SUCCESS) { |
| 16826 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16827 | "2601 failed to read config " |
| 16828 | "region 23, rc 0x%x Status 0x%x\n", |
| 16829 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16830 | mb->un.varDmp.word_cnt = 0; |
| 16831 | } |
| 16832 | /* |
| 16833 | * dump mem may return a zero when finished or we got a |
| 16834 | * mailbox error, either way we are done. |
| 16835 | */ |
| 16836 | if (mb->un.varDmp.word_cnt == 0) |
| 16837 | break; |
| 16838 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 16839 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 16840 | |
| 16841 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16842 | rgn23_data + offset, |
| 16843 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16844 | offset += mb->un.varDmp.word_cnt; |
| 16845 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 16846 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16847 | mempool_free(pmb, phba->mbox_mem_pool); |
| 16848 | return offset; |
| 16849 | } |
| 16850 | |
| 16851 | /** |
| 16852 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 16853 | * @phba: pointer to lpfc hba data structure. |
| 16854 | * @rgn23_data: pointer to configure region 23 data. |
| 16855 | * |
| 16856 | * This function gets SLI4 port configure region 23 data through memory dump |
| 16857 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16858 | * will be returned, otherwise, 0 will be returned. |
| 16859 | **/ |
| 16860 | static uint32_t |
| 16861 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 16862 | { |
| 16863 | LPFC_MBOXQ_t *mboxq = NULL; |
| 16864 | struct lpfc_dmabuf *mp = NULL; |
| 16865 | struct lpfc_mqe *mqe; |
| 16866 | uint32_t data_length = 0; |
| 16867 | int rc; |
| 16868 | |
| 16869 | if (!rgn23_data) |
| 16870 | return 0; |
| 16871 | |
| 16872 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16873 | if (!mboxq) { |
| 16874 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16875 | "3105 failed to allocate mailbox memory\n"); |
| 16876 | return 0; |
| 16877 | } |
| 16878 | |
| 16879 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 16880 | goto out; |
| 16881 | mqe = &mboxq->u.mqe; |
| 16882 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 16883 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 16884 | if (rc) |
| 16885 | goto out; |
| 16886 | data_length = mqe->un.mb_words[5]; |
| 16887 | if (data_length == 0) |
| 16888 | goto out; |
| 16889 | if (data_length > DMP_RGN23_SIZE) { |
| 16890 | data_length = 0; |
| 16891 | goto out; |
| 16892 | } |
| 16893 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 16894 | out: |
| 16895 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16896 | if (mp) { |
| 16897 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16898 | kfree(mp); |
| 16899 | } |
| 16900 | return data_length; |
| 16901 | } |
| 16902 | |
| 16903 | /** |
| 16904 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 16905 | * @phba: pointer to lpfc hba data structure. |
| 16906 | * |
| 16907 | * This function read region 23 and parse TLV for port status to |
| 16908 | * decide if the user disaled the port. If the TLV indicates the |
| 16909 | * port is disabled, the hba_flag is set accordingly. |
| 16910 | **/ |
| 16911 | void |
| 16912 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 16913 | { |
| 16914 | uint8_t *rgn23_data = NULL; |
| 16915 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 16916 | uint32_t offset = 0; |
| 16917 | |
| 16918 | /* Get adapter Region 23 data */ |
| 16919 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 16920 | if (!rgn23_data) |
| 16921 | goto out; |
| 16922 | |
| 16923 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16924 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 16925 | else { |
| 16926 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 16927 | &phba->sli4_hba.sli_intf); |
| 16928 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 16929 | goto out; |
| 16930 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 16931 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16932 | |
| 16933 | if (!data_size) |
| 16934 | goto out; |
| 16935 | |
| 16936 | /* Check the region signature first */ |
| 16937 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 16938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16939 | "2619 Config region 23 has bad signature\n"); |
| 16940 | goto out; |
| 16941 | } |
| 16942 | offset += 4; |
| 16943 | |
| 16944 | /* Check the data structure version */ |
| 16945 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16947 | "2620 Config region 23 has bad version\n"); |
| 16948 | goto out; |
| 16949 | } |
| 16950 | offset += 4; |
| 16951 | |
| 16952 | /* Parse TLV entries in the region */ |
| 16953 | while (offset < data_size) { |
| 16954 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16955 | break; |
| 16956 | /* |
| 16957 | * If the TLV is not driver specific TLV or driver id is |
| 16958 | * not linux driver id, skip the record. |
| 16959 | */ |
| 16960 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16961 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16962 | (rgn23_data[offset + 3] != 0)) { |
| 16963 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16964 | continue; |
| 16965 | } |
| 16966 | |
| 16967 | /* Driver found a driver specific TLV in the config region */ |
| 16968 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16969 | offset += 4; |
| 16970 | tlv_offset = 0; |
| 16971 | |
| 16972 | /* |
| 16973 | * Search for configured port state sub-TLV. |
| 16974 | */ |
| 16975 | while ((offset < data_size) && |
| 16976 | (tlv_offset < sub_tlv_len)) { |
| 16977 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16978 | offset += 4; |
| 16979 | tlv_offset += 4; |
| 16980 | break; |
| 16981 | } |
| 16982 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16983 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16984 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16985 | continue; |
| 16986 | } |
| 16987 | |
| 16988 | /* This HBA contains PORT_STE configured */ |
| 16989 | if (!rgn23_data[offset + 2]) |
| 16990 | phba->hba_flag |= LINK_DISABLED; |
| 16991 | |
| 16992 | goto out; |
| 16993 | } |
| 16994 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16995 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16996 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16997 | kfree(rgn23_data); |
| 16998 | return; |
| 16999 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17000 | |
| 17001 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 17002 | * lpfc_wr_object - write an object to the firmware |
| 17003 | * @phba: HBA structure that indicates port to create a queue on. |
| 17004 | * @dmabuf_list: list of dmabufs to write to the port. |
| 17005 | * @size: the total byte value of the objects to write to the port. |
| 17006 | * @offset: the current offset to be used to start the transfer. |
| 17007 | * |
| 17008 | * This routine will create a wr_object mailbox command to send to the port. |
| 17009 | * the mailbox command will be constructed using the dma buffers described in |
| 17010 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 17011 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 17012 | * used to indicate the starting offset of the transfer and will also return |
| 17013 | * the offset after the write object mailbox has completed. @size is used to |
| 17014 | * determine the end of the object and whether the eof bit should be set. |
| 17015 | * |
| 17016 | * Return 0 is successful and offset will contain the the new offset to use |
| 17017 | * for the next write. |
| 17018 | * Return negative value for error cases. |
| 17019 | **/ |
| 17020 | int |
| 17021 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 17022 | uint32_t size, uint32_t *offset) |
| 17023 | { |
| 17024 | struct lpfc_mbx_wr_object *wr_object; |
| 17025 | LPFC_MBOXQ_t *mbox; |
| 17026 | int rc = 0, i = 0; |
| 17027 | uint32_t shdr_status, shdr_add_status; |
| 17028 | uint32_t mbox_tmo; |
| 17029 | union lpfc_sli4_cfg_shdr *shdr; |
| 17030 | struct lpfc_dmabuf *dmabuf; |
| 17031 | uint32_t written = 0; |
| 17032 | |
| 17033 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17034 | if (!mbox) |
| 17035 | return -ENOMEM; |
| 17036 | |
| 17037 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 17038 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 17039 | sizeof(struct lpfc_mbx_wr_object) - |
| 17040 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 17041 | |
| 17042 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 17043 | wr_object->u.request.write_offset = *offset; |
| 17044 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 17045 | wr_object->u.request.object_name[0] = |
| 17046 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 17047 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 17048 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 17049 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 17050 | break; |
| 17051 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 17052 | wr_object->u.request.bde[i].addrHigh = |
| 17053 | putPaddrHigh(dmabuf->phys); |
| 17054 | if (written + SLI4_PAGE_SIZE >= size) { |
| 17055 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 17056 | (size - written); |
| 17057 | written += (size - written); |
| 17058 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 17059 | } else { |
| 17060 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 17061 | SLI4_PAGE_SIZE; |
| 17062 | written += SLI4_PAGE_SIZE; |
| 17063 | } |
| 17064 | i++; |
| 17065 | } |
| 17066 | wr_object->u.request.bde_count = i; |
| 17067 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 17068 | if (!phba->sli4_hba.intr_enable) |
| 17069 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17070 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17071 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 17072 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17073 | } |
| 17074 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17075 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 17076 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17077 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17078 | if (rc != MBX_TIMEOUT) |
| 17079 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17080 | if (shdr_status || shdr_add_status || rc) { |
| 17081 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17082 | "3025 Write Object mailbox failed with " |
| 17083 | "status x%x add_status x%x, mbx status x%x\n", |
| 17084 | shdr_status, shdr_add_status, rc); |
| 17085 | rc = -ENXIO; |
| 17086 | } else |
| 17087 | *offset += wr_object->u.response.actual_write_length; |
| 17088 | return rc; |
| 17089 | } |
| 17090 | |
| 17091 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17092 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 17093 | * @vport: pointer to vport data structure. |
| 17094 | * |
| 17095 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 17096 | * and REG_VPI mailbox commands associated with the vport. This function |
| 17097 | * is called when driver want to restart discovery of the vport due to |
| 17098 | * a Clear Virtual Link event. |
| 17099 | **/ |
| 17100 | void |
| 17101 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 17102 | { |
| 17103 | struct lpfc_hba *phba = vport->phba; |
| 17104 | LPFC_MBOXQ_t *mb, *nextmb; |
| 17105 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17106 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17107 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17108 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17109 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17110 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17111 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17112 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17113 | spin_lock_irq(&phba->hbalock); |
| 17114 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 17115 | if (mb->vport != vport) |
| 17116 | continue; |
| 17117 | |
| 17118 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17119 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17120 | continue; |
| 17121 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17122 | list_del(&mb->list); |
| 17123 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 17124 | } |
| 17125 | /* Clean up active mailbox command with the vport */ |
| 17126 | mb = phba->sli.mbox_active; |
| 17127 | if (mb && (mb->vport == vport)) { |
| 17128 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 17129 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 17130 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17131 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17132 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17133 | /* Put reference count for delayed processing */ |
| 17134 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 17135 | /* Unregister the RPI when mailbox complete */ |
| 17136 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17137 | } |
| 17138 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17139 | /* Cleanup any mailbox completions which are not yet processed */ |
| 17140 | do { |
| 17141 | restart_loop = 0; |
| 17142 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 17143 | /* |
| 17144 | * If this mailox is already processed or it is |
| 17145 | * for another vport ignore it. |
| 17146 | */ |
| 17147 | if ((mb->vport != vport) || |
| 17148 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 17149 | continue; |
| 17150 | |
| 17151 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17152 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17153 | continue; |
| 17154 | |
| 17155 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17156 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17157 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17158 | /* Unregister the RPI when mailbox complete */ |
| 17159 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17160 | restart_loop = 1; |
| 17161 | spin_unlock_irq(&phba->hbalock); |
| 17162 | spin_lock(shost->host_lock); |
| 17163 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17164 | spin_unlock(shost->host_lock); |
| 17165 | spin_lock_irq(&phba->hbalock); |
| 17166 | break; |
| 17167 | } |
| 17168 | } |
| 17169 | } while (restart_loop); |
| 17170 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17171 | spin_unlock_irq(&phba->hbalock); |
| 17172 | |
| 17173 | /* Release the cleaned-up mailbox commands */ |
| 17174 | while (!list_empty(&mbox_cmd_list)) { |
| 17175 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17176 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17177 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 17178 | if (mp) { |
| 17179 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 17180 | kfree(mp); |
| 17181 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17182 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17183 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17184 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17185 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17186 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17187 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17188 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17189 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17190 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17191 | mempool_free(mb, phba->mbox_mem_pool); |
| 17192 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17193 | |
| 17194 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 17195 | if (act_mbx_ndlp) { |
| 17196 | spin_lock(shost->host_lock); |
| 17197 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17198 | spin_unlock(shost->host_lock); |
| 17199 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17200 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17201 | } |
| 17202 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17203 | /** |
| 17204 | * lpfc_drain_txq - Drain the txq |
| 17205 | * @phba: Pointer to HBA context object. |
| 17206 | * |
| 17207 | * This function attempt to submit IOCBs on the txq |
| 17208 | * to the adapter. For SLI4 adapters, the txq contains |
| 17209 | * ELS IOCBs that have been deferred because the there |
| 17210 | * are no SGLs. This congestion can occur with large |
| 17211 | * vport counts during node discovery. |
| 17212 | **/ |
| 17213 | |
| 17214 | uint32_t |
| 17215 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 17216 | { |
| 17217 | LIST_HEAD(completions); |
| 17218 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 17219 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17220 | unsigned long iflags = 0; |
| 17221 | char *fail_msg = NULL; |
| 17222 | struct lpfc_sglq *sglq; |
| 17223 | union lpfc_wqe wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17224 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17225 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17226 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17227 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 17228 | txq_cnt++; |
| 17229 | } |
| 17230 | |
| 17231 | if (txq_cnt > pring->txq_max) |
| 17232 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17233 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17234 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17235 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17236 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17237 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17238 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17239 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17240 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17241 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17242 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17243 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17244 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17245 | break; |
| 17246 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17247 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17248 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17249 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17250 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17251 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17252 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17253 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17254 | |
| 17255 | /* The xri and iocb resources secured, |
| 17256 | * attempt to issue request |
| 17257 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17258 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17259 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 17260 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 17261 | fail_msg = "to convert bpl to sgl"; |
| 17262 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 17263 | fail_msg = "to convert iocb to wqe"; |
| 17264 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 17265 | fail_msg = " - Wq is full"; |
| 17266 | else |
| 17267 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 17268 | |
| 17269 | if (fail_msg) { |
| 17270 | /* Failed means we can't issue and need to cancel */ |
| 17271 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17272 | "2822 IOCB failed %s iotag 0x%x " |
| 17273 | "xri 0x%x\n", |
| 17274 | fail_msg, |
| 17275 | piocbq->iotag, piocbq->sli4_xritag); |
| 17276 | list_add_tail(&piocbq->list, &completions); |
| 17277 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17278 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17279 | } |
| 17280 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17281 | /* Cancel all the IOCBs that cannot be issued */ |
| 17282 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 17283 | IOERR_SLI_ABORTED); |
| 17284 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17285 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17286 | } |