| 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" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | |
| 51 | /* There are only four IOCB completion types. */ |
| 52 | typedef enum _lpfc_iocb_type { |
| 53 | LPFC_UNKNOWN_IOCB, |
| 54 | LPFC_UNSOL_IOCB, |
| 55 | LPFC_SOL_IOCB, |
| 56 | LPFC_ABORT_IOCB |
| 57 | } lpfc_iocb_type; |
| 58 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 59 | |
| 60 | /* Provide function prototypes local to this module. */ |
| 61 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 62 | uint32_t); |
| 63 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 64 | uint8_t *, uint32_t *); |
| 65 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 66 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 67 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 68 | struct hbq_dmabuf *); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 69 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
| 70 | struct lpfc_cqe *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 71 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
| 72 | int); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 73 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
| 74 | uint32_t); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 75 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 76 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 77 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 78 | static IOCB_t * |
| 79 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 80 | { |
| 81 | return &iocbq->iocb; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 86 | * @q: The Work Queue to operate on. |
| 87 | * @wqe: The work Queue Entry to put on the Work queue. |
| 88 | * |
| 89 | * This routine will copy the contents of @wqe to the next available entry on |
| 90 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 91 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 92 | * successful. If no entries are available on @q then this function will return |
| 93 | * -ENOMEM. |
| 94 | * The caller is expected to hold the hbalock when calling this routine. |
| 95 | **/ |
| 96 | static uint32_t |
| 97 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 98 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 99 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 100 | struct lpfc_register doorbell; |
| 101 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 102 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 103 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 104 | /* sanity check on queue memory */ |
| 105 | if (unlikely(!q)) |
| 106 | return -ENOMEM; |
| 107 | temp_wqe = q->qe[q->host_index].wqe; |
| 108 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 109 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 110 | idx = ((q->host_index + 1) % q->entry_count); |
| 111 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 112 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 113 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 114 | } |
| 115 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 116 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 117 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 118 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | e0d35e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 119 | else |
| 120 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 121 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 122 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 123 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 01347f5 | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 124 | /* ensure WQE bcopy flushed before doorbell write */ |
| 125 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 126 | |
| 127 | /* Update the host index before invoking device */ |
| 128 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 129 | |
| 130 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 131 | |
| 132 | /* Ring Doorbell */ |
| 133 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 134 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 135 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 136 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 137 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 138 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 139 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 140 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 141 | } else { |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 151 | * @q: The Work Queue to operate on. |
| 152 | * @index: The index to advance the hba index to. |
| 153 | * |
| 154 | * This routine will update the HBA index of a queue to reflect consumption of |
| 155 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 156 | * an entry the host calls this function to update the queue's internal |
| 157 | * pointers. This routine returns the number of entries that were consumed by |
| 158 | * the HBA. |
| 159 | **/ |
| 160 | static uint32_t |
| 161 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 162 | { |
| 163 | uint32_t released = 0; |
| 164 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 165 | /* sanity check on queue memory */ |
| 166 | if (unlikely(!q)) |
| 167 | return 0; |
| 168 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 169 | if (q->hba_index == index) |
| 170 | return 0; |
| 171 | do { |
| 172 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 173 | released++; |
| 174 | } while (q->hba_index != index); |
| 175 | return released; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 180 | * @q: The Mailbox Queue to operate on. |
| 181 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 182 | * |
| 183 | * This routine will copy the contents of @mqe to the next available entry on |
| 184 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 185 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 186 | * successful. If no entries are available on @q then this function will return |
| 187 | * -ENOMEM. |
| 188 | * The caller is expected to hold the hbalock when calling this routine. |
| 189 | **/ |
| 190 | static uint32_t |
| 191 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 192 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 193 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 194 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 195 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 196 | /* sanity check on queue memory */ |
| 197 | if (unlikely(!q)) |
| 198 | return -ENOMEM; |
| 199 | temp_mqe = q->qe[q->host_index].mqe; |
| 200 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 201 | /* If the host has not yet processed the next entry then we are done */ |
| 202 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 203 | return -ENOMEM; |
| 204 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 205 | /* Save off the mailbox pointer for completion */ |
| 206 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 207 | |
| 208 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 209 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 210 | |
| 211 | /* Ring Doorbell */ |
| 212 | doorbell.word0 = 0; |
| 213 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 214 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 215 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 221 | * @q: The Mailbox Queue to operate on. |
| 222 | * |
| 223 | * This routine will update the HBA index of a queue to reflect consumption of |
| 224 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 225 | * an entry the host calls this function to update the queue's internal |
| 226 | * pointers. This routine returns the number of entries that were consumed by |
| 227 | * the HBA. |
| 228 | **/ |
| 229 | static uint32_t |
| 230 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 231 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 232 | /* sanity check on queue memory */ |
| 233 | if (unlikely(!q)) |
| 234 | return 0; |
| 235 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 236 | /* Clear the mailbox pointer for completion */ |
| 237 | q->phba->mbox = NULL; |
| 238 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 239 | return 1; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 244 | * @q: The Event Queue to get the first valid EQE from |
| 245 | * |
| 246 | * This routine will get the first valid Event Queue Entry from @q, update |
| 247 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 248 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 249 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 250 | **/ |
| 251 | static struct lpfc_eqe * |
| 252 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 253 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 254 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 255 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 256 | |
| 257 | /* sanity check on queue memory */ |
| 258 | if (unlikely(!q)) |
| 259 | return NULL; |
| 260 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 261 | |
| 262 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 263 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 264 | return NULL; |
| 265 | /* 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] | 266 | idx = ((q->hba_index + 1) % q->entry_count); |
| 267 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 268 | return NULL; |
| 269 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 270 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * insert barrier for instruction interlock : data from the hardware |
| 274 | * must have the valid bit checked before it can be copied and acted |
| 275 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 276 | * instructions allowing action on content before valid bit checked, |
| 277 | * add barrier here as well. May not be needed as "content" is a |
| 278 | * single 32-bit entity here (vs multi word structure for cq's). |
| 279 | */ |
| 280 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 281 | return eqe; |
| 282 | } |
| 283 | |
| 284 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 285 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 286 | * @q: The Event Queue to disable interrupts |
| 287 | * |
| 288 | **/ |
| 289 | static inline void |
| 290 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 291 | { |
| 292 | struct lpfc_register doorbell; |
| 293 | |
| 294 | doorbell.word0 = 0; |
| 295 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 296 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 297 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 298 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 299 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 300 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 301 | } |
| 302 | |
| 303 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 304 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 305 | * @q: The Event Queue that the host has completed processing for. |
| 306 | * @arm: Indicates whether the host wants to arms this CQ. |
| 307 | * |
| 308 | * This routine will mark all Event Queue Entries on @q, from the last |
| 309 | * known completed entry to the last entry that was processed, as completed |
| 310 | * by clearing the valid bit for each completion queue entry. Then it will |
| 311 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 312 | * The internal host index in the @q will be updated by this routine to indicate |
| 313 | * that the host has finished processing the entries. The @arm parameter |
| 314 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 315 | * |
| 316 | * This function will return the number of EQEs that were popped. |
| 317 | **/ |
| 318 | uint32_t |
| 319 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 320 | { |
| 321 | uint32_t released = 0; |
| 322 | struct lpfc_eqe *temp_eqe; |
| 323 | struct lpfc_register doorbell; |
| 324 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 325 | /* sanity check on queue memory */ |
| 326 | if (unlikely(!q)) |
| 327 | return 0; |
| 328 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 329 | /* while there are valid entries */ |
| 330 | while (q->hba_index != q->host_index) { |
| 331 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 332 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 333 | released++; |
| 334 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 335 | } |
| 336 | if (unlikely(released == 0 && !arm)) |
| 337 | return 0; |
| 338 | |
| 339 | /* ring doorbell for number popped */ |
| 340 | doorbell.word0 = 0; |
| 341 | if (arm) { |
| 342 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 343 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 344 | } |
| 345 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 346 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 347 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 348 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 349 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 350 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 351 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 352 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 353 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 354 | return released; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 359 | * @q: The Completion Queue to get the first valid CQE from |
| 360 | * |
| 361 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 362 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 363 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 364 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 365 | **/ |
| 366 | static struct lpfc_cqe * |
| 367 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 368 | { |
| 369 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 370 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 371 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 372 | /* sanity check on queue memory */ |
| 373 | if (unlikely(!q)) |
| 374 | return NULL; |
| 375 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 376 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 377 | 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] | 378 | return NULL; |
| 379 | /* 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] | 380 | idx = ((q->hba_index + 1) % q->entry_count); |
| 381 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 382 | return NULL; |
| 383 | |
| 384 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 385 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * insert barrier for instruction interlock : data from the hardware |
| 389 | * must have the valid bit checked before it can be copied and acted |
| 390 | * upon. Speculative instructions were allowing a bcopy at the start |
| 391 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 392 | * after our return, to copy data before the valid bit check above |
| 393 | * was done. As such, some of the copied data was stale. The barrier |
| 394 | * ensures the check is before any data is copied. |
| 395 | */ |
| 396 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 397 | return cqe; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 402 | * @q: The Completion Queue that the host has completed processing for. |
| 403 | * @arm: Indicates whether the host wants to arms this CQ. |
| 404 | * |
| 405 | * This routine will mark all Completion queue entries on @q, from the last |
| 406 | * known completed entry to the last entry that was processed, as completed |
| 407 | * by clearing the valid bit for each completion queue entry. Then it will |
| 408 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 409 | * The internal host index in the @q will be updated by this routine to indicate |
| 410 | * that the host has finished processing the entries. The @arm parameter |
| 411 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 412 | * |
| 413 | * This function will return the number of CQEs that were released. |
| 414 | **/ |
| 415 | uint32_t |
| 416 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 417 | { |
| 418 | uint32_t released = 0; |
| 419 | struct lpfc_cqe *temp_qe; |
| 420 | struct lpfc_register doorbell; |
| 421 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 422 | /* sanity check on queue memory */ |
| 423 | if (unlikely(!q)) |
| 424 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 425 | /* while there are valid entries */ |
| 426 | while (q->hba_index != q->host_index) { |
| 427 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 428 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 429 | released++; |
| 430 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 431 | } |
| 432 | if (unlikely(released == 0 && !arm)) |
| 433 | return 0; |
| 434 | |
| 435 | /* ring doorbell for number popped */ |
| 436 | doorbell.word0 = 0; |
| 437 | if (arm) |
| 438 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 439 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 440 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 441 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 442 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 443 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 444 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 445 | return released; |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 450 | * @q: The Header Receive Queue to operate on. |
| 451 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 452 | * |
| 453 | * This routine will copy the contents of @wqe to the next available entry on |
| 454 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 455 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 456 | * index that the rqe was copied to if successful. If no entries are available |
| 457 | * on @q then this function will return -ENOMEM. |
| 458 | * The caller is expected to hold the hbalock when calling this routine. |
| 459 | **/ |
| 460 | static int |
| 461 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 462 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 463 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 464 | struct lpfc_rqe *temp_hrqe; |
| 465 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 466 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 467 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 468 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 469 | /* sanity check on queue memory */ |
| 470 | if (unlikely(!hq) || unlikely(!dq)) |
| 471 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 472 | put_index = hq->host_index; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 473 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 474 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 475 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 476 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 477 | return -EINVAL; |
| 478 | if (hq->host_index != dq->host_index) |
| 479 | return -EINVAL; |
| 480 | /* If the host has not yet processed the next entry then we are done */ |
| 481 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 482 | return -EBUSY; |
| 483 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 484 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 485 | |
| 486 | /* Update the host index to point to the next slot */ |
| 487 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 488 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 489 | |
| 490 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 491 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 492 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 493 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 494 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 495 | hq->entry_repost); |
| 496 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 497 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 498 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 499 | hq->entry_repost); |
| 500 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 501 | hq->host_index); |
| 502 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 503 | } else { |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 507 | } |
| 508 | return put_index; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 513 | * @q: The Header Receive Queue to operate on. |
| 514 | * |
| 515 | * This routine will update the HBA index of a queue to reflect consumption of |
| 516 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 517 | * consumed an entry the host calls this function to update the queue's |
| 518 | * internal pointers. This routine returns the number of entries that were |
| 519 | * consumed by the HBA. |
| 520 | **/ |
| 521 | static uint32_t |
| 522 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 523 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 524 | /* sanity check on queue memory */ |
| 525 | if (unlikely(!hq) || unlikely(!dq)) |
| 526 | return 0; |
| 527 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 528 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 529 | return 0; |
| 530 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 531 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 532 | return 1; |
| 533 | } |
| 534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 536 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 537 | * @phba: Pointer to HBA context object. |
| 538 | * @pring: Pointer to driver SLI ring object. |
| 539 | * |
| 540 | * This function returns pointer to next command iocb entry |
| 541 | * in the command ring. The caller must hold hbalock to prevent |
| 542 | * other threads consume the next command iocb. |
| 543 | * SLI-2/SLI-3 provide different sized iocbs. |
| 544 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 545 | static inline IOCB_t * |
| 546 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 547 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 548 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 549 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 550 | } |
| 551 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 552 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 553 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 554 | * @phba: Pointer to HBA context object. |
| 555 | * @pring: Pointer to driver SLI ring object. |
| 556 | * |
| 557 | * This function returns pointer to next response iocb entry |
| 558 | * in the response ring. The caller must hold hbalock to make sure |
| 559 | * that no other thread consume the next response iocb. |
| 560 | * SLI-2/SLI-3 provide different sized iocbs. |
| 561 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 562 | static inline IOCB_t * |
| 563 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 564 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 565 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 566 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 567 | } |
| 568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 569 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 570 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 571 | * @phba: Pointer to HBA context object. |
| 572 | * |
| 573 | * This function is called with hbalock held. This function |
| 574 | * allocates a new driver iocb object from the iocb pool. If the |
| 575 | * allocation is successful, it returns pointer to the newly |
| 576 | * allocated iocb object else it returns NULL. |
| 577 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 578 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 579 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 580 | { |
| 581 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 582 | struct lpfc_iocbq * iocbq = NULL; |
| 583 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 584 | lockdep_assert_held(&phba->hbalock); |
| 585 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 586 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 587 | if (iocbq) |
| 588 | phba->iocb_cnt++; |
| 589 | if (phba->iocb_cnt > phba->iocb_max) |
| 590 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 591 | return iocbq; |
| 592 | } |
| 593 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 594 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 595 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 596 | * @phba: Pointer to HBA context object. |
| 597 | * @xritag: XRI value. |
| 598 | * |
| 599 | * This function clears the sglq pointer from the array of acive |
| 600 | * sglq's. The xritag that is passed in is used to index into the |
| 601 | * array. Before the xritag can be used it needs to be adjusted |
| 602 | * by subtracting the xribase. |
| 603 | * |
| 604 | * Returns sglq ponter = success, NULL = Failure. |
| 605 | **/ |
| 606 | static struct lpfc_sglq * |
| 607 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 608 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 609 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 610 | |
| 611 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 612 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 613 | return sglq; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 618 | * @phba: Pointer to HBA context object. |
| 619 | * @xritag: XRI value. |
| 620 | * |
| 621 | * This function returns the sglq pointer from the array of acive |
| 622 | * sglq's. The xritag that is passed in is used to index into the |
| 623 | * array. Before the xritag can be used it needs to be adjusted |
| 624 | * by subtracting the xribase. |
| 625 | * |
| 626 | * Returns sglq ponter = success, NULL = Failure. |
| 627 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 628 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 629 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 630 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 631 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 632 | |
| 633 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 634 | return sglq; |
| 635 | } |
| 636 | |
| 637 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 638 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 639 | * @phba: Pointer to HBA context object. |
| 640 | * @xritag: xri used in this exchange. |
| 641 | * @rrq: The RRQ to be cleared. |
| 642 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 643 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 644 | void |
| 645 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 646 | uint16_t xritag, |
| 647 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 648 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 649 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 650 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 651 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 652 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 653 | |
| 654 | /* The target DID could have been swapped (cable swap) |
| 655 | * we should use the ndlp from the findnode if it is |
| 656 | * available. |
| 657 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 658 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 659 | ndlp = rrq->ndlp; |
| 660 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 661 | if (!ndlp) |
| 662 | goto out; |
| 663 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 664 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 665 | rrq->send_rrq = 0; |
| 666 | rrq->xritag = 0; |
| 667 | rrq->rrq_stop_time = 0; |
| 668 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 669 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 670 | mempool_free(rrq, phba->rrq_pool); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 675 | * @phba: Pointer to HBA context object. |
| 676 | * |
| 677 | * This function is called with hbalock held. This function |
| 678 | * Checks if stop_time (ratov from setting rrq active) has |
| 679 | * been reached, if it has and the send_rrq flag is set then |
| 680 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 681 | * then it will just call the routine to clear the rrq and |
| 682 | * free the rrq resource. |
| 683 | * The timer is set to the next rrq that is going to expire before |
| 684 | * leaving the routine. |
| 685 | * |
| 686 | **/ |
| 687 | void |
| 688 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 689 | { |
| 690 | struct lpfc_node_rrq *rrq; |
| 691 | struct lpfc_node_rrq *nextrrq; |
| 692 | unsigned long next_time; |
| 693 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 694 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 695 | |
| 696 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 697 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 698 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 699 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 700 | &phba->active_rrq_list, list) { |
| 701 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 702 | list_move(&rrq->list, &send_rrq); |
| 703 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 704 | next_time = rrq->rrq_stop_time; |
| 705 | } |
| 706 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 707 | if ((!list_empty(&phba->active_rrq_list)) && |
| 708 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 709 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 710 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 711 | list_del(&rrq->list); |
| 712 | if (!rrq->send_rrq) |
| 713 | /* this call will free the rrq */ |
| 714 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 715 | else if (lpfc_send_rrq(phba, rrq)) { |
| 716 | /* if we send the rrq then the completion handler |
| 717 | * will clear the bit in the xribitmap. |
| 718 | */ |
| 719 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 720 | rrq); |
| 721 | } |
| 722 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** |
| 726 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 727 | * @vport: Pointer to vport context object. |
| 728 | * @xri: The xri used in the exchange. |
| 729 | * @did: The targets DID for this exchange. |
| 730 | * |
| 731 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 732 | * rrq = rrq for this xri and target. |
| 733 | **/ |
| 734 | struct lpfc_node_rrq * |
| 735 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 736 | { |
| 737 | struct lpfc_hba *phba = vport->phba; |
| 738 | struct lpfc_node_rrq *rrq; |
| 739 | struct lpfc_node_rrq *nextrrq; |
| 740 | unsigned long iflags; |
| 741 | |
| 742 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 743 | return NULL; |
| 744 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 745 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 746 | if (rrq->vport == vport && rrq->xritag == xri && |
| 747 | rrq->nlp_DID == did){ |
| 748 | list_del(&rrq->list); |
| 749 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 750 | return rrq; |
| 751 | } |
| 752 | } |
| 753 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 754 | return NULL; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 759 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 760 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 761 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 762 | * phba->active_rrq_list and clear the rrq. |
| 763 | * 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] | 764 | **/ |
| 765 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 766 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 767 | |
| 768 | { |
| 769 | struct lpfc_hba *phba = vport->phba; |
| 770 | struct lpfc_node_rrq *rrq; |
| 771 | struct lpfc_node_rrq *nextrrq; |
| 772 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 773 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 774 | |
| 775 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 776 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 777 | if (!ndlp) { |
| 778 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 779 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 780 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 781 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 782 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 783 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 784 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 785 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 786 | |
| 787 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 788 | list_del(&rrq->list); |
| 789 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 790 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 794 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 795 | * @phba: Pointer to HBA context object. |
| 796 | * @ndlp: Targets nodelist pointer for this exchange. |
| 797 | * @xritag the xri in the bitmap to test. |
| 798 | * |
| 799 | * This function is called with hbalock held. This function |
| 800 | * returns 0 = rrq not active for this xri |
| 801 | * 1 = rrq is valid for this xri. |
| 802 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 803 | int |
| 804 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 805 | uint16_t xritag) |
| 806 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 807 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 808 | if (!ndlp) |
| 809 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 810 | if (!ndlp->active_rrqs_xri_bitmap) |
| 811 | return 0; |
| 812 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 813 | return 1; |
| 814 | else |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 820 | * @phba: Pointer to HBA context object. |
| 821 | * @ndlp: nodelist pointer for this target. |
| 822 | * @xritag: xri used in this exchange. |
| 823 | * @rxid: Remote Exchange ID. |
| 824 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 825 | * |
| 826 | * This function takes the hbalock. |
| 827 | * The active bit is always set in the active rrq xri_bitmap even |
| 828 | * if there is no slot avaiable for the other rrq information. |
| 829 | * |
| 830 | * returns 0 rrq actived for this xri |
| 831 | * < 0 No memory or invalid ndlp. |
| 832 | **/ |
| 833 | int |
| 834 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 835 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 836 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 837 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 838 | struct lpfc_node_rrq *rrq; |
| 839 | int empty; |
| 840 | |
| 841 | if (!ndlp) |
| 842 | return -EINVAL; |
| 843 | |
| 844 | if (!phba->cfg_enable_rrq) |
| 845 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 846 | |
| 847 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 848 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 849 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 850 | goto out; |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | * set the active bit even if there is no mem available. |
| 855 | */ |
| 856 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 857 | goto out; |
| 858 | |
| 859 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 860 | goto out; |
| 861 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 862 | if (!ndlp->active_rrqs_xri_bitmap) |
| 863 | goto out; |
| 864 | |
| 865 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 866 | goto out; |
| 867 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 869 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 870 | if (!rrq) { |
| 871 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 872 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 873 | " DID:0x%x Send:%d\n", |
| 874 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 875 | return -EINVAL; |
| 876 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 877 | if (phba->cfg_enable_rrq == 1) |
| 878 | rrq->send_rrq = send_rrq; |
| 879 | else |
| 880 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 881 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 882 | rrq->rrq_stop_time = jiffies + |
| 883 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 884 | rrq->ndlp = ndlp; |
| 885 | rrq->nlp_DID = ndlp->nlp_DID; |
| 886 | rrq->vport = ndlp->vport; |
| 887 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 888 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 889 | empty = list_empty(&phba->active_rrq_list); |
| 890 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 891 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 892 | if (empty) |
| 893 | lpfc_worker_wake_up(phba); |
| 894 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 895 | return 0; |
| 896 | out: |
| 897 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 898 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 899 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 900 | " DID:0x%x Send:%d\n", |
| 901 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 902 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 906 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 907 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 908 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 909 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 910 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 911 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 912 | * list is not empty then it is successful, it returns pointer to the newly |
| 913 | * allocated sglq object else it returns NULL. |
| 914 | **/ |
| 915 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 916 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 917 | { |
| 918 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 919 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 920 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 921 | struct lpfc_scsi_buf *lpfc_cmd; |
| 922 | struct lpfc_nodelist *ndlp; |
| 923 | int found = 0; |
| 924 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 925 | lockdep_assert_held(&phba->hbalock); |
| 926 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 927 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 928 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 929 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 930 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 931 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 932 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 933 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 934 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 935 | ndlp = NULL; |
| 936 | else |
| 937 | ndlp = piocbq->context_un.ndlp; |
| 938 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 939 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 940 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 941 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 942 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 943 | start_sglq = sglq; |
| 944 | while (!found) { |
| 945 | if (!sglq) |
| 946 | return NULL; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 947 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 948 | /* This xri has an rrq outstanding for this DID. |
| 949 | * put it back in the list and get another xri. |
| 950 | */ |
| 951 | list_add_tail(&sglq->list, lpfc_sgl_list); |
| 952 | sglq = NULL; |
| 953 | list_remove_head(lpfc_sgl_list, sglq, |
| 954 | struct lpfc_sglq, list); |
| 955 | if (sglq == start_sglq) { |
| 956 | sglq = NULL; |
| 957 | break; |
| 958 | } else |
| 959 | continue; |
| 960 | } |
| 961 | sglq->ndlp = ndlp; |
| 962 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 963 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 964 | sglq->state = SGL_ALLOCATED; |
| 965 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 966 | return sglq; |
| 967 | } |
| 968 | |
| 969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 970 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 971 | * @phba: Pointer to HBA context object. |
| 972 | * |
| 973 | * This function is called with no lock held. This function |
| 974 | * allocates a new driver iocb object from the iocb pool. If the |
| 975 | * allocation is successful, it returns pointer to the newly |
| 976 | * allocated iocb object else it returns NULL. |
| 977 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 978 | struct lpfc_iocbq * |
| 979 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 980 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 981 | struct lpfc_iocbq * iocbq = NULL; |
| 982 | unsigned long iflags; |
| 983 | |
| 984 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 985 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 986 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 987 | return iocbq; |
| 988 | } |
| 989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 990 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 991 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 992 | * @phba: Pointer to HBA context object. |
| 993 | * @iocbq: Pointer to driver iocb object. |
| 994 | * |
| 995 | * This function is called with hbalock held to release driver |
| 996 | * iocb object to the iocb pool. The iotag in the iocb object |
| 997 | * does not change for each use of the iocb object. This function |
| 998 | * clears all other fields of the iocb object when it is freed. |
| 999 | * The sqlq structure that holds the xritag and phys and virtual |
| 1000 | * mappings for the scatter gather list is retrieved from the |
| 1001 | * active array of sglq. The get of the sglq pointer also clears |
| 1002 | * the entry in the array. If the status of the IO indiactes that |
| 1003 | * this IO was aborted then the sglq entry it put on the |
| 1004 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1005 | * IO has good status or fails for any other reason then the sglq |
| 1006 | * entry is added to the free list (lpfc_sgl_list). |
| 1007 | **/ |
| 1008 | static void |
| 1009 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1010 | { |
| 1011 | struct lpfc_sglq *sglq; |
| 1012 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1013 | unsigned long iflag = 0; |
| 1014 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1015 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1016 | lockdep_assert_held(&phba->hbalock); |
| 1017 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1018 | if (iocbq->sli4_xritag == NO_XRI) |
| 1019 | sglq = NULL; |
| 1020 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1021 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1022 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1023 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1024 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1025 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1026 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1027 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 1028 | iflag); |
| 1029 | list_add(&sglq->list, |
| 1030 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1031 | spin_unlock_irqrestore( |
| 1032 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1033 | } else { |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1034 | spin_lock_irqsave(&pring->ring_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1035 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1036 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1037 | list_add_tail(&sglq->list, |
| 1038 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1039 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1040 | |
| 1041 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1042 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1043 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1044 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | /* |
| 1049 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1050 | */ |
| 1051 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1052 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1053 | iocbq->sli4_xritag = NO_XRI; |
| 1054 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1055 | } |
| 1056 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1057 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1058 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1059 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1060 | * @phba: Pointer to HBA context object. |
| 1061 | * @iocbq: Pointer to driver iocb object. |
| 1062 | * |
| 1063 | * This function is called with hbalock held to release driver |
| 1064 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1065 | * does not change for each use of the iocb object. This function |
| 1066 | * clears all other fields of the iocb object when it is freed. |
| 1067 | **/ |
| 1068 | static void |
| 1069 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1070 | { |
| 1071 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1072 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1073 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1074 | |
| 1075 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1076 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1077 | */ |
| 1078 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1079 | iocbq->sli4_xritag = NO_XRI; |
| 1080 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1081 | } |
| 1082 | |
| 1083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1084 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1085 | * @phba: Pointer to HBA context object. |
| 1086 | * @iocbq: Pointer to driver iocb object. |
| 1087 | * |
| 1088 | * This function is called with hbalock held to release driver |
| 1089 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1090 | * does not change for each use of the iocb object. This function |
| 1091 | * clears all other fields of the iocb object when it is freed. |
| 1092 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1093 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1094 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1095 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1096 | lockdep_assert_held(&phba->hbalock); |
| 1097 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1098 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1099 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1100 | } |
| 1101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1102 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1103 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1104 | * @phba: Pointer to HBA context object. |
| 1105 | * @iocbq: Pointer to driver iocb object. |
| 1106 | * |
| 1107 | * This function is called with no lock held to release the iocb to |
| 1108 | * iocb pool. |
| 1109 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | void |
| 1111 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1112 | { |
| 1113 | unsigned long iflags; |
| 1114 | |
| 1115 | /* |
| 1116 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1117 | */ |
| 1118 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1119 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1120 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1121 | } |
| 1122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1123 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1124 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1125 | * @phba: Pointer to HBA context object. |
| 1126 | * @iocblist: List of IOCBs. |
| 1127 | * @ulpstatus: ULP status in IOCB command field. |
| 1128 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1129 | * |
| 1130 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1131 | * on the list by invoking the complete callback function associated with the |
| 1132 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1133 | * fields. |
| 1134 | **/ |
| 1135 | void |
| 1136 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1137 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1138 | { |
| 1139 | struct lpfc_iocbq *piocb; |
| 1140 | |
| 1141 | while (!list_empty(iocblist)) { |
| 1142 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1143 | if (!piocb->iocb_cmpl) |
| 1144 | lpfc_sli_release_iocbq(phba, piocb); |
| 1145 | else { |
| 1146 | piocb->iocb.ulpStatus = ulpstatus; |
| 1147 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1148 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1149 | } |
| 1150 | } |
| 1151 | return; |
| 1152 | } |
| 1153 | |
| 1154 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1155 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1156 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | * |
| 1158 | * This function is called by ring event handler function to get the iocb type. |
| 1159 | * This function translates the iocb command to an iocb command type used to |
| 1160 | * decide the final disposition of each completed IOCB. |
| 1161 | * The function returns |
| 1162 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1163 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1164 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1165 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1166 | * |
| 1167 | * The caller is not required to hold any lock. |
| 1168 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | static lpfc_iocb_type |
| 1170 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1171 | { |
| 1172 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1173 | |
| 1174 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1175 | return 0; |
| 1176 | |
| 1177 | switch (iocb_cmnd) { |
| 1178 | case CMD_XMIT_SEQUENCE_CR: |
| 1179 | case CMD_XMIT_SEQUENCE_CX: |
| 1180 | case CMD_XMIT_BCAST_CN: |
| 1181 | case CMD_XMIT_BCAST_CX: |
| 1182 | case CMD_ELS_REQUEST_CR: |
| 1183 | case CMD_ELS_REQUEST_CX: |
| 1184 | case CMD_CREATE_XRI_CR: |
| 1185 | case CMD_CREATE_XRI_CX: |
| 1186 | case CMD_GET_RPI_CN: |
| 1187 | case CMD_XMIT_ELS_RSP_CX: |
| 1188 | case CMD_GET_RPI_CR: |
| 1189 | case CMD_FCP_IWRITE_CR: |
| 1190 | case CMD_FCP_IWRITE_CX: |
| 1191 | case CMD_FCP_IREAD_CR: |
| 1192 | case CMD_FCP_IREAD_CX: |
| 1193 | case CMD_FCP_ICMND_CR: |
| 1194 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1195 | case CMD_FCP_TSEND_CX: |
| 1196 | case CMD_FCP_TRSP_CX: |
| 1197 | case CMD_FCP_TRECEIVE_CX: |
| 1198 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | case CMD_ADAPTER_MSG: |
| 1200 | case CMD_ADAPTER_DUMP: |
| 1201 | case CMD_XMIT_SEQUENCE64_CR: |
| 1202 | case CMD_XMIT_SEQUENCE64_CX: |
| 1203 | case CMD_XMIT_BCAST64_CN: |
| 1204 | case CMD_XMIT_BCAST64_CX: |
| 1205 | case CMD_ELS_REQUEST64_CR: |
| 1206 | case CMD_ELS_REQUEST64_CX: |
| 1207 | case CMD_FCP_IWRITE64_CR: |
| 1208 | case CMD_FCP_IWRITE64_CX: |
| 1209 | case CMD_FCP_IREAD64_CR: |
| 1210 | case CMD_FCP_IREAD64_CX: |
| 1211 | case CMD_FCP_ICMND64_CR: |
| 1212 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1213 | case CMD_FCP_TSEND64_CX: |
| 1214 | case CMD_FCP_TRSP64_CX: |
| 1215 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | case CMD_GEN_REQUEST64_CR: |
| 1217 | case CMD_GEN_REQUEST64_CX: |
| 1218 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1219 | case DSSCMD_IWRITE64_CR: |
| 1220 | case DSSCMD_IWRITE64_CX: |
| 1221 | case DSSCMD_IREAD64_CR: |
| 1222 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | type = LPFC_SOL_IOCB; |
| 1224 | break; |
| 1225 | case CMD_ABORT_XRI_CN: |
| 1226 | case CMD_ABORT_XRI_CX: |
| 1227 | case CMD_CLOSE_XRI_CN: |
| 1228 | case CMD_CLOSE_XRI_CX: |
| 1229 | case CMD_XRI_ABORTED_CX: |
| 1230 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1231 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1232 | type = LPFC_ABORT_IOCB; |
| 1233 | break; |
| 1234 | case CMD_RCV_SEQUENCE_CX: |
| 1235 | case CMD_RCV_ELS_REQ_CX: |
| 1236 | case CMD_RCV_SEQUENCE64_CX: |
| 1237 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1238 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1239 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1240 | case CMD_IOCB_RCV_ELS64_CX: |
| 1241 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1242 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | type = LPFC_UNSOL_IOCB; |
| 1244 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1245 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1246 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1247 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1248 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1249 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1250 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1251 | case CMD_IOCB_RET_HBQE64_CN: |
| 1252 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1253 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1254 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1255 | case CMD_IOCB_LOGENTRY_CN: |
| 1256 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1257 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1258 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1259 | type = LPFC_UNKNOWN_IOCB; |
| 1260 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | default: |
| 1262 | type = LPFC_UNKNOWN_IOCB; |
| 1263 | break; |
| 1264 | } |
| 1265 | |
| 1266 | return type; |
| 1267 | } |
| 1268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1270 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1271 | * @phba: Pointer to HBA context object. |
| 1272 | * |
| 1273 | * This function is called from SLI initialization code |
| 1274 | * to configure every ring of the HBA's SLI interface. The |
| 1275 | * caller is not required to hold any lock. This function issues |
| 1276 | * a config_ring mailbox command for each ring. |
| 1277 | * This function returns zero if successful else returns a negative |
| 1278 | * error code. |
| 1279 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1281 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1282 | { |
| 1283 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1284 | LPFC_MBOXQ_t *pmb; |
| 1285 | MAILBOX_t *pmbox; |
| 1286 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1288 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1289 | if (!pmb) |
| 1290 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1291 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1292 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | lpfc_config_ring(phba, i, pmb); |
| 1295 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1296 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1298 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1300 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1301 | rc, pmbox->mbxCommand, |
| 1302 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1303 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1304 | ret = -ENXIO; |
| 1305 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | } |
| 1307 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1308 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1309 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | } |
| 1311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1313 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1314 | * @phba: Pointer to HBA context object. |
| 1315 | * @pring: Pointer to driver SLI ring object. |
| 1316 | * @piocb: Pointer to the driver iocb object. |
| 1317 | * |
| 1318 | * This function is called with hbalock held. The function adds the |
| 1319 | * new iocb to txcmplq of the given ring. This function always returns |
| 1320 | * 0. If this function is called for ELS ring, this function checks if |
| 1321 | * there is a vport associated with the ELS command. This function also |
| 1322 | * starts els_tmofunc timer if this is an ELS command. |
| 1323 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1324 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1325 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1326 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1328 | lockdep_assert_held(&phba->hbalock); |
| 1329 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1330 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1331 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1333 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1334 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1335 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1336 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1337 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1338 | BUG_ON(!piocb->vport); |
| 1339 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1340 | mod_timer(&piocb->vport->els_tmofunc, |
| 1341 | jiffies + |
| 1342 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1343 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | } |
| 1347 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1349 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | * @phba: Pointer to HBA context object. |
| 1351 | * @pring: Pointer to driver SLI ring object. |
| 1352 | * |
| 1353 | * This function is called with hbalock held to get next |
| 1354 | * iocb in txq of the given ring. If there is any iocb in |
| 1355 | * the txq, the function returns first iocb in the list after |
| 1356 | * removing the iocb from the list, else it returns NULL. |
| 1357 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1358 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | struct lpfc_iocbq *cmd_iocb; |
| 1362 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1363 | lockdep_assert_held(&phba->hbalock); |
| 1364 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1365 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1366 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | } |
| 1368 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1369 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1370 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1371 | * @phba: Pointer to HBA context object. |
| 1372 | * @pring: Pointer to driver SLI ring object. |
| 1373 | * |
| 1374 | * This function is called with hbalock held and the caller must post the |
| 1375 | * iocb without releasing the lock. If the caller releases the lock, |
| 1376 | * iocb slot returned by the function is not guaranteed to be available. |
| 1377 | * The function returns pointer to the next available iocb slot if there |
| 1378 | * is available slot in the ring, else it returns NULL. |
| 1379 | * If the get index of the ring is ahead of the put index, the function |
| 1380 | * will post an error attention event to the worker thread to take the |
| 1381 | * HBA to offline state. |
| 1382 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | static IOCB_t * |
| 1384 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1385 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1386 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1387 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1388 | |
| 1389 | lockdep_assert_held(&phba->hbalock); |
| 1390 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1391 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1392 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1393 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1395 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1396 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1398 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1400 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1402 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1403 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1404 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1405 | pring->sli.sli3.local_getidx, |
| 1406 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1408 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | /* |
| 1410 | * All error attention handlers are posted to |
| 1411 | * worker thread |
| 1412 | */ |
| 1413 | phba->work_ha |= HA_ERATT; |
| 1414 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1415 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1416 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1421 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | return NULL; |
| 1423 | } |
| 1424 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1425 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1429 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1430 | * @phba: Pointer to HBA context object. |
| 1431 | * @iocbq: Pointer to driver iocb object. |
| 1432 | * |
| 1433 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1434 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1435 | * array and assigns a new iotag. |
| 1436 | * The function returns the allocated iotag if successful, else returns zero. |
| 1437 | * Zero is not a valid iotag. |
| 1438 | * The caller is not required to hold any lock. |
| 1439 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1440 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1441 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1443 | struct lpfc_iocbq **new_arr; |
| 1444 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1445 | size_t new_len; |
| 1446 | struct lpfc_sli *psli = &phba->sli; |
| 1447 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1449 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1450 | iotag = psli->last_iotag; |
| 1451 | if(++iotag < psli->iocbq_lookup_len) { |
| 1452 | psli->last_iotag = iotag; |
| 1453 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1454 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1455 | iocbq->iotag = iotag; |
| 1456 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1458 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1459 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1460 | spin_unlock_irq(&phba->hbalock); |
| 1461 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1462 | GFP_KERNEL); |
| 1463 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1464 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1465 | old_arr = psli->iocbq_lookup; |
| 1466 | if (new_len <= psli->iocbq_lookup_len) { |
| 1467 | /* highly unprobable case */ |
| 1468 | kfree(new_arr); |
| 1469 | iotag = psli->last_iotag; |
| 1470 | if(++iotag < psli->iocbq_lookup_len) { |
| 1471 | psli->last_iotag = iotag; |
| 1472 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1473 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1474 | iocbq->iotag = iotag; |
| 1475 | return iotag; |
| 1476 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1477 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1478 | return 0; |
| 1479 | } |
| 1480 | if (psli->iocbq_lookup) |
| 1481 | memcpy(new_arr, old_arr, |
| 1482 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1483 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1484 | psli->iocbq_lookup = new_arr; |
| 1485 | psli->iocbq_lookup_len = new_len; |
| 1486 | psli->last_iotag = iotag; |
| 1487 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1488 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1489 | iocbq->iotag = iotag; |
| 1490 | kfree(old_arr); |
| 1491 | return iotag; |
| 1492 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1493 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1496 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1497 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1498 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1500 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1504 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1505 | * @phba: Pointer to HBA context object. |
| 1506 | * @pring: Pointer to driver SLI ring object. |
| 1507 | * @iocb: Pointer to iocb slot in the ring. |
| 1508 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1509 | * posted to firmware. |
| 1510 | * |
| 1511 | * This function is called with hbalock held to post a new iocb to |
| 1512 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1513 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1514 | * a completion call back for this iocb else the function will free the |
| 1515 | * iocb object. |
| 1516 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | static void |
| 1518 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1519 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1520 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1521 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1523 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1524 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1525 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1526 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1527 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1528 | if (pring->ringno == LPFC_ELS_RING) { |
| 1529 | lpfc_debugfs_slow_ring_trc(phba, |
| 1530 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1531 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1532 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1533 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1534 | } |
| 1535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | /* |
| 1537 | * Issue iocb command to adapter |
| 1538 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1539 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1540 | wmb(); |
| 1541 | pring->stats.iocb_cmd++; |
| 1542 | |
| 1543 | /* |
| 1544 | * If there is no completion routine to call, we can release the |
| 1545 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1546 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1547 | */ |
| 1548 | if (nextiocb->iocb_cmpl) |
| 1549 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1550 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | |
| 1553 | /* |
| 1554 | * Let the HBA know what IOCB slot will be the next one the |
| 1555 | * driver will put a command into. |
| 1556 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1557 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1558 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | } |
| 1560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1561 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1562 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1563 | * @phba: Pointer to HBA context object. |
| 1564 | * @pring: Pointer to driver SLI ring object. |
| 1565 | * |
| 1566 | * The caller is not required to hold any lock for calling this function. |
| 1567 | * This function updates the chip attention bits for the ring to inform firmware |
| 1568 | * that there are pending work to be done for this ring and requests an |
| 1569 | * interrupt when there is space available in the ring. This function is |
| 1570 | * called when the driver is unable to post more iocbs to the ring due |
| 1571 | * to unavailability of space in the ring. |
| 1572 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1573 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1574 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | { |
| 1576 | int ringno = pring->ringno; |
| 1577 | |
| 1578 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1579 | |
| 1580 | wmb(); |
| 1581 | |
| 1582 | /* |
| 1583 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1584 | * The HBA will tell us when an IOCB entry is available. |
| 1585 | */ |
| 1586 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1587 | readl(phba->CAregaddr); /* flush */ |
| 1588 | |
| 1589 | pring->stats.iocb_cmd_full++; |
| 1590 | } |
| 1591 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1592 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1593 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1594 | * @phba: Pointer to HBA context object. |
| 1595 | * @pring: Pointer to driver SLI ring object. |
| 1596 | * |
| 1597 | * This function updates the chip attention register bit for the |
| 1598 | * given ring to inform HBA that there is more work to be done |
| 1599 | * in this ring. The caller is not required to hold any lock. |
| 1600 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | { |
| 1604 | int ringno = pring->ringno; |
| 1605 | |
| 1606 | /* |
| 1607 | * Tell the HBA that there is work to do in this ring. |
| 1608 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1609 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1610 | wmb(); |
| 1611 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1612 | readl(phba->CAregaddr); /* flush */ |
| 1613 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | } |
| 1615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1617 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1618 | * @phba: Pointer to HBA context object. |
| 1619 | * @pring: Pointer to driver SLI ring object. |
| 1620 | * |
| 1621 | * This function is called with hbalock held to post pending iocbs |
| 1622 | * in the txq to the firmware. This function is called when driver |
| 1623 | * detects space available in the ring. |
| 1624 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1626 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1627 | { |
| 1628 | IOCB_t *iocb; |
| 1629 | struct lpfc_iocbq *nextiocb; |
| 1630 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1631 | lockdep_assert_held(&phba->hbalock); |
| 1632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | /* |
| 1634 | * Check to see if: |
| 1635 | * (a) there is anything on the txq to send |
| 1636 | * (b) link is up |
| 1637 | * (c) link attention events can be processed (fcp ring only) |
| 1638 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1639 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1640 | |
| 1641 | if (lpfc_is_link_up(phba) && |
| 1642 | (!list_empty(&pring->txq)) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1644 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | |
| 1646 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1647 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1648 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1649 | |
| 1650 | if (iocb) |
| 1651 | lpfc_sli_update_ring(phba, pring); |
| 1652 | else |
| 1653 | lpfc_sli_update_full_ring(phba, pring); |
| 1654 | } |
| 1655 | |
| 1656 | return; |
| 1657 | } |
| 1658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1659 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1660 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1661 | * @phba: Pointer to HBA context object. |
| 1662 | * @hbqno: HBQ number. |
| 1663 | * |
| 1664 | * This function is called with hbalock held to get the next |
| 1665 | * available slot for the given HBQ. If there is free slot |
| 1666 | * available for the HBQ it will return pointer to the next available |
| 1667 | * HBQ entry else it will return NULL. |
| 1668 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1669 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1670 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1671 | { |
| 1672 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1673 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1674 | lockdep_assert_held(&phba->hbalock); |
| 1675 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1676 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1677 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1678 | hbqp->next_hbqPutIdx = 0; |
| 1679 | |
| 1680 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1681 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1682 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1683 | |
| 1684 | hbqp->local_hbqGetIdx = getidx; |
| 1685 | |
| 1686 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1687 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1688 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1689 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1690 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1691 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1692 | hbqp->entry_count); |
| 1693 | |
| 1694 | phba->link_state = LPFC_HBA_ERROR; |
| 1695 | return NULL; |
| 1696 | } |
| 1697 | |
| 1698 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1699 | return NULL; |
| 1700 | } |
| 1701 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1702 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1703 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1704 | } |
| 1705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1707 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1708 | * @phba: Pointer to HBA context object. |
| 1709 | * |
| 1710 | * This function is called with no lock held to free all the |
| 1711 | * hbq buffers while uninitializing the SLI interface. It also |
| 1712 | * frees the HBQ buffers returned by the firmware but not yet |
| 1713 | * processed by the upper layers. |
| 1714 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1715 | void |
| 1716 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1717 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1718 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1719 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1720 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1721 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1722 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1723 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1724 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1725 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1726 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1727 | for (i = 0; i < hbq_count; ++i) { |
| 1728 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1729 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1730 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1731 | list_del(&hbq_buf->dbuf.list); |
| 1732 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1733 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1734 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1735 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1736 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1737 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1738 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1739 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1740 | list_del(&hbq_buf->dbuf.list); |
| 1741 | if (hbq_buf->tag == -1) { |
| 1742 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1743 | (phba, hbq_buf); |
| 1744 | } else { |
| 1745 | hbqno = hbq_buf->tag >> 16; |
| 1746 | if (hbqno >= LPFC_MAX_HBQS) |
| 1747 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1748 | (phba, hbq_buf); |
| 1749 | else |
| 1750 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1751 | hbq_buf); |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | /* Mark the HBQs not in use */ |
| 1756 | phba->hbq_in_use = 0; |
| 1757 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1758 | } |
| 1759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1760 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1761 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1762 | * @phba: Pointer to HBA context object. |
| 1763 | * @hbqno: HBQ number. |
| 1764 | * @hbq_buf: Pointer to HBQ buffer. |
| 1765 | * |
| 1766 | * This function is called with the hbalock held to post a |
| 1767 | * hbq buffer to the firmware. If the function finds an empty |
| 1768 | * slot in the HBQ, it will post the buffer. The function will return |
| 1769 | * pointer to the hbq entry if it successfully post the buffer |
| 1770 | * else it will return NULL. |
| 1771 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1772 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1773 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1774 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1775 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1776 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1777 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1782 | * @phba: Pointer to HBA context object. |
| 1783 | * @hbqno: HBQ number. |
| 1784 | * @hbq_buf: Pointer to HBQ buffer. |
| 1785 | * |
| 1786 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1787 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1788 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1789 | * it successfully post the buffer else it will return an error. |
| 1790 | **/ |
| 1791 | static int |
| 1792 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1793 | struct hbq_dmabuf *hbq_buf) |
| 1794 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1795 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1796 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1797 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1798 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1799 | /* Get next HBQ entry slot to use */ |
| 1800 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1801 | if (hbqe) { |
| 1802 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1803 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1804 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1805 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1806 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1807 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1808 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1809 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1810 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1811 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1812 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1813 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1814 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1815 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1816 | return 0; |
| 1817 | } else |
| 1818 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1819 | } |
| 1820 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1821 | /** |
| 1822 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1823 | * @phba: Pointer to HBA context object. |
| 1824 | * @hbqno: HBQ number. |
| 1825 | * @hbq_buf: Pointer to HBQ buffer. |
| 1826 | * |
| 1827 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1828 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1829 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1830 | **/ |
| 1831 | static int |
| 1832 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1833 | struct hbq_dmabuf *hbq_buf) |
| 1834 | { |
| 1835 | int rc; |
| 1836 | struct lpfc_rqe hrqe; |
| 1837 | struct lpfc_rqe drqe; |
| 1838 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1839 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1840 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1841 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1842 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1843 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1844 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1845 | &hrqe, &drqe); |
| 1846 | if (rc < 0) |
| 1847 | return rc; |
| 1848 | hbq_buf->tag = rc; |
| 1849 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1853 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1854 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1855 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1856 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | .mask_count = 0, |
| 1858 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1859 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1860 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1861 | .init_count = 40, |
| 1862 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1863 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1865 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1866 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1867 | .rn = 1, |
| 1868 | .entry_count = 200, |
| 1869 | .mask_count = 0, |
| 1870 | .profile = 0, |
| 1871 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1872 | .buffer_count = 0, |
| 1873 | .init_count = 0, |
| 1874 | .add_count = 5, |
| 1875 | }; |
| 1876 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1877 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1878 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1879 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1880 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1881 | }; |
| 1882 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1884 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1885 | * @phba: Pointer to HBA context object. |
| 1886 | * @hbqno: HBQ number. |
| 1887 | * @count: Number of HBQ buffers to be posted. |
| 1888 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1889 | * This function is called with no lock held to post more hbq buffers to the |
| 1890 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1891 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1892 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1893 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1894 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1895 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1896 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1897 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1898 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1899 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1900 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1901 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1902 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1903 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1904 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1905 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1906 | phba->hbqs[hbqno].buffer_count; |
| 1907 | if (!count) |
| 1908 | return 0; |
| 1909 | /* Allocate HBQ entries */ |
| 1910 | for (i = 0; i < count; i++) { |
| 1911 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1912 | if (!hbq_buffer) |
| 1913 | break; |
| 1914 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1915 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1916 | /* Check whether HBQ is still in use */ |
| 1917 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1918 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1919 | goto err; |
| 1920 | while (!list_empty(&hbq_buf_list)) { |
| 1921 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1922 | dbuf.list); |
| 1923 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1924 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1925 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1926 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1927 | posted++; |
| 1928 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1929 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1931 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1932 | return posted; |
| 1933 | err: |
| 1934 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1935 | while (!list_empty(&hbq_buf_list)) { |
| 1936 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1937 | dbuf.list); |
| 1938 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1939 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1940 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | } |
| 1942 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1943 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1944 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1945 | * @phba: Pointer to HBA context object. |
| 1946 | * @qno: HBQ number. |
| 1947 | * |
| 1948 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1949 | * is called with no lock held. The function returns the number of HBQ entries |
| 1950 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1951 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1952 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1954 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1955 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1956 | return 0; |
| 1957 | else |
| 1958 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1959 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1960 | } |
| 1961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1962 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1963 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1964 | * @phba: Pointer to HBA context object. |
| 1965 | * @qno: HBQ queue number. |
| 1966 | * |
| 1967 | * This function is called from SLI initialization code path with |
| 1968 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1969 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1970 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1971 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1972 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1973 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1974 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1975 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1976 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1977 | else |
| 1978 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1979 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1982 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1983 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1984 | * @phba: Pointer to HBA context object. |
| 1985 | * @hbqno: HBQ number. |
| 1986 | * |
| 1987 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1988 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1989 | **/ |
| 1990 | static struct hbq_dmabuf * |
| 1991 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1992 | { |
| 1993 | struct lpfc_dmabuf *d_buf; |
| 1994 | |
| 1995 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1996 | if (!d_buf) |
| 1997 | return NULL; |
| 1998 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1999 | } |
| 2000 | |
| 2001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2002 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2003 | * @phba: Pointer to HBA context object. |
| 2004 | * @tag: Tag of the hbq buffer. |
| 2005 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2006 | * This function searches for the hbq buffer associated with the given tag in |
| 2007 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2008 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2009 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2010 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2011 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2012 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2013 | struct lpfc_dmabuf *d_buf; |
| 2014 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2015 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2016 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2017 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2018 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2019 | return NULL; |
| 2020 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2021 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2022 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2023 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2024 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2025 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2026 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2027 | } |
| 2028 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2029 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2030 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2031 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2032 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2033 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2034 | } |
| 2035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2037 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2038 | * @phba: Pointer to HBA context object. |
| 2039 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2040 | * |
| 2041 | * This function is called with hbalock. This function gives back |
| 2042 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2043 | * post the buffer, it will free the buffer. |
| 2044 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2046 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2047 | { |
| 2048 | uint32_t hbqno; |
| 2049 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2050 | if (hbq_buffer) { |
| 2051 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2052 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2053 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2057 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2058 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2059 | * @mbxCommand: mailbox command code. |
| 2060 | * |
| 2061 | * This function is called by the mailbox event handler function to verify |
| 2062 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2063 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2064 | * and the mailbox event handler will take the HBA offline. |
| 2065 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | static int |
| 2067 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2068 | { |
| 2069 | uint8_t ret; |
| 2070 | |
| 2071 | switch (mbxCommand) { |
| 2072 | case MBX_LOAD_SM: |
| 2073 | case MBX_READ_NV: |
| 2074 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2075 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | case MBX_RUN_BIU_DIAG: |
| 2077 | case MBX_INIT_LINK: |
| 2078 | case MBX_DOWN_LINK: |
| 2079 | case MBX_CONFIG_LINK: |
| 2080 | case MBX_CONFIG_RING: |
| 2081 | case MBX_RESET_RING: |
| 2082 | case MBX_READ_CONFIG: |
| 2083 | case MBX_READ_RCONFIG: |
| 2084 | case MBX_READ_SPARM: |
| 2085 | case MBX_READ_STATUS: |
| 2086 | case MBX_READ_RPI: |
| 2087 | case MBX_READ_XRI: |
| 2088 | case MBX_READ_REV: |
| 2089 | case MBX_READ_LNK_STAT: |
| 2090 | case MBX_REG_LOGIN: |
| 2091 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | case MBX_CLEAR_LA: |
| 2093 | case MBX_DUMP_MEMORY: |
| 2094 | case MBX_DUMP_CONTEXT: |
| 2095 | case MBX_RUN_DIAGS: |
| 2096 | case MBX_RESTART: |
| 2097 | case MBX_UPDATE_CFG: |
| 2098 | case MBX_DOWN_LOAD: |
| 2099 | case MBX_DEL_LD_ENTRY: |
| 2100 | case MBX_RUN_PROGRAM: |
| 2101 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2102 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2104 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2106 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | case MBX_LOAD_AREA: |
| 2108 | case MBX_RUN_BIU_DIAG64: |
| 2109 | case MBX_CONFIG_PORT: |
| 2110 | case MBX_READ_SPARM64: |
| 2111 | case MBX_READ_RPI64: |
| 2112 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2113 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2114 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | case MBX_SET_DEBUG: |
| 2116 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2117 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2118 | case MBX_REG_VPI: |
| 2119 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2120 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2121 | case MBX_PORT_CAPABILITIES: |
| 2122 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2123 | case MBX_SLI4_CONFIG: |
| 2124 | case MBX_SLI4_REQ_FTRS: |
| 2125 | case MBX_REG_FCFI: |
| 2126 | case MBX_UNREG_FCFI: |
| 2127 | case MBX_REG_VFI: |
| 2128 | case MBX_UNREG_VFI: |
| 2129 | case MBX_INIT_VPI: |
| 2130 | case MBX_INIT_VFI: |
| 2131 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2132 | case MBX_READ_EVENT_LOG_STATUS: |
| 2133 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2134 | case MBX_SECURITY_MGMT: |
| 2135 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2136 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | ret = mbxCommand; |
| 2138 | break; |
| 2139 | default: |
| 2140 | ret = MBX_SHUTDOWN; |
| 2141 | break; |
| 2142 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2143 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2145 | |
| 2146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2147 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2148 | * @phba: Pointer to HBA context object. |
| 2149 | * @pmboxq: Pointer to mailbox command. |
| 2150 | * |
| 2151 | * This is completion handler function for mailbox commands issued from |
| 2152 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2153 | * mailbox event handler function with no lock held. This function |
| 2154 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2155 | * of the mailbox. |
| 2156 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2157 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2158 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | { |
| 2160 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2161 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
| 2163 | /* |
| 2164 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2165 | * continued running. |
| 2166 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2167 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2168 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2170 | if (pdone_q) |
| 2171 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2172 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | return; |
| 2174 | } |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | |
| 2177 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2178 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2179 | * @phba: Pointer to HBA context object. |
| 2180 | * @pmb: Pointer to mailbox object. |
| 2181 | * |
| 2182 | * This function is the default mailbox completion handler. It |
| 2183 | * frees the memory resources associated with the completed mailbox |
| 2184 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2185 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2186 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2190 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2192 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2193 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2194 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2195 | int rc; |
| 2196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | if (mp) { |
| 2200 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2201 | kfree(mp); |
| 2202 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2203 | |
| 2204 | /* |
| 2205 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2206 | * is in re-discovery driver need to cleanup the RPI. |
| 2207 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2209 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2210 | !pmb->u.mb.mbxStatus) { |
| 2211 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2212 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2213 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2214 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2215 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2216 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2217 | if (rc != MBX_NOT_FINISHED) |
| 2218 | return; |
| 2219 | } |
| 2220 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2221 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2222 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2223 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2224 | shost = lpfc_shost_from_vport(vport); |
| 2225 | spin_lock_irq(shost->host_lock); |
| 2226 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2227 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2228 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2229 | } |
| 2230 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2231 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2232 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2233 | lpfc_nlp_put(ndlp); |
| 2234 | pmb->context2 = NULL; |
| 2235 | } |
| 2236 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2237 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2238 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2239 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2240 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2241 | "2860 SLI authentication is required " |
| 2242 | "for INIT_LINK but has not done yet\n"); |
| 2243 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2244 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2245 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2246 | else |
| 2247 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2249 | /** |
| 2250 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2251 | * @phba: Pointer to HBA context object. |
| 2252 | * @pmb: Pointer to mailbox object. |
| 2253 | * |
| 2254 | * This function is the unreg rpi mailbox completion handler. It |
| 2255 | * frees the memory resources associated with the completed mailbox |
| 2256 | * command. An additional refrenece is put on the ndlp to prevent |
| 2257 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2258 | * the unreg mailbox command completes, this routine puts the |
| 2259 | * reference back. |
| 2260 | * |
| 2261 | **/ |
| 2262 | void |
| 2263 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2264 | { |
| 2265 | struct lpfc_vport *vport = pmb->vport; |
| 2266 | struct lpfc_nodelist *ndlp; |
| 2267 | |
| 2268 | ndlp = pmb->context1; |
| 2269 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2270 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2271 | (bf_get(lpfc_sli_intf_if_type, |
| 2272 | &phba->sli4_hba.sli_intf) == |
| 2273 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2274 | if (ndlp) { |
| 2275 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2276 | "0010 UNREG_LOGIN vpi:%x " |
| 2277 | "rpi:%x DID:%x map:%x %p\n", |
| 2278 | vport->vpi, ndlp->nlp_rpi, |
| 2279 | ndlp->nlp_DID, |
| 2280 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2281 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2282 | lpfc_nlp_put(ndlp); |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2288 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2291 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2292 | * @phba: Pointer to HBA context object. |
| 2293 | * |
| 2294 | * This function is called with no lock held. This function processes all |
| 2295 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2296 | * service routine processes mailbox completion interrupt and adds completed |
| 2297 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2298 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2299 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2300 | * function returns the mailbox commands to the upper layer by calling the |
| 2301 | * completion handler function of each mailbox. |
| 2302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2306 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | int rc; |
| 2309 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
| 2311 | phba->sli.slistat.mbox_event++; |
| 2312 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2313 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2314 | spin_lock_irq(&phba->hbalock); |
| 2315 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2316 | spin_unlock_irq(&phba->hbalock); |
| 2317 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2319 | do { |
| 2320 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2321 | if (pmb == NULL) |
| 2322 | break; |
| 2323 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2324 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2326 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2327 | if (pmb->vport) { |
| 2328 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2329 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2330 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2331 | (uint32_t)pmbox->mbxCommand, |
| 2332 | pmbox->un.varWords[0], |
| 2333 | pmbox->un.varWords[1]); |
| 2334 | } |
| 2335 | else { |
| 2336 | lpfc_debugfs_disc_trc(phba->pport, |
| 2337 | LPFC_DISC_TRC_MBOX, |
| 2338 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2339 | (uint32_t)pmbox->mbxCommand, |
| 2340 | pmbox->un.varWords[0], |
| 2341 | pmbox->un.varWords[1]); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | /* |
| 2346 | * It is a fatal error if unknown mbox command completion. |
| 2347 | */ |
| 2348 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2349 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2350 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2351 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2352 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2353 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2354 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2355 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2356 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2357 | pmb), |
| 2358 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2359 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | phba->work_hs = HS_FFER3; |
| 2362 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2363 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | } |
| 2365 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | if (pmbox->mbxStatus) { |
| 2367 | phba->sli.slistat.mbox_stat_err++; |
| 2368 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2369 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2370 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2371 | LOG_MBOX | LOG_SLI, |
| 2372 | "(%d):0305 Mbox cmd cmpl " |
| 2373 | "error - RETRYing Data: x%x " |
| 2374 | "(x%x/x%x) x%x x%x x%x\n", |
| 2375 | pmb->vport ? pmb->vport->vpi : 0, |
| 2376 | pmbox->mbxCommand, |
| 2377 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2378 | pmb), |
| 2379 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2380 | pmb), |
| 2381 | pmbox->mbxStatus, |
| 2382 | pmbox->un.varWords[0], |
| 2383 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | pmbox->mbxStatus = 0; |
| 2385 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2387 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2388 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2394 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2395 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2396 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2397 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2399 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2400 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | pmb->mbox_cmpl, |
| 2402 | *((uint32_t *) pmbox), |
| 2403 | pmbox->un.varWords[0], |
| 2404 | pmbox->un.varWords[1], |
| 2405 | pmbox->un.varWords[2], |
| 2406 | pmbox->un.varWords[3], |
| 2407 | pmbox->un.varWords[4], |
| 2408 | pmbox->un.varWords[5], |
| 2409 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2410 | pmbox->un.varWords[7], |
| 2411 | pmbox->un.varWords[8], |
| 2412 | pmbox->un.varWords[9], |
| 2413 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2415 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2417 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2418 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2422 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2423 | * @phba: Pointer to HBA context object. |
| 2424 | * @pring: Pointer to driver SLI ring object. |
| 2425 | * @tag: buffer tag. |
| 2426 | * |
| 2427 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2428 | * is set in the tag the buffer is posted for a particular exchange, |
| 2429 | * the function will return the buffer without replacing the buffer. |
| 2430 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2431 | * returns the buffer and also posts another buffer to the firmware. |
| 2432 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2433 | static struct lpfc_dmabuf * |
| 2434 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2435 | struct lpfc_sli_ring *pring, |
| 2436 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2437 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2438 | struct hbq_dmabuf *hbq_entry; |
| 2439 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2440 | if (tag & QUE_BUFTAG_BIT) |
| 2441 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2442 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2443 | if (!hbq_entry) |
| 2444 | return NULL; |
| 2445 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2446 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2447 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2448 | /** |
| 2449 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2450 | * @phba: Pointer to HBA context object. |
| 2451 | * @pring: Pointer to driver SLI ring object. |
| 2452 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2453 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2454 | * @fch_type: the type for the first frame of the sequence. |
| 2455 | * |
| 2456 | * This function is called with no lock held. This function uses the r_ctl and |
| 2457 | * type of the received sequence to find the correct callback function to call |
| 2458 | * to process the sequence. |
| 2459 | **/ |
| 2460 | static int |
| 2461 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2462 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2463 | uint32_t fch_type) |
| 2464 | { |
| 2465 | int i; |
| 2466 | |
| 2467 | /* unSolicited Responses */ |
| 2468 | if (pring->prt[0].profile) { |
| 2469 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2470 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2471 | saveq); |
| 2472 | return 1; |
| 2473 | } |
| 2474 | /* We must search, based on rctl / type |
| 2475 | for the right routine */ |
| 2476 | for (i = 0; i < pring->num_mask; i++) { |
| 2477 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2478 | (pring->prt[i].type == fch_type)) { |
| 2479 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2480 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2481 | (phba, pring, saveq); |
| 2482 | return 1; |
| 2483 | } |
| 2484 | } |
| 2485 | return 0; |
| 2486 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2487 | |
| 2488 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2489 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2490 | * @phba: Pointer to HBA context object. |
| 2491 | * @pring: Pointer to driver SLI ring object. |
| 2492 | * @saveq: Pointer to the unsolicited iocb. |
| 2493 | * |
| 2494 | * This function is called with no lock held by the ring event handler |
| 2495 | * when there is an unsolicited iocb posted to the response ring by the |
| 2496 | * firmware. This function gets the buffer associated with the iocbs |
| 2497 | * and calls the event handler for the ring. This function handles both |
| 2498 | * qring buffers and hbq buffers. |
| 2499 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2500 | * upper layer functions will free the iocb objects. |
| 2501 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | static int |
| 2503 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2504 | struct lpfc_iocbq *saveq) |
| 2505 | { |
| 2506 | IOCB_t * irsp; |
| 2507 | WORD5 * w5p; |
| 2508 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2509 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2510 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2513 | |
| 2514 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2515 | if (pring->lpfc_sli_rcv_async_status) |
| 2516 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2517 | else |
| 2518 | lpfc_printf_log(phba, |
| 2519 | KERN_WARNING, |
| 2520 | LOG_SLI, |
| 2521 | "0316 Ring %d handler: unexpected " |
| 2522 | "ASYNC_STATUS iocb received evt_code " |
| 2523 | "0x%x\n", |
| 2524 | pring->ringno, |
| 2525 | irsp->un.asyncstat.evt_code); |
| 2526 | return 1; |
| 2527 | } |
| 2528 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2529 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2530 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2531 | if (irsp->ulpBdeCount > 0) { |
| 2532 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2533 | irsp->un.ulpWord[3]); |
| 2534 | lpfc_in_buf_free(phba, dmzbuf); |
| 2535 | } |
| 2536 | |
| 2537 | if (irsp->ulpBdeCount > 1) { |
| 2538 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2539 | irsp->unsli3.sli3Words[3]); |
| 2540 | lpfc_in_buf_free(phba, dmzbuf); |
| 2541 | } |
| 2542 | |
| 2543 | if (irsp->ulpBdeCount > 2) { |
| 2544 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2545 | irsp->unsli3.sli3Words[7]); |
| 2546 | lpfc_in_buf_free(phba, dmzbuf); |
| 2547 | } |
| 2548 | |
| 2549 | return 1; |
| 2550 | } |
| 2551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2552 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2553 | if (irsp->ulpBdeCount != 0) { |
| 2554 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2556 | if (!saveq->context2) |
| 2557 | lpfc_printf_log(phba, |
| 2558 | KERN_ERR, |
| 2559 | LOG_SLI, |
| 2560 | "0341 Ring %d Cannot find buffer for " |
| 2561 | "an unsolicited iocb. tag 0x%x\n", |
| 2562 | pring->ringno, |
| 2563 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2564 | } |
| 2565 | if (irsp->ulpBdeCount == 2) { |
| 2566 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2567 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2568 | if (!saveq->context3) |
| 2569 | lpfc_printf_log(phba, |
| 2570 | KERN_ERR, |
| 2571 | LOG_SLI, |
| 2572 | "0342 Ring %d Cannot find buffer for an" |
| 2573 | " unsolicited iocb. tag 0x%x\n", |
| 2574 | pring->ringno, |
| 2575 | irsp->unsli3.sli3Words[7]); |
| 2576 | } |
| 2577 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2578 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2579 | if (irsp->ulpBdeCount != 0) { |
| 2580 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2581 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2582 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2583 | lpfc_printf_log(phba, |
| 2584 | KERN_ERR, |
| 2585 | LOG_SLI, |
| 2586 | "0343 Ring %d Cannot find " |
| 2587 | "buffer for an unsolicited iocb" |
| 2588 | ". tag 0x%x\n", pring->ringno, |
| 2589 | irsp->un.ulpWord[3]); |
| 2590 | } |
| 2591 | if (irsp->ulpBdeCount == 2) { |
| 2592 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2593 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2594 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2595 | lpfc_printf_log(phba, |
| 2596 | KERN_ERR, |
| 2597 | LOG_SLI, |
| 2598 | "0344 Ring %d Cannot find " |
| 2599 | "buffer for an unsolicited " |
| 2600 | "iocb. tag 0x%x\n", |
| 2601 | pring->ringno, |
| 2602 | irsp->unsli3.sli3Words[7]); |
| 2603 | } |
| 2604 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2605 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2606 | if (irsp->ulpBdeCount != 0 && |
| 2607 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2608 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2609 | int found = 0; |
| 2610 | |
| 2611 | /* search continue save q for same XRI */ |
| 2612 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2613 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2614 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2615 | list_add_tail(&saveq->list, &iocbq->list); |
| 2616 | found = 1; |
| 2617 | break; |
| 2618 | } |
| 2619 | } |
| 2620 | if (!found) |
| 2621 | list_add_tail(&saveq->clist, |
| 2622 | &pring->iocb_continue_saveq); |
| 2623 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2624 | list_del_init(&iocbq->clist); |
| 2625 | saveq = iocbq; |
| 2626 | irsp = &(saveq->iocb); |
| 2627 | } else |
| 2628 | return 0; |
| 2629 | } |
| 2630 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2631 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2632 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2633 | Rctl = FC_RCTL_ELS_REQ; |
| 2634 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2635 | } else { |
| 2636 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2637 | Rctl = w5p->hcsw.Rctl; |
| 2638 | Type = w5p->hcsw.Type; |
| 2639 | |
| 2640 | /* Firmware Workaround */ |
| 2641 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2642 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2643 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2644 | Rctl = FC_RCTL_ELS_REQ; |
| 2645 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2646 | w5p->hcsw.Rctl = Rctl; |
| 2647 | w5p->hcsw.Type = Type; |
| 2648 | } |
| 2649 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2650 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2651 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2652 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2653 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2654 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2655 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2656 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | } |
| 2659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2661 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2662 | * @phba: Pointer to HBA context object. |
| 2663 | * @pring: Pointer to driver SLI ring object. |
| 2664 | * @prspiocb: Pointer to response iocb object. |
| 2665 | * |
| 2666 | * This function looks up the iocb_lookup table to get the command iocb |
| 2667 | * corresponding to the given response iocb using the iotag of the |
| 2668 | * response iocb. This function is called with the hbalock held. |
| 2669 | * This function returns the command iocb object if it finds the command |
| 2670 | * iocb else returns NULL. |
| 2671 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2674 | struct lpfc_sli_ring *pring, |
| 2675 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2678 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2679 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2681 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2683 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2684 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2686 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2687 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2688 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2689 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2690 | } |
| 2691 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2692 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2693 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2694 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2695 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2696 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | return NULL; |
| 2698 | } |
| 2699 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2700 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2701 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2702 | * @phba: Pointer to HBA context object. |
| 2703 | * @pring: Pointer to driver SLI ring object. |
| 2704 | * @iotag: IOCB tag. |
| 2705 | * |
| 2706 | * This function looks up the iocb_lookup table to get the command iocb |
| 2707 | * corresponding to the given iotag. This function is called with the |
| 2708 | * hbalock held. |
| 2709 | * This function returns the command iocb object if it finds the command |
| 2710 | * iocb else returns NULL. |
| 2711 | **/ |
| 2712 | static struct lpfc_iocbq * |
| 2713 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2714 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2715 | { |
| 2716 | struct lpfc_iocbq *cmd_iocb; |
| 2717 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2718 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2719 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2720 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2721 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2722 | /* remove from txcmpl queue list */ |
| 2723 | list_del_init(&cmd_iocb->list); |
| 2724 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2725 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2726 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2727 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2728 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2729 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2730 | iotag, phba->sli.last_iotag); |
| 2731 | return NULL; |
| 2732 | } |
| 2733 | |
| 2734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2735 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2736 | * @phba: Pointer to HBA context object. |
| 2737 | * @pring: Pointer to driver SLI ring object. |
| 2738 | * @saveq: Pointer to the response iocb to be processed. |
| 2739 | * |
| 2740 | * This function is called by the ring event handler for non-fcp |
| 2741 | * rings when there is a new response iocb in the response ring. |
| 2742 | * The caller is not required to hold any locks. This function |
| 2743 | * gets the command iocb associated with the response iocb and |
| 2744 | * calls the completion handler for the command iocb. If there |
| 2745 | * is no completion handler, the function will free the resources |
| 2746 | * associated with command iocb. If the response iocb is for |
| 2747 | * an already aborted command iocb, the status of the completion |
| 2748 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2749 | * This function always returns 1. |
| 2750 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2752 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | struct lpfc_iocbq *saveq) |
| 2754 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2756 | int rc = 1; |
| 2757 | unsigned long iflag; |
| 2758 | |
| 2759 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2760 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2761 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2763 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | if (cmdiocbp) { |
| 2765 | if (cmdiocbp->iocb_cmpl) { |
| 2766 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2767 | * If an ELS command failed send an event to mgmt |
| 2768 | * application. |
| 2769 | */ |
| 2770 | if (saveq->iocb.ulpStatus && |
| 2771 | (pring->ringno == LPFC_ELS_RING) && |
| 2772 | (cmdiocbp->iocb.ulpCommand == |
| 2773 | CMD_ELS_REQUEST64_CR)) |
| 2774 | lpfc_send_els_failure_event(phba, |
| 2775 | cmdiocbp, saveq); |
| 2776 | |
| 2777 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | * Post all ELS completions to the worker thread. |
| 2779 | * All other are passed to the completion callback. |
| 2780 | */ |
| 2781 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2782 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2783 | (cmdiocbp->iocb_flag & |
| 2784 | LPFC_DRIVER_ABORTED)) { |
| 2785 | spin_lock_irqsave(&phba->hbalock, |
| 2786 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2787 | cmdiocbp->iocb_flag &= |
| 2788 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2789 | spin_unlock_irqrestore(&phba->hbalock, |
| 2790 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2791 | saveq->iocb.ulpStatus = |
| 2792 | IOSTAT_LOCAL_REJECT; |
| 2793 | saveq->iocb.un.ulpWord[4] = |
| 2794 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2795 | |
| 2796 | /* Firmware could still be in progress |
| 2797 | * of DMAing payload, so don't free data |
| 2798 | * buffer till after a hbeat. |
| 2799 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2800 | spin_lock_irqsave(&phba->hbalock, |
| 2801 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2802 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2803 | spin_unlock_irqrestore(&phba->hbalock, |
| 2804 | iflag); |
| 2805 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2806 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2807 | if (saveq->iocb_flag & |
| 2808 | LPFC_EXCHANGE_BUSY) { |
| 2809 | /* Set cmdiocb flag for the |
| 2810 | * exchange busy so sgl (xri) |
| 2811 | * will not be released until |
| 2812 | * the abort xri is received |
| 2813 | * from hba. |
| 2814 | */ |
| 2815 | spin_lock_irqsave( |
| 2816 | &phba->hbalock, iflag); |
| 2817 | cmdiocbp->iocb_flag |= |
| 2818 | LPFC_EXCHANGE_BUSY; |
| 2819 | spin_unlock_irqrestore( |
| 2820 | &phba->hbalock, iflag); |
| 2821 | } |
| 2822 | if (cmdiocbp->iocb_flag & |
| 2823 | LPFC_DRIVER_ABORTED) { |
| 2824 | /* |
| 2825 | * Clear LPFC_DRIVER_ABORTED |
| 2826 | * bit in case it was driver |
| 2827 | * initiated abort. |
| 2828 | */ |
| 2829 | spin_lock_irqsave( |
| 2830 | &phba->hbalock, iflag); |
| 2831 | cmdiocbp->iocb_flag &= |
| 2832 | ~LPFC_DRIVER_ABORTED; |
| 2833 | spin_unlock_irqrestore( |
| 2834 | &phba->hbalock, iflag); |
| 2835 | cmdiocbp->iocb.ulpStatus = |
| 2836 | IOSTAT_LOCAL_REJECT; |
| 2837 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2838 | IOERR_ABORT_REQUESTED; |
| 2839 | /* |
| 2840 | * For SLI4, irsiocb contains |
| 2841 | * NO_XRI in sli_xritag, it |
| 2842 | * shall not affect releasing |
| 2843 | * sgl (xri) process. |
| 2844 | */ |
| 2845 | saveq->iocb.ulpStatus = |
| 2846 | IOSTAT_LOCAL_REJECT; |
| 2847 | saveq->iocb.un.ulpWord[4] = |
| 2848 | IOERR_SLI_ABORTED; |
| 2849 | spin_lock_irqsave( |
| 2850 | &phba->hbalock, iflag); |
| 2851 | saveq->iocb_flag |= |
| 2852 | LPFC_DELAY_MEM_FREE; |
| 2853 | spin_unlock_irqrestore( |
| 2854 | &phba->hbalock, iflag); |
| 2855 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2856 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2859 | } else |
| 2860 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | } else { |
| 2862 | /* |
| 2863 | * Unknown initiating command based on the response iotag. |
| 2864 | * This could be the case on the ELS ring because of |
| 2865 | * lpfc_els_abort(). |
| 2866 | */ |
| 2867 | if (pring->ringno != LPFC_ELS_RING) { |
| 2868 | /* |
| 2869 | * Ring <ringno> handler: unexpected completion IoTag |
| 2870 | * <IoTag> |
| 2871 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2872 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2873 | "0322 Ring %d handler: " |
| 2874 | "unexpected completion IoTag x%x " |
| 2875 | "Data: x%x x%x x%x x%x\n", |
| 2876 | pring->ringno, |
| 2877 | saveq->iocb.ulpIoTag, |
| 2878 | saveq->iocb.ulpStatus, |
| 2879 | saveq->iocb.un.ulpWord[4], |
| 2880 | saveq->iocb.ulpCommand, |
| 2881 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | } |
| 2883 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2884 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | return rc; |
| 2886 | } |
| 2887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2889 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2890 | * @phba: Pointer to HBA context object. |
| 2891 | * @pring: Pointer to driver SLI ring object. |
| 2892 | * |
| 2893 | * This function is called from the iocb ring event handlers when |
| 2894 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2895 | * an error attention condition to the worker thread and the worker |
| 2896 | * thread will transition the HBA to offline state. |
| 2897 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2898 | static void |
| 2899 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2900 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2901 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2902 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2903 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2904 | * rsp ring <portRspMax> |
| 2905 | */ |
| 2906 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2907 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2908 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2909 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2910 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2912 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2913 | |
| 2914 | /* |
| 2915 | * All error attention handlers are posted to |
| 2916 | * worker thread |
| 2917 | */ |
| 2918 | phba->work_ha |= HA_ERATT; |
| 2919 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2920 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2921 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2922 | |
| 2923 | return; |
| 2924 | } |
| 2925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2926 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2927 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2928 | * @ptr: Pointer to address of HBA context object. |
| 2929 | * |
| 2930 | * This function is invoked by the Error Attention polling timer when the |
| 2931 | * timer times out. It will check the SLI Error Attention register for |
| 2932 | * possible attention events. If so, it will post an Error Attention event |
| 2933 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2934 | * Error Attention polling timer for the next poll. |
| 2935 | **/ |
| 2936 | void lpfc_poll_eratt(unsigned long ptr) |
| 2937 | { |
| 2938 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 2939 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2940 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2941 | |
| 2942 | phba = (struct lpfc_hba *)ptr; |
| 2943 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2944 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2945 | sli_intr = phba->sli.slistat.sli_intr; |
| 2946 | |
| 2947 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2948 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2949 | sli_intr); |
| 2950 | else |
| 2951 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2952 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2953 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 2954 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2955 | phba->sli.slistat.sli_ips = cnt; |
| 2956 | |
| 2957 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2958 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2959 | /* Check chip HA register for error event */ |
| 2960 | eratt = lpfc_sli_check_eratt(phba); |
| 2961 | |
| 2962 | if (eratt) |
| 2963 | /* Tell the worker thread there is work to do */ |
| 2964 | lpfc_worker_wake_up(phba); |
| 2965 | else |
| 2966 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 2967 | mod_timer(&phba->eratt_poll, |
| 2968 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2969 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2970 | return; |
| 2971 | } |
| 2972 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2974 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2975 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2976 | * @phba: Pointer to HBA context object. |
| 2977 | * @pring: Pointer to driver SLI ring object. |
| 2978 | * @mask: Host attention register mask for this ring. |
| 2979 | * |
| 2980 | * This function is called from the interrupt context when there is a ring |
| 2981 | * event for the fcp ring. The caller does not hold any lock. |
| 2982 | * The function processes each response iocb in the response ring until it |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2983 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2984 | * LE bit set. The function will call the completion handler of the command iocb |
| 2985 | * if the response iocb indicates a completion for a command iocb or it is |
| 2986 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2987 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2989 | * to check it explicitly. |
| 2990 | */ |
| 2991 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2992 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2993 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2994 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2995 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2996 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2997 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2999 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | uint32_t status; |
| 3001 | uint32_t portRspPut, portRspMax; |
| 3002 | int rc = 1; |
| 3003 | lpfc_iocb_type type; |
| 3004 | unsigned long iflag; |
| 3005 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3006 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3007 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | pring->stats.iocb_event++; |
| 3009 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | /* |
| 3011 | * The next available response entry should never exceed the maximum |
| 3012 | * entries. If it does, treat it as an adapter hardware error. |
| 3013 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3014 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3016 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3017 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3018 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | return 1; |
| 3020 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3021 | if (phba->fcp_ring_in_use) { |
| 3022 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3023 | return 1; |
| 3024 | } else |
| 3025 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | |
| 3027 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3028 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3029 | /* |
| 3030 | * Fetch an entry off the ring and copy it into a local data |
| 3031 | * structure. The copy involves a byte-swap since the |
| 3032 | * network byte order and pci byte orders are different. |
| 3033 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3034 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3035 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3036 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3037 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3038 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3039 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3040 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3041 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3042 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3043 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3044 | irsp = &rspiocbq.iocb; |
| 3045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3047 | pring->stats.iocb_rsp++; |
| 3048 | rsp_cmpl++; |
| 3049 | |
| 3050 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | /* |
| 3052 | * If resource errors reported from HBA, reduce |
| 3053 | * queuedepths of the SCSI device. |
| 3054 | */ |
| 3055 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3056 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3057 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3058 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3059 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3060 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3061 | } |
| 3062 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | /* Rsp ring <ringno> error: IOCB */ |
| 3064 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3065 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3066 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3067 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | irsp->un.ulpWord[0], |
| 3069 | irsp->un.ulpWord[1], |
| 3070 | irsp->un.ulpWord[2], |
| 3071 | irsp->un.ulpWord[3], |
| 3072 | irsp->un.ulpWord[4], |
| 3073 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3074 | *(uint32_t *)&irsp->un1, |
| 3075 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | switch (type) { |
| 3079 | case LPFC_ABORT_IOCB: |
| 3080 | case LPFC_SOL_IOCB: |
| 3081 | /* |
| 3082 | * Idle exchange closed via ABTS from port. No iocb |
| 3083 | * resources need to be recovered. |
| 3084 | */ |
| 3085 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3086 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3087 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3088 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3089 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3090 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3094 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3095 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3096 | if (unlikely(!cmdiocbq)) |
| 3097 | break; |
| 3098 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3099 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3100 | if (cmdiocbq->iocb_cmpl) { |
| 3101 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3102 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3103 | &rspiocbq); |
| 3104 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3105 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3107 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3109 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3110 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3111 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | default: |
| 3113 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3114 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3115 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3116 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3117 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3118 | dev_warn(&((phba->pcidev)->dev), |
| 3119 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3120 | phba->brd_no, adaptermsg); |
| 3121 | } else { |
| 3122 | /* Unknown IOCB command */ |
| 3123 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3124 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3125 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3126 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3127 | irsp->ulpStatus, |
| 3128 | irsp->ulpIoTag, |
| 3129 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | } |
| 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | /* |
| 3135 | * The response IOCB has been processed. Update the ring |
| 3136 | * pointer in SLIM. If the port response put pointer has not |
| 3137 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3138 | * response put pointer. |
| 3139 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3140 | writel(pring->sli.sli3.rspidx, |
| 3141 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3143 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3145 | } |
| 3146 | |
| 3147 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3148 | pring->stats.iocb_rsp_full++; |
| 3149 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3150 | writel(status, phba->CAregaddr); |
| 3151 | readl(phba->CAregaddr); |
| 3152 | } |
| 3153 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3154 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3155 | pring->stats.iocb_cmd_empty++; |
| 3156 | |
| 3157 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3158 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | lpfc_sli_resume_iocb(phba, pring); |
| 3160 | |
| 3161 | if ((pring->lpfc_sli_cmd_available)) |
| 3162 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3163 | |
| 3164 | } |
| 3165 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3166 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3167 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | return rc; |
| 3169 | } |
| 3170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3172 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3173 | * @phba: Pointer to HBA context object. |
| 3174 | * @pring: Pointer to driver SLI ring object. |
| 3175 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3176 | * |
| 3177 | * This function is called from the worker thread when there is a slow-path |
| 3178 | * response IOCB to process. This function chains all the response iocbs until |
| 3179 | * seeing the iocb with the LE bit set. The function will call |
| 3180 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3181 | * completion of a command iocb. The function will call the |
| 3182 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3183 | * The function frees the resources or calls the completion handler if this |
| 3184 | * iocb is an abort completion. The function returns NULL when the response |
| 3185 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3186 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3187 | * response iocb passed in. |
| 3188 | **/ |
| 3189 | static struct lpfc_iocbq * |
| 3190 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3191 | struct lpfc_iocbq *rspiocbp) |
| 3192 | { |
| 3193 | struct lpfc_iocbq *saveq; |
| 3194 | struct lpfc_iocbq *cmdiocbp; |
| 3195 | struct lpfc_iocbq *next_iocb; |
| 3196 | IOCB_t *irsp = NULL; |
| 3197 | uint32_t free_saveq; |
| 3198 | uint8_t iocb_cmd_type; |
| 3199 | lpfc_iocb_type type; |
| 3200 | unsigned long iflag; |
| 3201 | int rc; |
| 3202 | |
| 3203 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3204 | /* First add the response iocb to the countinueq list */ |
| 3205 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3206 | pring->iocb_continueq_cnt++; |
| 3207 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3208 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3209 | irsp = &rspiocbp->iocb; |
| 3210 | if (irsp->ulpLe) { |
| 3211 | /* |
| 3212 | * By default, the driver expects to free all resources |
| 3213 | * associated with this iocb completion. |
| 3214 | */ |
| 3215 | free_saveq = 1; |
| 3216 | saveq = list_get_first(&pring->iocb_continueq, |
| 3217 | struct lpfc_iocbq, list); |
| 3218 | irsp = &(saveq->iocb); |
| 3219 | list_del_init(&pring->iocb_continueq); |
| 3220 | pring->iocb_continueq_cnt = 0; |
| 3221 | |
| 3222 | pring->stats.iocb_rsp++; |
| 3223 | |
| 3224 | /* |
| 3225 | * If resource errors reported from HBA, reduce |
| 3226 | * queuedepths of the SCSI device. |
| 3227 | */ |
| 3228 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3229 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3230 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3231 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3232 | phba->lpfc_rampdown_queue_depth(phba); |
| 3233 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3234 | } |
| 3235 | |
| 3236 | if (irsp->ulpStatus) { |
| 3237 | /* Rsp ring <ringno> error: IOCB */ |
| 3238 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3239 | "0328 Rsp Ring %d error: " |
| 3240 | "IOCB Data: " |
| 3241 | "x%x x%x x%x x%x " |
| 3242 | "x%x x%x x%x x%x " |
| 3243 | "x%x x%x x%x x%x " |
| 3244 | "x%x x%x x%x x%x\n", |
| 3245 | pring->ringno, |
| 3246 | irsp->un.ulpWord[0], |
| 3247 | irsp->un.ulpWord[1], |
| 3248 | irsp->un.ulpWord[2], |
| 3249 | irsp->un.ulpWord[3], |
| 3250 | irsp->un.ulpWord[4], |
| 3251 | irsp->un.ulpWord[5], |
| 3252 | *(((uint32_t *) irsp) + 6), |
| 3253 | *(((uint32_t *) irsp) + 7), |
| 3254 | *(((uint32_t *) irsp) + 8), |
| 3255 | *(((uint32_t *) irsp) + 9), |
| 3256 | *(((uint32_t *) irsp) + 10), |
| 3257 | *(((uint32_t *) irsp) + 11), |
| 3258 | *(((uint32_t *) irsp) + 12), |
| 3259 | *(((uint32_t *) irsp) + 13), |
| 3260 | *(((uint32_t *) irsp) + 14), |
| 3261 | *(((uint32_t *) irsp) + 15)); |
| 3262 | } |
| 3263 | |
| 3264 | /* |
| 3265 | * Fetch the IOCB command type and call the correct completion |
| 3266 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3267 | * get freed back to the lpfc_iocb_list by the discovery |
| 3268 | * kernel thread. |
| 3269 | */ |
| 3270 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3271 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3272 | switch (type) { |
| 3273 | case LPFC_SOL_IOCB: |
| 3274 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3275 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3276 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3277 | break; |
| 3278 | |
| 3279 | case LPFC_UNSOL_IOCB: |
| 3280 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3281 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3282 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3283 | if (!rc) |
| 3284 | free_saveq = 0; |
| 3285 | break; |
| 3286 | |
| 3287 | case LPFC_ABORT_IOCB: |
| 3288 | cmdiocbp = NULL; |
| 3289 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3290 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3291 | saveq); |
| 3292 | if (cmdiocbp) { |
| 3293 | /* Call the specified completion routine */ |
| 3294 | if (cmdiocbp->iocb_cmpl) { |
| 3295 | spin_unlock_irqrestore(&phba->hbalock, |
| 3296 | iflag); |
| 3297 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3298 | saveq); |
| 3299 | spin_lock_irqsave(&phba->hbalock, |
| 3300 | iflag); |
| 3301 | } else |
| 3302 | __lpfc_sli_release_iocbq(phba, |
| 3303 | cmdiocbp); |
| 3304 | } |
| 3305 | break; |
| 3306 | |
| 3307 | case LPFC_UNKNOWN_IOCB: |
| 3308 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3309 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3310 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3311 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3312 | MAX_MSG_DATA); |
| 3313 | dev_warn(&((phba->pcidev)->dev), |
| 3314 | "lpfc%d: %s\n", |
| 3315 | phba->brd_no, adaptermsg); |
| 3316 | } else { |
| 3317 | /* Unknown IOCB command */ |
| 3318 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3319 | "0335 Unknown IOCB " |
| 3320 | "command Data: x%x " |
| 3321 | "x%x x%x x%x\n", |
| 3322 | irsp->ulpCommand, |
| 3323 | irsp->ulpStatus, |
| 3324 | irsp->ulpIoTag, |
| 3325 | irsp->ulpContext); |
| 3326 | } |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | if (free_saveq) { |
| 3331 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3332 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3333 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3334 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3335 | } |
| 3336 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3337 | } |
| 3338 | rspiocbp = NULL; |
| 3339 | } |
| 3340 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3341 | return rspiocbp; |
| 3342 | } |
| 3343 | |
| 3344 | /** |
| 3345 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3346 | * @phba: Pointer to HBA context object. |
| 3347 | * @pring: Pointer to driver SLI ring object. |
| 3348 | * @mask: Host attention register mask for this ring. |
| 3349 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3350 | * This routine wraps the actual slow_ring event process routine from the |
| 3351 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3352 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3353 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3354 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3355 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3357 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3362 | * @phba: Pointer to HBA context object. |
| 3363 | * @pring: Pointer to driver SLI ring object. |
| 3364 | * @mask: Host attention register mask for this ring. |
| 3365 | * |
| 3366 | * This function is called from the worker thread when there is a ring event |
| 3367 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3368 | * remove each response iocb in the response ring and calls the handle |
| 3369 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3370 | **/ |
| 3371 | static void |
| 3372 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3373 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3374 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3375 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | IOCB_t *entry; |
| 3377 | IOCB_t *irsp = NULL; |
| 3378 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3381 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3383 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3384 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | pring->stats.iocb_event++; |
| 3386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | /* |
| 3388 | * The next available response entry should never exceed the maximum |
| 3389 | * entries. If it does, treat it as an adapter hardware error. |
| 3390 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3391 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3393 | if (portRspPut >= portRspMax) { |
| 3394 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3395 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | * rsp ring <portRspMax> |
| 3397 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3399 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3400 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3401 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3402 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | phba->link_state = LPFC_HBA_ERROR; |
| 3404 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | |
| 3406 | phba->work_hs = HS_FFER3; |
| 3407 | lpfc_handle_eratt(phba); |
| 3408 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3409 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3413 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | /* |
| 3415 | * Build a completion list and call the appropriate handler. |
| 3416 | * The process is to get the next available response iocb, get |
| 3417 | * a free iocb from the list, copy the response data into the |
| 3418 | * free iocb, insert to the continuation list, and update the |
| 3419 | * next response index to slim. This process makes response |
| 3420 | * iocb's in the ring available to DMA as fast as possible but |
| 3421 | * pays a penalty for a copy operation. Since the iocb is |
| 3422 | * only 32 bytes, this penalty is considered small relative to |
| 3423 | * the PCI reads for register values and a slim write. When |
| 3424 | * the ulpLe field is set, the entire Command has been |
| 3425 | * received. |
| 3426 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3427 | entry = lpfc_resp_iocb(phba, pring); |
| 3428 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3429 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3430 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | if (rspiocbp == NULL) { |
| 3432 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3433 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | break; |
| 3435 | } |
| 3436 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3437 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3438 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | irsp = &rspiocbp->iocb; |
| 3440 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3441 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3442 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3444 | if (pring->ringno == LPFC_ELS_RING) { |
| 3445 | lpfc_debugfs_slow_ring_trc(phba, |
| 3446 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3447 | *(((uint32_t *) irsp) + 4), |
| 3448 | *(((uint32_t *) irsp) + 6), |
| 3449 | *(((uint32_t *) irsp) + 7)); |
| 3450 | } |
| 3451 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3452 | writel(pring->sli.sli3.rspidx, |
| 3453 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3455 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3456 | /* Handle the response IOCB */ |
| 3457 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3458 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3459 | |
| 3460 | /* |
| 3461 | * If the port response put pointer has not been updated, sync |
| 3462 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3463 | * response put pointer. |
| 3464 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3465 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3467 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3468 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3470 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | /* At least one response entry has been freed */ |
| 3472 | pring->stats.iocb_rsp_full++; |
| 3473 | /* SET RxRE_RSP in Chip Att register */ |
| 3474 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3475 | writel(status, phba->CAregaddr); |
| 3476 | readl(phba->CAregaddr); /* flush */ |
| 3477 | } |
| 3478 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3479 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3480 | pring->stats.iocb_cmd_empty++; |
| 3481 | |
| 3482 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3483 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | lpfc_sli_resume_iocb(phba, pring); |
| 3485 | |
| 3486 | if ((pring->lpfc_sli_cmd_available)) |
| 3487 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3488 | |
| 3489 | } |
| 3490 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3491 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3492 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | } |
| 3494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3495 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3496 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3497 | * @phba: Pointer to HBA context object. |
| 3498 | * @pring: Pointer to driver SLI ring object. |
| 3499 | * @mask: Host attention register mask for this ring. |
| 3500 | * |
| 3501 | * This function is called from the worker thread when there is a pending |
| 3502 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3503 | * queue. The caller does not hold any lock. The function will remove each |
| 3504 | * response iocb from the response worker queue and calls the handle |
| 3505 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3506 | **/ |
| 3507 | static void |
| 3508 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3509 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3510 | { |
| 3511 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3512 | struct hbq_dmabuf *dmabuf; |
| 3513 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3514 | unsigned long iflag; |
| 3515 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3516 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3517 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3518 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3519 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3520 | /* Get the response iocb from the head of work queue */ |
| 3521 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3522 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3523 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3524 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3525 | |
| 3526 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3527 | case CQE_CODE_COMPL_WQE: |
| 3528 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3529 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3530 | /* Translate ELS WCQE to response IOCBQ */ |
| 3531 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3532 | irspiocbq); |
| 3533 | if (irspiocbq) |
| 3534 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3535 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3536 | break; |
| 3537 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3538 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3539 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3540 | cq_event); |
| 3541 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3542 | break; |
| 3543 | default: |
| 3544 | break; |
| 3545 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3550 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3551 | * @phba: Pointer to HBA context object. |
| 3552 | * @pring: Pointer to driver SLI ring object. |
| 3553 | * |
| 3554 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3555 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3556 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3557 | * the return of this function. The caller is not required to hold any locks. |
| 3558 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3559 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3561 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3562 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3565 | if (pring->ringno == LPFC_ELS_RING) { |
| 3566 | lpfc_fabric_abort_hba(phba); |
| 3567 | } |
| 3568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | /* Error everything on txq and txcmplq |
| 3570 | * First do the txq. |
| 3571 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3572 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3573 | spin_lock_irq(&pring->ring_lock); |
| 3574 | list_splice_init(&pring->txq, &completions); |
| 3575 | pring->txq_cnt = 0; |
| 3576 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3578 | spin_lock_irq(&phba->hbalock); |
| 3579 | /* Next issue ABTS for everything on the txcmplq */ |
| 3580 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3581 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3582 | spin_unlock_irq(&phba->hbalock); |
| 3583 | } else { |
| 3584 | spin_lock_irq(&phba->hbalock); |
| 3585 | list_splice_init(&pring->txq, &completions); |
| 3586 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3587 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3588 | /* Next issue ABTS for everything on the txcmplq */ |
| 3589 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3590 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3591 | spin_unlock_irq(&phba->hbalock); |
| 3592 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3593 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3594 | /* Cancel all the IOCBs from the completions list */ |
| 3595 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3596 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | } |
| 3598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3599 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3600 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3601 | * @phba: Pointer to HBA context object. |
| 3602 | * @pring: Pointer to driver SLI ring object. |
| 3603 | * |
| 3604 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3605 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3606 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3607 | * the return of this function. The caller is not required to hold any locks. |
| 3608 | **/ |
| 3609 | void |
| 3610 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3611 | { |
| 3612 | struct lpfc_sli *psli = &phba->sli; |
| 3613 | struct lpfc_sli_ring *pring; |
| 3614 | uint32_t i; |
| 3615 | |
| 3616 | /* Look on all the FCP Rings for the iotag */ |
| 3617 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3618 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3619 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
| 3620 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3621 | } |
| 3622 | } else { |
| 3623 | pring = &psli->ring[psli->fcp_ring]; |
| 3624 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3630 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3631 | * @phba: Pointer to HBA context object. |
| 3632 | * |
| 3633 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3634 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3635 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3636 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3637 | * slot has been permanently disabled. |
| 3638 | **/ |
| 3639 | void |
| 3640 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3641 | { |
| 3642 | LIST_HEAD(txq); |
| 3643 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3644 | struct lpfc_sli *psli = &phba->sli; |
| 3645 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3646 | uint32_t i; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3647 | |
| 3648 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3649 | /* Indicate the I/O queues are flushed */ |
| 3650 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3651 | spin_unlock_irq(&phba->hbalock); |
| 3652 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3653 | /* Look on all the FCP Rings for the iotag */ |
| 3654 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3655 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 3656 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3657 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3658 | spin_lock_irq(&pring->ring_lock); |
| 3659 | /* Retrieve everything on txq */ |
| 3660 | list_splice_init(&pring->txq, &txq); |
| 3661 | /* Retrieve everything on the txcmplq */ |
| 3662 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3663 | pring->txq_cnt = 0; |
| 3664 | pring->txcmplq_cnt = 0; |
| 3665 | spin_unlock_irq(&pring->ring_lock); |
| 3666 | |
| 3667 | /* Flush the txq */ |
| 3668 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3669 | IOSTAT_LOCAL_REJECT, |
| 3670 | IOERR_SLI_DOWN); |
| 3671 | /* Flush the txcmpq */ |
| 3672 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3673 | IOSTAT_LOCAL_REJECT, |
| 3674 | IOERR_SLI_DOWN); |
| 3675 | } |
| 3676 | } else { |
| 3677 | pring = &psli->ring[psli->fcp_ring]; |
| 3678 | |
| 3679 | spin_lock_irq(&phba->hbalock); |
| 3680 | /* Retrieve everything on txq */ |
| 3681 | list_splice_init(&pring->txq, &txq); |
| 3682 | /* Retrieve everything on the txcmplq */ |
| 3683 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3684 | pring->txq_cnt = 0; |
| 3685 | pring->txcmplq_cnt = 0; |
| 3686 | spin_unlock_irq(&phba->hbalock); |
| 3687 | |
| 3688 | /* Flush the txq */ |
| 3689 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3690 | IOERR_SLI_DOWN); |
| 3691 | /* Flush the txcmpq */ |
| 3692 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3693 | IOERR_SLI_DOWN); |
| 3694 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3698 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3699 | * @phba: Pointer to HBA context object. |
| 3700 | * @mask: Bit mask to be checked. |
| 3701 | * |
| 3702 | * This function reads the host status register and compares |
| 3703 | * with the provided bit mask to check if HBA completed |
| 3704 | * the restart. This function will wait in a loop for the |
| 3705 | * HBA to complete restart. If the HBA does not restart within |
| 3706 | * 15 iterations, the function will reset the HBA again. The |
| 3707 | * function returns 1 when HBA fail to restart otherwise returns |
| 3708 | * zero. |
| 3709 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3710 | static int |
| 3711 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3713 | uint32_t status; |
| 3714 | int i = 0; |
| 3715 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3717 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3718 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3719 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3721 | /* |
| 3722 | * Check status register every 100ms for 5 retries, then every |
| 3723 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3724 | * every 2.5 sec for 4. |
| 3725 | * Break our of the loop if errors occurred during init. |
| 3726 | */ |
| 3727 | while (((status & mask) != mask) && |
| 3728 | !(status & HS_FFERM) && |
| 3729 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3731 | if (i <= 5) |
| 3732 | msleep(10); |
| 3733 | else if (i <= 10) |
| 3734 | msleep(500); |
| 3735 | else |
| 3736 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3738 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3739 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3740 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3741 | lpfc_sli_brdrestart(phba); |
| 3742 | } |
| 3743 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3744 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3745 | retval = 1; |
| 3746 | break; |
| 3747 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3750 | /* Check to see if any errors occurred during init */ |
| 3751 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3753 | "2751 Adapter failed to restart, " |
| 3754 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3755 | status, |
| 3756 | readl(phba->MBslimaddr + 0xa8), |
| 3757 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3758 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3759 | retval = 1; |
| 3760 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3762 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | } |
| 3764 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3765 | /** |
| 3766 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3767 | * @phba: Pointer to HBA context object. |
| 3768 | * @mask: Bit mask to be checked. |
| 3769 | * |
| 3770 | * This function checks the host status register to check if HBA is |
| 3771 | * ready. This function will wait in a loop for the HBA to be ready |
| 3772 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3773 | * function again. The function returns 1 when HBA fail to be ready |
| 3774 | * otherwise returns zero. |
| 3775 | **/ |
| 3776 | static int |
| 3777 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3778 | { |
| 3779 | uint32_t status; |
| 3780 | int retval = 0; |
| 3781 | |
| 3782 | /* Read the HBA Host Status Register */ |
| 3783 | status = lpfc_sli4_post_status_check(phba); |
| 3784 | |
| 3785 | if (status) { |
| 3786 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3787 | lpfc_sli_brdrestart(phba); |
| 3788 | status = lpfc_sli4_post_status_check(phba); |
| 3789 | } |
| 3790 | |
| 3791 | /* Check to see if any errors occurred during init */ |
| 3792 | if (status) { |
| 3793 | phba->link_state = LPFC_HBA_ERROR; |
| 3794 | retval = 1; |
| 3795 | } else |
| 3796 | phba->sli4_hba.intr_enable = 0; |
| 3797 | |
| 3798 | return retval; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3803 | * @phba: Pointer to HBA context object. |
| 3804 | * @mask: Bit mask to be checked. |
| 3805 | * |
| 3806 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3807 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3808 | **/ |
| 3809 | int |
| 3810 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3811 | { |
| 3812 | return phba->lpfc_sli_brdready(phba, mask); |
| 3813 | } |
| 3814 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3815 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3818 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3819 | * @phba: Pointer to HBA context object. |
| 3820 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3821 | * This function is called before resetting an HBA. This function is called |
| 3822 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3823 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3824 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3825 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3826 | uint32_t __iomem *resp_buf; |
| 3827 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3828 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3829 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3830 | int i; |
| 3831 | uint8_t hdrtype; |
| 3832 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3833 | lockdep_assert_held(&phba->hbalock); |
| 3834 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3835 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3836 | if (hdrtype != 0x80 || |
| 3837 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3838 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3839 | return; |
| 3840 | |
| 3841 | /* |
| 3842 | * Tell the other part of the chip to suspend temporarily all |
| 3843 | * its DMA activity. |
| 3844 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3845 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3846 | |
| 3847 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3848 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3849 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3850 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3851 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3853 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3854 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3855 | return; |
| 3856 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3857 | /* Clear Chip error bit */ |
| 3858 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3859 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | mbox = 0; |
| 3863 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3864 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3865 | |
| 3866 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3867 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3868 | writel(mbox, mbox_buf); |
| 3869 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3870 | for (i = 0; i < 50; i++) { |
| 3871 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3872 | return; |
| 3873 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3874 | mdelay(1); |
| 3875 | else |
| 3876 | break; |
| 3877 | } |
| 3878 | resp_data = 0; |
| 3879 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3880 | return; |
| 3881 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3882 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3883 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3884 | goto restore_hc; |
| 3885 | else |
| 3886 | goto clear_errat; |
| 3887 | } |
| 3888 | |
| 3889 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3890 | resp_data = 0; |
| 3891 | for (i = 0; i < 500; i++) { |
| 3892 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3893 | return; |
| 3894 | if (resp_data != mbox) |
| 3895 | mdelay(1); |
| 3896 | else |
| 3897 | break; |
| 3898 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3899 | |
| 3900 | clear_errat: |
| 3901 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3902 | while (++i < 500) { |
| 3903 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3904 | return; |
| 3905 | if (!(ha_copy & HA_ERATT)) |
| 3906 | mdelay(1); |
| 3907 | else |
| 3908 | break; |
| 3909 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3910 | |
| 3911 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3912 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3913 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3917 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3918 | writel(hc_copy, phba->HCregaddr); |
| 3919 | readl(phba->HCregaddr); /* flush */ |
| 3920 | } |
| 3921 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3922 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3923 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3924 | * @phba: Pointer to HBA context object. |
| 3925 | * |
| 3926 | * This function issues a kill_board mailbox command and waits for |
| 3927 | * the error attention interrupt. This function is called for stopping |
| 3928 | * the firmware processing. The caller is not required to hold any |
| 3929 | * locks. This function calls lpfc_hba_down_post function to free |
| 3930 | * any pending commands after the kill. The function will return 1 when it |
| 3931 | * fails to kill the board else will return 0. |
| 3932 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3933 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3934 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3935 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3936 | struct lpfc_sli *psli; |
| 3937 | LPFC_MBOXQ_t *pmb; |
| 3938 | uint32_t status; |
| 3939 | uint32_t ha_copy; |
| 3940 | int retval; |
| 3941 | int i = 0; |
| 3942 | |
| 3943 | psli = &phba->sli; |
| 3944 | |
| 3945 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3946 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3947 | "0329 Kill HBA Data: x%x x%x\n", |
| 3948 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3949 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3950 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3951 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3952 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3953 | |
| 3954 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3955 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3956 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3957 | spin_unlock_irq(&phba->hbalock); |
| 3958 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3959 | return 1; |
| 3960 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3961 | status &= ~HC_ERINT_ENA; |
| 3962 | writel(status, phba->HCregaddr); |
| 3963 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3964 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3965 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3966 | |
| 3967 | lpfc_kill_board(phba, pmb); |
| 3968 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3969 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3970 | |
| 3971 | if (retval != MBX_SUCCESS) { |
| 3972 | if (retval != MBX_BUSY) |
| 3973 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3975 | "2752 KILL_BOARD command failed retval %d\n", |
| 3976 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3977 | spin_lock_irq(&phba->hbalock); |
| 3978 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3979 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3980 | return 1; |
| 3981 | } |
| 3982 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3983 | spin_lock_irq(&phba->hbalock); |
| 3984 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3985 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3986 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3987 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3988 | |
| 3989 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3990 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3991 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3992 | * board is now undefined. |
| 3993 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3994 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3995 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3996 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3997 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3998 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3999 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4003 | if (ha_copy & HA_ERATT) { |
| 4004 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4005 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4006 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4007 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4008 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4009 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4011 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4012 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4013 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4015 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4019 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4020 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4021 | * @phba: Pointer to HBA context object. |
| 4022 | * |
| 4023 | * This function resets the HBA by writing HC_INITFF to the control |
| 4024 | * register. After the HBA resets, this function resets all the iocb ring |
| 4025 | * indices. This function disables PCI layer parity checking during |
| 4026 | * the reset. |
| 4027 | * This function returns 0 always. |
| 4028 | * The caller is not required to hold any locks. |
| 4029 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4030 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4031 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4032 | { |
| 4033 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4034 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4035 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4037 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4038 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4040 | /* Reset HBA */ |
| 4041 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4042 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4043 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4044 | |
| 4045 | /* perform board reset */ |
| 4046 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4047 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4048 | phba->pport->fc_myDID = 0; |
| 4049 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4051 | /* Turn off parity checking and serr during the physical reset */ |
| 4052 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4053 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4054 | (cfg_value & |
| 4055 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4056 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4057 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4058 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4059 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4060 | writel(HC_INITFF, phba->HCregaddr); |
| 4061 | mdelay(1); |
| 4062 | readl(phba->HCregaddr); /* flush */ |
| 4063 | writel(0, phba->HCregaddr); |
| 4064 | readl(phba->HCregaddr); /* flush */ |
| 4065 | |
| 4066 | /* Restore PCI cmd register */ |
| 4067 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | |
| 4069 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4070 | for (i = 0; i < psli->num_rings; i++) { |
| 4071 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4073 | pring->sli.sli3.rspidx = 0; |
| 4074 | pring->sli.sli3.next_cmdidx = 0; |
| 4075 | pring->sli.sli3.local_getidx = 0; |
| 4076 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | pring->missbufcnt = 0; |
| 4078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4080 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4081 | return 0; |
| 4082 | } |
| 4083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4084 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4085 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4086 | * @phba: Pointer to HBA context object. |
| 4087 | * |
| 4088 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4089 | * checking during resets the device. The caller is not required to hold |
| 4090 | * any locks. |
| 4091 | * |
| 4092 | * This function returns 0 always. |
| 4093 | **/ |
| 4094 | int |
| 4095 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4096 | { |
| 4097 | struct lpfc_sli *psli = &phba->sli; |
| 4098 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4099 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4100 | |
| 4101 | /* Reset HBA */ |
| 4102 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4103 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4104 | phba->pport->port_state, psli->sli_flag, |
| 4105 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4106 | |
| 4107 | /* perform board reset */ |
| 4108 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4109 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4110 | phba->pport->fc_myDID = 0; |
| 4111 | phba->pport->fc_prevDID = 0; |
| 4112 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4113 | spin_lock_irq(&phba->hbalock); |
| 4114 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4115 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4116 | spin_unlock_irq(&phba->hbalock); |
| 4117 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4118 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4119 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4120 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4121 | return rc; |
| 4122 | } |
| 4123 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4124 | /* Now physically reset the device */ |
| 4125 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4126 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4127 | |
| 4128 | /* Turn off parity checking and serr during the physical reset */ |
| 4129 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4130 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4131 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4132 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4133 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4134 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4135 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4136 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4137 | /* Restore PCI cmd register */ |
| 4138 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4139 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4140 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /** |
| 4144 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4145 | * @phba: Pointer to HBA context object. |
| 4146 | * |
| 4147 | * This function is called in the SLI initialization code path to |
| 4148 | * restart the HBA. The caller is not required to hold any lock. |
| 4149 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4150 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4151 | * function to free any pending commands. The function enables |
| 4152 | * POST only during the first initialization. The function returns zero. |
| 4153 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4154 | * command before the return of this function. |
| 4155 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4156 | static int |
| 4157 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4158 | { |
| 4159 | MAILBOX_t *mb; |
| 4160 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4161 | volatile uint32_t word0; |
| 4162 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4163 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4166 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4167 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4168 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4169 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4170 | psli = &phba->sli; |
| 4171 | |
| 4172 | /* Restart HBA */ |
| 4173 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4174 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4175 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4176 | |
| 4177 | word0 = 0; |
| 4178 | mb = (MAILBOX_t *) &word0; |
| 4179 | mb->mbxCommand = MBX_RESTART; |
| 4180 | mb->mbxHc = 1; |
| 4181 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4182 | lpfc_reset_barrier(phba); |
| 4183 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4184 | to_slim = phba->MBslimaddr; |
| 4185 | writel(*(uint32_t *) mb, to_slim); |
| 4186 | readl(to_slim); /* flush */ |
| 4187 | |
| 4188 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4189 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4190 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4191 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4192 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4193 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4194 | writel(*(uint32_t *) mb, to_slim); |
| 4195 | readl(to_slim); /* flush */ |
| 4196 | |
| 4197 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4198 | phba->pport->stopped = 0; |
| 4199 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4200 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4201 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4202 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4203 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4204 | psli->stats_start = get_seconds(); |
| 4205 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4206 | /* Give the INITFF and Post time to settle. */ |
| 4207 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4209 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4210 | if (hba_aer_enabled) |
| 4211 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4212 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4213 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | |
| 4215 | return 0; |
| 4216 | } |
| 4217 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4218 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4219 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4220 | * @phba: Pointer to HBA context object. |
| 4221 | * |
| 4222 | * This function is called in the SLI initialization code path to restart |
| 4223 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4224 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4225 | * free any pending commands. |
| 4226 | **/ |
| 4227 | static int |
| 4228 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4229 | { |
| 4230 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4231 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4232 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4233 | |
| 4234 | /* Restart HBA */ |
| 4235 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4236 | "0296 Restart HBA Data: x%x x%x\n", |
| 4237 | phba->pport->port_state, psli->sli_flag); |
| 4238 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4239 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4240 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4241 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4242 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4243 | |
| 4244 | spin_lock_irq(&phba->hbalock); |
| 4245 | phba->pport->stopped = 0; |
| 4246 | phba->link_state = LPFC_INIT_START; |
| 4247 | phba->hba_flag = 0; |
| 4248 | spin_unlock_irq(&phba->hbalock); |
| 4249 | |
| 4250 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4251 | psli->stats_start = get_seconds(); |
| 4252 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4253 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4254 | if (hba_aer_enabled) |
| 4255 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4256 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4257 | lpfc_hba_down_post(phba); |
| 4258 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4259 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4264 | * @phba: Pointer to HBA context object. |
| 4265 | * |
| 4266 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4267 | * API jump table function pointer from the lpfc_hba struct. |
| 4268 | **/ |
| 4269 | int |
| 4270 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4271 | { |
| 4272 | return phba->lpfc_sli_brdrestart(phba); |
| 4273 | } |
| 4274 | |
| 4275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4276 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4277 | * @phba: Pointer to HBA context object. |
| 4278 | * |
| 4279 | * This function is called after a HBA restart to wait for successful |
| 4280 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4281 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4282 | * iteration, the function will restart the HBA again. The function returns |
| 4283 | * zero if HBA successfully restarted else returns negative error code. |
| 4284 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | static int |
| 4286 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4287 | { |
| 4288 | uint32_t status, i = 0; |
| 4289 | |
| 4290 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4291 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4292 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 | |
| 4294 | /* Check status register to see what current state is */ |
| 4295 | i = 0; |
| 4296 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4297 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4298 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4299 | * retries, then every 1 sec for 50 retires for a total of |
| 4300 | * ~60 seconds before reset the board again and check every |
| 4301 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4302 | * board ready is required by the Falcon FIPS zeroization |
| 4303 | * complete, and any reset the board in between shall cause |
| 4304 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4306 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | /* Adapter failed to init, timeout, status reg |
| 4308 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4309 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4310 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4311 | "timeout, status reg x%x, " |
| 4312 | "FW Data: A8 x%x AC x%x\n", status, |
| 4313 | readl(phba->MBslimaddr + 0xa8), |
| 4314 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4315 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | return -ETIMEDOUT; |
| 4317 | } |
| 4318 | |
| 4319 | /* Check to see if any errors occurred during init */ |
| 4320 | if (status & HS_FFERM) { |
| 4321 | /* ERROR: During chipset initialization */ |
| 4322 | /* Adapter failed to init, chipset, status reg |
| 4323 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4325 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4326 | "chipset, status reg x%x, " |
| 4327 | "FW Data: A8 x%x AC x%x\n", status, |
| 4328 | readl(phba->MBslimaddr + 0xa8), |
| 4329 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | return -EIO; |
| 4332 | } |
| 4333 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4334 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4336 | else if (i <= 100) |
| 4337 | msleep(100); |
| 4338 | else |
| 4339 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4341 | if (i == 150) { |
| 4342 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4343 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4344 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4345 | } |
| 4346 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4347 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4348 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | /* Check to see if any errors occurred during init */ |
| 4352 | if (status & HS_FFERM) { |
| 4353 | /* ERROR: During chipset initialization */ |
| 4354 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4356 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4357 | "status reg x%x, " |
| 4358 | "FW Data: A8 x%x AC x%x\n", status, |
| 4359 | readl(phba->MBslimaddr + 0xa8), |
| 4360 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4361 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | return -EIO; |
| 4363 | } |
| 4364 | |
| 4365 | /* Clear all interrupt enable conditions */ |
| 4366 | writel(0, phba->HCregaddr); |
| 4367 | readl(phba->HCregaddr); /* flush */ |
| 4368 | |
| 4369 | /* setup host attn register */ |
| 4370 | writel(0xffffffff, phba->HAregaddr); |
| 4371 | readl(phba->HAregaddr); /* flush */ |
| 4372 | return 0; |
| 4373 | } |
| 4374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4375 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4376 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4377 | * |
| 4378 | * This function calculates and returns the number of HBQs required to be |
| 4379 | * configured. |
| 4380 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4381 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4382 | lpfc_sli_hbq_count(void) |
| 4383 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4385 | } |
| 4386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4388 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4389 | * |
| 4390 | * This function adds the number of hbq entries in every HBQ to get |
| 4391 | * the total number of hbq entries required for the HBA and returns |
| 4392 | * the total count. |
| 4393 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4394 | static int |
| 4395 | lpfc_sli_hbq_entry_count(void) |
| 4396 | { |
| 4397 | int hbq_count = lpfc_sli_hbq_count(); |
| 4398 | int count = 0; |
| 4399 | int i; |
| 4400 | |
| 4401 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4402 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4403 | return count; |
| 4404 | } |
| 4405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4407 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4408 | * |
| 4409 | * This function calculates amount of memory required for all hbq entries |
| 4410 | * to be configured and returns the total memory required. |
| 4411 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4413 | lpfc_sli_hbq_size(void) |
| 4414 | { |
| 4415 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4416 | } |
| 4417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4418 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4419 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4420 | * @phba: Pointer to HBA context object. |
| 4421 | * |
| 4422 | * This function is called during the SLI initialization to configure |
| 4423 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4424 | * required to hold any locks. This function will return zero if successful |
| 4425 | * else it will return negative error code. |
| 4426 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4427 | static int |
| 4428 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4429 | { |
| 4430 | int hbq_count = lpfc_sli_hbq_count(); |
| 4431 | LPFC_MBOXQ_t *pmb; |
| 4432 | MAILBOX_t *pmbox; |
| 4433 | uint32_t hbqno; |
| 4434 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4435 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4436 | /* Get a Mailbox buffer to setup mailbox |
| 4437 | * commands for HBA initialization |
| 4438 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4439 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4440 | |
| 4441 | if (!pmb) |
| 4442 | return -ENOMEM; |
| 4443 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4444 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4445 | |
| 4446 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4447 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4448 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4449 | |
| 4450 | hbq_entry_index = 0; |
| 4451 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4452 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4453 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4454 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4455 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4456 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4457 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4458 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4459 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4460 | |
| 4461 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4462 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4463 | mbxStatus <status>, ring <num> */ |
| 4464 | |
| 4465 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4466 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4467 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4468 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4469 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4470 | pmbox->mbxStatus, hbqno); |
| 4471 | |
| 4472 | phba->link_state = LPFC_HBA_ERROR; |
| 4473 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4474 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | phba->hbq_count = hbq_count; |
| 4478 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4479 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4480 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4481 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4482 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4483 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4484 | return 0; |
| 4485 | } |
| 4486 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4487 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4488 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4489 | * @phba: Pointer to HBA context object. |
| 4490 | * |
| 4491 | * This function is called during the SLI initialization to configure |
| 4492 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4493 | * required to hold any locks. This function will return zero if successful |
| 4494 | * else it will return negative error code. |
| 4495 | **/ |
| 4496 | static int |
| 4497 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4498 | { |
| 4499 | phba->hbq_in_use = 1; |
| 4500 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4501 | phba->hbq_count = 1; |
| 4502 | /* Initially populate or replenish the HBQs */ |
| 4503 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4504 | return 0; |
| 4505 | } |
| 4506 | |
| 4507 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4508 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4509 | * @phba: Pointer to HBA context object. |
| 4510 | * @sli_mode: sli mode - 2/3 |
| 4511 | * |
| 4512 | * This function is called by the sli intialization code path |
| 4513 | * to issue config_port mailbox command. This function restarts the |
| 4514 | * HBA firmware and issues a config_port mailbox command to configure |
| 4515 | * the SLI interface in the sli mode specified by sli_mode |
| 4516 | * variable. The caller is not required to hold any locks. |
| 4517 | * The function returns 0 if successful, else returns negative error |
| 4518 | * code. |
| 4519 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4520 | int |
| 4521 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | { |
| 4523 | LPFC_MBOXQ_t *pmb; |
| 4524 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4525 | |
| 4526 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4527 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4528 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | return -ENOMEM; |
| 4530 | } |
| 4531 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4532 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4533 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4535 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4538 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | rc = lpfc_sli_chipset_init(phba); |
| 4540 | if (rc) |
| 4541 | break; |
| 4542 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4543 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4544 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4545 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4546 | resetcount++; |
| 4547 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4548 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4549 | * value of 0 means the call was successful. Any other |
| 4550 | * nonzero value is a failure, but if ERESTART is returned, |
| 4551 | * the driver may reset the HBA and try again. |
| 4552 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4553 | rc = lpfc_config_port_prep(phba); |
| 4554 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4555 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4557 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4558 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4560 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | lpfc_config_port(phba, pmb); |
| 4562 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4563 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4564 | LPFC_SLI3_HBQ_ENABLED | |
| 4565 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4566 | LPFC_SLI3_BG_ENABLED | |
| 4567 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4568 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4570 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4571 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4572 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4573 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4574 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | spin_unlock_irq(&phba->hbalock); |
| 4576 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4577 | } else { |
| 4578 | /* Allow asynchronous mailbox command to go through */ |
| 4579 | spin_lock_irq(&phba->hbalock); |
| 4580 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4581 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4582 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4583 | |
| 4584 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4585 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4586 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4587 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4588 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4590 | if (!done) { |
| 4591 | rc = -EINVAL; |
| 4592 | goto do_prep_failed; |
| 4593 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4594 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4595 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4596 | rc = -ENXIO; |
| 4597 | goto do_prep_failed; |
| 4598 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4599 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4600 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4601 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4602 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4603 | phba->max_vpi : phba->max_vports; |
| 4604 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4605 | } else |
| 4606 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4607 | phba->fips_level = 0; |
| 4608 | phba->fips_spec_rev = 0; |
| 4609 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4610 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4611 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4612 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4613 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4614 | "2850 Security Crypto Active. FIPS x%d " |
| 4615 | "(Spec Rev: x%d)", |
| 4616 | phba->fips_level, phba->fips_spec_rev); |
| 4617 | } |
| 4618 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4620 | "2856 Config Port Security Crypto " |
| 4621 | "Error: x%x ", |
| 4622 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4623 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4624 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4625 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4626 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4627 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4628 | |
| 4629 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4630 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4631 | |
| 4632 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4633 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4634 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4635 | else |
| 4636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4637 | "0443 Adapter did not grant " |
| 4638 | "BlockGuard\n"); |
| 4639 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4640 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4641 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4642 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4643 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4644 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4645 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4646 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4647 | return rc; |
| 4648 | } |
| 4649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4650 | |
| 4651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4652 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4653 | * @phba: Pointer to HBA context object. |
| 4654 | * |
| 4655 | * This function is the main SLI intialization function. This function |
| 4656 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4657 | * error attention handler code. Caller is not required to hold any |
| 4658 | * locks. This function issues config_port mailbox command to configure |
| 4659 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4660 | * calls the config_port_post function to issue init_link mailbox |
| 4661 | * command and to start the discovery. The function will return zero |
| 4662 | * if successful, else it will return negative error code. |
| 4663 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4664 | int |
| 4665 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4666 | { |
| 4667 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4668 | int mode = 3, i; |
| 4669 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4670 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4671 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4672 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4673 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4675 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4676 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4677 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4678 | break; |
| 4679 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4680 | mode = 2; |
| 4681 | break; |
| 4682 | case 0: |
| 4683 | case 3: |
| 4684 | break; |
| 4685 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4686 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4687 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 4688 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4689 | |
| 4690 | break; |
| 4691 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 4692 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4693 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4694 | rc = lpfc_sli_config_port(phba, mode); |
| 4695 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4696 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4697 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4698 | "1820 Unable to select SLI-3. " |
| 4699 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4700 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4701 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 4702 | else if (rc && mode == 2) |
| 4703 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4704 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | goto lpfc_sli_hba_setup_error; |
| 4706 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4707 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4708 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4709 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4710 | if (!rc) { |
| 4711 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4712 | "2709 This device supports " |
| 4713 | "Advanced Error Reporting (AER)\n"); |
| 4714 | spin_lock_irq(&phba->hbalock); |
| 4715 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4716 | spin_unlock_irq(&phba->hbalock); |
| 4717 | } else { |
| 4718 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4719 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4720 | "Advanced Error Reporting (AER): %d\n", |
| 4721 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4722 | phba->cfg_aer_support = 0; |
| 4723 | } |
| 4724 | } |
| 4725 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4726 | if (phba->sli_rev == 3) { |
| 4727 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4728 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4729 | } else { |
| 4730 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4731 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4732 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4736 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4737 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4738 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4739 | |
| 4740 | if (rc) |
| 4741 | goto lpfc_sli_hba_setup_error; |
| 4742 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4743 | /* Initialize VPIs. */ |
| 4744 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4745 | /* |
| 4746 | * The VPI bitmask and physical ID array are allocated |
| 4747 | * and initialized once only - at driver load. A port |
| 4748 | * reset doesn't need to reinitialize this memory. |
| 4749 | */ |
| 4750 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4751 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4752 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4753 | GFP_KERNEL); |
| 4754 | if (!phba->vpi_bmask) { |
| 4755 | rc = -ENOMEM; |
| 4756 | goto lpfc_sli_hba_setup_error; |
| 4757 | } |
| 4758 | |
| 4759 | phba->vpi_ids = kzalloc( |
| 4760 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4761 | GFP_KERNEL); |
| 4762 | if (!phba->vpi_ids) { |
| 4763 | kfree(phba->vpi_bmask); |
| 4764 | rc = -ENOMEM; |
| 4765 | goto lpfc_sli_hba_setup_error; |
| 4766 | } |
| 4767 | for (i = 0; i < phba->max_vpi; i++) |
| 4768 | phba->vpi_ids[i] = i; |
| 4769 | } |
| 4770 | } |
| 4771 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4772 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4773 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4774 | rc = lpfc_sli_hbq_setup(phba); |
| 4775 | if (rc) |
| 4776 | goto lpfc_sli_hba_setup_error; |
| 4777 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4778 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4779 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4780 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4781 | |
| 4782 | rc = lpfc_config_port_post(phba); |
| 4783 | if (rc) |
| 4784 | goto lpfc_sli_hba_setup_error; |
| 4785 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4786 | return rc; |
| 4787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4788 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4789 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4791 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4792 | return rc; |
| 4793 | } |
| 4794 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4795 | /** |
| 4796 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4797 | * @phba: Pointer to HBA context object. |
| 4798 | * @mboxq: mailbox pointer. |
| 4799 | * This function issue a dump mailbox command to read config region |
| 4800 | * 23 and parse the records in the region and populate driver |
| 4801 | * data structure. |
| 4802 | **/ |
| 4803 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4804 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4805 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4806 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4807 | struct lpfc_dmabuf *mp; |
| 4808 | struct lpfc_mqe *mqe; |
| 4809 | uint32_t data_length; |
| 4810 | int rc; |
| 4811 | |
| 4812 | /* Program the default value of vlan_id and fc_map */ |
| 4813 | phba->valid_vlan = 0; |
| 4814 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4815 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4816 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4817 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4818 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4819 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4820 | return -ENOMEM; |
| 4821 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4822 | mqe = &mboxq->u.mqe; |
| 4823 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4824 | rc = -ENOMEM; |
| 4825 | goto out_free_mboxq; |
| 4826 | } |
| 4827 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4828 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4829 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4830 | |
| 4831 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4832 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4833 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4834 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4835 | "CQ: x%x x%x x%x x%x\n", |
| 4836 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4837 | bf_get(lpfc_mqe_command, mqe), |
| 4838 | bf_get(lpfc_mqe_status, mqe), |
| 4839 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4840 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4841 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4842 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4843 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4844 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4845 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4846 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4847 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4848 | mboxq->mcqe.word0, |
| 4849 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4850 | mboxq->mcqe.trailer); |
| 4851 | |
| 4852 | if (rc) { |
| 4853 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4854 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4855 | rc = -EIO; |
| 4856 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4857 | } |
| 4858 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4859 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4860 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4861 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4862 | rc = -EIO; |
| 4863 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4864 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4865 | |
| 4866 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4867 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4868 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4869 | rc = 0; |
| 4870 | |
| 4871 | out_free_mboxq: |
| 4872 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4873 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | /** |
| 4877 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4878 | * @phba: pointer to lpfc hba data structure. |
| 4879 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4880 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4881 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4882 | * On output, the number of data bytes in @vpd. |
| 4883 | * |
| 4884 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4885 | * addition, this routine gets the port vpd data. |
| 4886 | * |
| 4887 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4888 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4889 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4890 | **/ |
| 4891 | static int |
| 4892 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4893 | uint8_t *vpd, uint32_t *vpd_size) |
| 4894 | { |
| 4895 | int rc = 0; |
| 4896 | uint32_t dma_size; |
| 4897 | struct lpfc_dmabuf *dmabuf; |
| 4898 | struct lpfc_mqe *mqe; |
| 4899 | |
| 4900 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4901 | if (!dmabuf) |
| 4902 | return -ENOMEM; |
| 4903 | |
| 4904 | /* |
| 4905 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4906 | * mailbox command. |
| 4907 | */ |
| 4908 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 4909 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 4910 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4911 | if (!dmabuf->virt) { |
| 4912 | kfree(dmabuf); |
| 4913 | return -ENOMEM; |
| 4914 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4915 | |
| 4916 | /* |
| 4917 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4918 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4919 | * in SLI3. This code corrects the conflicts. |
| 4920 | */ |
| 4921 | lpfc_read_rev(phba, mboxq); |
| 4922 | mqe = &mboxq->u.mqe; |
| 4923 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4924 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4925 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4926 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4927 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4928 | |
| 4929 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4930 | if (rc) { |
| 4931 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4932 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4933 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4934 | return -EIO; |
| 4935 | } |
| 4936 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4937 | /* |
| 4938 | * The available vpd length cannot be bigger than the |
| 4939 | * DMA buffer passed to the port. Catch the less than |
| 4940 | * case and update the caller's size. |
| 4941 | */ |
| 4942 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4943 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4944 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4945 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4946 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4947 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4948 | dmabuf->virt, dmabuf->phys); |
| 4949 | kfree(dmabuf); |
| 4950 | return 0; |
| 4951 | } |
| 4952 | |
| 4953 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4954 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4955 | * @phba: pointer to lpfc hba data structure. |
| 4956 | * |
| 4957 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4958 | * is attached to. |
| 4959 | * |
| 4960 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4961 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4962 | * otherwise - failed to retrieve physical port name |
| 4963 | **/ |
| 4964 | static int |
| 4965 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4966 | { |
| 4967 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4968 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4969 | struct lpfc_controller_attribute *cntl_attr; |
| 4970 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4971 | void *virtaddr = NULL; |
| 4972 | uint32_t alloclen, reqlen; |
| 4973 | uint32_t shdr_status, shdr_add_status; |
| 4974 | union lpfc_sli4_cfg_shdr *shdr; |
| 4975 | char cport_name = 0; |
| 4976 | int rc; |
| 4977 | |
| 4978 | /* We assume nothing at this point */ |
| 4979 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4980 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4981 | |
| 4982 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4983 | if (!mboxq) |
| 4984 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4985 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4986 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4987 | lpfc_sli4_read_config(phba); |
| 4988 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4989 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4990 | |
| 4991 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4992 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4993 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4994 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4995 | LPFC_SLI4_MBX_NEMBED); |
| 4996 | if (alloclen < reqlen) { |
| 4997 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4998 | "3084 Allocated DMA memory size (%d) is " |
| 4999 | "less than the requested DMA memory size " |
| 5000 | "(%d)\n", alloclen, reqlen); |
| 5001 | rc = -ENOMEM; |
| 5002 | goto out_free_mboxq; |
| 5003 | } |
| 5004 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5005 | virtaddr = mboxq->sge_array->addr[0]; |
| 5006 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5007 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5008 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5009 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5010 | if (shdr_status || shdr_add_status || rc) { |
| 5011 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5012 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5013 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5014 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5015 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5016 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5017 | rc, shdr_status, shdr_add_status); |
| 5018 | rc = -ENXIO; |
| 5019 | goto out_free_mboxq; |
| 5020 | } |
| 5021 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5022 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5023 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5024 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5025 | phba->sli4_hba.lnk_info.lnk_no = |
| 5026 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5027 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5028 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5029 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5030 | phba->sli4_hba.lnk_info.lnk_no); |
| 5031 | |
| 5032 | retrieve_ppname: |
| 5033 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5034 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5035 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5036 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5037 | LPFC_SLI4_MBX_EMBED); |
| 5038 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5039 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5040 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5041 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5042 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5043 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5044 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5045 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5046 | if (shdr_status || shdr_add_status || rc) { |
| 5047 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5048 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5049 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5050 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5051 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5052 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5053 | rc, shdr_status, shdr_add_status); |
| 5054 | rc = -ENXIO; |
| 5055 | goto out_free_mboxq; |
| 5056 | } |
| 5057 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5058 | case LPFC_LINK_NUMBER_0: |
| 5059 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5060 | &get_port_name->u.response); |
| 5061 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5062 | break; |
| 5063 | case LPFC_LINK_NUMBER_1: |
| 5064 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5065 | &get_port_name->u.response); |
| 5066 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5067 | break; |
| 5068 | case LPFC_LINK_NUMBER_2: |
| 5069 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5070 | &get_port_name->u.response); |
| 5071 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5072 | break; |
| 5073 | case LPFC_LINK_NUMBER_3: |
| 5074 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5075 | &get_port_name->u.response); |
| 5076 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5077 | break; |
| 5078 | default: |
| 5079 | break; |
| 5080 | } |
| 5081 | |
| 5082 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5083 | phba->Port[0] = cport_name; |
| 5084 | phba->Port[1] = '\0'; |
| 5085 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5086 | "3091 SLI get port name: %s\n", phba->Port); |
| 5087 | } |
| 5088 | |
| 5089 | out_free_mboxq: |
| 5090 | if (rc != MBX_TIMEOUT) { |
| 5091 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5092 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5093 | else |
| 5094 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5095 | } |
| 5096 | return rc; |
| 5097 | } |
| 5098 | |
| 5099 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5100 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5101 | * @phba: pointer to lpfc hba data structure. |
| 5102 | * |
| 5103 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5104 | * event queues |
| 5105 | **/ |
| 5106 | static void |
| 5107 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5108 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 5109 | int fcp_eqidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5110 | |
| 5111 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5112 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5113 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5114 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5115 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5116 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 5117 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5118 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5119 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5120 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5121 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5122 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5123 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5124 | if (phba->sli4_hba.hba_eq) { |
| 5125 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5126 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5127 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5128 | LPFC_QUEUE_REARM); |
| 5129 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5130 | |
| 5131 | if (phba->cfg_fof) |
| 5132 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5136 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5137 | * @phba: Pointer to HBA context object. |
| 5138 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5139 | * @extnt_count: buffer to hold port available extent count. |
| 5140 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5141 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5142 | * This function calls the port and retrievs the number of available |
| 5143 | * extents and their size for a particular extent type. |
| 5144 | * |
| 5145 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5146 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5147 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5148 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5149 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5150 | { |
| 5151 | int rc = 0; |
| 5152 | uint32_t length; |
| 5153 | uint32_t mbox_tmo; |
| 5154 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5155 | LPFC_MBOXQ_t *mbox; |
| 5156 | |
| 5157 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5158 | if (!mbox) |
| 5159 | return -ENOMEM; |
| 5160 | |
| 5161 | /* Find out how many extents are available for this resource type */ |
| 5162 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5163 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5164 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5165 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5166 | length, LPFC_SLI4_MBX_EMBED); |
| 5167 | |
| 5168 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5169 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5170 | LPFC_SLI4_MBX_EMBED); |
| 5171 | if (unlikely(rc)) { |
| 5172 | rc = -EIO; |
| 5173 | goto err_exit; |
| 5174 | } |
| 5175 | |
| 5176 | if (!phba->sli4_hba.intr_enable) |
| 5177 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5178 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5179 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5180 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5181 | } |
| 5182 | if (unlikely(rc)) { |
| 5183 | rc = -EIO; |
| 5184 | goto err_exit; |
| 5185 | } |
| 5186 | |
| 5187 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5188 | if (bf_get(lpfc_mbox_hdr_status, |
| 5189 | &rsrc_info->header.cfg_shdr.response)) { |
| 5190 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5191 | "2930 Failed to get resource extents " |
| 5192 | "Status 0x%x Add'l Status 0x%x\n", |
| 5193 | bf_get(lpfc_mbox_hdr_status, |
| 5194 | &rsrc_info->header.cfg_shdr.response), |
| 5195 | bf_get(lpfc_mbox_hdr_add_status, |
| 5196 | &rsrc_info->header.cfg_shdr.response)); |
| 5197 | rc = -EIO; |
| 5198 | goto err_exit; |
| 5199 | } |
| 5200 | |
| 5201 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5202 | &rsrc_info->u.rsp); |
| 5203 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5204 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5205 | |
| 5206 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5207 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5208 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5209 | |
| 5210 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5211 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5212 | return rc; |
| 5213 | } |
| 5214 | |
| 5215 | /** |
| 5216 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5217 | * @phba: Pointer to HBA context object. |
| 5218 | * @type: The extent type to check. |
| 5219 | * |
| 5220 | * This function reads the current available extents from the port and checks |
| 5221 | * if the extent count or extent size has changed since the last access. |
| 5222 | * Callers use this routine post port reset to understand if there is a |
| 5223 | * extent reprovisioning requirement. |
| 5224 | * |
| 5225 | * Returns: |
| 5226 | * -Error: error indicates problem. |
| 5227 | * 1: Extent count or size has changed. |
| 5228 | * 0: No changes. |
| 5229 | **/ |
| 5230 | static int |
| 5231 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5232 | { |
| 5233 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5234 | uint16_t size_diff, rsrc_ext_size; |
| 5235 | int rc = 0; |
| 5236 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5237 | struct list_head *rsrc_blk_list = NULL; |
| 5238 | |
| 5239 | size_diff = 0; |
| 5240 | curr_ext_cnt = 0; |
| 5241 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5242 | &rsrc_ext_cnt, |
| 5243 | &rsrc_ext_size); |
| 5244 | if (unlikely(rc)) |
| 5245 | return -EIO; |
| 5246 | |
| 5247 | switch (type) { |
| 5248 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5249 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5250 | break; |
| 5251 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5252 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5253 | break; |
| 5254 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5255 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5256 | break; |
| 5257 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5258 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5259 | break; |
| 5260 | default: |
| 5261 | break; |
| 5262 | } |
| 5263 | |
| 5264 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5265 | curr_ext_cnt++; |
| 5266 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5267 | size_diff++; |
| 5268 | } |
| 5269 | |
| 5270 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5271 | rc = 1; |
| 5272 | |
| 5273 | return rc; |
| 5274 | } |
| 5275 | |
| 5276 | /** |
| 5277 | * lpfc_sli4_cfg_post_extnts - |
| 5278 | * @phba: Pointer to HBA context object. |
| 5279 | * @extnt_cnt - number of available extents. |
| 5280 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5281 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5282 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5283 | * |
| 5284 | * This function executes the extents allocation request. It also |
| 5285 | * takes care of the amount of memory needed to allocate or get the |
| 5286 | * allocated extents. It is the caller's responsibility to evaluate |
| 5287 | * the response. |
| 5288 | * |
| 5289 | * Returns: |
| 5290 | * -Error: Error value describes the condition found. |
| 5291 | * 0: if successful |
| 5292 | **/ |
| 5293 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5294 | 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] | 5295 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5296 | { |
| 5297 | int rc = 0; |
| 5298 | uint32_t req_len; |
| 5299 | uint32_t emb_len; |
| 5300 | uint32_t alloc_len, mbox_tmo; |
| 5301 | |
| 5302 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5303 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5304 | |
| 5305 | /* |
| 5306 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5307 | * accounts for extents-specific word. |
| 5308 | */ |
| 5309 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5310 | sizeof(uint32_t); |
| 5311 | |
| 5312 | /* |
| 5313 | * Presume the allocation and response will fit into an embedded |
| 5314 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5315 | */ |
| 5316 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5317 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5318 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5319 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5320 | sizeof(uint32_t); |
| 5321 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5322 | } |
| 5323 | |
| 5324 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5325 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5326 | req_len, *emb); |
| 5327 | if (alloc_len < req_len) { |
| 5328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5329 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5330 | "less than the requested DMA memory " |
| 5331 | "size (x%x)\n", alloc_len, req_len); |
| 5332 | return -ENOMEM; |
| 5333 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5334 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5335 | if (unlikely(rc)) |
| 5336 | return -EIO; |
| 5337 | |
| 5338 | if (!phba->sli4_hba.intr_enable) |
| 5339 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5340 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5341 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5342 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5343 | } |
| 5344 | |
| 5345 | if (unlikely(rc)) |
| 5346 | rc = -EIO; |
| 5347 | return rc; |
| 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5352 | * @phba: Pointer to HBA context object. |
| 5353 | * @type: The resource extent type to allocate. |
| 5354 | * |
| 5355 | * This function allocates the number of elements for the specified |
| 5356 | * resource type. |
| 5357 | **/ |
| 5358 | static int |
| 5359 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5360 | { |
| 5361 | bool emb = false; |
| 5362 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5363 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5364 | uint16_t *ids; |
| 5365 | int i, rc; |
| 5366 | unsigned long longs; |
| 5367 | unsigned long *bmask; |
| 5368 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5369 | LPFC_MBOXQ_t *mbox; |
| 5370 | uint32_t length; |
| 5371 | struct lpfc_id_range *id_array = NULL; |
| 5372 | void *virtaddr = NULL; |
| 5373 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5374 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5375 | struct list_head *ext_blk_list; |
| 5376 | |
| 5377 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5378 | &rsrc_cnt, |
| 5379 | &rsrc_size); |
| 5380 | if (unlikely(rc)) |
| 5381 | return -EIO; |
| 5382 | |
| 5383 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5384 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5385 | "3009 No available Resource Extents " |
| 5386 | "for resource type 0x%x: Count: 0x%x, " |
| 5387 | "Size 0x%x\n", type, rsrc_cnt, |
| 5388 | rsrc_size); |
| 5389 | return -ENOMEM; |
| 5390 | } |
| 5391 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5392 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5393 | "2903 Post resource extents type-0x%x: " |
| 5394 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5395 | |
| 5396 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5397 | if (!mbox) |
| 5398 | return -ENOMEM; |
| 5399 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5400 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5401 | if (unlikely(rc)) { |
| 5402 | rc = -EIO; |
| 5403 | goto err_exit; |
| 5404 | } |
| 5405 | |
| 5406 | /* |
| 5407 | * Figure out where the response is located. Then get local pointers |
| 5408 | * to the response data. The port does not guarantee to respond to |
| 5409 | * all extents counts request so update the local variable with the |
| 5410 | * allocated count from the port. |
| 5411 | */ |
| 5412 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5413 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5414 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5415 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5416 | } else { |
| 5417 | virtaddr = mbox->sge_array->addr[0]; |
| 5418 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5419 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5420 | id_array = &n_rsrc->id; |
| 5421 | } |
| 5422 | |
| 5423 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5424 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5425 | |
| 5426 | /* |
| 5427 | * Based on the resource size and count, correct the base and max |
| 5428 | * resource values. |
| 5429 | */ |
| 5430 | length = sizeof(struct lpfc_rsrc_blks); |
| 5431 | switch (type) { |
| 5432 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5433 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5434 | sizeof(unsigned long), |
| 5435 | GFP_KERNEL); |
| 5436 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5437 | rc = -ENOMEM; |
| 5438 | goto err_exit; |
| 5439 | } |
| 5440 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5441 | sizeof(uint16_t), |
| 5442 | GFP_KERNEL); |
| 5443 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5444 | kfree(phba->sli4_hba.rpi_bmask); |
| 5445 | rc = -ENOMEM; |
| 5446 | goto err_exit; |
| 5447 | } |
| 5448 | |
| 5449 | /* |
| 5450 | * The next_rpi was initialized with the maximum available |
| 5451 | * count but the port may allocate a smaller number. Catch |
| 5452 | * that case and update the next_rpi. |
| 5453 | */ |
| 5454 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5455 | |
| 5456 | /* Initialize local ptrs for common extent processing later. */ |
| 5457 | bmask = phba->sli4_hba.rpi_bmask; |
| 5458 | ids = phba->sli4_hba.rpi_ids; |
| 5459 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5460 | break; |
| 5461 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5462 | phba->vpi_bmask = kzalloc(longs * |
| 5463 | sizeof(unsigned long), |
| 5464 | GFP_KERNEL); |
| 5465 | if (unlikely(!phba->vpi_bmask)) { |
| 5466 | rc = -ENOMEM; |
| 5467 | goto err_exit; |
| 5468 | } |
| 5469 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5470 | sizeof(uint16_t), |
| 5471 | GFP_KERNEL); |
| 5472 | if (unlikely(!phba->vpi_ids)) { |
| 5473 | kfree(phba->vpi_bmask); |
| 5474 | rc = -ENOMEM; |
| 5475 | goto err_exit; |
| 5476 | } |
| 5477 | |
| 5478 | /* Initialize local ptrs for common extent processing later. */ |
| 5479 | bmask = phba->vpi_bmask; |
| 5480 | ids = phba->vpi_ids; |
| 5481 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5482 | break; |
| 5483 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5484 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5485 | sizeof(unsigned long), |
| 5486 | GFP_KERNEL); |
| 5487 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5488 | rc = -ENOMEM; |
| 5489 | goto err_exit; |
| 5490 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5491 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5492 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5493 | sizeof(uint16_t), |
| 5494 | GFP_KERNEL); |
| 5495 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5496 | kfree(phba->sli4_hba.xri_bmask); |
| 5497 | rc = -ENOMEM; |
| 5498 | goto err_exit; |
| 5499 | } |
| 5500 | |
| 5501 | /* Initialize local ptrs for common extent processing later. */ |
| 5502 | bmask = phba->sli4_hba.xri_bmask; |
| 5503 | ids = phba->sli4_hba.xri_ids; |
| 5504 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5505 | break; |
| 5506 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5507 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5508 | sizeof(unsigned long), |
| 5509 | GFP_KERNEL); |
| 5510 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5511 | rc = -ENOMEM; |
| 5512 | goto err_exit; |
| 5513 | } |
| 5514 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5515 | sizeof(uint16_t), |
| 5516 | GFP_KERNEL); |
| 5517 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5518 | kfree(phba->sli4_hba.vfi_bmask); |
| 5519 | rc = -ENOMEM; |
| 5520 | goto err_exit; |
| 5521 | } |
| 5522 | |
| 5523 | /* Initialize local ptrs for common extent processing later. */ |
| 5524 | bmask = phba->sli4_hba.vfi_bmask; |
| 5525 | ids = phba->sli4_hba.vfi_ids; |
| 5526 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5527 | break; |
| 5528 | default: |
| 5529 | /* Unsupported Opcode. Fail call. */ |
| 5530 | id_array = NULL; |
| 5531 | bmask = NULL; |
| 5532 | ids = NULL; |
| 5533 | ext_blk_list = NULL; |
| 5534 | goto err_exit; |
| 5535 | } |
| 5536 | |
| 5537 | /* |
| 5538 | * Complete initializing the extent configuration with the |
| 5539 | * allocated ids assigned to this function. The bitmask serves |
| 5540 | * as an index into the array and manages the available ids. The |
| 5541 | * array just stores the ids communicated to the port via the wqes. |
| 5542 | */ |
| 5543 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5544 | if ((i % 2) == 0) |
| 5545 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5546 | &id_array[k]); |
| 5547 | else |
| 5548 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5549 | &id_array[k]); |
| 5550 | |
| 5551 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5552 | if (unlikely(!rsrc_blks)) { |
| 5553 | rc = -ENOMEM; |
| 5554 | kfree(bmask); |
| 5555 | kfree(ids); |
| 5556 | goto err_exit; |
| 5557 | } |
| 5558 | rsrc_blks->rsrc_start = rsrc_id; |
| 5559 | rsrc_blks->rsrc_size = rsrc_size; |
| 5560 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5561 | rsrc_start = rsrc_id; |
| 5562 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5563 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5564 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5565 | |
| 5566 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5567 | ids[j] = rsrc_id; |
| 5568 | rsrc_id++; |
| 5569 | j++; |
| 5570 | } |
| 5571 | /* Entire word processed. Get next word.*/ |
| 5572 | if ((i % 2) == 1) |
| 5573 | k++; |
| 5574 | } |
| 5575 | err_exit: |
| 5576 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5577 | return rc; |
| 5578 | } |
| 5579 | |
| 5580 | /** |
| 5581 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5582 | * @phba: Pointer to HBA context object. |
| 5583 | * @type: the extent's type. |
| 5584 | * |
| 5585 | * This function deallocates all extents of a particular resource type. |
| 5586 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5587 | * is the caller's responsibility to release all kernel memory resources. |
| 5588 | **/ |
| 5589 | static int |
| 5590 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5591 | { |
| 5592 | int rc; |
| 5593 | uint32_t length, mbox_tmo = 0; |
| 5594 | LPFC_MBOXQ_t *mbox; |
| 5595 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5596 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5597 | |
| 5598 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5599 | if (!mbox) |
| 5600 | return -ENOMEM; |
| 5601 | |
| 5602 | /* |
| 5603 | * This function sends an embedded mailbox because it only sends the |
| 5604 | * the resource type. All extents of this type are released by the |
| 5605 | * port. |
| 5606 | */ |
| 5607 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5608 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5609 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5610 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5611 | length, LPFC_SLI4_MBX_EMBED); |
| 5612 | |
| 5613 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5614 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5615 | LPFC_SLI4_MBX_EMBED); |
| 5616 | if (unlikely(rc)) { |
| 5617 | rc = -EIO; |
| 5618 | goto out_free_mbox; |
| 5619 | } |
| 5620 | if (!phba->sli4_hba.intr_enable) |
| 5621 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5622 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5623 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5624 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5625 | } |
| 5626 | if (unlikely(rc)) { |
| 5627 | rc = -EIO; |
| 5628 | goto out_free_mbox; |
| 5629 | } |
| 5630 | |
| 5631 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5632 | if (bf_get(lpfc_mbox_hdr_status, |
| 5633 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5634 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5635 | "2919 Failed to release resource extents " |
| 5636 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5637 | "Resource memory not released.\n", |
| 5638 | type, |
| 5639 | bf_get(lpfc_mbox_hdr_status, |
| 5640 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5641 | bf_get(lpfc_mbox_hdr_add_status, |
| 5642 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5643 | rc = -EIO; |
| 5644 | goto out_free_mbox; |
| 5645 | } |
| 5646 | |
| 5647 | /* Release kernel memory resources for the specific type. */ |
| 5648 | switch (type) { |
| 5649 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5650 | kfree(phba->vpi_bmask); |
| 5651 | kfree(phba->vpi_ids); |
| 5652 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5653 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5654 | &phba->lpfc_vpi_blk_list, list) { |
| 5655 | list_del_init(&rsrc_blk->list); |
| 5656 | kfree(rsrc_blk); |
| 5657 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5658 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5659 | break; |
| 5660 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5661 | kfree(phba->sli4_hba.xri_bmask); |
| 5662 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5663 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5664 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5665 | list_del_init(&rsrc_blk->list); |
| 5666 | kfree(rsrc_blk); |
| 5667 | } |
| 5668 | break; |
| 5669 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5670 | kfree(phba->sli4_hba.vfi_bmask); |
| 5671 | kfree(phba->sli4_hba.vfi_ids); |
| 5672 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5673 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5674 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5675 | list_del_init(&rsrc_blk->list); |
| 5676 | kfree(rsrc_blk); |
| 5677 | } |
| 5678 | break; |
| 5679 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5680 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5681 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5682 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5683 | list_del_init(&rsrc_blk->list); |
| 5684 | kfree(rsrc_blk); |
| 5685 | } |
| 5686 | break; |
| 5687 | default: |
| 5688 | break; |
| 5689 | } |
| 5690 | |
| 5691 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5692 | |
| 5693 | out_free_mbox: |
| 5694 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5695 | return rc; |
| 5696 | } |
| 5697 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5698 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5699 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 5700 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5701 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5702 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5703 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5704 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 5705 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5706 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5707 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 5708 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5709 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5710 | switch (feature) { |
| 5711 | case LPFC_SET_UE_RECOVERY: |
| 5712 | bf_set(lpfc_mbx_set_feature_UER, |
| 5713 | &mbox->u.mqe.un.set_feature, 1); |
| 5714 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 5715 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5716 | break; |
| 5717 | case LPFC_SET_MDS_DIAGS: |
| 5718 | bf_set(lpfc_mbx_set_feature_mds, |
| 5719 | &mbox->u.mqe.un.set_feature, 1); |
| 5720 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
| 5721 | &mbox->u.mqe.un.set_feature, 0); |
| 5722 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 5723 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5724 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5725 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5726 | |
| 5727 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5730 | /** |
| 5731 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5732 | * @phba: Pointer to HBA context object. |
| 5733 | * |
| 5734 | * This function allocates all SLI4 resource identifiers. |
| 5735 | **/ |
| 5736 | int |
| 5737 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5738 | { |
| 5739 | int i, rc, error = 0; |
| 5740 | uint16_t count, base; |
| 5741 | unsigned long longs; |
| 5742 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5743 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5744 | 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] | 5745 | if (phba->sli4_hba.extents_in_use) { |
| 5746 | /* |
| 5747 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5748 | * resource extent count must be read and allocated before |
| 5749 | * provisioning the resource id arrays. |
| 5750 | */ |
| 5751 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5752 | LPFC_IDX_RSRC_RDY) { |
| 5753 | /* |
| 5754 | * Extent-based resources are set - the driver could |
| 5755 | * be in a port reset. Figure out if any corrective |
| 5756 | * actions need to be taken. |
| 5757 | */ |
| 5758 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5759 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5760 | if (rc != 0) |
| 5761 | error++; |
| 5762 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5763 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5764 | if (rc != 0) |
| 5765 | error++; |
| 5766 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5767 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5768 | if (rc != 0) |
| 5769 | error++; |
| 5770 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5771 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5772 | if (rc != 0) |
| 5773 | error++; |
| 5774 | |
| 5775 | /* |
| 5776 | * It's possible that the number of resources |
| 5777 | * provided to this port instance changed between |
| 5778 | * resets. Detect this condition and reallocate |
| 5779 | * resources. Otherwise, there is no action. |
| 5780 | */ |
| 5781 | if (error) { |
| 5782 | lpfc_printf_log(phba, KERN_INFO, |
| 5783 | LOG_MBOX | LOG_INIT, |
| 5784 | "2931 Detected extent resource " |
| 5785 | "change. Reallocating all " |
| 5786 | "extents.\n"); |
| 5787 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5788 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5789 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5790 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5791 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5792 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5793 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5794 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5795 | } else |
| 5796 | return 0; |
| 5797 | } |
| 5798 | |
| 5799 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5800 | if (unlikely(rc)) |
| 5801 | goto err_exit; |
| 5802 | |
| 5803 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5804 | if (unlikely(rc)) |
| 5805 | goto err_exit; |
| 5806 | |
| 5807 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5808 | if (unlikely(rc)) |
| 5809 | goto err_exit; |
| 5810 | |
| 5811 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5812 | if (unlikely(rc)) |
| 5813 | goto err_exit; |
| 5814 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5815 | LPFC_IDX_RSRC_RDY); |
| 5816 | return rc; |
| 5817 | } else { |
| 5818 | /* |
| 5819 | * The port does not support resource extents. The XRI, VPI, |
| 5820 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5821 | * Just allocate the bitmasks and provision the resource id |
| 5822 | * arrays. If a port reset is active, the resources don't |
| 5823 | * need any action - just exit. |
| 5824 | */ |
| 5825 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5826 | LPFC_IDX_RSRC_RDY) { |
| 5827 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5828 | lpfc_sli4_remove_rpis(phba); |
| 5829 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5830 | /* RPIs. */ |
| 5831 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5832 | if (count <= 0) { |
| 5833 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5834 | "3279 Invalid provisioning of " |
| 5835 | "rpi:%d\n", count); |
| 5836 | rc = -EINVAL; |
| 5837 | goto err_exit; |
| 5838 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5839 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5840 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5841 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5842 | sizeof(unsigned long), |
| 5843 | GFP_KERNEL); |
| 5844 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5845 | rc = -ENOMEM; |
| 5846 | goto err_exit; |
| 5847 | } |
| 5848 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5849 | sizeof(uint16_t), |
| 5850 | GFP_KERNEL); |
| 5851 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5852 | rc = -ENOMEM; |
| 5853 | goto free_rpi_bmask; |
| 5854 | } |
| 5855 | |
| 5856 | for (i = 0; i < count; i++) |
| 5857 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5858 | |
| 5859 | /* VPIs. */ |
| 5860 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5861 | if (count <= 0) { |
| 5862 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5863 | "3280 Invalid provisioning of " |
| 5864 | "vpi:%d\n", count); |
| 5865 | rc = -EINVAL; |
| 5866 | goto free_rpi_ids; |
| 5867 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5868 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5869 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5870 | phba->vpi_bmask = kzalloc(longs * |
| 5871 | sizeof(unsigned long), |
| 5872 | GFP_KERNEL); |
| 5873 | if (unlikely(!phba->vpi_bmask)) { |
| 5874 | rc = -ENOMEM; |
| 5875 | goto free_rpi_ids; |
| 5876 | } |
| 5877 | phba->vpi_ids = kzalloc(count * |
| 5878 | sizeof(uint16_t), |
| 5879 | GFP_KERNEL); |
| 5880 | if (unlikely(!phba->vpi_ids)) { |
| 5881 | rc = -ENOMEM; |
| 5882 | goto free_vpi_bmask; |
| 5883 | } |
| 5884 | |
| 5885 | for (i = 0; i < count; i++) |
| 5886 | phba->vpi_ids[i] = base + i; |
| 5887 | |
| 5888 | /* XRIs. */ |
| 5889 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5890 | if (count <= 0) { |
| 5891 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5892 | "3281 Invalid provisioning of " |
| 5893 | "xri:%d\n", count); |
| 5894 | rc = -EINVAL; |
| 5895 | goto free_vpi_ids; |
| 5896 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5897 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5898 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5899 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5900 | sizeof(unsigned long), |
| 5901 | GFP_KERNEL); |
| 5902 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5903 | rc = -ENOMEM; |
| 5904 | goto free_vpi_ids; |
| 5905 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5906 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5907 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5908 | sizeof(uint16_t), |
| 5909 | GFP_KERNEL); |
| 5910 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5911 | rc = -ENOMEM; |
| 5912 | goto free_xri_bmask; |
| 5913 | } |
| 5914 | |
| 5915 | for (i = 0; i < count; i++) |
| 5916 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5917 | |
| 5918 | /* VFIs. */ |
| 5919 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5920 | if (count <= 0) { |
| 5921 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5922 | "3282 Invalid provisioning of " |
| 5923 | "vfi:%d\n", count); |
| 5924 | rc = -EINVAL; |
| 5925 | goto free_xri_ids; |
| 5926 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5927 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5928 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5929 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5930 | sizeof(unsigned long), |
| 5931 | GFP_KERNEL); |
| 5932 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5933 | rc = -ENOMEM; |
| 5934 | goto free_xri_ids; |
| 5935 | } |
| 5936 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5937 | sizeof(uint16_t), |
| 5938 | GFP_KERNEL); |
| 5939 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5940 | rc = -ENOMEM; |
| 5941 | goto free_vfi_bmask; |
| 5942 | } |
| 5943 | |
| 5944 | for (i = 0; i < count; i++) |
| 5945 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5946 | |
| 5947 | /* |
| 5948 | * Mark all resources ready. An HBA reset doesn't need |
| 5949 | * to reset the initialization. |
| 5950 | */ |
| 5951 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5952 | LPFC_IDX_RSRC_RDY); |
| 5953 | return 0; |
| 5954 | } |
| 5955 | |
| 5956 | free_vfi_bmask: |
| 5957 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5958 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5959 | free_xri_ids: |
| 5960 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5961 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5962 | free_xri_bmask: |
| 5963 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5964 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5965 | free_vpi_ids: |
| 5966 | kfree(phba->vpi_ids); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5967 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5968 | free_vpi_bmask: |
| 5969 | kfree(phba->vpi_bmask); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5970 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5971 | free_rpi_ids: |
| 5972 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5973 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5974 | free_rpi_bmask: |
| 5975 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | c32462d | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 5976 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5977 | err_exit: |
| 5978 | return rc; |
| 5979 | } |
| 5980 | |
| 5981 | /** |
| 5982 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5983 | * @phba: Pointer to HBA context object. |
| 5984 | * |
| 5985 | * This function allocates the number of elements for the specified |
| 5986 | * resource type. |
| 5987 | **/ |
| 5988 | int |
| 5989 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5990 | { |
| 5991 | if (phba->sli4_hba.extents_in_use) { |
| 5992 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5993 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5994 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5995 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5996 | } else { |
| 5997 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5998 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5999 | kfree(phba->vpi_ids); |
| 6000 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6001 | kfree(phba->sli4_hba.xri_bmask); |
| 6002 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6003 | kfree(phba->sli4_hba.vfi_bmask); |
| 6004 | kfree(phba->sli4_hba.vfi_ids); |
| 6005 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6006 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6007 | } |
| 6008 | |
| 6009 | return 0; |
| 6010 | } |
| 6011 | |
| 6012 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6013 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6014 | * @phba: Pointer to HBA context object. |
| 6015 | * @type: The resource extent type. |
| 6016 | * @extnt_count: buffer to hold port extent count response |
| 6017 | * @extnt_size: buffer to hold port extent size response. |
| 6018 | * |
| 6019 | * This function calls the port to read the host allocated extents |
| 6020 | * for a particular type. |
| 6021 | **/ |
| 6022 | int |
| 6023 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6024 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6025 | { |
| 6026 | bool emb; |
| 6027 | int rc = 0; |
| 6028 | uint16_t curr_blks = 0; |
| 6029 | uint32_t req_len, emb_len; |
| 6030 | uint32_t alloc_len, mbox_tmo; |
| 6031 | struct list_head *blk_list_head; |
| 6032 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6033 | LPFC_MBOXQ_t *mbox; |
| 6034 | void *virtaddr = NULL; |
| 6035 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6036 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6037 | union lpfc_sli4_cfg_shdr *shdr; |
| 6038 | |
| 6039 | switch (type) { |
| 6040 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6041 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6042 | break; |
| 6043 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6044 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6045 | break; |
| 6046 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6047 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6048 | break; |
| 6049 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6050 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6051 | break; |
| 6052 | default: |
| 6053 | return -EIO; |
| 6054 | } |
| 6055 | |
| 6056 | /* Count the number of extents currently allocatd for this type. */ |
| 6057 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6058 | if (curr_blks == 0) { |
| 6059 | /* |
| 6060 | * The GET_ALLOCATED mailbox does not return the size, |
| 6061 | * just the count. The size should be just the size |
| 6062 | * stored in the current allocated block and all sizes |
| 6063 | * for an extent type are the same so set the return |
| 6064 | * value now. |
| 6065 | */ |
| 6066 | *extnt_size = rsrc_blk->rsrc_size; |
| 6067 | } |
| 6068 | curr_blks++; |
| 6069 | } |
| 6070 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6071 | /* |
| 6072 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6073 | * accounts for extents-specific word. |
| 6074 | */ |
| 6075 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6076 | sizeof(uint32_t); |
| 6077 | |
| 6078 | /* |
| 6079 | * Presume the allocation and response will fit into an embedded |
| 6080 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6081 | */ |
| 6082 | emb = LPFC_SLI4_MBX_EMBED; |
| 6083 | req_len = emb_len; |
| 6084 | if (req_len > emb_len) { |
| 6085 | req_len = curr_blks * sizeof(uint16_t) + |
| 6086 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6087 | sizeof(uint32_t); |
| 6088 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6089 | } |
| 6090 | |
| 6091 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6092 | if (!mbox) |
| 6093 | return -ENOMEM; |
| 6094 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6095 | |
| 6096 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6097 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6098 | req_len, emb); |
| 6099 | if (alloc_len < req_len) { |
| 6100 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6101 | "2983 Allocated DMA memory size (x%x) is " |
| 6102 | "less than the requested DMA memory " |
| 6103 | "size (x%x)\n", alloc_len, req_len); |
| 6104 | rc = -ENOMEM; |
| 6105 | goto err_exit; |
| 6106 | } |
| 6107 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6108 | if (unlikely(rc)) { |
| 6109 | rc = -EIO; |
| 6110 | goto err_exit; |
| 6111 | } |
| 6112 | |
| 6113 | if (!phba->sli4_hba.intr_enable) |
| 6114 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6115 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6116 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6117 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6118 | } |
| 6119 | |
| 6120 | if (unlikely(rc)) { |
| 6121 | rc = -EIO; |
| 6122 | goto err_exit; |
| 6123 | } |
| 6124 | |
| 6125 | /* |
| 6126 | * Figure out where the response is located. Then get local pointers |
| 6127 | * to the response data. The port does not guarantee to respond to |
| 6128 | * all extents counts request so update the local variable with the |
| 6129 | * allocated count from the port. |
| 6130 | */ |
| 6131 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6132 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6133 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6134 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6135 | } else { |
| 6136 | virtaddr = mbox->sge_array->addr[0]; |
| 6137 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6138 | shdr = &n_rsrc->cfg_shdr; |
| 6139 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6140 | } |
| 6141 | |
| 6142 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6143 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6144 | "2984 Failed to read allocated resources " |
| 6145 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6146 | type, |
| 6147 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6148 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6149 | rc = -EIO; |
| 6150 | goto err_exit; |
| 6151 | } |
| 6152 | err_exit: |
| 6153 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6154 | return rc; |
| 6155 | } |
| 6156 | |
| 6157 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6158 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 6159 | * @phba: pointer to lpfc hba data structure. |
| 6160 | * |
| 6161 | * This routine walks the list of els buffers that have been allocated and |
| 6162 | * repost them to the port by using SGL block post. This is needed after a |
| 6163 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 6164 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 6165 | * SGL block post mailbox commands to post them to the port. For single els |
| 6166 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6167 | * mailbox command for posting. |
| 6168 | * |
| 6169 | * Returns: 0 = success, non-zero failure. |
| 6170 | **/ |
| 6171 | static int |
| 6172 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 6173 | { |
| 6174 | struct lpfc_sglq *sglq_entry = NULL; |
| 6175 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6176 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6177 | 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] | 6178 | int last_xritag = NO_XRI; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6179 | struct lpfc_sli_ring *pring; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6180 | LIST_HEAD(prep_sgl_list); |
| 6181 | LIST_HEAD(blck_sgl_list); |
| 6182 | LIST_HEAD(allc_sgl_list); |
| 6183 | LIST_HEAD(post_sgl_list); |
| 6184 | LIST_HEAD(free_sgl_list); |
| 6185 | |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6186 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6187 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6188 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6189 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6190 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6191 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6192 | |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6193 | total_cnt = phba->sli4_hba.els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6194 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6195 | &allc_sgl_list, list) { |
| 6196 | list_del_init(&sglq_entry->list); |
| 6197 | block_cnt++; |
| 6198 | if ((last_xritag != NO_XRI) && |
| 6199 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6200 | /* a hole in xri block, form a sgl posting block */ |
| 6201 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6202 | post_cnt = block_cnt - 1; |
| 6203 | /* prepare list for next posting block */ |
| 6204 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6205 | block_cnt = 1; |
| 6206 | } else { |
| 6207 | /* prepare list for next posting block */ |
| 6208 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6209 | /* enough sgls for non-embed sgl mbox command */ |
| 6210 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6211 | list_splice_init(&prep_sgl_list, |
| 6212 | &blck_sgl_list); |
| 6213 | post_cnt = block_cnt; |
| 6214 | block_cnt = 0; |
| 6215 | } |
| 6216 | } |
| 6217 | num_posted++; |
| 6218 | |
| 6219 | /* keep track of last sgl's xritag */ |
| 6220 | last_xritag = sglq_entry->sli4_xritag; |
| 6221 | |
| 6222 | /* end of repost sgl list condition for els buffers */ |
| 6223 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 6224 | if (post_cnt == 0) { |
| 6225 | list_splice_init(&prep_sgl_list, |
| 6226 | &blck_sgl_list); |
| 6227 | post_cnt = block_cnt; |
| 6228 | } else if (block_cnt == 1) { |
| 6229 | status = lpfc_sli4_post_sgl(phba, |
| 6230 | sglq_entry->phys, 0, |
| 6231 | sglq_entry->sli4_xritag); |
| 6232 | if (!status) { |
| 6233 | /* successful, put sgl to posted list */ |
| 6234 | list_add_tail(&sglq_entry->list, |
| 6235 | &post_sgl_list); |
| 6236 | } else { |
| 6237 | /* Failure, put sgl to free list */ |
| 6238 | lpfc_printf_log(phba, KERN_WARNING, |
| 6239 | LOG_SLI, |
| 6240 | "3159 Failed to post els " |
| 6241 | "sgl, xritag:x%x\n", |
| 6242 | sglq_entry->sli4_xritag); |
| 6243 | list_add_tail(&sglq_entry->list, |
| 6244 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6245 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6246 | } |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | /* continue until a nembed page worth of sgls */ |
| 6251 | if (post_cnt == 0) |
| 6252 | continue; |
| 6253 | |
| 6254 | /* post the els buffer list sgls as a block */ |
| 6255 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6256 | post_cnt); |
| 6257 | |
| 6258 | if (!status) { |
| 6259 | /* success, put sgl list to posted sgl list */ |
| 6260 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6261 | } else { |
| 6262 | /* Failure, put sgl list to free sgl list */ |
| 6263 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6264 | struct lpfc_sglq, |
| 6265 | list); |
| 6266 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6267 | "3160 Failed to post els sgl-list, " |
| 6268 | "xritag:x%x-x%x\n", |
| 6269 | sglq_entry_first->sli4_xritag, |
| 6270 | (sglq_entry_first->sli4_xritag + |
| 6271 | post_cnt - 1)); |
| 6272 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6273 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | /* don't reset xirtag due to hole in xri block */ |
| 6277 | if (block_cnt == 0) |
| 6278 | last_xritag = NO_XRI; |
| 6279 | |
| 6280 | /* reset els sgl post count for next round of posting */ |
| 6281 | post_cnt = 0; |
| 6282 | } |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6283 | /* update the number of XRIs posted for ELS */ |
| 6284 | phba->sli4_hba.els_xri_cnt = total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6285 | |
| 6286 | /* free the els sgls failed to post */ |
| 6287 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6288 | |
| 6289 | /* push els sgls posted to the availble list */ |
| 6290 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6291 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6292 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6293 | list_splice_init(&post_sgl_list, |
| 6294 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 6295 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6296 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6297 | } else { |
| 6298 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6299 | "3161 Failure to post els sgl to port.\n"); |
| 6300 | return -EIO; |
| 6301 | } |
| 6302 | return 0; |
| 6303 | } |
| 6304 | |
| 6305 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6306 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6307 | * @phba: Pointer to HBA context object. |
| 6308 | * |
| 6309 | * This function is the main SLI4 device intialization PCI function. This |
| 6310 | * function is called by the HBA intialization code, HBA reset code and |
| 6311 | * HBA error attention handler code. Caller is not required to hold any |
| 6312 | * locks. |
| 6313 | **/ |
| 6314 | int |
| 6315 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6316 | { |
| 6317 | int rc; |
| 6318 | LPFC_MBOXQ_t *mboxq; |
| 6319 | struct lpfc_mqe *mqe; |
| 6320 | uint8_t *vpd; |
| 6321 | uint32_t vpd_size; |
| 6322 | uint32_t ftr_rsp = 0; |
| 6323 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6324 | struct lpfc_vport *vport = phba->pport; |
| 6325 | struct lpfc_dmabuf *mp; |
| 6326 | |
| 6327 | /* Perform a PCI function reset to start from clean */ |
| 6328 | rc = lpfc_pci_function_reset(phba); |
| 6329 | if (unlikely(rc)) |
| 6330 | return -ENODEV; |
| 6331 | |
| 6332 | /* Check the HBA Host Status Register for readyness */ |
| 6333 | rc = lpfc_sli4_post_status_check(phba); |
| 6334 | if (unlikely(rc)) |
| 6335 | return -ENODEV; |
| 6336 | else { |
| 6337 | spin_lock_irq(&phba->hbalock); |
| 6338 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6339 | spin_unlock_irq(&phba->hbalock); |
| 6340 | } |
| 6341 | |
| 6342 | /* |
| 6343 | * Allocate a single mailbox container for initializing the |
| 6344 | * port. |
| 6345 | */ |
| 6346 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6347 | if (!mboxq) |
| 6348 | return -ENOMEM; |
| 6349 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6350 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6351 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6352 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6353 | if (!vpd) { |
| 6354 | rc = -ENOMEM; |
| 6355 | goto out_free_mbox; |
| 6356 | } |
| 6357 | |
| 6358 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6359 | if (unlikely(rc)) { |
| 6360 | kfree(vpd); |
| 6361 | goto out_free_mbox; |
| 6362 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6363 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6364 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6365 | 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] | 6366 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6367 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6368 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6369 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6370 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6371 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6372 | |
| 6373 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6374 | LPFC_DCBX_CEE_MODE) |
| 6375 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6376 | else |
| 6377 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6378 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6379 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6380 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6381 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6382 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6383 | "0376 READ_REV Error. SLI Level %d " |
| 6384 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6385 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6386 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6387 | kfree(vpd); |
| 6388 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6389 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6390 | |
| 6391 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6392 | * Continue initialization with default values even if driver failed |
| 6393 | * to read FCoE param config regions, only read parameters if the |
| 6394 | * board is FCoE |
| 6395 | */ |
| 6396 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6397 | lpfc_sli4_read_fcoe_params(phba)) |
| 6398 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6399 | "2570 Failed to read FCoE parameters\n"); |
| 6400 | |
| 6401 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6402 | * Retrieve sli4 device physical port name, failure of doing it |
| 6403 | * is considered as non-fatal. |
| 6404 | */ |
| 6405 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6406 | if (!rc) |
| 6407 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6408 | "3080 Successful retrieving SLI4 device " |
| 6409 | "physical port name: %s.\n", phba->Port); |
| 6410 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6411 | /* |
| 6412 | * Evaluate the read rev and vpd data. Populate the driver |
| 6413 | * state with the results. If this routine fails, the failure |
| 6414 | * is not fatal as the driver will use generic values. |
| 6415 | */ |
| 6416 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6417 | if (unlikely(!rc)) { |
| 6418 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6419 | "0377 Error %d parsing vpd. " |
| 6420 | "Using defaults.\n", rc); |
| 6421 | rc = 0; |
| 6422 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6423 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6424 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6425 | /* Save information as VPD data */ |
| 6426 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6427 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6428 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6429 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6430 | &mqe->un.read_rev); |
| 6431 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6432 | &mqe->un.read_rev); |
| 6433 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6434 | &mqe->un.read_rev); |
| 6435 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6436 | &mqe->un.read_rev); |
| 6437 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6438 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6439 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6440 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6441 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6442 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6443 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6444 | "(%d):0380 READ_REV Status x%x " |
| 6445 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6446 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6447 | bf_get(lpfc_mqe_status, mqe), |
| 6448 | phba->vpd.rev.opFwName, |
| 6449 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6450 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6451 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6452 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6453 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6454 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6455 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6456 | "3362 LUN queue depth changed from %d to %d\n", |
| 6457 | phba->pport->cfg_lun_queue_depth, rc); |
| 6458 | phba->pport->cfg_lun_queue_depth = rc; |
| 6459 | } |
| 6460 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6461 | 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] | 6462 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6463 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6464 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6465 | if (rc == MBX_SUCCESS) { |
| 6466 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6467 | /* Set 1Sec interval to detect UE */ |
| 6468 | phba->eratt_poll_interval = 1; |
| 6469 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6470 | lpfc_mbx_set_feature_UESR, |
| 6471 | &mboxq->u.mqe.un.set_feature); |
| 6472 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6473 | lpfc_mbx_set_feature_UERP, |
| 6474 | &mboxq->u.mqe.un.set_feature); |
| 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6479 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6480 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6481 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6482 | if (rc != MBX_SUCCESS) |
| 6483 | phba->mds_diags_support = 0; |
| 6484 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6485 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6486 | /* |
| 6487 | * Discover the port's supported feature set and match it against the |
| 6488 | * hosts requests. |
| 6489 | */ |
| 6490 | lpfc_request_features(phba, mboxq); |
| 6491 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6492 | if (unlikely(rc)) { |
| 6493 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6494 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6495 | } |
| 6496 | |
| 6497 | /* |
| 6498 | * The port must support FCP initiator mode as this is the |
| 6499 | * only mode running in the host. |
| 6500 | */ |
| 6501 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6502 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6503 | "0378 No support for fcpi mode.\n"); |
| 6504 | ftr_rsp++; |
| 6505 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6506 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6507 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6508 | else |
| 6509 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6510 | /* |
| 6511 | * If the port cannot support the host's requested features |
| 6512 | * then turn off the global config parameters to disable the |
| 6513 | * feature in the driver. This is not a fatal error. |
| 6514 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6515 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6516 | if (phba->cfg_enable_bg) { |
| 6517 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6518 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6519 | else |
| 6520 | ftr_rsp++; |
| 6521 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6522 | |
| 6523 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6524 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6525 | ftr_rsp++; |
| 6526 | |
| 6527 | if (ftr_rsp) { |
| 6528 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6529 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6530 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6531 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6532 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6533 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6534 | phba->cfg_enable_bg = 0; |
| 6535 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6536 | phba->cfg_enable_npiv = 0; |
| 6537 | } |
| 6538 | |
| 6539 | /* These SLI3 features are assumed in SLI4 */ |
| 6540 | spin_lock_irq(&phba->hbalock); |
| 6541 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6542 | spin_unlock_irq(&phba->hbalock); |
| 6543 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6544 | /* |
| 6545 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6546 | * calls depends on these resources to complete port setup. |
| 6547 | */ |
| 6548 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6549 | if (rc) { |
| 6550 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6551 | "2920 Failed to alloc Resource IDs " |
| 6552 | "rc = x%x\n", rc); |
| 6553 | goto out_free_mbox; |
| 6554 | } |
| 6555 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6556 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6557 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6558 | if (rc) { |
| 6559 | phba->link_state = LPFC_HBA_ERROR; |
| 6560 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6561 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6562 | } |
| 6563 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6564 | mboxq->vport = vport; |
| 6565 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6566 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6567 | if (rc == MBX_SUCCESS) { |
| 6568 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6569 | rc = 0; |
| 6570 | } |
| 6571 | |
| 6572 | /* |
| 6573 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6574 | * it to the mbuf pool. |
| 6575 | */ |
| 6576 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6577 | kfree(mp); |
| 6578 | mboxq->context1 = NULL; |
| 6579 | if (unlikely(rc)) { |
| 6580 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6581 | "0382 READ_SPARAM command failed " |
| 6582 | "status %d, mbxStatus x%x\n", |
| 6583 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6584 | phba->link_state = LPFC_HBA_ERROR; |
| 6585 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6586 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6587 | } |
| 6588 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6589 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6590 | |
| 6591 | /* Update the fc_host data structures with new wwn. */ |
| 6592 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6593 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6594 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6595 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6596 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6597 | if (unlikely(rc)) { |
| 6598 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6599 | "1400 Failed to update xri-sgl size and " |
| 6600 | "mapping: %d\n", rc); |
| 6601 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6602 | } |
| 6603 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6604 | /* register the els sgl pool to the port */ |
| 6605 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6606 | if (unlikely(rc)) { |
| 6607 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6608 | "0582 Error %d during els sgl post " |
| 6609 | "operation\n", rc); |
| 6610 | rc = -ENODEV; |
| 6611 | goto out_free_mbox; |
| 6612 | } |
| 6613 | |
| 6614 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6615 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6616 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6617 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6618 | "0383 Error %d during scsi sgl post " |
| 6619 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6620 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6621 | /* A pci function reset will repost them */ |
| 6622 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6623 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | /* Post the rpi header region to the device. */ |
| 6627 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6628 | if (unlikely(rc)) { |
| 6629 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6630 | "0393 Error %d during rpi post operation\n", |
| 6631 | rc); |
| 6632 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6633 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6634 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6635 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6636 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6637 | /* Create all the SLI4 queues */ |
| 6638 | rc = lpfc_sli4_queue_create(phba); |
| 6639 | if (rc) { |
| 6640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6641 | "3089 Failed to allocate queues\n"); |
| 6642 | rc = -ENODEV; |
| 6643 | goto out_stop_timers; |
| 6644 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6645 | /* Set up all the queues to the device */ |
| 6646 | rc = lpfc_sli4_queue_setup(phba); |
| 6647 | if (unlikely(rc)) { |
| 6648 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6649 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6650 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | /* Arm the CQs and then EQs on device */ |
| 6654 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6655 | |
| 6656 | /* Indicate device interrupt mode */ |
| 6657 | phba->sli4_hba.intr_enable = 1; |
| 6658 | |
| 6659 | /* Allow asynchronous mailbox command to go through */ |
| 6660 | spin_lock_irq(&phba->hbalock); |
| 6661 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6662 | spin_unlock_irq(&phba->hbalock); |
| 6663 | |
| 6664 | /* Post receive buffers to the device */ |
| 6665 | lpfc_sli4_rb_setup(phba); |
| 6666 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6667 | /* Reset HBA FCF states after HBA reset */ |
| 6668 | phba->fcf.fcf_flag = 0; |
| 6669 | phba->fcf.current_rec.flag = 0; |
| 6670 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6671 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6672 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6673 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6674 | |
| 6675 | /* Start heart beat timer */ |
| 6676 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6677 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6678 | phba->hb_outstanding = 0; |
| 6679 | phba->last_completion_time = jiffies; |
| 6680 | |
| 6681 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6682 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6683 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6684 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6685 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6686 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6687 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6688 | if (!rc) { |
| 6689 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6690 | "2829 This device supports " |
| 6691 | "Advanced Error Reporting (AER)\n"); |
| 6692 | spin_lock_irq(&phba->hbalock); |
| 6693 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6694 | spin_unlock_irq(&phba->hbalock); |
| 6695 | } else { |
| 6696 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6697 | "2830 This device does not support " |
| 6698 | "Advanced Error Reporting (AER)\n"); |
| 6699 | phba->cfg_aer_support = 0; |
| 6700 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6701 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6702 | } |
| 6703 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6704 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6705 | /* |
| 6706 | * The FC Port needs to register FCFI (index 0) |
| 6707 | */ |
| 6708 | lpfc_reg_fcfi(phba, mboxq); |
| 6709 | mboxq->vport = phba->pport; |
| 6710 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6711 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6712 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6713 | rc = 0; |
| 6714 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6715 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6716 | |
| 6717 | /* Check if the port is configured to be disabled */ |
| 6718 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6719 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6720 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6721 | /* |
| 6722 | * The port is ready, set the host's link state to LINK_DOWN |
| 6723 | * in preparation for link interrupts. |
| 6724 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6725 | spin_lock_irq(&phba->hbalock); |
| 6726 | phba->link_state = LPFC_LINK_DOWN; |
| 6727 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6728 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6729 | (phba->hba_flag & LINK_DISABLED)) { |
| 6730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6731 | "3103 Adapter Link is disabled.\n"); |
| 6732 | lpfc_down_link(phba, mboxq); |
| 6733 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6734 | if (rc != MBX_SUCCESS) { |
| 6735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6736 | "3104 Adapter failed to issue " |
| 6737 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6738 | goto out_unset_queue; |
| 6739 | } |
| 6740 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6741 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6742 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6743 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6744 | if (rc) |
| 6745 | goto out_unset_queue; |
| 6746 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6747 | } |
| 6748 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6749 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6750 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6751 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6752 | lpfc_sli4_queue_unset(phba); |
| 6753 | out_destroy_queue: |
| 6754 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6755 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6756 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6757 | out_free_mbox: |
| 6758 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6759 | return rc; |
| 6760 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6761 | |
| 6762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6763 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6764 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6765 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6766 | * This is the callback function for mailbox timer. The mailbox |
| 6767 | * timer is armed when a new mailbox command is issued and the timer |
| 6768 | * is deleted when the mailbox complete. The function is called by |
| 6769 | * the kernel timer code when a mailbox does not complete within |
| 6770 | * expected time. This function wakes up the worker thread to |
| 6771 | * process the mailbox timeout and returns. All the processing is |
| 6772 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6773 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6774 | void |
| 6775 | lpfc_mbox_timeout(unsigned long ptr) |
| 6776 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6777 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6778 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6779 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6780 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6781 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6782 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6783 | if (!tmo_posted) |
| 6784 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6785 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6786 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6787 | if (!tmo_posted) |
| 6788 | lpfc_worker_wake_up(phba); |
| 6789 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6790 | } |
| 6791 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6792 | /** |
| 6793 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 6794 | * are pending |
| 6795 | * @phba: Pointer to HBA context object. |
| 6796 | * |
| 6797 | * This function checks if any mailbox completions are present on the mailbox |
| 6798 | * completion queue. |
| 6799 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 6800 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6801 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 6802 | { |
| 6803 | |
| 6804 | uint32_t idx; |
| 6805 | struct lpfc_queue *mcq; |
| 6806 | struct lpfc_mcqe *mcqe; |
| 6807 | bool pending_completions = false; |
| 6808 | |
| 6809 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6810 | return false; |
| 6811 | |
| 6812 | /* Check for completions on mailbox completion queue */ |
| 6813 | |
| 6814 | mcq = phba->sli4_hba.mbx_cq; |
| 6815 | idx = mcq->hba_index; |
| 6816 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 6817 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 6818 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 6819 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 6820 | pending_completions = true; |
| 6821 | break; |
| 6822 | } |
| 6823 | idx = (idx + 1) % mcq->entry_count; |
| 6824 | if (mcq->hba_index == idx) |
| 6825 | break; |
| 6826 | } |
| 6827 | return pending_completions; |
| 6828 | |
| 6829 | } |
| 6830 | |
| 6831 | /** |
| 6832 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 6833 | * that were missed. |
| 6834 | * @phba: Pointer to HBA context object. |
| 6835 | * |
| 6836 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 6837 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 6838 | * checks to see if mbox completions are on the mailbox completion queue |
| 6839 | * and will process all the completions associated with the eq for the |
| 6840 | * mailbox completion queue. |
| 6841 | **/ |
| 6842 | bool |
| 6843 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 6844 | { |
| 6845 | |
| 6846 | uint32_t eqidx; |
| 6847 | struct lpfc_queue *fpeq = NULL; |
| 6848 | struct lpfc_eqe *eqe; |
| 6849 | bool mbox_pending; |
| 6850 | |
| 6851 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6852 | return false; |
| 6853 | |
| 6854 | /* Find the eq associated with the mcq */ |
| 6855 | |
| 6856 | if (phba->sli4_hba.hba_eq) |
| 6857 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) |
| 6858 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 6859 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 6860 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 6861 | break; |
| 6862 | } |
| 6863 | if (!fpeq) |
| 6864 | return false; |
| 6865 | |
| 6866 | /* Turn off interrupts from this EQ */ |
| 6867 | |
| 6868 | lpfc_sli4_eq_clr_intr(fpeq); |
| 6869 | |
| 6870 | /* Check to see if a mbox completion is pending */ |
| 6871 | |
| 6872 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 6873 | |
| 6874 | /* |
| 6875 | * If a mbox completion is pending, process all the events on EQ |
| 6876 | * associated with the mbox completion queue (this could include |
| 6877 | * mailbox commands, async events, els commands, receive queue data |
| 6878 | * and fcp commands) |
| 6879 | */ |
| 6880 | |
| 6881 | if (mbox_pending) |
| 6882 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 6883 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 6884 | fpeq->EQ_processed++; |
| 6885 | } |
| 6886 | |
| 6887 | /* Always clear and re-arm the EQ */ |
| 6888 | |
| 6889 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 6890 | |
| 6891 | return mbox_pending; |
| 6892 | |
| 6893 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6894 | |
| 6895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6896 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6897 | * @phba: Pointer to HBA context object. |
| 6898 | * |
| 6899 | * This function is called from worker thread when a mailbox command times out. |
| 6900 | * The caller is not required to hold any locks. This function will reset the |
| 6901 | * HBA and recover all the pending commands. |
| 6902 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6903 | void |
| 6904 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6905 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6906 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6907 | MAILBOX_t *mb = NULL; |
| 6908 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6909 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6910 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6911 | /* If the mailbox completed, process the completion and return */ |
| 6912 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 6913 | return; |
| 6914 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 6915 | if (pmbox != NULL) |
| 6916 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6917 | /* Check the pmbox pointer first. There is a race condition |
| 6918 | * between the mbox timeout handler getting executed in the |
| 6919 | * worklist and the mailbox actually completing. When this |
| 6920 | * race condition occurs, the mbox_active will be NULL. |
| 6921 | */ |
| 6922 | spin_lock_irq(&phba->hbalock); |
| 6923 | if (pmbox == NULL) { |
| 6924 | lpfc_printf_log(phba, KERN_WARNING, |
| 6925 | LOG_MBOX | LOG_SLI, |
| 6926 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6927 | "exiting\n"); |
| 6928 | spin_unlock_irq(&phba->hbalock); |
| 6929 | return; |
| 6930 | } |
| 6931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6932 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6933 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6934 | "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] | 6935 | mb->mbxCommand, |
| 6936 | phba->pport->port_state, |
| 6937 | phba->sli.sli_flag, |
| 6938 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6939 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6940 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6941 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6942 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6943 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6944 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6945 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6946 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6947 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6948 | spin_lock_irq(&phba->hbalock); |
| 6949 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6950 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6951 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6952 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 6953 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6954 | |
| 6955 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6956 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6957 | |
| 6958 | /* Reset the HBA device */ |
| 6959 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6960 | } |
| 6961 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6962 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6963 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6964 | * @phba: Pointer to HBA context object. |
| 6965 | * @pmbox: Pointer to mailbox object. |
| 6966 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6967 | * |
| 6968 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6969 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6970 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6971 | * The mailbox command can be submitted in polling mode, in which case |
| 6972 | * this function will wait in a polling loop for the completion of the |
| 6973 | * mailbox. |
| 6974 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6975 | * function will submit the command and returns immediately without waiting |
| 6976 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6977 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6978 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6979 | * mailbox is issued in polling mode and there is already a mailbox |
| 6980 | * pending, then the function will return an error. If the mailbox is issued |
| 6981 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6982 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6983 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6984 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6985 | * return codes the caller owns the mailbox command after the return of |
| 6986 | * the function. |
| 6987 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6988 | static int |
| 6989 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6990 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6991 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6992 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6993 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6994 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6995 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6996 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6997 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6998 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6999 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7000 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7001 | int processing_queue = 0; |
| 7002 | |
| 7003 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7004 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7005 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7006 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7007 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7008 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7009 | return MBX_SUCCESS; |
| 7010 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7011 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7012 | pmbox = lpfc_mbox_get(phba); |
| 7013 | if (!pmbox) { |
| 7014 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7015 | return MBX_SUCCESS; |
| 7016 | } |
| 7017 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7018 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7019 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7020 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7021 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7022 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7023 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7024 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7025 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7026 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7027 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7028 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7029 | } |
| 7030 | } |
| 7031 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7032 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7033 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7034 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7035 | goto out_not_finished; |
| 7036 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7037 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7038 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7039 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7040 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7041 | goto out_not_finished; |
| 7042 | } |
| 7043 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7044 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7045 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7046 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7047 | status = MBX_SUCCESS; |
| 7048 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7049 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7050 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7051 | |
| 7052 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7053 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7054 | "(%d):0311 Mailbox command x%x cannot " |
| 7055 | "issue Data: x%x x%x\n", |
| 7056 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7057 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7058 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7059 | } |
| 7060 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7061 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7062 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7063 | !(hc_copy & HC_MBINT_ENA)) { |
| 7064 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7065 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7066 | "(%d):2528 Mailbox command x%x cannot " |
| 7067 | "issue Data: x%x x%x\n", |
| 7068 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7069 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7070 | goto out_not_finished; |
| 7071 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7072 | } |
| 7073 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7074 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7075 | /* Polling for a mbox command when another one is already active |
| 7076 | * is not allowed in SLI. Also, the driver must have established |
| 7077 | * SLI2 mode to queue and process multiple mbox commands. |
| 7078 | */ |
| 7079 | |
| 7080 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7081 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7082 | |
| 7083 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7084 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7085 | "(%d):2529 Mailbox command x%x " |
| 7086 | "cannot issue Data: x%x x%x\n", |
| 7087 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7088 | pmbox->u.mb.mbxCommand, |
| 7089 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7090 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7091 | } |
| 7092 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7093 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7094 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7095 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7096 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7097 | "(%d):2530 Mailbox command x%x " |
| 7098 | "cannot issue Data: x%x x%x\n", |
| 7099 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7100 | pmbox->u.mb.mbxCommand, |
| 7101 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7102 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7103 | } |
| 7104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7105 | /* Another mailbox command is still being processed, queue this |
| 7106 | * command to be processed later. |
| 7107 | */ |
| 7108 | lpfc_mbox_put(phba, pmbox); |
| 7109 | |
| 7110 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7111 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7112 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7113 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7114 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7115 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7116 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7117 | |
| 7118 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7119 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7120 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7121 | if (pmbox->vport) { |
| 7122 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7123 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7124 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7125 | (uint32_t)mbx->mbxCommand, |
| 7126 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7127 | } |
| 7128 | else { |
| 7129 | lpfc_debugfs_disc_trc(phba->pport, |
| 7130 | LPFC_DISC_TRC_MBOX, |
| 7131 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7132 | (uint32_t)mbx->mbxCommand, |
| 7133 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7134 | } |
| 7135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7136 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7137 | } |
| 7138 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7139 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7140 | |
| 7141 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7142 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7143 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7144 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7145 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7146 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7147 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7148 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7149 | "(%d):2531 Mailbox command x%x " |
| 7150 | "cannot issue Data: x%x x%x\n", |
| 7151 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7152 | pmbox->u.mb.mbxCommand, |
| 7153 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7154 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7155 | } |
| 7156 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7157 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7158 | 1000); |
| 7159 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7163 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7164 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7165 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7166 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7167 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7168 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7169 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7170 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7171 | if (pmbox->vport) { |
| 7172 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7173 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7174 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7175 | (uint32_t)mbx->mbxCommand, |
| 7176 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7177 | } |
| 7178 | else { |
| 7179 | lpfc_debugfs_disc_trc(phba->pport, |
| 7180 | LPFC_DISC_TRC_MBOX, |
| 7181 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7182 | (uint32_t)mbx->mbxCommand, |
| 7183 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7184 | } |
| 7185 | } |
| 7186 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7187 | psli->slistat.mbox_cmd++; |
| 7188 | evtctr = psli->slistat.mbox_event; |
| 7189 | |
| 7190 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7191 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7192 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7193 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7194 | /* Populate mbox extension offset word. */ |
| 7195 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7196 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7197 | = (uint8_t *)phba->mbox_ext |
| 7198 | - (uint8_t *)phba->mbox; |
| 7199 | } |
| 7200 | |
| 7201 | /* Copy the mailbox extension data */ |
| 7202 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7203 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7204 | (uint8_t *)phba->mbox_ext, |
| 7205 | pmbox->in_ext_byte_len); |
| 7206 | } |
| 7207 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7208 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7209 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7210 | /* Populate mbox extension offset word. */ |
| 7211 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7212 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7213 | = MAILBOX_HBA_EXT_OFFSET; |
| 7214 | |
| 7215 | /* Copy the mailbox extension data */ |
| 7216 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7217 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7218 | MAILBOX_HBA_EXT_OFFSET, |
| 7219 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7220 | |
| 7221 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7222 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7223 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7224 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7228 | word */ |
| 7229 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7230 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7231 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7232 | |
| 7233 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7234 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7235 | to_slim = phba->MBslimaddr; |
| 7236 | writel(ldata, to_slim); |
| 7237 | readl(to_slim); /* flush */ |
| 7238 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7239 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7240 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7241 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7246 | |
| 7247 | switch (flag) { |
| 7248 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7249 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7250 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7251 | /* Interrupt board to do it */ |
| 7252 | writel(CA_MBATT, phba->CAregaddr); |
| 7253 | readl(phba->CAregaddr); /* flush */ |
| 7254 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7255 | break; |
| 7256 | |
| 7257 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7258 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7259 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7260 | /* Interrupt board to do it */ |
| 7261 | writel(CA_MBATT, phba->CAregaddr); |
| 7262 | readl(phba->CAregaddr); /* flush */ |
| 7263 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7264 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7265 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7266 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7267 | word0 = le32_to_cpu(word0); |
| 7268 | } else { |
| 7269 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7270 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7271 | spin_unlock_irqrestore(&phba->hbalock, |
| 7272 | drvr_flag); |
| 7273 | goto out_not_finished; |
| 7274 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7275 | } |
| 7276 | |
| 7277 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7278 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7279 | spin_unlock_irqrestore(&phba->hbalock, |
| 7280 | drvr_flag); |
| 7281 | goto out_not_finished; |
| 7282 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7283 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7284 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7285 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7286 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7287 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7288 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7289 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7290 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7291 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7292 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7293 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7294 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7295 | } |
| 7296 | |
| 7297 | /* Check if we took a mbox interrupt while we were |
| 7298 | polling */ |
| 7299 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7300 | && (evtctr != psli->slistat.mbox_event)) |
| 7301 | break; |
| 7302 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7303 | if (i++ > 10) { |
| 7304 | spin_unlock_irqrestore(&phba->hbalock, |
| 7305 | drvr_flag); |
| 7306 | msleep(1); |
| 7307 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7308 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7309 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7310 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7311 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7312 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7313 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7314 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7315 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7316 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7317 | /* Check real SLIM for any errors */ |
| 7318 | slimword0 = readl(phba->MBslimaddr); |
| 7319 | slimmb = (MAILBOX_t *) & slimword0; |
| 7320 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7321 | && slimmb->mbxStatus) { |
| 7322 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7323 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7324 | word0 = slimword0; |
| 7325 | } |
| 7326 | } |
| 7327 | } else { |
| 7328 | /* First copy command data */ |
| 7329 | word0 = readl(phba->MBslimaddr); |
| 7330 | } |
| 7331 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7332 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7333 | spin_unlock_irqrestore(&phba->hbalock, |
| 7334 | drvr_flag); |
| 7335 | goto out_not_finished; |
| 7336 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7337 | } |
| 7338 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7339 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7340 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7341 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7342 | /* Copy the mailbox extension data */ |
| 7343 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7344 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7345 | pmbox->context2, |
| 7346 | pmbox->out_ext_byte_len); |
| 7347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7348 | } else { |
| 7349 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7350 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7351 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7352 | /* Copy the mailbox extension data */ |
| 7353 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7354 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7355 | phba->MBslimaddr + |
| 7356 | MAILBOX_HBA_EXT_OFFSET, |
| 7357 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7358 | } |
| 7359 | } |
| 7360 | |
| 7361 | writel(HA_MBATT, phba->HAregaddr); |
| 7362 | readl(phba->HAregaddr); /* flush */ |
| 7363 | |
| 7364 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7365 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7366 | } |
| 7367 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7368 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7369 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7370 | |
| 7371 | out_not_finished: |
| 7372 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7373 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7374 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7375 | } |
| 7376 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7377 | } |
| 7378 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7379 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7380 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7381 | * @phba: Pointer to HBA context object. |
| 7382 | * |
| 7383 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7384 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7385 | * possible outstanding mailbox command before return. |
| 7386 | * |
| 7387 | * Returns: |
| 7388 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7389 | * the outstanding mailbox command timed out. |
| 7390 | **/ |
| 7391 | static int |
| 7392 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7393 | { |
| 7394 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7395 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7396 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7397 | |
| 7398 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7399 | spin_lock_irq(&phba->hbalock); |
| 7400 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7401 | /* Determine how long we might wait for the active mailbox |
| 7402 | * command to be gracefully completed by firmware. |
| 7403 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7404 | if (phba->sli.mbox_active) |
| 7405 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7406 | phba->sli.mbox_active) * |
| 7407 | 1000) + jiffies; |
| 7408 | spin_unlock_irq(&phba->hbalock); |
| 7409 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7410 | /* Make sure the mailbox is really active */ |
| 7411 | if (timeout) |
| 7412 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7413 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7414 | /* Wait for the outstnading mailbox command to complete */ |
| 7415 | while (phba->sli.mbox_active) { |
| 7416 | /* Check active mailbox complete status every 2ms */ |
| 7417 | msleep(2); |
| 7418 | if (time_after(jiffies, timeout)) { |
| 7419 | /* Timeout, marked the outstanding cmd not complete */ |
| 7420 | rc = 1; |
| 7421 | break; |
| 7422 | } |
| 7423 | } |
| 7424 | |
| 7425 | /* Can not cleanly block async mailbox command, fails it */ |
| 7426 | if (rc) { |
| 7427 | spin_lock_irq(&phba->hbalock); |
| 7428 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7429 | spin_unlock_irq(&phba->hbalock); |
| 7430 | } |
| 7431 | return rc; |
| 7432 | } |
| 7433 | |
| 7434 | /** |
| 7435 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7436 | * @phba: Pointer to HBA context object. |
| 7437 | * |
| 7438 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7439 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7440 | * that there is no outstanding mailbox command before resuming posting |
| 7441 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7442 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7443 | * mailbox command posting. |
| 7444 | **/ |
| 7445 | static void |
| 7446 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7447 | { |
| 7448 | struct lpfc_sli *psli = &phba->sli; |
| 7449 | |
| 7450 | spin_lock_irq(&phba->hbalock); |
| 7451 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7452 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7453 | spin_unlock_irq(&phba->hbalock); |
| 7454 | return; |
| 7455 | } |
| 7456 | |
| 7457 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7458 | * successful or timeout, after timing-out the outstanding mailbox |
| 7459 | * command shall always be removed, so just unblock posting async |
| 7460 | * mailbox command and resume |
| 7461 | */ |
| 7462 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7463 | spin_unlock_irq(&phba->hbalock); |
| 7464 | |
| 7465 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7466 | lpfc_worker_wake_up(phba); |
| 7467 | } |
| 7468 | |
| 7469 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7470 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7471 | * @phba: Pointer to HBA context object. |
| 7472 | * @mboxq: Pointer to mailbox object. |
| 7473 | * |
| 7474 | * The function waits for the bootstrap mailbox register ready bit from |
| 7475 | * port for twice the regular mailbox command timeout value. |
| 7476 | * |
| 7477 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7478 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7479 | **/ |
| 7480 | static int |
| 7481 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7482 | { |
| 7483 | uint32_t db_ready; |
| 7484 | unsigned long timeout; |
| 7485 | struct lpfc_register bmbx_reg; |
| 7486 | |
| 7487 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7488 | * 1000) + jiffies; |
| 7489 | |
| 7490 | do { |
| 7491 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7492 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7493 | if (!db_ready) |
| 7494 | msleep(2); |
| 7495 | |
| 7496 | if (time_after(jiffies, timeout)) |
| 7497 | return MBXERR_ERROR; |
| 7498 | } while (!db_ready); |
| 7499 | |
| 7500 | return 0; |
| 7501 | } |
| 7502 | |
| 7503 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7504 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7505 | * @phba: Pointer to HBA context object. |
| 7506 | * @mboxq: Pointer to mailbox object. |
| 7507 | * |
| 7508 | * The function posts a mailbox to the port. The mailbox is expected |
| 7509 | * to be comletely filled in and ready for the port to operate on it. |
| 7510 | * This routine executes a synchronous completion operation on the |
| 7511 | * mailbox by polling for its completion. |
| 7512 | * |
| 7513 | * The caller must not be holding any locks when calling this routine. |
| 7514 | * |
| 7515 | * Returns: |
| 7516 | * MBX_SUCCESS - mailbox posted successfully |
| 7517 | * Any of the MBX error values. |
| 7518 | **/ |
| 7519 | static int |
| 7520 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7521 | { |
| 7522 | int rc = MBX_SUCCESS; |
| 7523 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7524 | uint32_t mcqe_status; |
| 7525 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7526 | struct lpfc_sli *psli = &phba->sli; |
| 7527 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7528 | struct lpfc_bmbx_create *mbox_rgn; |
| 7529 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7530 | |
| 7531 | /* |
| 7532 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7533 | * at a time and there is no queueing provided. |
| 7534 | */ |
| 7535 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7536 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7537 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7538 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7539 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | "cannot issue Data: x%x x%x\n", |
| 7541 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7542 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7543 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7544 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7545 | psli->sli_flag, MBX_POLL); |
| 7546 | return MBXERR_ERROR; |
| 7547 | } |
| 7548 | /* The server grabs the token and owns it until release */ |
| 7549 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7550 | phba->sli.mbox_active = mboxq; |
| 7551 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7552 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7553 | /* wait for bootstrap mbox register for readyness */ |
| 7554 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7555 | if (rc) |
| 7556 | goto exit; |
| 7557 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7558 | /* |
| 7559 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7560 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7561 | * the bmbx mailbox region. |
| 7562 | */ |
| 7563 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7564 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7565 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7566 | sizeof(struct lpfc_mqe)); |
| 7567 | |
| 7568 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7569 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7570 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7571 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7572 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7573 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7574 | if (rc) |
| 7575 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7576 | |
| 7577 | /* Post the low mailbox dma address to the port. */ |
| 7578 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7579 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7580 | /* wait for bootstrap mbox register for low address write done */ |
| 7581 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7582 | if (rc) |
| 7583 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7584 | |
| 7585 | /* |
| 7586 | * Read the CQ to ensure the mailbox has completed. |
| 7587 | * If so, update the mailbox status so that the upper layers |
| 7588 | * can complete the request normally. |
| 7589 | */ |
| 7590 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7591 | sizeof(struct lpfc_mqe)); |
| 7592 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7593 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7594 | sizeof(struct lpfc_mcqe)); |
| 7595 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7596 | /* |
| 7597 | * When the CQE status indicates a failure and the mailbox status |
| 7598 | * indicates success then copy the CQE status into the mailbox status |
| 7599 | * (and prefix it with x4000). |
| 7600 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7601 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7602 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7603 | bf_set(lpfc_mqe_status, mb, |
| 7604 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7605 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7606 | } else |
| 7607 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7608 | |
| 7609 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7610 | "(%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] | 7611 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7612 | " 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] | 7613 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7614 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7615 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7616 | bf_get(lpfc_mqe_status, mb), |
| 7617 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7618 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7619 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7620 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7621 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7622 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7623 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7624 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7625 | mboxq->mcqe.trailer); |
| 7626 | exit: |
| 7627 | /* We are holding the token, no needed for lock when release */ |
| 7628 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7629 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7630 | phba->sli.mbox_active = NULL; |
| 7631 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7632 | return rc; |
| 7633 | } |
| 7634 | |
| 7635 | /** |
| 7636 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7637 | * @phba: Pointer to HBA context object. |
| 7638 | * @pmbox: Pointer to mailbox object. |
| 7639 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7640 | * |
| 7641 | * This function is called by discovery code and HBA management code to submit |
| 7642 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7643 | * |
| 7644 | * Return codes the caller owns the mailbox command after the return of the |
| 7645 | * function. |
| 7646 | **/ |
| 7647 | static int |
| 7648 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7649 | uint32_t flag) |
| 7650 | { |
| 7651 | struct lpfc_sli *psli = &phba->sli; |
| 7652 | unsigned long iflags; |
| 7653 | int rc; |
| 7654 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7655 | /* dump from issue mailbox command if setup */ |
| 7656 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7657 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7658 | rc = lpfc_mbox_dev_check(phba); |
| 7659 | if (unlikely(rc)) { |
| 7660 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7661 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7662 | "cannot issue Data: x%x x%x\n", |
| 7663 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7664 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7665 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7666 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7667 | psli->sli_flag, flag); |
| 7668 | goto out_not_finished; |
| 7669 | } |
| 7670 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7671 | /* Detect polling mode and jump to a handler */ |
| 7672 | if (!phba->sli4_hba.intr_enable) { |
| 7673 | if (flag == MBX_POLL) |
| 7674 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7675 | else |
| 7676 | rc = -EIO; |
| 7677 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7678 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7679 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7680 | "(x%x/x%x) failure: " |
| 7681 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7682 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7683 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7684 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7685 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7686 | mboxq), |
| 7687 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7688 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7689 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7690 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7691 | bf_get(lpfc_mcqe_ext_status, |
| 7692 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7693 | psli->sli_flag, flag); |
| 7694 | return rc; |
| 7695 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7696 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7697 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7698 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7699 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7700 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7701 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7702 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7703 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7704 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7705 | /* Try to block the asynchronous mailbox posting */ |
| 7706 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7707 | if (!rc) { |
| 7708 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7709 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7710 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7711 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7712 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7713 | "(%d):2597 Sync Mailbox command " |
| 7714 | "x%x (x%x/x%x) failure: " |
| 7715 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7716 | "Data: x%x x%x\n,", |
| 7717 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7718 | mboxq->u.mb.mbxCommand, |
| 7719 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7720 | mboxq), |
| 7721 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7722 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7723 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7724 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7725 | bf_get(lpfc_mcqe_ext_status, |
| 7726 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7727 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7728 | /* Unblock the async mailbox posting afterward */ |
| 7729 | lpfc_sli4_async_mbox_unblock(phba); |
| 7730 | } |
| 7731 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7732 | } |
| 7733 | |
| 7734 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7735 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7736 | if (rc) { |
| 7737 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7738 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7739 | "cannot issue Data: x%x x%x\n", |
| 7740 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7741 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7742 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7743 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7744 | psli->sli_flag, flag); |
| 7745 | goto out_not_finished; |
| 7746 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7747 | |
| 7748 | /* Put the mailbox command to the driver internal FIFO */ |
| 7749 | psli->slistat.mbox_busy++; |
| 7750 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7751 | lpfc_mbox_put(phba, mboxq); |
| 7752 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7753 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7754 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7755 | "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] | 7756 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7757 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7758 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7759 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7760 | phba->pport->port_state, |
| 7761 | psli->sli_flag, MBX_NOWAIT); |
| 7762 | /* Wake up worker thread to transport mailbox command from head */ |
| 7763 | lpfc_worker_wake_up(phba); |
| 7764 | |
| 7765 | return MBX_BUSY; |
| 7766 | |
| 7767 | out_not_finished: |
| 7768 | return MBX_NOT_FINISHED; |
| 7769 | } |
| 7770 | |
| 7771 | /** |
| 7772 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7773 | * @phba: Pointer to HBA context object. |
| 7774 | * |
| 7775 | * This function is called by worker thread to send a mailbox command to |
| 7776 | * SLI4 HBA firmware. |
| 7777 | * |
| 7778 | **/ |
| 7779 | int |
| 7780 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7781 | { |
| 7782 | struct lpfc_sli *psli = &phba->sli; |
| 7783 | LPFC_MBOXQ_t *mboxq; |
| 7784 | int rc = MBX_SUCCESS; |
| 7785 | unsigned long iflags; |
| 7786 | struct lpfc_mqe *mqe; |
| 7787 | uint32_t mbx_cmnd; |
| 7788 | |
| 7789 | /* Check interrupt mode before post async mailbox command */ |
| 7790 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7791 | return MBX_NOT_FINISHED; |
| 7792 | |
| 7793 | /* Check for mailbox command service token */ |
| 7794 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7795 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7796 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7797 | return MBX_NOT_FINISHED; |
| 7798 | } |
| 7799 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7800 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7801 | return MBX_NOT_FINISHED; |
| 7802 | } |
| 7803 | if (unlikely(phba->sli.mbox_active)) { |
| 7804 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7805 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7806 | "0384 There is pending active mailbox cmd\n"); |
| 7807 | return MBX_NOT_FINISHED; |
| 7808 | } |
| 7809 | /* Take the mailbox command service token */ |
| 7810 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7811 | |
| 7812 | /* Get the next mailbox command from head of queue */ |
| 7813 | mboxq = lpfc_mbox_get(phba); |
| 7814 | |
| 7815 | /* If no more mailbox command waiting for post, we're done */ |
| 7816 | if (!mboxq) { |
| 7817 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7818 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7819 | return MBX_SUCCESS; |
| 7820 | } |
| 7821 | phba->sli.mbox_active = mboxq; |
| 7822 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7823 | |
| 7824 | /* Check device readiness for posting mailbox command */ |
| 7825 | rc = lpfc_mbox_dev_check(phba); |
| 7826 | if (unlikely(rc)) |
| 7827 | /* Driver clean routine will clean up pending mailbox */ |
| 7828 | goto out_not_finished; |
| 7829 | |
| 7830 | /* Prepare the mbox command to be posted */ |
| 7831 | mqe = &mboxq->u.mqe; |
| 7832 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7833 | |
| 7834 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7835 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7836 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7837 | |
| 7838 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7839 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7840 | "x%x x%x\n", |
| 7841 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7842 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7843 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7844 | phba->pport->port_state, psli->sli_flag); |
| 7845 | |
| 7846 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7847 | if (mboxq->vport) { |
| 7848 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7849 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7850 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7851 | mbx_cmnd, mqe->un.mb_words[0], |
| 7852 | mqe->un.mb_words[1]); |
| 7853 | } else { |
| 7854 | lpfc_debugfs_disc_trc(phba->pport, |
| 7855 | LPFC_DISC_TRC_MBOX, |
| 7856 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7857 | mbx_cmnd, mqe->un.mb_words[0], |
| 7858 | mqe->un.mb_words[1]); |
| 7859 | } |
| 7860 | } |
| 7861 | psli->slistat.mbox_cmd++; |
| 7862 | |
| 7863 | /* Post the mailbox command to the port */ |
| 7864 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7865 | if (rc != MBX_SUCCESS) { |
| 7866 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7867 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7868 | "cannot issue Data: x%x x%x\n", |
| 7869 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7870 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7871 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7872 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7873 | psli->sli_flag, MBX_NOWAIT); |
| 7874 | goto out_not_finished; |
| 7875 | } |
| 7876 | |
| 7877 | return rc; |
| 7878 | |
| 7879 | out_not_finished: |
| 7880 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7881 | if (phba->sli.mbox_active) { |
| 7882 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7883 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7884 | /* Release the token */ |
| 7885 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7886 | phba->sli.mbox_active = NULL; |
| 7887 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7888 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7889 | |
| 7890 | return MBX_NOT_FINISHED; |
| 7891 | } |
| 7892 | |
| 7893 | /** |
| 7894 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7895 | * @phba: Pointer to HBA context object. |
| 7896 | * @pmbox: Pointer to mailbox object. |
| 7897 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7898 | * |
| 7899 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7900 | * the API jump table function pointer from the lpfc_hba struct. |
| 7901 | * |
| 7902 | * Return codes the caller owns the mailbox command after the return of the |
| 7903 | * function. |
| 7904 | **/ |
| 7905 | int |
| 7906 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7907 | { |
| 7908 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7909 | } |
| 7910 | |
| 7911 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7912 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7913 | * @phba: The hba struct for which this call is being executed. |
| 7914 | * @dev_grp: The HBA PCI-Device group number. |
| 7915 | * |
| 7916 | * This routine sets up the mbox interface API function jump table in @phba |
| 7917 | * struct. |
| 7918 | * Returns: 0 - success, -ENODEV - failure. |
| 7919 | **/ |
| 7920 | int |
| 7921 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7922 | { |
| 7923 | |
| 7924 | switch (dev_grp) { |
| 7925 | case LPFC_PCI_DEV_LP: |
| 7926 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7927 | phba->lpfc_sli_handle_slow_ring_event = |
| 7928 | lpfc_sli_handle_slow_ring_event_s3; |
| 7929 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7930 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7931 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7932 | break; |
| 7933 | case LPFC_PCI_DEV_OC: |
| 7934 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7935 | phba->lpfc_sli_handle_slow_ring_event = |
| 7936 | lpfc_sli_handle_slow_ring_event_s4; |
| 7937 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7938 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7939 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7940 | break; |
| 7941 | default: |
| 7942 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7943 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7944 | dev_grp); |
| 7945 | return -ENODEV; |
| 7946 | break; |
| 7947 | } |
| 7948 | return 0; |
| 7949 | } |
| 7950 | |
| 7951 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7952 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7953 | * @phba: Pointer to HBA context object. |
| 7954 | * @pring: Pointer to driver SLI ring object. |
| 7955 | * @piocb: Pointer to address of newly added command iocb. |
| 7956 | * |
| 7957 | * This function is called with hbalock held to add a command |
| 7958 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7959 | * to the ring. |
| 7960 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7961 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7962 | __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] | 7963 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7964 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7965 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7966 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7967 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7968 | } |
| 7969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7971 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7972 | * @phba: Pointer to HBA context object. |
| 7973 | * @pring: Pointer to driver SLI ring object. |
| 7974 | * @piocb: Pointer to address of newly added command iocb. |
| 7975 | * |
| 7976 | * This function is called with hbalock held before a new |
| 7977 | * iocb is submitted to the firmware. This function checks |
| 7978 | * txq to flush the iocbs in txq to Firmware before |
| 7979 | * submitting new iocbs to the Firmware. |
| 7980 | * If there are iocbs in the txq which need to be submitted |
| 7981 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7982 | * of the txq after dequeuing it from txq. |
| 7983 | * If there is no iocb in the txq then the function will return |
| 7984 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7985 | * *piocb to find if there are more commands in the txq. |
| 7986 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7987 | static struct lpfc_iocbq * |
| 7988 | 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] | 7989 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7990 | { |
| 7991 | struct lpfc_iocbq * nextiocb; |
| 7992 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 7993 | lockdep_assert_held(&phba->hbalock); |
| 7994 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7995 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7996 | if (!nextiocb) { |
| 7997 | nextiocb = *piocb; |
| 7998 | *piocb = NULL; |
| 7999 | } |
| 8000 | |
| 8001 | return nextiocb; |
| 8002 | } |
| 8003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8004 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8005 | * __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] | 8006 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8007 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8008 | * @piocb: Pointer to command iocb. |
| 8009 | * @flag: Flag indicating if this command can be put into txq. |
| 8010 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8011 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8012 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8013 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8014 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8015 | * this function allows only iocbs for posting buffers. This function finds |
| 8016 | * next available slot in the command ring and posts the command to the |
| 8017 | * available slot and writes the port attention register to request HBA start |
| 8018 | * processing new iocb. If there is no slot available in the ring and |
| 8019 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8020 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8021 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8022 | * This function is called with hbalock held. The function will return success |
| 8023 | * after it successfully submit the iocb to firmware or after adding to the |
| 8024 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8025 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8026 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8027 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8028 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8029 | { |
| 8030 | struct lpfc_iocbq *nextiocb; |
| 8031 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8032 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8033 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8034 | lockdep_assert_held(&phba->hbalock); |
| 8035 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8036 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8037 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8038 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8039 | lpfc_printf_log(phba, KERN_ERR, |
| 8040 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8041 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8042 | piocb->iocb.ulpCommand); |
| 8043 | dump_stack(); |
| 8044 | return IOCB_ERROR; |
| 8045 | } |
| 8046 | |
| 8047 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8048 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8049 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8050 | return IOCB_ERROR; |
| 8051 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8052 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8053 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8054 | return IOCB_ERROR; |
| 8055 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8056 | /* |
| 8057 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8058 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8059 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8060 | return IOCB_ERROR; |
| 8061 | |
| 8062 | /* |
| 8063 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8064 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8065 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8066 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8067 | goto iocb_busy; |
| 8068 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8069 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8070 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8071 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8072 | * can be issued if the link is not up. |
| 8073 | */ |
| 8074 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8075 | case CMD_GEN_REQUEST64_CR: |
| 8076 | case CMD_GEN_REQUEST64_CX: |
| 8077 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8078 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8079 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8080 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8081 | MENLO_TRANSPORT_TYPE)) |
| 8082 | |
| 8083 | goto iocb_busy; |
| 8084 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8085 | case CMD_QUE_RING_BUF_CN: |
| 8086 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8087 | /* |
| 8088 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8089 | * completion, iocb_cmpl MUST be 0. |
| 8090 | */ |
| 8091 | if (piocb->iocb_cmpl) |
| 8092 | piocb->iocb_cmpl = NULL; |
| 8093 | /*FALLTHROUGH*/ |
| 8094 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8095 | case CMD_CLOSE_XRI_CN: |
| 8096 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8097 | break; |
| 8098 | default: |
| 8099 | goto iocb_busy; |
| 8100 | } |
| 8101 | |
| 8102 | /* |
| 8103 | * For FCP commands, we must be in a state where we can process link |
| 8104 | * attention events. |
| 8105 | */ |
| 8106 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8107 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8108 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8109 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8110 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8111 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8112 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8113 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8114 | |
| 8115 | if (iocb) |
| 8116 | lpfc_sli_update_ring(phba, pring); |
| 8117 | else |
| 8118 | lpfc_sli_update_full_ring(phba, pring); |
| 8119 | |
| 8120 | if (!piocb) |
| 8121 | return IOCB_SUCCESS; |
| 8122 | |
| 8123 | goto out_busy; |
| 8124 | |
| 8125 | iocb_busy: |
| 8126 | pring->stats.iocb_cmd_delay++; |
| 8127 | |
| 8128 | out_busy: |
| 8129 | |
| 8130 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8131 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8132 | return IOCB_SUCCESS; |
| 8133 | } |
| 8134 | |
| 8135 | return IOCB_BUSY; |
| 8136 | } |
| 8137 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8138 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8139 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8140 | * @phba: Pointer to HBA context object. |
| 8141 | * @piocb: Pointer to command iocb. |
| 8142 | * @sglq: Pointer to the scatter gather queue object. |
| 8143 | * |
| 8144 | * This routine converts the bpl or bde that is in the IOCB |
| 8145 | * to a sgl list for the sli4 hardware. The physical address |
| 8146 | * of the bpl/bde is converted back to a virtual address. |
| 8147 | * If the IOCB contains a BPL then the list of BDE's is |
| 8148 | * converted to sli4_sge's. If the IOCB contains a single |
| 8149 | * BDE then it is converted to a single sli_sge. |
| 8150 | * The IOCB is still in cpu endianess so the contents of |
| 8151 | * the bpl can be used without byte swapping. |
| 8152 | * |
| 8153 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8154 | **/ |
| 8155 | static uint16_t |
| 8156 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8157 | struct lpfc_sglq *sglq) |
| 8158 | { |
| 8159 | uint16_t xritag = NO_XRI; |
| 8160 | struct ulp_bde64 *bpl = NULL; |
| 8161 | struct ulp_bde64 bde; |
| 8162 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8163 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8164 | IOCB_t *icmd; |
| 8165 | int numBdes = 0; |
| 8166 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8167 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8168 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8169 | |
| 8170 | if (!piocbq || !sglq) |
| 8171 | return xritag; |
| 8172 | |
| 8173 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8174 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8175 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8176 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8177 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8178 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8179 | sizeof(struct ulp_bde64); |
| 8180 | /* The addrHigh and addrLow fields within the IOCB |
| 8181 | * have not been byteswapped yet so there is no |
| 8182 | * need to swap them back. |
| 8183 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8184 | if (piocbq->context3) |
| 8185 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8186 | else |
| 8187 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8188 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8189 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8190 | if (!bpl) |
| 8191 | return xritag; |
| 8192 | |
| 8193 | for (i = 0; i < numBdes; i++) { |
| 8194 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8195 | sgl->addr_hi = bpl->addrHigh; |
| 8196 | sgl->addr_lo = bpl->addrLow; |
| 8197 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8198 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8199 | if ((i+1) == numBdes) |
| 8200 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8201 | else |
| 8202 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8203 | /* swap the size field back to the cpu so we |
| 8204 | * can assign it to the sgl. |
| 8205 | */ |
| 8206 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8207 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8208 | /* The offsets in the sgl need to be accumulated |
| 8209 | * separately for the request and reply lists. |
| 8210 | * The request is always first, the reply follows. |
| 8211 | */ |
| 8212 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8213 | /* add up the reply sg entries */ |
| 8214 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8215 | inbound++; |
| 8216 | /* first inbound? reset the offset */ |
| 8217 | if (inbound == 1) |
| 8218 | offset = 0; |
| 8219 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8220 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8221 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8222 | offset += bde.tus.f.bdeSize; |
| 8223 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8224 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8225 | bpl++; |
| 8226 | sgl++; |
| 8227 | } |
| 8228 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8229 | /* The addrHigh and addrLow fields of the BDE have not |
| 8230 | * been byteswapped yet so they need to be swapped |
| 8231 | * before putting them in the sgl. |
| 8232 | */ |
| 8233 | sgl->addr_hi = |
| 8234 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8235 | sgl->addr_lo = |
| 8236 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8237 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8238 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8239 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8240 | sgl->sge_len = |
| 8241 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8242 | } |
| 8243 | return sglq->sli4_xritag; |
| 8244 | } |
| 8245 | |
| 8246 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8247 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8248 | * @phba: Pointer to HBA context object. |
| 8249 | * @piocb: Pointer to command iocb. |
| 8250 | * @wqe: Pointer to the work queue entry. |
| 8251 | * |
| 8252 | * This routine converts the iocb command to its Work Queue Entry |
| 8253 | * equivalent. The wqe pointer should not have any fields set when |
| 8254 | * this routine is called because it will memcpy over them. |
| 8255 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8256 | * wqe. |
| 8257 | * |
| 8258 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8259 | **/ |
| 8260 | static int |
| 8261 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8262 | union lpfc_wqe *wqe) |
| 8263 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8264 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8265 | uint8_t ct = 0; |
| 8266 | uint32_t fip; |
| 8267 | uint32_t abort_tag; |
| 8268 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8269 | uint8_t cmnd; |
| 8270 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8271 | uint16_t abrt_iotag; |
| 8272 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8273 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8274 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8275 | int numBdes, i; |
| 8276 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8277 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8278 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8279 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8280 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8281 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8282 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8283 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8284 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8285 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8286 | command_type = ELS_COMMAND_FIP; |
| 8287 | else |
| 8288 | command_type = ELS_COMMAND_NON_FIP; |
| 8289 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8290 | if (phba->fcp_embed_io) |
| 8291 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8292 | /* Some of the fields are in the right position already */ |
| 8293 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8294 | 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] | 8295 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8296 | |
| 8297 | abort_tag = (uint32_t) iocbq->iotag; |
| 8298 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8299 | /* words0-2 bpl convert bde */ |
| 8300 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8301 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8302 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8303 | bpl = (struct ulp_bde64 *) |
| 8304 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8305 | if (!bpl) |
| 8306 | return IOCB_ERROR; |
| 8307 | |
| 8308 | /* Should already be byte swapped. */ |
| 8309 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8310 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8311 | /* swap the size field back to the cpu so we |
| 8312 | * can assign it to the sgl. |
| 8313 | */ |
| 8314 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8315 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8316 | total_len = 0; |
| 8317 | for (i = 0; i < numBdes; i++) { |
| 8318 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8319 | total_len += bde.tus.f.bdeSize; |
| 8320 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8321 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8322 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8323 | |
| 8324 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8325 | cmnd = iocbq->iocb.ulpCommand; |
| 8326 | |
| 8327 | switch (iocbq->iocb.ulpCommand) { |
| 8328 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8329 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8330 | ndlp = iocbq->context_un.ndlp; |
| 8331 | else |
| 8332 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8333 | if (!iocbq->iocb.ulpLe) { |
| 8334 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8335 | "2007 Only Limited Edition cmd Format" |
| 8336 | " supported 0x%x\n", |
| 8337 | iocbq->iocb.ulpCommand); |
| 8338 | return IOCB_ERROR; |
| 8339 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8340 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8341 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8342 | /* Els_reguest64 has a TMO */ |
| 8343 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8344 | iocbq->iocb.ulpTimeout); |
| 8345 | /* Need a VF for word 4 set the vf bit*/ |
| 8346 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8347 | /* And a VFID for word 12 */ |
| 8348 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8349 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8350 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8351 | iocbq->iocb.ulpContext); |
| 8352 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8353 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8354 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8355 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8356 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8357 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8358 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8359 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8360 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8361 | &phba->sli4_hba.sli_intf); |
| 8362 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8363 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8364 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8365 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8366 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8367 | *pcmd == ELS_CMD_PLOGI)) { |
| 8368 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8369 | bf_set(els_req64_sid, &wqe->els_req, |
| 8370 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8371 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8372 | !(phba->fc_topology == |
| 8373 | LPFC_TOPOLOGY_LOOP)) |
| 8374 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8375 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8376 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8377 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8378 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8379 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8380 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8381 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8382 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8383 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8384 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8385 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8386 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8387 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8388 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8389 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8390 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8391 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8392 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8393 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8394 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8395 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8396 | iocbq->iocb.un.ulpWord[3]); |
| 8397 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8398 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8399 | /* The entire sequence is transmitted for this IOCB */ |
| 8400 | xmit_len = total_len; |
| 8401 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8402 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8403 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8404 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8405 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8406 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8407 | /* word4 relative_offset memcpy */ |
| 8408 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8409 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8410 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8411 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8412 | LPFC_WQE_IOD_WRITE); |
| 8413 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8414 | LPFC_WQE_LENLOC_WORD12); |
| 8415 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8416 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8417 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8418 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8419 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8420 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8421 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8422 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8423 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8424 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8425 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8426 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8427 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8428 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8429 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8430 | LPFC_WQE_LENLOC_WORD3); |
| 8431 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8432 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8433 | case CMD_FCP_IWRITE64_CR: |
| 8434 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8435 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8436 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8437 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8438 | xmit_len + sizeof(struct fcp_rsp)); |
| 8439 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8440 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8441 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8442 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8443 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8444 | iocbq->iocb.ulpFCP2Rcvy); |
| 8445 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8446 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8447 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8448 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8449 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8450 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8451 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8452 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8453 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8454 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8455 | if (iocbq->priority) { |
| 8456 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8457 | (iocbq->priority << 1)); |
| 8458 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8459 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8460 | (phba->cfg_XLanePriority << 1)); |
| 8461 | } |
| 8462 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8463 | /* Note, word 10 is already initialized to 0 */ |
| 8464 | |
| 8465 | if (phba->fcp_embed_io) { |
| 8466 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8467 | struct sli4_sge *sgl; |
| 8468 | union lpfc_wqe128 *wqe128; |
| 8469 | struct fcp_cmnd *fcp_cmnd; |
| 8470 | uint32_t *ptr; |
| 8471 | |
| 8472 | /* 128 byte wqe support here */ |
| 8473 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8474 | |
| 8475 | lpfc_cmd = iocbq->context1; |
| 8476 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8477 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8478 | |
| 8479 | /* Word 0-2 - FCP_CMND */ |
| 8480 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8481 | BUFF_TYPE_BDE_IMMED; |
| 8482 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8483 | wqe128->generic.bde.addrHigh = 0; |
| 8484 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8485 | |
| 8486 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8487 | |
| 8488 | /* Word 22-29 FCP CMND Payload */ |
| 8489 | ptr = &wqe128->words[22]; |
| 8490 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8491 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8492 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8493 | case CMD_FCP_IREAD64_CR: |
| 8494 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8495 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8496 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8497 | xmit_len + sizeof(struct fcp_rsp)); |
| 8498 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8499 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8500 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8501 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8502 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8503 | iocbq->iocb.ulpFCP2Rcvy); |
| 8504 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8505 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8506 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8507 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8508 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8509 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8510 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8511 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8512 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8513 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8514 | if (iocbq->priority) { |
| 8515 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8516 | (iocbq->priority << 1)); |
| 8517 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8518 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8519 | (phba->cfg_XLanePriority << 1)); |
| 8520 | } |
| 8521 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8522 | /* Note, word 10 is already initialized to 0 */ |
| 8523 | |
| 8524 | if (phba->fcp_embed_io) { |
| 8525 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8526 | struct sli4_sge *sgl; |
| 8527 | union lpfc_wqe128 *wqe128; |
| 8528 | struct fcp_cmnd *fcp_cmnd; |
| 8529 | uint32_t *ptr; |
| 8530 | |
| 8531 | /* 128 byte wqe support here */ |
| 8532 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8533 | |
| 8534 | lpfc_cmd = iocbq->context1; |
| 8535 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8536 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8537 | |
| 8538 | /* Word 0-2 - FCP_CMND */ |
| 8539 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8540 | BUFF_TYPE_BDE_IMMED; |
| 8541 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8542 | wqe128->generic.bde.addrHigh = 0; |
| 8543 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8544 | |
| 8545 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8546 | |
| 8547 | /* Word 22-29 FCP CMND Payload */ |
| 8548 | ptr = &wqe128->words[22]; |
| 8549 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8550 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8551 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8552 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8553 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8554 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8555 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8556 | xmit_len + sizeof(struct fcp_rsp)); |
| 8557 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8558 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8559 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8560 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8561 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8562 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8563 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8564 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8565 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8566 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8567 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8568 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8569 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8570 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8571 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8572 | if (iocbq->priority) { |
| 8573 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8574 | (iocbq->priority << 1)); |
| 8575 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8576 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8577 | (phba->cfg_XLanePriority << 1)); |
| 8578 | } |
| 8579 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8580 | /* Note, word 10 is already initialized to 0 */ |
| 8581 | |
| 8582 | if (phba->fcp_embed_io) { |
| 8583 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8584 | struct sli4_sge *sgl; |
| 8585 | union lpfc_wqe128 *wqe128; |
| 8586 | struct fcp_cmnd *fcp_cmnd; |
| 8587 | uint32_t *ptr; |
| 8588 | |
| 8589 | /* 128 byte wqe support here */ |
| 8590 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8591 | |
| 8592 | lpfc_cmd = iocbq->context1; |
| 8593 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8594 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8595 | |
| 8596 | /* Word 0-2 - FCP_CMND */ |
| 8597 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8598 | BUFF_TYPE_BDE_IMMED; |
| 8599 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8600 | wqe128->generic.bde.addrHigh = 0; |
| 8601 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8602 | |
| 8603 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 8604 | |
| 8605 | /* Word 22-29 FCP CMND Payload */ |
| 8606 | ptr = &wqe128->words[22]; |
| 8607 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8608 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8609 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8610 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8611 | /* For this command calculate the xmit length of the |
| 8612 | * request bde. |
| 8613 | */ |
| 8614 | xmit_len = 0; |
| 8615 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8616 | sizeof(struct ulp_bde64); |
| 8617 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8618 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8619 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8620 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8621 | xmit_len += bde.tus.f.bdeSize; |
| 8622 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8623 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8624 | wqe->gen_req.request_payload_len = xmit_len; |
| 8625 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8626 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8627 | /* word6 context tag copied in memcpy */ |
| 8628 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8629 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8630 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8631 | "2015 Invalid CT %x command 0x%x\n", |
| 8632 | ct, iocbq->iocb.ulpCommand); |
| 8633 | return IOCB_ERROR; |
| 8634 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8635 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8636 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8637 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8638 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8639 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8640 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8641 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8642 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8643 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8644 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8645 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8646 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8647 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8648 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8649 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8650 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8651 | /* word4 */ |
| 8652 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8653 | /* word5 iocb=rsvd wge=did */ |
| 8654 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8655 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8656 | |
| 8657 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8658 | &phba->sli4_hba.sli_intf); |
| 8659 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8660 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8661 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8662 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8663 | iocbq->vport->fc_myDID); |
| 8664 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8665 | bf_set(wqe_els_did, |
| 8666 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8667 | } |
| 8668 | } |
| 8669 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8670 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8671 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8672 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8673 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8674 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8675 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8676 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8677 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8678 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8679 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8680 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8681 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8682 | LPFC_WQE_LENLOC_WORD3); |
| 8683 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8684 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8685 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8686 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8687 | iocbq->context2)->virt); |
| 8688 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8689 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8690 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8691 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8692 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8693 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8694 | phba->vpi_ids[phba->pport->vpi]); |
| 8695 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8696 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8697 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8698 | case CMD_CLOSE_XRI_CN: |
| 8699 | case CMD_ABORT_XRI_CN: |
| 8700 | case CMD_ABORT_XRI_CX: |
| 8701 | /* words 0-2 memcpy should be 0 rserved */ |
| 8702 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8703 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8704 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8705 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8706 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8707 | } else |
| 8708 | fip = 0; |
| 8709 | |
| 8710 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8711 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8712 | * The link is down, or the command was ELS_FIP |
| 8713 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8714 | * on the wire. |
| 8715 | */ |
| 8716 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8717 | else |
| 8718 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8719 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8720 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8721 | wqe->abort_cmd.rsrvd5 = 0; |
| 8722 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8723 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8724 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8725 | /* |
| 8726 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8727 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8728 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8729 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8730 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8731 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8732 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8733 | cmnd = CMD_ABORT_XRI_CX; |
| 8734 | command_type = OTHER_COMMAND; |
| 8735 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8736 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8737 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8738 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8739 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8740 | * we re-construct this WQE here based on information in |
| 8741 | * iocbq from scratch. |
| 8742 | */ |
| 8743 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8744 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8745 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8746 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8747 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8748 | LPFC_ABTS_UNSOL_INT) { |
| 8749 | /* ABTS sent by initiator to CT exchange, the |
| 8750 | * RX_ID field will be filled with the newly |
| 8751 | * allocated responder XRI. |
| 8752 | */ |
| 8753 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8754 | iocbq->sli4_xritag); |
| 8755 | } else { |
| 8756 | /* ABTS sent by responder to CT exchange, the |
| 8757 | * RX_ID field will be filled with the responder |
| 8758 | * RX_ID from ABTS. |
| 8759 | */ |
| 8760 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8761 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8762 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8763 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8764 | 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] | 8765 | |
| 8766 | /* Use CT=VPI */ |
| 8767 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8768 | ndlp->nlp_DID); |
| 8769 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8770 | iocbq->iocb.ulpContext); |
| 8771 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8772 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8773 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8774 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8775 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8776 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8777 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8778 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8779 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8780 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8781 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8782 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8783 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8784 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8785 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8786 | } |
| 8787 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8788 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8789 | case CMD_XRI_ABORTED_CX: |
| 8790 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8791 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8792 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8793 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8794 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8795 | default: |
| 8796 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8797 | "2014 Invalid command 0x%x\n", |
| 8798 | iocbq->iocb.ulpCommand); |
| 8799 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8800 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8801 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8802 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8803 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8804 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8805 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8806 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8807 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8808 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8809 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8810 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8811 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8812 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8813 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8814 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8815 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8816 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8817 | 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] | 8818 | return 0; |
| 8819 | } |
| 8820 | |
| 8821 | /** |
| 8822 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8823 | * @phba: Pointer to HBA context object. |
| 8824 | * @ring_number: SLI ring number to issue iocb on. |
| 8825 | * @piocb: Pointer to command iocb. |
| 8826 | * @flag: Flag indicating if this command can be put into txq. |
| 8827 | * |
| 8828 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8829 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8830 | * |
| 8831 | * This function is called with hbalock held. The function will return success |
| 8832 | * after it successfully submit the iocb to firmware or after adding to the |
| 8833 | * txq. |
| 8834 | **/ |
| 8835 | static int |
| 8836 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8837 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8838 | { |
| 8839 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8840 | union lpfc_wqe *wqe; |
| 8841 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8842 | struct lpfc_queue *wq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8843 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8844 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8845 | lockdep_assert_held(&phba->hbalock); |
| 8846 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8847 | /* |
| 8848 | * The WQE can be either 64 or 128 bytes, |
| 8849 | * so allocate space on the stack assuming the largest. |
| 8850 | */ |
| 8851 | wqe = (union lpfc_wqe *)&wqe128; |
| 8852 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8853 | if (piocb->sli4_xritag == NO_XRI) { |
| 8854 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8855 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8856 | sglq = NULL; |
| 8857 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8858 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8859 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8860 | __lpfc_sli_ringtx_put(phba, |
| 8861 | pring, piocb); |
| 8862 | return IOCB_SUCCESS; |
| 8863 | } else { |
| 8864 | return IOCB_BUSY; |
| 8865 | } |
| 8866 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8867 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8868 | if (!sglq) { |
| 8869 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8870 | __lpfc_sli_ringtx_put(phba, |
| 8871 | pring, |
| 8872 | piocb); |
| 8873 | return IOCB_SUCCESS; |
| 8874 | } else |
| 8875 | return IOCB_BUSY; |
| 8876 | } |
| 8877 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8878 | } |
| 8879 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8880 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8881 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8882 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8883 | /* |
| 8884 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8885 | * sglq is on the active list |
| 8886 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8887 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8888 | if (!sglq) |
| 8889 | return IOCB_ERROR; |
| 8890 | } |
| 8891 | |
| 8892 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8893 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8894 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8895 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8896 | return IOCB_ERROR; |
| 8897 | } |
| 8898 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8899 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8900 | return IOCB_ERROR; |
| 8901 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8902 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8903 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 8904 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8905 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
| 8906 | } else { |
| 8907 | wq = phba->sli4_hba.oas_wq; |
| 8908 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8909 | if (lpfc_sli4_wq_put(wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8910 | return IOCB_ERROR; |
| 8911 | } else { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8912 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 8913 | return IOCB_ERROR; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8914 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8915 | return IOCB_ERROR; |
| 8916 | } |
| 8917 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8918 | |
| 8919 | return 0; |
| 8920 | } |
| 8921 | |
| 8922 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8923 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8924 | * |
| 8925 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8926 | * pointer from the lpfc_hba struct. |
| 8927 | * |
| 8928 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8929 | * IOCB_ERROR - Error |
| 8930 | * IOCB_SUCCESS - Success |
| 8931 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8932 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8933 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8934 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8935 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8936 | { |
| 8937 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8938 | } |
| 8939 | |
| 8940 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8941 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8942 | * @phba: The hba struct for which this call is being executed. |
| 8943 | * @dev_grp: The HBA PCI-Device group number. |
| 8944 | * |
| 8945 | * This routine sets up the SLI interface API function jump table in @phba |
| 8946 | * struct. |
| 8947 | * Returns: 0 - success, -ENODEV - failure. |
| 8948 | **/ |
| 8949 | int |
| 8950 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8951 | { |
| 8952 | |
| 8953 | switch (dev_grp) { |
| 8954 | case LPFC_PCI_DEV_LP: |
| 8955 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8956 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8957 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8958 | case LPFC_PCI_DEV_OC: |
| 8959 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8960 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8961 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8962 | default: |
| 8963 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8964 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8965 | dev_grp); |
| 8966 | return -ENODEV; |
| 8967 | break; |
| 8968 | } |
| 8969 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8970 | return 0; |
| 8971 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8972 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 8973 | /** |
| 8974 | * lpfc_sli_calc_ring - Calculates which ring to use |
| 8975 | * @phba: Pointer to HBA context object. |
| 8976 | * @ring_number: Initial ring |
| 8977 | * @piocb: Pointer to command iocb. |
| 8978 | * |
| 8979 | * For SLI4, FCP IO can deferred to one fo many WQs, based on |
| 8980 | * fcp_wqidx, thus we need to calculate the corresponding ring. |
| 8981 | * Since ABORTS must go on the same WQ of the command they are |
| 8982 | * aborting, we use command's fcp_wqidx. |
| 8983 | */ |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 8984 | static int |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 8985 | lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number, |
| 8986 | struct lpfc_iocbq *piocb) |
| 8987 | { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 8988 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 8989 | return ring_number; |
| 8990 | |
| 8991 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
| 8992 | if (!(phba->cfg_fof) || |
| 8993 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
| 8994 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8995 | return LPFC_HBA_ERROR; |
| 8996 | /* |
| 8997 | * for abort iocb fcp_wqidx should already |
| 8998 | * be setup based on what work queue we used. |
| 8999 | */ |
| 9000 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) |
| 9001 | piocb->fcp_wqidx = |
| 9002 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9003 | piocb->context1); |
| 9004 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 9005 | piocb->fcp_wqidx; |
| 9006 | } else { |
| 9007 | if (unlikely(!phba->sli4_hba.oas_wq)) |
| 9008 | return LPFC_HBA_ERROR; |
| 9009 | piocb->fcp_wqidx = 0; |
| 9010 | ring_number = LPFC_FCP_OAS_RING; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9011 | } |
| 9012 | } |
| 9013 | return ring_number; |
| 9014 | } |
| 9015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9016 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9017 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9018 | * @phba: Pointer to HBA context object. |
| 9019 | * @pring: Pointer to driver SLI ring object. |
| 9020 | * @piocb: Pointer to command iocb. |
| 9021 | * @flag: Flag indicating if this command can be put into txq. |
| 9022 | * |
| 9023 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9024 | * function. This function gets the hbalock and calls |
| 9025 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9026 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9027 | * functions which do not hold hbalock. |
| 9028 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9029 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9030 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9031 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9032 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9033 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9034 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9035 | struct lpfc_queue *fpeq; |
| 9036 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9037 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9038 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9039 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9040 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9041 | ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb); |
| 9042 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 9043 | return IOCB_ERROR; |
| 9044 | idx = piocb->fcp_wqidx; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9045 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9046 | pring = &phba->sli.ring[ring_number]; |
| 9047 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9048 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9049 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9050 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9051 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
| 9052 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9053 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9054 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 9055 | fcp_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9056 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9057 | /* Get associated EQ with this index */ |
| 9058 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9059 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9060 | /* Turn off interrupts from this EQ */ |
| 9061 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9062 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9063 | /* |
| 9064 | * Process all the events on FCP EQ |
| 9065 | */ |
| 9066 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9067 | lpfc_sli4_hba_handle_eqe(phba, |
| 9068 | eqe, idx); |
| 9069 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9070 | } |
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 | /* Always clear and re-arm the EQ */ |
| 9073 | lpfc_sli4_eq_release(fpeq, |
| 9074 | LPFC_QUEUE_REARM); |
| 9075 | } |
| 9076 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9077 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9078 | } else { |
| 9079 | /* For now, SLI2/3 will still use hbalock */ |
| 9080 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9081 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9082 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9083 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9084 | return rc; |
| 9085 | } |
| 9086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9088 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9089 | * @phba: Pointer to HBA context object. |
| 9090 | * |
| 9091 | * This function is called while driver attaches with the |
| 9092 | * HBA to setup the extra ring. The extra ring is used |
| 9093 | * only when driver needs to support target mode functionality |
| 9094 | * or IP over FC functionalities. |
| 9095 | * |
| 9096 | * This function is called with no lock held. |
| 9097 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9098 | static int |
| 9099 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9100 | { |
| 9101 | struct lpfc_sli *psli; |
| 9102 | struct lpfc_sli_ring *pring; |
| 9103 | |
| 9104 | psli = &phba->sli; |
| 9105 | |
| 9106 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9107 | |
| 9108 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9109 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9110 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9111 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9112 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9113 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9114 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9115 | /* and give them to the extra ring */ |
| 9116 | pring = &psli->ring[psli->extra_ring]; |
| 9117 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9118 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9119 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9120 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9121 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9122 | |
| 9123 | /* Setup default profile for this ring */ |
| 9124 | pring->iotag_max = 4096; |
| 9125 | pring->num_mask = 1; |
| 9126 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9127 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9128 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9129 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9130 | return 0; |
| 9131 | } |
| 9132 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9133 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9134 | * @phba: Pointer to HBA context object. |
| 9135 | * @iocbq: Pointer to iocb object. |
| 9136 | * |
| 9137 | * The async_event handler calls this routine when it receives |
| 9138 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9139 | * this event when an Abort Sequence request to an rport fails |
| 9140 | * twice in succession. The abort could be originated by the |
| 9141 | * driver or by the port. The ABTS could have been for an ELS |
| 9142 | * or FCP IO. The port only generates this event when an ABTS |
| 9143 | * fails to complete after one retry. |
| 9144 | */ |
| 9145 | static void |
| 9146 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9147 | struct lpfc_iocbq *iocbq) |
| 9148 | { |
| 9149 | struct lpfc_nodelist *ndlp = NULL; |
| 9150 | uint16_t rpi = 0, vpi = 0; |
| 9151 | struct lpfc_vport *vport = NULL; |
| 9152 | |
| 9153 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9154 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9155 | rpi = iocbq->iocb.ulpContext; |
| 9156 | |
| 9157 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9158 | "3092 Port generated ABTS async event " |
| 9159 | "on vpi %d rpi %d status 0x%x\n", |
| 9160 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9161 | |
| 9162 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9163 | if (!vport) |
| 9164 | goto err_exit; |
| 9165 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9166 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9167 | goto err_exit; |
| 9168 | |
| 9169 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9170 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9171 | return; |
| 9172 | |
| 9173 | err_exit: |
| 9174 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9175 | "3095 Event Context not found, no " |
| 9176 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9177 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9178 | vpi, rpi); |
| 9179 | } |
| 9180 | |
| 9181 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9182 | * @phba: pointer to HBA context object. |
| 9183 | * @ndlp: nodelist pointer for the impacted rport. |
| 9184 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9185 | * |
| 9186 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9187 | * port. The port generates this event when an abort exchange request to an |
| 9188 | * rport fails twice in succession with no reply. The abort could be originated |
| 9189 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9190 | */ |
| 9191 | void |
| 9192 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9193 | struct lpfc_nodelist *ndlp, |
| 9194 | struct sli4_wcqe_xri_aborted *axri) |
| 9195 | { |
| 9196 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9197 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9198 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9199 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9200 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9201 | "3115 Node Context not found, driver " |
| 9202 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9203 | return; |
| 9204 | } |
| 9205 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9206 | vport = ndlp->vport; |
| 9207 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9208 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9209 | "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] | 9210 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9211 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9212 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9213 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9214 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9215 | /* |
| 9216 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9217 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9218 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9219 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9220 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9221 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9222 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9223 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9224 | } |
| 9225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9226 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9227 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9228 | * @phba: Pointer to HBA context object. |
| 9229 | * @pring: Pointer to driver SLI ring object. |
| 9230 | * @iocbq: Pointer to iocb object. |
| 9231 | * |
| 9232 | * This function is called by the slow ring event handler |
| 9233 | * function when there is an ASYNC event iocb in the ring. |
| 9234 | * This function is called with no lock held. |
| 9235 | * Currently this function handles only temperature related |
| 9236 | * ASYNC events. The function decodes the temperature sensor |
| 9237 | * event message and posts events for the management applications. |
| 9238 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9239 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9240 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9241 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9242 | { |
| 9243 | IOCB_t *icmd; |
| 9244 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9245 | struct temp_event temp_event_data; |
| 9246 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9247 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9248 | |
| 9249 | icmd = &iocbq->iocb; |
| 9250 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9251 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9252 | switch (evt_code) { |
| 9253 | case ASYNC_TEMP_WARN: |
| 9254 | case ASYNC_TEMP_SAFE: |
| 9255 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9256 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9257 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9258 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9259 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9260 | "0347 Adapter is very hot, please take " |
| 9261 | "corrective action. temperature : %d Celsius\n", |
| 9262 | (uint32_t) icmd->ulpContext); |
| 9263 | } else { |
| 9264 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9265 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9266 | "0340 Adapter temperature is OK now. " |
| 9267 | "temperature : %d Celsius\n", |
| 9268 | (uint32_t) icmd->ulpContext); |
| 9269 | } |
| 9270 | |
| 9271 | /* Send temperature change event to applications */ |
| 9272 | shost = lpfc_shost_from_vport(phba->pport); |
| 9273 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9274 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9275 | LPFC_NL_VENDOR_ID); |
| 9276 | break; |
| 9277 | case ASYNC_STATUS_CN: |
| 9278 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9279 | break; |
| 9280 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9281 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9282 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9283 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9284 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9285 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9286 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9287 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9288 | "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] | 9289 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9290 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9291 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9292 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9293 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9294 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9295 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9296 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9297 | } |
| 9298 | |
| 9299 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9301 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9302 | * @phba: Pointer to HBA context object. |
| 9303 | * |
| 9304 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9305 | * number of iocbs per ring and iotags. This function is |
| 9306 | * called while driver attach to the HBA and before the |
| 9307 | * interrupts are enabled. So there is no need for locking. |
| 9308 | * |
| 9309 | * This function always returns 0. |
| 9310 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9311 | int |
| 9312 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9313 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9314 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9315 | struct lpfc_sli *psli = &phba->sli; |
| 9316 | struct lpfc_sli_ring *pring; |
| 9317 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9318 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 9319 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9320 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9321 | psli->sli_flag = 0; |
| 9322 | psli->fcp_ring = LPFC_FCP_RING; |
| 9323 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9324 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9325 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9326 | psli->iocbq_lookup = NULL; |
| 9327 | psli->iocbq_lookup_len = 0; |
| 9328 | psli->last_iotag = 0; |
| 9329 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9330 | for (i = 0; i < psli->num_rings; i++) { |
| 9331 | pring = &psli->ring[i]; |
| 9332 | switch (i) { |
| 9333 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9334 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9335 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9336 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9337 | pring->sli.sli3.numCiocb += |
| 9338 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9339 | pring->sli.sli3.numRiocb += |
| 9340 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9341 | pring->sli.sli3.numCiocb += |
| 9342 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9343 | pring->sli.sli3.numRiocb += |
| 9344 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9345 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9346 | SLI3_IOCB_CMD_SIZE : |
| 9347 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9348 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9349 | SLI3_IOCB_RSP_SIZE : |
| 9350 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9351 | pring->iotag_ctr = 0; |
| 9352 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9353 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9354 | pring->fast_iotag = pring->iotag_max; |
| 9355 | pring->num_mask = 0; |
| 9356 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9357 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9358 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9359 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9360 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9361 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9362 | SLI3_IOCB_CMD_SIZE : |
| 9363 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9364 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9365 | SLI3_IOCB_RSP_SIZE : |
| 9366 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9367 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9368 | pring->num_mask = 0; |
| 9369 | break; |
| 9370 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9371 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9372 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9373 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9374 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9375 | SLI3_IOCB_CMD_SIZE : |
| 9376 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9377 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9378 | SLI3_IOCB_RSP_SIZE : |
| 9379 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9380 | pring->fast_iotag = 0; |
| 9381 | pring->iotag_ctr = 0; |
| 9382 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9383 | pring->lpfc_sli_rcv_async_status = |
| 9384 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9385 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9386 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9387 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9388 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9389 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9390 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9391 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9392 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9393 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9394 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9395 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9396 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9397 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9398 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9399 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9400 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9401 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9402 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9403 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9404 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9405 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9406 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9407 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9408 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9409 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9410 | break; |
| 9411 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9412 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9413 | pring->sli.sli3.sizeCiocb) + |
| 9414 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9415 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9416 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9417 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9418 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9419 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9420 | phba->brd_no, totiocbsize, |
| 9421 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9422 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9423 | if (phba->cfg_multi_ring_support == 2) |
| 9424 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9425 | |
| 9426 | return 0; |
| 9427 | } |
| 9428 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9429 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9430 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9431 | * @phba: Pointer to HBA context object. |
| 9432 | * |
| 9433 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 9434 | * ring. This function also initializes ring indices of each ring. |
| 9435 | * This function is called during the initialization of the SLI |
| 9436 | * interface of an HBA. |
| 9437 | * This function is called with no lock held and always returns |
| 9438 | * 1. |
| 9439 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9440 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9441 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9442 | { |
| 9443 | struct lpfc_sli *psli; |
| 9444 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9445 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9446 | |
| 9447 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9448 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9449 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9450 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9451 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9452 | for (i = 0; i < psli->num_rings; i++) { |
| 9453 | pring = &psli->ring[i]; |
| 9454 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9455 | pring->sli.sli3.next_cmdidx = 0; |
| 9456 | pring->sli.sli3.local_getidx = 0; |
| 9457 | pring->sli.sli3.cmdidx = 0; |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 9458 | pring->flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9459 | INIT_LIST_HEAD(&pring->txq); |
| 9460 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9461 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9462 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9463 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9464 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9465 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9466 | spin_unlock_irq(&phba->hbalock); |
| 9467 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9468 | } |
| 9469 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9470 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9471 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9472 | * @phba: Pointer to HBA context object. |
| 9473 | * |
| 9474 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9475 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9476 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9477 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9478 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9479 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9480 | * pending mailbox command queue from the various clients must be stopped; |
| 9481 | * either the HBA is in a state that it will never works on the outstanding |
| 9482 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9483 | * mailbox command has been completed. |
| 9484 | **/ |
| 9485 | static void |
| 9486 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 9487 | { |
| 9488 | LIST_HEAD(completions); |
| 9489 | struct lpfc_sli *psli = &phba->sli; |
| 9490 | LPFC_MBOXQ_t *pmb; |
| 9491 | unsigned long iflag; |
| 9492 | |
| 9493 | /* Flush all the mailbox commands in the mbox system */ |
| 9494 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9495 | /* The pending mailbox command queue */ |
| 9496 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9497 | /* The outstanding active mailbox command */ |
| 9498 | if (psli->mbox_active) { |
| 9499 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9500 | psli->mbox_active = NULL; |
| 9501 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9502 | } |
| 9503 | /* The completed mailbox command queue */ |
| 9504 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9505 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9506 | |
| 9507 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9508 | while (!list_empty(&completions)) { |
| 9509 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9510 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9511 | if (pmb->mbox_cmpl) |
| 9512 | pmb->mbox_cmpl(phba, pmb); |
| 9513 | } |
| 9514 | } |
| 9515 | |
| 9516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9517 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9518 | * @vport: Pointer to virtual port object. |
| 9519 | * |
| 9520 | * lpfc_sli_host_down is called to clean up the resources |
| 9521 | * associated with a vport before destroying virtual |
| 9522 | * port data structures. |
| 9523 | * This function does following operations: |
| 9524 | * - Free discovery resources associated with this virtual |
| 9525 | * port. |
| 9526 | * - Free iocbs associated with this virtual port in |
| 9527 | * the txq. |
| 9528 | * - Send abort for all iocb commands associated with this |
| 9529 | * vport in txcmplq. |
| 9530 | * |
| 9531 | * This function is called with no lock held and always returns 1. |
| 9532 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9533 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9534 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9535 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9536 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9537 | struct lpfc_hba *phba = vport->phba; |
| 9538 | struct lpfc_sli *psli = &phba->sli; |
| 9539 | struct lpfc_sli_ring *pring; |
| 9540 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9541 | int i; |
| 9542 | unsigned long flags = 0; |
| 9543 | uint16_t prev_pring_flag; |
| 9544 | |
| 9545 | lpfc_cleanup_discovery_resources(vport); |
| 9546 | |
| 9547 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9548 | for (i = 0; i < psli->num_rings; i++) { |
| 9549 | pring = &psli->ring[i]; |
| 9550 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9551 | /* Only slow rings */ |
| 9552 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9553 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9554 | /* Set the lpfc data pending flag */ |
| 9555 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9556 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9557 | /* |
| 9558 | * Error everything on the txq since these iocbs have not been |
| 9559 | * given to the FW yet. |
| 9560 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9561 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9562 | if (iocb->vport != vport) |
| 9563 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9564 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9565 | } |
| 9566 | |
| 9567 | /* Next issue ABTS for everything on the txcmplq */ |
| 9568 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9569 | list) { |
| 9570 | if (iocb->vport != vport) |
| 9571 | continue; |
| 9572 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9573 | } |
| 9574 | |
| 9575 | pring->flag = prev_pring_flag; |
| 9576 | } |
| 9577 | |
| 9578 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9579 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9580 | /* Cancel all the IOCBs from the completions list */ |
| 9581 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9582 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9583 | return 1; |
| 9584 | } |
| 9585 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9586 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9587 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9588 | * @phba: Pointer to HBA context object. |
| 9589 | * |
| 9590 | * This function cleans up all iocb, buffers, mailbox commands |
| 9591 | * while shutting down the HBA. This function is called with no |
| 9592 | * lock held and always returns 1. |
| 9593 | * This function does the following to cleanup driver resources: |
| 9594 | * - Free discovery resources for each virtual port |
| 9595 | * - Cleanup any pending fabric iocbs |
| 9596 | * - Iterate through the iocb txq and free each entry |
| 9597 | * in the list. |
| 9598 | * - Free up any buffer posted to the HBA |
| 9599 | * - Free mailbox commands in the mailbox queue. |
| 9600 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9601 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9602 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9603 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9604 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9605 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9606 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9607 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9608 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9609 | int i; |
| 9610 | |
| 9611 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9612 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9613 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9614 | lpfc_hba_down_prep(phba); |
| 9615 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9616 | lpfc_fabric_abort_hba(phba); |
| 9617 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9618 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9619 | for (i = 0; i < psli->num_rings; i++) { |
| 9620 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9621 | /* Only slow rings */ |
| 9622 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9623 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9624 | /* Set the lpfc data pending flag */ |
| 9625 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9627 | |
| 9628 | /* |
| 9629 | * Error everything on the txq since these iocbs have not been |
| 9630 | * given to the FW yet. |
| 9631 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9632 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9633 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9634 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9635 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9636 | /* Cancel all the IOCBs from the completions list */ |
| 9637 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9638 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9639 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9640 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9641 | list_splice_init(&phba->elsbuf, &completions); |
| 9642 | phba->elsbuf_cnt = 0; |
| 9643 | phba->elsbuf_prev_cnt = 0; |
| 9644 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9645 | |
| 9646 | while (!list_empty(&completions)) { |
| 9647 | list_remove_head(&completions, buf_ptr, |
| 9648 | struct lpfc_dmabuf, list); |
| 9649 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9650 | kfree(buf_ptr); |
| 9651 | } |
| 9652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9653 | /* Return any active mbox cmds */ |
| 9654 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9655 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9656 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9657 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9658 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9659 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9660 | return 1; |
| 9661 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9662 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9663 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9664 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9665 | * @srcp: Source memory pointer. |
| 9666 | * @destp: Destination memory pointer. |
| 9667 | * @cnt: Number of words required to be copied. |
| 9668 | * |
| 9669 | * This function is used for copying data between driver memory |
| 9670 | * and the SLI memory. This function also changes the endianness |
| 9671 | * of each word if native endianness is different from SLI |
| 9672 | * endianness. This function can be called with or without |
| 9673 | * lock. |
| 9674 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9675 | void |
| 9676 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9677 | { |
| 9678 | uint32_t *src = srcp; |
| 9679 | uint32_t *dest = destp; |
| 9680 | uint32_t ldata; |
| 9681 | int i; |
| 9682 | |
| 9683 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9684 | ldata = *src; |
| 9685 | ldata = le32_to_cpu(ldata); |
| 9686 | *dest = ldata; |
| 9687 | src++; |
| 9688 | dest++; |
| 9689 | } |
| 9690 | } |
| 9691 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9692 | |
| 9693 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9694 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9695 | * @srcp: Source memory pointer. |
| 9696 | * @destp: Destination memory pointer. |
| 9697 | * @cnt: Number of words required to be copied. |
| 9698 | * |
| 9699 | * This function is used for copying data between a data structure |
| 9700 | * with big endian representation to local endianness. |
| 9701 | * This function can be called with or without lock. |
| 9702 | **/ |
| 9703 | void |
| 9704 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9705 | { |
| 9706 | uint32_t *src = srcp; |
| 9707 | uint32_t *dest = destp; |
| 9708 | uint32_t ldata; |
| 9709 | int i; |
| 9710 | |
| 9711 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9712 | ldata = *src; |
| 9713 | ldata = be32_to_cpu(ldata); |
| 9714 | *dest = ldata; |
| 9715 | src++; |
| 9716 | dest++; |
| 9717 | } |
| 9718 | } |
| 9719 | |
| 9720 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9721 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9722 | * @phba: Pointer to HBA context object. |
| 9723 | * @pring: Pointer to driver SLI ring object. |
| 9724 | * @mp: Pointer to driver buffer object. |
| 9725 | * |
| 9726 | * This function is called with no lock held. |
| 9727 | * It always return zero after adding the buffer to the postbufq |
| 9728 | * buffer list. |
| 9729 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9730 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9731 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9732 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9733 | { |
| 9734 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9735 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9736 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9737 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9738 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9739 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9740 | return 0; |
| 9741 | } |
| 9742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9744 | * 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] | 9745 | * @phba: Pointer to HBA context object. |
| 9746 | * |
| 9747 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9748 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9749 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9750 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9751 | * The function returns the allocated tag. The function is called with |
| 9752 | * no locks held. |
| 9753 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9754 | uint32_t |
| 9755 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9756 | { |
| 9757 | spin_lock_irq(&phba->hbalock); |
| 9758 | phba->buffer_tag_count++; |
| 9759 | /* |
| 9760 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9761 | * a tag assigned by HBQ. |
| 9762 | */ |
| 9763 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9764 | spin_unlock_irq(&phba->hbalock); |
| 9765 | return phba->buffer_tag_count; |
| 9766 | } |
| 9767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9769 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9770 | * @phba: Pointer to HBA context object. |
| 9771 | * @pring: Pointer to driver SLI ring object. |
| 9772 | * @tag: Buffer tag. |
| 9773 | * |
| 9774 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9775 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9776 | * iocb is posted to the response ring with the tag of the buffer. |
| 9777 | * This function searches the pring->postbufq list using the tag |
| 9778 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9779 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9780 | * buffer is returned to the caller else NULL is returned. |
| 9781 | * This function is called with no lock held. |
| 9782 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9783 | struct lpfc_dmabuf * |
| 9784 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9785 | uint32_t tag) |
| 9786 | { |
| 9787 | struct lpfc_dmabuf *mp, *next_mp; |
| 9788 | struct list_head *slp = &pring->postbufq; |
| 9789 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9790 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9791 | spin_lock_irq(&phba->hbalock); |
| 9792 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9793 | if (mp->buffer_tag == tag) { |
| 9794 | list_del_init(&mp->list); |
| 9795 | pring->postbufq_cnt--; |
| 9796 | spin_unlock_irq(&phba->hbalock); |
| 9797 | return mp; |
| 9798 | } |
| 9799 | } |
| 9800 | |
| 9801 | spin_unlock_irq(&phba->hbalock); |
| 9802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9803 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9804 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9805 | pring->ringno, (unsigned long) tag, |
| 9806 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9807 | |
| 9808 | return NULL; |
| 9809 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9810 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9811 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9812 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9813 | * @phba: Pointer to HBA context object. |
| 9814 | * @pring: Pointer to driver SLI ring object. |
| 9815 | * @phys: DMA address of the buffer. |
| 9816 | * |
| 9817 | * This function searches the buffer list using the dma_address |
| 9818 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9819 | * corresponding to the dma_address. The function returns the |
| 9820 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9821 | * This function is called by the ct and els unsolicited event |
| 9822 | * handlers to get the buffer associated with the unsolicited |
| 9823 | * event. |
| 9824 | * |
| 9825 | * This function is called with no lock held. |
| 9826 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9827 | struct lpfc_dmabuf * |
| 9828 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9829 | dma_addr_t phys) |
| 9830 | { |
| 9831 | struct lpfc_dmabuf *mp, *next_mp; |
| 9832 | struct list_head *slp = &pring->postbufq; |
| 9833 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9834 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9835 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9836 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9837 | if (mp->phys == phys) { |
| 9838 | list_del_init(&mp->list); |
| 9839 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9840 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9841 | return mp; |
| 9842 | } |
| 9843 | } |
| 9844 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9845 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9846 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9847 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9848 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9849 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9850 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9851 | return NULL; |
| 9852 | } |
| 9853 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9854 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9855 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9856 | * @phba: Pointer to HBA context object. |
| 9857 | * @cmdiocb: Pointer to driver command iocb object. |
| 9858 | * @rspiocb: Pointer to driver response iocb object. |
| 9859 | * |
| 9860 | * This function is the completion handler for the abort iocbs for |
| 9861 | * ELS commands. This function is called from the ELS ring event |
| 9862 | * handler with no lock held. This function frees memory resources |
| 9863 | * associated with the abort iocb. |
| 9864 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9865 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9866 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9867 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9868 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9869 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9870 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9871 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9872 | |
| 9873 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9874 | |
| 9875 | /* |
| 9876 | * Assume that the port already completed and returned, or |
| 9877 | * will return the iocb. Just Log the message. |
| 9878 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9879 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9880 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9881 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9882 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9883 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9884 | if (abort_iotag != 0 && |
| 9885 | abort_iotag <= phba->sli.last_iotag) |
| 9886 | abort_iocb = |
| 9887 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9888 | } else |
| 9889 | /* For sli4 the abort_tag is the XRI, |
| 9890 | * so the abort routine puts the iotag of the iocb |
| 9891 | * being aborted in the context field of the abort |
| 9892 | * IOCB. |
| 9893 | */ |
| 9894 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9895 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9896 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9897 | "0327 Cannot abort els iocb %p " |
| 9898 | "with tag %x context %x, abort status %x, " |
| 9899 | "abort code %x\n", |
| 9900 | abort_iocb, abort_iotag, abort_context, |
| 9901 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9902 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9903 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9904 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9905 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9906 | return; |
| 9907 | } |
| 9908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9909 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9910 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9911 | * @phba: Pointer to HBA context object. |
| 9912 | * @cmdiocb: Pointer to driver command iocb object. |
| 9913 | * @rspiocb: Pointer to driver response iocb object. |
| 9914 | * |
| 9915 | * The function is called from SLI ring event handler with no |
| 9916 | * lock held. This function is the completion handler for ELS commands |
| 9917 | * which are aborted. The function frees memory resources used for |
| 9918 | * the aborted ELS commands. |
| 9919 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9920 | static void |
| 9921 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9922 | struct lpfc_iocbq *rspiocb) |
| 9923 | { |
| 9924 | IOCB_t *irsp = &rspiocb->iocb; |
| 9925 | |
| 9926 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9927 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9928 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9929 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9930 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9931 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9932 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9933 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9934 | else |
| 9935 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9936 | return; |
| 9937 | } |
| 9938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9939 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9940 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9941 | * @phba: Pointer to HBA context object. |
| 9942 | * @pring: Pointer to driver SLI ring object. |
| 9943 | * @cmdiocb: Pointer to driver command iocb object. |
| 9944 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9945 | * This function issues an abort iocb for the provided command iocb down to |
| 9946 | * the port. Other than the case the outstanding command iocb is an abort |
| 9947 | * request, this function issues abort out unconditionally. This function is |
| 9948 | * called with hbalock held. The function returns 0 when it fails due to |
| 9949 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9950 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9951 | static int |
| 9952 | 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] | 9953 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9954 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9955 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9956 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9957 | IOCB_t *icmd = NULL; |
| 9958 | IOCB_t *iabt = NULL; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9959 | int ring_number; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9960 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9961 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9962 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9963 | lockdep_assert_held(&phba->hbalock); |
| 9964 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9965 | /* |
| 9966 | * There are certain command types we don't want to abort. And we |
| 9967 | * don't want to abort commands that are already in the process of |
| 9968 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9969 | */ |
| 9970 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9971 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9972 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9973 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9974 | return 0; |
| 9975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9976 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9977 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9978 | if (abtsiocbp == NULL) |
| 9979 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9980 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9981 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9982 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9983 | */ |
| 9984 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9985 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9986 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9987 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9988 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9989 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9990 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9991 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9992 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9993 | else |
| 9994 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9995 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9996 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9997 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9998 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9999 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10000 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10001 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10002 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10003 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10004 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10005 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10006 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10007 | else |
| 10008 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10009 | |
| 10010 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 235d82c | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 10011 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10012 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10013 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10014 | "0339 Abort xri x%x, original iotag x%x, " |
| 10015 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10016 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10017 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10018 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10019 | |
| 10020 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10021 | ring_number = |
| 10022 | lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp); |
| 10023 | if (unlikely(ring_number == LPFC_HBA_ERROR)) |
| 10024 | return 0; |
| 10025 | pring = &phba->sli.ring[ring_number]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10026 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10027 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10028 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10029 | abtsiocbp, 0); |
| 10030 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10031 | } else { |
| 10032 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10033 | abtsiocbp, 0); |
| 10034 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10035 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10036 | if (retval) |
| 10037 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10038 | |
| 10039 | /* |
| 10040 | * Caller to this routine should check for IOCB_ERROR |
| 10041 | * and handle it properly. This routine no longer removes |
| 10042 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10043 | */ |
| 10044 | return retval; |
| 10045 | } |
| 10046 | |
| 10047 | /** |
| 10048 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10049 | * @phba: Pointer to HBA context object. |
| 10050 | * @pring: Pointer to driver SLI ring object. |
| 10051 | * @cmdiocb: Pointer to driver command iocb object. |
| 10052 | * |
| 10053 | * This function issues an abort iocb for the provided command iocb. In case |
| 10054 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10055 | * ring. Instead, the callback function shall be changed to those commands |
| 10056 | * so that nothing happens when them finishes. This function is called with |
| 10057 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10058 | * request. |
| 10059 | **/ |
| 10060 | int |
| 10061 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10062 | struct lpfc_iocbq *cmdiocb) |
| 10063 | { |
| 10064 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10065 | int retval = IOCB_ERROR; |
| 10066 | IOCB_t *icmd = NULL; |
| 10067 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10068 | lockdep_assert_held(&phba->hbalock); |
| 10069 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10070 | /* |
| 10071 | * There are certain command types we don't want to abort. And we |
| 10072 | * don't want to abort commands that are already in the process of |
| 10073 | * being aborted. |
| 10074 | */ |
| 10075 | icmd = &cmdiocb->iocb; |
| 10076 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10077 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10078 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10079 | return 0; |
| 10080 | |
| 10081 | /* |
| 10082 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10083 | * the callback so that nothing happens when it finishes. |
| 10084 | */ |
| 10085 | if ((vport->load_flag & FC_UNLOADING) && |
| 10086 | (pring->ringno == LPFC_ELS_RING)) { |
| 10087 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10088 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10089 | else |
| 10090 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10091 | goto abort_iotag_exit; |
| 10092 | } |
| 10093 | |
| 10094 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10095 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10096 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10097 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10098 | /* |
| 10099 | * Caller to this routine should check for IOCB_ERROR |
| 10100 | * and handle it properly. This routine no longer removes |
| 10101 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10102 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10103 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10104 | } |
| 10105 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10106 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10107 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10108 | * @phba: pointer to lpfc HBA data structure. |
| 10109 | * |
| 10110 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10111 | **/ |
| 10112 | void |
| 10113 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10114 | { |
| 10115 | struct lpfc_sli *psli = &phba->sli; |
| 10116 | struct lpfc_sli_ring *pring; |
| 10117 | int i; |
| 10118 | |
| 10119 | for (i = 0; i < psli->num_rings; i++) { |
| 10120 | pring = &psli->ring[i]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10121 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10122 | } |
| 10123 | } |
| 10124 | |
| 10125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10126 | * 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] | 10127 | * @iocbq: Pointer to driver iocb object. |
| 10128 | * @vport: Pointer to driver virtual port object. |
| 10129 | * @tgt_id: SCSI ID of the target. |
| 10130 | * @lun_id: LUN ID of the scsi device. |
| 10131 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10132 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10133 | * 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] | 10134 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10135 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10136 | * 1 if the filtering criteria is not met. |
| 10137 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10138 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10139 | * lun_id parameter. |
| 10140 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10141 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10142 | * parameters. |
| 10143 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10144 | * given iocb is for the SCSI host associated with the given vport. |
| 10145 | * This function is called with no locks held. |
| 10146 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10147 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10148 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10149 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10150 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10151 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10152 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10153 | int rc = 1; |
| 10154 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10155 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10156 | return rc; |
| 10157 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10158 | if (iocbq->vport != vport) |
| 10159 | return rc; |
| 10160 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10161 | 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] | 10162 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10163 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10164 | return rc; |
| 10165 | |
| 10166 | switch (ctx_cmd) { |
| 10167 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10168 | if ((lpfc_cmd->rdata->pnode) && |
| 10169 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10170 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10171 | rc = 0; |
| 10172 | break; |
| 10173 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10174 | if ((lpfc_cmd->rdata->pnode) && |
| 10175 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10176 | rc = 0; |
| 10177 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10178 | case LPFC_CTX_HOST: |
| 10179 | rc = 0; |
| 10180 | break; |
| 10181 | default: |
| 10182 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10183 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10184 | break; |
| 10185 | } |
| 10186 | |
| 10187 | return rc; |
| 10188 | } |
| 10189 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10191 | * 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] | 10192 | * @vport: Pointer to virtual port. |
| 10193 | * @tgt_id: SCSI ID of the target. |
| 10194 | * @lun_id: LUN ID of the scsi device. |
| 10195 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10196 | * |
| 10197 | * This function returns number of FCP commands pending for the vport. |
| 10198 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10199 | * commands pending on the vport associated with SCSI device specified |
| 10200 | * by tgt_id and lun_id parameters. |
| 10201 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10202 | * commands pending on the vport associated with SCSI target specified |
| 10203 | * by tgt_id parameter. |
| 10204 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10205 | * commands pending on the vport. |
| 10206 | * This function returns the number of iocbs which satisfy the filter. |
| 10207 | * This function is called without any lock held. |
| 10208 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10209 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10210 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10211 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10212 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10213 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10214 | struct lpfc_iocbq *iocbq; |
| 10215 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10216 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10217 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10218 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10219 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10220 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10221 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10222 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10223 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10224 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10225 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10227 | return sum; |
| 10228 | } |
| 10229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10231 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10232 | * @phba: Pointer to HBA context object |
| 10233 | * @cmdiocb: Pointer to command iocb object. |
| 10234 | * @rspiocb: Pointer to response iocb object. |
| 10235 | * |
| 10236 | * This function is called when an aborted FCP iocb completes. This |
| 10237 | * function is called by the ring event handler with no lock held. |
| 10238 | * This function frees the iocb. |
| 10239 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10240 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10241 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10242 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10243 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10244 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10245 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10246 | "original iotag x%x, abort cmd iotag x%x " |
| 10247 | "status 0x%x, reason 0x%x\n", |
| 10248 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10249 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10250 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10251 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10252 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10253 | return; |
| 10254 | } |
| 10255 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10257 | * 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] | 10258 | * @vport: Pointer to virtual port. |
| 10259 | * @pring: Pointer to driver SLI ring object. |
| 10260 | * @tgt_id: SCSI ID of the target. |
| 10261 | * @lun_id: LUN ID of the scsi device. |
| 10262 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10263 | * |
| 10264 | * This function sends an abort command for every SCSI command |
| 10265 | * associated with the given virtual port pending on the ring |
| 10266 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10267 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10268 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10269 | * parameters |
| 10270 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10271 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10272 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10273 | * FCP iocbs associated with virtual port. |
| 10274 | * This function returns number of iocbs it failed to abort. |
| 10275 | * This function is called with no locks held. |
| 10276 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10277 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10278 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10279 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10280 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10281 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10282 | struct lpfc_iocbq *iocbq; |
| 10283 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10284 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10285 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10286 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10287 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10288 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10289 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10290 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10291 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10292 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10293 | continue; |
| 10294 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10295 | /* |
| 10296 | * If the iocbq is already being aborted, don't take a second |
| 10297 | * action, but do count it. |
| 10298 | */ |
| 10299 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10300 | continue; |
| 10301 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10302 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10303 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10304 | if (abtsiocb == NULL) { |
| 10305 | errcnt++; |
| 10306 | continue; |
| 10307 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10308 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10309 | /* indicate the IO is being aborted by the driver. */ |
| 10310 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10311 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10312 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10313 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10314 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10315 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10316 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 10317 | else |
| 10318 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10319 | abtsiocb->iocb.ulpLe = 1; |
| 10320 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10321 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10322 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10323 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10324 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10325 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10326 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10327 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10328 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10329 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10330 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10331 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10332 | else |
| 10333 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10334 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10335 | /* Setup callback routine and issue the command. */ |
| 10336 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10337 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10338 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10339 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10340 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10341 | errcnt++; |
| 10342 | continue; |
| 10343 | } |
| 10344 | } |
| 10345 | |
| 10346 | return errcnt; |
| 10347 | } |
| 10348 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10349 | /** |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10350 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 10351 | * @vport: Pointer to virtual port. |
| 10352 | * @pring: Pointer to driver SLI ring object. |
| 10353 | * @tgt_id: SCSI ID of the target. |
| 10354 | * @lun_id: LUN ID of the scsi device. |
| 10355 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10356 | * |
| 10357 | * This function sends an abort command for every SCSI command |
| 10358 | * associated with the given virtual port pending on the ring |
| 10359 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10360 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10361 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10362 | * parameters |
| 10363 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10364 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10365 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10366 | * FCP iocbs associated with virtual port. |
| 10367 | * This function returns number of iocbs it aborted . |
| 10368 | * This function is called with no locks held right after a taskmgmt |
| 10369 | * command is sent. |
| 10370 | **/ |
| 10371 | int |
| 10372 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10373 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 10374 | { |
| 10375 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10376 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10377 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10378 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10379 | struct lpfc_iocbq *iocbq; |
| 10380 | IOCB_t *icmd; |
| 10381 | int sum, i, ret_val; |
| 10382 | unsigned long iflags; |
| 10383 | struct lpfc_sli_ring *pring_s4; |
| 10384 | uint32_t ring_number; |
| 10385 | |
| 10386 | spin_lock_irq(&phba->hbalock); |
| 10387 | |
| 10388 | /* all I/Os are in process of being flushed */ |
| 10389 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 10390 | spin_unlock_irq(&phba->hbalock); |
| 10391 | return 0; |
| 10392 | } |
| 10393 | sum = 0; |
| 10394 | |
| 10395 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10396 | iocbq = phba->sli.iocbq_lookup[i]; |
| 10397 | |
| 10398 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 10399 | cmd) != 0) |
| 10400 | continue; |
| 10401 | |
| 10402 | /* |
| 10403 | * If the iocbq is already being aborted, don't take a second |
| 10404 | * action, but do count it. |
| 10405 | */ |
| 10406 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10407 | continue; |
| 10408 | |
| 10409 | /* issue ABTS for this IOCB based on iotag */ |
| 10410 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 10411 | if (abtsiocbq == NULL) |
| 10412 | continue; |
| 10413 | |
| 10414 | icmd = &iocbq->iocb; |
| 10415 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10416 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 10417 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10418 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 10419 | iocbq->sli4_xritag; |
| 10420 | else |
| 10421 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 10422 | abtsiocbq->iocb.ulpLe = 1; |
| 10423 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 10424 | abtsiocbq->vport = vport; |
| 10425 | |
| 10426 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10427 | abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx; |
| 10428 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10429 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10430 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 10431 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10432 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 10433 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 10434 | ndlp = lpfc_cmd->rdata->pnode; |
| 10435 | |
| 10436 | if (lpfc_is_link_up(phba) && |
| 10437 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dd | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 10438 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10439 | else |
| 10440 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10441 | |
| 10442 | /* Setup callback routine and issue the command. */ |
| 10443 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 10444 | |
| 10445 | /* |
| 10446 | * Indicate the IO is being aborted by the driver and set |
| 10447 | * the caller's flag into the aborted IO. |
| 10448 | */ |
| 10449 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10450 | |
| 10451 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 10452 | ring_number = MAX_SLI3_CONFIGURED_RINGS + |
| 10453 | iocbq->fcp_wqidx; |
| 10454 | pring_s4 = &phba->sli.ring[ring_number]; |
| 10455 | /* Note: both hbalock and ring_lock must be set here */ |
| 10456 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 10457 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 10458 | abtsiocbq, 0); |
| 10459 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 10460 | } else { |
| 10461 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10462 | abtsiocbq, 0); |
| 10463 | } |
| 10464 | |
| 10465 | |
| 10466 | if (ret_val == IOCB_ERROR) |
| 10467 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 10468 | else |
| 10469 | sum++; |
| 10470 | } |
| 10471 | spin_unlock_irq(&phba->hbalock); |
| 10472 | return sum; |
| 10473 | } |
| 10474 | |
| 10475 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10476 | * 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] | 10477 | * @phba: Pointer to HBA context object. |
| 10478 | * @cmdiocbq: Pointer to command iocb. |
| 10479 | * @rspiocbq: Pointer to response iocb. |
| 10480 | * |
| 10481 | * This function is the completion handler for iocbs issued using |
| 10482 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 10483 | * ring event handler function without any lock held. This function |
| 10484 | * can be called from both worker thread context and interrupt |
| 10485 | * context. This function also can be called from other thread which |
| 10486 | * cleans up the SLI layer objects. |
| 10487 | * This function copy the contents of the response iocb to the |
| 10488 | * response iocb memory object provided by the caller of |
| 10489 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 10490 | * sleeps for the iocb completion. |
| 10491 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10492 | static void |
| 10493 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 10494 | struct lpfc_iocbq *cmdiocbq, |
| 10495 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10496 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10497 | wait_queue_head_t *pdone_q; |
| 10498 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10499 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10500 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10501 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10502 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 10503 | |
| 10504 | /* |
| 10505 | * A time out has occurred for the iocb. If a time out |
| 10506 | * completion handler has been supplied, call it. Otherwise, |
| 10507 | * just free the iocbq. |
| 10508 | */ |
| 10509 | |
| 10510 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10511 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 10512 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 10513 | if (cmdiocbq->iocb_cmpl) |
| 10514 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 10515 | else |
| 10516 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 10517 | return; |
| 10518 | } |
| 10519 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10520 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 10521 | if (cmdiocbq->context2 && rspiocbq) |
| 10522 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 10523 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 10524 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10525 | /* Set the exchange busy flag for task management commands */ |
| 10526 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 10527 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 10528 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 10529 | cur_iocbq); |
| 10530 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 10531 | } |
| 10532 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10533 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10534 | if (pdone_q) |
| 10535 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10536 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10537 | return; |
| 10538 | } |
| 10539 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10540 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10541 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 10542 | * @phba: Pointer to HBA context object.. |
| 10543 | * @piocbq: Pointer to command iocb. |
| 10544 | * @flag: Flag to test. |
| 10545 | * |
| 10546 | * This routine grabs the hbalock and then test the iocb_flag to |
| 10547 | * see if the passed in flag is set. |
| 10548 | * Returns: |
| 10549 | * 1 if flag is set. |
| 10550 | * 0 if flag is not set. |
| 10551 | **/ |
| 10552 | static int |
| 10553 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 10554 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 10555 | { |
| 10556 | unsigned long iflags; |
| 10557 | int ret; |
| 10558 | |
| 10559 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10560 | ret = piocbq->iocb_flag & flag; |
| 10561 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10562 | return ret; |
| 10563 | |
| 10564 | } |
| 10565 | |
| 10566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10567 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10568 | * @phba: Pointer to HBA context object.. |
| 10569 | * @pring: Pointer to sli ring. |
| 10570 | * @piocb: Pointer to command iocb. |
| 10571 | * @prspiocbq: Pointer to response iocb. |
| 10572 | * @timeout: Timeout in number of seconds. |
| 10573 | * |
| 10574 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10575 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 10576 | * to handle iocbs which time out. If the field is NULL, the |
| 10577 | * function shall free the iocbq structure. If more clean up is |
| 10578 | * needed, the caller is expected to provide a completion function |
| 10579 | * that will provide the needed clean up. If the iocb command is |
| 10580 | * not completed within timeout seconds, the function will either |
| 10581 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 10582 | * completion function set in the iocb_cmpl field and then return |
| 10583 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 10584 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10585 | * The function waits for the iocb completion using an |
| 10586 | * non-interruptible wait. |
| 10587 | * This function will sleep while waiting for iocb completion. |
| 10588 | * So, this function should not be called from any context which |
| 10589 | * does not allow sleeping. Due to the same reason, this function |
| 10590 | * cannot be called with interrupt disabled. |
| 10591 | * This function assumes that the iocb completions occur while |
| 10592 | * this function sleep. So, this function cannot be called from |
| 10593 | * the thread which process iocb completion for this ring. |
| 10594 | * This function clears the iocb_flag of the iocb object before |
| 10595 | * issuing the iocb and the iocb completion handler sets this |
| 10596 | * flag and wakes this thread when the iocb completes. |
| 10597 | * The contents of the response iocb will be copied to prspiocbq |
| 10598 | * by the completion handler when the command completes. |
| 10599 | * This function returns IOCB_SUCCESS when success. |
| 10600 | * This function is called with no lock held. |
| 10601 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10602 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10603 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10604 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10605 | struct lpfc_iocbq *piocb, |
| 10606 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10607 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10608 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10609 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10610 | long timeleft, timeout_req = 0; |
| 10611 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10612 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10613 | struct lpfc_iocbq *iocb; |
| 10614 | int txq_cnt = 0; |
| 10615 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10616 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10617 | unsigned long iflags; |
| 10618 | bool iocb_completed = true; |
| 10619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10620 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10621 | * If the caller has provided a response iocbq buffer, then context2 |
| 10622 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10623 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10624 | if (prspiocbq) { |
| 10625 | if (piocb->context2) |
| 10626 | return IOCB_ERROR; |
| 10627 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10628 | } |
| 10629 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10630 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10631 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 10632 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10633 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10634 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10635 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10636 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10637 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10638 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 10639 | writel(creg_val, phba->HCregaddr); |
| 10640 | readl(phba->HCregaddr); /* flush */ |
| 10641 | } |
| 10642 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10643 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10644 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10645 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10646 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10647 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10648 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10649 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10650 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10651 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10652 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10653 | /* |
| 10654 | * IOCB timed out. Inform the wake iocb wait |
| 10655 | * completion function and set local status |
| 10656 | */ |
| 10657 | |
| 10658 | iocb_completed = false; |
| 10659 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 10660 | } |
| 10661 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10662 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10663 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10664 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 10665 | /* Note: we are not indicating if the IOCB has a success |
| 10666 | * status or not - that's for the caller to check. |
| 10667 | * IOCB_SUCCESS means just that the command was sent and |
| 10668 | * completed. Not that it completed successfully. |
| 10669 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10670 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10671 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10672 | "0338 IOCB wait timeout error - no " |
| 10673 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10674 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10675 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10677 | "0330 IOCB wake NOT set, " |
| 10678 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10679 | timeout, (timeleft / jiffies)); |
| 10680 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10681 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10682 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10683 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10684 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10685 | txq_cnt++; |
| 10686 | } |
| 10687 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10688 | txcmplq_cnt++; |
| 10689 | } |
| 10690 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10691 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10692 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10693 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10694 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10695 | } else { |
| 10696 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10697 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10698 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10699 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10700 | } |
| 10701 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10702 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10703 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10704 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10705 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10706 | writel(creg_val, phba->HCregaddr); |
| 10707 | readl(phba->HCregaddr); /* flush */ |
| 10708 | } |
| 10709 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10710 | if (prspiocbq) |
| 10711 | piocb->context2 = NULL; |
| 10712 | |
| 10713 | piocb->context_un.wait_queue = NULL; |
| 10714 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10715 | return retval; |
| 10716 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10718 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10719 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10720 | * @phba: Pointer to HBA context object. |
| 10721 | * @pmboxq: Pointer to driver mailbox object. |
| 10722 | * @timeout: Timeout in number of seconds. |
| 10723 | * |
| 10724 | * This function issues the mailbox to firmware and waits for the |
| 10725 | * mailbox command to complete. If the mailbox command is not |
| 10726 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10727 | * The function waits for the mailbox completion using an |
| 10728 | * interruptible wait. If the thread is woken up due to a |
| 10729 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10730 | * should not free the mailbox resources, if this function returns |
| 10731 | * MBX_TIMEOUT. |
| 10732 | * This function will sleep while waiting for mailbox completion. |
| 10733 | * So, this function should not be called from any context which |
| 10734 | * does not allow sleeping. Due to the same reason, this function |
| 10735 | * cannot be called with interrupt disabled. |
| 10736 | * This function assumes that the mailbox completion occurs while |
| 10737 | * this function sleep. So, this function cannot be called from |
| 10738 | * the worker thread which processes mailbox completion. |
| 10739 | * This function is called in the context of HBA management |
| 10740 | * applications. |
| 10741 | * This function returns MBX_SUCCESS when successful. |
| 10742 | * This function is called with no lock held. |
| 10743 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10744 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10745 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10746 | uint32_t timeout) |
| 10747 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10748 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10749 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10750 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10751 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10752 | |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10753 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10754 | if (pmboxq->context1) |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10755 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10756 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10757 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10758 | /* setup wake call as IOCB callback */ |
| 10759 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10760 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10761 | pmboxq->context1 = &done_q; |
| 10762 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10763 | /* now issue the command */ |
| 10764 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10765 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10766 | wait_event_interruptible_timeout(done_q, |
| 10767 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10768 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10769 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10770 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10771 | /* restore the possible extended buffer for free resource */ |
| 10772 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10773 | /* |
| 10774 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10775 | * else do not free the resources. |
| 10776 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10777 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10778 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10779 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10780 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10781 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10782 | } |
| 10783 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10784 | } else { |
| 10785 | /* restore the possible extended buffer for free resource */ |
| 10786 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10787 | } |
| 10788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10789 | return retval; |
| 10790 | } |
| 10791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10792 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10793 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10794 | * @phba: Pointer to HBA context. |
| 10795 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10796 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10797 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10798 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10799 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10800 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10801 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10802 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10803 | * as with offline or HBA function reset), this routine will wait for the |
| 10804 | * outstanding mailbox command to complete before invoking the mailbox |
| 10805 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10806 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10807 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10808 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10809 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10810 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10811 | unsigned long timeout; |
| 10812 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10813 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10814 | /* delay 100ms for port state */ |
| 10815 | msleep(100); |
| 10816 | lpfc_sli_mbox_sys_flush(phba); |
| 10817 | return; |
| 10818 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10819 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10820 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10821 | spin_lock_irq(&phba->hbalock); |
| 10822 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10823 | |
| 10824 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10825 | /* Determine how long we might wait for the active mailbox |
| 10826 | * command to be gracefully completed by firmware. |
| 10827 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10828 | if (phba->sli.mbox_active) |
| 10829 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10830 | phba->sli.mbox_active) * |
| 10831 | 1000) + jiffies; |
| 10832 | spin_unlock_irq(&phba->hbalock); |
| 10833 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10834 | while (phba->sli.mbox_active) { |
| 10835 | /* Check active mailbox complete status every 2ms */ |
| 10836 | msleep(2); |
| 10837 | if (time_after(jiffies, timeout)) |
| 10838 | /* Timeout, let the mailbox flush routine to |
| 10839 | * forcefully release active mailbox command |
| 10840 | */ |
| 10841 | break; |
| 10842 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10843 | } else |
| 10844 | spin_unlock_irq(&phba->hbalock); |
| 10845 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10846 | lpfc_sli_mbox_sys_flush(phba); |
| 10847 | } |
| 10848 | |
| 10849 | /** |
| 10850 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10851 | * @phba: Pointer to HBA context. |
| 10852 | * |
| 10853 | * This function is called to read the SLI3 device error attention registers |
| 10854 | * for possible error attention events. The caller must hold the hostlock |
| 10855 | * with spin_lock_irq(). |
| 10856 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10857 | * 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] | 10858 | * Register and returns 0 otherwise. |
| 10859 | **/ |
| 10860 | static int |
| 10861 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10862 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10863 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10864 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10865 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10866 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10867 | goto unplug_err; |
| 10868 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10869 | if (ha_copy & HA_ERATT) { |
| 10870 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10871 | if (lpfc_sli_read_hs(phba)) |
| 10872 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10873 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10874 | /* Check if there is a deferred error condition is active */ |
| 10875 | if ((HS_FFER1 & phba->work_hs) && |
| 10876 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10877 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10878 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10879 | /* Clear all interrupt enable conditions */ |
| 10880 | writel(0, phba->HCregaddr); |
| 10881 | readl(phba->HCregaddr); |
| 10882 | } |
| 10883 | |
| 10884 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10885 | phba->work_ha |= HA_ERATT; |
| 10886 | /* Indicate polling handles this ERATT */ |
| 10887 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10888 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10889 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10890 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10891 | |
| 10892 | unplug_err: |
| 10893 | /* Set the driver HS work bitmap */ |
| 10894 | phba->work_hs |= UNPLUG_ERR; |
| 10895 | /* Set the driver HA work bitmap */ |
| 10896 | phba->work_ha |= HA_ERATT; |
| 10897 | /* Indicate polling handles this ERATT */ |
| 10898 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10899 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10900 | } |
| 10901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10902 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10903 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10904 | * @phba: Pointer to HBA context. |
| 10905 | * |
| 10906 | * This function is called to read the SLI4 device error attention registers |
| 10907 | * for possible error attention events. The caller must hold the hostlock |
| 10908 | * with spin_lock_irq(). |
| 10909 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10910 | * 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] | 10911 | * Register and returns 0 otherwise. |
| 10912 | **/ |
| 10913 | static int |
| 10914 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10915 | { |
| 10916 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10917 | uint32_t if_type, portsmphr; |
| 10918 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10919 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10920 | /* |
| 10921 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10922 | * registers for error attention. This can be changed later. |
| 10923 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10924 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10925 | switch (if_type) { |
| 10926 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10927 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10928 | &uerr_sta_lo) || |
| 10929 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10930 | &uerr_sta_hi)) { |
| 10931 | phba->work_hs |= UNPLUG_ERR; |
| 10932 | phba->work_ha |= HA_ERATT; |
| 10933 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10934 | return 1; |
| 10935 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10936 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10937 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10939 | "1423 HBA Unrecoverable error: " |
| 10940 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10941 | "ue_mask_lo_reg=0x%x, " |
| 10942 | "ue_mask_hi_reg=0x%x\n", |
| 10943 | uerr_sta_lo, uerr_sta_hi, |
| 10944 | phba->sli4_hba.ue_mask_lo, |
| 10945 | phba->sli4_hba.ue_mask_hi); |
| 10946 | phba->work_status[0] = uerr_sta_lo; |
| 10947 | phba->work_status[1] = uerr_sta_hi; |
| 10948 | phba->work_ha |= HA_ERATT; |
| 10949 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10950 | return 1; |
| 10951 | } |
| 10952 | break; |
| 10953 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10954 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10955 | &portstat_reg.word0) || |
| 10956 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10957 | &portsmphr)){ |
| 10958 | phba->work_hs |= UNPLUG_ERR; |
| 10959 | phba->work_ha |= HA_ERATT; |
| 10960 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10961 | return 1; |
| 10962 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10963 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10964 | phba->work_status[0] = |
| 10965 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10966 | phba->work_status[1] = |
| 10967 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10968 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10969 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10970 | "port status reg 0x%x, " |
| 10971 | "port smphr reg 0x%x, " |
| 10972 | "error 1=0x%x, error 2=0x%x\n", |
| 10973 | portstat_reg.word0, |
| 10974 | portsmphr, |
| 10975 | phba->work_status[0], |
| 10976 | phba->work_status[1]); |
| 10977 | phba->work_ha |= HA_ERATT; |
| 10978 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10979 | return 1; |
| 10980 | } |
| 10981 | break; |
| 10982 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10983 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10984 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10985 | "2886 HBA Error Attention on unsupported " |
| 10986 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10987 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10988 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10989 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10990 | return 0; |
| 10991 | } |
| 10992 | |
| 10993 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10994 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10995 | * @phba: Pointer to HBA context. |
| 10996 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10997 | * 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] | 10998 | * error attention register bit for error attention events. |
| 10999 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11000 | * 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] | 11001 | * Register and returns 0 otherwise. |
| 11002 | **/ |
| 11003 | int |
| 11004 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11005 | { |
| 11006 | uint32_t ha_copy; |
| 11007 | |
| 11008 | /* If somebody is waiting to handle an eratt, don't process it |
| 11009 | * here. The brdkill function will do this. |
| 11010 | */ |
| 11011 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11012 | return 0; |
| 11013 | |
| 11014 | /* Check if interrupt handler handles this ERATT */ |
| 11015 | spin_lock_irq(&phba->hbalock); |
| 11016 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11017 | /* Interrupt handler has handled ERATT */ |
| 11018 | spin_unlock_irq(&phba->hbalock); |
| 11019 | return 0; |
| 11020 | } |
| 11021 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11022 | /* |
| 11023 | * If there is deferred error attention, do not check for error |
| 11024 | * attention |
| 11025 | */ |
| 11026 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11027 | spin_unlock_irq(&phba->hbalock); |
| 11028 | return 0; |
| 11029 | } |
| 11030 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11031 | /* If PCI channel is offline, don't process it */ |
| 11032 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11033 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11034 | return 0; |
| 11035 | } |
| 11036 | |
| 11037 | switch (phba->sli_rev) { |
| 11038 | case LPFC_SLI_REV2: |
| 11039 | case LPFC_SLI_REV3: |
| 11040 | /* Read chip Host Attention (HA) register */ |
| 11041 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11042 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11043 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11044 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11045 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11046 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11047 | default: |
| 11048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11049 | "0299 Invalid SLI revision (%d)\n", |
| 11050 | phba->sli_rev); |
| 11051 | ha_copy = 0; |
| 11052 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11053 | } |
| 11054 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11055 | |
| 11056 | return ha_copy; |
| 11057 | } |
| 11058 | |
| 11059 | /** |
| 11060 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 11061 | * @phba: Pointer to HBA context. |
| 11062 | * |
| 11063 | * This inline routine checks whether a device or its PCI slot is in a state |
| 11064 | * that the interrupt should be handled. |
| 11065 | * |
| 11066 | * This function returns 0 if the device or the PCI slot is in a state that |
| 11067 | * interrupt should be handled, otherwise -EIO. |
| 11068 | */ |
| 11069 | static inline int |
| 11070 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 11071 | { |
| 11072 | /* If the pci channel is offline, ignore all the interrupts */ |
| 11073 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 11074 | return -EIO; |
| 11075 | |
| 11076 | /* Update device level interrupt statistics */ |
| 11077 | phba->sli.slistat.sli_intr++; |
| 11078 | |
| 11079 | /* Ignore all interrupts during initialization. */ |
| 11080 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11081 | return -EIO; |
| 11082 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11083 | return 0; |
| 11084 | } |
| 11085 | |
| 11086 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11087 | * 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] | 11088 | * @irq: Interrupt number. |
| 11089 | * @dev_id: The device context pointer. |
| 11090 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11091 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11092 | * service routine when device with SLI-3 interface spec is enabled with |
| 11093 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11094 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11095 | * interrupt mode, this function is called as part of the device-level |
| 11096 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11097 | * is undergoing initialization, the interrupt handler will not process |
| 11098 | * the interrupt. The link attention and ELS ring attention events are |
| 11099 | * handled by the worker thread. The interrupt handler signals the worker |
| 11100 | * thread and returns for these events. This function is called without |
| 11101 | * 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] | 11102 | * structures. |
| 11103 | * |
| 11104 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11105 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11106 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11107 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11108 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11109 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11110 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11111 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11112 | uint32_t work_ha_copy; |
| 11113 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11114 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11115 | uint32_t control; |
| 11116 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11117 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11118 | struct lpfc_vport *vport; |
| 11119 | struct lpfc_nodelist *ndlp; |
| 11120 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11121 | LPFC_MBOXQ_t *pmb; |
| 11122 | int rc; |
| 11123 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11124 | /* |
| 11125 | * Get the driver's phba structure from the dev_id and |
| 11126 | * assume the HBA is not interrupting. |
| 11127 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11128 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11129 | |
| 11130 | if (unlikely(!phba)) |
| 11131 | return IRQ_NONE; |
| 11132 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11133 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11134 | * Stuff needs to be attented to when this function is invoked as an |
| 11135 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11136 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11137 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11138 | /* Check device state for handling interrupt */ |
| 11139 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11140 | return IRQ_NONE; |
| 11141 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11142 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11143 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11144 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11145 | /* If somebody is waiting to handle an eratt don't process it |
| 11146 | * here. The brdkill function will do this. |
| 11147 | */ |
| 11148 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11149 | ha_copy &= ~HA_ERATT; |
| 11150 | /* Check the need for handling ERATT in interrupt handler */ |
| 11151 | if (ha_copy & HA_ERATT) { |
| 11152 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11153 | /* ERATT polling has handled ERATT */ |
| 11154 | ha_copy &= ~HA_ERATT; |
| 11155 | else |
| 11156 | /* Indicate interrupt handler handles ERATT */ |
| 11157 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11158 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11159 | |
| 11160 | /* |
| 11161 | * If there is deferred error attention, do not check for any |
| 11162 | * interrupt. |
| 11163 | */ |
| 11164 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11165 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11166 | return IRQ_NONE; |
| 11167 | } |
| 11168 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11169 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11170 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11171 | goto unplug_error; |
| 11172 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11173 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11174 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11175 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11176 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11177 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11178 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11179 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11180 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11181 | } else |
| 11182 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11184 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11185 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11186 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11187 | if (work_ha_copy & HA_LATT) { |
| 11188 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11189 | /* |
| 11190 | * Turn off Link Attention interrupts |
| 11191 | * until CLEAR_LA done |
| 11192 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11193 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11194 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11195 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11196 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11197 | control &= ~HC_LAINT_ENA; |
| 11198 | writel(control, phba->HCregaddr); |
| 11199 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11200 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11201 | } |
| 11202 | else |
| 11203 | work_ha_copy &= ~HA_LATT; |
| 11204 | } |
| 11205 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11206 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11207 | /* |
| 11208 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11209 | * the only slow ring. |
| 11210 | */ |
| 11211 | status = (work_ha_copy & |
| 11212 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11213 | status >>= (4*LPFC_ELS_RING); |
| 11214 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11215 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11216 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11217 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11218 | |
| 11219 | lpfc_debugfs_slow_ring_trc(phba, |
| 11220 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11221 | control, status, |
| 11222 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11223 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11224 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11225 | lpfc_debugfs_slow_ring_trc(phba, |
| 11226 | "ISR Disable ring:" |
| 11227 | "pwork:x%x hawork:x%x wait:x%x", |
| 11228 | phba->work_ha, work_ha_copy, |
| 11229 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11230 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11231 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11232 | control &= |
| 11233 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11234 | writel(control, phba->HCregaddr); |
| 11235 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11236 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11237 | else { |
| 11238 | lpfc_debugfs_slow_ring_trc(phba, |
| 11239 | "ISR slow ring: pwork:" |
| 11240 | "x%x hawork:x%x wait:x%x", |
| 11241 | phba->work_ha, work_ha_copy, |
| 11242 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11243 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11244 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11245 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11246 | } |
| 11247 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11248 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11249 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11250 | if (lpfc_sli_read_hs(phba)) |
| 11251 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11252 | /* |
| 11253 | * Check if there is a deferred error condition |
| 11254 | * is active |
| 11255 | */ |
| 11256 | if ((HS_FFER1 & phba->work_hs) && |
| 11257 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11258 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11259 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11260 | phba->hba_flag |= DEFER_ERATT; |
| 11261 | /* Clear all interrupt enable conditions */ |
| 11262 | writel(0, phba->HCregaddr); |
| 11263 | readl(phba->HCregaddr); |
| 11264 | } |
| 11265 | } |
| 11266 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11267 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11268 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11269 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11270 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11271 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11272 | |
| 11273 | /* First check out the status word */ |
| 11274 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11275 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11276 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11277 | /* |
| 11278 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 11279 | * mbxStatus <status> |
| 11280 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11281 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11282 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11283 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11284 | "Interrupt mbxCommand x%x " |
| 11285 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11286 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11287 | pmbox->mbxCommand, |
| 11288 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11289 | /* clear mailbox attention bit */ |
| 11290 | work_ha_copy &= ~HA_MBATT; |
| 11291 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11292 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11293 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11294 | phba->last_completion_time = jiffies; |
| 11295 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11296 | if (pmb->mbox_cmpl) { |
| 11297 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 11298 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 11299 | if (pmb->out_ext_byte_len && |
| 11300 | pmb->context2) |
| 11301 | lpfc_sli_pcimem_bcopy( |
| 11302 | phba->mbox_ext, |
| 11303 | pmb->context2, |
| 11304 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11305 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11306 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11307 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11308 | |
| 11309 | lpfc_debugfs_disc_trc(vport, |
| 11310 | LPFC_DISC_TRC_MBOX_VPORT, |
| 11311 | "MBOX dflt rpi: : " |
| 11312 | "status:x%x rpi:x%x", |
| 11313 | (uint32_t)pmbox->mbxStatus, |
| 11314 | pmbox->un.varWords[0], 0); |
| 11315 | |
| 11316 | if (!pmbox->mbxStatus) { |
| 11317 | mp = (struct lpfc_dmabuf *) |
| 11318 | (pmb->context1); |
| 11319 | ndlp = (struct lpfc_nodelist *) |
| 11320 | pmb->context2; |
| 11321 | |
| 11322 | /* Reg_LOGIN of dflt RPI was |
| 11323 | * successful. new lets get |
| 11324 | * rid of the RPI using the |
| 11325 | * same mbox buffer. |
| 11326 | */ |
| 11327 | lpfc_unreg_login(phba, |
| 11328 | vport->vpi, |
| 11329 | pmbox->un.varWords[0], |
| 11330 | pmb); |
| 11331 | pmb->mbox_cmpl = |
| 11332 | lpfc_mbx_cmpl_dflt_rpi; |
| 11333 | pmb->context1 = mp; |
| 11334 | pmb->context2 = ndlp; |
| 11335 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11336 | rc = lpfc_sli_issue_mbox(phba, |
| 11337 | pmb, |
| 11338 | MBX_NOWAIT); |
| 11339 | if (rc != MBX_BUSY) |
| 11340 | lpfc_printf_log(phba, |
| 11341 | KERN_ERR, |
| 11342 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11343 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11344 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11345 | if (rc != MBX_NOT_FINISHED) |
| 11346 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11347 | } |
| 11348 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11349 | spin_lock_irqsave( |
| 11350 | &phba->pport->work_port_lock, |
| 11351 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11352 | phba->pport->work_port_events &= |
| 11353 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11354 | spin_unlock_irqrestore( |
| 11355 | &phba->pport->work_port_lock, |
| 11356 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11357 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11358 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11359 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11360 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11361 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11362 | if ((work_ha_copy & HA_MBATT) && |
| 11363 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11364 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11365 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11366 | do { |
| 11367 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 11368 | MBX_NOWAIT); |
| 11369 | } while (rc == MBX_NOT_FINISHED); |
| 11370 | if (rc != MBX_SUCCESS) |
| 11371 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11372 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11373 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11374 | } |
| 11375 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11376 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11377 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11378 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11379 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11380 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11381 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11382 | unplug_error: |
| 11383 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 11384 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11385 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11386 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11387 | |
| 11388 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11389 | * 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] | 11390 | * @irq: Interrupt number. |
| 11391 | * @dev_id: The device context pointer. |
| 11392 | * |
| 11393 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11394 | * service routine when device with SLI-3 interface spec is enabled with |
| 11395 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 11396 | * ring event in the HBA. However, when the device is enabled with either |
| 11397 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 11398 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 11399 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 11400 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 11401 | * the intrrupt context. This function is called without any lock held. |
| 11402 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11403 | * |
| 11404 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11405 | * returns IRQ_NONE. |
| 11406 | **/ |
| 11407 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11408 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11409 | { |
| 11410 | struct lpfc_hba *phba; |
| 11411 | uint32_t ha_copy; |
| 11412 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11413 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11414 | |
| 11415 | /* Get the driver's phba structure from the dev_id and |
| 11416 | * assume the HBA is not interrupting. |
| 11417 | */ |
| 11418 | phba = (struct lpfc_hba *) dev_id; |
| 11419 | |
| 11420 | if (unlikely(!phba)) |
| 11421 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11422 | |
| 11423 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11424 | * Stuff needs to be attented to when this function is invoked as an |
| 11425 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11426 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11427 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11428 | /* Check device state for handling interrupt */ |
| 11429 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11430 | return IRQ_NONE; |
| 11431 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11432 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11433 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11434 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11435 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11436 | /* |
| 11437 | * If there is deferred error attention, do not check for |
| 11438 | * any interrupt. |
| 11439 | */ |
| 11440 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11441 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11442 | return IRQ_NONE; |
| 11443 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11444 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 11445 | phba->HAregaddr); |
| 11446 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11447 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11448 | } else |
| 11449 | ha_copy = phba->ha_copy; |
| 11450 | |
| 11451 | /* |
| 11452 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 11453 | */ |
| 11454 | ha_copy &= ~(phba->work_ha_mask); |
| 11455 | |
| 11456 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11457 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11458 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11459 | lpfc_sli_handle_fast_ring_event(phba, |
| 11460 | &phba->sli.ring[LPFC_FCP_RING], |
| 11461 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11462 | |
| 11463 | if (phba->cfg_multi_ring_support == 2) { |
| 11464 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11465 | * Process all events on extra ring. Take the optimized path |
| 11466 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11467 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11468 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11469 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11470 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11471 | lpfc_sli_handle_fast_ring_event(phba, |
| 11472 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 11473 | status); |
| 11474 | } |
| 11475 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11476 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11477 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11478 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11479 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11480 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11481 | * @irq: Interrupt number. |
| 11482 | * @dev_id: The device context pointer. |
| 11483 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11484 | * This function is the HBA device-level interrupt handler to device with |
| 11485 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 11486 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 11487 | * requires driver attention. This function invokes the slow-path interrupt |
| 11488 | * attention handling function and fast-path interrupt attention handling |
| 11489 | * function in turn to process the relevant HBA attention events. This |
| 11490 | * function is called without any lock held. It gets the hbalock to access |
| 11491 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11492 | * |
| 11493 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11494 | * returns IRQ_NONE. |
| 11495 | **/ |
| 11496 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11497 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11498 | { |
| 11499 | struct lpfc_hba *phba; |
| 11500 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11501 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11502 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11503 | |
| 11504 | /* |
| 11505 | * Get the driver's phba structure from the dev_id and |
| 11506 | * assume the HBA is not interrupting. |
| 11507 | */ |
| 11508 | phba = (struct lpfc_hba *) dev_id; |
| 11509 | |
| 11510 | if (unlikely(!phba)) |
| 11511 | return IRQ_NONE; |
| 11512 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11513 | /* Check device state for handling interrupt */ |
| 11514 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11515 | return IRQ_NONE; |
| 11516 | |
| 11517 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11518 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 11519 | spin_unlock(&phba->hbalock); |
| 11520 | return IRQ_HANDLED; |
| 11521 | } |
| 11522 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11523 | if (unlikely(!phba->ha_copy)) { |
| 11524 | spin_unlock(&phba->hbalock); |
| 11525 | return IRQ_NONE; |
| 11526 | } else if (phba->ha_copy & HA_ERATT) { |
| 11527 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11528 | /* ERATT polling has handled ERATT */ |
| 11529 | phba->ha_copy &= ~HA_ERATT; |
| 11530 | else |
| 11531 | /* Indicate interrupt handler handles ERATT */ |
| 11532 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11533 | } |
| 11534 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11535 | /* |
| 11536 | * If there is deferred error attention, do not check for any interrupt. |
| 11537 | */ |
| 11538 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 11539 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11540 | return IRQ_NONE; |
| 11541 | } |
| 11542 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11543 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11544 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 11545 | spin_unlock(&phba->hbalock); |
| 11546 | return IRQ_HANDLED; |
| 11547 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11548 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 11549 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11550 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11551 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11552 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11553 | readl(phba->HAregaddr); /* flush */ |
| 11554 | spin_unlock(&phba->hbalock); |
| 11555 | |
| 11556 | /* |
| 11557 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11558 | */ |
| 11559 | |
| 11560 | /* status of events with mailbox and link attention */ |
| 11561 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 11562 | |
| 11563 | /* status of events with ELS ring */ |
| 11564 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11565 | status2 >>= (4*LPFC_ELS_RING); |
| 11566 | |
| 11567 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11568 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11569 | else |
| 11570 | sp_irq_rc = IRQ_NONE; |
| 11571 | |
| 11572 | /* |
| 11573 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11574 | */ |
| 11575 | |
| 11576 | /* status of events with FCP ring */ |
| 11577 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 11578 | status1 >>= (4*LPFC_FCP_RING); |
| 11579 | |
| 11580 | /* status of events with extra ring */ |
| 11581 | if (phba->cfg_multi_ring_support == 2) { |
| 11582 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 11583 | status2 >>= (4*LPFC_EXTRA_RING); |
| 11584 | } else |
| 11585 | status2 = 0; |
| 11586 | |
| 11587 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11588 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11589 | else |
| 11590 | fp_irq_rc = IRQ_NONE; |
| 11591 | |
| 11592 | /* Return device-level interrupt handling status */ |
| 11593 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11594 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11595 | |
| 11596 | /** |
| 11597 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 11598 | * @phba: pointer to lpfc hba data structure. |
| 11599 | * |
| 11600 | * This routine is invoked by the worker thread to process all the pending |
| 11601 | * SLI4 FCP abort XRI events. |
| 11602 | **/ |
| 11603 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11604 | { |
| 11605 | struct lpfc_cq_event *cq_event; |
| 11606 | |
| 11607 | /* First, declare the fcp xri abort event has been handled */ |
| 11608 | spin_lock_irq(&phba->hbalock); |
| 11609 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 11610 | spin_unlock_irq(&phba->hbalock); |
| 11611 | /* Now, handle all the fcp xri abort events */ |
| 11612 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 11613 | /* Get the first event from the head of the event queue */ |
| 11614 | spin_lock_irq(&phba->hbalock); |
| 11615 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 11616 | cq_event, struct lpfc_cq_event, list); |
| 11617 | spin_unlock_irq(&phba->hbalock); |
| 11618 | /* Notify aborted XRI for FCP work queue */ |
| 11619 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11620 | /* Free the event processed back to the free pool */ |
| 11621 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11622 | } |
| 11623 | } |
| 11624 | |
| 11625 | /** |
| 11626 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 11627 | * @phba: pointer to lpfc hba data structure. |
| 11628 | * |
| 11629 | * This routine is invoked by the worker thread to process all the pending |
| 11630 | * SLI4 els abort xri events. |
| 11631 | **/ |
| 11632 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11633 | { |
| 11634 | struct lpfc_cq_event *cq_event; |
| 11635 | |
| 11636 | /* First, declare the els xri abort event has been handled */ |
| 11637 | spin_lock_irq(&phba->hbalock); |
| 11638 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 11639 | spin_unlock_irq(&phba->hbalock); |
| 11640 | /* Now, handle all the els xri abort events */ |
| 11641 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 11642 | /* Get the first event from the head of the event queue */ |
| 11643 | spin_lock_irq(&phba->hbalock); |
| 11644 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11645 | cq_event, struct lpfc_cq_event, list); |
| 11646 | spin_unlock_irq(&phba->hbalock); |
| 11647 | /* Notify aborted XRI for ELS work queue */ |
| 11648 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11649 | /* Free the event processed back to the free pool */ |
| 11650 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11651 | } |
| 11652 | } |
| 11653 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11654 | /** |
| 11655 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 11656 | * @phba: pointer to lpfc hba data structure |
| 11657 | * @pIocbIn: pointer to the rspiocbq |
| 11658 | * @pIocbOut: pointer to the cmdiocbq |
| 11659 | * @wcqe: pointer to the complete wcqe |
| 11660 | * |
| 11661 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11662 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11663 | * completion status information from the complete wcqe. |
| 11664 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11665 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11666 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11667 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11668 | struct lpfc_iocbq *pIocbOut, |
| 11669 | struct lpfc_wcqe_complete *wcqe) |
| 11670 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11671 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11672 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11673 | uint32_t status, max_response; |
| 11674 | struct lpfc_dmabuf *dmabuf; |
| 11675 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11676 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11677 | |
| 11678 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11679 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11680 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11681 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11682 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11683 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11684 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11685 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11686 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11687 | wcqe->total_data_placed; |
| 11688 | else |
| 11689 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11690 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11691 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11692 | switch (pIocbOut->iocb.ulpCommand) { |
| 11693 | case CMD_ELS_REQUEST64_CR: |
| 11694 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11695 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11696 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 11697 | max_response = bde.tus.f.bdeSize; |
| 11698 | break; |
| 11699 | case CMD_GEN_REQUEST64_CR: |
| 11700 | max_response = 0; |
| 11701 | if (!pIocbOut->context3) |
| 11702 | break; |
| 11703 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 11704 | sizeof(struct ulp_bde64); |
| 11705 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11706 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11707 | for (i = 0; i < numBdes; i++) { |
| 11708 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 11709 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 11710 | max_response += bde.tus.f.bdeSize; |
| 11711 | } |
| 11712 | break; |
| 11713 | default: |
| 11714 | max_response = wcqe->total_data_placed; |
| 11715 | break; |
| 11716 | } |
| 11717 | if (max_response < wcqe->total_data_placed) |
| 11718 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 11719 | else |
| 11720 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 11721 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11722 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11723 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11724 | /* Convert BG errors for completion status */ |
| 11725 | if (status == CQE_STATUS_DI_ERROR) { |
| 11726 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11727 | |
| 11728 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11729 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11730 | else |
| 11731 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11732 | |
| 11733 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11734 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11735 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11736 | BGS_GUARD_ERR_MASK; |
| 11737 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11738 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11739 | BGS_APPTAG_ERR_MASK; |
| 11740 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11741 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11742 | BGS_REFTAG_ERR_MASK; |
| 11743 | |
| 11744 | /* Check to see if there was any good data before the error */ |
| 11745 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11746 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11747 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11748 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11749 | wcqe->total_data_placed; |
| 11750 | } |
| 11751 | |
| 11752 | /* |
| 11753 | * Set ALL the error bits to indicate we don't know what |
| 11754 | * type of error it is. |
| 11755 | */ |
| 11756 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11757 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11758 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11759 | BGS_GUARD_ERR_MASK); |
| 11760 | } |
| 11761 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11762 | /* Pick up HBA exchange busy condition */ |
| 11763 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11764 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11765 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11766 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11767 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11768 | } |
| 11769 | |
| 11770 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11771 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11772 | * @phba: Pointer to HBA context object. |
| 11773 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11774 | * |
| 11775 | * This routine handles an ELS work-queue completion event and construct |
| 11776 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11777 | * discovery engine to handle. |
| 11778 | * |
| 11779 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11780 | **/ |
| 11781 | static struct lpfc_iocbq * |
| 11782 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11783 | struct lpfc_iocbq *irspiocbq) |
| 11784 | { |
| 11785 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11786 | struct lpfc_iocbq *cmdiocbq; |
| 11787 | struct lpfc_wcqe_complete *wcqe; |
| 11788 | unsigned long iflags; |
| 11789 | |
| 11790 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11791 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11792 | pring->stats.iocb_event++; |
| 11793 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11794 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11795 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11796 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11797 | |
| 11798 | if (unlikely(!cmdiocbq)) { |
| 11799 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11800 | "0386 ELS complete with no corresponding " |
| 11801 | "cmdiocb: iotag (%d)\n", |
| 11802 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11803 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11804 | return NULL; |
| 11805 | } |
| 11806 | |
| 11807 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11808 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11809 | |
| 11810 | return irspiocbq; |
| 11811 | } |
| 11812 | |
| 11813 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11814 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11815 | * @phba: Pointer to HBA context object. |
| 11816 | * @cqe: Pointer to mailbox completion queue entry. |
| 11817 | * |
| 11818 | * This routine process a mailbox completion queue entry with asynchrous |
| 11819 | * event. |
| 11820 | * |
| 11821 | * Return: true if work posted to worker thread, otherwise false. |
| 11822 | **/ |
| 11823 | static bool |
| 11824 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11825 | { |
| 11826 | struct lpfc_cq_event *cq_event; |
| 11827 | unsigned long iflags; |
| 11828 | |
| 11829 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11830 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11831 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11832 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11833 | |
| 11834 | /* Allocate a new internal CQ_EVENT entry */ |
| 11835 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11836 | if (!cq_event) { |
| 11837 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11838 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11839 | return false; |
| 11840 | } |
| 11841 | |
| 11842 | /* Move the CQE into an asynchronous event entry */ |
| 11843 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11844 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11845 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11846 | /* Set the async event flag */ |
| 11847 | phba->hba_flag |= ASYNC_EVENT; |
| 11848 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11849 | |
| 11850 | return true; |
| 11851 | } |
| 11852 | |
| 11853 | /** |
| 11854 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11855 | * @phba: Pointer to HBA context object. |
| 11856 | * @cqe: Pointer to mailbox completion queue entry. |
| 11857 | * |
| 11858 | * This routine process a mailbox completion queue entry with mailbox |
| 11859 | * completion event. |
| 11860 | * |
| 11861 | * Return: true if work posted to worker thread, otherwise false. |
| 11862 | **/ |
| 11863 | static bool |
| 11864 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11865 | { |
| 11866 | uint32_t mcqe_status; |
| 11867 | MAILBOX_t *mbox, *pmbox; |
| 11868 | struct lpfc_mqe *mqe; |
| 11869 | struct lpfc_vport *vport; |
| 11870 | struct lpfc_nodelist *ndlp; |
| 11871 | struct lpfc_dmabuf *mp; |
| 11872 | unsigned long iflags; |
| 11873 | LPFC_MBOXQ_t *pmb; |
| 11874 | bool workposted = false; |
| 11875 | int rc; |
| 11876 | |
| 11877 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11878 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11879 | goto out_no_mqe_complete; |
| 11880 | |
| 11881 | /* Get the reference to the active mbox command */ |
| 11882 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11883 | pmb = phba->sli.mbox_active; |
| 11884 | if (unlikely(!pmb)) { |
| 11885 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11886 | "1832 No pending MBOX command to handle\n"); |
| 11887 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11888 | goto out_no_mqe_complete; |
| 11889 | } |
| 11890 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11891 | mqe = &pmb->u.mqe; |
| 11892 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11893 | mbox = phba->mbox; |
| 11894 | vport = pmb->vport; |
| 11895 | |
| 11896 | /* Reset heartbeat timer */ |
| 11897 | phba->last_completion_time = jiffies; |
| 11898 | del_timer(&phba->sli.mbox_tmo); |
| 11899 | |
| 11900 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11901 | if (pmb->mbox_cmpl && mbox) |
| 11902 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11903 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11904 | /* |
| 11905 | * For mcqe errors, conditionally move a modified error code to |
| 11906 | * the mbox so that the error will not be missed. |
| 11907 | */ |
| 11908 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11909 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11910 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11911 | bf_set(lpfc_mqe_status, mqe, |
| 11912 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11913 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11914 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11915 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11916 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11917 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11918 | mcqe_status, |
| 11919 | pmbox->un.varWords[0], 0); |
| 11920 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11921 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11922 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11923 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11924 | * RID of the PPI using the same mbox buffer. |
| 11925 | */ |
| 11926 | lpfc_unreg_login(phba, vport->vpi, |
| 11927 | pmbox->un.varWords[0], pmb); |
| 11928 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11929 | pmb->context1 = mp; |
| 11930 | pmb->context2 = ndlp; |
| 11931 | pmb->vport = vport; |
| 11932 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11933 | if (rc != MBX_BUSY) |
| 11934 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11935 | LOG_SLI, "0385 rc should " |
| 11936 | "have been MBX_BUSY\n"); |
| 11937 | if (rc != MBX_NOT_FINISHED) |
| 11938 | goto send_current_mbox; |
| 11939 | } |
| 11940 | } |
| 11941 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11942 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11943 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11944 | |
| 11945 | /* There is mailbox completion work to do */ |
| 11946 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11947 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11948 | phba->work_ha |= HA_MBATT; |
| 11949 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11950 | workposted = true; |
| 11951 | |
| 11952 | send_current_mbox: |
| 11953 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11954 | /* Release the mailbox command posting token */ |
| 11955 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11956 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11957 | phba->sli.mbox_active = NULL; |
| 11958 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11959 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11960 | lpfc_worker_wake_up(phba); |
| 11961 | out_no_mqe_complete: |
| 11962 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11963 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11964 | return workposted; |
| 11965 | } |
| 11966 | |
| 11967 | /** |
| 11968 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11969 | * @phba: Pointer to HBA context object. |
| 11970 | * @cqe: Pointer to mailbox completion queue entry. |
| 11971 | * |
| 11972 | * This routine process a mailbox completion queue entry, it invokes the |
| 11973 | * proper mailbox complete handling or asynchrous event handling routine |
| 11974 | * according to the MCQE's async bit. |
| 11975 | * |
| 11976 | * Return: true if work posted to worker thread, otherwise false. |
| 11977 | **/ |
| 11978 | static bool |
| 11979 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11980 | { |
| 11981 | struct lpfc_mcqe mcqe; |
| 11982 | bool workposted; |
| 11983 | |
| 11984 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11985 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11986 | |
| 11987 | /* Invoke the proper event handling routine */ |
| 11988 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11989 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11990 | else |
| 11991 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11992 | return workposted; |
| 11993 | } |
| 11994 | |
| 11995 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11996 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11997 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11998 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11999 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12000 | * |
| 12001 | * This routine handles an ELS work-queue completion event. |
| 12002 | * |
| 12003 | * Return: true if work posted to worker thread, otherwise false. |
| 12004 | **/ |
| 12005 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12006 | 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] | 12007 | struct lpfc_wcqe_complete *wcqe) |
| 12008 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12009 | struct lpfc_iocbq *irspiocbq; |
| 12010 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12011 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12012 | int txq_cnt = 0; |
| 12013 | int txcmplq_cnt = 0; |
| 12014 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12015 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12016 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12017 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12018 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12019 | if (!list_empty(&pring->txq)) |
| 12020 | txq_cnt++; |
| 12021 | if (!list_empty(&pring->txcmplq)) |
| 12022 | txcmplq_cnt++; |
| 12023 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 12024 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12025 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12026 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12027 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12028 | txq_cnt, phba->iocb_cnt, |
| 12029 | fcp_txcmplq_cnt, |
| 12030 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12031 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12032 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12033 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12034 | /* Save off the slow-path queue event for work thread to process */ |
| 12035 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12036 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12037 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12038 | &phba->sli4_hba.sp_queue_event); |
| 12039 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12040 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12041 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12042 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12043 | } |
| 12044 | |
| 12045 | /** |
| 12046 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 12047 | * @phba: Pointer to HBA context object. |
| 12048 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12049 | * |
| 12050 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 12051 | * proper WQ release routine to the slow-path WQ. |
| 12052 | **/ |
| 12053 | static void |
| 12054 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 12055 | struct lpfc_wcqe_release *wcqe) |
| 12056 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12057 | /* sanity check on queue memory */ |
| 12058 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 12059 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12060 | /* Check for the slow-path ELS work queue */ |
| 12061 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 12062 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 12063 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12064 | else |
| 12065 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12066 | "2579 Slow-path wqe consume event carries " |
| 12067 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 12068 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 12069 | phba->sli4_hba.els_wq->queue_id); |
| 12070 | } |
| 12071 | |
| 12072 | /** |
| 12073 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 12074 | * @phba: Pointer to HBA context object. |
| 12075 | * @cq: Pointer to a WQ completion queue. |
| 12076 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12077 | * |
| 12078 | * This routine handles an XRI abort event. |
| 12079 | * |
| 12080 | * Return: true if work posted to worker thread, otherwise false. |
| 12081 | **/ |
| 12082 | static bool |
| 12083 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12084 | struct lpfc_queue *cq, |
| 12085 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12086 | { |
| 12087 | bool workposted = false; |
| 12088 | struct lpfc_cq_event *cq_event; |
| 12089 | unsigned long iflags; |
| 12090 | |
| 12091 | /* Allocate a new internal CQ_EVENT entry */ |
| 12092 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12093 | if (!cq_event) { |
| 12094 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12095 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 12096 | return false; |
| 12097 | } |
| 12098 | |
| 12099 | /* Move the CQE into the proper xri abort event list */ |
| 12100 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12101 | switch (cq->subtype) { |
| 12102 | case LPFC_FCP: |
| 12103 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12104 | list_add_tail(&cq_event->list, |
| 12105 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12106 | /* Set the fcp xri abort event flag */ |
| 12107 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12108 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12109 | workposted = true; |
| 12110 | break; |
| 12111 | case LPFC_ELS: |
| 12112 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12113 | list_add_tail(&cq_event->list, |
| 12114 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12115 | /* Set the els xri abort event flag */ |
| 12116 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12117 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12118 | workposted = true; |
| 12119 | break; |
| 12120 | default: |
| 12121 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12122 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 12123 | cq->subtype); |
| 12124 | workposted = false; |
| 12125 | break; |
| 12126 | } |
| 12127 | return workposted; |
| 12128 | } |
| 12129 | |
| 12130 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12131 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12132 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12133 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12134 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12135 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12136 | * |
| 12137 | * Return: true if work posted to worker thread, otherwise false. |
| 12138 | **/ |
| 12139 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12140 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12141 | { |
| 12142 | bool workposted = false; |
| 12143 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12144 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 12145 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12146 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12147 | unsigned long iflags; |
| 12148 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12149 | /* sanity check on queue memory */ |
| 12150 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12151 | return workposted; |
| 12152 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12153 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12154 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12155 | else |
| 12156 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12157 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12158 | goto out; |
| 12159 | |
| 12160 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12161 | switch (status) { |
| 12162 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12163 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12164 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12165 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12166 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12167 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12168 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12169 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12170 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12171 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12172 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12173 | goto out; |
| 12174 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12175 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12176 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 12177 | /* save off the frame for the word thread to process */ |
| 12178 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12179 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12180 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12181 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12182 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12183 | workposted = true; |
| 12184 | break; |
| 12185 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 12186 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12187 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12188 | /* Post more buffers if possible */ |
| 12189 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12190 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12191 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12192 | workposted = true; |
| 12193 | break; |
| 12194 | } |
| 12195 | out: |
| 12196 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12197 | } |
| 12198 | |
| 12199 | /** |
| 12200 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12201 | * @phba: Pointer to HBA context object. |
| 12202 | * @cq: Pointer to the completion queue. |
| 12203 | * @wcqe: Pointer to a completion queue entry. |
| 12204 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12205 | * 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] | 12206 | * entry. |
| 12207 | * |
| 12208 | * Return: true if work posted to worker thread, otherwise false. |
| 12209 | **/ |
| 12210 | static bool |
| 12211 | 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] | 12212 | struct lpfc_cqe *cqe) |
| 12213 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12214 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12215 | bool workposted = false; |
| 12216 | |
| 12217 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12218 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12219 | |
| 12220 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12221 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12222 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12223 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12224 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12225 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12226 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12227 | break; |
| 12228 | case CQE_CODE_RELEASE_WQE: |
| 12229 | /* Process the WQ release event */ |
| 12230 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12231 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12232 | break; |
| 12233 | case CQE_CODE_XRI_ABORTED: |
| 12234 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12235 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12236 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12237 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12238 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12239 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12240 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12241 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12242 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12243 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12244 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12245 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12246 | default: |
| 12247 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12248 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12249 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12250 | break; |
| 12251 | } |
| 12252 | return workposted; |
| 12253 | } |
| 12254 | |
| 12255 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12256 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 12257 | * @phba: Pointer to HBA context object. |
| 12258 | * @eqe: Pointer to fast-path event queue entry. |
| 12259 | * |
| 12260 | * This routine process a event queue entry from the slow-path event queue. |
| 12261 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12262 | * completion event on a completion queue, if not, an error shall be logged |
| 12263 | * and just return. Otherwise, it will get to the corresponding completion |
| 12264 | * queue and process all the entries on that completion queue, rearm the |
| 12265 | * completion queue, and then return. |
| 12266 | * |
| 12267 | **/ |
| 12268 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12269 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12270 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12271 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12272 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12273 | struct lpfc_cqe *cqe; |
| 12274 | bool workposted = false; |
| 12275 | int ecount = 0; |
| 12276 | uint16_t cqid; |
| 12277 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12278 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12279 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12280 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12281 | list_for_each_entry(childq, &speq->child_list, list) { |
| 12282 | if (childq->queue_id == cqid) { |
| 12283 | cq = childq; |
| 12284 | break; |
| 12285 | } |
| 12286 | } |
| 12287 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12288 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12289 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12290 | "0365 Slow-path CQ identifier " |
| 12291 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12292 | return; |
| 12293 | } |
| 12294 | |
| 12295 | /* Process all the entries to the CQ */ |
| 12296 | switch (cq->type) { |
| 12297 | case LPFC_MCQ: |
| 12298 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12299 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12300 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12301 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12302 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12303 | } |
| 12304 | break; |
| 12305 | case LPFC_WCQ: |
| 12306 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12307 | if (cq->subtype == LPFC_FCP) |
| 12308 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 12309 | cqe); |
| 12310 | else |
| 12311 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 12312 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12313 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12314 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12315 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12316 | |
| 12317 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12318 | if (ecount > cq->CQ_max_cqe) |
| 12319 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12320 | break; |
| 12321 | default: |
| 12322 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12323 | "0370 Invalid completion queue type (%d)\n", |
| 12324 | cq->type); |
| 12325 | return; |
| 12326 | } |
| 12327 | |
| 12328 | /* Catch the no cq entry condition, log an error */ |
| 12329 | if (unlikely(ecount == 0)) |
| 12330 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12331 | "0371 No entry from the CQ: identifier " |
| 12332 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 12333 | |
| 12334 | /* In any case, flash and re-arm the RCQ */ |
| 12335 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12336 | |
| 12337 | /* wake up worker thread if there are works to be done */ |
| 12338 | if (workposted) |
| 12339 | lpfc_worker_wake_up(phba); |
| 12340 | } |
| 12341 | |
| 12342 | /** |
| 12343 | * 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] | 12344 | * @phba: Pointer to HBA context object. |
| 12345 | * @cq: Pointer to associated CQ |
| 12346 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12347 | * |
| 12348 | * This routine process a fast-path work queue completion entry from fast-path |
| 12349 | * event queue for FCP command response completion. |
| 12350 | **/ |
| 12351 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12352 | 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] | 12353 | struct lpfc_wcqe_complete *wcqe) |
| 12354 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12355 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12356 | struct lpfc_iocbq *cmdiocbq; |
| 12357 | struct lpfc_iocbq irspiocbq; |
| 12358 | unsigned long iflags; |
| 12359 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12360 | /* Check for response status */ |
| 12361 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 12362 | /* If resource errors reported from HBA, reduce queue |
| 12363 | * depth of the SCSI device. |
| 12364 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12365 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 12366 | IOSTAT_LOCAL_REJECT)) && |
| 12367 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 12368 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12369 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 12370 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12371 | /* Log the error status */ |
| 12372 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12373 | "0373 FCP complete error: status=x%x, " |
| 12374 | "hw_status=x%x, total_data_specified=%d, " |
| 12375 | "parameter=x%x, word3=x%x\n", |
| 12376 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 12377 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 12378 | wcqe->total_data_placed, wcqe->parameter, |
| 12379 | wcqe->word3); |
| 12380 | } |
| 12381 | |
| 12382 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12383 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 12384 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12385 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12386 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12387 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12388 | if (unlikely(!cmdiocbq)) { |
| 12389 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12390 | "0374 FCP complete with no corresponding " |
| 12391 | "cmdiocb: iotag (%d)\n", |
| 12392 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12393 | return; |
| 12394 | } |
| 12395 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 12396 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12397 | "0375 FCP cmdiocb not callback function " |
| 12398 | "iotag: (%d)\n", |
| 12399 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 12400 | return; |
| 12401 | } |
| 12402 | |
| 12403 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12404 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12405 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 12406 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 12407 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12408 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 12409 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12410 | } |
| 12411 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12412 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 12413 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 12414 | } |
| 12415 | |
| 12416 | /** |
| 12417 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 12418 | * @phba: Pointer to HBA context object. |
| 12419 | * @cq: Pointer to completion queue. |
| 12420 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12421 | * |
| 12422 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 12423 | * proper WQ release routine to the slow-path WQ. |
| 12424 | **/ |
| 12425 | static void |
| 12426 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12427 | struct lpfc_wcqe_release *wcqe) |
| 12428 | { |
| 12429 | struct lpfc_queue *childwq; |
| 12430 | bool wqid_matched = false; |
| 12431 | uint16_t fcp_wqid; |
| 12432 | |
| 12433 | /* Check for fast-path FCP work queue release */ |
| 12434 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 12435 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 12436 | if (childwq->queue_id == fcp_wqid) { |
| 12437 | lpfc_sli4_wq_release(childwq, |
| 12438 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12439 | wqid_matched = true; |
| 12440 | break; |
| 12441 | } |
| 12442 | } |
| 12443 | /* Report warning log message if no match found */ |
| 12444 | if (wqid_matched != true) |
| 12445 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12446 | "2580 Fast-path wqe consume event carries " |
| 12447 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 12448 | } |
| 12449 | |
| 12450 | /** |
| 12451 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 12452 | * @cq: Pointer to the completion queue. |
| 12453 | * @eqe: Pointer to fast-path completion queue entry. |
| 12454 | * |
| 12455 | * This routine process a fast-path work queue completion entry from fast-path |
| 12456 | * event queue for FCP command response completion. |
| 12457 | **/ |
| 12458 | static int |
| 12459 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12460 | struct lpfc_cqe *cqe) |
| 12461 | { |
| 12462 | struct lpfc_wcqe_release wcqe; |
| 12463 | bool workposted = false; |
| 12464 | |
| 12465 | /* Copy the work queue CQE and convert endian order if needed */ |
| 12466 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 12467 | |
| 12468 | /* Check and process for different type of WCQE and dispatch */ |
| 12469 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 12470 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12471 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12472 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 12473 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12474 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12475 | (struct lpfc_wcqe_complete *)&wcqe); |
| 12476 | break; |
| 12477 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12478 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12479 | /* Process the WQ release event */ |
| 12480 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 12481 | (struct lpfc_wcqe_release *)&wcqe); |
| 12482 | break; |
| 12483 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12484 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12485 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12486 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12487 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 12488 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 12489 | break; |
| 12490 | default: |
| 12491 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12492 | "0144 Not a valid WCQE code: x%x\n", |
| 12493 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 12494 | break; |
| 12495 | } |
| 12496 | return workposted; |
| 12497 | } |
| 12498 | |
| 12499 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12500 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12501 | * @phba: Pointer to HBA context object. |
| 12502 | * @eqe: Pointer to fast-path event queue entry. |
| 12503 | * |
| 12504 | * This routine process a event queue entry from the fast-path event queue. |
| 12505 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12506 | * completion event on a completion queue, if not, an error shall be logged |
| 12507 | * and just return. Otherwise, it will get to the corresponding completion |
| 12508 | * queue and process all the entries on the completion queue, rearm the |
| 12509 | * completion queue, and then return. |
| 12510 | **/ |
| 12511 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12512 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12513 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12514 | { |
| 12515 | struct lpfc_queue *cq; |
| 12516 | struct lpfc_cqe *cqe; |
| 12517 | bool workposted = false; |
| 12518 | uint16_t cqid; |
| 12519 | int ecount = 0; |
| 12520 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12521 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12522 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12523 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12524 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12525 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12526 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12527 | return; |
| 12528 | } |
| 12529 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12530 | /* Get the reference to the corresponding CQ */ |
| 12531 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12532 | |
| 12533 | /* Check if this is a Slow path event */ |
| 12534 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 12535 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 12536 | phba->sli4_hba.hba_eq[qidx]); |
| 12537 | return; |
| 12538 | } |
| 12539 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12540 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 12541 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12542 | "3146 Fast-path completion queues " |
| 12543 | "does not exist\n"); |
| 12544 | return; |
| 12545 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12546 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12547 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12548 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12549 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12550 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12551 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12552 | return; |
| 12553 | } |
| 12554 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12555 | if (unlikely(cqid != cq->queue_id)) { |
| 12556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12557 | "0368 Miss-matched fast-path completion " |
| 12558 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 12559 | cqid, cq->queue_id); |
| 12560 | return; |
| 12561 | } |
| 12562 | |
| 12563 | /* Process all the entries to the CQ */ |
| 12564 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12565 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12566 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12567 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12568 | } |
| 12569 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12570 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12571 | if (ecount > cq->CQ_max_cqe) |
| 12572 | cq->CQ_max_cqe = ecount; |
| 12573 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12574 | /* Catch the no cq entry condition */ |
| 12575 | if (unlikely(ecount == 0)) |
| 12576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12577 | "0369 No entry from fast-path completion " |
| 12578 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12579 | |
| 12580 | /* In any case, flash and re-arm the CQ */ |
| 12581 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12582 | |
| 12583 | /* wake up worker thread if there are works to be done */ |
| 12584 | if (workposted) |
| 12585 | lpfc_worker_wake_up(phba); |
| 12586 | } |
| 12587 | |
| 12588 | static void |
| 12589 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12590 | { |
| 12591 | struct lpfc_eqe *eqe; |
| 12592 | |
| 12593 | /* walk all the EQ entries and drop on the floor */ |
| 12594 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 12595 | ; |
| 12596 | |
| 12597 | /* Clear and re-arm the EQ */ |
| 12598 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12599 | } |
| 12600 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12601 | |
| 12602 | /** |
| 12603 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 12604 | * entry |
| 12605 | * @phba: Pointer to HBA context object. |
| 12606 | * @eqe: Pointer to fast-path event queue entry. |
| 12607 | * |
| 12608 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 12609 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 12610 | * is for a completion event on a completion queue, if not, an error shall be |
| 12611 | * logged and just return. Otherwise, it will get to the corresponding |
| 12612 | * completion queue and process all the entries on the completion queue, rearm |
| 12613 | * the completion queue, and then return. |
| 12614 | **/ |
| 12615 | static void |
| 12616 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 12617 | { |
| 12618 | struct lpfc_queue *cq; |
| 12619 | struct lpfc_cqe *cqe; |
| 12620 | bool workposted = false; |
| 12621 | uint16_t cqid; |
| 12622 | int ecount = 0; |
| 12623 | |
| 12624 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 12625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12626 | "9147 Not a valid completion " |
| 12627 | "event: majorcode=x%x, minorcode=x%x\n", |
| 12628 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12629 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 12630 | return; |
| 12631 | } |
| 12632 | |
| 12633 | /* Get the reference to the corresponding CQ */ |
| 12634 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12635 | |
| 12636 | /* Next check for OAS */ |
| 12637 | cq = phba->sli4_hba.oas_cq; |
| 12638 | if (unlikely(!cq)) { |
| 12639 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12640 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12641 | "9148 OAS completion queue " |
| 12642 | "does not exist\n"); |
| 12643 | return; |
| 12644 | } |
| 12645 | |
| 12646 | if (unlikely(cqid != cq->queue_id)) { |
| 12647 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12648 | "9149 Miss-matched fast-path compl " |
| 12649 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 12650 | cqid, cq->queue_id); |
| 12651 | return; |
| 12652 | } |
| 12653 | |
| 12654 | /* Process all the entries to the OAS CQ */ |
| 12655 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12656 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
| 12657 | if (!(++ecount % cq->entry_repost)) |
| 12658 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12659 | } |
| 12660 | |
| 12661 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12662 | if (ecount > cq->CQ_max_cqe) |
| 12663 | cq->CQ_max_cqe = ecount; |
| 12664 | |
| 12665 | /* Catch the no cq entry condition */ |
| 12666 | if (unlikely(ecount == 0)) |
| 12667 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12668 | "9153 No entry from fast-path completion " |
| 12669 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12670 | |
| 12671 | /* In any case, flash and re-arm the CQ */ |
| 12672 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12673 | |
| 12674 | /* wake up worker thread if there are works to be done */ |
| 12675 | if (workposted) |
| 12676 | lpfc_worker_wake_up(phba); |
| 12677 | } |
| 12678 | |
| 12679 | /** |
| 12680 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 12681 | * @irq: Interrupt number. |
| 12682 | * @dev_id: The device context pointer. |
| 12683 | * |
| 12684 | * This function is directly called from the PCI layer as an interrupt |
| 12685 | * service routine when device with SLI-4 interface spec is enabled with |
| 12686 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 12687 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 12688 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12689 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12690 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12691 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 12692 | * the intrrupt context. This function is called without any lock held. |
| 12693 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12694 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 12695 | * equal to that of CQ index. |
| 12696 | * |
| 12697 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12698 | * returns IRQ_NONE. |
| 12699 | **/ |
| 12700 | irqreturn_t |
| 12701 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 12702 | { |
| 12703 | struct lpfc_hba *phba; |
| 12704 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12705 | struct lpfc_queue *eq; |
| 12706 | struct lpfc_eqe *eqe; |
| 12707 | unsigned long iflag; |
| 12708 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12709 | |
| 12710 | /* Get the driver's phba structure from the dev_id */ |
| 12711 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12712 | phba = fcp_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12713 | |
| 12714 | if (unlikely(!phba)) |
| 12715 | return IRQ_NONE; |
| 12716 | |
| 12717 | /* Get to the EQ struct associated with this vector */ |
| 12718 | eq = phba->sli4_hba.fof_eq; |
| 12719 | if (unlikely(!eq)) |
| 12720 | return IRQ_NONE; |
| 12721 | |
| 12722 | /* Check device state for handling interrupt */ |
| 12723 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 12724 | eq->EQ_badstate++; |
| 12725 | /* Check again for link_state with lock held */ |
| 12726 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12727 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12728 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12729 | lpfc_sli4_eq_flush(phba, eq); |
| 12730 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12731 | return IRQ_NONE; |
| 12732 | } |
| 12733 | |
| 12734 | /* |
| 12735 | * Process all the event on FCP fast-path EQ |
| 12736 | */ |
| 12737 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 12738 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 12739 | if (!(++ecount % eq->entry_repost)) |
| 12740 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); |
| 12741 | eq->EQ_processed++; |
| 12742 | } |
| 12743 | |
| 12744 | /* Track the max number of EQEs processed in 1 intr */ |
| 12745 | if (ecount > eq->EQ_max_eqe) |
| 12746 | eq->EQ_max_eqe = ecount; |
| 12747 | |
| 12748 | |
| 12749 | if (unlikely(ecount == 0)) { |
| 12750 | eq->EQ_no_entry++; |
| 12751 | |
| 12752 | if (phba->intr_type == MSIX) |
| 12753 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12754 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12755 | "9145 MSI-X interrupt with no EQE\n"); |
| 12756 | else { |
| 12757 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12758 | "9146 ISR interrupt with no EQE\n"); |
| 12759 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12760 | return IRQ_NONE; |
| 12761 | } |
| 12762 | } |
| 12763 | /* Always clear and re-arm the fast-path EQ */ |
| 12764 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12765 | return IRQ_HANDLED; |
| 12766 | } |
| 12767 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12768 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12769 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12770 | * @irq: Interrupt number. |
| 12771 | * @dev_id: The device context pointer. |
| 12772 | * |
| 12773 | * This function is directly called from the PCI layer as an interrupt |
| 12774 | * service routine when device with SLI-4 interface spec is enabled with |
| 12775 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12776 | * ring event in the HBA. However, when the device is enabled with either |
| 12777 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12778 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12779 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12780 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12781 | * the intrrupt context. This function is called without any lock held. |
| 12782 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12783 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 12784 | * equal to that of FCP CQ index. |
| 12785 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12786 | * The link attention and ELS ring attention events are handled |
| 12787 | * by the worker thread. The interrupt handler signals the worker thread |
| 12788 | * and returns for these events. This function is called without any lock |
| 12789 | * held. It gets the hbalock to access and update SLI data structures. |
| 12790 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12791 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12792 | * returns IRQ_NONE. |
| 12793 | **/ |
| 12794 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12795 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12796 | { |
| 12797 | struct lpfc_hba *phba; |
| 12798 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12799 | struct lpfc_queue *fpeq; |
| 12800 | struct lpfc_eqe *eqe; |
| 12801 | unsigned long iflag; |
| 12802 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12803 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12804 | |
| 12805 | /* Get the driver's phba structure from the dev_id */ |
| 12806 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12807 | phba = fcp_eq_hdl->phba; |
| 12808 | fcp_eqidx = fcp_eq_hdl->idx; |
| 12809 | |
| 12810 | if (unlikely(!phba)) |
| 12811 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12812 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12813 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12814 | |
| 12815 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12816 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12817 | if (unlikely(!fpeq)) |
| 12818 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12819 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12820 | if (lpfc_fcp_look_ahead) { |
| 12821 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 12822 | lpfc_sli4_eq_clr_intr(fpeq); |
| 12823 | else { |
| 12824 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12825 | return IRQ_NONE; |
| 12826 | } |
| 12827 | } |
| 12828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12829 | /* Check device state for handling interrupt */ |
| 12830 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12831 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12832 | /* Check again for link_state with lock held */ |
| 12833 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12834 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12835 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12836 | lpfc_sli4_eq_flush(phba, fpeq); |
| 12837 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12838 | if (lpfc_fcp_look_ahead) |
| 12839 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12840 | return IRQ_NONE; |
| 12841 | } |
| 12842 | |
| 12843 | /* |
| 12844 | * Process all the event on FCP fast-path EQ |
| 12845 | */ |
| 12846 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 12847 | if (eqe == NULL) |
| 12848 | break; |
| 12849 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12850 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12851 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12852 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12853 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12854 | } |
| 12855 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12856 | /* Track the max number of EQEs processed in 1 intr */ |
| 12857 | if (ecount > fpeq->EQ_max_eqe) |
| 12858 | fpeq->EQ_max_eqe = ecount; |
| 12859 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12860 | /* Always clear and re-arm the fast-path EQ */ |
| 12861 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 12862 | |
| 12863 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12864 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12865 | |
| 12866 | if (lpfc_fcp_look_ahead) { |
| 12867 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12868 | return IRQ_NONE; |
| 12869 | } |
| 12870 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12871 | if (phba->intr_type == MSIX) |
| 12872 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12873 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12874 | "0358 MSI-X interrupt with no EQE\n"); |
| 12875 | else |
| 12876 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12877 | return IRQ_NONE; |
| 12878 | } |
| 12879 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12880 | if (lpfc_fcp_look_ahead) |
| 12881 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12882 | return IRQ_HANDLED; |
| 12883 | } /* lpfc_sli4_fp_intr_handler */ |
| 12884 | |
| 12885 | /** |
| 12886 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12887 | * @irq: Interrupt number. |
| 12888 | * @dev_id: The device context pointer. |
| 12889 | * |
| 12890 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12891 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12892 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12893 | * driver attention. This function invokes the slow-path interrupt attention |
| 12894 | * handling function and fast-path interrupt attention handling function in |
| 12895 | * turn to process the relevant HBA attention events. This function is called |
| 12896 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12897 | * structures. |
| 12898 | * |
| 12899 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12900 | * returns IRQ_NONE. |
| 12901 | **/ |
| 12902 | irqreturn_t |
| 12903 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12904 | { |
| 12905 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12906 | irqreturn_t hba_irq_rc; |
| 12907 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12908 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12909 | |
| 12910 | /* Get the driver's phba structure from the dev_id */ |
| 12911 | phba = (struct lpfc_hba *)dev_id; |
| 12912 | |
| 12913 | if (unlikely(!phba)) |
| 12914 | return IRQ_NONE; |
| 12915 | |
| 12916 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12917 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12918 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12919 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12920 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12921 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12922 | if (hba_irq_rc == IRQ_HANDLED) |
| 12923 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12924 | } |
| 12925 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12926 | if (phba->cfg_fof) { |
| 12927 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
| 12928 | &phba->sli4_hba.fcp_eq_hdl[0]); |
| 12929 | if (hba_irq_rc == IRQ_HANDLED) |
| 12930 | hba_handled |= true; |
| 12931 | } |
| 12932 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12933 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12934 | } /* lpfc_sli4_intr_handler */ |
| 12935 | |
| 12936 | /** |
| 12937 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12938 | * @queue: The queue structure to free. |
| 12939 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12940 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12941 | * the host resident queue. This function must be called after destroying the |
| 12942 | * queue on the HBA. |
| 12943 | **/ |
| 12944 | void |
| 12945 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12946 | { |
| 12947 | struct lpfc_dmabuf *dmabuf; |
| 12948 | |
| 12949 | if (!queue) |
| 12950 | return; |
| 12951 | |
| 12952 | while (!list_empty(&queue->page_list)) { |
| 12953 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12954 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12955 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12956 | dmabuf->virt, dmabuf->phys); |
| 12957 | kfree(dmabuf); |
| 12958 | } |
| 12959 | kfree(queue); |
| 12960 | return; |
| 12961 | } |
| 12962 | |
| 12963 | /** |
| 12964 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12965 | * @phba: The HBA that this queue is being created on. |
| 12966 | * @entry_size: The size of each queue entry for this queue. |
| 12967 | * @entry count: The number of entries that this queue will handle. |
| 12968 | * |
| 12969 | * This function allocates a queue structure and the DMAable memory used for |
| 12970 | * the host resident queue. This function must be called before creating the |
| 12971 | * queue on the HBA. |
| 12972 | **/ |
| 12973 | struct lpfc_queue * |
| 12974 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12975 | uint32_t entry_count) |
| 12976 | { |
| 12977 | struct lpfc_queue *queue; |
| 12978 | struct lpfc_dmabuf *dmabuf; |
| 12979 | int x, total_qe_count; |
| 12980 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12981 | 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] | 12982 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12983 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12984 | hw_page_size = SLI4_PAGE_SIZE; |
| 12985 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12986 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12987 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12988 | if (!queue) |
| 12989 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12990 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12991 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12992 | INIT_LIST_HEAD(&queue->list); |
| 12993 | INIT_LIST_HEAD(&queue->page_list); |
| 12994 | INIT_LIST_HEAD(&queue->child_list); |
| 12995 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12996 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12997 | if (!dmabuf) |
| 12998 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 12999 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 13000 | hw_page_size, &dmabuf->phys, |
| 13001 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13002 | if (!dmabuf->virt) { |
| 13003 | kfree(dmabuf); |
| 13004 | goto out_fail; |
| 13005 | } |
| 13006 | dmabuf->buffer_tag = x; |
| 13007 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 13008 | /* initialize queue's entry array */ |
| 13009 | dma_pointer = dmabuf->virt; |
| 13010 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13011 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13012 | total_qe_count++, dma_pointer += entry_size) { |
| 13013 | queue->qe[total_qe_count].address = dma_pointer; |
| 13014 | } |
| 13015 | } |
| 13016 | queue->entry_size = entry_size; |
| 13017 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13018 | |
| 13019 | /* |
| 13020 | * entry_repost is calculated based on the number of entries in the |
| 13021 | * queue. This works out except for RQs. If buffers are NOT initially |
| 13022 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 13023 | */ |
| 13024 | queue->entry_repost = (entry_count >> 3); |
| 13025 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 13026 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13027 | queue->phba = phba; |
| 13028 | |
| 13029 | return queue; |
| 13030 | out_fail: |
| 13031 | lpfc_sli4_queue_free(queue); |
| 13032 | return NULL; |
| 13033 | } |
| 13034 | |
| 13035 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13036 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 13037 | * @phba: HBA structure that indicates port to create a queue on. |
| 13038 | * @pci_barset: PCI BAR set flag. |
| 13039 | * |
| 13040 | * This function shall perform iomap of the specified PCI BAR address to host |
| 13041 | * memory address if not already done so and return it. The returned host |
| 13042 | * memory address can be NULL. |
| 13043 | */ |
| 13044 | static void __iomem * |
| 13045 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 13046 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13047 | if (!phba->pcidev) |
| 13048 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13049 | |
| 13050 | switch (pci_barset) { |
| 13051 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13052 | return phba->pci_bar0_memmap_p; |
| 13053 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13054 | return phba->pci_bar2_memmap_p; |
| 13055 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13056 | return phba->pci_bar4_memmap_p; |
| 13057 | default: |
| 13058 | break; |
| 13059 | } |
| 13060 | return NULL; |
| 13061 | } |
| 13062 | |
| 13063 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13064 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 13065 | * @phba: HBA structure that indicates port to create a queue on. |
| 13066 | * @startq: The starting FCP EQ to modify |
| 13067 | * |
| 13068 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 13069 | * |
| 13070 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 13071 | * is used to get the starting FCP EQ to change. |
| 13072 | * This function is asynchronous and will wait for the mailbox |
| 13073 | * command to finish before continuing. |
| 13074 | * |
| 13075 | * On success this function will return a zero. If unable to allocate enough |
| 13076 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13077 | * fails this function will return -ENXIO. |
| 13078 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13079 | int |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13080 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13081 | { |
| 13082 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 13083 | LPFC_MBOXQ_t *mbox; |
| 13084 | struct lpfc_queue *eq; |
| 13085 | int cnt, rc, length, status = 0; |
| 13086 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13087 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13088 | int fcp_eqidx; |
| 13089 | union lpfc_sli4_cfg_shdr *shdr; |
| 13090 | uint16_t dmult; |
| 13091 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13092 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13093 | return 0; |
| 13094 | |
| 13095 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13096 | if (!mbox) |
| 13097 | return -ENOMEM; |
| 13098 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 13099 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13100 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13101 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 13102 | length, LPFC_SLI4_MBX_EMBED); |
| 13103 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 13104 | |
| 13105 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13106 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 13107 | if (result > LPFC_DMULT_CONST) |
| 13108 | dmult = 0; |
| 13109 | else |
| 13110 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13111 | |
| 13112 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13113 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13114 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13115 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 13116 | if (!eq) |
| 13117 | continue; |
| 13118 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 13119 | eq_delay->u.request.eq[cnt].phase = 0; |
| 13120 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 13121 | cnt++; |
| 13122 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 13123 | break; |
| 13124 | } |
| 13125 | eq_delay->u.request.num_eq = cnt; |
| 13126 | |
| 13127 | mbox->vport = phba->pport; |
| 13128 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13129 | mbox->context1 = NULL; |
| 13130 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13131 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 13132 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13133 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13134 | if (shdr_status || shdr_add_status || rc) { |
| 13135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13136 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 13137 | "status x%x add_status x%x, mbx status x%x\n", |
| 13138 | shdr_status, shdr_add_status, rc); |
| 13139 | status = -ENXIO; |
| 13140 | } |
| 13141 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13142 | return status; |
| 13143 | } |
| 13144 | |
| 13145 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13146 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 13147 | * @phba: HBA structure that indicates port to create a queue on. |
| 13148 | * @eq: The queue structure to use to create the event queue. |
| 13149 | * @imax: The maximum interrupt per second limit. |
| 13150 | * |
| 13151 | * This function creates an event queue, as detailed in @eq, on a port, |
| 13152 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 13153 | * |
| 13154 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 13155 | * is used to get the entry count and entry size that are necessary to |
| 13156 | * determine the number of pages to allocate and use for this queue. This |
| 13157 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 13158 | * event queue. This function is asynchronous and will wait for the mailbox |
| 13159 | * command to finish before continuing. |
| 13160 | * |
| 13161 | * 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] | 13162 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13163 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13164 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13165 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 13166 | 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] | 13167 | { |
| 13168 | struct lpfc_mbx_eq_create *eq_create; |
| 13169 | LPFC_MBOXQ_t *mbox; |
| 13170 | int rc, length, status = 0; |
| 13171 | struct lpfc_dmabuf *dmabuf; |
| 13172 | uint32_t shdr_status, shdr_add_status; |
| 13173 | union lpfc_sli4_cfg_shdr *shdr; |
| 13174 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13175 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13176 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13177 | /* sanity check on queue memory */ |
| 13178 | if (!eq) |
| 13179 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13180 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13181 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13182 | |
| 13183 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13184 | if (!mbox) |
| 13185 | return -ENOMEM; |
| 13186 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 13187 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13188 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13189 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 13190 | length, LPFC_SLI4_MBX_EMBED); |
| 13191 | eq_create = &mbox->u.mqe.un.eq_create; |
| 13192 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 13193 | eq->page_count); |
| 13194 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 13195 | LPFC_EQE_SIZE); |
| 13196 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 13197 | /* don't setup delay multiplier using EQ_CREATE */ |
| 13198 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13199 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 13200 | dmult); |
| 13201 | switch (eq->entry_count) { |
| 13202 | default: |
| 13203 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13204 | "0360 Unsupported EQ count. (%d)\n", |
| 13205 | eq->entry_count); |
| 13206 | if (eq->entry_count < 256) |
| 13207 | return -EINVAL; |
| 13208 | /* otherwise default to smallest count (drop through) */ |
| 13209 | case 256: |
| 13210 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13211 | LPFC_EQ_CNT_256); |
| 13212 | break; |
| 13213 | case 512: |
| 13214 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13215 | LPFC_EQ_CNT_512); |
| 13216 | break; |
| 13217 | case 1024: |
| 13218 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13219 | LPFC_EQ_CNT_1024); |
| 13220 | break; |
| 13221 | case 2048: |
| 13222 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13223 | LPFC_EQ_CNT_2048); |
| 13224 | break; |
| 13225 | case 4096: |
| 13226 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 13227 | LPFC_EQ_CNT_4096); |
| 13228 | break; |
| 13229 | } |
| 13230 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13231 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13232 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13233 | putPaddrLow(dmabuf->phys); |
| 13234 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13235 | putPaddrHigh(dmabuf->phys); |
| 13236 | } |
| 13237 | mbox->vport = phba->pport; |
| 13238 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13239 | mbox->context1 = NULL; |
| 13240 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13241 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 13242 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13243 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13244 | if (shdr_status || shdr_add_status || rc) { |
| 13245 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13246 | "2500 EQ_CREATE mailbox failed with " |
| 13247 | "status x%x add_status x%x, mbx status x%x\n", |
| 13248 | shdr_status, shdr_add_status, rc); |
| 13249 | status = -ENXIO; |
| 13250 | } |
| 13251 | eq->type = LPFC_EQ; |
| 13252 | eq->subtype = LPFC_NONE; |
| 13253 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 13254 | if (eq->queue_id == 0xFFFF) |
| 13255 | status = -ENXIO; |
| 13256 | eq->host_index = 0; |
| 13257 | eq->hba_index = 0; |
| 13258 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13259 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13260 | return status; |
| 13261 | } |
| 13262 | |
| 13263 | /** |
| 13264 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 13265 | * @phba: HBA structure that indicates port to create a queue on. |
| 13266 | * @cq: The queue structure to use to create the completion queue. |
| 13267 | * @eq: The event queue to bind this completion queue to. |
| 13268 | * |
| 13269 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 13270 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 13271 | * |
| 13272 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13273 | * is used to get the entry count and entry size that are necessary to |
| 13274 | * determine the number of pages to allocate and use for this queue. The @eq |
| 13275 | * is used to indicate which event queue to bind this completion queue to. This |
| 13276 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 13277 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 13278 | * command to finish before continuing. |
| 13279 | * |
| 13280 | * 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] | 13281 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13282 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13283 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13284 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13285 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13286 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 13287 | { |
| 13288 | struct lpfc_mbx_cq_create *cq_create; |
| 13289 | struct lpfc_dmabuf *dmabuf; |
| 13290 | LPFC_MBOXQ_t *mbox; |
| 13291 | int rc, length, status = 0; |
| 13292 | uint32_t shdr_status, shdr_add_status; |
| 13293 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13294 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 13295 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13296 | /* sanity check on queue memory */ |
| 13297 | if (!cq || !eq) |
| 13298 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13299 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13300 | hw_page_size = SLI4_PAGE_SIZE; |
| 13301 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13302 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13303 | if (!mbox) |
| 13304 | return -ENOMEM; |
| 13305 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 13306 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13307 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13308 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 13309 | length, LPFC_SLI4_MBX_EMBED); |
| 13310 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13311 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13312 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 13313 | cq->page_count); |
| 13314 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 13315 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13316 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13317 | phba->sli4_hba.pc_sli4_params.cqv); |
| 13318 | 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] | 13319 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 13320 | 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] | 13321 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 13322 | eq->queue_id); |
| 13323 | } else { |
| 13324 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 13325 | eq->queue_id); |
| 13326 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13327 | switch (cq->entry_count) { |
| 13328 | default: |
| 13329 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13330 | "0361 Unsupported CQ count. (%d)\n", |
| 13331 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13332 | if (cq->entry_count < 256) { |
| 13333 | status = -EINVAL; |
| 13334 | goto out; |
| 13335 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13336 | /* otherwise default to smallest count (drop through) */ |
| 13337 | case 256: |
| 13338 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13339 | LPFC_CQ_CNT_256); |
| 13340 | break; |
| 13341 | case 512: |
| 13342 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13343 | LPFC_CQ_CNT_512); |
| 13344 | break; |
| 13345 | case 1024: |
| 13346 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 13347 | LPFC_CQ_CNT_1024); |
| 13348 | break; |
| 13349 | } |
| 13350 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13351 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13352 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13353 | putPaddrLow(dmabuf->phys); |
| 13354 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13355 | putPaddrHigh(dmabuf->phys); |
| 13356 | } |
| 13357 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13358 | |
| 13359 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13361 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13362 | if (shdr_status || shdr_add_status || rc) { |
| 13363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13364 | "2501 CQ_CREATE mailbox failed with " |
| 13365 | "status x%x add_status x%x, mbx status x%x\n", |
| 13366 | shdr_status, shdr_add_status, rc); |
| 13367 | status = -ENXIO; |
| 13368 | goto out; |
| 13369 | } |
| 13370 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 13371 | if (cq->queue_id == 0xFFFF) { |
| 13372 | status = -ENXIO; |
| 13373 | goto out; |
| 13374 | } |
| 13375 | /* link the cq onto the parent eq child list */ |
| 13376 | list_add_tail(&cq->list, &eq->child_list); |
| 13377 | /* Set up completion queue's type and subtype */ |
| 13378 | cq->type = type; |
| 13379 | cq->subtype = subtype; |
| 13380 | 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] | 13381 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13382 | cq->host_index = 0; |
| 13383 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13384 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13385 | out: |
| 13386 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13387 | return status; |
| 13388 | } |
| 13389 | |
| 13390 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13391 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13392 | * @phba: HBA structure that indicates port to create a queue on. |
| 13393 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13394 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 13395 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13396 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13397 | * This function provides failback (fb) functionality when the |
| 13398 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 13399 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13400 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13401 | * This routine cannot fail as all attributes were previously accessed and |
| 13402 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13403 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13404 | static void |
| 13405 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13406 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13407 | { |
| 13408 | struct lpfc_mbx_mq_create *mq_create; |
| 13409 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13410 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13411 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13412 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 13413 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13414 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13415 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 13416 | length, LPFC_SLI4_MBX_EMBED); |
| 13417 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13418 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13419 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13420 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13421 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13422 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 13423 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13424 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13425 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13426 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13427 | break; |
| 13428 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13429 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13430 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13431 | break; |
| 13432 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13433 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13434 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13435 | break; |
| 13436 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13437 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13438 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13439 | break; |
| 13440 | } |
| 13441 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 13442 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13443 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13444 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13445 | putPaddrHigh(dmabuf->phys); |
| 13446 | } |
| 13447 | } |
| 13448 | |
| 13449 | /** |
| 13450 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 13451 | * @phba: HBA structure that indicates port to create a queue on. |
| 13452 | * @mq: The queue structure to use to create the mailbox queue. |
| 13453 | * @cq: The completion queue to associate with this cq. |
| 13454 | * @subtype: The queue's subtype. |
| 13455 | * |
| 13456 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 13457 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 13458 | * |
| 13459 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13460 | * is used to get the entry count and entry size that are necessary to |
| 13461 | * determine the number of pages to allocate and use for this queue. This |
| 13462 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 13463 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 13464 | * command to finish before continuing. |
| 13465 | * |
| 13466 | * 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] | 13467 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13468 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13469 | **/ |
| 13470 | int32_t |
| 13471 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13472 | struct lpfc_queue *cq, uint32_t subtype) |
| 13473 | { |
| 13474 | struct lpfc_mbx_mq_create *mq_create; |
| 13475 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 13476 | struct lpfc_dmabuf *dmabuf; |
| 13477 | LPFC_MBOXQ_t *mbox; |
| 13478 | int rc, length, status = 0; |
| 13479 | uint32_t shdr_status, shdr_add_status; |
| 13480 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13481 | 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] | 13482 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13483 | /* sanity check on queue memory */ |
| 13484 | if (!mq || !cq) |
| 13485 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13486 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13487 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13488 | |
| 13489 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13490 | if (!mbox) |
| 13491 | return -ENOMEM; |
| 13492 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 13493 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13494 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13495 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 13496 | length, LPFC_SLI4_MBX_EMBED); |
| 13497 | |
| 13498 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13499 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13500 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 13501 | &mq_create_ext->u.request, mq->page_count); |
| 13502 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 13503 | &mq_create_ext->u.request, 1); |
| 13504 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13505 | &mq_create_ext->u.request, 1); |
| 13506 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 13507 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13508 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 13509 | &mq_create_ext->u.request, 1); |
| 13510 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 13511 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13512 | 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] | 13513 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13514 | phba->sli4_hba.pc_sli4_params.mqv); |
| 13515 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 13516 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 13517 | cq->queue_id); |
| 13518 | else |
| 13519 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 13520 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13521 | switch (mq->entry_count) { |
| 13522 | default: |
| 13523 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13524 | "0362 Unsupported MQ count. (%d)\n", |
| 13525 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13526 | if (mq->entry_count < 16) { |
| 13527 | status = -EINVAL; |
| 13528 | goto out; |
| 13529 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13530 | /* otherwise default to smallest count (drop through) */ |
| 13531 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13532 | bf_set(lpfc_mq_context_ring_size, |
| 13533 | &mq_create_ext->u.request.context, |
| 13534 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13535 | break; |
| 13536 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13537 | bf_set(lpfc_mq_context_ring_size, |
| 13538 | &mq_create_ext->u.request.context, |
| 13539 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13540 | break; |
| 13541 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13542 | bf_set(lpfc_mq_context_ring_size, |
| 13543 | &mq_create_ext->u.request.context, |
| 13544 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13545 | break; |
| 13546 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13547 | bf_set(lpfc_mq_context_ring_size, |
| 13548 | &mq_create_ext->u.request.context, |
| 13549 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13550 | break; |
| 13551 | } |
| 13552 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13553 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13554 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13555 | putPaddrLow(dmabuf->phys); |
| 13556 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13557 | putPaddrHigh(dmabuf->phys); |
| 13558 | } |
| 13559 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13560 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13561 | &mq_create_ext->u.response); |
| 13562 | if (rc != MBX_SUCCESS) { |
| 13563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13564 | "2795 MQ_CREATE_EXT failed with " |
| 13565 | "status x%x. Failback to MQ_CREATE.\n", |
| 13566 | rc); |
| 13567 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 13568 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13569 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13570 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 13571 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13572 | &mq_create->u.response); |
| 13573 | } |
| 13574 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13575 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13576 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13577 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13578 | if (shdr_status || shdr_add_status || rc) { |
| 13579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13580 | "2502 MQ_CREATE mailbox failed with " |
| 13581 | "status x%x add_status x%x, mbx status x%x\n", |
| 13582 | shdr_status, shdr_add_status, rc); |
| 13583 | status = -ENXIO; |
| 13584 | goto out; |
| 13585 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13586 | if (mq->queue_id == 0xFFFF) { |
| 13587 | status = -ENXIO; |
| 13588 | goto out; |
| 13589 | } |
| 13590 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13591 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13592 | mq->subtype = subtype; |
| 13593 | mq->host_index = 0; |
| 13594 | mq->hba_index = 0; |
| 13595 | |
| 13596 | /* link the mq onto the parent cq child list */ |
| 13597 | list_add_tail(&mq->list, &cq->child_list); |
| 13598 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13599 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13600 | return status; |
| 13601 | } |
| 13602 | |
| 13603 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13604 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 13605 | * @phba: HBA structure that indicates port to create a queue on. |
| 13606 | * @wq: The queue structure to use to create the work queue. |
| 13607 | * @cq: The completion queue to bind this work queue to. |
| 13608 | * @subtype: The subtype of the work queue indicating its functionality. |
| 13609 | * |
| 13610 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 13611 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 13612 | * |
| 13613 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 13614 | * is used to get the entry count and entry size that are necessary to |
| 13615 | * determine the number of pages to allocate and use for this queue. The @cq |
| 13616 | * is used to indicate which completion queue to bind this work queue to. This |
| 13617 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 13618 | * work queue. This function is asynchronous and will wait for the mailbox |
| 13619 | * command to finish before continuing. |
| 13620 | * |
| 13621 | * 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] | 13622 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13623 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13624 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13625 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13626 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 13627 | struct lpfc_queue *cq, uint32_t subtype) |
| 13628 | { |
| 13629 | struct lpfc_mbx_wq_create *wq_create; |
| 13630 | struct lpfc_dmabuf *dmabuf; |
| 13631 | LPFC_MBOXQ_t *mbox; |
| 13632 | int rc, length, status = 0; |
| 13633 | uint32_t shdr_status, shdr_add_status; |
| 13634 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13635 | 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] | 13636 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13637 | void __iomem *bar_memmap_p; |
| 13638 | uint32_t db_offset; |
| 13639 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13640 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13641 | /* sanity check on queue memory */ |
| 13642 | if (!wq || !cq) |
| 13643 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13644 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13645 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13646 | |
| 13647 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13648 | if (!mbox) |
| 13649 | return -ENOMEM; |
| 13650 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 13651 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13652 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13653 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 13654 | length, LPFC_SLI4_MBX_EMBED); |
| 13655 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13656 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13657 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 13658 | wq->page_count); |
| 13659 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 13660 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13661 | |
| 13662 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13663 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13664 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13665 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13666 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 13667 | case LPFC_Q_CREATE_VERSION_0: |
| 13668 | switch (wq->entry_size) { |
| 13669 | default: |
| 13670 | case 64: |
| 13671 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 13672 | page = wq_create->u.request.page; |
| 13673 | break; |
| 13674 | case 128: |
| 13675 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13676 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13677 | status = -ERANGE; |
| 13678 | goto out; |
| 13679 | } |
| 13680 | /* If we get here the HBA MUST also support V1 and |
| 13681 | * we MUST use it |
| 13682 | */ |
| 13683 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13684 | LPFC_Q_CREATE_VERSION_1); |
| 13685 | |
| 13686 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 13687 | &wq_create->u.request_1, wq->entry_count); |
| 13688 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13689 | &wq_create->u.request_1, |
| 13690 | LPFC_WQ_WQE_SIZE_128); |
| 13691 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13692 | &wq_create->u.request_1, |
James Smart | 27ab541 | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 13693 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13694 | page = wq_create->u.request_1.page; |
| 13695 | break; |
| 13696 | } |
| 13697 | break; |
| 13698 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13699 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 13700 | wq->entry_count); |
James Smart | 730ff61 | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 13701 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13702 | LPFC_Q_CREATE_VERSION_1); |
| 13703 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13704 | switch (wq->entry_size) { |
| 13705 | default: |
| 13706 | case 64: |
| 13707 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13708 | &wq_create->u.request_1, |
| 13709 | LPFC_WQ_WQE_SIZE_64); |
| 13710 | break; |
| 13711 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13712 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13713 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13714 | status = -ERANGE; |
| 13715 | goto out; |
| 13716 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13717 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13718 | &wq_create->u.request_1, |
| 13719 | LPFC_WQ_WQE_SIZE_128); |
| 13720 | break; |
| 13721 | } |
James Smart | 27ab541 | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 13722 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13723 | &wq_create->u.request_1, |
| 13724 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13725 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13726 | break; |
| 13727 | default: |
| 13728 | status = -ERANGE; |
| 13729 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13730 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13731 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13732 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13733 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13734 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 13735 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13736 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13737 | |
| 13738 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13739 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 13740 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13741 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13742 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13743 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13744 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13745 | if (shdr_status || shdr_add_status || rc) { |
| 13746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13747 | "2503 WQ_CREATE mailbox failed with " |
| 13748 | "status x%x add_status x%x, mbx status x%x\n", |
| 13749 | shdr_status, shdr_add_status, rc); |
| 13750 | status = -ENXIO; |
| 13751 | goto out; |
| 13752 | } |
| 13753 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 13754 | if (wq->queue_id == 0xFFFF) { |
| 13755 | status = -ENXIO; |
| 13756 | goto out; |
| 13757 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13758 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13759 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 13760 | &wq_create->u.response); |
| 13761 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13762 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13763 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13764 | "3265 WQ[%d] doorbell format not " |
| 13765 | "supported: x%x\n", wq->queue_id, |
| 13766 | wq->db_format); |
| 13767 | status = -EINVAL; |
| 13768 | goto out; |
| 13769 | } |
| 13770 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 13771 | &wq_create->u.response); |
| 13772 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13773 | if (!bar_memmap_p) { |
| 13774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13775 | "3263 WQ[%d] failed to memmap pci " |
| 13776 | "barset:x%x\n", wq->queue_id, |
| 13777 | pci_barset); |
| 13778 | status = -ENOMEM; |
| 13779 | goto out; |
| 13780 | } |
| 13781 | db_offset = wq_create->u.response.doorbell_offset; |
| 13782 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 13783 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 13784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13785 | "3252 WQ[%d] doorbell offset not " |
| 13786 | "supported: x%x\n", wq->queue_id, |
| 13787 | db_offset); |
| 13788 | status = -EINVAL; |
| 13789 | goto out; |
| 13790 | } |
| 13791 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 13792 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13793 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 13794 | "format:x%x\n", wq->queue_id, pci_barset, |
| 13795 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13796 | } else { |
| 13797 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 13798 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 13799 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13800 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13801 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13802 | wq->subtype = subtype; |
| 13803 | wq->host_index = 0; |
| 13804 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 13805 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13806 | |
| 13807 | /* link the wq onto the parent cq child list */ |
| 13808 | list_add_tail(&wq->list, &cq->child_list); |
| 13809 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13810 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13811 | return status; |
| 13812 | } |
| 13813 | |
| 13814 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13815 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 13816 | * @phba: HBA structure that indicates port to create a queue on. |
| 13817 | * @rq: The queue structure to use for the receive queue. |
| 13818 | * @qno: The associated HBQ number |
| 13819 | * |
| 13820 | * |
| 13821 | * For SLI4 we need to adjust the RQ repost value based on |
| 13822 | * the number of buffers that are initially posted to the RQ. |
| 13823 | */ |
| 13824 | void |
| 13825 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 13826 | { |
| 13827 | uint32_t cnt; |
| 13828 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13829 | /* sanity check on queue memory */ |
| 13830 | if (!rq) |
| 13831 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13832 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 13833 | |
| 13834 | /* Recalc repost for RQs based on buffers initially posted */ |
| 13835 | cnt = (cnt >> 3); |
| 13836 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 13837 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 13838 | |
| 13839 | rq->entry_repost = cnt; |
| 13840 | } |
| 13841 | |
| 13842 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13843 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 13844 | * @phba: HBA structure that indicates port to create a queue on. |
| 13845 | * @hrq: The queue structure to use to create the header receive queue. |
| 13846 | * @drq: The queue structure to use to create the data receive queue. |
| 13847 | * @cq: The completion queue to bind this work queue to. |
| 13848 | * |
| 13849 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 13850 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 13851 | * to the HBA. |
| 13852 | * |
| 13853 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 13854 | * struct is used to get the entry count that is necessary to determine the |
| 13855 | * number of pages to use for this queue. The @cq is used to indicate which |
| 13856 | * completion queue to bind received buffers that are posted to these queues to. |
| 13857 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 13858 | * receive queue pair. This function is asynchronous and will wait for the |
| 13859 | * mailbox command to finish before continuing. |
| 13860 | * |
| 13861 | * 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] | 13862 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13863 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13864 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 13865 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13866 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13867 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 13868 | { |
| 13869 | struct lpfc_mbx_rq_create *rq_create; |
| 13870 | struct lpfc_dmabuf *dmabuf; |
| 13871 | LPFC_MBOXQ_t *mbox; |
| 13872 | int rc, length, status = 0; |
| 13873 | uint32_t shdr_status, shdr_add_status; |
| 13874 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13875 | 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] | 13876 | void __iomem *bar_memmap_p; |
| 13877 | uint32_t db_offset; |
| 13878 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13879 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13880 | /* sanity check on queue memory */ |
| 13881 | if (!hrq || !drq || !cq) |
| 13882 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13883 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13884 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13885 | |
| 13886 | if (hrq->entry_count != drq->entry_count) |
| 13887 | return -EINVAL; |
| 13888 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13889 | if (!mbox) |
| 13890 | return -ENOMEM; |
| 13891 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 13892 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13893 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13894 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13895 | length, LPFC_SLI4_MBX_EMBED); |
| 13896 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13897 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13898 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13899 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13900 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13901 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13902 | &rq_create->u.request.context, |
| 13903 | hrq->entry_count); |
| 13904 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13905 | bf_set(lpfc_rq_context_rqe_size, |
| 13906 | &rq_create->u.request.context, |
| 13907 | LPFC_RQE_SIZE_8); |
| 13908 | bf_set(lpfc_rq_context_page_size, |
| 13909 | &rq_create->u.request.context, |
James Smart | 27ab541 | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 13910 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13911 | } else { |
| 13912 | switch (hrq->entry_count) { |
| 13913 | default: |
| 13914 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13915 | "2535 Unsupported RQ count. (%d)\n", |
| 13916 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13917 | if (hrq->entry_count < 512) { |
| 13918 | status = -EINVAL; |
| 13919 | goto out; |
| 13920 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13921 | /* otherwise default to smallest count (drop through) */ |
| 13922 | case 512: |
| 13923 | bf_set(lpfc_rq_context_rqe_count, |
| 13924 | &rq_create->u.request.context, |
| 13925 | LPFC_RQ_RING_SIZE_512); |
| 13926 | break; |
| 13927 | case 1024: |
| 13928 | bf_set(lpfc_rq_context_rqe_count, |
| 13929 | &rq_create->u.request.context, |
| 13930 | LPFC_RQ_RING_SIZE_1024); |
| 13931 | break; |
| 13932 | case 2048: |
| 13933 | bf_set(lpfc_rq_context_rqe_count, |
| 13934 | &rq_create->u.request.context, |
| 13935 | LPFC_RQ_RING_SIZE_2048); |
| 13936 | break; |
| 13937 | case 4096: |
| 13938 | bf_set(lpfc_rq_context_rqe_count, |
| 13939 | &rq_create->u.request.context, |
| 13940 | LPFC_RQ_RING_SIZE_4096); |
| 13941 | break; |
| 13942 | } |
| 13943 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13944 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13945 | } |
| 13946 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13947 | cq->queue_id); |
| 13948 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13949 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13950 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13951 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13952 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13953 | putPaddrLow(dmabuf->phys); |
| 13954 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13955 | putPaddrHigh(dmabuf->phys); |
| 13956 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13957 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13958 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 13959 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13960 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13961 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13962 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13963 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13964 | if (shdr_status || shdr_add_status || rc) { |
| 13965 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13966 | "2504 RQ_CREATE mailbox failed with " |
| 13967 | "status x%x add_status x%x, mbx status x%x\n", |
| 13968 | shdr_status, shdr_add_status, rc); |
| 13969 | status = -ENXIO; |
| 13970 | goto out; |
| 13971 | } |
| 13972 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13973 | if (hrq->queue_id == 0xFFFF) { |
| 13974 | status = -ENXIO; |
| 13975 | goto out; |
| 13976 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13977 | |
| 13978 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13979 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13980 | &rq_create->u.response); |
| 13981 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13982 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13984 | "3262 RQ [%d] doorbell format not " |
| 13985 | "supported: x%x\n", hrq->queue_id, |
| 13986 | hrq->db_format); |
| 13987 | status = -EINVAL; |
| 13988 | goto out; |
| 13989 | } |
| 13990 | |
| 13991 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 13992 | &rq_create->u.response); |
| 13993 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13994 | if (!bar_memmap_p) { |
| 13995 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13996 | "3269 RQ[%d] failed to memmap pci " |
| 13997 | "barset:x%x\n", hrq->queue_id, |
| 13998 | pci_barset); |
| 13999 | status = -ENOMEM; |
| 14000 | goto out; |
| 14001 | } |
| 14002 | |
| 14003 | db_offset = rq_create->u.response.doorbell_offset; |
| 14004 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 14005 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 14006 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14007 | "3270 RQ[%d] doorbell offset not " |
| 14008 | "supported: x%x\n", hrq->queue_id, |
| 14009 | db_offset); |
| 14010 | status = -EINVAL; |
| 14011 | goto out; |
| 14012 | } |
| 14013 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 14014 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 14015 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 14016 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 14017 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14018 | } else { |
| 14019 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 14020 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 14021 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14022 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14023 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14024 | hrq->subtype = subtype; |
| 14025 | hrq->host_index = 0; |
| 14026 | hrq->hba_index = 0; |
| 14027 | |
| 14028 | /* now create the data queue */ |
| 14029 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14030 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 14031 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14032 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14033 | phba->sli4_hba.pc_sli4_params.rqv); |
| 14034 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 14035 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 14036 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14037 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 14038 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 14039 | LPFC_RQE_SIZE_8); |
| 14040 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 14041 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14042 | } else { |
| 14043 | switch (drq->entry_count) { |
| 14044 | default: |
| 14045 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14046 | "2536 Unsupported RQ count. (%d)\n", |
| 14047 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14048 | if (drq->entry_count < 512) { |
| 14049 | status = -EINVAL; |
| 14050 | goto out; |
| 14051 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14052 | /* otherwise default to smallest count (drop through) */ |
| 14053 | case 512: |
| 14054 | bf_set(lpfc_rq_context_rqe_count, |
| 14055 | &rq_create->u.request.context, |
| 14056 | LPFC_RQ_RING_SIZE_512); |
| 14057 | break; |
| 14058 | case 1024: |
| 14059 | bf_set(lpfc_rq_context_rqe_count, |
| 14060 | &rq_create->u.request.context, |
| 14061 | LPFC_RQ_RING_SIZE_1024); |
| 14062 | break; |
| 14063 | case 2048: |
| 14064 | bf_set(lpfc_rq_context_rqe_count, |
| 14065 | &rq_create->u.request.context, |
| 14066 | LPFC_RQ_RING_SIZE_2048); |
| 14067 | break; |
| 14068 | case 4096: |
| 14069 | bf_set(lpfc_rq_context_rqe_count, |
| 14070 | &rq_create->u.request.context, |
| 14071 | LPFC_RQ_RING_SIZE_4096); |
| 14072 | break; |
| 14073 | } |
| 14074 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 14075 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14076 | } |
| 14077 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 14078 | cq->queue_id); |
| 14079 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 14080 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14081 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 14082 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14083 | putPaddrLow(dmabuf->phys); |
| 14084 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14085 | putPaddrHigh(dmabuf->phys); |
| 14086 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14087 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 14088 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14089 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14090 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14091 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 14092 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14093 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14094 | if (shdr_status || shdr_add_status || rc) { |
| 14095 | status = -ENXIO; |
| 14096 | goto out; |
| 14097 | } |
| 14098 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 14099 | if (drq->queue_id == 0xFFFF) { |
| 14100 | status = -ENXIO; |
| 14101 | goto out; |
| 14102 | } |
| 14103 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14104 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14105 | drq->subtype = subtype; |
| 14106 | drq->host_index = 0; |
| 14107 | drq->hba_index = 0; |
| 14108 | |
| 14109 | /* link the header and data RQs onto the parent cq child list */ |
| 14110 | list_add_tail(&hrq->list, &cq->child_list); |
| 14111 | list_add_tail(&drq->list, &cq->child_list); |
| 14112 | |
| 14113 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14114 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14115 | return status; |
| 14116 | } |
| 14117 | |
| 14118 | /** |
| 14119 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 14120 | * @eq: The queue structure associated with the queue to destroy. |
| 14121 | * |
| 14122 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 14123 | * command, specific to the type of queue, to the HBA. |
| 14124 | * |
| 14125 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 14126 | * |
| 14127 | * 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] | 14128 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14129 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14130 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14131 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 14132 | { |
| 14133 | LPFC_MBOXQ_t *mbox; |
| 14134 | int rc, length, status = 0; |
| 14135 | uint32_t shdr_status, shdr_add_status; |
| 14136 | union lpfc_sli4_cfg_shdr *shdr; |
| 14137 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14138 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14139 | if (!eq) |
| 14140 | return -ENODEV; |
| 14141 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14142 | if (!mbox) |
| 14143 | return -ENOMEM; |
| 14144 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 14145 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14146 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14147 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 14148 | length, LPFC_SLI4_MBX_EMBED); |
| 14149 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 14150 | eq->queue_id); |
| 14151 | mbox->vport = eq->phba->pport; |
| 14152 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14153 | |
| 14154 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 14155 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14156 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14157 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 14158 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14159 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14160 | if (shdr_status || shdr_add_status || rc) { |
| 14161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14162 | "2505 EQ_DESTROY mailbox failed with " |
| 14163 | "status x%x add_status x%x, mbx status x%x\n", |
| 14164 | shdr_status, shdr_add_status, rc); |
| 14165 | status = -ENXIO; |
| 14166 | } |
| 14167 | |
| 14168 | /* Remove eq from any list */ |
| 14169 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14170 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14171 | return status; |
| 14172 | } |
| 14173 | |
| 14174 | /** |
| 14175 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 14176 | * @cq: The queue structure associated with the queue to destroy. |
| 14177 | * |
| 14178 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 14179 | * command, specific to the type of queue, to the HBA. |
| 14180 | * |
| 14181 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 14182 | * |
| 14183 | * 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] | 14184 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14185 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14186 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14187 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 14188 | { |
| 14189 | LPFC_MBOXQ_t *mbox; |
| 14190 | int rc, length, status = 0; |
| 14191 | uint32_t shdr_status, shdr_add_status; |
| 14192 | union lpfc_sli4_cfg_shdr *shdr; |
| 14193 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14194 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14195 | if (!cq) |
| 14196 | return -ENODEV; |
| 14197 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14198 | if (!mbox) |
| 14199 | return -ENOMEM; |
| 14200 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 14201 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14202 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14203 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 14204 | length, LPFC_SLI4_MBX_EMBED); |
| 14205 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 14206 | cq->queue_id); |
| 14207 | mbox->vport = cq->phba->pport; |
| 14208 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14209 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 14210 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14211 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14212 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 14213 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14214 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14215 | if (shdr_status || shdr_add_status || rc) { |
| 14216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14217 | "2506 CQ_DESTROY mailbox failed with " |
| 14218 | "status x%x add_status x%x, mbx status x%x\n", |
| 14219 | shdr_status, shdr_add_status, rc); |
| 14220 | status = -ENXIO; |
| 14221 | } |
| 14222 | /* Remove cq from any list */ |
| 14223 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14224 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | return status; |
| 14226 | } |
| 14227 | |
| 14228 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14229 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 14230 | * @qm: The queue structure associated with the queue to destroy. |
| 14231 | * |
| 14232 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 14233 | * command, specific to the type of queue, to the HBA. |
| 14234 | * |
| 14235 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 14236 | * |
| 14237 | * 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] | 14238 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14239 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14240 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14241 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 14242 | { |
| 14243 | LPFC_MBOXQ_t *mbox; |
| 14244 | int rc, length, status = 0; |
| 14245 | uint32_t shdr_status, shdr_add_status; |
| 14246 | union lpfc_sli4_cfg_shdr *shdr; |
| 14247 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14248 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14249 | if (!mq) |
| 14250 | return -ENODEV; |
| 14251 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14252 | if (!mbox) |
| 14253 | return -ENOMEM; |
| 14254 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 14255 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14256 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14257 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 14258 | length, LPFC_SLI4_MBX_EMBED); |
| 14259 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 14260 | mq->queue_id); |
| 14261 | mbox->vport = mq->phba->pport; |
| 14262 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14263 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 14264 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14265 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14266 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 14267 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14268 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14269 | if (shdr_status || shdr_add_status || rc) { |
| 14270 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14271 | "2507 MQ_DESTROY mailbox failed with " |
| 14272 | "status x%x add_status x%x, mbx status x%x\n", |
| 14273 | shdr_status, shdr_add_status, rc); |
| 14274 | status = -ENXIO; |
| 14275 | } |
| 14276 | /* Remove mq from any list */ |
| 14277 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14278 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14279 | return status; |
| 14280 | } |
| 14281 | |
| 14282 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14283 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 14284 | * @wq: The queue structure associated with the queue to destroy. |
| 14285 | * |
| 14286 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 14287 | * command, specific to the type of queue, to the HBA. |
| 14288 | * |
| 14289 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 14290 | * |
| 14291 | * 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] | 14292 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14293 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14294 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14295 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 14296 | { |
| 14297 | LPFC_MBOXQ_t *mbox; |
| 14298 | int rc, length, status = 0; |
| 14299 | uint32_t shdr_status, shdr_add_status; |
| 14300 | union lpfc_sli4_cfg_shdr *shdr; |
| 14301 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14302 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14303 | if (!wq) |
| 14304 | return -ENODEV; |
| 14305 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14306 | if (!mbox) |
| 14307 | return -ENOMEM; |
| 14308 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 14309 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14310 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14311 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 14312 | length, LPFC_SLI4_MBX_EMBED); |
| 14313 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 14314 | wq->queue_id); |
| 14315 | mbox->vport = wq->phba->pport; |
| 14316 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14317 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 14318 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14319 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 14320 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14321 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14322 | if (shdr_status || shdr_add_status || rc) { |
| 14323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14324 | "2508 WQ_DESTROY mailbox failed with " |
| 14325 | "status x%x add_status x%x, mbx status x%x\n", |
| 14326 | shdr_status, shdr_add_status, rc); |
| 14327 | status = -ENXIO; |
| 14328 | } |
| 14329 | /* Remove wq from any list */ |
| 14330 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14331 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14332 | return status; |
| 14333 | } |
| 14334 | |
| 14335 | /** |
| 14336 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 14337 | * @rq: The queue structure associated with the queue to destroy. |
| 14338 | * |
| 14339 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 14340 | * command, specific to the type of queue, to the HBA. |
| 14341 | * |
| 14342 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 14343 | * |
| 14344 | * 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] | 14345 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14346 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14347 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14348 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 14349 | struct lpfc_queue *drq) |
| 14350 | { |
| 14351 | LPFC_MBOXQ_t *mbox; |
| 14352 | int rc, length, status = 0; |
| 14353 | uint32_t shdr_status, shdr_add_status; |
| 14354 | union lpfc_sli4_cfg_shdr *shdr; |
| 14355 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14356 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14357 | if (!hrq || !drq) |
| 14358 | return -ENODEV; |
| 14359 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 14360 | if (!mbox) |
| 14361 | return -ENOMEM; |
| 14362 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14363 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14364 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14365 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 14366 | length, LPFC_SLI4_MBX_EMBED); |
| 14367 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14368 | hrq->queue_id); |
| 14369 | mbox->vport = hrq->phba->pport; |
| 14370 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14371 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 14372 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14373 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14374 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14375 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14376 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14377 | if (shdr_status || shdr_add_status || rc) { |
| 14378 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14379 | "2509 RQ_DESTROY mailbox failed with " |
| 14380 | "status x%x add_status x%x, mbx status x%x\n", |
| 14381 | shdr_status, shdr_add_status, rc); |
| 14382 | if (rc != MBX_TIMEOUT) |
| 14383 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 14384 | return -ENXIO; |
| 14385 | } |
| 14386 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 14387 | drq->queue_id); |
| 14388 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 14389 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 14390 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 14391 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14392 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14393 | if (shdr_status || shdr_add_status || rc) { |
| 14394 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14395 | "2510 RQ_DESTROY mailbox failed with " |
| 14396 | "status x%x add_status x%x, mbx status x%x\n", |
| 14397 | shdr_status, shdr_add_status, rc); |
| 14398 | status = -ENXIO; |
| 14399 | } |
| 14400 | list_del_init(&hrq->list); |
| 14401 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14402 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14403 | return status; |
| 14404 | } |
| 14405 | |
| 14406 | /** |
| 14407 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 14408 | * @phba: The virtual port for which this call being executed. |
| 14409 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 14410 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 14411 | * @xritag: the xritag that ties this io to the SGL pages. |
| 14412 | * |
| 14413 | * This routine will post the sgl pages for the IO that has the xritag |
| 14414 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 14415 | * creation and persists for as long as the driver is loaded. |
| 14416 | * if the caller has fewer than 256 scatter gather segments to map then |
| 14417 | * pdma_phys_addr1 should be 0. |
| 14418 | * If the caller needs to map more than 256 scatter gather segment then |
| 14419 | * pdma_phys_addr1 should be a valid physical address. |
| 14420 | * physical address for SGLs must be 64 byte aligned. |
| 14421 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 14422 | * the second sgl can have between 1 and 256 entries. |
| 14423 | * |
| 14424 | * Return codes: |
| 14425 | * 0 - Success |
| 14426 | * -ENXIO, -ENOMEM - Failure |
| 14427 | **/ |
| 14428 | int |
| 14429 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 14430 | dma_addr_t pdma_phys_addr0, |
| 14431 | dma_addr_t pdma_phys_addr1, |
| 14432 | uint16_t xritag) |
| 14433 | { |
| 14434 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 14435 | LPFC_MBOXQ_t *mbox; |
| 14436 | int rc; |
| 14437 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14438 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14439 | union lpfc_sli4_cfg_shdr *shdr; |
| 14440 | |
| 14441 | if (xritag == NO_XRI) { |
| 14442 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14443 | "0364 Invalid param:\n"); |
| 14444 | return -EINVAL; |
| 14445 | } |
| 14446 | |
| 14447 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14448 | if (!mbox) |
| 14449 | return -ENOMEM; |
| 14450 | |
| 14451 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14452 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 14453 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14454 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14455 | |
| 14456 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 14457 | &mbox->u.mqe.un.post_sgl_pages; |
| 14458 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 14459 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 14460 | |
| 14461 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 14462 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 14463 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 14464 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 14465 | |
| 14466 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 14467 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 14468 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 14469 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 14470 | if (!phba->sli4_hba.intr_enable) |
| 14471 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14472 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14473 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14474 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14475 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14476 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14477 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 14478 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14479 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14480 | if (rc != MBX_TIMEOUT) |
| 14481 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14482 | if (shdr_status || shdr_add_status || rc) { |
| 14483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14484 | "2511 POST_SGL mailbox failed with " |
| 14485 | "status x%x add_status x%x, mbx status x%x\n", |
| 14486 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14487 | } |
| 14488 | return 0; |
| 14489 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14490 | |
| 14491 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14492 | * 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] | 14493 | * @phba: pointer to lpfc hba data structure. |
| 14494 | * |
| 14495 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14496 | * HBA consistent with the SLI-4 interface spec. This routine |
| 14497 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14498 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14499 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14500 | * Returns |
| 14501 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 14502 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14503 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14504 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14505 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 14506 | { |
| 14507 | unsigned long xri; |
| 14508 | |
| 14509 | /* |
| 14510 | * Fetch the next logical xri. Because this index is logical, |
| 14511 | * the driver starts at 0 each time. |
| 14512 | */ |
| 14513 | spin_lock_irq(&phba->hbalock); |
| 14514 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 14515 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 14516 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 14517 | spin_unlock_irq(&phba->hbalock); |
| 14518 | return NO_XRI; |
| 14519 | } else { |
| 14520 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 14521 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14522 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14523 | spin_unlock_irq(&phba->hbalock); |
| 14524 | return xri; |
| 14525 | } |
| 14526 | |
| 14527 | /** |
| 14528 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14529 | * @phba: pointer to lpfc hba data structure. |
| 14530 | * |
| 14531 | * This routine is invoked to release an xri to the pool of |
| 14532 | * available rpis maintained by the driver. |
| 14533 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14534 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14535 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14536 | { |
| 14537 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14538 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 14539 | } |
| 14540 | } |
| 14541 | |
| 14542 | /** |
| 14543 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14544 | * @phba: pointer to lpfc hba data structure. |
| 14545 | * |
| 14546 | * This routine is invoked to release an xri to the pool of |
| 14547 | * available rpis maintained by the driver. |
| 14548 | **/ |
| 14549 | void |
| 14550 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14551 | { |
| 14552 | spin_lock_irq(&phba->hbalock); |
| 14553 | __lpfc_sli4_free_xri(phba, xri); |
| 14554 | spin_unlock_irq(&phba->hbalock); |
| 14555 | } |
| 14556 | |
| 14557 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14558 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 14559 | * @phba: Pointer to HBA context object. |
| 14560 | * |
| 14561 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 14562 | * it will return 0xffff. |
| 14563 | * The function returns the allocated xritag if successful, else returns zero. |
| 14564 | * Zero is not a valid xritag. |
| 14565 | * The caller is not required to hold any lock. |
| 14566 | **/ |
| 14567 | uint16_t |
| 14568 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 14569 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14570 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14571 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14572 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 14573 | if (xri_index == NO_XRI) |
| 14574 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14575 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 14576 | " Max XRI is %d, Used XRI is %d\n", |
| 14577 | xri_index, |
| 14578 | phba->sli4_hba.max_cfg_param.max_xri, |
| 14579 | phba->sli4_hba.max_cfg_param.xri_used); |
| 14580 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14581 | } |
| 14582 | |
| 14583 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14584 | * 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] | 14585 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14586 | * @post_sgl_list: pointer to els sgl entry list. |
| 14587 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14588 | * |
| 14589 | * This routine is invoked to post a block of driver's sgl pages to the |
| 14590 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 14591 | * is only called when the driver is loading and after all IO has been |
| 14592 | * stopped. |
| 14593 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14594 | static int |
| 14595 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 14596 | struct list_head *post_sgl_list, |
| 14597 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14598 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14599 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14600 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14601 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14602 | void *viraddr; |
| 14603 | LPFC_MBOXQ_t *mbox; |
| 14604 | uint32_t reqlen, alloclen, pg_pairs; |
| 14605 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14606 | uint16_t xritag_start = 0; |
| 14607 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14608 | uint32_t shdr_status, shdr_add_status; |
| 14609 | union lpfc_sli4_cfg_shdr *shdr; |
| 14610 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14611 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14612 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14613 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14614 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14615 | "2559 Block sgl registration required DMA " |
| 14616 | "size (%d) great than a page\n", reqlen); |
| 14617 | return -ENOMEM; |
| 14618 | } |
| 14619 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14620 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14621 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14622 | |
| 14623 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14624 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14625 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14626 | LPFC_SLI4_MBX_NEMBED); |
| 14627 | |
| 14628 | if (alloclen < reqlen) { |
| 14629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14630 | "0285 Allocated DMA memory size (%d) is " |
| 14631 | "less than the requested DMA memory " |
| 14632 | "size (%d)\n", alloclen, reqlen); |
| 14633 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14634 | return -ENOMEM; |
| 14635 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14636 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14637 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14638 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14639 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14640 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14641 | pg_pairs = 0; |
| 14642 | 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] | 14643 | /* Set up the sge entry */ |
| 14644 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14645 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 14646 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14647 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 14648 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14649 | cpu_to_le32(putPaddrLow(0)); |
| 14650 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14651 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14652 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14653 | /* Keep the first xritag on the list */ |
| 14654 | if (pg_pairs == 0) |
| 14655 | xritag_start = sglq_entry->sli4_xritag; |
| 14656 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14657 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14658 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14659 | |
| 14660 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14661 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14662 | 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] | 14663 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14664 | if (!phba->sli4_hba.intr_enable) |
| 14665 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14666 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14667 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14668 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14669 | } |
| 14670 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14671 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14672 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14673 | if (rc != MBX_TIMEOUT) |
| 14674 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14675 | if (shdr_status || shdr_add_status || rc) { |
| 14676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14677 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 14678 | "status x%x add_status x%x mbx status x%x\n", |
| 14679 | shdr_status, shdr_add_status, rc); |
| 14680 | rc = -ENXIO; |
| 14681 | } |
| 14682 | return rc; |
| 14683 | } |
| 14684 | |
| 14685 | /** |
| 14686 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 14687 | * @phba: pointer to lpfc hba data structure. |
| 14688 | * @sblist: pointer to scsi buffer list. |
| 14689 | * @count: number of scsi buffers on the list. |
| 14690 | * |
| 14691 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 14692 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 14693 | * No Lock is held. |
| 14694 | * |
| 14695 | **/ |
| 14696 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14697 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 14698 | struct list_head *sblist, |
| 14699 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14700 | { |
| 14701 | struct lpfc_scsi_buf *psb; |
| 14702 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14703 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14704 | void *viraddr; |
| 14705 | LPFC_MBOXQ_t *mbox; |
| 14706 | uint32_t reqlen, alloclen, pg_pairs; |
| 14707 | uint32_t mbox_tmo; |
| 14708 | uint16_t xritag_start = 0; |
| 14709 | int rc = 0; |
| 14710 | uint32_t shdr_status, shdr_add_status; |
| 14711 | dma_addr_t pdma_phys_bpl1; |
| 14712 | union lpfc_sli4_cfg_shdr *shdr; |
| 14713 | |
| 14714 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14715 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14716 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14717 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14718 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14719 | "0217 Block sgl registration required DMA " |
| 14720 | "size (%d) great than a page\n", reqlen); |
| 14721 | return -ENOMEM; |
| 14722 | } |
| 14723 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14724 | if (!mbox) { |
| 14725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14726 | "0283 Failed to allocate mbox cmd memory\n"); |
| 14727 | return -ENOMEM; |
| 14728 | } |
| 14729 | |
| 14730 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14731 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14732 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14733 | LPFC_SLI4_MBX_NEMBED); |
| 14734 | |
| 14735 | if (alloclen < reqlen) { |
| 14736 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14737 | "2561 Allocated DMA memory size (%d) is " |
| 14738 | "less than the requested DMA memory " |
| 14739 | "size (%d)\n", alloclen, reqlen); |
| 14740 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14741 | return -ENOMEM; |
| 14742 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14743 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14744 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14745 | viraddr = mbox->sge_array->addr[0]; |
| 14746 | |
| 14747 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 14748 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14749 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14750 | |
| 14751 | pg_pairs = 0; |
| 14752 | list_for_each_entry(psb, sblist, list) { |
| 14753 | /* Set up the sge entry */ |
| 14754 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14755 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 14756 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14757 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 14758 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 14759 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 14760 | else |
| 14761 | pdma_phys_bpl1 = 0; |
| 14762 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14763 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 14764 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14765 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 14766 | /* Keep the first xritag on the list */ |
| 14767 | if (pg_pairs == 0) |
| 14768 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 14769 | sgl_pg_pairs++; |
| 14770 | pg_pairs++; |
| 14771 | } |
| 14772 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 14773 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 14774 | /* Perform endian conversion if necessary */ |
| 14775 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 14776 | |
| 14777 | if (!phba->sli4_hba.intr_enable) |
| 14778 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14779 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14780 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14781 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14782 | } |
| 14783 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14784 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14785 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14786 | if (rc != MBX_TIMEOUT) |
| 14787 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14788 | if (shdr_status || shdr_add_status || rc) { |
| 14789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14790 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 14791 | "status x%x add_status x%x mbx status x%x\n", |
| 14792 | shdr_status, shdr_add_status, rc); |
| 14793 | rc = -ENXIO; |
| 14794 | } |
| 14795 | return rc; |
| 14796 | } |
| 14797 | |
| 14798 | /** |
| 14799 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 14800 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 14801 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14802 | * |
| 14803 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 14804 | * valid type of frame that the LPFC driver will handle. This function will |
| 14805 | * return a zero if the frame is a valid frame or a non zero value when the |
| 14806 | * frame does not pass the check. |
| 14807 | **/ |
| 14808 | static int |
| 14809 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 14810 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 14811 | /* make rctl_names static to save stack space */ |
| 14812 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14813 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 14814 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14815 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14816 | |
| 14817 | switch (fc_hdr->fh_r_ctl) { |
| 14818 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 14819 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 14820 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 14821 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 14822 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 14823 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 14824 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 14825 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 14826 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 14827 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 14828 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 14829 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 14830 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 14831 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 14832 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 14833 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 14834 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 14835 | case FC_RCTL_BA_PRMT: |
| 14836 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 14837 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 14838 | case FC_RCTL_P_RJT: /* port reject */ |
| 14839 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 14840 | case FC_RCTL_P_BSY: /* port busy */ |
| 14841 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 14842 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 14843 | case FC_RCTL_LCR: /* link credit reset */ |
| 14844 | case FC_RCTL_END: /* end */ |
| 14845 | break; |
| 14846 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 14847 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14848 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 14849 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 14850 | default: |
| 14851 | goto drop; |
| 14852 | } |
| 14853 | switch (fc_hdr->fh_type) { |
| 14854 | case FC_TYPE_BLS: |
| 14855 | case FC_TYPE_ELS: |
| 14856 | case FC_TYPE_FCP: |
| 14857 | case FC_TYPE_CT: |
| 14858 | break; |
| 14859 | case FC_TYPE_IP: |
| 14860 | case FC_TYPE_ILS: |
| 14861 | default: |
| 14862 | goto drop; |
| 14863 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14864 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14865 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14866 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
| 14867 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
| 14868 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, |
| 14869 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14870 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 14871 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14872 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 14873 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14874 | return 0; |
| 14875 | drop: |
| 14876 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14877 | "2539 Dropped frame rctl:%s type:%s\n", |
| 14878 | rctl_names[fc_hdr->fh_r_ctl], |
| 14879 | type_names[fc_hdr->fh_type]); |
| 14880 | return 1; |
| 14881 | } |
| 14882 | |
| 14883 | /** |
| 14884 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 14885 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14886 | * |
| 14887 | * This function processes the FC header to retrieve the VFI from the VF |
| 14888 | * header, if one exists. This function will return the VFI if one exists |
| 14889 | * or 0 if no VSAN Header exists. |
| 14890 | **/ |
| 14891 | static uint32_t |
| 14892 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 14893 | { |
| 14894 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14895 | |
| 14896 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14897 | return 0; |
| 14898 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14899 | } |
| 14900 | |
| 14901 | /** |
| 14902 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14903 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14904 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14905 | * @fcfi: The FC Fabric ID that the frame came from |
| 14906 | * |
| 14907 | * This function searches the @phba for a vport that matches the content of the |
| 14908 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14909 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14910 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14911 | * vport. |
| 14912 | **/ |
| 14913 | static struct lpfc_vport * |
| 14914 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14915 | uint16_t fcfi) |
| 14916 | { |
| 14917 | struct lpfc_vport **vports; |
| 14918 | struct lpfc_vport *vport = NULL; |
| 14919 | int i; |
| 14920 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14921 | fc_hdr->fh_d_id[1] << 8 | |
| 14922 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14923 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14924 | if (did == Fabric_DID) |
| 14925 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14926 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14927 | !(phba->link_state == LPFC_HBA_READY)) |
| 14928 | return phba->pport; |
| 14929 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14930 | vports = lpfc_create_vport_work_array(phba); |
| 14931 | if (vports != NULL) |
| 14932 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14933 | if (phba->fcf.fcfi == fcfi && |
| 14934 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14935 | vports[i]->fc_myDID == did) { |
| 14936 | vport = vports[i]; |
| 14937 | break; |
| 14938 | } |
| 14939 | } |
| 14940 | lpfc_destroy_vport_work_array(phba, vports); |
| 14941 | return vport; |
| 14942 | } |
| 14943 | |
| 14944 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14945 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14946 | * @vport: The vport to work on. |
| 14947 | * |
| 14948 | * This function updates the receive sequence time stamp for this vport. The |
| 14949 | * receive sequence time stamp indicates the time that the last frame of the |
| 14950 | * the sequence that has been idle for the longest amount of time was received. |
| 14951 | * the driver uses this time stamp to indicate if any received sequences have |
| 14952 | * timed out. |
| 14953 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 14954 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14955 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14956 | { |
| 14957 | struct lpfc_dmabuf *h_buf; |
| 14958 | struct hbq_dmabuf *dmabuf = NULL; |
| 14959 | |
| 14960 | /* get the oldest sequence on the rcv list */ |
| 14961 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14962 | struct lpfc_dmabuf, list); |
| 14963 | if (!h_buf) |
| 14964 | return; |
| 14965 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14966 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14967 | } |
| 14968 | |
| 14969 | /** |
| 14970 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14971 | * @vport: The vport that the received sequences were sent to. |
| 14972 | * |
| 14973 | * This function cleans up all outstanding received sequences. This is called |
| 14974 | * by the driver when a link event or user action invalidates all the received |
| 14975 | * sequences. |
| 14976 | **/ |
| 14977 | void |
| 14978 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14979 | { |
| 14980 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14981 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14982 | struct hbq_dmabuf *dmabuf = NULL; |
| 14983 | |
| 14984 | /* start with the oldest sequence on the rcv list */ |
| 14985 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14986 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14987 | list_del_init(&dmabuf->hbuf.list); |
| 14988 | list_for_each_entry_safe(d_buf, dnext, |
| 14989 | &dmabuf->dbuf.list, list) { |
| 14990 | list_del_init(&d_buf->list); |
| 14991 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14992 | } |
| 14993 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14994 | } |
| 14995 | } |
| 14996 | |
| 14997 | /** |
| 14998 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 14999 | * @vport: The vport that the received sequences were sent to. |
| 15000 | * |
| 15001 | * This function determines whether any received sequences have timed out by |
| 15002 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 15003 | * indicates that there is at least one timed out sequence this routine will |
| 15004 | * go through the received sequences one at a time from most inactive to most |
| 15005 | * active to determine which ones need to be cleaned up. Once it has determined |
| 15006 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 15007 | * without sending an abort. |
| 15008 | **/ |
| 15009 | void |
| 15010 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 15011 | { |
| 15012 | struct lpfc_dmabuf *h_buf, *hnext; |
| 15013 | struct lpfc_dmabuf *d_buf, *dnext; |
| 15014 | struct hbq_dmabuf *dmabuf = NULL; |
| 15015 | unsigned long timeout; |
| 15016 | int abort_count = 0; |
| 15017 | |
| 15018 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 15019 | vport->rcv_buffer_time_stamp); |
| 15020 | if (list_empty(&vport->rcv_buffer_list) || |
| 15021 | time_before(jiffies, timeout)) |
| 15022 | return; |
| 15023 | /* start with the oldest sequence on the rcv list */ |
| 15024 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 15025 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15026 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 15027 | dmabuf->time_stamp); |
| 15028 | if (time_before(jiffies, timeout)) |
| 15029 | break; |
| 15030 | abort_count++; |
| 15031 | list_del_init(&dmabuf->hbuf.list); |
| 15032 | list_for_each_entry_safe(d_buf, dnext, |
| 15033 | &dmabuf->dbuf.list, list) { |
| 15034 | list_del_init(&d_buf->list); |
| 15035 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15036 | } |
| 15037 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 15038 | } |
| 15039 | if (abort_count) |
| 15040 | lpfc_update_rcv_time_stamp(vport); |
| 15041 | } |
| 15042 | |
| 15043 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15044 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 15045 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 15046 | * |
| 15047 | * This function searches through the existing incomplete sequences that have |
| 15048 | * been sent to this @vport. If the frame matches one of the incomplete |
| 15049 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 15050 | * make up that sequence. If no sequence is found that matches this frame then |
| 15051 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 15052 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 15053 | * the frame was linked to. |
| 15054 | **/ |
| 15055 | static struct hbq_dmabuf * |
| 15056 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 15057 | { |
| 15058 | struct fc_frame_header *new_hdr; |
| 15059 | struct fc_frame_header *temp_hdr; |
| 15060 | struct lpfc_dmabuf *d_buf; |
| 15061 | struct lpfc_dmabuf *h_buf; |
| 15062 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 15063 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15064 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15065 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15066 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15067 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15068 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15069 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15070 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 15071 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 15072 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 15073 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 15074 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 15075 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 15076 | continue; |
| 15077 | /* found a pending sequence that matches this frame */ |
| 15078 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15079 | break; |
| 15080 | } |
| 15081 | if (!seq_dmabuf) { |
| 15082 | /* |
| 15083 | * This indicates first frame received for this sequence. |
| 15084 | * Queue the buffer on the vport's rcv_buffer_list. |
| 15085 | */ |
| 15086 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15087 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15088 | return dmabuf; |
| 15089 | } |
| 15090 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15091 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 15092 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15093 | list_del_init(&seq_dmabuf->hbuf.list); |
| 15094 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15095 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15096 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15097 | return dmabuf; |
| 15098 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15099 | /* move this sequence to the tail to indicate a young sequence */ |
| 15100 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 15101 | seq_dmabuf->time_stamp = jiffies; |
| 15102 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15103 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 15104 | temp_hdr = dmabuf->hbuf.virt; |
| 15105 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 15106 | return seq_dmabuf; |
| 15107 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15108 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15109 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 15110 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15111 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15112 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 15113 | /* |
| 15114 | * If the frame's sequence count is greater than the frame on |
| 15115 | * the list then insert the frame right after this frame |
| 15116 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15117 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 15118 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15119 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15120 | found = 1; |
| 15121 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15122 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15123 | |
| 15124 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 15125 | break; |
| 15126 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15127 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 15128 | |
| 15129 | if (found) |
| 15130 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15131 | return NULL; |
| 15132 | } |
| 15133 | |
| 15134 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15135 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 15136 | * @vport: pointer to a vitural port |
| 15137 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15138 | * |
| 15139 | * This function tries to abort from the partially assembed sequence, described |
| 15140 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 15141 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 15142 | * the frames from the partially assembled sequence. |
| 15143 | * |
| 15144 | * Return |
| 15145 | * true -- if there is matching partially assembled sequence present and all |
| 15146 | * the frames freed with the sequence; |
| 15147 | * false -- if there is no matching partially assembled sequence present so |
| 15148 | * nothing got aborted in the lower layer driver |
| 15149 | **/ |
| 15150 | static bool |
| 15151 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 15152 | struct hbq_dmabuf *dmabuf) |
| 15153 | { |
| 15154 | struct fc_frame_header *new_hdr; |
| 15155 | struct fc_frame_header *temp_hdr; |
| 15156 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 15157 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 15158 | |
| 15159 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 15160 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 15161 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 15162 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15163 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 15164 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 15165 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 15166 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 15167 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 15168 | continue; |
| 15169 | /* found a pending sequence that matches this frame */ |
| 15170 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 15171 | break; |
| 15172 | } |
| 15173 | |
| 15174 | /* Free up all the frames from the partially assembled sequence */ |
| 15175 | if (seq_dmabuf) { |
| 15176 | list_for_each_entry_safe(d_buf, n_buf, |
| 15177 | &seq_dmabuf->dbuf.list, list) { |
| 15178 | list_del_init(&d_buf->list); |
| 15179 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15180 | } |
| 15181 | return true; |
| 15182 | } |
| 15183 | return false; |
| 15184 | } |
| 15185 | |
| 15186 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15187 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 15188 | * @vport: pointer to a vitural port |
| 15189 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15190 | * |
| 15191 | * This function tries to abort from the assembed sequence from upper level |
| 15192 | * protocol, described by the information from basic abbort @dmabuf. It |
| 15193 | * checks to see whether such pending context exists at upper level protocol. |
| 15194 | * If so, it shall clean up the pending context. |
| 15195 | * |
| 15196 | * Return |
| 15197 | * true -- if there is matching pending context of the sequence cleaned |
| 15198 | * at ulp; |
| 15199 | * false -- if there is no matching pending context of the sequence present |
| 15200 | * at ulp. |
| 15201 | **/ |
| 15202 | static bool |
| 15203 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 15204 | { |
| 15205 | struct lpfc_hba *phba = vport->phba; |
| 15206 | int handled; |
| 15207 | |
| 15208 | /* Accepting abort at ulp with SLI4 only */ |
| 15209 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 15210 | return false; |
| 15211 | |
| 15212 | /* Register all caring upper level protocols to attend abort */ |
| 15213 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 15214 | if (handled) |
| 15215 | return true; |
| 15216 | |
| 15217 | return false; |
| 15218 | } |
| 15219 | |
| 15220 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15221 | * 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] | 15222 | * @phba: Pointer to HBA context object. |
| 15223 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 15224 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 15225 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15226 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15227 | * event. It properly releases the memory allocated to the sequence abort |
| 15228 | * accept iocb. |
| 15229 | **/ |
| 15230 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15231 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15232 | struct lpfc_iocbq *cmd_iocbq, |
| 15233 | struct lpfc_iocbq *rsp_iocbq) |
| 15234 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15235 | struct lpfc_nodelist *ndlp; |
| 15236 | |
| 15237 | if (cmd_iocbq) { |
| 15238 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 15239 | lpfc_nlp_put(ndlp); |
| 15240 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15241 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15242 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15243 | |
| 15244 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 15245 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 15246 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15247 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 15248 | rsp_iocbq->iocb.ulpStatus, |
| 15249 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15250 | } |
| 15251 | |
| 15252 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15253 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 15254 | * @phba: Pointer to HBA context object. |
| 15255 | * @xri: xri id in transaction. |
| 15256 | * |
| 15257 | * This function validates the xri maps to the known range of XRIs allocated an |
| 15258 | * used by the driver. |
| 15259 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15260 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15261 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 15262 | uint16_t xri) |
| 15263 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15264 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15265 | |
| 15266 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 15267 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 15268 | return i; |
| 15269 | } |
| 15270 | return NO_XRI; |
| 15271 | } |
| 15272 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15273 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15274 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15275 | * @phba: Pointer to HBA context object. |
| 15276 | * @fc_hdr: pointer to a FC frame header. |
| 15277 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15278 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15279 | * event after aborting the sequence handling. |
| 15280 | **/ |
| 15281 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15282 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 15283 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15284 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15285 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15286 | struct lpfc_iocbq *ctiocb = NULL; |
| 15287 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15288 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15289 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15290 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15291 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15292 | |
| 15293 | if (!lpfc_is_link_up(phba)) |
| 15294 | return; |
| 15295 | |
| 15296 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 15297 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15298 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15299 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15300 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15301 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15302 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 15303 | if (!ndlp) { |
| 15304 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15305 | "1268 Failed to allocate ndlp for " |
| 15306 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 15307 | return; |
| 15308 | } |
| 15309 | lpfc_nlp_init(vport, ndlp, sid); |
| 15310 | /* Put ndlp onto pport node list */ |
| 15311 | lpfc_enqueue_node(vport, ndlp); |
| 15312 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 15313 | /* re-setup ndlp without removing from node list */ |
| 15314 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 15315 | if (!ndlp) { |
| 15316 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 15317 | "3275 Failed to active ndlp found " |
| 15318 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 15319 | return; |
| 15320 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15321 | } |
| 15322 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15323 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15324 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 15325 | if (!ctiocb) |
| 15326 | return; |
| 15327 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15328 | /* Extract the F_CTL field from FC_HDR */ |
| 15329 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 15330 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15331 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15332 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15333 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15334 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 15335 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 15336 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 15337 | |
| 15338 | /* Fill in the rest of iocb fields */ |
| 15339 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 15340 | icmd->ulpBdeCount = 0; |
| 15341 | icmd->ulpLe = 1; |
| 15342 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15343 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15344 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15345 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15346 | ctiocb->iocb_cmpl = NULL; |
| 15347 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15348 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15349 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15350 | ctiocb->sli4_xritag = NO_XRI; |
| 15351 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 15352 | if (fctl & FC_FC_EX_CTX) |
| 15353 | /* Exchange responder sent the abort so we |
| 15354 | * own the oxid. |
| 15355 | */ |
| 15356 | xri = oxid; |
| 15357 | else |
| 15358 | xri = rxid; |
| 15359 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 15360 | if (lxri != NO_XRI) |
| 15361 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 15362 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15363 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 15364 | * the oxid maps to the FCP XRI range, the port no longer has |
| 15365 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 15366 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15367 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15368 | if ((fctl & FC_FC_EX_CTX) && |
| 15369 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 15370 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15371 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15372 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15373 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15374 | } |
| 15375 | |
| 15376 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 15377 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 15378 | * the IOCB for a BA_RJT. |
| 15379 | */ |
| 15380 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15381 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 15382 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 15383 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 15384 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 15385 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15386 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15387 | if (fctl & FC_FC_EX_CTX) { |
| 15388 | /* ABTS sent by responder to CT exchange, construction |
| 15389 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 15390 | * field and RX_ID from ABTS for RX_ID field. |
| 15391 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15392 | 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] | 15393 | } else { |
| 15394 | /* ABTS sent by initiator to CT exchange, construction |
| 15395 | * 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] | 15396 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15397 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15398 | 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] | 15399 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 15400 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15401 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15402 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15403 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15404 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 15405 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 15406 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15407 | |
| 15408 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 15409 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15410 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 15411 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 15412 | "xri x%x, Data x%x\n", |
| 15413 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 15414 | phba->link_state); |
| 15415 | lpfc_nlp_put(ndlp); |
| 15416 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 15417 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 15418 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15419 | } |
| 15420 | |
| 15421 | /** |
| 15422 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 15423 | * @vport: Pointer to the vport on which this sequence was received |
| 15424 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15425 | * |
| 15426 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 15427 | * receive sequence is only partially assembed by the driver, it shall abort |
| 15428 | * the partially assembled frames for the sequence. Otherwise, if the |
| 15429 | * unsolicited receive sequence has been completely assembled and passed to |
| 15430 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 15431 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 15432 | * accept to accept the abort. |
| 15433 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15434 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15435 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 15436 | struct hbq_dmabuf *dmabuf) |
| 15437 | { |
| 15438 | struct lpfc_hba *phba = vport->phba; |
| 15439 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15440 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15441 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15442 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15443 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 15444 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15445 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15446 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15447 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15448 | /* ABTS by responder to exchange, no cleanup needed */ |
| 15449 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15450 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15451 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 15452 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 15453 | if (aborted == false) |
| 15454 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15455 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15456 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15457 | |
| 15458 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 15459 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15460 | } |
| 15461 | |
| 15462 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15463 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 15464 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15465 | * |
| 15466 | * This function checks the sequence, starting with the frame described by |
| 15467 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 15468 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 15469 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 15470 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 15471 | * set. 3) That there are no holes in the sequence count. The function will |
| 15472 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 15473 | **/ |
| 15474 | static int |
| 15475 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 15476 | { |
| 15477 | struct fc_frame_header *hdr; |
| 15478 | struct lpfc_dmabuf *d_buf; |
| 15479 | struct hbq_dmabuf *seq_dmabuf; |
| 15480 | uint32_t fctl; |
| 15481 | int seq_count = 0; |
| 15482 | |
| 15483 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15484 | /* make sure first fame of sequence has a sequence count of zero */ |
| 15485 | if (hdr->fh_seq_cnt != seq_count) |
| 15486 | return 0; |
| 15487 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15488 | hdr->fh_f_ctl[1] << 8 | |
| 15489 | hdr->fh_f_ctl[2]); |
| 15490 | /* If last frame of sequence we can return success. */ |
| 15491 | if (fctl & FC_FC_END_SEQ) |
| 15492 | return 1; |
| 15493 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 15494 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15495 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15496 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15497 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15498 | return 0; |
| 15499 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15500 | hdr->fh_f_ctl[1] << 8 | |
| 15501 | hdr->fh_f_ctl[2]); |
| 15502 | /* If last frame of sequence we can return success. */ |
| 15503 | if (fctl & FC_FC_END_SEQ) |
| 15504 | return 1; |
| 15505 | } |
| 15506 | return 0; |
| 15507 | } |
| 15508 | |
| 15509 | /** |
| 15510 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 15511 | * @vport: Pointer to the vport on which this sequence was received |
| 15512 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15513 | * |
| 15514 | * This function takes a sequence, described by a list of frames, and creates |
| 15515 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 15516 | * used to issue to the generic unsolicited sequence handler. This routine |
| 15517 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 15518 | * to allocate an iocbq then it throw out the received frames that were not |
| 15519 | * able to be described and return a pointer to the first iocbq. If unable to |
| 15520 | * allocate any iocbqs (including the first) this function will return NULL. |
| 15521 | **/ |
| 15522 | static struct lpfc_iocbq * |
| 15523 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 15524 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15525 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15526 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 15527 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 15528 | struct fc_frame_header *fc_hdr; |
| 15529 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15530 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15531 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15532 | |
| 15533 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15534 | /* remove from receive buffer list */ |
| 15535 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15536 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15537 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15538 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15539 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15540 | /* Get an iocbq struct to fill in. */ |
| 15541 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15542 | if (first_iocbq) { |
| 15543 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15544 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15545 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15546 | |
| 15547 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 15548 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 15549 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 15550 | first_iocbq->iocb.un.rcvels.parmRo = |
| 15551 | sli4_did_from_fc_hdr(fc_hdr); |
| 15552 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 15553 | } else |
| 15554 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15555 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 15556 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 15557 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 15558 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 15559 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 15560 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15561 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15562 | tot_len = bf_get(lpfc_rcqe_length, |
| 15563 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15564 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15565 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 15566 | first_iocbq->context3 = NULL; |
| 15567 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15568 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 15569 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15570 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15571 | else |
| 15572 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 15573 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15574 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15575 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15576 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15577 | } |
| 15578 | iocbq = first_iocbq; |
| 15579 | /* |
| 15580 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 15581 | * of buffers for this sequence and save two buffers in each IOCBq |
| 15582 | */ |
| 15583 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 15584 | if (!iocbq) { |
| 15585 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15586 | continue; |
| 15587 | } |
| 15588 | if (!iocbq->context3) { |
| 15589 | iocbq->context3 = d_buf; |
| 15590 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15591 | /* We need to get the size out of the right CQE */ |
| 15592 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15593 | len = bf_get(lpfc_rcqe_length, |
| 15594 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15595 | pbde = (struct ulp_bde64 *) |
| 15596 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 15597 | if (len > LPFC_DATA_BUF_SIZE) |
| 15598 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 15599 | else |
| 15600 | pbde->tus.f.bdeSize = len; |
| 15601 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15602 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 15603 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15604 | } else { |
| 15605 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15606 | if (!iocbq) { |
| 15607 | if (first_iocbq) { |
| 15608 | first_iocbq->iocb.ulpStatus = |
| 15609 | IOSTAT_FCP_RSP_ERROR; |
| 15610 | first_iocbq->iocb.un.ulpWord[4] = |
| 15611 | IOERR_NO_RESOURCES; |
| 15612 | } |
| 15613 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15614 | continue; |
| 15615 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15616 | /* We need to get the size out of the right CQE */ |
| 15617 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15618 | len = bf_get(lpfc_rcqe_length, |
| 15619 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15620 | iocbq->context2 = d_buf; |
| 15621 | iocbq->context3 = NULL; |
| 15622 | iocbq->iocb.ulpBdeCount = 1; |
| 15623 | if (len > LPFC_DATA_BUF_SIZE) |
| 15624 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 15625 | LPFC_DATA_BUF_SIZE; |
| 15626 | else |
| 15627 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 15628 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15629 | tot_len += len; |
| 15630 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 15631 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15632 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 15633 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 15634 | } |
| 15635 | } |
| 15636 | return first_iocbq; |
| 15637 | } |
| 15638 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15639 | static void |
| 15640 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 15641 | struct hbq_dmabuf *seq_dmabuf) |
| 15642 | { |
| 15643 | struct fc_frame_header *fc_hdr; |
| 15644 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 15645 | struct lpfc_hba *phba = vport->phba; |
| 15646 | |
| 15647 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15648 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 15649 | if (!iocbq) { |
| 15650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15651 | "2707 Ring %d handler: Failed to allocate " |
| 15652 | "iocb Rctl x%x Type x%x received\n", |
| 15653 | LPFC_ELS_RING, |
| 15654 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15655 | return; |
| 15656 | } |
| 15657 | if (!lpfc_complete_unsol_iocb(phba, |
| 15658 | &phba->sli.ring[LPFC_ELS_RING], |
| 15659 | iocbq, fc_hdr->fh_r_ctl, |
| 15660 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15661 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15662 | "2540 Ring %d handler: unexpected Rctl " |
| 15663 | "x%x Type x%x received\n", |
| 15664 | LPFC_ELS_RING, |
| 15665 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15666 | |
| 15667 | /* Free iocb created in lpfc_prep_seq */ |
| 15668 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 15669 | &iocbq->list, list) { |
| 15670 | list_del_init(&curr_iocb->list); |
| 15671 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 15672 | } |
| 15673 | lpfc_sli_release_iocbq(phba, iocbq); |
| 15674 | } |
| 15675 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15676 | /** |
| 15677 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 15678 | * @phba: Pointer to HBA context object. |
| 15679 | * |
| 15680 | * This function is called with no lock held. This function processes all |
| 15681 | * the received buffers and gives it to upper layers when a received buffer |
| 15682 | * indicates that it is the final frame in the sequence. The interrupt |
| 15683 | * service routine processes received buffers at interrupt contexts and adds |
| 15684 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 15685 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 15686 | * appropriate receive function when the final frame in a sequence is received. |
| 15687 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15688 | void |
| 15689 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 15690 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15691 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15692 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15693 | struct fc_frame_header *fc_hdr; |
| 15694 | struct lpfc_vport *vport; |
| 15695 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15696 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15697 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15698 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15699 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15700 | /* check to see if this a valid type of frame */ |
| 15701 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 15702 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15703 | return; |
| 15704 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15705 | if ((bf_get(lpfc_cqe_code, |
| 15706 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 15707 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 15708 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15709 | else |
| 15710 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 15711 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15712 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15713 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15714 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15715 | /* throw out the frame */ |
| 15716 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15717 | return; |
| 15718 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15719 | |
| 15720 | /* d_id this frame is directed to */ |
| 15721 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 15722 | |
| 15723 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 15724 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 15725 | (did != Fabric_DID)) { |
| 15726 | /* |
| 15727 | * Throw out the frame if we are not pt2pt. |
| 15728 | * The pt2pt protocol allows for discovery frames |
| 15729 | * to be received without a registered VPI. |
| 15730 | */ |
| 15731 | if (!(vport->fc_flag & FC_PT2PT) || |
| 15732 | (phba->link_state == LPFC_HBA_READY)) { |
| 15733 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15734 | return; |
| 15735 | } |
| 15736 | } |
| 15737 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15738 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 15739 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 15740 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 15741 | return; |
| 15742 | } |
| 15743 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15744 | /* Link this frame */ |
| 15745 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 15746 | if (!seq_dmabuf) { |
| 15747 | /* unable to add frame to vport - throw it out */ |
| 15748 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15749 | return; |
| 15750 | } |
| 15751 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15752 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15753 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15754 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15755 | /* Send the complete sequence to the upper layer protocol */ |
| 15756 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15757 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15758 | |
| 15759 | /** |
| 15760 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 15761 | * @phba: pointer to lpfc hba data structure. |
| 15762 | * |
| 15763 | * This routine is invoked to post rpi header templates to the |
| 15764 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15765 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15766 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15767 | * |
| 15768 | * This routine does not require any locks. It's usage is expected |
| 15769 | * to be driver load or reset recovery when the driver is |
| 15770 | * sequential. |
| 15771 | * |
| 15772 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15773 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15774 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15775 | * When this error occurs, the driver is not guaranteed |
| 15776 | * to have any rpi regions posted to the device and |
| 15777 | * must either attempt to repost the regions or take a |
| 15778 | * fatal error. |
| 15779 | **/ |
| 15780 | int |
| 15781 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 15782 | { |
| 15783 | struct lpfc_rpi_hdr *rpi_page; |
| 15784 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15785 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15786 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15787 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15788 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15789 | goto exit; |
| 15790 | if (phba->sli4_hba.extents_in_use) |
| 15791 | return -EIO; |
| 15792 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15793 | 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] | 15794 | /* |
| 15795 | * Assign the rpi headers a physical rpi only if the driver |
| 15796 | * has not initialized those resources. A port reset only |
| 15797 | * needs the headers posted. |
| 15798 | */ |
| 15799 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 15800 | LPFC_RPI_RSRC_RDY) |
| 15801 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 15802 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15803 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 15804 | if (rc != MBX_SUCCESS) { |
| 15805 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15806 | "2008 Error %d posting all rpi " |
| 15807 | "headers\n", rc); |
| 15808 | rc = -EIO; |
| 15809 | break; |
| 15810 | } |
| 15811 | } |
| 15812 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15813 | exit: |
| 15814 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 15815 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15816 | return rc; |
| 15817 | } |
| 15818 | |
| 15819 | /** |
| 15820 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 15821 | * @phba: pointer to lpfc hba data structure. |
| 15822 | * @rpi_page: pointer to the rpi memory region. |
| 15823 | * |
| 15824 | * This routine is invoked to post a single rpi header to the |
| 15825 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 15826 | * maps up to 64 rpi context regions. |
| 15827 | * |
| 15828 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15829 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15830 | * -ENOMEM - No available memory |
| 15831 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15832 | **/ |
| 15833 | int |
| 15834 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 15835 | { |
| 15836 | LPFC_MBOXQ_t *mboxq; |
| 15837 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 15838 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15839 | uint32_t shdr_status, shdr_add_status; |
| 15840 | union lpfc_sli4_cfg_shdr *shdr; |
| 15841 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15842 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15843 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15844 | return rc; |
| 15845 | if (phba->sli4_hba.extents_in_use) |
| 15846 | return -EIO; |
| 15847 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15848 | /* The port is notified of the header region via a mailbox command. */ |
| 15849 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15850 | if (!mboxq) { |
| 15851 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15852 | "2001 Unable to allocate memory for issuing " |
| 15853 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 15854 | return -ENOMEM; |
| 15855 | } |
| 15856 | |
| 15857 | /* Post all rpi memory regions to the port. */ |
| 15858 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15859 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15860 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 15861 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15862 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 15863 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15864 | |
| 15865 | |
| 15866 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15867 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 15868 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15869 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 15870 | hdr_tmpl, rpi_page->page_count); |
| 15871 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15872 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 15873 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 15874 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15875 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 15876 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15877 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15878 | if (rc != MBX_TIMEOUT) |
| 15879 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15880 | if (shdr_status || shdr_add_status || rc) { |
| 15881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15882 | "2514 POST_RPI_HDR mailbox failed with " |
| 15883 | "status x%x add_status x%x, mbx status x%x\n", |
| 15884 | shdr_status, shdr_add_status, rc); |
| 15885 | rc = -ENXIO; |
| 15886 | } |
| 15887 | return rc; |
| 15888 | } |
| 15889 | |
| 15890 | /** |
| 15891 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 15892 | * @phba: pointer to lpfc hba data structure. |
| 15893 | * |
| 15894 | * This routine is invoked to post rpi header templates to the |
| 15895 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15896 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15897 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15898 | * |
| 15899 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15900 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15901 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15902 | **/ |
| 15903 | int |
| 15904 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 15905 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15906 | unsigned long rpi; |
| 15907 | uint16_t max_rpi, rpi_limit; |
| 15908 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15909 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15910 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15911 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15912 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15913 | * Fetch the next logical rpi. Because this index is logical, |
| 15914 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15915 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15916 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15917 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 15918 | rpi_limit = phba->sli4_hba.next_rpi; |
| 15919 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15920 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15921 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15922 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15923 | else { |
| 15924 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15925 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15926 | phba->sli4_hba.rpi_count++; |
| 15927 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 15928 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 15929 | "0001 rpi:%x max:%x lim:%x\n", |
| 15930 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15931 | |
| 15932 | /* |
| 15933 | * 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] | 15934 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15935 | */ |
| 15936 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15937 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15938 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15939 | return rpi; |
| 15940 | } |
| 15941 | |
| 15942 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15943 | * RPI header postings are not required for SLI4 ports capable of |
| 15944 | * extents. |
| 15945 | */ |
| 15946 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15947 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15948 | return rpi; |
| 15949 | } |
| 15950 | |
| 15951 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15952 | * If the driver is running low on rpi resources, allocate another |
| 15953 | * page now. Note that the next_rpi value is used because |
| 15954 | * it represents how many are actually in use whereas max_rpi notes |
| 15955 | * how many are supported max by the device. |
| 15956 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15957 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15958 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15959 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15960 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15961 | if (!rpi_hdr) { |
| 15962 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15963 | "2002 Error Could not grow rpi " |
| 15964 | "count\n"); |
| 15965 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15966 | lrpi = rpi_hdr->start_rpi; |
| 15967 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15968 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15969 | } |
| 15970 | } |
| 15971 | |
| 15972 | return rpi; |
| 15973 | } |
| 15974 | |
| 15975 | /** |
| 15976 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15977 | * @phba: pointer to lpfc hba data structure. |
| 15978 | * |
| 15979 | * This routine is invoked to release an rpi to the pool of |
| 15980 | * available rpis maintained by the driver. |
| 15981 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15982 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15983 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15984 | { |
| 15985 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 15986 | phba->sli4_hba.rpi_count--; |
| 15987 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 15988 | } |
| 15989 | } |
| 15990 | |
| 15991 | /** |
| 15992 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15993 | * @phba: pointer to lpfc hba data structure. |
| 15994 | * |
| 15995 | * This routine is invoked to release an rpi to the pool of |
| 15996 | * available rpis maintained by the driver. |
| 15997 | **/ |
| 15998 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15999 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 16000 | { |
| 16001 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 16002 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16003 | spin_unlock_irq(&phba->hbalock); |
| 16004 | } |
| 16005 | |
| 16006 | /** |
| 16007 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 16008 | * @phba: pointer to lpfc hba data structure. |
| 16009 | * |
| 16010 | * This routine is invoked to remove the memory region that |
| 16011 | * provided rpi via a bitmask. |
| 16012 | **/ |
| 16013 | void |
| 16014 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 16015 | { |
| 16016 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16017 | kfree(phba->sli4_hba.rpi_ids); |
| 16018 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16019 | } |
| 16020 | |
| 16021 | /** |
| 16022 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 16023 | * @phba: pointer to lpfc hba data structure. |
| 16024 | * |
| 16025 | * This routine is invoked to remove the memory region that |
| 16026 | * provided rpi via a bitmask. |
| 16027 | **/ |
| 16028 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16029 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 16030 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16031 | { |
| 16032 | LPFC_MBOXQ_t *mboxq; |
| 16033 | struct lpfc_hba *phba = ndlp->phba; |
| 16034 | int rc; |
| 16035 | |
| 16036 | /* The port is notified of the header region via a mailbox command. */ |
| 16037 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16038 | if (!mboxq) |
| 16039 | return -ENOMEM; |
| 16040 | |
| 16041 | /* Post all rpi memory regions to the port. */ |
| 16042 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16043 | if (cmpl) { |
| 16044 | mboxq->mbox_cmpl = cmpl; |
| 16045 | mboxq->context1 = arg; |
| 16046 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 16047 | } else |
| 16048 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16049 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16050 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16051 | if (rc == MBX_NOT_FINISHED) { |
| 16052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16053 | "2010 Resume RPI Mailbox failed " |
| 16054 | "status %d, mbxStatus x%x\n", rc, |
| 16055 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 16056 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16057 | return -EIO; |
| 16058 | } |
| 16059 | return 0; |
| 16060 | } |
| 16061 | |
| 16062 | /** |
| 16063 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16064 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16065 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16066 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16067 | * |
| 16068 | * Returns: |
| 16069 | * 0 success |
| 16070 | * -Evalue otherwise |
| 16071 | **/ |
| 16072 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16073 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16074 | { |
| 16075 | LPFC_MBOXQ_t *mboxq; |
| 16076 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16077 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16078 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16079 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16080 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16081 | if (!mboxq) |
| 16082 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16083 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16084 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16085 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16086 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16087 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16088 | "2022 INIT VPI Mailbox failed " |
| 16089 | "status %d, mbxStatus x%x\n", rc, |
| 16090 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16091 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16092 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16093 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 16094 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 16095 | |
| 16096 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16097 | } |
| 16098 | |
| 16099 | /** |
| 16100 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 16101 | * @phba: pointer to lpfc hba data structure. |
| 16102 | * @mboxq: Pointer to mailbox object. |
| 16103 | * |
| 16104 | * This routine is invoked to manually add a single FCF record. The caller |
| 16105 | * must pass a completely initialized FCF_Record. This routine takes |
| 16106 | * care of the nonembedded mailbox operations. |
| 16107 | **/ |
| 16108 | static void |
| 16109 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 16110 | { |
| 16111 | void *virt_addr; |
| 16112 | union lpfc_sli4_cfg_shdr *shdr; |
| 16113 | uint32_t shdr_status, shdr_add_status; |
| 16114 | |
| 16115 | virt_addr = mboxq->sge_array->addr[0]; |
| 16116 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16117 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 16118 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16119 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16120 | |
| 16121 | if ((shdr_status || shdr_add_status) && |
| 16122 | (shdr_status != STATUS_FCF_IN_USE)) |
| 16123 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16124 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 16125 | "status x%x add_status x%x\n", |
| 16126 | shdr_status, shdr_add_status); |
| 16127 | |
| 16128 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16129 | } |
| 16130 | |
| 16131 | /** |
| 16132 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 16133 | * @phba: pointer to lpfc hba data structure. |
| 16134 | * @fcf_record: pointer to the initialized fcf record to add. |
| 16135 | * |
| 16136 | * This routine is invoked to manually add a single FCF record. The caller |
| 16137 | * must pass a completely initialized FCF_Record. This routine takes |
| 16138 | * care of the nonembedded mailbox operations. |
| 16139 | **/ |
| 16140 | int |
| 16141 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 16142 | { |
| 16143 | int rc = 0; |
| 16144 | LPFC_MBOXQ_t *mboxq; |
| 16145 | uint8_t *bytep; |
| 16146 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16147 | struct lpfc_mbx_sge sge; |
| 16148 | uint32_t alloc_len, req_len; |
| 16149 | uint32_t fcfindex; |
| 16150 | |
| 16151 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16152 | if (!mboxq) { |
| 16153 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16154 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 16155 | return -ENOMEM; |
| 16156 | } |
| 16157 | |
| 16158 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 16159 | sizeof(uint32_t); |
| 16160 | |
| 16161 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16162 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16163 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 16164 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 16165 | if (alloc_len < req_len) { |
| 16166 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16167 | "2523 Allocated DMA memory size (x%x) is " |
| 16168 | "less than the requested DMA memory " |
| 16169 | "size (x%x)\n", alloc_len, req_len); |
| 16170 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16171 | return -ENOMEM; |
| 16172 | } |
| 16173 | |
| 16174 | /* |
| 16175 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 16176 | * routine only uses a single SGE. |
| 16177 | */ |
| 16178 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16179 | virt_addr = mboxq->sge_array->addr[0]; |
| 16180 | /* |
| 16181 | * Configure the FCF record for FCFI 0. This is the driver's |
| 16182 | * hardcoded default and gets used in nonFIP mode. |
| 16183 | */ |
| 16184 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 16185 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 16186 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 16187 | |
| 16188 | /* |
| 16189 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 16190 | * the FCoE header plus word10. The data copy needs to be endian |
| 16191 | * correct. |
| 16192 | */ |
| 16193 | bytep += sizeof(uint32_t); |
| 16194 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 16195 | mboxq->vport = phba->pport; |
| 16196 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 16197 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16198 | if (rc == MBX_NOT_FINISHED) { |
| 16199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16200 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 16201 | "status 0x%x\n", rc); |
| 16202 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16203 | rc = -EIO; |
| 16204 | } else |
| 16205 | rc = 0; |
| 16206 | |
| 16207 | return rc; |
| 16208 | } |
| 16209 | |
| 16210 | /** |
| 16211 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 16212 | * @phba: pointer to lpfc hba data structure. |
| 16213 | * @fcf_record: pointer to the fcf record to write the default data. |
| 16214 | * @fcf_index: FCF table entry index. |
| 16215 | * |
| 16216 | * This routine is invoked to build the driver's default FCF record. The |
| 16217 | * values used are hardcoded. This routine handles memory initialization. |
| 16218 | * |
| 16219 | **/ |
| 16220 | void |
| 16221 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 16222 | struct fcf_record *fcf_record, |
| 16223 | uint16_t fcf_index) |
| 16224 | { |
| 16225 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 16226 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 16227 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 16228 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 16229 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 16230 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 16231 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 16232 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 16233 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 16234 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 16235 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 16236 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 16237 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 16238 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 16239 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16240 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 16241 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 16242 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 16243 | /* Set the VLAN bit map */ |
| 16244 | if (phba->valid_vlan) { |
| 16245 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 16246 | = 1 << (phba->vlan_id % 8); |
| 16247 | } |
| 16248 | } |
| 16249 | |
| 16250 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16251 | * 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] | 16252 | * @phba: pointer to lpfc hba data structure. |
| 16253 | * @fcf_index: FCF table entry offset. |
| 16254 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16255 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 16256 | * record and processing it one at a time starting from the @fcf_index |
| 16257 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 16258 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16259 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16260 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16261 | **/ |
| 16262 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16263 | 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] | 16264 | { |
| 16265 | int rc = 0, error; |
| 16266 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16267 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16268 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 16269 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16270 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16271 | if (!mboxq) { |
| 16272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16273 | "2000 Failed to allocate mbox for " |
| 16274 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16275 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16276 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16277 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16278 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16279 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16280 | if (rc) { |
| 16281 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16282 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16283 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16284 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16285 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16286 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16287 | |
| 16288 | spin_lock_irq(&phba->hbalock); |
| 16289 | phba->hba_flag |= FCF_TS_INPROG; |
| 16290 | spin_unlock_irq(&phba->hbalock); |
| 16291 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16292 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16293 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16294 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16295 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 16296 | /* Reset eligible FCF count for new scan */ |
| 16297 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 16298 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16299 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 16300 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16301 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16302 | if (error) { |
| 16303 | if (mboxq) |
| 16304 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16305 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16306 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16307 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16308 | spin_unlock_irq(&phba->hbalock); |
| 16309 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 16310 | return error; |
| 16311 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16312 | |
| 16313 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16314 | * 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] | 16315 | * @phba: pointer to lpfc hba data structure. |
| 16316 | * @fcf_index: FCF table entry offset. |
| 16317 | * |
| 16318 | * 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] | 16319 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16320 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16321 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16322 | * otherwise. |
| 16323 | **/ |
| 16324 | int |
| 16325 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16326 | { |
| 16327 | int rc = 0, error; |
| 16328 | LPFC_MBOXQ_t *mboxq; |
| 16329 | |
| 16330 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16331 | if (!mboxq) { |
| 16332 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16333 | "2763 Failed to allocate mbox for " |
| 16334 | "READ_FCF cmd\n"); |
| 16335 | error = -ENOMEM; |
| 16336 | goto fail_fcf_read; |
| 16337 | } |
| 16338 | /* Construct the read FCF record mailbox command */ |
| 16339 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16340 | if (rc) { |
| 16341 | error = -EINVAL; |
| 16342 | goto fail_fcf_read; |
| 16343 | } |
| 16344 | /* Issue the mailbox command asynchronously */ |
| 16345 | mboxq->vport = phba->pport; |
| 16346 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 16347 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16348 | if (rc == MBX_NOT_FINISHED) |
| 16349 | error = -EIO; |
| 16350 | else |
| 16351 | error = 0; |
| 16352 | |
| 16353 | fail_fcf_read: |
| 16354 | if (error && mboxq) |
| 16355 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16356 | return error; |
| 16357 | } |
| 16358 | |
| 16359 | /** |
| 16360 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 16361 | * @phba: pointer to lpfc hba data structure. |
| 16362 | * @fcf_index: FCF table entry offset. |
| 16363 | * |
| 16364 | * 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] | 16365 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16366 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16367 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16368 | * otherwise. |
| 16369 | **/ |
| 16370 | int |
| 16371 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16372 | { |
| 16373 | int rc = 0, error; |
| 16374 | LPFC_MBOXQ_t *mboxq; |
| 16375 | |
| 16376 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16377 | if (!mboxq) { |
| 16378 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 16379 | "2758 Failed to allocate mbox for " |
| 16380 | "READ_FCF cmd\n"); |
| 16381 | error = -ENOMEM; |
| 16382 | goto fail_fcf_read; |
| 16383 | } |
| 16384 | /* Construct the read FCF record mailbox command */ |
| 16385 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 16386 | if (rc) { |
| 16387 | error = -EINVAL; |
| 16388 | goto fail_fcf_read; |
| 16389 | } |
| 16390 | /* Issue the mailbox command asynchronously */ |
| 16391 | mboxq->vport = phba->pport; |
| 16392 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 16393 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 16394 | if (rc == MBX_NOT_FINISHED) |
| 16395 | error = -EIO; |
| 16396 | else |
| 16397 | error = 0; |
| 16398 | |
| 16399 | fail_fcf_read: |
| 16400 | if (error && mboxq) |
| 16401 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 16402 | return error; |
| 16403 | } |
| 16404 | |
| 16405 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16406 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16407 | * phba pointer to the lpfc_hba struct for this port. |
| 16408 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 16409 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 16410 | * rr_bmask based on their priority level. Starting from the highest priority |
| 16411 | * to the lowest. The most likely FCF candidate will be in the highest |
| 16412 | * priority group. When this routine is called it searches the fcf_pri list for |
| 16413 | * next lowest priority group and repopulates the rr_bmask with only those |
| 16414 | * fcf_indexes. |
| 16415 | * returns: |
| 16416 | * 1=success 0=failure |
| 16417 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16418 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16419 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 16420 | { |
| 16421 | uint16_t next_fcf_pri; |
| 16422 | uint16_t last_index; |
| 16423 | struct lpfc_fcf_pri *fcf_pri; |
| 16424 | int rc; |
| 16425 | int ret = 0; |
| 16426 | |
| 16427 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 16428 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16429 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 16430 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16431 | |
| 16432 | /* Verify the priority list has 2 or more entries */ |
| 16433 | spin_lock_irq(&phba->hbalock); |
| 16434 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 16435 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 16436 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16437 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 16438 | "3061 Last IDX %d\n", last_index); |
| 16439 | return 0; /* Empty rr list */ |
| 16440 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16441 | spin_unlock_irq(&phba->hbalock); |
| 16442 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16443 | next_fcf_pri = 0; |
| 16444 | /* |
| 16445 | * Clear the rr_bmask and set all of the bits that are at this |
| 16446 | * priority. |
| 16447 | */ |
| 16448 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 16449 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 16450 | spin_lock_irq(&phba->hbalock); |
| 16451 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16452 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 16453 | continue; |
| 16454 | /* |
| 16455 | * the 1st priority that has not FLOGI failed |
| 16456 | * will be the highest. |
| 16457 | */ |
| 16458 | if (!next_fcf_pri) |
| 16459 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16460 | spin_unlock_irq(&phba->hbalock); |
| 16461 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16462 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16463 | fcf_pri->fcf_rec.fcf_index); |
| 16464 | if (rc) |
| 16465 | return 0; |
| 16466 | } |
| 16467 | spin_lock_irq(&phba->hbalock); |
| 16468 | } |
| 16469 | /* |
| 16470 | * if next_fcf_pri was not set above and the list is not empty then |
| 16471 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 16472 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16473 | */ |
| 16474 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 16475 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16476 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 16477 | /* |
| 16478 | * the 1st priority that has not FLOGI failed |
| 16479 | * will be the highest. |
| 16480 | */ |
| 16481 | if (!next_fcf_pri) |
| 16482 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16483 | spin_unlock_irq(&phba->hbalock); |
| 16484 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16485 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16486 | fcf_pri->fcf_rec.fcf_index); |
| 16487 | if (rc) |
| 16488 | return 0; |
| 16489 | } |
| 16490 | spin_lock_irq(&phba->hbalock); |
| 16491 | } |
| 16492 | } else |
| 16493 | ret = 1; |
| 16494 | spin_unlock_irq(&phba->hbalock); |
| 16495 | |
| 16496 | return ret; |
| 16497 | } |
| 16498 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16499 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 16500 | * @phba: pointer to lpfc hba data structure. |
| 16501 | * |
| 16502 | * This routine is to get the next eligible FCF record index in a round |
| 16503 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16504 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16505 | * shall be returned, otherwise, the next eligible FCF record's index |
| 16506 | * shall be returned. |
| 16507 | **/ |
| 16508 | uint16_t |
| 16509 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 16510 | { |
| 16511 | uint16_t next_fcf_index; |
| 16512 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16513 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16514 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16515 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 16516 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16517 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16518 | /* Determine the next fcf index to check */ |
| 16519 | 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] | 16520 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16521 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16522 | next_fcf_index); |
| 16523 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16524 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16525 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16526 | /* |
| 16527 | * If we have wrapped then we need to clear the bits that |
| 16528 | * have been tested so that we can detect when we should |
| 16529 | * change the priority level. |
| 16530 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16531 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16532 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16533 | } |
| 16534 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16535 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16536 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16537 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 16538 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 16539 | /* |
| 16540 | * If next fcf index is not found check if there are lower |
| 16541 | * Priority level fcf's in the fcf_priority list. |
| 16542 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 16543 | * at that level and continue the selection process. |
| 16544 | */ |
| 16545 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16546 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16547 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16548 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16549 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 16550 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16551 | else { |
| 16552 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16553 | "3063 Only FCF available idx %d, flag %x\n", |
| 16554 | next_fcf_index, |
| 16555 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 16556 | return next_fcf_index; |
| 16557 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16558 | } |
| 16559 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16560 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 16561 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16562 | LPFC_FCF_FLOGI_FAILED) { |
| 16563 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 16564 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16565 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16566 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 16567 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16568 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16569 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16570 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 16571 | next_fcf_index); |
| 16572 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16573 | return next_fcf_index; |
| 16574 | } |
| 16575 | |
| 16576 | /** |
| 16577 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 16578 | * @phba: pointer to lpfc hba data structure. |
| 16579 | * |
| 16580 | * 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] | 16581 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16582 | * does not go beyond the range of the driver allocated bmask dimension |
| 16583 | * before setting the bit. |
| 16584 | * |
| 16585 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 16586 | * -EINVAL. |
| 16587 | **/ |
| 16588 | int |
| 16589 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16590 | { |
| 16591 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16592 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16593 | "2610 FCF (x%x) reached driver's book " |
| 16594 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16595 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16596 | return -EINVAL; |
| 16597 | } |
| 16598 | /* Set the eligible FCF record index bmask */ |
| 16599 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 16600 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16601 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16602 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16603 | "bmask\n", fcf_index); |
| 16604 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16605 | return 0; |
| 16606 | } |
| 16607 | |
| 16608 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16609 | * 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] | 16610 | * @phba: pointer to lpfc hba data structure. |
| 16611 | * |
| 16612 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16613 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16614 | * does not go beyond the range of the driver allocated bmask dimension |
| 16615 | * before clearing the bit. |
| 16616 | **/ |
| 16617 | void |
| 16618 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16619 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16620 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16621 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16622 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16623 | "2762 FCF (x%x) reached driver's book " |
| 16624 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16625 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16626 | return; |
| 16627 | } |
| 16628 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16629 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16630 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 16631 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16632 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 16633 | list_del_init(&fcf_pri->list); |
| 16634 | break; |
| 16635 | } |
| 16636 | } |
| 16637 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16638 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16639 | |
| 16640 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16641 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16642 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16643 | } |
| 16644 | |
| 16645 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16646 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 16647 | * @phba: pointer to lpfc hba data structure. |
| 16648 | * |
| 16649 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 16650 | * command. If the mailbox command returned failure, it will try to stop the |
| 16651 | * FCF rediscover wait timer. |
| 16652 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16653 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16654 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 16655 | { |
| 16656 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16657 | uint32_t shdr_status, shdr_add_status; |
| 16658 | |
| 16659 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16660 | |
| 16661 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 16662 | &redisc_fcf->header.cfg_shdr.response); |
| 16663 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 16664 | &redisc_fcf->header.cfg_shdr.response); |
| 16665 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16666 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16667 | "2746 Requesting for FCF rediscovery failed " |
| 16668 | "status x%x add_status x%x\n", |
| 16669 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16670 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16671 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16672 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16673 | spin_unlock_irq(&phba->hbalock); |
| 16674 | /* |
| 16675 | * CVL event triggered FCF rediscover request failed, |
| 16676 | * last resort to re-try current registered FCF entry. |
| 16677 | */ |
| 16678 | lpfc_retry_pport_discovery(phba); |
| 16679 | } else { |
| 16680 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16681 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16682 | spin_unlock_irq(&phba->hbalock); |
| 16683 | /* |
| 16684 | * DEAD FCF event triggered FCF rediscover request |
| 16685 | * failed, last resort to fail over as a link down |
| 16686 | * to FCF registration. |
| 16687 | */ |
| 16688 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 16689 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16690 | } else { |
| 16691 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16692 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16693 | /* |
| 16694 | * Start FCF rediscovery wait timer for pending FCF |
| 16695 | * before rescan FCF record table. |
| 16696 | */ |
| 16697 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16698 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16699 | |
| 16700 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16701 | } |
| 16702 | |
| 16703 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16704 | * 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] | 16705 | * @phba: pointer to lpfc hba data structure. |
| 16706 | * |
| 16707 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 16708 | * by the port. |
| 16709 | **/ |
| 16710 | int |
| 16711 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 16712 | { |
| 16713 | LPFC_MBOXQ_t *mbox; |
| 16714 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16715 | int rc, length; |
| 16716 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16717 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 16718 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 16719 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16720 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16721 | if (!mbox) { |
| 16722 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16723 | "2745 Failed to allocate mbox for " |
| 16724 | "requesting FCF rediscover.\n"); |
| 16725 | return -ENOMEM; |
| 16726 | } |
| 16727 | |
| 16728 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 16729 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16730 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16731 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 16732 | length, LPFC_SLI4_MBX_EMBED); |
| 16733 | |
| 16734 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16735 | /* Set count to 0 for invalidating the entire FCF database */ |
| 16736 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 16737 | |
| 16738 | /* Issue the mailbox command asynchronously */ |
| 16739 | mbox->vport = phba->pport; |
| 16740 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 16741 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 16742 | |
| 16743 | if (rc == MBX_NOT_FINISHED) { |
| 16744 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16745 | return -EIO; |
| 16746 | } |
| 16747 | return 0; |
| 16748 | } |
| 16749 | |
| 16750 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16751 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 16752 | * @phba: pointer to lpfc hba data structure. |
| 16753 | * |
| 16754 | * This function is the failover routine as a last resort to the FCF DEAD |
| 16755 | * event when driver failed to perform fast FCF failover. |
| 16756 | **/ |
| 16757 | void |
| 16758 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 16759 | { |
| 16760 | uint32_t link_state; |
| 16761 | |
| 16762 | /* |
| 16763 | * Last resort as FCF DEAD event failover will treat this as |
| 16764 | * a link down, but save the link state because we don't want |
| 16765 | * it to be changed to Link Down unless it is already down. |
| 16766 | */ |
| 16767 | link_state = phba->link_state; |
| 16768 | lpfc_linkdown(phba); |
| 16769 | phba->link_state = link_state; |
| 16770 | |
| 16771 | /* Unregister FCF if no devices connected to it */ |
| 16772 | lpfc_unregister_unused_fcf(phba); |
| 16773 | } |
| 16774 | |
| 16775 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16776 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16777 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16778 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16779 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16780 | * This function gets SLI3 port configure region 23 data through memory dump |
| 16781 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16782 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16783 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16784 | static uint32_t |
| 16785 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16786 | { |
| 16787 | LPFC_MBOXQ_t *pmb = NULL; |
| 16788 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16789 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16790 | int rc; |
| 16791 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16792 | if (!rgn23_data) |
| 16793 | return 0; |
| 16794 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16795 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16796 | if (!pmb) { |
| 16797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16798 | "2600 failed to allocate mailbox memory\n"); |
| 16799 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16800 | } |
| 16801 | mb = &pmb->u.mb; |
| 16802 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16803 | do { |
| 16804 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 16805 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 16806 | |
| 16807 | if (rc != MBX_SUCCESS) { |
| 16808 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16809 | "2601 failed to read config " |
| 16810 | "region 23, rc 0x%x Status 0x%x\n", |
| 16811 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16812 | mb->un.varDmp.word_cnt = 0; |
| 16813 | } |
| 16814 | /* |
| 16815 | * dump mem may return a zero when finished or we got a |
| 16816 | * mailbox error, either way we are done. |
| 16817 | */ |
| 16818 | if (mb->un.varDmp.word_cnt == 0) |
| 16819 | break; |
| 16820 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 16821 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 16822 | |
| 16823 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16824 | rgn23_data + offset, |
| 16825 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16826 | offset += mb->un.varDmp.word_cnt; |
| 16827 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 16828 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16829 | mempool_free(pmb, phba->mbox_mem_pool); |
| 16830 | return offset; |
| 16831 | } |
| 16832 | |
| 16833 | /** |
| 16834 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 16835 | * @phba: pointer to lpfc hba data structure. |
| 16836 | * @rgn23_data: pointer to configure region 23 data. |
| 16837 | * |
| 16838 | * This function gets SLI4 port configure region 23 data through memory dump |
| 16839 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16840 | * will be returned, otherwise, 0 will be returned. |
| 16841 | **/ |
| 16842 | static uint32_t |
| 16843 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 16844 | { |
| 16845 | LPFC_MBOXQ_t *mboxq = NULL; |
| 16846 | struct lpfc_dmabuf *mp = NULL; |
| 16847 | struct lpfc_mqe *mqe; |
| 16848 | uint32_t data_length = 0; |
| 16849 | int rc; |
| 16850 | |
| 16851 | if (!rgn23_data) |
| 16852 | return 0; |
| 16853 | |
| 16854 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16855 | if (!mboxq) { |
| 16856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16857 | "3105 failed to allocate mailbox memory\n"); |
| 16858 | return 0; |
| 16859 | } |
| 16860 | |
| 16861 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 16862 | goto out; |
| 16863 | mqe = &mboxq->u.mqe; |
| 16864 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 16865 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 16866 | if (rc) |
| 16867 | goto out; |
| 16868 | data_length = mqe->un.mb_words[5]; |
| 16869 | if (data_length == 0) |
| 16870 | goto out; |
| 16871 | if (data_length > DMP_RGN23_SIZE) { |
| 16872 | data_length = 0; |
| 16873 | goto out; |
| 16874 | } |
| 16875 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 16876 | out: |
| 16877 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16878 | if (mp) { |
| 16879 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16880 | kfree(mp); |
| 16881 | } |
| 16882 | return data_length; |
| 16883 | } |
| 16884 | |
| 16885 | /** |
| 16886 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 16887 | * @phba: pointer to lpfc hba data structure. |
| 16888 | * |
| 16889 | * This function read region 23 and parse TLV for port status to |
| 16890 | * decide if the user disaled the port. If the TLV indicates the |
| 16891 | * port is disabled, the hba_flag is set accordingly. |
| 16892 | **/ |
| 16893 | void |
| 16894 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 16895 | { |
| 16896 | uint8_t *rgn23_data = NULL; |
| 16897 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 16898 | uint32_t offset = 0; |
| 16899 | |
| 16900 | /* Get adapter Region 23 data */ |
| 16901 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 16902 | if (!rgn23_data) |
| 16903 | goto out; |
| 16904 | |
| 16905 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16906 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 16907 | else { |
| 16908 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 16909 | &phba->sli4_hba.sli_intf); |
| 16910 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 16911 | goto out; |
| 16912 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 16913 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16914 | |
| 16915 | if (!data_size) |
| 16916 | goto out; |
| 16917 | |
| 16918 | /* Check the region signature first */ |
| 16919 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 16920 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16921 | "2619 Config region 23 has bad signature\n"); |
| 16922 | goto out; |
| 16923 | } |
| 16924 | offset += 4; |
| 16925 | |
| 16926 | /* Check the data structure version */ |
| 16927 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16928 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16929 | "2620 Config region 23 has bad version\n"); |
| 16930 | goto out; |
| 16931 | } |
| 16932 | offset += 4; |
| 16933 | |
| 16934 | /* Parse TLV entries in the region */ |
| 16935 | while (offset < data_size) { |
| 16936 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16937 | break; |
| 16938 | /* |
| 16939 | * If the TLV is not driver specific TLV or driver id is |
| 16940 | * not linux driver id, skip the record. |
| 16941 | */ |
| 16942 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16943 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16944 | (rgn23_data[offset + 3] != 0)) { |
| 16945 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16946 | continue; |
| 16947 | } |
| 16948 | |
| 16949 | /* Driver found a driver specific TLV in the config region */ |
| 16950 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16951 | offset += 4; |
| 16952 | tlv_offset = 0; |
| 16953 | |
| 16954 | /* |
| 16955 | * Search for configured port state sub-TLV. |
| 16956 | */ |
| 16957 | while ((offset < data_size) && |
| 16958 | (tlv_offset < sub_tlv_len)) { |
| 16959 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16960 | offset += 4; |
| 16961 | tlv_offset += 4; |
| 16962 | break; |
| 16963 | } |
| 16964 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16965 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16966 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16967 | continue; |
| 16968 | } |
| 16969 | |
| 16970 | /* This HBA contains PORT_STE configured */ |
| 16971 | if (!rgn23_data[offset + 2]) |
| 16972 | phba->hba_flag |= LINK_DISABLED; |
| 16973 | |
| 16974 | goto out; |
| 16975 | } |
| 16976 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16977 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16978 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16979 | kfree(rgn23_data); |
| 16980 | return; |
| 16981 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16982 | |
| 16983 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16984 | * lpfc_wr_object - write an object to the firmware |
| 16985 | * @phba: HBA structure that indicates port to create a queue on. |
| 16986 | * @dmabuf_list: list of dmabufs to write to the port. |
| 16987 | * @size: the total byte value of the objects to write to the port. |
| 16988 | * @offset: the current offset to be used to start the transfer. |
| 16989 | * |
| 16990 | * This routine will create a wr_object mailbox command to send to the port. |
| 16991 | * the mailbox command will be constructed using the dma buffers described in |
| 16992 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 16993 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 16994 | * used to indicate the starting offset of the transfer and will also return |
| 16995 | * the offset after the write object mailbox has completed. @size is used to |
| 16996 | * determine the end of the object and whether the eof bit should be set. |
| 16997 | * |
| 16998 | * Return 0 is successful and offset will contain the the new offset to use |
| 16999 | * for the next write. |
| 17000 | * Return negative value for error cases. |
| 17001 | **/ |
| 17002 | int |
| 17003 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 17004 | uint32_t size, uint32_t *offset) |
| 17005 | { |
| 17006 | struct lpfc_mbx_wr_object *wr_object; |
| 17007 | LPFC_MBOXQ_t *mbox; |
| 17008 | int rc = 0, i = 0; |
| 17009 | uint32_t shdr_status, shdr_add_status; |
| 17010 | uint32_t mbox_tmo; |
| 17011 | union lpfc_sli4_cfg_shdr *shdr; |
| 17012 | struct lpfc_dmabuf *dmabuf; |
| 17013 | uint32_t written = 0; |
| 17014 | |
| 17015 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17016 | if (!mbox) |
| 17017 | return -ENOMEM; |
| 17018 | |
| 17019 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 17020 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 17021 | sizeof(struct lpfc_mbx_wr_object) - |
| 17022 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 17023 | |
| 17024 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 17025 | wr_object->u.request.write_offset = *offset; |
| 17026 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 17027 | wr_object->u.request.object_name[0] = |
| 17028 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 17029 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 17030 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 17031 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 17032 | break; |
| 17033 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 17034 | wr_object->u.request.bde[i].addrHigh = |
| 17035 | putPaddrHigh(dmabuf->phys); |
| 17036 | if (written + SLI4_PAGE_SIZE >= size) { |
| 17037 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 17038 | (size - written); |
| 17039 | written += (size - written); |
| 17040 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 17041 | } else { |
| 17042 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 17043 | SLI4_PAGE_SIZE; |
| 17044 | written += SLI4_PAGE_SIZE; |
| 17045 | } |
| 17046 | i++; |
| 17047 | } |
| 17048 | wr_object->u.request.bde_count = i; |
| 17049 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 17050 | if (!phba->sli4_hba.intr_enable) |
| 17051 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 17052 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17053 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 17054 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 17055 | } |
| 17056 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17057 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 17058 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17059 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17060 | if (rc != MBX_TIMEOUT) |
| 17061 | mempool_free(mbox, phba->mbox_mem_pool); |
| 17062 | if (shdr_status || shdr_add_status || rc) { |
| 17063 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17064 | "3025 Write Object mailbox failed with " |
| 17065 | "status x%x add_status x%x, mbx status x%x\n", |
| 17066 | shdr_status, shdr_add_status, rc); |
| 17067 | rc = -ENXIO; |
| 17068 | } else |
| 17069 | *offset += wr_object->u.response.actual_write_length; |
| 17070 | return rc; |
| 17071 | } |
| 17072 | |
| 17073 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17074 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 17075 | * @vport: pointer to vport data structure. |
| 17076 | * |
| 17077 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 17078 | * and REG_VPI mailbox commands associated with the vport. This function |
| 17079 | * is called when driver want to restart discovery of the vport due to |
| 17080 | * a Clear Virtual Link event. |
| 17081 | **/ |
| 17082 | void |
| 17083 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 17084 | { |
| 17085 | struct lpfc_hba *phba = vport->phba; |
| 17086 | LPFC_MBOXQ_t *mb, *nextmb; |
| 17087 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17088 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17089 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17090 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17091 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17092 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17093 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17094 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17095 | spin_lock_irq(&phba->hbalock); |
| 17096 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 17097 | if (mb->vport != vport) |
| 17098 | continue; |
| 17099 | |
| 17100 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17101 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17102 | continue; |
| 17103 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17104 | list_del(&mb->list); |
| 17105 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 17106 | } |
| 17107 | /* Clean up active mailbox command with the vport */ |
| 17108 | mb = phba->sli.mbox_active; |
| 17109 | if (mb && (mb->vport == vport)) { |
| 17110 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 17111 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 17112 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17113 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17114 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17115 | /* Put reference count for delayed processing */ |
| 17116 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 17117 | /* Unregister the RPI when mailbox complete */ |
| 17118 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17119 | } |
| 17120 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 17121 | /* Cleanup any mailbox completions which are not yet processed */ |
| 17122 | do { |
| 17123 | restart_loop = 0; |
| 17124 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 17125 | /* |
| 17126 | * If this mailox is already processed or it is |
| 17127 | * for another vport ignore it. |
| 17128 | */ |
| 17129 | if ((mb->vport != vport) || |
| 17130 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 17131 | continue; |
| 17132 | |
| 17133 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 17134 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 17135 | continue; |
| 17136 | |
| 17137 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 17138 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17139 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 17140 | /* Unregister the RPI when mailbox complete */ |
| 17141 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 17142 | restart_loop = 1; |
| 17143 | spin_unlock_irq(&phba->hbalock); |
| 17144 | spin_lock(shost->host_lock); |
| 17145 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17146 | spin_unlock(shost->host_lock); |
| 17147 | spin_lock_irq(&phba->hbalock); |
| 17148 | break; |
| 17149 | } |
| 17150 | } |
| 17151 | } while (restart_loop); |
| 17152 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17153 | spin_unlock_irq(&phba->hbalock); |
| 17154 | |
| 17155 | /* Release the cleaned-up mailbox commands */ |
| 17156 | while (!list_empty(&mbox_cmd_list)) { |
| 17157 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17158 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 17159 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 17160 | if (mp) { |
| 17161 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 17162 | kfree(mp); |
| 17163 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17164 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17165 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17166 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17167 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 17168 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 17169 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17170 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 17171 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17172 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17173 | mempool_free(mb, phba->mbox_mem_pool); |
| 17174 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17175 | |
| 17176 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 17177 | if (act_mbx_ndlp) { |
| 17178 | spin_lock(shost->host_lock); |
| 17179 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 17180 | spin_unlock(shost->host_lock); |
| 17181 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17182 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 17183 | } |
| 17184 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17185 | /** |
| 17186 | * lpfc_drain_txq - Drain the txq |
| 17187 | * @phba: Pointer to HBA context object. |
| 17188 | * |
| 17189 | * This function attempt to submit IOCBs on the txq |
| 17190 | * to the adapter. For SLI4 adapters, the txq contains |
| 17191 | * ELS IOCBs that have been deferred because the there |
| 17192 | * are no SGLs. This congestion can occur with large |
| 17193 | * vport counts during node discovery. |
| 17194 | **/ |
| 17195 | |
| 17196 | uint32_t |
| 17197 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 17198 | { |
| 17199 | LIST_HEAD(completions); |
| 17200 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 17201 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17202 | unsigned long iflags = 0; |
| 17203 | char *fail_msg = NULL; |
| 17204 | struct lpfc_sglq *sglq; |
| 17205 | union lpfc_wqe wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17206 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17207 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17208 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17209 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 17210 | txq_cnt++; |
| 17211 | } |
| 17212 | |
| 17213 | if (txq_cnt > pring->txq_max) |
| 17214 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17215 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17216 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17217 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17218 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17219 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17220 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17221 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17222 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17223 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17224 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17225 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17226 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 17227 | break; |
| 17228 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17229 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17230 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 17231 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17232 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17233 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17234 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17235 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17236 | |
| 17237 | /* The xri and iocb resources secured, |
| 17238 | * attempt to issue request |
| 17239 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17240 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17241 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 17242 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 17243 | fail_msg = "to convert bpl to sgl"; |
| 17244 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 17245 | fail_msg = "to convert iocb to wqe"; |
| 17246 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 17247 | fail_msg = " - Wq is full"; |
| 17248 | else |
| 17249 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 17250 | |
| 17251 | if (fail_msg) { |
| 17252 | /* Failed means we can't issue and need to cancel */ |
| 17253 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17254 | "2822 IOCB failed %s iotag 0x%x " |
| 17255 | "xri 0x%x\n", |
| 17256 | fail_msg, |
| 17257 | piocbq->iotag, piocbq->sli4_xritag); |
| 17258 | list_add_tail(&piocbq->list, &completions); |
| 17259 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 17260 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17261 | } |
| 17262 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17263 | /* Cancel all the IOCBs that cannot be issued */ |
| 17264 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 17265 | IOERR_SLI_ABORTED); |
| 17266 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 17267 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 17268 | } |