| 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 | 92c13f2 | 2013-05-31 17:05:45 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2013 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 28 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 | #include <scsi/scsi_cmnd.h> |
| 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 32 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 33 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 34 | #include <linux/aer.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_crtn.h" |
| 45 | #include "lpfc_logmsg.h" |
| 46 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 47 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 48 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | |
| 50 | /* There are only four IOCB completion types. */ |
| 51 | typedef enum _lpfc_iocb_type { |
| 52 | LPFC_UNKNOWN_IOCB, |
| 53 | LPFC_UNSOL_IOCB, |
| 54 | LPFC_SOL_IOCB, |
| 55 | LPFC_ABORT_IOCB |
| 56 | } lpfc_iocb_type; |
| 57 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 58 | |
| 59 | /* Provide function prototypes local to this module. */ |
| 60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 61 | uint32_t); |
| 62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 63 | uint8_t *, uint32_t *); |
| 64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 65 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 67 | struct hbq_dmabuf *); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 68 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
| 69 | struct lpfc_cqe *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 70 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
| 71 | int); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 72 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
| 73 | uint32_t); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 74 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 75 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 76 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 77 | static IOCB_t * |
| 78 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 79 | { |
| 80 | return &iocbq->iocb; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 85 | * @q: The Work Queue to operate on. |
| 86 | * @wqe: The work Queue Entry to put on the Work queue. |
| 87 | * |
| 88 | * This routine will copy the contents of @wqe to the next available entry on |
| 89 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 90 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 91 | * successful. If no entries are available on @q then this function will return |
| 92 | * -ENOMEM. |
| 93 | * The caller is expected to hold the hbalock when calling this routine. |
| 94 | **/ |
| 95 | static uint32_t |
| 96 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 97 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 98 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 99 | struct lpfc_register doorbell; |
| 100 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 101 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 102 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 103 | /* sanity check on queue memory */ |
| 104 | if (unlikely(!q)) |
| 105 | return -ENOMEM; |
| 106 | temp_wqe = q->qe[q->host_index].wqe; |
| 107 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 108 | /* 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] | 109 | idx = ((q->host_index + 1) % q->entry_count); |
| 110 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 111 | q->WQ_overflow++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 112 | return -ENOMEM; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 113 | } |
| 114 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 115 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 116 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 117 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 118 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 119 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 120 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
| 121 | |
| 122 | /* Update the host index before invoking device */ |
| 123 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 124 | |
| 125 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 126 | |
| 127 | /* Ring Doorbell */ |
| 128 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 129 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 130 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 131 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 132 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 133 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 134 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 135 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 136 | } else { |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 146 | * @q: The Work Queue to operate on. |
| 147 | * @index: The index to advance the hba index to. |
| 148 | * |
| 149 | * This routine will update the HBA index of a queue to reflect consumption of |
| 150 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 151 | * an entry the host calls this function to update the queue's internal |
| 152 | * pointers. This routine returns the number of entries that were consumed by |
| 153 | * the HBA. |
| 154 | **/ |
| 155 | static uint32_t |
| 156 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 157 | { |
| 158 | uint32_t released = 0; |
| 159 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 160 | /* sanity check on queue memory */ |
| 161 | if (unlikely(!q)) |
| 162 | return 0; |
| 163 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 164 | if (q->hba_index == index) |
| 165 | return 0; |
| 166 | do { |
| 167 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 168 | released++; |
| 169 | } while (q->hba_index != index); |
| 170 | return released; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 175 | * @q: The Mailbox Queue to operate on. |
| 176 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 177 | * |
| 178 | * This routine will copy the contents of @mqe to the next available entry on |
| 179 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 180 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 181 | * successful. If no entries are available on @q then this function will return |
| 182 | * -ENOMEM. |
| 183 | * The caller is expected to hold the hbalock when calling this routine. |
| 184 | **/ |
| 185 | static uint32_t |
| 186 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 187 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 188 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 189 | struct lpfc_register doorbell; |
| 190 | uint32_t host_index; |
| 191 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 192 | /* sanity check on queue memory */ |
| 193 | if (unlikely(!q)) |
| 194 | return -ENOMEM; |
| 195 | temp_mqe = q->qe[q->host_index].mqe; |
| 196 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 197 | /* If the host has not yet processed the next entry then we are done */ |
| 198 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 199 | return -ENOMEM; |
| 200 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 201 | /* Save off the mailbox pointer for completion */ |
| 202 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 203 | |
| 204 | /* Update the host index before invoking device */ |
| 205 | host_index = q->host_index; |
| 206 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 207 | |
| 208 | /* Ring Doorbell */ |
| 209 | doorbell.word0 = 0; |
| 210 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 211 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 212 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 218 | * @q: The Mailbox Queue to operate on. |
| 219 | * |
| 220 | * This routine will update the HBA index of a queue to reflect consumption of |
| 221 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 222 | * an entry the host calls this function to update the queue's internal |
| 223 | * pointers. This routine returns the number of entries that were consumed by |
| 224 | * the HBA. |
| 225 | **/ |
| 226 | static uint32_t |
| 227 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 228 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 229 | /* sanity check on queue memory */ |
| 230 | if (unlikely(!q)) |
| 231 | return 0; |
| 232 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 233 | /* Clear the mailbox pointer for completion */ |
| 234 | q->phba->mbox = NULL; |
| 235 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 241 | * @q: The Event Queue to get the first valid EQE from |
| 242 | * |
| 243 | * This routine will get the first valid Event Queue Entry from @q, update |
| 244 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 245 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 246 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 247 | **/ |
| 248 | static struct lpfc_eqe * |
| 249 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 250 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 251 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 252 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 253 | |
| 254 | /* sanity check on queue memory */ |
| 255 | if (unlikely(!q)) |
| 256 | return NULL; |
| 257 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 258 | |
| 259 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 260 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 261 | return NULL; |
| 262 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 263 | idx = ((q->hba_index + 1) % q->entry_count); |
| 264 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 265 | return NULL; |
| 266 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 267 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 268 | return eqe; |
| 269 | } |
| 270 | |
| 271 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 272 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 273 | * @q: The Event Queue to disable interrupts |
| 274 | * |
| 275 | **/ |
| 276 | static inline void |
| 277 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 278 | { |
| 279 | struct lpfc_register doorbell; |
| 280 | |
| 281 | doorbell.word0 = 0; |
| 282 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 283 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 284 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 285 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 286 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 287 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 288 | } |
| 289 | |
| 290 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 291 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 292 | * @q: The Event Queue that the host has completed processing for. |
| 293 | * @arm: Indicates whether the host wants to arms this CQ. |
| 294 | * |
| 295 | * This routine will mark all Event Queue Entries on @q, from the last |
| 296 | * known completed entry to the last entry that was processed, as completed |
| 297 | * by clearing the valid bit for each completion queue entry. Then it will |
| 298 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 299 | * The internal host index in the @q will be updated by this routine to indicate |
| 300 | * that the host has finished processing the entries. The @arm parameter |
| 301 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 302 | * |
| 303 | * This function will return the number of EQEs that were popped. |
| 304 | **/ |
| 305 | uint32_t |
| 306 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 307 | { |
| 308 | uint32_t released = 0; |
| 309 | struct lpfc_eqe *temp_eqe; |
| 310 | struct lpfc_register doorbell; |
| 311 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 312 | /* sanity check on queue memory */ |
| 313 | if (unlikely(!q)) |
| 314 | return 0; |
| 315 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 316 | /* while there are valid entries */ |
| 317 | while (q->hba_index != q->host_index) { |
| 318 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 319 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 320 | released++; |
| 321 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 322 | } |
| 323 | if (unlikely(released == 0 && !arm)) |
| 324 | return 0; |
| 325 | |
| 326 | /* ring doorbell for number popped */ |
| 327 | doorbell.word0 = 0; |
| 328 | if (arm) { |
| 329 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 330 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 331 | } |
| 332 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 333 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 334 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 335 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 336 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 337 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 338 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 339 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 340 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 341 | return released; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 346 | * @q: The Completion Queue to get the first valid CQE from |
| 347 | * |
| 348 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 349 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 350 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 351 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 352 | **/ |
| 353 | static struct lpfc_cqe * |
| 354 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 355 | { |
| 356 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 357 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 358 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 359 | /* sanity check on queue memory */ |
| 360 | if (unlikely(!q)) |
| 361 | return NULL; |
| 362 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 363 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 364 | 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] | 365 | return NULL; |
| 366 | /* 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] | 367 | idx = ((q->hba_index + 1) % q->entry_count); |
| 368 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 369 | return NULL; |
| 370 | |
| 371 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 372 | q->hba_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 373 | return cqe; |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 378 | * @q: The Completion Queue that the host has completed processing for. |
| 379 | * @arm: Indicates whether the host wants to arms this CQ. |
| 380 | * |
| 381 | * This routine will mark all Completion queue entries on @q, from the last |
| 382 | * known completed entry to the last entry that was processed, as completed |
| 383 | * by clearing the valid bit for each completion queue entry. Then it will |
| 384 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 385 | * The internal host index in the @q will be updated by this routine to indicate |
| 386 | * that the host has finished processing the entries. The @arm parameter |
| 387 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 388 | * |
| 389 | * This function will return the number of CQEs that were released. |
| 390 | **/ |
| 391 | uint32_t |
| 392 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 393 | { |
| 394 | uint32_t released = 0; |
| 395 | struct lpfc_cqe *temp_qe; |
| 396 | struct lpfc_register doorbell; |
| 397 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 398 | /* sanity check on queue memory */ |
| 399 | if (unlikely(!q)) |
| 400 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 401 | /* while there are valid entries */ |
| 402 | while (q->hba_index != q->host_index) { |
| 403 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 404 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 405 | released++; |
| 406 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 407 | } |
| 408 | if (unlikely(released == 0 && !arm)) |
| 409 | return 0; |
| 410 | |
| 411 | /* ring doorbell for number popped */ |
| 412 | doorbell.word0 = 0; |
| 413 | if (arm) |
| 414 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 415 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 416 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 417 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 418 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 419 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 420 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 421 | return released; |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 426 | * @q: The Header Receive Queue to operate on. |
| 427 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 428 | * |
| 429 | * This routine will copy the contents of @wqe to the next available entry on |
| 430 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 431 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 432 | * index that the rqe was copied to if successful. If no entries are available |
| 433 | * on @q then this function will return -ENOMEM. |
| 434 | * The caller is expected to hold the hbalock when calling this routine. |
| 435 | **/ |
| 436 | static int |
| 437 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 438 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 439 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 440 | struct lpfc_rqe *temp_hrqe; |
| 441 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 442 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 443 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 444 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 445 | /* sanity check on queue memory */ |
| 446 | if (unlikely(!hq) || unlikely(!dq)) |
| 447 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 448 | put_index = hq->host_index; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 449 | temp_hrqe = hq->qe[hq->host_index].rqe; |
| 450 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 451 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 452 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 453 | return -EINVAL; |
| 454 | if (hq->host_index != dq->host_index) |
| 455 | return -EINVAL; |
| 456 | /* If the host has not yet processed the next entry then we are done */ |
| 457 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) |
| 458 | return -EBUSY; |
| 459 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 460 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 461 | |
| 462 | /* Update the host index to point to the next slot */ |
| 463 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); |
| 464 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
| 465 | |
| 466 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 467 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 468 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 469 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 470 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 471 | hq->entry_repost); |
| 472 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 473 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 474 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 475 | hq->entry_repost); |
| 476 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 477 | hq->host_index); |
| 478 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 479 | } else { |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 483 | } |
| 484 | return put_index; |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 489 | * @q: The Header Receive Queue to operate on. |
| 490 | * |
| 491 | * This routine will update the HBA index of a queue to reflect consumption of |
| 492 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 493 | * consumed an entry the host calls this function to update the queue's |
| 494 | * internal pointers. This routine returns the number of entries that were |
| 495 | * consumed by the HBA. |
| 496 | **/ |
| 497 | static uint32_t |
| 498 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 499 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 500 | /* sanity check on queue memory */ |
| 501 | if (unlikely(!hq) || unlikely(!dq)) |
| 502 | return 0; |
| 503 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 504 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 505 | return 0; |
| 506 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 507 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 508 | return 1; |
| 509 | } |
| 510 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 511 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 512 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 513 | * @phba: Pointer to HBA context object. |
| 514 | * @pring: Pointer to driver SLI ring object. |
| 515 | * |
| 516 | * This function returns pointer to next command iocb entry |
| 517 | * in the command ring. The caller must hold hbalock to prevent |
| 518 | * other threads consume the next command iocb. |
| 519 | * SLI-2/SLI-3 provide different sized iocbs. |
| 520 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 521 | static inline IOCB_t * |
| 522 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 523 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 524 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 525 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 526 | } |
| 527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 529 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 530 | * @phba: Pointer to HBA context object. |
| 531 | * @pring: Pointer to driver SLI ring object. |
| 532 | * |
| 533 | * This function returns pointer to next response iocb entry |
| 534 | * in the response ring. The caller must hold hbalock to make sure |
| 535 | * that no other thread consume the next response iocb. |
| 536 | * SLI-2/SLI-3 provide different sized iocbs. |
| 537 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 538 | static inline IOCB_t * |
| 539 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 540 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 541 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 542 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 543 | } |
| 544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 546 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 547 | * @phba: Pointer to HBA context object. |
| 548 | * |
| 549 | * This function is called with hbalock held. This function |
| 550 | * allocates a new driver iocb object from the iocb pool. If the |
| 551 | * allocation is successful, it returns pointer to the newly |
| 552 | * allocated iocb object else it returns NULL. |
| 553 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 554 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 555 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 556 | { |
| 557 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 558 | struct lpfc_iocbq * iocbq = NULL; |
| 559 | |
| 560 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 561 | if (iocbq) |
| 562 | phba->iocb_cnt++; |
| 563 | if (phba->iocb_cnt > phba->iocb_max) |
| 564 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 565 | return iocbq; |
| 566 | } |
| 567 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 568 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 569 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 570 | * @phba: Pointer to HBA context object. |
| 571 | * @xritag: XRI value. |
| 572 | * |
| 573 | * This function clears the sglq pointer from the array of acive |
| 574 | * sglq's. The xritag that is passed in is used to index into the |
| 575 | * array. Before the xritag can be used it needs to be adjusted |
| 576 | * by subtracting the xribase. |
| 577 | * |
| 578 | * Returns sglq ponter = success, NULL = Failure. |
| 579 | **/ |
| 580 | static struct lpfc_sglq * |
| 581 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 582 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 583 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 584 | |
| 585 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 586 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 587 | return sglq; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 592 | * @phba: Pointer to HBA context object. |
| 593 | * @xritag: XRI value. |
| 594 | * |
| 595 | * This function returns the sglq pointer from the array of acive |
| 596 | * sglq's. The xritag that is passed in is used to index into the |
| 597 | * array. Before the xritag can be used it needs to be adjusted |
| 598 | * by subtracting the xribase. |
| 599 | * |
| 600 | * Returns sglq ponter = success, NULL = Failure. |
| 601 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 602 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 603 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 604 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 605 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 606 | |
| 607 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 608 | return sglq; |
| 609 | } |
| 610 | |
| 611 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 612 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 613 | * @phba: Pointer to HBA context object. |
| 614 | * @xritag: xri used in this exchange. |
| 615 | * @rrq: The RRQ to be cleared. |
| 616 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 617 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 618 | void |
| 619 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 620 | uint16_t xritag, |
| 621 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 622 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 623 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 624 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 625 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 626 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 627 | |
| 628 | /* The target DID could have been swapped (cable swap) |
| 629 | * we should use the ndlp from the findnode if it is |
| 630 | * available. |
| 631 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 632 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 633 | ndlp = rrq->ndlp; |
| 634 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 635 | if (!ndlp) |
| 636 | goto out; |
| 637 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 638 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 639 | rrq->send_rrq = 0; |
| 640 | rrq->xritag = 0; |
| 641 | rrq->rrq_stop_time = 0; |
| 642 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 643 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 644 | mempool_free(rrq, phba->rrq_pool); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 649 | * @phba: Pointer to HBA context object. |
| 650 | * |
| 651 | * This function is called with hbalock held. This function |
| 652 | * Checks if stop_time (ratov from setting rrq active) has |
| 653 | * been reached, if it has and the send_rrq flag is set then |
| 654 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 655 | * then it will just call the routine to clear the rrq and |
| 656 | * free the rrq resource. |
| 657 | * The timer is set to the next rrq that is going to expire before |
| 658 | * leaving the routine. |
| 659 | * |
| 660 | **/ |
| 661 | void |
| 662 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 663 | { |
| 664 | struct lpfc_node_rrq *rrq; |
| 665 | struct lpfc_node_rrq *nextrrq; |
| 666 | unsigned long next_time; |
| 667 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 668 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 669 | |
| 670 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 671 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 672 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 673 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 674 | &phba->active_rrq_list, list) { |
| 675 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 676 | list_move(&rrq->list, &send_rrq); |
| 677 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 678 | next_time = rrq->rrq_stop_time; |
| 679 | } |
| 680 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 681 | if (!list_empty(&phba->active_rrq_list)) |
| 682 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 683 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 684 | list_del(&rrq->list); |
| 685 | if (!rrq->send_rrq) |
| 686 | /* this call will free the rrq */ |
| 687 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 688 | else if (lpfc_send_rrq(phba, rrq)) { |
| 689 | /* if we send the rrq then the completion handler |
| 690 | * will clear the bit in the xribitmap. |
| 691 | */ |
| 692 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 693 | rrq); |
| 694 | } |
| 695 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /** |
| 699 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 700 | * @vport: Pointer to vport context object. |
| 701 | * @xri: The xri used in the exchange. |
| 702 | * @did: The targets DID for this exchange. |
| 703 | * |
| 704 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 705 | * rrq = rrq for this xri and target. |
| 706 | **/ |
| 707 | struct lpfc_node_rrq * |
| 708 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 709 | { |
| 710 | struct lpfc_hba *phba = vport->phba; |
| 711 | struct lpfc_node_rrq *rrq; |
| 712 | struct lpfc_node_rrq *nextrrq; |
| 713 | unsigned long iflags; |
| 714 | |
| 715 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 716 | return NULL; |
| 717 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 718 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 719 | if (rrq->vport == vport && rrq->xritag == xri && |
| 720 | rrq->nlp_DID == did){ |
| 721 | list_del(&rrq->list); |
| 722 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 723 | return rrq; |
| 724 | } |
| 725 | } |
| 726 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 727 | return NULL; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 732 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 733 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 734 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 735 | * phba->active_rrq_list and clear the rrq. |
| 736 | * 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] | 737 | **/ |
| 738 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 739 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 740 | |
| 741 | { |
| 742 | struct lpfc_hba *phba = vport->phba; |
| 743 | struct lpfc_node_rrq *rrq; |
| 744 | struct lpfc_node_rrq *nextrrq; |
| 745 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 746 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 747 | |
| 748 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 749 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 750 | if (!ndlp) { |
| 751 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 752 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 753 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 754 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 755 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 756 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 757 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 758 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 759 | |
| 760 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 761 | list_del(&rrq->list); |
| 762 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 763 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. |
| 768 | * @phba: Pointer to HBA context object. |
| 769 | * |
| 770 | * Remove all rrqs from the phba->active_rrq_list and free them by |
| 771 | * calling __lpfc_clr_active_rrq |
| 772 | * |
| 773 | **/ |
| 774 | void |
| 775 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) |
| 776 | { |
| 777 | struct lpfc_node_rrq *rrq; |
| 778 | struct lpfc_node_rrq *nextrrq; |
| 779 | unsigned long next_time; |
| 780 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 781 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 782 | |
| 783 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 784 | return; |
| 785 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 786 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 787 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 788 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 789 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 790 | |
| 791 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 792 | list_del(&rrq->list); |
| 793 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 794 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 795 | if (!list_empty(&phba->active_rrq_list)) |
| 796 | mod_timer(&phba->rrq_tmr, next_time); |
| 797 | } |
| 798 | |
| 799 | |
| 800 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 801 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 802 | * @phba: Pointer to HBA context object. |
| 803 | * @ndlp: Targets nodelist pointer for this exchange. |
| 804 | * @xritag the xri in the bitmap to test. |
| 805 | * |
| 806 | * This function is called with hbalock held. This function |
| 807 | * returns 0 = rrq not active for this xri |
| 808 | * 1 = rrq is valid for this xri. |
| 809 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 810 | int |
| 811 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 812 | uint16_t xritag) |
| 813 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 814 | if (!ndlp) |
| 815 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 816 | if (!ndlp->active_rrqs_xri_bitmap) |
| 817 | return 0; |
| 818 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 819 | return 1; |
| 820 | else |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 826 | * @phba: Pointer to HBA context object. |
| 827 | * @ndlp: nodelist pointer for this target. |
| 828 | * @xritag: xri used in this exchange. |
| 829 | * @rxid: Remote Exchange ID. |
| 830 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 831 | * |
| 832 | * This function takes the hbalock. |
| 833 | * The active bit is always set in the active rrq xri_bitmap even |
| 834 | * if there is no slot avaiable for the other rrq information. |
| 835 | * |
| 836 | * returns 0 rrq actived for this xri |
| 837 | * < 0 No memory or invalid ndlp. |
| 838 | **/ |
| 839 | int |
| 840 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 841 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 842 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 843 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 844 | struct lpfc_node_rrq *rrq; |
| 845 | int empty; |
| 846 | |
| 847 | if (!ndlp) |
| 848 | return -EINVAL; |
| 849 | |
| 850 | if (!phba->cfg_enable_rrq) |
| 851 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 852 | |
| 853 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 854 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 855 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 856 | goto out; |
| 857 | } |
| 858 | |
| 859 | /* |
| 860 | * set the active bit even if there is no mem available. |
| 861 | */ |
| 862 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 863 | goto out; |
| 864 | |
| 865 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 866 | goto out; |
| 867 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 868 | if (!ndlp->active_rrqs_xri_bitmap) |
| 869 | goto out; |
| 870 | |
| 871 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 872 | goto out; |
| 873 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 874 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 875 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 876 | if (!rrq) { |
| 877 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 878 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 879 | " DID:0x%x Send:%d\n", |
| 880 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 881 | return -EINVAL; |
| 882 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 883 | if (phba->cfg_enable_rrq == 1) |
| 884 | rrq->send_rrq = send_rrq; |
| 885 | else |
| 886 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 887 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 888 | rrq->rrq_stop_time = jiffies + |
| 889 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 890 | rrq->ndlp = ndlp; |
| 891 | rrq->nlp_DID = ndlp->nlp_DID; |
| 892 | rrq->vport = ndlp->vport; |
| 893 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 894 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 895 | empty = list_empty(&phba->active_rrq_list); |
| 896 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 897 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 898 | if (empty) |
| 899 | lpfc_worker_wake_up(phba); |
| 900 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 901 | return 0; |
| 902 | out: |
| 903 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 904 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 905 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 906 | " DID:0x%x Send:%d\n", |
| 907 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 908 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 912 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool |
| 913 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 914 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 915 | * |
| 916 | * This function is called with hbalock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 917 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 918 | * list is not empty then it is successful, it returns pointer to the newly |
| 919 | * allocated sglq object else it returns NULL. |
| 920 | **/ |
| 921 | static struct lpfc_sglq * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 922 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 923 | { |
| 924 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; |
| 925 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 926 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 927 | struct lpfc_scsi_buf *lpfc_cmd; |
| 928 | struct lpfc_nodelist *ndlp; |
| 929 | int found = 0; |
| 930 | |
| 931 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 932 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 933 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 934 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
| 935 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 936 | ndlp = piocbq->context_un.ndlp; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 937 | else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 938 | ndlp = piocbq->context_un.ndlp; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 939 | else |
| 940 | ndlp = piocbq->context1; |
| 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 | |
| 1016 | if (iocbq->sli4_xritag == NO_XRI) |
| 1017 | sglq = NULL; |
| 1018 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1019 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1020 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1021 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1022 | if (sglq) { |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1023 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1024 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1025 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
| 1026 | iflag); |
| 1027 | list_add(&sglq->list, |
| 1028 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 1029 | spin_unlock_irqrestore( |
| 1030 | &phba->sli4_hba.abts_sgl_list_lock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1031 | } else { |
| 1032 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1033 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1034 | list_add_tail(&sglq->list, |
| 1035 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1036 | |
| 1037 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1038 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1039 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1040 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | /* |
| 1045 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1046 | */ |
| 1047 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1048 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1049 | iocbq->sli4_xritag = NO_XRI; |
| 1050 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1051 | } |
| 1052 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1053 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1054 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1055 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1056 | * @phba: Pointer to HBA context object. |
| 1057 | * @iocbq: Pointer to driver iocb object. |
| 1058 | * |
| 1059 | * This function is called with hbalock held to release driver |
| 1060 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1061 | * does not change for each use of the iocb object. This function |
| 1062 | * clears all other fields of the iocb object when it is freed. |
| 1063 | **/ |
| 1064 | static void |
| 1065 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1066 | { |
| 1067 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1068 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1069 | |
| 1070 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1071 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1072 | */ |
| 1073 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1074 | iocbq->sli4_xritag = NO_XRI; |
| 1075 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1079 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1080 | * @phba: Pointer to HBA context object. |
| 1081 | * @iocbq: Pointer to driver iocb object. |
| 1082 | * |
| 1083 | * This function is called with hbalock held to release driver |
| 1084 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1085 | * does not change for each use of the iocb object. This function |
| 1086 | * clears all other fields of the iocb object when it is freed. |
| 1087 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1088 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1089 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1090 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1091 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1092 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1095 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1096 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1097 | * @phba: Pointer to HBA context object. |
| 1098 | * @iocbq: Pointer to driver iocb object. |
| 1099 | * |
| 1100 | * This function is called with no lock held to release the iocb to |
| 1101 | * iocb pool. |
| 1102 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1103 | void |
| 1104 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1105 | { |
| 1106 | unsigned long iflags; |
| 1107 | |
| 1108 | /* |
| 1109 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1110 | */ |
| 1111 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1112 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1113 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1114 | } |
| 1115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1116 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1117 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1118 | * @phba: Pointer to HBA context object. |
| 1119 | * @iocblist: List of IOCBs. |
| 1120 | * @ulpstatus: ULP status in IOCB command field. |
| 1121 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1122 | * |
| 1123 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1124 | * on the list by invoking the complete callback function associated with the |
| 1125 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1126 | * fields. |
| 1127 | **/ |
| 1128 | void |
| 1129 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1130 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1131 | { |
| 1132 | struct lpfc_iocbq *piocb; |
| 1133 | |
| 1134 | while (!list_empty(iocblist)) { |
| 1135 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1136 | if (!piocb->iocb_cmpl) |
| 1137 | lpfc_sli_release_iocbq(phba, piocb); |
| 1138 | else { |
| 1139 | piocb->iocb.ulpStatus = ulpstatus; |
| 1140 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1141 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1142 | } |
| 1143 | } |
| 1144 | return; |
| 1145 | } |
| 1146 | |
| 1147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1148 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1149 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1150 | * |
| 1151 | * This function is called by ring event handler function to get the iocb type. |
| 1152 | * This function translates the iocb command to an iocb command type used to |
| 1153 | * decide the final disposition of each completed IOCB. |
| 1154 | * The function returns |
| 1155 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1156 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1157 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1158 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1159 | * |
| 1160 | * The caller is not required to hold any lock. |
| 1161 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | static lpfc_iocb_type |
| 1163 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1164 | { |
| 1165 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1166 | |
| 1167 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1168 | return 0; |
| 1169 | |
| 1170 | switch (iocb_cmnd) { |
| 1171 | case CMD_XMIT_SEQUENCE_CR: |
| 1172 | case CMD_XMIT_SEQUENCE_CX: |
| 1173 | case CMD_XMIT_BCAST_CN: |
| 1174 | case CMD_XMIT_BCAST_CX: |
| 1175 | case CMD_ELS_REQUEST_CR: |
| 1176 | case CMD_ELS_REQUEST_CX: |
| 1177 | case CMD_CREATE_XRI_CR: |
| 1178 | case CMD_CREATE_XRI_CX: |
| 1179 | case CMD_GET_RPI_CN: |
| 1180 | case CMD_XMIT_ELS_RSP_CX: |
| 1181 | case CMD_GET_RPI_CR: |
| 1182 | case CMD_FCP_IWRITE_CR: |
| 1183 | case CMD_FCP_IWRITE_CX: |
| 1184 | case CMD_FCP_IREAD_CR: |
| 1185 | case CMD_FCP_IREAD_CX: |
| 1186 | case CMD_FCP_ICMND_CR: |
| 1187 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1188 | case CMD_FCP_TSEND_CX: |
| 1189 | case CMD_FCP_TRSP_CX: |
| 1190 | case CMD_FCP_TRECEIVE_CX: |
| 1191 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1192 | case CMD_ADAPTER_MSG: |
| 1193 | case CMD_ADAPTER_DUMP: |
| 1194 | case CMD_XMIT_SEQUENCE64_CR: |
| 1195 | case CMD_XMIT_SEQUENCE64_CX: |
| 1196 | case CMD_XMIT_BCAST64_CN: |
| 1197 | case CMD_XMIT_BCAST64_CX: |
| 1198 | case CMD_ELS_REQUEST64_CR: |
| 1199 | case CMD_ELS_REQUEST64_CX: |
| 1200 | case CMD_FCP_IWRITE64_CR: |
| 1201 | case CMD_FCP_IWRITE64_CX: |
| 1202 | case CMD_FCP_IREAD64_CR: |
| 1203 | case CMD_FCP_IREAD64_CX: |
| 1204 | case CMD_FCP_ICMND64_CR: |
| 1205 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1206 | case CMD_FCP_TSEND64_CX: |
| 1207 | case CMD_FCP_TRSP64_CX: |
| 1208 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | case CMD_GEN_REQUEST64_CR: |
| 1210 | case CMD_GEN_REQUEST64_CX: |
| 1211 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1212 | case DSSCMD_IWRITE64_CR: |
| 1213 | case DSSCMD_IWRITE64_CX: |
| 1214 | case DSSCMD_IREAD64_CR: |
| 1215 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | type = LPFC_SOL_IOCB; |
| 1217 | break; |
| 1218 | case CMD_ABORT_XRI_CN: |
| 1219 | case CMD_ABORT_XRI_CX: |
| 1220 | case CMD_CLOSE_XRI_CN: |
| 1221 | case CMD_CLOSE_XRI_CX: |
| 1222 | case CMD_XRI_ABORTED_CX: |
| 1223 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1224 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | type = LPFC_ABORT_IOCB; |
| 1226 | break; |
| 1227 | case CMD_RCV_SEQUENCE_CX: |
| 1228 | case CMD_RCV_ELS_REQ_CX: |
| 1229 | case CMD_RCV_SEQUENCE64_CX: |
| 1230 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1231 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1232 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1233 | case CMD_IOCB_RCV_ELS64_CX: |
| 1234 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1235 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1236 | type = LPFC_UNSOL_IOCB; |
| 1237 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1238 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1239 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1240 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1241 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1242 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1243 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1244 | case CMD_IOCB_RET_HBQE64_CN: |
| 1245 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1246 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1247 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1248 | case CMD_IOCB_LOGENTRY_CN: |
| 1249 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1250 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1251 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1252 | type = LPFC_UNKNOWN_IOCB; |
| 1253 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | default: |
| 1255 | type = LPFC_UNKNOWN_IOCB; |
| 1256 | break; |
| 1257 | } |
| 1258 | |
| 1259 | return type; |
| 1260 | } |
| 1261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1262 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1263 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1264 | * @phba: Pointer to HBA context object. |
| 1265 | * |
| 1266 | * This function is called from SLI initialization code |
| 1267 | * to configure every ring of the HBA's SLI interface. The |
| 1268 | * caller is not required to hold any lock. This function issues |
| 1269 | * a config_ring mailbox command for each ring. |
| 1270 | * This function returns zero if successful else returns a negative |
| 1271 | * error code. |
| 1272 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1274 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | { |
| 1276 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1277 | LPFC_MBOXQ_t *pmb; |
| 1278 | MAILBOX_t *pmbox; |
| 1279 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1281 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1282 | if (!pmb) |
| 1283 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1284 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1285 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1286 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | lpfc_config_ring(phba, i, pmb); |
| 1288 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1289 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1291 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1293 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1294 | rc, pmbox->mbxCommand, |
| 1295 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1297 | ret = -ENXIO; |
| 1298 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | } |
| 1300 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1301 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1302 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | } |
| 1304 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1305 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1306 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1307 | * @phba: Pointer to HBA context object. |
| 1308 | * @pring: Pointer to driver SLI ring object. |
| 1309 | * @piocb: Pointer to the driver iocb object. |
| 1310 | * |
| 1311 | * This function is called with hbalock held. The function adds the |
| 1312 | * new iocb to txcmplq of the given ring. This function always returns |
| 1313 | * 0. If this function is called for ELS ring, this function checks if |
| 1314 | * there is a vport associated with the ELS command. This function also |
| 1315 | * starts els_tmofunc timer if this is an ELS command. |
| 1316 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1318 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1319 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1322 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1323 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1324 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1325 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 1326 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1327 | if (!piocb->vport) |
| 1328 | BUG(); |
| 1329 | else |
| 1330 | mod_timer(&piocb->vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1331 | jiffies + |
| 1332 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1333 | } |
| 1334 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1336 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | } |
| 1338 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1340 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1341 | * @phba: Pointer to HBA context object. |
| 1342 | * @pring: Pointer to driver SLI ring object. |
| 1343 | * |
| 1344 | * This function is called with hbalock held to get next |
| 1345 | * iocb in txq of the given ring. If there is any iocb in |
| 1346 | * the txq, the function returns first iocb in the list after |
| 1347 | * removing the iocb from the list, else it returns NULL. |
| 1348 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1349 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1350 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | struct lpfc_iocbq *cmd_iocb; |
| 1353 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1354 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1355 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1356 | } |
| 1357 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1358 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1359 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1360 | * @phba: Pointer to HBA context object. |
| 1361 | * @pring: Pointer to driver SLI ring object. |
| 1362 | * |
| 1363 | * This function is called with hbalock held and the caller must post the |
| 1364 | * iocb without releasing the lock. If the caller releases the lock, |
| 1365 | * iocb slot returned by the function is not guaranteed to be available. |
| 1366 | * The function returns pointer to the next available iocb slot if there |
| 1367 | * is available slot in the ring, else it returns NULL. |
| 1368 | * If the get index of the ring is ahead of the put index, the function |
| 1369 | * will post an error attention event to the worker thread to take the |
| 1370 | * HBA to offline state. |
| 1371 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1372 | static IOCB_t * |
| 1373 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1374 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1375 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1376 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
| 1377 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1378 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1379 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1381 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1382 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1384 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1385 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1386 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1387 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1388 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1389 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1390 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1391 | pring->sli.sli3.local_getidx, |
| 1392 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1394 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | /* |
| 1396 | * All error attention handlers are posted to |
| 1397 | * worker thread |
| 1398 | */ |
| 1399 | phba->work_ha |= HA_ERATT; |
| 1400 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1401 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1402 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1403 | |
| 1404 | return NULL; |
| 1405 | } |
| 1406 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1407 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | return NULL; |
| 1409 | } |
| 1410 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1411 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | } |
| 1413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1415 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1416 | * @phba: Pointer to HBA context object. |
| 1417 | * @iocbq: Pointer to driver iocb object. |
| 1418 | * |
| 1419 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1420 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1421 | * array and assigns a new iotag. |
| 1422 | * The function returns the allocated iotag if successful, else returns zero. |
| 1423 | * Zero is not a valid iotag. |
| 1424 | * The caller is not required to hold any lock. |
| 1425 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1426 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1427 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1429 | struct lpfc_iocbq **new_arr; |
| 1430 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1431 | size_t new_len; |
| 1432 | struct lpfc_sli *psli = &phba->sli; |
| 1433 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1435 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1436 | iotag = psli->last_iotag; |
| 1437 | if(++iotag < psli->iocbq_lookup_len) { |
| 1438 | psli->last_iotag = iotag; |
| 1439 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1440 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1441 | iocbq->iotag = iotag; |
| 1442 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1443 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1444 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1445 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1446 | spin_unlock_irq(&phba->hbalock); |
| 1447 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1448 | GFP_KERNEL); |
| 1449 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1451 | old_arr = psli->iocbq_lookup; |
| 1452 | if (new_len <= psli->iocbq_lookup_len) { |
| 1453 | /* highly unprobable case */ |
| 1454 | kfree(new_arr); |
| 1455 | iotag = psli->last_iotag; |
| 1456 | if(++iotag < psli->iocbq_lookup_len) { |
| 1457 | psli->last_iotag = iotag; |
| 1458 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1460 | iocbq->iotag = iotag; |
| 1461 | return iotag; |
| 1462 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1464 | return 0; |
| 1465 | } |
| 1466 | if (psli->iocbq_lookup) |
| 1467 | memcpy(new_arr, old_arr, |
| 1468 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1469 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1470 | psli->iocbq_lookup = new_arr; |
| 1471 | psli->iocbq_lookup_len = new_len; |
| 1472 | psli->last_iotag = iotag; |
| 1473 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1474 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1475 | iocbq->iotag = iotag; |
| 1476 | kfree(old_arr); |
| 1477 | return iotag; |
| 1478 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1479 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1480 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1482 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1483 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1484 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1486 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1489 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1490 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1491 | * @phba: Pointer to HBA context object. |
| 1492 | * @pring: Pointer to driver SLI ring object. |
| 1493 | * @iocb: Pointer to iocb slot in the ring. |
| 1494 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1495 | * posted to firmware. |
| 1496 | * |
| 1497 | * This function is called with hbalock held to post a new iocb to |
| 1498 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1499 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1500 | * a completion call back for this iocb else the function will free the |
| 1501 | * iocb object. |
| 1502 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1503 | static void |
| 1504 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1505 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1506 | { |
| 1507 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1508 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1509 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1510 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1511 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1512 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1513 | if (pring->ringno == LPFC_ELS_RING) { |
| 1514 | lpfc_debugfs_slow_ring_trc(phba, |
| 1515 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1516 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1517 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1518 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1519 | } |
| 1520 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1521 | /* |
| 1522 | * Issue iocb command to adapter |
| 1523 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1524 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | wmb(); |
| 1526 | pring->stats.iocb_cmd++; |
| 1527 | |
| 1528 | /* |
| 1529 | * If there is no completion routine to call, we can release the |
| 1530 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1531 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1532 | */ |
| 1533 | if (nextiocb->iocb_cmpl) |
| 1534 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1535 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1536 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1537 | |
| 1538 | /* |
| 1539 | * Let the HBA know what IOCB slot will be the next one the |
| 1540 | * driver will put a command into. |
| 1541 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1542 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1543 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | } |
| 1545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1547 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1548 | * @phba: Pointer to HBA context object. |
| 1549 | * @pring: Pointer to driver SLI ring object. |
| 1550 | * |
| 1551 | * The caller is not required to hold any lock for calling this function. |
| 1552 | * This function updates the chip attention bits for the ring to inform firmware |
| 1553 | * that there are pending work to be done for this ring and requests an |
| 1554 | * interrupt when there is space available in the ring. This function is |
| 1555 | * called when the driver is unable to post more iocbs to the ring due |
| 1556 | * to unavailability of space in the ring. |
| 1557 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | { |
| 1561 | int ringno = pring->ringno; |
| 1562 | |
| 1563 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1564 | |
| 1565 | wmb(); |
| 1566 | |
| 1567 | /* |
| 1568 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1569 | * The HBA will tell us when an IOCB entry is available. |
| 1570 | */ |
| 1571 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1572 | readl(phba->CAregaddr); /* flush */ |
| 1573 | |
| 1574 | pring->stats.iocb_cmd_full++; |
| 1575 | } |
| 1576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1578 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1579 | * @phba: Pointer to HBA context object. |
| 1580 | * @pring: Pointer to driver SLI ring object. |
| 1581 | * |
| 1582 | * This function updates the chip attention register bit for the |
| 1583 | * given ring to inform HBA that there is more work to be done |
| 1584 | * in this ring. The caller is not required to hold any lock. |
| 1585 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | { |
| 1589 | int ringno = pring->ringno; |
| 1590 | |
| 1591 | /* |
| 1592 | * Tell the HBA that there is work to do in this ring. |
| 1593 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1594 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1595 | wmb(); |
| 1596 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1597 | readl(phba->CAregaddr); /* flush */ |
| 1598 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1601 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1602 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1603 | * @phba: Pointer to HBA context object. |
| 1604 | * @pring: Pointer to driver SLI ring object. |
| 1605 | * |
| 1606 | * This function is called with hbalock held to post pending iocbs |
| 1607 | * in the txq to the firmware. This function is called when driver |
| 1608 | * detects space available in the ring. |
| 1609 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1611 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | { |
| 1613 | IOCB_t *iocb; |
| 1614 | struct lpfc_iocbq *nextiocb; |
| 1615 | |
| 1616 | /* |
| 1617 | * Check to see if: |
| 1618 | * (a) there is anything on the txq to send |
| 1619 | * (b) link is up |
| 1620 | * (c) link attention events can be processed (fcp ring only) |
| 1621 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1622 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1623 | |
| 1624 | if (lpfc_is_link_up(phba) && |
| 1625 | (!list_empty(&pring->txq)) && |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | (pring->ringno != phba->sli.fcp_ring || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1627 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | |
| 1629 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1630 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1631 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1632 | |
| 1633 | if (iocb) |
| 1634 | lpfc_sli_update_ring(phba, pring); |
| 1635 | else |
| 1636 | lpfc_sli_update_full_ring(phba, pring); |
| 1637 | } |
| 1638 | |
| 1639 | return; |
| 1640 | } |
| 1641 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1642 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1643 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1644 | * @phba: Pointer to HBA context object. |
| 1645 | * @hbqno: HBQ number. |
| 1646 | * |
| 1647 | * This function is called with hbalock held to get the next |
| 1648 | * available slot for the given HBQ. If there is free slot |
| 1649 | * available for the HBQ it will return pointer to the next available |
| 1650 | * HBQ entry else it will return NULL. |
| 1651 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1652 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1653 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1654 | { |
| 1655 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1656 | |
| 1657 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1658 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1659 | hbqp->next_hbqPutIdx = 0; |
| 1660 | |
| 1661 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1662 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1663 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1664 | |
| 1665 | hbqp->local_hbqGetIdx = getidx; |
| 1666 | |
| 1667 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1668 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1669 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1670 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1671 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1672 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1673 | hbqp->entry_count); |
| 1674 | |
| 1675 | phba->link_state = LPFC_HBA_ERROR; |
| 1676 | return NULL; |
| 1677 | } |
| 1678 | |
| 1679 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1680 | return NULL; |
| 1681 | } |
| 1682 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1683 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1684 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1685 | } |
| 1686 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1687 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1688 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1689 | * @phba: Pointer to HBA context object. |
| 1690 | * |
| 1691 | * This function is called with no lock held to free all the |
| 1692 | * hbq buffers while uninitializing the SLI interface. It also |
| 1693 | * frees the HBQ buffers returned by the firmware but not yet |
| 1694 | * processed by the upper layers. |
| 1695 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1696 | void |
| 1697 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1698 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1699 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1700 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1701 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1702 | int i, hbq_count; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1703 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1704 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1705 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1706 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1707 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1708 | for (i = 0; i < hbq_count; ++i) { |
| 1709 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1710 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1711 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1712 | list_del(&hbq_buf->dbuf.list); |
| 1713 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1714 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1715 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1716 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1717 | /* Return all HBQ buffer that are in-fly */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1718 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
| 1719 | list) { |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1720 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1721 | list_del(&hbq_buf->dbuf.list); |
| 1722 | if (hbq_buf->tag == -1) { |
| 1723 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1724 | (phba, hbq_buf); |
| 1725 | } else { |
| 1726 | hbqno = hbq_buf->tag >> 16; |
| 1727 | if (hbqno >= LPFC_MAX_HBQS) |
| 1728 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) |
| 1729 | (phba, hbq_buf); |
| 1730 | else |
| 1731 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, |
| 1732 | hbq_buf); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | /* Mark the HBQs not in use */ |
| 1737 | phba->hbq_in_use = 0; |
| 1738 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1739 | } |
| 1740 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1742 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1743 | * @phba: Pointer to HBA context object. |
| 1744 | * @hbqno: HBQ number. |
| 1745 | * @hbq_buf: Pointer to HBQ buffer. |
| 1746 | * |
| 1747 | * This function is called with the hbalock held to post a |
| 1748 | * hbq buffer to the firmware. If the function finds an empty |
| 1749 | * slot in the HBQ, it will post the buffer. The function will return |
| 1750 | * pointer to the hbq entry if it successfully post the buffer |
| 1751 | * else it will return NULL. |
| 1752 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1753 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1754 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1755 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1756 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1757 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1758 | } |
| 1759 | |
| 1760 | /** |
| 1761 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 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 hbq buffer to the |
| 1767 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1768 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1769 | * it successfully post the buffer else it will return an error. |
| 1770 | **/ |
| 1771 | static int |
| 1772 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1773 | struct hbq_dmabuf *hbq_buf) |
| 1774 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1775 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1776 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1777 | |
| 1778 | /* Get next HBQ entry slot to use */ |
| 1779 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1780 | if (hbqe) { |
| 1781 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1782 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1783 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1784 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1785 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1786 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1787 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1788 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1789 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1790 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1791 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1792 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1793 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1794 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1795 | return 0; |
| 1796 | } else |
| 1797 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1798 | } |
| 1799 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1800 | /** |
| 1801 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1802 | * @phba: Pointer to HBA context object. |
| 1803 | * @hbqno: HBQ number. |
| 1804 | * @hbq_buf: Pointer to HBQ buffer. |
| 1805 | * |
| 1806 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1807 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1808 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1809 | **/ |
| 1810 | static int |
| 1811 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1812 | struct hbq_dmabuf *hbq_buf) |
| 1813 | { |
| 1814 | int rc; |
| 1815 | struct lpfc_rqe hrqe; |
| 1816 | struct lpfc_rqe drqe; |
| 1817 | |
| 1818 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1819 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1820 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1821 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
| 1822 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
| 1823 | &hrqe, &drqe); |
| 1824 | if (rc < 0) |
| 1825 | return rc; |
| 1826 | hbq_buf->tag = rc; |
| 1827 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1828 | return 0; |
| 1829 | } |
| 1830 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1831 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1832 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1833 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1834 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1835 | .mask_count = 0, |
| 1836 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1837 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1838 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1839 | .init_count = 40, |
| 1840 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1841 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1843 | /* HBQ for the extra ring if needed */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1844 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
| 1845 | .rn = 1, |
| 1846 | .entry_count = 200, |
| 1847 | .mask_count = 0, |
| 1848 | .profile = 0, |
| 1849 | .ring_mask = (1 << LPFC_EXTRA_RING), |
| 1850 | .buffer_count = 0, |
| 1851 | .init_count = 0, |
| 1852 | .add_count = 5, |
| 1853 | }; |
| 1854 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1855 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1856 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1857 | &lpfc_els_hbq, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1858 | &lpfc_extra_hbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1859 | }; |
| 1860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1861 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1862 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1863 | * @phba: Pointer to HBA context object. |
| 1864 | * @hbqno: HBQ number. |
| 1865 | * @count: Number of HBQ buffers to be posted. |
| 1866 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1867 | * This function is called with no lock held to post more hbq buffers to the |
| 1868 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1869 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1870 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1871 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1872 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1873 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1874 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1875 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1876 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1877 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1878 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1879 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1880 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1881 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1882 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1883 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1884 | phba->hbqs[hbqno].buffer_count; |
| 1885 | if (!count) |
| 1886 | return 0; |
| 1887 | /* Allocate HBQ entries */ |
| 1888 | for (i = 0; i < count; i++) { |
| 1889 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1890 | if (!hbq_buffer) |
| 1891 | break; |
| 1892 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1893 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1894 | /* Check whether HBQ is still in use */ |
| 1895 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1896 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1897 | goto err; |
| 1898 | while (!list_empty(&hbq_buf_list)) { |
| 1899 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1900 | dbuf.list); |
| 1901 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1902 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1903 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1904 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1905 | posted++; |
| 1906 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1907 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1908 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1909 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1910 | return posted; |
| 1911 | err: |
| 1912 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1913 | while (!list_empty(&hbq_buf_list)) { |
| 1914 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1915 | dbuf.list); |
| 1916 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1917 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1918 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1919 | } |
| 1920 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1921 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1922 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1923 | * @phba: Pointer to HBA context object. |
| 1924 | * @qno: HBQ number. |
| 1925 | * |
| 1926 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1927 | * is called with no lock held. The function returns the number of HBQ entries |
| 1928 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1929 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1930 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1931 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1932 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1933 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1934 | return 0; |
| 1935 | else |
| 1936 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1937 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1938 | } |
| 1939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1941 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1942 | * @phba: Pointer to HBA context object. |
| 1943 | * @qno: HBQ queue number. |
| 1944 | * |
| 1945 | * This function is called from SLI initialization code path with |
| 1946 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1947 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1948 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1949 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1951 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1952 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1953 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1954 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1955 | else |
| 1956 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1957 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1958 | } |
| 1959 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1960 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1961 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 1962 | * @phba: Pointer to HBA context object. |
| 1963 | * @hbqno: HBQ number. |
| 1964 | * |
| 1965 | * This function removes the first hbq buffer on an hbq list and returns a |
| 1966 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 1967 | **/ |
| 1968 | static struct hbq_dmabuf * |
| 1969 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 1970 | { |
| 1971 | struct lpfc_dmabuf *d_buf; |
| 1972 | |
| 1973 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 1974 | if (!d_buf) |
| 1975 | return NULL; |
| 1976 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 1977 | } |
| 1978 | |
| 1979 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1980 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1981 | * @phba: Pointer to HBA context object. |
| 1982 | * @tag: Tag of the hbq buffer. |
| 1983 | * |
| 1984 | * This function is called with hbalock held. This function searches |
| 1985 | * for the hbq buffer associated with the given tag in the hbq buffer |
| 1986 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise |
| 1987 | * it returns NULL. |
| 1988 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1989 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1990 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 1991 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | struct lpfc_dmabuf *d_buf; |
| 1993 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1994 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1995 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1996 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 1997 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1998 | return NULL; |
| 1999 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2000 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2001 | 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] | 2002 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2003 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2004 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2005 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2006 | } |
| 2007 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2008 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2010 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2011 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2012 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2013 | } |
| 2014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2015 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2016 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2017 | * @phba: Pointer to HBA context object. |
| 2018 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2019 | * |
| 2020 | * This function is called with hbalock. This function gives back |
| 2021 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2022 | * post the buffer, it will free the buffer. |
| 2023 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2024 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2025 | 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] | 2026 | { |
| 2027 | uint32_t hbqno; |
| 2028 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2029 | if (hbq_buffer) { |
| 2030 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2031 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2032 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2033 | } |
| 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_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2038 | * @mbxCommand: mailbox command code. |
| 2039 | * |
| 2040 | * This function is called by the mailbox event handler function to verify |
| 2041 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2042 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2043 | * and the mailbox event handler will take the HBA offline. |
| 2044 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | static int |
| 2046 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2047 | { |
| 2048 | uint8_t ret; |
| 2049 | |
| 2050 | switch (mbxCommand) { |
| 2051 | case MBX_LOAD_SM: |
| 2052 | case MBX_READ_NV: |
| 2053 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2054 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | case MBX_RUN_BIU_DIAG: |
| 2056 | case MBX_INIT_LINK: |
| 2057 | case MBX_DOWN_LINK: |
| 2058 | case MBX_CONFIG_LINK: |
| 2059 | case MBX_CONFIG_RING: |
| 2060 | case MBX_RESET_RING: |
| 2061 | case MBX_READ_CONFIG: |
| 2062 | case MBX_READ_RCONFIG: |
| 2063 | case MBX_READ_SPARM: |
| 2064 | case MBX_READ_STATUS: |
| 2065 | case MBX_READ_RPI: |
| 2066 | case MBX_READ_XRI: |
| 2067 | case MBX_READ_REV: |
| 2068 | case MBX_READ_LNK_STAT: |
| 2069 | case MBX_REG_LOGIN: |
| 2070 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | case MBX_CLEAR_LA: |
| 2072 | case MBX_DUMP_MEMORY: |
| 2073 | case MBX_DUMP_CONTEXT: |
| 2074 | case MBX_RUN_DIAGS: |
| 2075 | case MBX_RESTART: |
| 2076 | case MBX_UPDATE_CFG: |
| 2077 | case MBX_DOWN_LOAD: |
| 2078 | case MBX_DEL_LD_ENTRY: |
| 2079 | case MBX_RUN_PROGRAM: |
| 2080 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2081 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2083 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2085 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2086 | case MBX_LOAD_AREA: |
| 2087 | case MBX_RUN_BIU_DIAG64: |
| 2088 | case MBX_CONFIG_PORT: |
| 2089 | case MBX_READ_SPARM64: |
| 2090 | case MBX_READ_RPI64: |
| 2091 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2092 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2093 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | case MBX_SET_DEBUG: |
| 2095 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2096 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2097 | case MBX_REG_VPI: |
| 2098 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2099 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2100 | case MBX_PORT_CAPABILITIES: |
| 2101 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2102 | case MBX_SLI4_CONFIG: |
| 2103 | case MBX_SLI4_REQ_FTRS: |
| 2104 | case MBX_REG_FCFI: |
| 2105 | case MBX_UNREG_FCFI: |
| 2106 | case MBX_REG_VFI: |
| 2107 | case MBX_UNREG_VFI: |
| 2108 | case MBX_INIT_VPI: |
| 2109 | case MBX_INIT_VFI: |
| 2110 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2111 | case MBX_READ_EVENT_LOG_STATUS: |
| 2112 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2113 | case MBX_SECURITY_MGMT: |
| 2114 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2115 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | ret = mbxCommand; |
| 2117 | break; |
| 2118 | default: |
| 2119 | ret = MBX_SHUTDOWN; |
| 2120 | break; |
| 2121 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2124 | |
| 2125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2126 | * 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] | 2127 | * @phba: Pointer to HBA context object. |
| 2128 | * @pmboxq: Pointer to mailbox command. |
| 2129 | * |
| 2130 | * This is completion handler function for mailbox commands issued from |
| 2131 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2132 | * mailbox event handler function with no lock held. This function |
| 2133 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2134 | * of the mailbox. |
| 2135 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2136 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2137 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | { |
| 2139 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2140 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | |
| 2142 | /* |
| 2143 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2144 | * continued running. |
| 2145 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2146 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2147 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2149 | if (pdone_q) |
| 2150 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2151 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | return; |
| 2153 | } |
| 2154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2155 | |
| 2156 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2157 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2158 | * @phba: Pointer to HBA context object. |
| 2159 | * @pmb: Pointer to mailbox object. |
| 2160 | * |
| 2161 | * This function is the default mailbox completion handler. It |
| 2162 | * frees the memory resources associated with the completed mailbox |
| 2163 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2164 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2165 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2169 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2171 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2172 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2173 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2174 | int rc; |
| 2175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2176 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2177 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | if (mp) { |
| 2179 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2180 | kfree(mp); |
| 2181 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2182 | |
| 2183 | /* |
| 2184 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2185 | * is in re-discovery driver need to cleanup the RPI. |
| 2186 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2187 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2188 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2189 | !pmb->u.mb.mbxStatus) { |
| 2190 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2191 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2192 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2194 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2195 | if (rc != MBX_NOT_FINISHED) |
| 2196 | return; |
| 2197 | } |
| 2198 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2199 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2200 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2201 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2202 | shost = lpfc_shost_from_vport(vport); |
| 2203 | spin_lock_irq(shost->host_lock); |
| 2204 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2205 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2206 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2207 | } |
| 2208 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2209 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2210 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2211 | lpfc_nlp_put(ndlp); |
| 2212 | pmb->context2 = NULL; |
| 2213 | } |
| 2214 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2215 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2216 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2217 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2218 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2219 | "2860 SLI authentication is required " |
| 2220 | "for INIT_LINK but has not done yet\n"); |
| 2221 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2222 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2223 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2224 | else |
| 2225 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | } |
| 2227 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2228 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2229 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2230 | * @phba: Pointer to HBA context object. |
| 2231 | * |
| 2232 | * This function is called with no lock held. This function processes all |
| 2233 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2234 | * service routine processes mailbox completion interrupt and adds completed |
| 2235 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2236 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2237 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2238 | * function returns the mailbox commands to the upper layer by calling the |
| 2239 | * completion handler function of each mailbox. |
| 2240 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2241 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2242 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2243 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2244 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2246 | int rc; |
| 2247 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | |
| 2249 | phba->sli.slistat.mbox_event++; |
| 2250 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2251 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2252 | spin_lock_irq(&phba->hbalock); |
| 2253 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2254 | spin_unlock_irq(&phba->hbalock); |
| 2255 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2257 | do { |
| 2258 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2259 | if (pmb == NULL) |
| 2260 | break; |
| 2261 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2262 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2263 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2264 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2265 | if (pmb->vport) { |
| 2266 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2267 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2268 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2269 | (uint32_t)pmbox->mbxCommand, |
| 2270 | pmbox->un.varWords[0], |
| 2271 | pmbox->un.varWords[1]); |
| 2272 | } |
| 2273 | else { |
| 2274 | lpfc_debugfs_disc_trc(phba->pport, |
| 2275 | LPFC_DISC_TRC_MBOX, |
| 2276 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2277 | (uint32_t)pmbox->mbxCommand, |
| 2278 | pmbox->un.varWords[0], |
| 2279 | pmbox->un.varWords[1]); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | /* |
| 2284 | * It is a fatal error if unknown mbox command completion. |
| 2285 | */ |
| 2286 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2287 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2288 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2290 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2291 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2293 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2294 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2295 | pmb), |
| 2296 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2297 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2298 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2299 | phba->work_hs = HS_FFER3; |
| 2300 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2301 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | } |
| 2303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | if (pmbox->mbxStatus) { |
| 2305 | phba->sli.slistat.mbox_stat_err++; |
| 2306 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2307 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2308 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2309 | LOG_MBOX | LOG_SLI, |
| 2310 | "(%d):0305 Mbox cmd cmpl " |
| 2311 | "error - RETRYing Data: x%x " |
| 2312 | "(x%x/x%x) x%x x%x x%x\n", |
| 2313 | pmb->vport ? pmb->vport->vpi : 0, |
| 2314 | pmbox->mbxCommand, |
| 2315 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2316 | pmb), |
| 2317 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2318 | pmb), |
| 2319 | pmbox->mbxStatus, |
| 2320 | pmbox->un.varWords[0], |
| 2321 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | pmbox->mbxStatus = 0; |
| 2323 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2325 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2326 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2331 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2332 | "(%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] | 2333 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2334 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2335 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2337 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2338 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | pmb->mbox_cmpl, |
| 2340 | *((uint32_t *) pmbox), |
| 2341 | pmbox->un.varWords[0], |
| 2342 | pmbox->un.varWords[1], |
| 2343 | pmbox->un.varWords[2], |
| 2344 | pmbox->un.varWords[3], |
| 2345 | pmbox->un.varWords[4], |
| 2346 | pmbox->un.varWords[5], |
| 2347 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2348 | pmbox->un.varWords[7], |
| 2349 | pmbox->un.varWords[8], |
| 2350 | pmbox->un.varWords[9], |
| 2351 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2353 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2355 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2359 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2360 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2361 | * @phba: Pointer to HBA context object. |
| 2362 | * @pring: Pointer to driver SLI ring object. |
| 2363 | * @tag: buffer tag. |
| 2364 | * |
| 2365 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2366 | * is set in the tag the buffer is posted for a particular exchange, |
| 2367 | * the function will return the buffer without replacing the buffer. |
| 2368 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2369 | * returns the buffer and also posts another buffer to the firmware. |
| 2370 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2371 | static struct lpfc_dmabuf * |
| 2372 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2373 | struct lpfc_sli_ring *pring, |
| 2374 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2375 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2376 | struct hbq_dmabuf *hbq_entry; |
| 2377 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2378 | if (tag & QUE_BUFTAG_BIT) |
| 2379 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2380 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2381 | if (!hbq_entry) |
| 2382 | return NULL; |
| 2383 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2384 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2385 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2386 | /** |
| 2387 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2388 | * @phba: Pointer to HBA context object. |
| 2389 | * @pring: Pointer to driver SLI ring object. |
| 2390 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2391 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2392 | * @fch_type: the type for the first frame of the sequence. |
| 2393 | * |
| 2394 | * This function is called with no lock held. This function uses the r_ctl and |
| 2395 | * type of the received sequence to find the correct callback function to call |
| 2396 | * to process the sequence. |
| 2397 | **/ |
| 2398 | static int |
| 2399 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2400 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2401 | uint32_t fch_type) |
| 2402 | { |
| 2403 | int i; |
| 2404 | |
| 2405 | /* unSolicited Responses */ |
| 2406 | if (pring->prt[0].profile) { |
| 2407 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2408 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2409 | saveq); |
| 2410 | return 1; |
| 2411 | } |
| 2412 | /* We must search, based on rctl / type |
| 2413 | for the right routine */ |
| 2414 | for (i = 0; i < pring->num_mask; i++) { |
| 2415 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2416 | (pring->prt[i].type == fch_type)) { |
| 2417 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2418 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2419 | (phba, pring, saveq); |
| 2420 | return 1; |
| 2421 | } |
| 2422 | } |
| 2423 | return 0; |
| 2424 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2425 | |
| 2426 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2427 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2428 | * @phba: Pointer to HBA context object. |
| 2429 | * @pring: Pointer to driver SLI ring object. |
| 2430 | * @saveq: Pointer to the unsolicited iocb. |
| 2431 | * |
| 2432 | * This function is called with no lock held by the ring event handler |
| 2433 | * when there is an unsolicited iocb posted to the response ring by the |
| 2434 | * firmware. This function gets the buffer associated with the iocbs |
| 2435 | * and calls the event handler for the ring. This function handles both |
| 2436 | * qring buffers and hbq buffers. |
| 2437 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2438 | * upper layer functions will free the iocb objects. |
| 2439 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | static int |
| 2441 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2442 | struct lpfc_iocbq *saveq) |
| 2443 | { |
| 2444 | IOCB_t * irsp; |
| 2445 | WORD5 * w5p; |
| 2446 | uint32_t Rctl, Type; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2447 | uint32_t match; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2448 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2449 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | |
| 2451 | match = 0; |
| 2452 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2453 | |
| 2454 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2455 | if (pring->lpfc_sli_rcv_async_status) |
| 2456 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2457 | else |
| 2458 | lpfc_printf_log(phba, |
| 2459 | KERN_WARNING, |
| 2460 | LOG_SLI, |
| 2461 | "0316 Ring %d handler: unexpected " |
| 2462 | "ASYNC_STATUS iocb received evt_code " |
| 2463 | "0x%x\n", |
| 2464 | pring->ringno, |
| 2465 | irsp->un.asyncstat.evt_code); |
| 2466 | return 1; |
| 2467 | } |
| 2468 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2469 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2470 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2471 | if (irsp->ulpBdeCount > 0) { |
| 2472 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2473 | irsp->un.ulpWord[3]); |
| 2474 | lpfc_in_buf_free(phba, dmzbuf); |
| 2475 | } |
| 2476 | |
| 2477 | if (irsp->ulpBdeCount > 1) { |
| 2478 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2479 | irsp->unsli3.sli3Words[3]); |
| 2480 | lpfc_in_buf_free(phba, dmzbuf); |
| 2481 | } |
| 2482 | |
| 2483 | if (irsp->ulpBdeCount > 2) { |
| 2484 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2485 | irsp->unsli3.sli3Words[7]); |
| 2486 | lpfc_in_buf_free(phba, dmzbuf); |
| 2487 | } |
| 2488 | |
| 2489 | return 1; |
| 2490 | } |
| 2491 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2492 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2493 | if (irsp->ulpBdeCount != 0) { |
| 2494 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2495 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2496 | if (!saveq->context2) |
| 2497 | lpfc_printf_log(phba, |
| 2498 | KERN_ERR, |
| 2499 | LOG_SLI, |
| 2500 | "0341 Ring %d Cannot find buffer for " |
| 2501 | "an unsolicited iocb. tag 0x%x\n", |
| 2502 | pring->ringno, |
| 2503 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2504 | } |
| 2505 | if (irsp->ulpBdeCount == 2) { |
| 2506 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2507 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2508 | if (!saveq->context3) |
| 2509 | lpfc_printf_log(phba, |
| 2510 | KERN_ERR, |
| 2511 | LOG_SLI, |
| 2512 | "0342 Ring %d Cannot find buffer for an" |
| 2513 | " unsolicited iocb. tag 0x%x\n", |
| 2514 | pring->ringno, |
| 2515 | irsp->unsli3.sli3Words[7]); |
| 2516 | } |
| 2517 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2518 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2519 | if (irsp->ulpBdeCount != 0) { |
| 2520 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2521 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2522 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2523 | lpfc_printf_log(phba, |
| 2524 | KERN_ERR, |
| 2525 | LOG_SLI, |
| 2526 | "0343 Ring %d Cannot find " |
| 2527 | "buffer for an unsolicited iocb" |
| 2528 | ". tag 0x%x\n", pring->ringno, |
| 2529 | irsp->un.ulpWord[3]); |
| 2530 | } |
| 2531 | if (irsp->ulpBdeCount == 2) { |
| 2532 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2533 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2534 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2535 | lpfc_printf_log(phba, |
| 2536 | KERN_ERR, |
| 2537 | LOG_SLI, |
| 2538 | "0344 Ring %d Cannot find " |
| 2539 | "buffer for an unsolicited " |
| 2540 | "iocb. tag 0x%x\n", |
| 2541 | pring->ringno, |
| 2542 | irsp->unsli3.sli3Words[7]); |
| 2543 | } |
| 2544 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2545 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2546 | if (irsp->ulpBdeCount != 0 && |
| 2547 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2548 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2549 | int found = 0; |
| 2550 | |
| 2551 | /* search continue save q for same XRI */ |
| 2552 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2553 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2554 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2555 | list_add_tail(&saveq->list, &iocbq->list); |
| 2556 | found = 1; |
| 2557 | break; |
| 2558 | } |
| 2559 | } |
| 2560 | if (!found) |
| 2561 | list_add_tail(&saveq->clist, |
| 2562 | &pring->iocb_continue_saveq); |
| 2563 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2564 | list_del_init(&iocbq->clist); |
| 2565 | saveq = iocbq; |
| 2566 | irsp = &(saveq->iocb); |
| 2567 | } else |
| 2568 | return 0; |
| 2569 | } |
| 2570 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2571 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2572 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2573 | Rctl = FC_RCTL_ELS_REQ; |
| 2574 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2575 | } else { |
| 2576 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2577 | Rctl = w5p->hcsw.Rctl; |
| 2578 | Type = w5p->hcsw.Type; |
| 2579 | |
| 2580 | /* Firmware Workaround */ |
| 2581 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2582 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2583 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2584 | Rctl = FC_RCTL_ELS_REQ; |
| 2585 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2586 | w5p->hcsw.Rctl = Rctl; |
| 2587 | w5p->hcsw.Type = Type; |
| 2588 | } |
| 2589 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2590 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2591 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2592 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2593 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2594 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2595 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2596 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2597 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | } |
| 2599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2601 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2602 | * @phba: Pointer to HBA context object. |
| 2603 | * @pring: Pointer to driver SLI ring object. |
| 2604 | * @prspiocb: Pointer to response iocb object. |
| 2605 | * |
| 2606 | * This function looks up the iocb_lookup table to get the command iocb |
| 2607 | * corresponding to the given response iocb using the iotag of the |
| 2608 | * response iocb. This function is called with the hbalock held. |
| 2609 | * This function returns the command iocb object if it finds the command |
| 2610 | * iocb else returns NULL. |
| 2611 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2613 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2614 | struct lpfc_sli_ring *pring, |
| 2615 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2618 | uint16_t iotag; |
| 2619 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2620 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2622 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2623 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2624 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2625 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2626 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2627 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2628 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | } |
| 2630 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2632 | "0317 iotag x%x is out off " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2633 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2634 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2635 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | return NULL; |
| 2637 | } |
| 2638 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2639 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2640 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2641 | * @phba: Pointer to HBA context object. |
| 2642 | * @pring: Pointer to driver SLI ring object. |
| 2643 | * @iotag: IOCB tag. |
| 2644 | * |
| 2645 | * This function looks up the iocb_lookup table to get the command iocb |
| 2646 | * corresponding to the given iotag. This function is called with the |
| 2647 | * hbalock held. |
| 2648 | * This function returns the command iocb object if it finds the command |
| 2649 | * iocb else returns NULL. |
| 2650 | **/ |
| 2651 | static struct lpfc_iocbq * |
| 2652 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2653 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2654 | { |
| 2655 | struct lpfc_iocbq *cmd_iocb; |
| 2656 | |
| 2657 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2658 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2659 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2660 | /* remove from txcmpl queue list */ |
| 2661 | list_del_init(&cmd_iocb->list); |
| 2662 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2663 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2664 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2665 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2666 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2667 | "0372 iotag x%x is out off range: max iotag (x%x)\n", |
| 2668 | iotag, phba->sli.last_iotag); |
| 2669 | return NULL; |
| 2670 | } |
| 2671 | |
| 2672 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2673 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2674 | * @phba: Pointer to HBA context object. |
| 2675 | * @pring: Pointer to driver SLI ring object. |
| 2676 | * @saveq: Pointer to the response iocb to be processed. |
| 2677 | * |
| 2678 | * This function is called by the ring event handler for non-fcp |
| 2679 | * rings when there is a new response iocb in the response ring. |
| 2680 | * The caller is not required to hold any locks. This function |
| 2681 | * gets the command iocb associated with the response iocb and |
| 2682 | * calls the completion handler for the command iocb. If there |
| 2683 | * is no completion handler, the function will free the resources |
| 2684 | * associated with command iocb. If the response iocb is for |
| 2685 | * an already aborted command iocb, the status of the completion |
| 2686 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2687 | * This function always returns 1. |
| 2688 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2690 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | struct lpfc_iocbq *saveq) |
| 2692 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2693 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | int rc = 1; |
| 2695 | unsigned long iflag; |
| 2696 | |
| 2697 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2699 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2700 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2701 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | if (cmdiocbp) { |
| 2703 | if (cmdiocbp->iocb_cmpl) { |
| 2704 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2705 | * If an ELS command failed send an event to mgmt |
| 2706 | * application. |
| 2707 | */ |
| 2708 | if (saveq->iocb.ulpStatus && |
| 2709 | (pring->ringno == LPFC_ELS_RING) && |
| 2710 | (cmdiocbp->iocb.ulpCommand == |
| 2711 | CMD_ELS_REQUEST64_CR)) |
| 2712 | lpfc_send_els_failure_event(phba, |
| 2713 | cmdiocbp, saveq); |
| 2714 | |
| 2715 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | * Post all ELS completions to the worker thread. |
| 2717 | * All other are passed to the completion callback. |
| 2718 | */ |
| 2719 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2720 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2721 | (cmdiocbp->iocb_flag & |
| 2722 | LPFC_DRIVER_ABORTED)) { |
| 2723 | spin_lock_irqsave(&phba->hbalock, |
| 2724 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2725 | cmdiocbp->iocb_flag &= |
| 2726 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2727 | spin_unlock_irqrestore(&phba->hbalock, |
| 2728 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2729 | saveq->iocb.ulpStatus = |
| 2730 | IOSTAT_LOCAL_REJECT; |
| 2731 | saveq->iocb.un.ulpWord[4] = |
| 2732 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2733 | |
| 2734 | /* Firmware could still be in progress |
| 2735 | * of DMAing payload, so don't free data |
| 2736 | * buffer till after a hbeat. |
| 2737 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2738 | spin_lock_irqsave(&phba->hbalock, |
| 2739 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2740 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2741 | spin_unlock_irqrestore(&phba->hbalock, |
| 2742 | iflag); |
| 2743 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2744 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2745 | if (saveq->iocb_flag & |
| 2746 | LPFC_EXCHANGE_BUSY) { |
| 2747 | /* Set cmdiocb flag for the |
| 2748 | * exchange busy so sgl (xri) |
| 2749 | * will not be released until |
| 2750 | * the abort xri is received |
| 2751 | * from hba. |
| 2752 | */ |
| 2753 | spin_lock_irqsave( |
| 2754 | &phba->hbalock, iflag); |
| 2755 | cmdiocbp->iocb_flag |= |
| 2756 | LPFC_EXCHANGE_BUSY; |
| 2757 | spin_unlock_irqrestore( |
| 2758 | &phba->hbalock, iflag); |
| 2759 | } |
| 2760 | if (cmdiocbp->iocb_flag & |
| 2761 | LPFC_DRIVER_ABORTED) { |
| 2762 | /* |
| 2763 | * Clear LPFC_DRIVER_ABORTED |
| 2764 | * bit in case it was driver |
| 2765 | * initiated abort. |
| 2766 | */ |
| 2767 | spin_lock_irqsave( |
| 2768 | &phba->hbalock, iflag); |
| 2769 | cmdiocbp->iocb_flag &= |
| 2770 | ~LPFC_DRIVER_ABORTED; |
| 2771 | spin_unlock_irqrestore( |
| 2772 | &phba->hbalock, iflag); |
| 2773 | cmdiocbp->iocb.ulpStatus = |
| 2774 | IOSTAT_LOCAL_REJECT; |
| 2775 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2776 | IOERR_ABORT_REQUESTED; |
| 2777 | /* |
| 2778 | * For SLI4, irsiocb contains |
| 2779 | * NO_XRI in sli_xritag, it |
| 2780 | * shall not affect releasing |
| 2781 | * sgl (xri) process. |
| 2782 | */ |
| 2783 | saveq->iocb.ulpStatus = |
| 2784 | IOSTAT_LOCAL_REJECT; |
| 2785 | saveq->iocb.un.ulpWord[4] = |
| 2786 | IOERR_SLI_ABORTED; |
| 2787 | spin_lock_irqsave( |
| 2788 | &phba->hbalock, iflag); |
| 2789 | saveq->iocb_flag |= |
| 2790 | LPFC_DELAY_MEM_FREE; |
| 2791 | spin_unlock_irqrestore( |
| 2792 | &phba->hbalock, iflag); |
| 2793 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2794 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2796 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2797 | } else |
| 2798 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | } else { |
| 2800 | /* |
| 2801 | * Unknown initiating command based on the response iotag. |
| 2802 | * This could be the case on the ELS ring because of |
| 2803 | * lpfc_els_abort(). |
| 2804 | */ |
| 2805 | if (pring->ringno != LPFC_ELS_RING) { |
| 2806 | /* |
| 2807 | * Ring <ringno> handler: unexpected completion IoTag |
| 2808 | * <IoTag> |
| 2809 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2810 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2811 | "0322 Ring %d handler: " |
| 2812 | "unexpected completion IoTag x%x " |
| 2813 | "Data: x%x x%x x%x x%x\n", |
| 2814 | pring->ringno, |
| 2815 | saveq->iocb.ulpIoTag, |
| 2816 | saveq->iocb.ulpStatus, |
| 2817 | saveq->iocb.un.ulpWord[4], |
| 2818 | saveq->iocb.ulpCommand, |
| 2819 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | } |
| 2821 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2822 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | return rc; |
| 2824 | } |
| 2825 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2826 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2827 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2828 | * @phba: Pointer to HBA context object. |
| 2829 | * @pring: Pointer to driver SLI ring object. |
| 2830 | * |
| 2831 | * This function is called from the iocb ring event handlers when |
| 2832 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2833 | * an error attention condition to the worker thread and the worker |
| 2834 | * thread will transition the HBA to offline state. |
| 2835 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2836 | static void |
| 2837 | 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] | 2838 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2839 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2840 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2841 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2842 | * rsp ring <portRspMax> |
| 2843 | */ |
| 2844 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2845 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2846 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2847 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2848 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2849 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2850 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2851 | |
| 2852 | /* |
| 2853 | * All error attention handlers are posted to |
| 2854 | * worker thread |
| 2855 | */ |
| 2856 | phba->work_ha |= HA_ERATT; |
| 2857 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2858 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2859 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2860 | |
| 2861 | return; |
| 2862 | } |
| 2863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2865 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2866 | * @ptr: Pointer to address of HBA context object. |
| 2867 | * |
| 2868 | * This function is invoked by the Error Attention polling timer when the |
| 2869 | * timer times out. It will check the SLI Error Attention register for |
| 2870 | * possible attention events. If so, it will post an Error Attention event |
| 2871 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 2872 | * Error Attention polling timer for the next poll. |
| 2873 | **/ |
| 2874 | void lpfc_poll_eratt(unsigned long ptr) |
| 2875 | { |
| 2876 | struct lpfc_hba *phba; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2877 | uint32_t eratt = 0, rem; |
| 2878 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2879 | |
| 2880 | phba = (struct lpfc_hba *)ptr; |
| 2881 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 2882 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 2883 | sli_intr = phba->sli.slistat.sli_intr; |
| 2884 | |
| 2885 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 2886 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 2887 | sli_intr); |
| 2888 | else |
| 2889 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 2890 | |
| 2891 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ |
| 2892 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); |
| 2893 | phba->sli.slistat.sli_ips = cnt; |
| 2894 | |
| 2895 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 2896 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2897 | /* Check chip HA register for error event */ |
| 2898 | eratt = lpfc_sli_check_eratt(phba); |
| 2899 | |
| 2900 | if (eratt) |
| 2901 | /* Tell the worker thread there is work to do */ |
| 2902 | lpfc_worker_wake_up(phba); |
| 2903 | else |
| 2904 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 2905 | mod_timer(&phba->eratt_poll, |
| 2906 | jiffies + |
| 2907 | msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2908 | return; |
| 2909 | } |
| 2910 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2911 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2912 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2913 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2914 | * @phba: Pointer to HBA context object. |
| 2915 | * @pring: Pointer to driver SLI ring object. |
| 2916 | * @mask: Host attention register mask for this ring. |
| 2917 | * |
| 2918 | * This function is called from the interrupt context when there is a ring |
| 2919 | * event for the fcp ring. The caller does not hold any lock. |
| 2920 | * 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] | 2921 | * 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] | 2922 | * LE bit set. The function will call the completion handler of the command iocb |
| 2923 | * if the response iocb indicates a completion for a command iocb or it is |
| 2924 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 2925 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2927 | * to check it explicitly. |
| 2928 | */ |
| 2929 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2930 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 2931 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2933 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2934 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2935 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 2937 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | uint32_t status; |
| 2939 | uint32_t portRspPut, portRspMax; |
| 2940 | int rc = 1; |
| 2941 | lpfc_iocb_type type; |
| 2942 | unsigned long iflag; |
| 2943 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2944 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2945 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2946 | pring->stats.iocb_event++; |
| 2947 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2948 | /* |
| 2949 | * The next available response entry should never exceed the maximum |
| 2950 | * entries. If it does, treat it as an adapter hardware error. |
| 2951 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2952 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 2954 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2955 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2956 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | return 1; |
| 2958 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 2959 | if (phba->fcp_ring_in_use) { |
| 2960 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2961 | return 1; |
| 2962 | } else |
| 2963 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | |
| 2965 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2966 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2967 | /* |
| 2968 | * Fetch an entry off the ring and copy it into a local data |
| 2969 | * structure. The copy involves a byte-swap since the |
| 2970 | * network byte order and pci byte orders are different. |
| 2971 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2972 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2973 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2974 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2975 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 2976 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2977 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2978 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 2979 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2980 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2981 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 2982 | irsp = &rspiocbq.iocb; |
| 2983 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 2985 | pring->stats.iocb_rsp++; |
| 2986 | rsp_cmpl++; |
| 2987 | |
| 2988 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2989 | /* |
| 2990 | * If resource errors reported from HBA, reduce |
| 2991 | * queuedepths of the SCSI device. |
| 2992 | */ |
| 2993 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 2994 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 2995 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2996 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2997 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2999 | } |
| 3000 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | /* Rsp ring <ringno> error: IOCB */ |
| 3002 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3003 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3004 | "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] | 3005 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3006 | irsp->un.ulpWord[0], |
| 3007 | irsp->un.ulpWord[1], |
| 3008 | irsp->un.ulpWord[2], |
| 3009 | irsp->un.ulpWord[3], |
| 3010 | irsp->un.ulpWord[4], |
| 3011 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3012 | *(uint32_t *)&irsp->un1, |
| 3013 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | switch (type) { |
| 3017 | case LPFC_ABORT_IOCB: |
| 3018 | case LPFC_SOL_IOCB: |
| 3019 | /* |
| 3020 | * Idle exchange closed via ABTS from port. No iocb |
| 3021 | * resources need to be recovered. |
| 3022 | */ |
| 3023 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3024 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3025 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3026 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3027 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3028 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | break; |
| 3030 | } |
| 3031 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3032 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3033 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3034 | if (unlikely(!cmdiocbq)) |
| 3035 | break; |
| 3036 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3037 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3038 | if (cmdiocbq->iocb_cmpl) { |
| 3039 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3040 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3041 | &rspiocbq); |
| 3042 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3043 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3044 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3045 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3046 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3047 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3048 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3049 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | default: |
| 3051 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3052 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3053 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3054 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3055 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3056 | dev_warn(&((phba->pcidev)->dev), |
| 3057 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | phba->brd_no, adaptermsg); |
| 3059 | } else { |
| 3060 | /* Unknown IOCB command */ |
| 3061 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3062 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3063 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3064 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3065 | irsp->ulpStatus, |
| 3066 | irsp->ulpIoTag, |
| 3067 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | } |
| 3069 | break; |
| 3070 | } |
| 3071 | |
| 3072 | /* |
| 3073 | * The response IOCB has been processed. Update the ring |
| 3074 | * pointer in SLIM. If the port response put pointer has not |
| 3075 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3076 | * response put pointer. |
| 3077 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3078 | writel(pring->sli.sli3.rspidx, |
| 3079 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3080 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3081 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3083 | } |
| 3084 | |
| 3085 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3086 | pring->stats.iocb_rsp_full++; |
| 3087 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3088 | writel(status, phba->CAregaddr); |
| 3089 | readl(phba->CAregaddr); |
| 3090 | } |
| 3091 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3092 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3093 | pring->stats.iocb_cmd_empty++; |
| 3094 | |
| 3095 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3096 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | lpfc_sli_resume_iocb(phba, pring); |
| 3098 | |
| 3099 | if ((pring->lpfc_sli_cmd_available)) |
| 3100 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3101 | |
| 3102 | } |
| 3103 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3104 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3105 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | return rc; |
| 3107 | } |
| 3108 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3109 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3110 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3111 | * @phba: Pointer to HBA context object. |
| 3112 | * @pring: Pointer to driver SLI ring object. |
| 3113 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3114 | * |
| 3115 | * This function is called from the worker thread when there is a slow-path |
| 3116 | * response IOCB to process. This function chains all the response iocbs until |
| 3117 | * seeing the iocb with the LE bit set. The function will call |
| 3118 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3119 | * completion of a command iocb. The function will call the |
| 3120 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3121 | * The function frees the resources or calls the completion handler if this |
| 3122 | * iocb is an abort completion. The function returns NULL when the response |
| 3123 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3124 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3125 | * response iocb passed in. |
| 3126 | **/ |
| 3127 | static struct lpfc_iocbq * |
| 3128 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3129 | struct lpfc_iocbq *rspiocbp) |
| 3130 | { |
| 3131 | struct lpfc_iocbq *saveq; |
| 3132 | struct lpfc_iocbq *cmdiocbp; |
| 3133 | struct lpfc_iocbq *next_iocb; |
| 3134 | IOCB_t *irsp = NULL; |
| 3135 | uint32_t free_saveq; |
| 3136 | uint8_t iocb_cmd_type; |
| 3137 | lpfc_iocb_type type; |
| 3138 | unsigned long iflag; |
| 3139 | int rc; |
| 3140 | |
| 3141 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3142 | /* First add the response iocb to the countinueq list */ |
| 3143 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3144 | pring->iocb_continueq_cnt++; |
| 3145 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3146 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3147 | irsp = &rspiocbp->iocb; |
| 3148 | if (irsp->ulpLe) { |
| 3149 | /* |
| 3150 | * By default, the driver expects to free all resources |
| 3151 | * associated with this iocb completion. |
| 3152 | */ |
| 3153 | free_saveq = 1; |
| 3154 | saveq = list_get_first(&pring->iocb_continueq, |
| 3155 | struct lpfc_iocbq, list); |
| 3156 | irsp = &(saveq->iocb); |
| 3157 | list_del_init(&pring->iocb_continueq); |
| 3158 | pring->iocb_continueq_cnt = 0; |
| 3159 | |
| 3160 | pring->stats.iocb_rsp++; |
| 3161 | |
| 3162 | /* |
| 3163 | * If resource errors reported from HBA, reduce |
| 3164 | * queuedepths of the SCSI device. |
| 3165 | */ |
| 3166 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3167 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3168 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3169 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3170 | phba->lpfc_rampdown_queue_depth(phba); |
| 3171 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3172 | } |
| 3173 | |
| 3174 | if (irsp->ulpStatus) { |
| 3175 | /* Rsp ring <ringno> error: IOCB */ |
| 3176 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3177 | "0328 Rsp Ring %d error: " |
| 3178 | "IOCB Data: " |
| 3179 | "x%x x%x x%x x%x " |
| 3180 | "x%x x%x x%x x%x " |
| 3181 | "x%x x%x x%x x%x " |
| 3182 | "x%x x%x x%x x%x\n", |
| 3183 | pring->ringno, |
| 3184 | irsp->un.ulpWord[0], |
| 3185 | irsp->un.ulpWord[1], |
| 3186 | irsp->un.ulpWord[2], |
| 3187 | irsp->un.ulpWord[3], |
| 3188 | irsp->un.ulpWord[4], |
| 3189 | irsp->un.ulpWord[5], |
| 3190 | *(((uint32_t *) irsp) + 6), |
| 3191 | *(((uint32_t *) irsp) + 7), |
| 3192 | *(((uint32_t *) irsp) + 8), |
| 3193 | *(((uint32_t *) irsp) + 9), |
| 3194 | *(((uint32_t *) irsp) + 10), |
| 3195 | *(((uint32_t *) irsp) + 11), |
| 3196 | *(((uint32_t *) irsp) + 12), |
| 3197 | *(((uint32_t *) irsp) + 13), |
| 3198 | *(((uint32_t *) irsp) + 14), |
| 3199 | *(((uint32_t *) irsp) + 15)); |
| 3200 | } |
| 3201 | |
| 3202 | /* |
| 3203 | * Fetch the IOCB command type and call the correct completion |
| 3204 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3205 | * get freed back to the lpfc_iocb_list by the discovery |
| 3206 | * kernel thread. |
| 3207 | */ |
| 3208 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3209 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3210 | switch (type) { |
| 3211 | case LPFC_SOL_IOCB: |
| 3212 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3213 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3214 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3215 | break; |
| 3216 | |
| 3217 | case LPFC_UNSOL_IOCB: |
| 3218 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3219 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3220 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3221 | if (!rc) |
| 3222 | free_saveq = 0; |
| 3223 | break; |
| 3224 | |
| 3225 | case LPFC_ABORT_IOCB: |
| 3226 | cmdiocbp = NULL; |
| 3227 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3228 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3229 | saveq); |
| 3230 | if (cmdiocbp) { |
| 3231 | /* Call the specified completion routine */ |
| 3232 | if (cmdiocbp->iocb_cmpl) { |
| 3233 | spin_unlock_irqrestore(&phba->hbalock, |
| 3234 | iflag); |
| 3235 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3236 | saveq); |
| 3237 | spin_lock_irqsave(&phba->hbalock, |
| 3238 | iflag); |
| 3239 | } else |
| 3240 | __lpfc_sli_release_iocbq(phba, |
| 3241 | cmdiocbp); |
| 3242 | } |
| 3243 | break; |
| 3244 | |
| 3245 | case LPFC_UNKNOWN_IOCB: |
| 3246 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3247 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3248 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3249 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3250 | MAX_MSG_DATA); |
| 3251 | dev_warn(&((phba->pcidev)->dev), |
| 3252 | "lpfc%d: %s\n", |
| 3253 | phba->brd_no, adaptermsg); |
| 3254 | } else { |
| 3255 | /* Unknown IOCB command */ |
| 3256 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3257 | "0335 Unknown IOCB " |
| 3258 | "command Data: x%x " |
| 3259 | "x%x x%x x%x\n", |
| 3260 | irsp->ulpCommand, |
| 3261 | irsp->ulpStatus, |
| 3262 | irsp->ulpIoTag, |
| 3263 | irsp->ulpContext); |
| 3264 | } |
| 3265 | break; |
| 3266 | } |
| 3267 | |
| 3268 | if (free_saveq) { |
| 3269 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3270 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3271 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3272 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3273 | } |
| 3274 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3275 | } |
| 3276 | rspiocbp = NULL; |
| 3277 | } |
| 3278 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3279 | return rspiocbp; |
| 3280 | } |
| 3281 | |
| 3282 | /** |
| 3283 | * 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] | 3284 | * @phba: Pointer to HBA context object. |
| 3285 | * @pring: Pointer to driver SLI ring object. |
| 3286 | * @mask: Host attention register mask for this ring. |
| 3287 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3288 | * This routine wraps the actual slow_ring event process routine from the |
| 3289 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3290 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3291 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3292 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3293 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3295 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
| 3299 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3300 | * @phba: Pointer to HBA context object. |
| 3301 | * @pring: Pointer to driver SLI ring object. |
| 3302 | * @mask: Host attention register mask for this ring. |
| 3303 | * |
| 3304 | * This function is called from the worker thread when there is a ring event |
| 3305 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3306 | * remove each response iocb in the response ring and calls the handle |
| 3307 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3308 | **/ |
| 3309 | static void |
| 3310 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3311 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3312 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3313 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | IOCB_t *entry; |
| 3315 | IOCB_t *irsp = NULL; |
| 3316 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3319 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3321 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3322 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | pring->stats.iocb_event++; |
| 3324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | /* |
| 3326 | * The next available response entry should never exceed the maximum |
| 3327 | * entries. If it does, treat it as an adapter hardware error. |
| 3328 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3329 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3331 | if (portRspPut >= portRspMax) { |
| 3332 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3333 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | * rsp ring <portRspMax> |
| 3335 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3336 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3337 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3338 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3339 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3341 | phba->link_state = LPFC_HBA_ERROR; |
| 3342 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | |
| 3344 | phba->work_hs = HS_FFER3; |
| 3345 | lpfc_handle_eratt(phba); |
| 3346 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3347 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3351 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | /* |
| 3353 | * Build a completion list and call the appropriate handler. |
| 3354 | * The process is to get the next available response iocb, get |
| 3355 | * a free iocb from the list, copy the response data into the |
| 3356 | * free iocb, insert to the continuation list, and update the |
| 3357 | * next response index to slim. This process makes response |
| 3358 | * iocb's in the ring available to DMA as fast as possible but |
| 3359 | * pays a penalty for a copy operation. Since the iocb is |
| 3360 | * only 32 bytes, this penalty is considered small relative to |
| 3361 | * the PCI reads for register values and a slim write. When |
| 3362 | * the ulpLe field is set, the entire Command has been |
| 3363 | * received. |
| 3364 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3365 | entry = lpfc_resp_iocb(phba, pring); |
| 3366 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3367 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3368 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | if (rspiocbp == NULL) { |
| 3370 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3371 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | break; |
| 3373 | } |
| 3374 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3375 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3376 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | irsp = &rspiocbp->iocb; |
| 3378 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3379 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3380 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3382 | if (pring->ringno == LPFC_ELS_RING) { |
| 3383 | lpfc_debugfs_slow_ring_trc(phba, |
| 3384 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3385 | *(((uint32_t *) irsp) + 4), |
| 3386 | *(((uint32_t *) irsp) + 6), |
| 3387 | *(((uint32_t *) irsp) + 7)); |
| 3388 | } |
| 3389 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3390 | writel(pring->sli.sli3.rspidx, |
| 3391 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3393 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3394 | /* Handle the response IOCB */ |
| 3395 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3396 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | |
| 3398 | /* |
| 3399 | * If the port response put pointer has not been updated, sync |
| 3400 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3401 | * response put pointer. |
| 3402 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3403 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3405 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3406 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3408 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | /* At least one response entry has been freed */ |
| 3410 | pring->stats.iocb_rsp_full++; |
| 3411 | /* SET RxRE_RSP in Chip Att register */ |
| 3412 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3413 | writel(status, phba->CAregaddr); |
| 3414 | readl(phba->CAregaddr); /* flush */ |
| 3415 | } |
| 3416 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3417 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3418 | pring->stats.iocb_cmd_empty++; |
| 3419 | |
| 3420 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3421 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3422 | lpfc_sli_resume_iocb(phba, pring); |
| 3423 | |
| 3424 | if ((pring->lpfc_sli_cmd_available)) |
| 3425 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3426 | |
| 3427 | } |
| 3428 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3429 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3430 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | } |
| 3432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3433 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3434 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3435 | * @phba: Pointer to HBA context object. |
| 3436 | * @pring: Pointer to driver SLI ring object. |
| 3437 | * @mask: Host attention register mask for this ring. |
| 3438 | * |
| 3439 | * This function is called from the worker thread when there is a pending |
| 3440 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3441 | * queue. The caller does not hold any lock. The function will remove each |
| 3442 | * response iocb from the response worker queue and calls the handle |
| 3443 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3444 | **/ |
| 3445 | static void |
| 3446 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3447 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3448 | { |
| 3449 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3450 | struct hbq_dmabuf *dmabuf; |
| 3451 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3452 | unsigned long iflag; |
| 3453 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3454 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3455 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3456 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3457 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3458 | /* Get the response iocb from the head of work queue */ |
| 3459 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3460 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3461 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3462 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3463 | |
| 3464 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3465 | case CQE_CODE_COMPL_WQE: |
| 3466 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3467 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3468 | /* Translate ELS WCQE to response IOCBQ */ |
| 3469 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3470 | irspiocbq); |
| 3471 | if (irspiocbq) |
| 3472 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3473 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3474 | break; |
| 3475 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3476 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3477 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3478 | cq_event); |
| 3479 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3480 | break; |
| 3481 | default: |
| 3482 | break; |
| 3483 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | |
| 3487 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3488 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3489 | * @phba: Pointer to HBA context object. |
| 3490 | * @pring: Pointer to driver SLI ring object. |
| 3491 | * |
| 3492 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3493 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3494 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3495 | * the return of this function. The caller is not required to hold any locks. |
| 3496 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3499 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3500 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3503 | if (pring->ringno == LPFC_ELS_RING) { |
| 3504 | lpfc_fabric_abort_hba(phba); |
| 3505 | } |
| 3506 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | /* Error everything on txq and txcmplq |
| 3508 | * First do the txq. |
| 3509 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3510 | spin_lock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3511 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | |
| 3513 | /* Next issue ABTS for everything on the txcmplq */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3514 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3515 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3516 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3517 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3518 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3519 | /* Cancel all the IOCBs from the completions list */ |
| 3520 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3521 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3522 | } |
| 3523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3524 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3525 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3526 | * @phba: Pointer to HBA context object. |
| 3527 | * |
| 3528 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3529 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3530 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3531 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3532 | * slot has been permanently disabled. |
| 3533 | **/ |
| 3534 | void |
| 3535 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3536 | { |
| 3537 | LIST_HEAD(txq); |
| 3538 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3539 | struct lpfc_sli *psli = &phba->sli; |
| 3540 | struct lpfc_sli_ring *pring; |
| 3541 | |
| 3542 | /* Currently, only one fcp ring */ |
| 3543 | pring = &psli->ring[psli->fcp_ring]; |
| 3544 | |
| 3545 | spin_lock_irq(&phba->hbalock); |
| 3546 | /* Retrieve everything on txq */ |
| 3547 | list_splice_init(&pring->txq, &txq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3548 | |
| 3549 | /* Retrieve everything on the txcmplq */ |
| 3550 | list_splice_init(&pring->txcmplq, &txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3551 | |
| 3552 | /* Indicate the I/O queues are flushed */ |
| 3553 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3554 | spin_unlock_irq(&phba->hbalock); |
| 3555 | |
| 3556 | /* Flush the txq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3557 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3558 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3559 | |
| 3560 | /* Flush the txcmpq */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3561 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3562 | IOERR_SLI_DOWN); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3566 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3567 | * @phba: Pointer to HBA context object. |
| 3568 | * @mask: Bit mask to be checked. |
| 3569 | * |
| 3570 | * This function reads the host status register and compares |
| 3571 | * with the provided bit mask to check if HBA completed |
| 3572 | * the restart. This function will wait in a loop for the |
| 3573 | * HBA to complete restart. If the HBA does not restart within |
| 3574 | * 15 iterations, the function will reset the HBA again. The |
| 3575 | * function returns 1 when HBA fail to restart otherwise returns |
| 3576 | * zero. |
| 3577 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3578 | static int |
| 3579 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3581 | uint32_t status; |
| 3582 | int i = 0; |
| 3583 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3585 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3586 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3587 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3589 | /* |
| 3590 | * Check status register every 100ms for 5 retries, then every |
| 3591 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3592 | * every 2.5 sec for 4. |
| 3593 | * Break our of the loop if errors occurred during init. |
| 3594 | */ |
| 3595 | while (((status & mask) != mask) && |
| 3596 | !(status & HS_FFERM) && |
| 3597 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3599 | if (i <= 5) |
| 3600 | msleep(10); |
| 3601 | else if (i <= 10) |
| 3602 | msleep(500); |
| 3603 | else |
| 3604 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3605 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3606 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3607 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3608 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3609 | lpfc_sli_brdrestart(phba); |
| 3610 | } |
| 3611 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3612 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3613 | retval = 1; |
| 3614 | break; |
| 3615 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3616 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3617 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3618 | /* Check to see if any errors occurred during init */ |
| 3619 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3620 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3621 | "2751 Adapter failed to restart, " |
| 3622 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3623 | status, |
| 3624 | readl(phba->MBslimaddr + 0xa8), |
| 3625 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3627 | retval = 1; |
| 3628 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3630 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | } |
| 3632 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3633 | /** |
| 3634 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3635 | * @phba: Pointer to HBA context object. |
| 3636 | * @mask: Bit mask to be checked. |
| 3637 | * |
| 3638 | * This function checks the host status register to check if HBA is |
| 3639 | * ready. This function will wait in a loop for the HBA to be ready |
| 3640 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3641 | * function again. The function returns 1 when HBA fail to be ready |
| 3642 | * otherwise returns zero. |
| 3643 | **/ |
| 3644 | static int |
| 3645 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3646 | { |
| 3647 | uint32_t status; |
| 3648 | int retval = 0; |
| 3649 | |
| 3650 | /* Read the HBA Host Status Register */ |
| 3651 | status = lpfc_sli4_post_status_check(phba); |
| 3652 | |
| 3653 | if (status) { |
| 3654 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3655 | lpfc_sli_brdrestart(phba); |
| 3656 | status = lpfc_sli4_post_status_check(phba); |
| 3657 | } |
| 3658 | |
| 3659 | /* Check to see if any errors occurred during init */ |
| 3660 | if (status) { |
| 3661 | phba->link_state = LPFC_HBA_ERROR; |
| 3662 | retval = 1; |
| 3663 | } else |
| 3664 | phba->sli4_hba.intr_enable = 0; |
| 3665 | |
| 3666 | return retval; |
| 3667 | } |
| 3668 | |
| 3669 | /** |
| 3670 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3671 | * @phba: Pointer to HBA context object. |
| 3672 | * @mask: Bit mask to be checked. |
| 3673 | * |
| 3674 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3675 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3676 | **/ |
| 3677 | int |
| 3678 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3679 | { |
| 3680 | return phba->lpfc_sli_brdready(phba, mask); |
| 3681 | } |
| 3682 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3683 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3684 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3685 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3686 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3687 | * @phba: Pointer to HBA context object. |
| 3688 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3689 | * This function is called before resetting an HBA. This function is called |
| 3690 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3691 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3692 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3693 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3694 | uint32_t __iomem *resp_buf; |
| 3695 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3696 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3697 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3698 | int i; |
| 3699 | uint8_t hdrtype; |
| 3700 | |
| 3701 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 3702 | if (hdrtype != 0x80 || |
| 3703 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 3704 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 3705 | return; |
| 3706 | |
| 3707 | /* |
| 3708 | * Tell the other part of the chip to suspend temporarily all |
| 3709 | * its DMA activity. |
| 3710 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3711 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3712 | |
| 3713 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3714 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 3715 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3716 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 3717 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3718 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3719 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3720 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3721 | return; |
| 3722 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3723 | /* Clear Chip error bit */ |
| 3724 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3725 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | mbox = 0; |
| 3729 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 3730 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 3731 | |
| 3732 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3733 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3734 | writel(mbox, mbox_buf); |
| 3735 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3736 | for (i = 0; i < 50; i++) { |
| 3737 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3738 | return; |
| 3739 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 3740 | mdelay(1); |
| 3741 | else |
| 3742 | break; |
| 3743 | } |
| 3744 | resp_data = 0; |
| 3745 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 3746 | return; |
| 3747 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3748 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3750 | goto restore_hc; |
| 3751 | else |
| 3752 | goto clear_errat; |
| 3753 | } |
| 3754 | |
| 3755 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3756 | resp_data = 0; |
| 3757 | for (i = 0; i < 500; i++) { |
| 3758 | if (lpfc_readl(resp_buf, &resp_data)) |
| 3759 | return; |
| 3760 | if (resp_data != mbox) |
| 3761 | mdelay(1); |
| 3762 | else |
| 3763 | break; |
| 3764 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3765 | |
| 3766 | clear_errat: |
| 3767 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3768 | while (++i < 500) { |
| 3769 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3770 | return; |
| 3771 | if (!(ha_copy & HA_ERATT)) |
| 3772 | mdelay(1); |
| 3773 | else |
| 3774 | break; |
| 3775 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3776 | |
| 3777 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 3778 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3779 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3783 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3784 | writel(hc_copy, phba->HCregaddr); |
| 3785 | readl(phba->HCregaddr); /* flush */ |
| 3786 | } |
| 3787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3789 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3790 | * @phba: Pointer to HBA context object. |
| 3791 | * |
| 3792 | * This function issues a kill_board mailbox command and waits for |
| 3793 | * the error attention interrupt. This function is called for stopping |
| 3794 | * the firmware processing. The caller is not required to hold any |
| 3795 | * locks. This function calls lpfc_hba_down_post function to free |
| 3796 | * any pending commands after the kill. The function will return 1 when it |
| 3797 | * fails to kill the board else will return 0. |
| 3798 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3799 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3800 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3802 | struct lpfc_sli *psli; |
| 3803 | LPFC_MBOXQ_t *pmb; |
| 3804 | uint32_t status; |
| 3805 | uint32_t ha_copy; |
| 3806 | int retval; |
| 3807 | int i = 0; |
| 3808 | |
| 3809 | psli = &phba->sli; |
| 3810 | |
| 3811 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3812 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3813 | "0329 Kill HBA Data: x%x x%x\n", |
| 3814 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3815 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3816 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3817 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3818 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3819 | |
| 3820 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3821 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3822 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 3823 | spin_unlock_irq(&phba->hbalock); |
| 3824 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3825 | return 1; |
| 3826 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3827 | status &= ~HC_ERINT_ENA; |
| 3828 | writel(status, phba->HCregaddr); |
| 3829 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3830 | phba->link_flag |= LS_IGNORE_ERATT; |
| 3831 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3832 | |
| 3833 | lpfc_kill_board(phba, pmb); |
| 3834 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 3835 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3836 | |
| 3837 | if (retval != MBX_SUCCESS) { |
| 3838 | if (retval != MBX_BUSY) |
| 3839 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3840 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3841 | "2752 KILL_BOARD command failed retval %d\n", |
| 3842 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3843 | spin_lock_irq(&phba->hbalock); |
| 3844 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3845 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3846 | return 1; |
| 3847 | } |
| 3848 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3849 | spin_lock_irq(&phba->hbalock); |
| 3850 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 3851 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3852 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3853 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3854 | |
| 3855 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 3856 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 3857 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 3858 | * board is now undefined. |
| 3859 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3860 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3861 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3862 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 3863 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3864 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 3865 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3869 | if (ha_copy & HA_ERATT) { |
| 3870 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3872 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3873 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3874 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3875 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 3877 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3878 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3879 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3880 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3881 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3883 | } |
| 3884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3885 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3886 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3887 | * @phba: Pointer to HBA context object. |
| 3888 | * |
| 3889 | * This function resets the HBA by writing HC_INITFF to the control |
| 3890 | * register. After the HBA resets, this function resets all the iocb ring |
| 3891 | * indices. This function disables PCI layer parity checking during |
| 3892 | * the reset. |
| 3893 | * This function returns 0 always. |
| 3894 | * The caller is not required to hold any locks. |
| 3895 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3896 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3897 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3898 | { |
| 3899 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3900 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3901 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3904 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3906 | /* Reset HBA */ |
| 3907 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3908 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3909 | phba->pport->port_state, psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3910 | |
| 3911 | /* perform board reset */ |
| 3912 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3913 | phba->link_events = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3914 | phba->pport->fc_myDID = 0; |
| 3915 | phba->pport->fc_prevDID = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3917 | /* Turn off parity checking and serr during the physical reset */ |
| 3918 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3919 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 3920 | (cfg_value & |
| 3921 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3922 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3923 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 3924 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3925 | /* Now toggle INITFF bit in the Host Control Register */ |
| 3926 | writel(HC_INITFF, phba->HCregaddr); |
| 3927 | mdelay(1); |
| 3928 | readl(phba->HCregaddr); /* flush */ |
| 3929 | writel(0, phba->HCregaddr); |
| 3930 | readl(phba->HCregaddr); /* flush */ |
| 3931 | |
| 3932 | /* Restore PCI cmd register */ |
| 3933 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | |
| 3935 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3936 | for (i = 0; i < psli->num_rings; i++) { |
| 3937 | pring = &psli->ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3939 | pring->sli.sli3.rspidx = 0; |
| 3940 | pring->sli.sli3.next_cmdidx = 0; |
| 3941 | pring->sli.sli3.local_getidx = 0; |
| 3942 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | pring->missbufcnt = 0; |
| 3944 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3945 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3946 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3947 | return 0; |
| 3948 | } |
| 3949 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3950 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3951 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 3952 | * @phba: Pointer to HBA context object. |
| 3953 | * |
| 3954 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 3955 | * checking during resets the device. The caller is not required to hold |
| 3956 | * any locks. |
| 3957 | * |
| 3958 | * This function returns 0 always. |
| 3959 | **/ |
| 3960 | int |
| 3961 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 3962 | { |
| 3963 | struct lpfc_sli *psli = &phba->sli; |
| 3964 | uint16_t cfg_value; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3965 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3966 | |
| 3967 | /* Reset HBA */ |
| 3968 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3969 | "0295 Reset HBA Data: x%x x%x\n", |
| 3970 | phba->pport->port_state, psli->sli_flag); |
| 3971 | |
| 3972 | /* perform board reset */ |
| 3973 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3974 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3975 | phba->pport->fc_myDID = 0; |
| 3976 | phba->pport->fc_prevDID = 0; |
| 3977 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3978 | spin_lock_irq(&phba->hbalock); |
| 3979 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 3980 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3981 | spin_unlock_irq(&phba->hbalock); |
| 3982 | |
| 3983 | /* Now physically reset the device */ |
| 3984 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3985 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3986 | |
| 3987 | /* Turn off parity checking and serr during the physical reset */ |
| 3988 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 3989 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 3990 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 3991 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3992 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3993 | rc = lpfc_pci_function_reset(phba); |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 3994 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3995 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 3996 | /* Restore PCI cmd register */ |
| 3997 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 3998 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 3999 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | /** |
| 4003 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4004 | * @phba: Pointer to HBA context object. |
| 4005 | * |
| 4006 | * This function is called in the SLI initialization code path to |
| 4007 | * restart the HBA. The caller is not required to hold any lock. |
| 4008 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4009 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4010 | * function to free any pending commands. The function enables |
| 4011 | * POST only during the first initialization. The function returns zero. |
| 4012 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4013 | * command before the return of this function. |
| 4014 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4015 | static int |
| 4016 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4017 | { |
| 4018 | MAILBOX_t *mb; |
| 4019 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4020 | volatile uint32_t word0; |
| 4021 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4022 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4023 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4025 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4026 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4027 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4028 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4029 | psli = &phba->sli; |
| 4030 | |
| 4031 | /* Restart HBA */ |
| 4032 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4033 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4034 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4035 | |
| 4036 | word0 = 0; |
| 4037 | mb = (MAILBOX_t *) &word0; |
| 4038 | mb->mbxCommand = MBX_RESTART; |
| 4039 | mb->mbxHc = 1; |
| 4040 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4041 | lpfc_reset_barrier(phba); |
| 4042 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4043 | to_slim = phba->MBslimaddr; |
| 4044 | writel(*(uint32_t *) mb, to_slim); |
| 4045 | readl(to_slim); /* flush */ |
| 4046 | |
| 4047 | /* Only skip post after fc_ffinit is completed */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4048 | if (phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4049 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4050 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4051 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4052 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4053 | writel(*(uint32_t *) mb, to_slim); |
| 4054 | readl(to_slim); /* flush */ |
| 4055 | |
| 4056 | lpfc_sli_brdreset(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | phba->pport->stopped = 0; |
| 4058 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4059 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4060 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4061 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4062 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4063 | psli->stats_start = get_seconds(); |
| 4064 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4065 | /* Give the INITFF and Post time to settle. */ |
| 4066 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4068 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4069 | if (hba_aer_enabled) |
| 4070 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4071 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4072 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4077 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4078 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4079 | * @phba: Pointer to HBA context object. |
| 4080 | * |
| 4081 | * This function is called in the SLI initialization code path to restart |
| 4082 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4083 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4084 | * free any pending commands. |
| 4085 | **/ |
| 4086 | static int |
| 4087 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4088 | { |
| 4089 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4090 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4091 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4092 | |
| 4093 | /* Restart HBA */ |
| 4094 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4095 | "0296 Restart HBA Data: x%x x%x\n", |
| 4096 | phba->pport->port_state, psli->sli_flag); |
| 4097 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4098 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4099 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4100 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4101 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4102 | |
| 4103 | spin_lock_irq(&phba->hbalock); |
| 4104 | phba->pport->stopped = 0; |
| 4105 | phba->link_state = LPFC_INIT_START; |
| 4106 | phba->hba_flag = 0; |
| 4107 | spin_unlock_irq(&phba->hbalock); |
| 4108 | |
| 4109 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4110 | psli->stats_start = get_seconds(); |
| 4111 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4112 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4113 | if (hba_aer_enabled) |
| 4114 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4115 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4116 | lpfc_hba_down_post(phba); |
| 4117 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4118 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | /** |
| 4122 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4123 | * @phba: Pointer to HBA context object. |
| 4124 | * |
| 4125 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4126 | * API jump table function pointer from the lpfc_hba struct. |
| 4127 | **/ |
| 4128 | int |
| 4129 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4130 | { |
| 4131 | return phba->lpfc_sli_brdrestart(phba); |
| 4132 | } |
| 4133 | |
| 4134 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4135 | * 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] | 4136 | * @phba: Pointer to HBA context object. |
| 4137 | * |
| 4138 | * This function is called after a HBA restart to wait for successful |
| 4139 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4140 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4141 | * iteration, the function will restart the HBA again. The function returns |
| 4142 | * zero if HBA successfully restarted else returns negative error code. |
| 4143 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4144 | static int |
| 4145 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4146 | { |
| 4147 | uint32_t status, i = 0; |
| 4148 | |
| 4149 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4150 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4151 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | |
| 4153 | /* Check status register to see what current state is */ |
| 4154 | i = 0; |
| 4155 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4156 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4157 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4158 | * retries, then every 1 sec for 50 retires for a total of |
| 4159 | * ~60 seconds before reset the board again and check every |
| 4160 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4161 | * board ready is required by the Falcon FIPS zeroization |
| 4162 | * complete, and any reset the board in between shall cause |
| 4163 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4165 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | /* Adapter failed to init, timeout, status reg |
| 4167 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4168 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4169 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4170 | "timeout, status reg x%x, " |
| 4171 | "FW Data: A8 x%x AC x%x\n", status, |
| 4172 | readl(phba->MBslimaddr + 0xa8), |
| 4173 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4175 | return -ETIMEDOUT; |
| 4176 | } |
| 4177 | |
| 4178 | /* Check to see if any errors occurred during init */ |
| 4179 | if (status & HS_FFERM) { |
| 4180 | /* ERROR: During chipset initialization */ |
| 4181 | /* Adapter failed to init, chipset, status reg |
| 4182 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4184 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4185 | "chipset, status reg x%x, " |
| 4186 | "FW Data: A8 x%x AC x%x\n", status, |
| 4187 | readl(phba->MBslimaddr + 0xa8), |
| 4188 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4189 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4190 | return -EIO; |
| 4191 | } |
| 4192 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4193 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4194 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4195 | else if (i <= 100) |
| 4196 | msleep(100); |
| 4197 | else |
| 4198 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4200 | if (i == 150) { |
| 4201 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4202 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4203 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4204 | } |
| 4205 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4206 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4207 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /* Check to see if any errors occurred during init */ |
| 4211 | if (status & HS_FFERM) { |
| 4212 | /* ERROR: During chipset initialization */ |
| 4213 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4215 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4216 | "status reg x%x, " |
| 4217 | "FW Data: A8 x%x AC x%x\n", status, |
| 4218 | readl(phba->MBslimaddr + 0xa8), |
| 4219 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4220 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | return -EIO; |
| 4222 | } |
| 4223 | |
| 4224 | /* Clear all interrupt enable conditions */ |
| 4225 | writel(0, phba->HCregaddr); |
| 4226 | readl(phba->HCregaddr); /* flush */ |
| 4227 | |
| 4228 | /* setup host attn register */ |
| 4229 | writel(0xffffffff, phba->HAregaddr); |
| 4230 | readl(phba->HAregaddr); /* flush */ |
| 4231 | return 0; |
| 4232 | } |
| 4233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4234 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4235 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4236 | * |
| 4237 | * This function calculates and returns the number of HBQs required to be |
| 4238 | * configured. |
| 4239 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4240 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4241 | lpfc_sli_hbq_count(void) |
| 4242 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4243 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4244 | } |
| 4245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4247 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4248 | * |
| 4249 | * This function adds the number of hbq entries in every HBQ to get |
| 4250 | * the total number of hbq entries required for the HBA and returns |
| 4251 | * the total count. |
| 4252 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4253 | static int |
| 4254 | lpfc_sli_hbq_entry_count(void) |
| 4255 | { |
| 4256 | int hbq_count = lpfc_sli_hbq_count(); |
| 4257 | int count = 0; |
| 4258 | int i; |
| 4259 | |
| 4260 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4261 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4262 | return count; |
| 4263 | } |
| 4264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4266 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4267 | * |
| 4268 | * This function calculates amount of memory required for all hbq entries |
| 4269 | * to be configured and returns the total memory required. |
| 4270 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4272 | lpfc_sli_hbq_size(void) |
| 4273 | { |
| 4274 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4275 | } |
| 4276 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4277 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4278 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4279 | * @phba: Pointer to HBA context object. |
| 4280 | * |
| 4281 | * This function is called during the SLI initialization to configure |
| 4282 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4283 | * required to hold any locks. This function will return zero if successful |
| 4284 | * else it will return negative error code. |
| 4285 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4286 | static int |
| 4287 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4288 | { |
| 4289 | int hbq_count = lpfc_sli_hbq_count(); |
| 4290 | LPFC_MBOXQ_t *pmb; |
| 4291 | MAILBOX_t *pmbox; |
| 4292 | uint32_t hbqno; |
| 4293 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4294 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4295 | /* Get a Mailbox buffer to setup mailbox |
| 4296 | * commands for HBA initialization |
| 4297 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4298 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4299 | |
| 4300 | if (!pmb) |
| 4301 | return -ENOMEM; |
| 4302 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4303 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4304 | |
| 4305 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4306 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4307 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4308 | |
| 4309 | hbq_entry_index = 0; |
| 4310 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4311 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4312 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4313 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4314 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4315 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4316 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4317 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4318 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4319 | |
| 4320 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4321 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4322 | mbxStatus <status>, ring <num> */ |
| 4323 | |
| 4324 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4325 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4326 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4327 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4328 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4329 | pmbox->mbxStatus, hbqno); |
| 4330 | |
| 4331 | phba->link_state = LPFC_HBA_ERROR; |
| 4332 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4333 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | phba->hbq_count = hbq_count; |
| 4337 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4338 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4340 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4341 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4342 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4343 | return 0; |
| 4344 | } |
| 4345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4346 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4347 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4348 | * @phba: Pointer to HBA context object. |
| 4349 | * |
| 4350 | * This function is called during the SLI initialization to configure |
| 4351 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4352 | * required to hold any locks. This function will return zero if successful |
| 4353 | * else it will return negative error code. |
| 4354 | **/ |
| 4355 | static int |
| 4356 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4357 | { |
| 4358 | phba->hbq_in_use = 1; |
| 4359 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; |
| 4360 | phba->hbq_count = 1; |
| 4361 | /* Initially populate or replenish the HBQs */ |
| 4362 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); |
| 4363 | return 0; |
| 4364 | } |
| 4365 | |
| 4366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4367 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | * @phba: Pointer to HBA context object. |
| 4369 | * @sli_mode: sli mode - 2/3 |
| 4370 | * |
| 4371 | * This function is called by the sli intialization code path |
| 4372 | * to issue config_port mailbox command. This function restarts the |
| 4373 | * HBA firmware and issues a config_port mailbox command to configure |
| 4374 | * the SLI interface in the sli mode specified by sli_mode |
| 4375 | * variable. The caller is not required to hold any locks. |
| 4376 | * The function returns 0 if successful, else returns negative error |
| 4377 | * code. |
| 4378 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4379 | int |
| 4380 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4381 | { |
| 4382 | LPFC_MBOXQ_t *pmb; |
| 4383 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4384 | |
| 4385 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4386 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4388 | return -ENOMEM; |
| 4389 | } |
| 4390 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4391 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4393 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4394 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4395 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4396 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4397 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4398 | rc = lpfc_sli_chipset_init(phba); |
| 4399 | if (rc) |
| 4400 | break; |
| 4401 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4402 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4403 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4404 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4405 | resetcount++; |
| 4406 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4407 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4408 | * value of 0 means the call was successful. Any other |
| 4409 | * nonzero value is a failure, but if ERESTART is returned, |
| 4410 | * the driver may reset the HBA and try again. |
| 4411 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4412 | rc = lpfc_config_port_prep(phba); |
| 4413 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4414 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4416 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4417 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4418 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4420 | lpfc_config_port(phba, pmb); |
| 4421 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4422 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4423 | LPFC_SLI3_HBQ_ENABLED | |
| 4424 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4425 | LPFC_SLI3_BG_ENABLED | |
| 4426 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4427 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4429 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4430 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4431 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4432 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4433 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4434 | spin_unlock_irq(&phba->hbalock); |
| 4435 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4436 | } else { |
| 4437 | /* Allow asynchronous mailbox command to go through */ |
| 4438 | spin_lock_irq(&phba->hbalock); |
| 4439 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4440 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4441 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4442 | |
| 4443 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4444 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4445 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4446 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4447 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4449 | if (!done) { |
| 4450 | rc = -EINVAL; |
| 4451 | goto do_prep_failed; |
| 4452 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4453 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4454 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4455 | rc = -ENXIO; |
| 4456 | goto do_prep_failed; |
| 4457 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4458 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4459 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4460 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4461 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4462 | phba->max_vpi : phba->max_vports; |
| 4463 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4464 | } else |
| 4465 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4466 | phba->fips_level = 0; |
| 4467 | phba->fips_spec_rev = 0; |
| 4468 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4469 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4470 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4471 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4472 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4473 | "2850 Security Crypto Active. FIPS x%d " |
| 4474 | "(Spec Rev: x%d)", |
| 4475 | phba->fips_level, phba->fips_spec_rev); |
| 4476 | } |
| 4477 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4479 | "2856 Config Port Security Crypto " |
| 4480 | "Error: x%x ", |
| 4481 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4482 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4483 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4484 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4485 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4486 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4487 | |
| 4488 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4489 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4490 | |
| 4491 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4492 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4493 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4494 | else |
| 4495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4496 | "0443 Adapter did not grant " |
| 4497 | "BlockGuard\n"); |
| 4498 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4499 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4500 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4501 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4502 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4503 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4504 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4505 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4506 | return rc; |
| 4507 | } |
| 4508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4509 | |
| 4510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4511 | * lpfc_sli_hba_setup - SLI intialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4512 | * @phba: Pointer to HBA context object. |
| 4513 | * |
| 4514 | * This function is the main SLI intialization function. This function |
| 4515 | * is called by the HBA intialization code, HBA reset code and HBA |
| 4516 | * error attention handler code. Caller is not required to hold any |
| 4517 | * locks. This function issues config_port mailbox command to configure |
| 4518 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4519 | * calls the config_port_post function to issue init_link mailbox |
| 4520 | * command and to start the discovery. The function will return zero |
| 4521 | * if successful, else it will return negative error code. |
| 4522 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4523 | int |
| 4524 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4525 | { |
| 4526 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4527 | int mode = 3, i; |
| 4528 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4529 | |
| 4530 | switch (lpfc_sli_mode) { |
| 4531 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4532 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4534 | "1824 NPIV enabled: Override lpfc_sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4535 | "parameter (%d) to auto (0).\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4536 | lpfc_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | break; |
| 4538 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4539 | mode = 2; |
| 4540 | break; |
| 4541 | case 0: |
| 4542 | case 3: |
| 4543 | break; |
| 4544 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4545 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4546 | "1819 Unrecognized lpfc_sli_mode " |
| 4547 | "parameter: %d.\n", lpfc_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4548 | |
| 4549 | break; |
| 4550 | } |
| 4551 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4552 | rc = lpfc_sli_config_port(phba, mode); |
| 4553 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4554 | if (rc && lpfc_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4556 | "1820 Unable to select SLI-3. " |
| 4557 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4558 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4559 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4560 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4561 | goto lpfc_sli_hba_setup_error; |
| 4562 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4563 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4564 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4565 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4566 | if (!rc) { |
| 4567 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4568 | "2709 This device supports " |
| 4569 | "Advanced Error Reporting (AER)\n"); |
| 4570 | spin_lock_irq(&phba->hbalock); |
| 4571 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4572 | spin_unlock_irq(&phba->hbalock); |
| 4573 | } else { |
| 4574 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4575 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4576 | "Advanced Error Reporting (AER): %d\n", |
| 4577 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4578 | phba->cfg_aer_support = 0; |
| 4579 | } |
| 4580 | } |
| 4581 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4582 | if (phba->sli_rev == 3) { |
| 4583 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4584 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4585 | } else { |
| 4586 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4587 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4588 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4592 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4593 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4594 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | |
| 4596 | if (rc) |
| 4597 | goto lpfc_sli_hba_setup_error; |
| 4598 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4599 | /* Initialize VPIs. */ |
| 4600 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4601 | /* |
| 4602 | * The VPI bitmask and physical ID array are allocated |
| 4603 | * and initialized once only - at driver load. A port |
| 4604 | * reset doesn't need to reinitialize this memory. |
| 4605 | */ |
| 4606 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4607 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4608 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4609 | GFP_KERNEL); |
| 4610 | if (!phba->vpi_bmask) { |
| 4611 | rc = -ENOMEM; |
| 4612 | goto lpfc_sli_hba_setup_error; |
| 4613 | } |
| 4614 | |
| 4615 | phba->vpi_ids = kzalloc( |
| 4616 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4617 | GFP_KERNEL); |
| 4618 | if (!phba->vpi_ids) { |
| 4619 | kfree(phba->vpi_bmask); |
| 4620 | rc = -ENOMEM; |
| 4621 | goto lpfc_sli_hba_setup_error; |
| 4622 | } |
| 4623 | for (i = 0; i < phba->max_vpi; i++) |
| 4624 | phba->vpi_ids[i] = i; |
| 4625 | } |
| 4626 | } |
| 4627 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4628 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4629 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4630 | rc = lpfc_sli_hbq_setup(phba); |
| 4631 | if (rc) |
| 4632 | goto lpfc_sli_hba_setup_error; |
| 4633 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4634 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4636 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4637 | |
| 4638 | rc = lpfc_config_port_post(phba); |
| 4639 | if (rc) |
| 4640 | goto lpfc_sli_hba_setup_error; |
| 4641 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4642 | return rc; |
| 4643 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4644 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4645 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4646 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4647 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4648 | return rc; |
| 4649 | } |
| 4650 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4651 | /** |
| 4652 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4653 | * @phba: Pointer to HBA context object. |
| 4654 | * @mboxq: mailbox pointer. |
| 4655 | * This function issue a dump mailbox command to read config region |
| 4656 | * 23 and parse the records in the region and populate driver |
| 4657 | * data structure. |
| 4658 | **/ |
| 4659 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4660 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4661 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4662 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4663 | struct lpfc_dmabuf *mp; |
| 4664 | struct lpfc_mqe *mqe; |
| 4665 | uint32_t data_length; |
| 4666 | int rc; |
| 4667 | |
| 4668 | /* Program the default value of vlan_id and fc_map */ |
| 4669 | phba->valid_vlan = 0; |
| 4670 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4671 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4672 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4673 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4674 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4675 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4676 | return -ENOMEM; |
| 4677 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4678 | mqe = &mboxq->u.mqe; |
| 4679 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4680 | rc = -ENOMEM; |
| 4681 | goto out_free_mboxq; |
| 4682 | } |
| 4683 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4684 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 4685 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4686 | |
| 4687 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 4688 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 4689 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4690 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 4691 | "CQ: x%x x%x x%x x%x\n", |
| 4692 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 4693 | bf_get(lpfc_mqe_command, mqe), |
| 4694 | bf_get(lpfc_mqe_status, mqe), |
| 4695 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 4696 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 4697 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 4698 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 4699 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 4700 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 4701 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 4702 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 4703 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 4704 | mboxq->mcqe.word0, |
| 4705 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 4706 | mboxq->mcqe.trailer); |
| 4707 | |
| 4708 | if (rc) { |
| 4709 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4710 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4711 | rc = -EIO; |
| 4712 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4713 | } |
| 4714 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 4715 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4716 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4717 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4718 | rc = -EIO; |
| 4719 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4720 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4721 | |
| 4722 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 4723 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 4724 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4725 | rc = 0; |
| 4726 | |
| 4727 | out_free_mboxq: |
| 4728 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4729 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 4734 | * @phba: pointer to lpfc hba data structure. |
| 4735 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 4736 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 4737 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 4738 | * On output, the number of data bytes in @vpd. |
| 4739 | * |
| 4740 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 4741 | * addition, this routine gets the port vpd data. |
| 4742 | * |
| 4743 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4744 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 4745 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4746 | **/ |
| 4747 | static int |
| 4748 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 4749 | uint8_t *vpd, uint32_t *vpd_size) |
| 4750 | { |
| 4751 | int rc = 0; |
| 4752 | uint32_t dma_size; |
| 4753 | struct lpfc_dmabuf *dmabuf; |
| 4754 | struct lpfc_mqe *mqe; |
| 4755 | |
| 4756 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4757 | if (!dmabuf) |
| 4758 | return -ENOMEM; |
| 4759 | |
| 4760 | /* |
| 4761 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 4762 | * mailbox command. |
| 4763 | */ |
| 4764 | dma_size = *vpd_size; |
| 4765 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 4766 | dma_size, |
| 4767 | &dmabuf->phys, |
| 4768 | GFP_KERNEL); |
| 4769 | if (!dmabuf->virt) { |
| 4770 | kfree(dmabuf); |
| 4771 | return -ENOMEM; |
| 4772 | } |
| 4773 | memset(dmabuf->virt, 0, dma_size); |
| 4774 | |
| 4775 | /* |
| 4776 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 4777 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 4778 | * in SLI3. This code corrects the conflicts. |
| 4779 | */ |
| 4780 | lpfc_read_rev(phba, mboxq); |
| 4781 | mqe = &mboxq->u.mqe; |
| 4782 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 4783 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 4784 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 4785 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 4786 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 4787 | |
| 4788 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4789 | if (rc) { |
| 4790 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4791 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 4792 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4793 | return -EIO; |
| 4794 | } |
| 4795 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4796 | /* |
| 4797 | * The available vpd length cannot be bigger than the |
| 4798 | * DMA buffer passed to the port. Catch the less than |
| 4799 | * case and update the caller's size. |
| 4800 | */ |
| 4801 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 4802 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 4803 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 4804 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 4805 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4806 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 4807 | dmabuf->virt, dmabuf->phys); |
| 4808 | kfree(dmabuf); |
| 4809 | return 0; |
| 4810 | } |
| 4811 | |
| 4812 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4813 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 4814 | * @phba: pointer to lpfc hba data structure. |
| 4815 | * |
| 4816 | * This routine retrieves SLI4 device physical port name this PCI function |
| 4817 | * is attached to. |
| 4818 | * |
| 4819 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 4820 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4821 | * otherwise - failed to retrieve physical port name |
| 4822 | **/ |
| 4823 | static int |
| 4824 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 4825 | { |
| 4826 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4827 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 4828 | struct lpfc_controller_attribute *cntl_attr; |
| 4829 | struct lpfc_mbx_get_port_name *get_port_name; |
| 4830 | void *virtaddr = NULL; |
| 4831 | uint32_t alloclen, reqlen; |
| 4832 | uint32_t shdr_status, shdr_add_status; |
| 4833 | union lpfc_sli4_cfg_shdr *shdr; |
| 4834 | char cport_name = 0; |
| 4835 | int rc; |
| 4836 | |
| 4837 | /* We assume nothing at this point */ |
| 4838 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4839 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 4840 | |
| 4841 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4842 | if (!mboxq) |
| 4843 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4844 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4845 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 4846 | lpfc_sli4_read_config(phba); |
| 4847 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 4848 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 4849 | |
| 4850 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 4851 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 4852 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4853 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 4854 | LPFC_SLI4_MBX_NEMBED); |
| 4855 | if (alloclen < reqlen) { |
| 4856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4857 | "3084 Allocated DMA memory size (%d) is " |
| 4858 | "less than the requested DMA memory size " |
| 4859 | "(%d)\n", alloclen, reqlen); |
| 4860 | rc = -ENOMEM; |
| 4861 | goto out_free_mboxq; |
| 4862 | } |
| 4863 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4864 | virtaddr = mboxq->sge_array->addr[0]; |
| 4865 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 4866 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 4867 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4868 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4869 | if (shdr_status || shdr_add_status || rc) { |
| 4870 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4871 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 4872 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4873 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4874 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4875 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4876 | rc, shdr_status, shdr_add_status); |
| 4877 | rc = -ENXIO; |
| 4878 | goto out_free_mboxq; |
| 4879 | } |
| 4880 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 4881 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 4882 | phba->sli4_hba.lnk_info.lnk_tp = |
| 4883 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 4884 | phba->sli4_hba.lnk_info.lnk_no = |
| 4885 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 4886 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4887 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 4888 | phba->sli4_hba.lnk_info.lnk_tp, |
| 4889 | phba->sli4_hba.lnk_info.lnk_no); |
| 4890 | |
| 4891 | retrieve_ppname: |
| 4892 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 4893 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 4894 | sizeof(struct lpfc_mbx_get_port_name) - |
| 4895 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 4896 | LPFC_SLI4_MBX_EMBED); |
| 4897 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 4898 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 4899 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 4900 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 4901 | phba->sli4_hba.lnk_info.lnk_tp); |
| 4902 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4903 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 4904 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 4905 | if (shdr_status || shdr_add_status || rc) { |
| 4906 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4907 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 4908 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 4909 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4910 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 4911 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 4912 | rc, shdr_status, shdr_add_status); |
| 4913 | rc = -ENXIO; |
| 4914 | goto out_free_mboxq; |
| 4915 | } |
| 4916 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4917 | case LPFC_LINK_NUMBER_0: |
| 4918 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 4919 | &get_port_name->u.response); |
| 4920 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4921 | break; |
| 4922 | case LPFC_LINK_NUMBER_1: |
| 4923 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 4924 | &get_port_name->u.response); |
| 4925 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4926 | break; |
| 4927 | case LPFC_LINK_NUMBER_2: |
| 4928 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 4929 | &get_port_name->u.response); |
| 4930 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4931 | break; |
| 4932 | case LPFC_LINK_NUMBER_3: |
| 4933 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 4934 | &get_port_name->u.response); |
| 4935 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 4936 | break; |
| 4937 | default: |
| 4938 | break; |
| 4939 | } |
| 4940 | |
| 4941 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 4942 | phba->Port[0] = cport_name; |
| 4943 | phba->Port[1] = '\0'; |
| 4944 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4945 | "3091 SLI get port name: %s\n", phba->Port); |
| 4946 | } |
| 4947 | |
| 4948 | out_free_mboxq: |
| 4949 | if (rc != MBX_TIMEOUT) { |
| 4950 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 4951 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 4952 | else |
| 4953 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4954 | } |
| 4955 | return rc; |
| 4956 | } |
| 4957 | |
| 4958 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4959 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 4960 | * @phba: pointer to lpfc hba data structure. |
| 4961 | * |
| 4962 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 4963 | * event queues |
| 4964 | **/ |
| 4965 | static void |
| 4966 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 4967 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 4968 | int fcp_eqidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4969 | |
| 4970 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 4971 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4972 | fcp_eqidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4973 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4974 | do { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4975 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
| 4976 | LPFC_QUEUE_REARM); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4977 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4978 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 4979 | |
| 4980 | if (phba->cfg_EnableXLane) |
| 4981 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 4982 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4983 | if (phba->sli4_hba.hba_eq) { |
| 4984 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4985 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4986 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4987 | LPFC_QUEUE_REARM); |
| 4988 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 4989 | |
| 4990 | if (phba->cfg_fof) |
| 4991 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4995 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4996 | * @phba: Pointer to HBA context object. |
| 4997 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4998 | * @extnt_count: buffer to hold port available extent count. |
| 4999 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5000 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5001 | * This function calls the port and retrievs the number of available |
| 5002 | * extents and their size for a particular extent type. |
| 5003 | * |
| 5004 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5005 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5006 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5007 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5008 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5009 | { |
| 5010 | int rc = 0; |
| 5011 | uint32_t length; |
| 5012 | uint32_t mbox_tmo; |
| 5013 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5014 | LPFC_MBOXQ_t *mbox; |
| 5015 | |
| 5016 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5017 | if (!mbox) |
| 5018 | return -ENOMEM; |
| 5019 | |
| 5020 | /* Find out how many extents are available for this resource type */ |
| 5021 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5022 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5023 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5024 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5025 | length, LPFC_SLI4_MBX_EMBED); |
| 5026 | |
| 5027 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5028 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5029 | LPFC_SLI4_MBX_EMBED); |
| 5030 | if (unlikely(rc)) { |
| 5031 | rc = -EIO; |
| 5032 | goto err_exit; |
| 5033 | } |
| 5034 | |
| 5035 | if (!phba->sli4_hba.intr_enable) |
| 5036 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5037 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5038 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5039 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5040 | } |
| 5041 | if (unlikely(rc)) { |
| 5042 | rc = -EIO; |
| 5043 | goto err_exit; |
| 5044 | } |
| 5045 | |
| 5046 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5047 | if (bf_get(lpfc_mbox_hdr_status, |
| 5048 | &rsrc_info->header.cfg_shdr.response)) { |
| 5049 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5050 | "2930 Failed to get resource extents " |
| 5051 | "Status 0x%x Add'l Status 0x%x\n", |
| 5052 | bf_get(lpfc_mbox_hdr_status, |
| 5053 | &rsrc_info->header.cfg_shdr.response), |
| 5054 | bf_get(lpfc_mbox_hdr_add_status, |
| 5055 | &rsrc_info->header.cfg_shdr.response)); |
| 5056 | rc = -EIO; |
| 5057 | goto err_exit; |
| 5058 | } |
| 5059 | |
| 5060 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5061 | &rsrc_info->u.rsp); |
| 5062 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5063 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5064 | |
| 5065 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5066 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5067 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5068 | |
| 5069 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5070 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5071 | return rc; |
| 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5076 | * @phba: Pointer to HBA context object. |
| 5077 | * @type: The extent type to check. |
| 5078 | * |
| 5079 | * This function reads the current available extents from the port and checks |
| 5080 | * if the extent count or extent size has changed since the last access. |
| 5081 | * Callers use this routine post port reset to understand if there is a |
| 5082 | * extent reprovisioning requirement. |
| 5083 | * |
| 5084 | * Returns: |
| 5085 | * -Error: error indicates problem. |
| 5086 | * 1: Extent count or size has changed. |
| 5087 | * 0: No changes. |
| 5088 | **/ |
| 5089 | static int |
| 5090 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5091 | { |
| 5092 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5093 | uint16_t size_diff, rsrc_ext_size; |
| 5094 | int rc = 0; |
| 5095 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5096 | struct list_head *rsrc_blk_list = NULL; |
| 5097 | |
| 5098 | size_diff = 0; |
| 5099 | curr_ext_cnt = 0; |
| 5100 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5101 | &rsrc_ext_cnt, |
| 5102 | &rsrc_ext_size); |
| 5103 | if (unlikely(rc)) |
| 5104 | return -EIO; |
| 5105 | |
| 5106 | switch (type) { |
| 5107 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5108 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5109 | break; |
| 5110 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5111 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5112 | break; |
| 5113 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5114 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5115 | break; |
| 5116 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5117 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5118 | break; |
| 5119 | default: |
| 5120 | break; |
| 5121 | } |
| 5122 | |
| 5123 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5124 | curr_ext_cnt++; |
| 5125 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5126 | size_diff++; |
| 5127 | } |
| 5128 | |
| 5129 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5130 | rc = 1; |
| 5131 | |
| 5132 | return rc; |
| 5133 | } |
| 5134 | |
| 5135 | /** |
| 5136 | * lpfc_sli4_cfg_post_extnts - |
| 5137 | * @phba: Pointer to HBA context object. |
| 5138 | * @extnt_cnt - number of available extents. |
| 5139 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5140 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5141 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5142 | * |
| 5143 | * This function executes the extents allocation request. It also |
| 5144 | * takes care of the amount of memory needed to allocate or get the |
| 5145 | * allocated extents. It is the caller's responsibility to evaluate |
| 5146 | * the response. |
| 5147 | * |
| 5148 | * Returns: |
| 5149 | * -Error: Error value describes the condition found. |
| 5150 | * 0: if successful |
| 5151 | **/ |
| 5152 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5153 | 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] | 5154 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5155 | { |
| 5156 | int rc = 0; |
| 5157 | uint32_t req_len; |
| 5158 | uint32_t emb_len; |
| 5159 | uint32_t alloc_len, mbox_tmo; |
| 5160 | |
| 5161 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5162 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5163 | |
| 5164 | /* |
| 5165 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5166 | * accounts for extents-specific word. |
| 5167 | */ |
| 5168 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5169 | sizeof(uint32_t); |
| 5170 | |
| 5171 | /* |
| 5172 | * Presume the allocation and response will fit into an embedded |
| 5173 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5174 | */ |
| 5175 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5176 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5177 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5178 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5179 | sizeof(uint32_t); |
| 5180 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5181 | } |
| 5182 | |
| 5183 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5184 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5185 | req_len, *emb); |
| 5186 | if (alloc_len < req_len) { |
| 5187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5188 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5189 | "less than the requested DMA memory " |
| 5190 | "size (x%x)\n", alloc_len, req_len); |
| 5191 | return -ENOMEM; |
| 5192 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5193 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5194 | if (unlikely(rc)) |
| 5195 | return -EIO; |
| 5196 | |
| 5197 | if (!phba->sli4_hba.intr_enable) |
| 5198 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5199 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5200 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5201 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5202 | } |
| 5203 | |
| 5204 | if (unlikely(rc)) |
| 5205 | rc = -EIO; |
| 5206 | return rc; |
| 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5211 | * @phba: Pointer to HBA context object. |
| 5212 | * @type: The resource extent type to allocate. |
| 5213 | * |
| 5214 | * This function allocates the number of elements for the specified |
| 5215 | * resource type. |
| 5216 | **/ |
| 5217 | static int |
| 5218 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5219 | { |
| 5220 | bool emb = false; |
| 5221 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5222 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5223 | uint16_t *ids; |
| 5224 | int i, rc; |
| 5225 | unsigned long longs; |
| 5226 | unsigned long *bmask; |
| 5227 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5228 | LPFC_MBOXQ_t *mbox; |
| 5229 | uint32_t length; |
| 5230 | struct lpfc_id_range *id_array = NULL; |
| 5231 | void *virtaddr = NULL; |
| 5232 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5233 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5234 | struct list_head *ext_blk_list; |
| 5235 | |
| 5236 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5237 | &rsrc_cnt, |
| 5238 | &rsrc_size); |
| 5239 | if (unlikely(rc)) |
| 5240 | return -EIO; |
| 5241 | |
| 5242 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5243 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5244 | "3009 No available Resource Extents " |
| 5245 | "for resource type 0x%x: Count: 0x%x, " |
| 5246 | "Size 0x%x\n", type, rsrc_cnt, |
| 5247 | rsrc_size); |
| 5248 | return -ENOMEM; |
| 5249 | } |
| 5250 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5251 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5252 | "2903 Post resource extents type-0x%x: " |
| 5253 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5254 | |
| 5255 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5256 | if (!mbox) |
| 5257 | return -ENOMEM; |
| 5258 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5259 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5260 | if (unlikely(rc)) { |
| 5261 | rc = -EIO; |
| 5262 | goto err_exit; |
| 5263 | } |
| 5264 | |
| 5265 | /* |
| 5266 | * Figure out where the response is located. Then get local pointers |
| 5267 | * to the response data. The port does not guarantee to respond to |
| 5268 | * all extents counts request so update the local variable with the |
| 5269 | * allocated count from the port. |
| 5270 | */ |
| 5271 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5272 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5273 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5274 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5275 | } else { |
| 5276 | virtaddr = mbox->sge_array->addr[0]; |
| 5277 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5278 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5279 | id_array = &n_rsrc->id; |
| 5280 | } |
| 5281 | |
| 5282 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5283 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5284 | |
| 5285 | /* |
| 5286 | * Based on the resource size and count, correct the base and max |
| 5287 | * resource values. |
| 5288 | */ |
| 5289 | length = sizeof(struct lpfc_rsrc_blks); |
| 5290 | switch (type) { |
| 5291 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5292 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5293 | sizeof(unsigned long), |
| 5294 | GFP_KERNEL); |
| 5295 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5296 | rc = -ENOMEM; |
| 5297 | goto err_exit; |
| 5298 | } |
| 5299 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5300 | sizeof(uint16_t), |
| 5301 | GFP_KERNEL); |
| 5302 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5303 | kfree(phba->sli4_hba.rpi_bmask); |
| 5304 | rc = -ENOMEM; |
| 5305 | goto err_exit; |
| 5306 | } |
| 5307 | |
| 5308 | /* |
| 5309 | * The next_rpi was initialized with the maximum available |
| 5310 | * count but the port may allocate a smaller number. Catch |
| 5311 | * that case and update the next_rpi. |
| 5312 | */ |
| 5313 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5314 | |
| 5315 | /* Initialize local ptrs for common extent processing later. */ |
| 5316 | bmask = phba->sli4_hba.rpi_bmask; |
| 5317 | ids = phba->sli4_hba.rpi_ids; |
| 5318 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5319 | break; |
| 5320 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5321 | phba->vpi_bmask = kzalloc(longs * |
| 5322 | sizeof(unsigned long), |
| 5323 | GFP_KERNEL); |
| 5324 | if (unlikely(!phba->vpi_bmask)) { |
| 5325 | rc = -ENOMEM; |
| 5326 | goto err_exit; |
| 5327 | } |
| 5328 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5329 | sizeof(uint16_t), |
| 5330 | GFP_KERNEL); |
| 5331 | if (unlikely(!phba->vpi_ids)) { |
| 5332 | kfree(phba->vpi_bmask); |
| 5333 | rc = -ENOMEM; |
| 5334 | goto err_exit; |
| 5335 | } |
| 5336 | |
| 5337 | /* Initialize local ptrs for common extent processing later. */ |
| 5338 | bmask = phba->vpi_bmask; |
| 5339 | ids = phba->vpi_ids; |
| 5340 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5341 | break; |
| 5342 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5343 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5344 | sizeof(unsigned long), |
| 5345 | GFP_KERNEL); |
| 5346 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5347 | rc = -ENOMEM; |
| 5348 | goto err_exit; |
| 5349 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5350 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5351 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5352 | sizeof(uint16_t), |
| 5353 | GFP_KERNEL); |
| 5354 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5355 | kfree(phba->sli4_hba.xri_bmask); |
| 5356 | rc = -ENOMEM; |
| 5357 | goto err_exit; |
| 5358 | } |
| 5359 | |
| 5360 | /* Initialize local ptrs for common extent processing later. */ |
| 5361 | bmask = phba->sli4_hba.xri_bmask; |
| 5362 | ids = phba->sli4_hba.xri_ids; |
| 5363 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5364 | break; |
| 5365 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5366 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5367 | sizeof(unsigned long), |
| 5368 | GFP_KERNEL); |
| 5369 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5370 | rc = -ENOMEM; |
| 5371 | goto err_exit; |
| 5372 | } |
| 5373 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5374 | sizeof(uint16_t), |
| 5375 | GFP_KERNEL); |
| 5376 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5377 | kfree(phba->sli4_hba.vfi_bmask); |
| 5378 | rc = -ENOMEM; |
| 5379 | goto err_exit; |
| 5380 | } |
| 5381 | |
| 5382 | /* Initialize local ptrs for common extent processing later. */ |
| 5383 | bmask = phba->sli4_hba.vfi_bmask; |
| 5384 | ids = phba->sli4_hba.vfi_ids; |
| 5385 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5386 | break; |
| 5387 | default: |
| 5388 | /* Unsupported Opcode. Fail call. */ |
| 5389 | id_array = NULL; |
| 5390 | bmask = NULL; |
| 5391 | ids = NULL; |
| 5392 | ext_blk_list = NULL; |
| 5393 | goto err_exit; |
| 5394 | } |
| 5395 | |
| 5396 | /* |
| 5397 | * Complete initializing the extent configuration with the |
| 5398 | * allocated ids assigned to this function. The bitmask serves |
| 5399 | * as an index into the array and manages the available ids. The |
| 5400 | * array just stores the ids communicated to the port via the wqes. |
| 5401 | */ |
| 5402 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5403 | if ((i % 2) == 0) |
| 5404 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5405 | &id_array[k]); |
| 5406 | else |
| 5407 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5408 | &id_array[k]); |
| 5409 | |
| 5410 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5411 | if (unlikely(!rsrc_blks)) { |
| 5412 | rc = -ENOMEM; |
| 5413 | kfree(bmask); |
| 5414 | kfree(ids); |
| 5415 | goto err_exit; |
| 5416 | } |
| 5417 | rsrc_blks->rsrc_start = rsrc_id; |
| 5418 | rsrc_blks->rsrc_size = rsrc_size; |
| 5419 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5420 | rsrc_start = rsrc_id; |
| 5421 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5422 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5423 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5424 | |
| 5425 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5426 | ids[j] = rsrc_id; |
| 5427 | rsrc_id++; |
| 5428 | j++; |
| 5429 | } |
| 5430 | /* Entire word processed. Get next word.*/ |
| 5431 | if ((i % 2) == 1) |
| 5432 | k++; |
| 5433 | } |
| 5434 | err_exit: |
| 5435 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5436 | return rc; |
| 5437 | } |
| 5438 | |
| 5439 | /** |
| 5440 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5441 | * @phba: Pointer to HBA context object. |
| 5442 | * @type: the extent's type. |
| 5443 | * |
| 5444 | * This function deallocates all extents of a particular resource type. |
| 5445 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5446 | * is the caller's responsibility to release all kernel memory resources. |
| 5447 | **/ |
| 5448 | static int |
| 5449 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5450 | { |
| 5451 | int rc; |
| 5452 | uint32_t length, mbox_tmo = 0; |
| 5453 | LPFC_MBOXQ_t *mbox; |
| 5454 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5455 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5456 | |
| 5457 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5458 | if (!mbox) |
| 5459 | return -ENOMEM; |
| 5460 | |
| 5461 | /* |
| 5462 | * This function sends an embedded mailbox because it only sends the |
| 5463 | * the resource type. All extents of this type are released by the |
| 5464 | * port. |
| 5465 | */ |
| 5466 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5467 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5468 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5469 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5470 | length, LPFC_SLI4_MBX_EMBED); |
| 5471 | |
| 5472 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5473 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5474 | LPFC_SLI4_MBX_EMBED); |
| 5475 | if (unlikely(rc)) { |
| 5476 | rc = -EIO; |
| 5477 | goto out_free_mbox; |
| 5478 | } |
| 5479 | if (!phba->sli4_hba.intr_enable) |
| 5480 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5481 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5482 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5483 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5484 | } |
| 5485 | if (unlikely(rc)) { |
| 5486 | rc = -EIO; |
| 5487 | goto out_free_mbox; |
| 5488 | } |
| 5489 | |
| 5490 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5491 | if (bf_get(lpfc_mbox_hdr_status, |
| 5492 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5493 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5494 | "2919 Failed to release resource extents " |
| 5495 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5496 | "Resource memory not released.\n", |
| 5497 | type, |
| 5498 | bf_get(lpfc_mbox_hdr_status, |
| 5499 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5500 | bf_get(lpfc_mbox_hdr_add_status, |
| 5501 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5502 | rc = -EIO; |
| 5503 | goto out_free_mbox; |
| 5504 | } |
| 5505 | |
| 5506 | /* Release kernel memory resources for the specific type. */ |
| 5507 | switch (type) { |
| 5508 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5509 | kfree(phba->vpi_bmask); |
| 5510 | kfree(phba->vpi_ids); |
| 5511 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5512 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5513 | &phba->lpfc_vpi_blk_list, list) { |
| 5514 | list_del_init(&rsrc_blk->list); |
| 5515 | kfree(rsrc_blk); |
| 5516 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5517 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5518 | break; |
| 5519 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5520 | kfree(phba->sli4_hba.xri_bmask); |
| 5521 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5522 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5523 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5524 | list_del_init(&rsrc_blk->list); |
| 5525 | kfree(rsrc_blk); |
| 5526 | } |
| 5527 | break; |
| 5528 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5529 | kfree(phba->sli4_hba.vfi_bmask); |
| 5530 | kfree(phba->sli4_hba.vfi_ids); |
| 5531 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5532 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5533 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5534 | list_del_init(&rsrc_blk->list); |
| 5535 | kfree(rsrc_blk); |
| 5536 | } |
| 5537 | break; |
| 5538 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5539 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5540 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5541 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5542 | list_del_init(&rsrc_blk->list); |
| 5543 | kfree(rsrc_blk); |
| 5544 | } |
| 5545 | break; |
| 5546 | default: |
| 5547 | break; |
| 5548 | } |
| 5549 | |
| 5550 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5551 | |
| 5552 | out_free_mbox: |
| 5553 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5554 | return rc; |
| 5555 | } |
| 5556 | |
| 5557 | /** |
| 5558 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5559 | * @phba: Pointer to HBA context object. |
| 5560 | * |
| 5561 | * This function allocates all SLI4 resource identifiers. |
| 5562 | **/ |
| 5563 | int |
| 5564 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5565 | { |
| 5566 | int i, rc, error = 0; |
| 5567 | uint16_t count, base; |
| 5568 | unsigned long longs; |
| 5569 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5570 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5571 | 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] | 5572 | if (phba->sli4_hba.extents_in_use) { |
| 5573 | /* |
| 5574 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5575 | * resource extent count must be read and allocated before |
| 5576 | * provisioning the resource id arrays. |
| 5577 | */ |
| 5578 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5579 | LPFC_IDX_RSRC_RDY) { |
| 5580 | /* |
| 5581 | * Extent-based resources are set - the driver could |
| 5582 | * be in a port reset. Figure out if any corrective |
| 5583 | * actions need to be taken. |
| 5584 | */ |
| 5585 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5586 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5587 | if (rc != 0) |
| 5588 | error++; |
| 5589 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5590 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5591 | if (rc != 0) |
| 5592 | error++; |
| 5593 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5594 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5595 | if (rc != 0) |
| 5596 | error++; |
| 5597 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5598 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5599 | if (rc != 0) |
| 5600 | error++; |
| 5601 | |
| 5602 | /* |
| 5603 | * It's possible that the number of resources |
| 5604 | * provided to this port instance changed between |
| 5605 | * resets. Detect this condition and reallocate |
| 5606 | * resources. Otherwise, there is no action. |
| 5607 | */ |
| 5608 | if (error) { |
| 5609 | lpfc_printf_log(phba, KERN_INFO, |
| 5610 | LOG_MBOX | LOG_INIT, |
| 5611 | "2931 Detected extent resource " |
| 5612 | "change. Reallocating all " |
| 5613 | "extents.\n"); |
| 5614 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5615 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5616 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5617 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5618 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5619 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5620 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5621 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5622 | } else |
| 5623 | return 0; |
| 5624 | } |
| 5625 | |
| 5626 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5627 | if (unlikely(rc)) |
| 5628 | goto err_exit; |
| 5629 | |
| 5630 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5631 | if (unlikely(rc)) |
| 5632 | goto err_exit; |
| 5633 | |
| 5634 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5635 | if (unlikely(rc)) |
| 5636 | goto err_exit; |
| 5637 | |
| 5638 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5639 | if (unlikely(rc)) |
| 5640 | goto err_exit; |
| 5641 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5642 | LPFC_IDX_RSRC_RDY); |
| 5643 | return rc; |
| 5644 | } else { |
| 5645 | /* |
| 5646 | * The port does not support resource extents. The XRI, VPI, |
| 5647 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5648 | * Just allocate the bitmasks and provision the resource id |
| 5649 | * arrays. If a port reset is active, the resources don't |
| 5650 | * need any action - just exit. |
| 5651 | */ |
| 5652 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5653 | LPFC_IDX_RSRC_RDY) { |
| 5654 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5655 | lpfc_sli4_remove_rpis(phba); |
| 5656 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5657 | /* RPIs. */ |
| 5658 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5659 | if (count <= 0) { |
| 5660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5661 | "3279 Invalid provisioning of " |
| 5662 | "rpi:%d\n", count); |
| 5663 | rc = -EINVAL; |
| 5664 | goto err_exit; |
| 5665 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5666 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5667 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5668 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5669 | sizeof(unsigned long), |
| 5670 | GFP_KERNEL); |
| 5671 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5672 | rc = -ENOMEM; |
| 5673 | goto err_exit; |
| 5674 | } |
| 5675 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5676 | sizeof(uint16_t), |
| 5677 | GFP_KERNEL); |
| 5678 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5679 | rc = -ENOMEM; |
| 5680 | goto free_rpi_bmask; |
| 5681 | } |
| 5682 | |
| 5683 | for (i = 0; i < count; i++) |
| 5684 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5685 | |
| 5686 | /* VPIs. */ |
| 5687 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5688 | if (count <= 0) { |
| 5689 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5690 | "3280 Invalid provisioning of " |
| 5691 | "vpi:%d\n", count); |
| 5692 | rc = -EINVAL; |
| 5693 | goto free_rpi_ids; |
| 5694 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5695 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5696 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5697 | phba->vpi_bmask = kzalloc(longs * |
| 5698 | sizeof(unsigned long), |
| 5699 | GFP_KERNEL); |
| 5700 | if (unlikely(!phba->vpi_bmask)) { |
| 5701 | rc = -ENOMEM; |
| 5702 | goto free_rpi_ids; |
| 5703 | } |
| 5704 | phba->vpi_ids = kzalloc(count * |
| 5705 | sizeof(uint16_t), |
| 5706 | GFP_KERNEL); |
| 5707 | if (unlikely(!phba->vpi_ids)) { |
| 5708 | rc = -ENOMEM; |
| 5709 | goto free_vpi_bmask; |
| 5710 | } |
| 5711 | |
| 5712 | for (i = 0; i < count; i++) |
| 5713 | phba->vpi_ids[i] = base + i; |
| 5714 | |
| 5715 | /* XRIs. */ |
| 5716 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5717 | if (count <= 0) { |
| 5718 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5719 | "3281 Invalid provisioning of " |
| 5720 | "xri:%d\n", count); |
| 5721 | rc = -EINVAL; |
| 5722 | goto free_vpi_ids; |
| 5723 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5724 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5725 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5726 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5727 | sizeof(unsigned long), |
| 5728 | GFP_KERNEL); |
| 5729 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5730 | rc = -ENOMEM; |
| 5731 | goto free_vpi_ids; |
| 5732 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5733 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5734 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5735 | sizeof(uint16_t), |
| 5736 | GFP_KERNEL); |
| 5737 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5738 | rc = -ENOMEM; |
| 5739 | goto free_xri_bmask; |
| 5740 | } |
| 5741 | |
| 5742 | for (i = 0; i < count; i++) |
| 5743 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5744 | |
| 5745 | /* VFIs. */ |
| 5746 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5747 | if (count <= 0) { |
| 5748 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5749 | "3282 Invalid provisioning of " |
| 5750 | "vfi:%d\n", count); |
| 5751 | rc = -EINVAL; |
| 5752 | goto free_xri_ids; |
| 5753 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5754 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5755 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5756 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5757 | sizeof(unsigned long), |
| 5758 | GFP_KERNEL); |
| 5759 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5760 | rc = -ENOMEM; |
| 5761 | goto free_xri_ids; |
| 5762 | } |
| 5763 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5764 | sizeof(uint16_t), |
| 5765 | GFP_KERNEL); |
| 5766 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5767 | rc = -ENOMEM; |
| 5768 | goto free_vfi_bmask; |
| 5769 | } |
| 5770 | |
| 5771 | for (i = 0; i < count; i++) |
| 5772 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5773 | |
| 5774 | /* |
| 5775 | * Mark all resources ready. An HBA reset doesn't need |
| 5776 | * to reset the initialization. |
| 5777 | */ |
| 5778 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5779 | LPFC_IDX_RSRC_RDY); |
| 5780 | return 0; |
| 5781 | } |
| 5782 | |
| 5783 | free_vfi_bmask: |
| 5784 | kfree(phba->sli4_hba.vfi_bmask); |
| 5785 | free_xri_ids: |
| 5786 | kfree(phba->sli4_hba.xri_ids); |
| 5787 | free_xri_bmask: |
| 5788 | kfree(phba->sli4_hba.xri_bmask); |
| 5789 | free_vpi_ids: |
| 5790 | kfree(phba->vpi_ids); |
| 5791 | free_vpi_bmask: |
| 5792 | kfree(phba->vpi_bmask); |
| 5793 | free_rpi_ids: |
| 5794 | kfree(phba->sli4_hba.rpi_ids); |
| 5795 | free_rpi_bmask: |
| 5796 | kfree(phba->sli4_hba.rpi_bmask); |
| 5797 | err_exit: |
| 5798 | return rc; |
| 5799 | } |
| 5800 | |
| 5801 | /** |
| 5802 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5803 | * @phba: Pointer to HBA context object. |
| 5804 | * |
| 5805 | * This function allocates the number of elements for the specified |
| 5806 | * resource type. |
| 5807 | **/ |
| 5808 | int |
| 5809 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5810 | { |
| 5811 | if (phba->sli4_hba.extents_in_use) { |
| 5812 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5813 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5814 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5815 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5816 | } else { |
| 5817 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5818 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5819 | kfree(phba->vpi_ids); |
| 5820 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5821 | kfree(phba->sli4_hba.xri_bmask); |
| 5822 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5823 | kfree(phba->sli4_hba.vfi_bmask); |
| 5824 | kfree(phba->sli4_hba.vfi_ids); |
| 5825 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5826 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5827 | } |
| 5828 | |
| 5829 | return 0; |
| 5830 | } |
| 5831 | |
| 5832 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5833 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5834 | * @phba: Pointer to HBA context object. |
| 5835 | * @type: The resource extent type. |
| 5836 | * @extnt_count: buffer to hold port extent count response |
| 5837 | * @extnt_size: buffer to hold port extent size response. |
| 5838 | * |
| 5839 | * This function calls the port to read the host allocated extents |
| 5840 | * for a particular type. |
| 5841 | **/ |
| 5842 | int |
| 5843 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5844 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5845 | { |
| 5846 | bool emb; |
| 5847 | int rc = 0; |
| 5848 | uint16_t curr_blks = 0; |
| 5849 | uint32_t req_len, emb_len; |
| 5850 | uint32_t alloc_len, mbox_tmo; |
| 5851 | struct list_head *blk_list_head; |
| 5852 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5853 | LPFC_MBOXQ_t *mbox; |
| 5854 | void *virtaddr = NULL; |
| 5855 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5856 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5857 | union lpfc_sli4_cfg_shdr *shdr; |
| 5858 | |
| 5859 | switch (type) { |
| 5860 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5861 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5862 | break; |
| 5863 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5864 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5865 | break; |
| 5866 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5867 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5868 | break; |
| 5869 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5870 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5871 | break; |
| 5872 | default: |
| 5873 | return -EIO; |
| 5874 | } |
| 5875 | |
| 5876 | /* Count the number of extents currently allocatd for this type. */ |
| 5877 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5878 | if (curr_blks == 0) { |
| 5879 | /* |
| 5880 | * The GET_ALLOCATED mailbox does not return the size, |
| 5881 | * just the count. The size should be just the size |
| 5882 | * stored in the current allocated block and all sizes |
| 5883 | * for an extent type are the same so set the return |
| 5884 | * value now. |
| 5885 | */ |
| 5886 | *extnt_size = rsrc_blk->rsrc_size; |
| 5887 | } |
| 5888 | curr_blks++; |
| 5889 | } |
| 5890 | |
| 5891 | /* Calculate the total requested length of the dma memory. */ |
| 5892 | req_len = curr_blks * sizeof(uint16_t); |
| 5893 | |
| 5894 | /* |
| 5895 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5896 | * accounts for extents-specific word. |
| 5897 | */ |
| 5898 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5899 | sizeof(uint32_t); |
| 5900 | |
| 5901 | /* |
| 5902 | * Presume the allocation and response will fit into an embedded |
| 5903 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5904 | */ |
| 5905 | emb = LPFC_SLI4_MBX_EMBED; |
| 5906 | req_len = emb_len; |
| 5907 | if (req_len > emb_len) { |
| 5908 | req_len = curr_blks * sizeof(uint16_t) + |
| 5909 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5910 | sizeof(uint32_t); |
| 5911 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5912 | } |
| 5913 | |
| 5914 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5915 | if (!mbox) |
| 5916 | return -ENOMEM; |
| 5917 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5918 | |
| 5919 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5920 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5921 | req_len, emb); |
| 5922 | if (alloc_len < req_len) { |
| 5923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5924 | "2983 Allocated DMA memory size (x%x) is " |
| 5925 | "less than the requested DMA memory " |
| 5926 | "size (x%x)\n", alloc_len, req_len); |
| 5927 | rc = -ENOMEM; |
| 5928 | goto err_exit; |
| 5929 | } |
| 5930 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5931 | if (unlikely(rc)) { |
| 5932 | rc = -EIO; |
| 5933 | goto err_exit; |
| 5934 | } |
| 5935 | |
| 5936 | if (!phba->sli4_hba.intr_enable) |
| 5937 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5938 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5939 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5940 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5941 | } |
| 5942 | |
| 5943 | if (unlikely(rc)) { |
| 5944 | rc = -EIO; |
| 5945 | goto err_exit; |
| 5946 | } |
| 5947 | |
| 5948 | /* |
| 5949 | * Figure out where the response is located. Then get local pointers |
| 5950 | * to the response data. The port does not guarantee to respond to |
| 5951 | * all extents counts request so update the local variable with the |
| 5952 | * allocated count from the port. |
| 5953 | */ |
| 5954 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5955 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5956 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5957 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5958 | } else { |
| 5959 | virtaddr = mbox->sge_array->addr[0]; |
| 5960 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5961 | shdr = &n_rsrc->cfg_shdr; |
| 5962 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5963 | } |
| 5964 | |
| 5965 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5966 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5967 | "2984 Failed to read allocated resources " |
| 5968 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5969 | type, |
| 5970 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5971 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5972 | rc = -EIO; |
| 5973 | goto err_exit; |
| 5974 | } |
| 5975 | err_exit: |
| 5976 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5977 | return rc; |
| 5978 | } |
| 5979 | |
| 5980 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5981 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5982 | * @phba: pointer to lpfc hba data structure. |
| 5983 | * |
| 5984 | * This routine walks the list of els buffers that have been allocated and |
| 5985 | * repost them to the port by using SGL block post. This is needed after a |
| 5986 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5987 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5988 | * SGL block post mailbox commands to post them to the port. For single els |
| 5989 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5990 | * mailbox command for posting. |
| 5991 | * |
| 5992 | * Returns: 0 = success, non-zero failure. |
| 5993 | **/ |
| 5994 | static int |
| 5995 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5996 | { |
| 5997 | struct lpfc_sglq *sglq_entry = NULL; |
| 5998 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5999 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6000 | 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] | 6001 | int last_xritag = NO_XRI; |
| 6002 | LIST_HEAD(prep_sgl_list); |
| 6003 | LIST_HEAD(blck_sgl_list); |
| 6004 | LIST_HEAD(allc_sgl_list); |
| 6005 | LIST_HEAD(post_sgl_list); |
| 6006 | LIST_HEAD(free_sgl_list); |
| 6007 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6008 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6009 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6010 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6011 | |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6012 | total_cnt = phba->sli4_hba.els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6013 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6014 | &allc_sgl_list, list) { |
| 6015 | list_del_init(&sglq_entry->list); |
| 6016 | block_cnt++; |
| 6017 | if ((last_xritag != NO_XRI) && |
| 6018 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6019 | /* a hole in xri block, form a sgl posting block */ |
| 6020 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6021 | post_cnt = block_cnt - 1; |
| 6022 | /* prepare list for next posting block */ |
| 6023 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6024 | block_cnt = 1; |
| 6025 | } else { |
| 6026 | /* prepare list for next posting block */ |
| 6027 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6028 | /* enough sgls for non-embed sgl mbox command */ |
| 6029 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6030 | list_splice_init(&prep_sgl_list, |
| 6031 | &blck_sgl_list); |
| 6032 | post_cnt = block_cnt; |
| 6033 | block_cnt = 0; |
| 6034 | } |
| 6035 | } |
| 6036 | num_posted++; |
| 6037 | |
| 6038 | /* keep track of last sgl's xritag */ |
| 6039 | last_xritag = sglq_entry->sli4_xritag; |
| 6040 | |
| 6041 | /* end of repost sgl list condition for els buffers */ |
| 6042 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 6043 | if (post_cnt == 0) { |
| 6044 | list_splice_init(&prep_sgl_list, |
| 6045 | &blck_sgl_list); |
| 6046 | post_cnt = block_cnt; |
| 6047 | } else if (block_cnt == 1) { |
| 6048 | status = lpfc_sli4_post_sgl(phba, |
| 6049 | sglq_entry->phys, 0, |
| 6050 | sglq_entry->sli4_xritag); |
| 6051 | if (!status) { |
| 6052 | /* successful, put sgl to posted list */ |
| 6053 | list_add_tail(&sglq_entry->list, |
| 6054 | &post_sgl_list); |
| 6055 | } else { |
| 6056 | /* Failure, put sgl to free list */ |
| 6057 | lpfc_printf_log(phba, KERN_WARNING, |
| 6058 | LOG_SLI, |
| 6059 | "3159 Failed to post els " |
| 6060 | "sgl, xritag:x%x\n", |
| 6061 | sglq_entry->sli4_xritag); |
| 6062 | list_add_tail(&sglq_entry->list, |
| 6063 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6064 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | /* continue until a nembed page worth of sgls */ |
| 6070 | if (post_cnt == 0) |
| 6071 | continue; |
| 6072 | |
| 6073 | /* post the els buffer list sgls as a block */ |
| 6074 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6075 | post_cnt); |
| 6076 | |
| 6077 | if (!status) { |
| 6078 | /* success, put sgl list to posted sgl list */ |
| 6079 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6080 | } else { |
| 6081 | /* Failure, put sgl list to free sgl list */ |
| 6082 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6083 | struct lpfc_sglq, |
| 6084 | list); |
| 6085 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6086 | "3160 Failed to post els sgl-list, " |
| 6087 | "xritag:x%x-x%x\n", |
| 6088 | sglq_entry_first->sli4_xritag, |
| 6089 | (sglq_entry_first->sli4_xritag + |
| 6090 | post_cnt - 1)); |
| 6091 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6092 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6093 | } |
| 6094 | |
| 6095 | /* don't reset xirtag due to hole in xri block */ |
| 6096 | if (block_cnt == 0) |
| 6097 | last_xritag = NO_XRI; |
| 6098 | |
| 6099 | /* reset els sgl post count for next round of posting */ |
| 6100 | post_cnt = 0; |
| 6101 | } |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6102 | /* update the number of XRIs posted for ELS */ |
| 6103 | phba->sli4_hba.els_xri_cnt = total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6104 | |
| 6105 | /* free the els sgls failed to post */ |
| 6106 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6107 | |
| 6108 | /* push els sgls posted to the availble list */ |
| 6109 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6110 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6111 | list_splice_init(&post_sgl_list, |
| 6112 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6113 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6114 | } else { |
| 6115 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6116 | "3161 Failure to post els sgl to port.\n"); |
| 6117 | return -EIO; |
| 6118 | } |
| 6119 | return 0; |
| 6120 | } |
| 6121 | |
| 6122 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6123 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6124 | * @phba: Pointer to HBA context object. |
| 6125 | * |
| 6126 | * This function is the main SLI4 device intialization PCI function. This |
| 6127 | * function is called by the HBA intialization code, HBA reset code and |
| 6128 | * HBA error attention handler code. Caller is not required to hold any |
| 6129 | * locks. |
| 6130 | **/ |
| 6131 | int |
| 6132 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6133 | { |
| 6134 | int rc; |
| 6135 | LPFC_MBOXQ_t *mboxq; |
| 6136 | struct lpfc_mqe *mqe; |
| 6137 | uint8_t *vpd; |
| 6138 | uint32_t vpd_size; |
| 6139 | uint32_t ftr_rsp = 0; |
| 6140 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6141 | struct lpfc_vport *vport = phba->pport; |
| 6142 | struct lpfc_dmabuf *mp; |
| 6143 | |
| 6144 | /* Perform a PCI function reset to start from clean */ |
| 6145 | rc = lpfc_pci_function_reset(phba); |
| 6146 | if (unlikely(rc)) |
| 6147 | return -ENODEV; |
| 6148 | |
| 6149 | /* Check the HBA Host Status Register for readyness */ |
| 6150 | rc = lpfc_sli4_post_status_check(phba); |
| 6151 | if (unlikely(rc)) |
| 6152 | return -ENODEV; |
| 6153 | else { |
| 6154 | spin_lock_irq(&phba->hbalock); |
| 6155 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6156 | spin_unlock_irq(&phba->hbalock); |
| 6157 | } |
| 6158 | |
| 6159 | /* |
| 6160 | * Allocate a single mailbox container for initializing the |
| 6161 | * port. |
| 6162 | */ |
| 6163 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6164 | if (!mboxq) |
| 6165 | return -ENOMEM; |
| 6166 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6167 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6168 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6169 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6170 | if (!vpd) { |
| 6171 | rc = -ENOMEM; |
| 6172 | goto out_free_mbox; |
| 6173 | } |
| 6174 | |
| 6175 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6176 | if (unlikely(rc)) { |
| 6177 | kfree(vpd); |
| 6178 | goto out_free_mbox; |
| 6179 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6180 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6181 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6182 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6183 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6184 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6185 | else |
| 6186 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6187 | |
| 6188 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6189 | LPFC_DCBX_CEE_MODE) |
| 6190 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6191 | else |
| 6192 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6193 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6194 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6195 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6196 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6197 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6198 | "0376 READ_REV Error. SLI Level %d " |
| 6199 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6200 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6201 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6202 | kfree(vpd); |
| 6203 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6204 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6205 | |
| 6206 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6207 | * Continue initialization with default values even if driver failed |
| 6208 | * to read FCoE param config regions, only read parameters if the |
| 6209 | * board is FCoE |
| 6210 | */ |
| 6211 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6212 | lpfc_sli4_read_fcoe_params(phba)) |
| 6213 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6214 | "2570 Failed to read FCoE parameters\n"); |
| 6215 | |
| 6216 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6217 | * Retrieve sli4 device physical port name, failure of doing it |
| 6218 | * is considered as non-fatal. |
| 6219 | */ |
| 6220 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6221 | if (!rc) |
| 6222 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6223 | "3080 Successful retrieving SLI4 device " |
| 6224 | "physical port name: %s.\n", phba->Port); |
| 6225 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6226 | /* |
| 6227 | * Evaluate the read rev and vpd data. Populate the driver |
| 6228 | * state with the results. If this routine fails, the failure |
| 6229 | * is not fatal as the driver will use generic values. |
| 6230 | */ |
| 6231 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6232 | if (unlikely(!rc)) { |
| 6233 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6234 | "0377 Error %d parsing vpd. " |
| 6235 | "Using defaults.\n", rc); |
| 6236 | rc = 0; |
| 6237 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6238 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6239 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6240 | /* Save information as VPD data */ |
| 6241 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6242 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6243 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6244 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6245 | &mqe->un.read_rev); |
| 6246 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6247 | &mqe->un.read_rev); |
| 6248 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6249 | &mqe->un.read_rev); |
| 6250 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6251 | &mqe->un.read_rev); |
| 6252 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6253 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6254 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6255 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6256 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6257 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6258 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6259 | "(%d):0380 READ_REV Status x%x " |
| 6260 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6261 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6262 | bf_get(lpfc_mqe_status, mqe), |
| 6263 | phba->vpd.rev.opFwName, |
| 6264 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6265 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6266 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6267 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6268 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6269 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6270 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6271 | "3362 LUN queue depth changed from %d to %d\n", |
| 6272 | phba->pport->cfg_lun_queue_depth, rc); |
| 6273 | phba->pport->cfg_lun_queue_depth = rc; |
| 6274 | } |
| 6275 | |
| 6276 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6277 | /* |
| 6278 | * Discover the port's supported feature set and match it against the |
| 6279 | * hosts requests. |
| 6280 | */ |
| 6281 | lpfc_request_features(phba, mboxq); |
| 6282 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6283 | if (unlikely(rc)) { |
| 6284 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6285 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | /* |
| 6289 | * The port must support FCP initiator mode as this is the |
| 6290 | * only mode running in the host. |
| 6291 | */ |
| 6292 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6293 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6294 | "0378 No support for fcpi mode.\n"); |
| 6295 | ftr_rsp++; |
| 6296 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6297 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6298 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6299 | else |
| 6300 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6301 | /* |
| 6302 | * If the port cannot support the host's requested features |
| 6303 | * then turn off the global config parameters to disable the |
| 6304 | * feature in the driver. This is not a fatal error. |
| 6305 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6306 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6307 | if (phba->cfg_enable_bg) { |
| 6308 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6309 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6310 | else |
| 6311 | ftr_rsp++; |
| 6312 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6313 | |
| 6314 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6315 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6316 | ftr_rsp++; |
| 6317 | |
| 6318 | if (ftr_rsp) { |
| 6319 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6320 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6321 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6322 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6323 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6324 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6325 | phba->cfg_enable_bg = 0; |
| 6326 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6327 | phba->cfg_enable_npiv = 0; |
| 6328 | } |
| 6329 | |
| 6330 | /* These SLI3 features are assumed in SLI4 */ |
| 6331 | spin_lock_irq(&phba->hbalock); |
| 6332 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6333 | spin_unlock_irq(&phba->hbalock); |
| 6334 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6335 | /* |
| 6336 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6337 | * calls depends on these resources to complete port setup. |
| 6338 | */ |
| 6339 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6340 | if (rc) { |
| 6341 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6342 | "2920 Failed to alloc Resource IDs " |
| 6343 | "rc = x%x\n", rc); |
| 6344 | goto out_free_mbox; |
| 6345 | } |
| 6346 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6347 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6348 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6349 | if (rc) { |
| 6350 | phba->link_state = LPFC_HBA_ERROR; |
| 6351 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6352 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6353 | } |
| 6354 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6355 | mboxq->vport = vport; |
| 6356 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6357 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6358 | if (rc == MBX_SUCCESS) { |
| 6359 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6360 | rc = 0; |
| 6361 | } |
| 6362 | |
| 6363 | /* |
| 6364 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6365 | * it to the mbuf pool. |
| 6366 | */ |
| 6367 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6368 | kfree(mp); |
| 6369 | mboxq->context1 = NULL; |
| 6370 | if (unlikely(rc)) { |
| 6371 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6372 | "0382 READ_SPARAM command failed " |
| 6373 | "status %d, mbxStatus x%x\n", |
| 6374 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6375 | phba->link_state = LPFC_HBA_ERROR; |
| 6376 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6377 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6380 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6381 | |
| 6382 | /* Update the fc_host data structures with new wwn. */ |
| 6383 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6384 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6385 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6386 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6387 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6388 | if (unlikely(rc)) { |
| 6389 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6390 | "1400 Failed to update xri-sgl size and " |
| 6391 | "mapping: %d\n", rc); |
| 6392 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6395 | /* register the els sgl pool to the port */ |
| 6396 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6397 | if (unlikely(rc)) { |
| 6398 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6399 | "0582 Error %d during els sgl post " |
| 6400 | "operation\n", rc); |
| 6401 | rc = -ENODEV; |
| 6402 | goto out_free_mbox; |
| 6403 | } |
| 6404 | |
| 6405 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6406 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6407 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6408 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6409 | "0383 Error %d during scsi sgl post " |
| 6410 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6411 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6412 | /* A pci function reset will repost them */ |
| 6413 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6414 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | /* Post the rpi header region to the device. */ |
| 6418 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6419 | if (unlikely(rc)) { |
| 6420 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6421 | "0393 Error %d during rpi post operation\n", |
| 6422 | rc); |
| 6423 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6424 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6425 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6426 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6427 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6428 | /* Create all the SLI4 queues */ |
| 6429 | rc = lpfc_sli4_queue_create(phba); |
| 6430 | if (rc) { |
| 6431 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6432 | "3089 Failed to allocate queues\n"); |
| 6433 | rc = -ENODEV; |
| 6434 | goto out_stop_timers; |
| 6435 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6436 | /* Set up all the queues to the device */ |
| 6437 | rc = lpfc_sli4_queue_setup(phba); |
| 6438 | if (unlikely(rc)) { |
| 6439 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6440 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6441 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | /* Arm the CQs and then EQs on device */ |
| 6445 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6446 | |
| 6447 | /* Indicate device interrupt mode */ |
| 6448 | phba->sli4_hba.intr_enable = 1; |
| 6449 | |
| 6450 | /* Allow asynchronous mailbox command to go through */ |
| 6451 | spin_lock_irq(&phba->hbalock); |
| 6452 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6453 | spin_unlock_irq(&phba->hbalock); |
| 6454 | |
| 6455 | /* Post receive buffers to the device */ |
| 6456 | lpfc_sli4_rb_setup(phba); |
| 6457 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6458 | /* Reset HBA FCF states after HBA reset */ |
| 6459 | phba->fcf.fcf_flag = 0; |
| 6460 | phba->fcf.current_rec.flag = 0; |
| 6461 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6462 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6463 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6464 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6465 | |
| 6466 | /* Start heart beat timer */ |
| 6467 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6468 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6469 | phba->hb_outstanding = 0; |
| 6470 | phba->last_completion_time = jiffies; |
| 6471 | |
| 6472 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6473 | mod_timer(&phba->eratt_poll, |
| 6474 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6475 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6476 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6477 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6478 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6479 | if (!rc) { |
| 6480 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6481 | "2829 This device supports " |
| 6482 | "Advanced Error Reporting (AER)\n"); |
| 6483 | spin_lock_irq(&phba->hbalock); |
| 6484 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6485 | spin_unlock_irq(&phba->hbalock); |
| 6486 | } else { |
| 6487 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6488 | "2830 This device does not support " |
| 6489 | "Advanced Error Reporting (AER)\n"); |
| 6490 | phba->cfg_aer_support = 0; |
| 6491 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6492 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6493 | } |
| 6494 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6495 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6496 | /* |
| 6497 | * The FC Port needs to register FCFI (index 0) |
| 6498 | */ |
| 6499 | lpfc_reg_fcfi(phba, mboxq); |
| 6500 | mboxq->vport = phba->pport; |
| 6501 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6502 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6503 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6504 | rc = 0; |
| 6505 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6506 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6507 | |
| 6508 | /* Check if the port is configured to be disabled */ |
| 6509 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6510 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6511 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6512 | /* |
| 6513 | * The port is ready, set the host's link state to LINK_DOWN |
| 6514 | * in preparation for link interrupts. |
| 6515 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6516 | spin_lock_irq(&phba->hbalock); |
| 6517 | phba->link_state = LPFC_LINK_DOWN; |
| 6518 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6519 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6520 | (phba->hba_flag & LINK_DISABLED)) { |
| 6521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6522 | "3103 Adapter Link is disabled.\n"); |
| 6523 | lpfc_down_link(phba, mboxq); |
| 6524 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6525 | if (rc != MBX_SUCCESS) { |
| 6526 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6527 | "3104 Adapter failed to issue " |
| 6528 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6529 | goto out_unset_queue; |
| 6530 | } |
| 6531 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6532 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6533 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6534 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6535 | if (rc) |
| 6536 | goto out_unset_queue; |
| 6537 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6538 | } |
| 6539 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6540 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6541 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6542 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6543 | lpfc_sli4_queue_unset(phba); |
| 6544 | out_destroy_queue: |
| 6545 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6546 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6547 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6548 | out_free_mbox: |
| 6549 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6550 | return rc; |
| 6551 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6552 | |
| 6553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6554 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6555 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6556 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6557 | * This is the callback function for mailbox timer. The mailbox |
| 6558 | * timer is armed when a new mailbox command is issued and the timer |
| 6559 | * is deleted when the mailbox complete. The function is called by |
| 6560 | * the kernel timer code when a mailbox does not complete within |
| 6561 | * expected time. This function wakes up the worker thread to |
| 6562 | * process the mailbox timeout and returns. All the processing is |
| 6563 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6564 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6565 | void |
| 6566 | lpfc_mbox_timeout(unsigned long ptr) |
| 6567 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6568 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6569 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6570 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6572 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6573 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6574 | if (!tmo_posted) |
| 6575 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6576 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6577 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6578 | if (!tmo_posted) |
| 6579 | lpfc_worker_wake_up(phba); |
| 6580 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6581 | } |
| 6582 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6583 | /** |
| 6584 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 6585 | * are pending |
| 6586 | * @phba: Pointer to HBA context object. |
| 6587 | * |
| 6588 | * This function checks if any mailbox completions are present on the mailbox |
| 6589 | * completion queue. |
| 6590 | **/ |
| 6591 | bool |
| 6592 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 6593 | { |
| 6594 | |
| 6595 | uint32_t idx; |
| 6596 | struct lpfc_queue *mcq; |
| 6597 | struct lpfc_mcqe *mcqe; |
| 6598 | bool pending_completions = false; |
| 6599 | |
| 6600 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6601 | return false; |
| 6602 | |
| 6603 | /* Check for completions on mailbox completion queue */ |
| 6604 | |
| 6605 | mcq = phba->sli4_hba.mbx_cq; |
| 6606 | idx = mcq->hba_index; |
| 6607 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 6608 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 6609 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 6610 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 6611 | pending_completions = true; |
| 6612 | break; |
| 6613 | } |
| 6614 | idx = (idx + 1) % mcq->entry_count; |
| 6615 | if (mcq->hba_index == idx) |
| 6616 | break; |
| 6617 | } |
| 6618 | return pending_completions; |
| 6619 | |
| 6620 | } |
| 6621 | |
| 6622 | /** |
| 6623 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 6624 | * that were missed. |
| 6625 | * @phba: Pointer to HBA context object. |
| 6626 | * |
| 6627 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 6628 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 6629 | * checks to see if mbox completions are on the mailbox completion queue |
| 6630 | * and will process all the completions associated with the eq for the |
| 6631 | * mailbox completion queue. |
| 6632 | **/ |
| 6633 | bool |
| 6634 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 6635 | { |
| 6636 | |
| 6637 | uint32_t eqidx; |
| 6638 | struct lpfc_queue *fpeq = NULL; |
| 6639 | struct lpfc_eqe *eqe; |
| 6640 | bool mbox_pending; |
| 6641 | |
| 6642 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6643 | return false; |
| 6644 | |
| 6645 | /* Find the eq associated with the mcq */ |
| 6646 | |
| 6647 | if (phba->sli4_hba.hba_eq) |
| 6648 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) |
| 6649 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 6650 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 6651 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 6652 | break; |
| 6653 | } |
| 6654 | if (!fpeq) |
| 6655 | return false; |
| 6656 | |
| 6657 | /* Turn off interrupts from this EQ */ |
| 6658 | |
| 6659 | lpfc_sli4_eq_clr_intr(fpeq); |
| 6660 | |
| 6661 | /* Check to see if a mbox completion is pending */ |
| 6662 | |
| 6663 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 6664 | |
| 6665 | /* |
| 6666 | * If a mbox completion is pending, process all the events on EQ |
| 6667 | * associated with the mbox completion queue (this could include |
| 6668 | * mailbox commands, async events, els commands, receive queue data |
| 6669 | * and fcp commands) |
| 6670 | */ |
| 6671 | |
| 6672 | if (mbox_pending) |
| 6673 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 6674 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 6675 | fpeq->EQ_processed++; |
| 6676 | } |
| 6677 | |
| 6678 | /* Always clear and re-arm the EQ */ |
| 6679 | |
| 6680 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 6681 | |
| 6682 | return mbox_pending; |
| 6683 | |
| 6684 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6685 | |
| 6686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6687 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6688 | * @phba: Pointer to HBA context object. |
| 6689 | * |
| 6690 | * This function is called from worker thread when a mailbox command times out. |
| 6691 | * The caller is not required to hold any locks. This function will reset the |
| 6692 | * HBA and recover all the pending commands. |
| 6693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6694 | void |
| 6695 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6696 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6697 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6698 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6699 | struct lpfc_sli *psli = &phba->sli; |
| 6700 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6701 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6702 | /* If the mailbox completed, process the completion and return */ |
| 6703 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 6704 | return; |
| 6705 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6706 | /* Check the pmbox pointer first. There is a race condition |
| 6707 | * between the mbox timeout handler getting executed in the |
| 6708 | * worklist and the mailbox actually completing. When this |
| 6709 | * race condition occurs, the mbox_active will be NULL. |
| 6710 | */ |
| 6711 | spin_lock_irq(&phba->hbalock); |
| 6712 | if (pmbox == NULL) { |
| 6713 | lpfc_printf_log(phba, KERN_WARNING, |
| 6714 | LOG_MBOX | LOG_SLI, |
| 6715 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6716 | "exiting\n"); |
| 6717 | spin_unlock_irq(&phba->hbalock); |
| 6718 | return; |
| 6719 | } |
| 6720 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6721 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6722 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6723 | "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] | 6724 | mb->mbxCommand, |
| 6725 | phba->pport->port_state, |
| 6726 | phba->sli.sli_flag, |
| 6727 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6728 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6729 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6730 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6731 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6732 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6733 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6734 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6735 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6736 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6737 | spin_lock_irq(&phba->hbalock); |
| 6738 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6739 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6740 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6741 | |
| 6742 | pring = &psli->ring[psli->fcp_ring]; |
| 6743 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6744 | |
| 6745 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6746 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6747 | |
| 6748 | /* Reset the HBA device */ |
| 6749 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6750 | } |
| 6751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6752 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6753 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6754 | * @phba: Pointer to HBA context object. |
| 6755 | * @pmbox: Pointer to mailbox object. |
| 6756 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6757 | * |
| 6758 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6759 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6760 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6761 | * The mailbox command can be submitted in polling mode, in which case |
| 6762 | * this function will wait in a polling loop for the completion of the |
| 6763 | * mailbox. |
| 6764 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6765 | * function will submit the command and returns immediately without waiting |
| 6766 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6767 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6768 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6769 | * mailbox is issued in polling mode and there is already a mailbox |
| 6770 | * pending, then the function will return an error. If the mailbox is issued |
| 6771 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6772 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6773 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6774 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6775 | * return codes the caller owns the mailbox command after the return of |
| 6776 | * the function. |
| 6777 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6778 | static int |
| 6779 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6780 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6781 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6782 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6783 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6784 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6785 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6786 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6787 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6788 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6789 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6790 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6791 | int processing_queue = 0; |
| 6792 | |
| 6793 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6794 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6795 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6796 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6797 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6798 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6799 | return MBX_SUCCESS; |
| 6800 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6801 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6802 | pmbox = lpfc_mbox_get(phba); |
| 6803 | if (!pmbox) { |
| 6804 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6805 | return MBX_SUCCESS; |
| 6806 | } |
| 6807 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6808 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6809 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6810 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6811 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6812 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6813 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6814 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6815 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6816 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6817 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6818 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6819 | } |
| 6820 | } |
| 6821 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6822 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6823 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6824 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6825 | goto out_not_finished; |
| 6826 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6827 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6828 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6829 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6830 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6831 | goto out_not_finished; |
| 6832 | } |
| 6833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6834 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6835 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6836 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6837 | status = MBX_SUCCESS; |
| 6838 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6839 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6840 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6841 | |
| 6842 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6843 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6844 | "(%d):0311 Mailbox command x%x cannot " |
| 6845 | "issue Data: x%x x%x\n", |
| 6846 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6847 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6848 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6849 | } |
| 6850 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6851 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6852 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6853 | !(hc_copy & HC_MBINT_ENA)) { |
| 6854 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6855 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6856 | "(%d):2528 Mailbox command x%x cannot " |
| 6857 | "issue Data: x%x x%x\n", |
| 6858 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6859 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6860 | goto out_not_finished; |
| 6861 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6862 | } |
| 6863 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6864 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6865 | /* Polling for a mbox command when another one is already active |
| 6866 | * is not allowed in SLI. Also, the driver must have established |
| 6867 | * SLI2 mode to queue and process multiple mbox commands. |
| 6868 | */ |
| 6869 | |
| 6870 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6871 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6872 | |
| 6873 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6874 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6875 | "(%d):2529 Mailbox command x%x " |
| 6876 | "cannot issue Data: x%x x%x\n", |
| 6877 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6878 | pmbox->u.mb.mbxCommand, |
| 6879 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6880 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6881 | } |
| 6882 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6883 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6884 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6885 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6886 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6887 | "(%d):2530 Mailbox command x%x " |
| 6888 | "cannot issue Data: x%x x%x\n", |
| 6889 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6890 | pmbox->u.mb.mbxCommand, |
| 6891 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6892 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6893 | } |
| 6894 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6895 | /* Another mailbox command is still being processed, queue this |
| 6896 | * command to be processed later. |
| 6897 | */ |
| 6898 | lpfc_mbox_put(phba, pmbox); |
| 6899 | |
| 6900 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6901 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6902 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6903 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6904 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6905 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6906 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6907 | |
| 6908 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6909 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6910 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6911 | if (pmbox->vport) { |
| 6912 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6913 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6914 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6915 | (uint32_t)mbx->mbxCommand, |
| 6916 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6917 | } |
| 6918 | else { |
| 6919 | lpfc_debugfs_disc_trc(phba->pport, |
| 6920 | LPFC_DISC_TRC_MBOX, |
| 6921 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6922 | (uint32_t)mbx->mbxCommand, |
| 6923 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6924 | } |
| 6925 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6926 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6927 | } |
| 6928 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6929 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6930 | |
| 6931 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6932 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6933 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6934 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6935 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6936 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6937 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6938 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6939 | "(%d):2531 Mailbox command x%x " |
| 6940 | "cannot issue Data: x%x x%x\n", |
| 6941 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6942 | pmbox->u.mb.mbxCommand, |
| 6943 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6944 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6945 | } |
| 6946 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6947 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6948 | 1000); |
| 6949 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6953 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6954 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6955 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6956 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6957 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6958 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6959 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6960 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6961 | if (pmbox->vport) { |
| 6962 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6963 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6964 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6965 | (uint32_t)mbx->mbxCommand, |
| 6966 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6967 | } |
| 6968 | else { |
| 6969 | lpfc_debugfs_disc_trc(phba->pport, |
| 6970 | LPFC_DISC_TRC_MBOX, |
| 6971 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6972 | (uint32_t)mbx->mbxCommand, |
| 6973 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6977 | psli->slistat.mbox_cmd++; |
| 6978 | evtctr = psli->slistat.mbox_event; |
| 6979 | |
| 6980 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6981 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6982 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6983 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6984 | /* Populate mbox extension offset word. */ |
| 6985 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6986 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6987 | = (uint8_t *)phba->mbox_ext |
| 6988 | - (uint8_t *)phba->mbox; |
| 6989 | } |
| 6990 | |
| 6991 | /* Copy the mailbox extension data */ |
| 6992 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6993 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6994 | (uint8_t *)phba->mbox_ext, |
| 6995 | pmbox->in_ext_byte_len); |
| 6996 | } |
| 6997 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6998 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6999 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7000 | /* Populate mbox extension offset word. */ |
| 7001 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7002 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7003 | = MAILBOX_HBA_EXT_OFFSET; |
| 7004 | |
| 7005 | /* Copy the mailbox extension data */ |
| 7006 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7007 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7008 | MAILBOX_HBA_EXT_OFFSET, |
| 7009 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7010 | |
| 7011 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7012 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7013 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7014 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7015 | } |
| 7016 | |
| 7017 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7018 | word */ |
| 7019 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7020 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7021 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7022 | |
| 7023 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7024 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7025 | to_slim = phba->MBslimaddr; |
| 7026 | writel(ldata, to_slim); |
| 7027 | readl(to_slim); /* flush */ |
| 7028 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7029 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7030 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7031 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7036 | |
| 7037 | switch (flag) { |
| 7038 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7039 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7040 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7041 | /* Interrupt board to do it */ |
| 7042 | writel(CA_MBATT, phba->CAregaddr); |
| 7043 | readl(phba->CAregaddr); /* flush */ |
| 7044 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7045 | break; |
| 7046 | |
| 7047 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7048 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7049 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7050 | /* Interrupt board to do it */ |
| 7051 | writel(CA_MBATT, phba->CAregaddr); |
| 7052 | readl(phba->CAregaddr); /* flush */ |
| 7053 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7054 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7055 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7056 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7057 | word0 = le32_to_cpu(word0); |
| 7058 | } else { |
| 7059 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7060 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7061 | spin_unlock_irqrestore(&phba->hbalock, |
| 7062 | drvr_flag); |
| 7063 | goto out_not_finished; |
| 7064 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7065 | } |
| 7066 | |
| 7067 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7068 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7069 | spin_unlock_irqrestore(&phba->hbalock, |
| 7070 | drvr_flag); |
| 7071 | goto out_not_finished; |
| 7072 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7073 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7074 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7075 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7076 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7077 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7078 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7079 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7080 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7081 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7082 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7083 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7084 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | /* Check if we took a mbox interrupt while we were |
| 7088 | polling */ |
| 7089 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7090 | && (evtctr != psli->slistat.mbox_event)) |
| 7091 | break; |
| 7092 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7093 | if (i++ > 10) { |
| 7094 | spin_unlock_irqrestore(&phba->hbalock, |
| 7095 | drvr_flag); |
| 7096 | msleep(1); |
| 7097 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7098 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7099 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7100 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7101 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7102 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7103 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7104 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7105 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7106 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7107 | /* Check real SLIM for any errors */ |
| 7108 | slimword0 = readl(phba->MBslimaddr); |
| 7109 | slimmb = (MAILBOX_t *) & slimword0; |
| 7110 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7111 | && slimmb->mbxStatus) { |
| 7112 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7113 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7114 | word0 = slimword0; |
| 7115 | } |
| 7116 | } |
| 7117 | } else { |
| 7118 | /* First copy command data */ |
| 7119 | word0 = readl(phba->MBslimaddr); |
| 7120 | } |
| 7121 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7122 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7123 | spin_unlock_irqrestore(&phba->hbalock, |
| 7124 | drvr_flag); |
| 7125 | goto out_not_finished; |
| 7126 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7127 | } |
| 7128 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7129 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7130 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7131 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7132 | /* Copy the mailbox extension data */ |
| 7133 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7134 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7135 | pmbox->context2, |
| 7136 | pmbox->out_ext_byte_len); |
| 7137 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7138 | } else { |
| 7139 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7140 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7141 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7142 | /* Copy the mailbox extension data */ |
| 7143 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7144 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7145 | phba->MBslimaddr + |
| 7146 | MAILBOX_HBA_EXT_OFFSET, |
| 7147 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7148 | } |
| 7149 | } |
| 7150 | |
| 7151 | writel(HA_MBATT, phba->HAregaddr); |
| 7152 | readl(phba->HAregaddr); /* flush */ |
| 7153 | |
| 7154 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7155 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7156 | } |
| 7157 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7158 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7159 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7160 | |
| 7161 | out_not_finished: |
| 7162 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7163 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7164 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7165 | } |
| 7166 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7167 | } |
| 7168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7169 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7170 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7171 | * @phba: Pointer to HBA context object. |
| 7172 | * |
| 7173 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7174 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7175 | * possible outstanding mailbox command before return. |
| 7176 | * |
| 7177 | * Returns: |
| 7178 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7179 | * the outstanding mailbox command timed out. |
| 7180 | **/ |
| 7181 | static int |
| 7182 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7183 | { |
| 7184 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7185 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7186 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7187 | |
| 7188 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7189 | spin_lock_irq(&phba->hbalock); |
| 7190 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7191 | /* Determine how long we might wait for the active mailbox |
| 7192 | * command to be gracefully completed by firmware. |
| 7193 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7194 | if (phba->sli.mbox_active) |
| 7195 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7196 | phba->sli.mbox_active) * |
| 7197 | 1000) + jiffies; |
| 7198 | spin_unlock_irq(&phba->hbalock); |
| 7199 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7200 | /* Make sure the mailbox is really active */ |
| 7201 | if (timeout) |
| 7202 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7203 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7204 | /* Wait for the outstnading mailbox command to complete */ |
| 7205 | while (phba->sli.mbox_active) { |
| 7206 | /* Check active mailbox complete status every 2ms */ |
| 7207 | msleep(2); |
| 7208 | if (time_after(jiffies, timeout)) { |
| 7209 | /* Timeout, marked the outstanding cmd not complete */ |
| 7210 | rc = 1; |
| 7211 | break; |
| 7212 | } |
| 7213 | } |
| 7214 | |
| 7215 | /* Can not cleanly block async mailbox command, fails it */ |
| 7216 | if (rc) { |
| 7217 | spin_lock_irq(&phba->hbalock); |
| 7218 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7219 | spin_unlock_irq(&phba->hbalock); |
| 7220 | } |
| 7221 | return rc; |
| 7222 | } |
| 7223 | |
| 7224 | /** |
| 7225 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7226 | * @phba: Pointer to HBA context object. |
| 7227 | * |
| 7228 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7229 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7230 | * that there is no outstanding mailbox command before resuming posting |
| 7231 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7232 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7233 | * mailbox command posting. |
| 7234 | **/ |
| 7235 | static void |
| 7236 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7237 | { |
| 7238 | struct lpfc_sli *psli = &phba->sli; |
| 7239 | |
| 7240 | spin_lock_irq(&phba->hbalock); |
| 7241 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7242 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7243 | spin_unlock_irq(&phba->hbalock); |
| 7244 | return; |
| 7245 | } |
| 7246 | |
| 7247 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7248 | * successful or timeout, after timing-out the outstanding mailbox |
| 7249 | * command shall always be removed, so just unblock posting async |
| 7250 | * mailbox command and resume |
| 7251 | */ |
| 7252 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7253 | spin_unlock_irq(&phba->hbalock); |
| 7254 | |
| 7255 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7256 | lpfc_worker_wake_up(phba); |
| 7257 | } |
| 7258 | |
| 7259 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7260 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7261 | * @phba: Pointer to HBA context object. |
| 7262 | * @mboxq: Pointer to mailbox object. |
| 7263 | * |
| 7264 | * The function waits for the bootstrap mailbox register ready bit from |
| 7265 | * port for twice the regular mailbox command timeout value. |
| 7266 | * |
| 7267 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7268 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7269 | **/ |
| 7270 | static int |
| 7271 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7272 | { |
| 7273 | uint32_t db_ready; |
| 7274 | unsigned long timeout; |
| 7275 | struct lpfc_register bmbx_reg; |
| 7276 | |
| 7277 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7278 | * 1000) + jiffies; |
| 7279 | |
| 7280 | do { |
| 7281 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7282 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7283 | if (!db_ready) |
| 7284 | msleep(2); |
| 7285 | |
| 7286 | if (time_after(jiffies, timeout)) |
| 7287 | return MBXERR_ERROR; |
| 7288 | } while (!db_ready); |
| 7289 | |
| 7290 | return 0; |
| 7291 | } |
| 7292 | |
| 7293 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7294 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7295 | * @phba: Pointer to HBA context object. |
| 7296 | * @mboxq: Pointer to mailbox object. |
| 7297 | * |
| 7298 | * The function posts a mailbox to the port. The mailbox is expected |
| 7299 | * to be comletely filled in and ready for the port to operate on it. |
| 7300 | * This routine executes a synchronous completion operation on the |
| 7301 | * mailbox by polling for its completion. |
| 7302 | * |
| 7303 | * The caller must not be holding any locks when calling this routine. |
| 7304 | * |
| 7305 | * Returns: |
| 7306 | * MBX_SUCCESS - mailbox posted successfully |
| 7307 | * Any of the MBX error values. |
| 7308 | **/ |
| 7309 | static int |
| 7310 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7311 | { |
| 7312 | int rc = MBX_SUCCESS; |
| 7313 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7314 | uint32_t mcqe_status; |
| 7315 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7316 | struct lpfc_sli *psli = &phba->sli; |
| 7317 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7318 | struct lpfc_bmbx_create *mbox_rgn; |
| 7319 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7320 | |
| 7321 | /* |
| 7322 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7323 | * at a time and there is no queueing provided. |
| 7324 | */ |
| 7325 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7326 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7327 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7328 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7329 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7330 | "cannot issue Data: x%x x%x\n", |
| 7331 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7332 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7333 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7334 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7335 | psli->sli_flag, MBX_POLL); |
| 7336 | return MBXERR_ERROR; |
| 7337 | } |
| 7338 | /* The server grabs the token and owns it until release */ |
| 7339 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7340 | phba->sli.mbox_active = mboxq; |
| 7341 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7342 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7343 | /* wait for bootstrap mbox register for readyness */ |
| 7344 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7345 | if (rc) |
| 7346 | goto exit; |
| 7347 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7348 | /* |
| 7349 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7350 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7351 | * the bmbx mailbox region. |
| 7352 | */ |
| 7353 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7354 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7355 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7356 | sizeof(struct lpfc_mqe)); |
| 7357 | |
| 7358 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7359 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7360 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7361 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7362 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7363 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7364 | if (rc) |
| 7365 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7366 | |
| 7367 | /* Post the low mailbox dma address to the port. */ |
| 7368 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7369 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7370 | /* wait for bootstrap mbox register for low address write done */ |
| 7371 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7372 | if (rc) |
| 7373 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7374 | |
| 7375 | /* |
| 7376 | * Read the CQ to ensure the mailbox has completed. |
| 7377 | * If so, update the mailbox status so that the upper layers |
| 7378 | * can complete the request normally. |
| 7379 | */ |
| 7380 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7381 | sizeof(struct lpfc_mqe)); |
| 7382 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7383 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7384 | sizeof(struct lpfc_mcqe)); |
| 7385 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7386 | /* |
| 7387 | * When the CQE status indicates a failure and the mailbox status |
| 7388 | * indicates success then copy the CQE status into the mailbox status |
| 7389 | * (and prefix it with x4000). |
| 7390 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7391 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7392 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7393 | bf_set(lpfc_mqe_status, mb, |
| 7394 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7395 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7396 | } else |
| 7397 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7398 | |
| 7399 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7400 | "(%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] | 7401 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7402 | " 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] | 7403 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7404 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7405 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7406 | bf_get(lpfc_mqe_status, mb), |
| 7407 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7408 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7409 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7410 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7411 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7412 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7413 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7414 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7415 | mboxq->mcqe.trailer); |
| 7416 | exit: |
| 7417 | /* We are holding the token, no needed for lock when release */ |
| 7418 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7419 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7420 | phba->sli.mbox_active = NULL; |
| 7421 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7422 | return rc; |
| 7423 | } |
| 7424 | |
| 7425 | /** |
| 7426 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7427 | * @phba: Pointer to HBA context object. |
| 7428 | * @pmbox: Pointer to mailbox object. |
| 7429 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7430 | * |
| 7431 | * This function is called by discovery code and HBA management code to submit |
| 7432 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7433 | * |
| 7434 | * Return codes the caller owns the mailbox command after the return of the |
| 7435 | * function. |
| 7436 | **/ |
| 7437 | static int |
| 7438 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7439 | uint32_t flag) |
| 7440 | { |
| 7441 | struct lpfc_sli *psli = &phba->sli; |
| 7442 | unsigned long iflags; |
| 7443 | int rc; |
| 7444 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7445 | /* dump from issue mailbox command if setup */ |
| 7446 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7447 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7448 | rc = lpfc_mbox_dev_check(phba); |
| 7449 | if (unlikely(rc)) { |
| 7450 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7451 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7452 | "cannot issue Data: x%x x%x\n", |
| 7453 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7454 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7455 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7456 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7457 | psli->sli_flag, flag); |
| 7458 | goto out_not_finished; |
| 7459 | } |
| 7460 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7461 | /* Detect polling mode and jump to a handler */ |
| 7462 | if (!phba->sli4_hba.intr_enable) { |
| 7463 | if (flag == MBX_POLL) |
| 7464 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7465 | else |
| 7466 | rc = -EIO; |
| 7467 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7468 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7469 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7470 | "(x%x/x%x) failure: " |
| 7471 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7472 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7473 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7474 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7475 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7476 | mboxq), |
| 7477 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7478 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7479 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7480 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7481 | bf_get(lpfc_mcqe_ext_status, |
| 7482 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7483 | psli->sli_flag, flag); |
| 7484 | return rc; |
| 7485 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7486 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7487 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7488 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7489 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7490 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7491 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7492 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7493 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7494 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7495 | /* Try to block the asynchronous mailbox posting */ |
| 7496 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7497 | if (!rc) { |
| 7498 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7499 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7500 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7501 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7502 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7503 | "(%d):2597 Sync Mailbox command " |
| 7504 | "x%x (x%x/x%x) failure: " |
| 7505 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7506 | "Data: x%x x%x\n,", |
| 7507 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7508 | mboxq->u.mb.mbxCommand, |
| 7509 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7510 | mboxq), |
| 7511 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7512 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7513 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7514 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7515 | bf_get(lpfc_mcqe_ext_status, |
| 7516 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7517 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7518 | /* Unblock the async mailbox posting afterward */ |
| 7519 | lpfc_sli4_async_mbox_unblock(phba); |
| 7520 | } |
| 7521 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7525 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7526 | if (rc) { |
| 7527 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7528 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7529 | "cannot issue Data: x%x x%x\n", |
| 7530 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7531 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7532 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7533 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7534 | psli->sli_flag, flag); |
| 7535 | goto out_not_finished; |
| 7536 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7537 | |
| 7538 | /* Put the mailbox command to the driver internal FIFO */ |
| 7539 | psli->slistat.mbox_busy++; |
| 7540 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7541 | lpfc_mbox_put(phba, mboxq); |
| 7542 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7543 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7544 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7545 | "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] | 7546 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7547 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7548 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7549 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7550 | phba->pport->port_state, |
| 7551 | psli->sli_flag, MBX_NOWAIT); |
| 7552 | /* Wake up worker thread to transport mailbox command from head */ |
| 7553 | lpfc_worker_wake_up(phba); |
| 7554 | |
| 7555 | return MBX_BUSY; |
| 7556 | |
| 7557 | out_not_finished: |
| 7558 | return MBX_NOT_FINISHED; |
| 7559 | } |
| 7560 | |
| 7561 | /** |
| 7562 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7563 | * @phba: Pointer to HBA context object. |
| 7564 | * |
| 7565 | * This function is called by worker thread to send a mailbox command to |
| 7566 | * SLI4 HBA firmware. |
| 7567 | * |
| 7568 | **/ |
| 7569 | int |
| 7570 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7571 | { |
| 7572 | struct lpfc_sli *psli = &phba->sli; |
| 7573 | LPFC_MBOXQ_t *mboxq; |
| 7574 | int rc = MBX_SUCCESS; |
| 7575 | unsigned long iflags; |
| 7576 | struct lpfc_mqe *mqe; |
| 7577 | uint32_t mbx_cmnd; |
| 7578 | |
| 7579 | /* Check interrupt mode before post async mailbox command */ |
| 7580 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7581 | return MBX_NOT_FINISHED; |
| 7582 | |
| 7583 | /* Check for mailbox command service token */ |
| 7584 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7585 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7586 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7587 | return MBX_NOT_FINISHED; |
| 7588 | } |
| 7589 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7590 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7591 | return MBX_NOT_FINISHED; |
| 7592 | } |
| 7593 | if (unlikely(phba->sli.mbox_active)) { |
| 7594 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7595 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7596 | "0384 There is pending active mailbox cmd\n"); |
| 7597 | return MBX_NOT_FINISHED; |
| 7598 | } |
| 7599 | /* Take the mailbox command service token */ |
| 7600 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7601 | |
| 7602 | /* Get the next mailbox command from head of queue */ |
| 7603 | mboxq = lpfc_mbox_get(phba); |
| 7604 | |
| 7605 | /* If no more mailbox command waiting for post, we're done */ |
| 7606 | if (!mboxq) { |
| 7607 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7608 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7609 | return MBX_SUCCESS; |
| 7610 | } |
| 7611 | phba->sli.mbox_active = mboxq; |
| 7612 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7613 | |
| 7614 | /* Check device readiness for posting mailbox command */ |
| 7615 | rc = lpfc_mbox_dev_check(phba); |
| 7616 | if (unlikely(rc)) |
| 7617 | /* Driver clean routine will clean up pending mailbox */ |
| 7618 | goto out_not_finished; |
| 7619 | |
| 7620 | /* Prepare the mbox command to be posted */ |
| 7621 | mqe = &mboxq->u.mqe; |
| 7622 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7623 | |
| 7624 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7625 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7626 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7627 | |
| 7628 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7629 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7630 | "x%x x%x\n", |
| 7631 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7632 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7633 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7634 | phba->pport->port_state, psli->sli_flag); |
| 7635 | |
| 7636 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7637 | if (mboxq->vport) { |
| 7638 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7639 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7640 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7641 | mbx_cmnd, mqe->un.mb_words[0], |
| 7642 | mqe->un.mb_words[1]); |
| 7643 | } else { |
| 7644 | lpfc_debugfs_disc_trc(phba->pport, |
| 7645 | LPFC_DISC_TRC_MBOX, |
| 7646 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7647 | mbx_cmnd, mqe->un.mb_words[0], |
| 7648 | mqe->un.mb_words[1]); |
| 7649 | } |
| 7650 | } |
| 7651 | psli->slistat.mbox_cmd++; |
| 7652 | |
| 7653 | /* Post the mailbox command to the port */ |
| 7654 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7655 | if (rc != MBX_SUCCESS) { |
| 7656 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7657 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7658 | "cannot issue Data: x%x x%x\n", |
| 7659 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7660 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7661 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7662 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7663 | psli->sli_flag, MBX_NOWAIT); |
| 7664 | goto out_not_finished; |
| 7665 | } |
| 7666 | |
| 7667 | return rc; |
| 7668 | |
| 7669 | out_not_finished: |
| 7670 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7671 | if (phba->sli.mbox_active) { |
| 7672 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7673 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7674 | /* Release the token */ |
| 7675 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7676 | phba->sli.mbox_active = NULL; |
| 7677 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7678 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7679 | |
| 7680 | return MBX_NOT_FINISHED; |
| 7681 | } |
| 7682 | |
| 7683 | /** |
| 7684 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7685 | * @phba: Pointer to HBA context object. |
| 7686 | * @pmbox: Pointer to mailbox object. |
| 7687 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7688 | * |
| 7689 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7690 | * the API jump table function pointer from the lpfc_hba struct. |
| 7691 | * |
| 7692 | * Return codes the caller owns the mailbox command after the return of the |
| 7693 | * function. |
| 7694 | **/ |
| 7695 | int |
| 7696 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7697 | { |
| 7698 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7699 | } |
| 7700 | |
| 7701 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7702 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7703 | * @phba: The hba struct for which this call is being executed. |
| 7704 | * @dev_grp: The HBA PCI-Device group number. |
| 7705 | * |
| 7706 | * This routine sets up the mbox interface API function jump table in @phba |
| 7707 | * struct. |
| 7708 | * Returns: 0 - success, -ENODEV - failure. |
| 7709 | **/ |
| 7710 | int |
| 7711 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7712 | { |
| 7713 | |
| 7714 | switch (dev_grp) { |
| 7715 | case LPFC_PCI_DEV_LP: |
| 7716 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7717 | phba->lpfc_sli_handle_slow_ring_event = |
| 7718 | lpfc_sli_handle_slow_ring_event_s3; |
| 7719 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7720 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7721 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7722 | break; |
| 7723 | case LPFC_PCI_DEV_OC: |
| 7724 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7725 | phba->lpfc_sli_handle_slow_ring_event = |
| 7726 | lpfc_sli_handle_slow_ring_event_s4; |
| 7727 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7728 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7729 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7730 | break; |
| 7731 | default: |
| 7732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7733 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7734 | dev_grp); |
| 7735 | return -ENODEV; |
| 7736 | break; |
| 7737 | } |
| 7738 | return 0; |
| 7739 | } |
| 7740 | |
| 7741 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7742 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7743 | * @phba: Pointer to HBA context object. |
| 7744 | * @pring: Pointer to driver SLI ring object. |
| 7745 | * @piocb: Pointer to address of newly added command iocb. |
| 7746 | * |
| 7747 | * This function is called with hbalock held to add a command |
| 7748 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7749 | * to the ring. |
| 7750 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7751 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7752 | __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] | 7753 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | { |
| 7755 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7756 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7757 | } |
| 7758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7760 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7761 | * @phba: Pointer to HBA context object. |
| 7762 | * @pring: Pointer to driver SLI ring object. |
| 7763 | * @piocb: Pointer to address of newly added command iocb. |
| 7764 | * |
| 7765 | * This function is called with hbalock held before a new |
| 7766 | * iocb is submitted to the firmware. This function checks |
| 7767 | * txq to flush the iocbs in txq to Firmware before |
| 7768 | * submitting new iocbs to the Firmware. |
| 7769 | * If there are iocbs in the txq which need to be submitted |
| 7770 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7771 | * of the txq after dequeuing it from txq. |
| 7772 | * If there is no iocb in the txq then the function will return |
| 7773 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7774 | * *piocb to find if there are more commands in the txq. |
| 7775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7776 | static struct lpfc_iocbq * |
| 7777 | 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] | 7778 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7779 | { |
| 7780 | struct lpfc_iocbq * nextiocb; |
| 7781 | |
| 7782 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7783 | if (!nextiocb) { |
| 7784 | nextiocb = *piocb; |
| 7785 | *piocb = NULL; |
| 7786 | } |
| 7787 | |
| 7788 | return nextiocb; |
| 7789 | } |
| 7790 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7791 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7792 | * __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] | 7793 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7794 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7795 | * @piocb: Pointer to command iocb. |
| 7796 | * @flag: Flag indicating if this command can be put into txq. |
| 7797 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7798 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7799 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7800 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7801 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7802 | * this function allows only iocbs for posting buffers. This function finds |
| 7803 | * next available slot in the command ring and posts the command to the |
| 7804 | * available slot and writes the port attention register to request HBA start |
| 7805 | * processing new iocb. If there is no slot available in the ring and |
| 7806 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7807 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7808 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7809 | * This function is called with hbalock held. The function will return success |
| 7810 | * after it successfully submit the iocb to firmware or after adding to the |
| 7811 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7812 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7813 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7814 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7815 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7816 | { |
| 7817 | struct lpfc_iocbq *nextiocb; |
| 7818 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7819 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7820 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7821 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7822 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7823 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7824 | lpfc_printf_log(phba, KERN_ERR, |
| 7825 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7826 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7827 | piocb->iocb.ulpCommand); |
| 7828 | dump_stack(); |
| 7829 | return IOCB_ERROR; |
| 7830 | } |
| 7831 | |
| 7832 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7833 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7834 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7835 | return IOCB_ERROR; |
| 7836 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7837 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7838 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7839 | return IOCB_ERROR; |
| 7840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7841 | /* |
| 7842 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7843 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7844 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7845 | return IOCB_ERROR; |
| 7846 | |
| 7847 | /* |
| 7848 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7849 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7850 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7851 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7852 | goto iocb_busy; |
| 7853 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7854 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7855 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7856 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7857 | * can be issued if the link is not up. |
| 7858 | */ |
| 7859 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7860 | case CMD_GEN_REQUEST64_CR: |
| 7861 | case CMD_GEN_REQUEST64_CX: |
| 7862 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7863 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7864 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7865 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7866 | MENLO_TRANSPORT_TYPE)) |
| 7867 | |
| 7868 | goto iocb_busy; |
| 7869 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7870 | case CMD_QUE_RING_BUF_CN: |
| 7871 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7872 | /* |
| 7873 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7874 | * completion, iocb_cmpl MUST be 0. |
| 7875 | */ |
| 7876 | if (piocb->iocb_cmpl) |
| 7877 | piocb->iocb_cmpl = NULL; |
| 7878 | /*FALLTHROUGH*/ |
| 7879 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7880 | case CMD_CLOSE_XRI_CN: |
| 7881 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7882 | break; |
| 7883 | default: |
| 7884 | goto iocb_busy; |
| 7885 | } |
| 7886 | |
| 7887 | /* |
| 7888 | * For FCP commands, we must be in a state where we can process link |
| 7889 | * attention events. |
| 7890 | */ |
| 7891 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7892 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7893 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7894 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7896 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7897 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7898 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7899 | |
| 7900 | if (iocb) |
| 7901 | lpfc_sli_update_ring(phba, pring); |
| 7902 | else |
| 7903 | lpfc_sli_update_full_ring(phba, pring); |
| 7904 | |
| 7905 | if (!piocb) |
| 7906 | return IOCB_SUCCESS; |
| 7907 | |
| 7908 | goto out_busy; |
| 7909 | |
| 7910 | iocb_busy: |
| 7911 | pring->stats.iocb_cmd_delay++; |
| 7912 | |
| 7913 | out_busy: |
| 7914 | |
| 7915 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7916 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7917 | return IOCB_SUCCESS; |
| 7918 | } |
| 7919 | |
| 7920 | return IOCB_BUSY; |
| 7921 | } |
| 7922 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7923 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7924 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7925 | * @phba: Pointer to HBA context object. |
| 7926 | * @piocb: Pointer to command iocb. |
| 7927 | * @sglq: Pointer to the scatter gather queue object. |
| 7928 | * |
| 7929 | * This routine converts the bpl or bde that is in the IOCB |
| 7930 | * to a sgl list for the sli4 hardware. The physical address |
| 7931 | * of the bpl/bde is converted back to a virtual address. |
| 7932 | * If the IOCB contains a BPL then the list of BDE's is |
| 7933 | * converted to sli4_sge's. If the IOCB contains a single |
| 7934 | * BDE then it is converted to a single sli_sge. |
| 7935 | * The IOCB is still in cpu endianess so the contents of |
| 7936 | * the bpl can be used without byte swapping. |
| 7937 | * |
| 7938 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7939 | **/ |
| 7940 | static uint16_t |
| 7941 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7942 | struct lpfc_sglq *sglq) |
| 7943 | { |
| 7944 | uint16_t xritag = NO_XRI; |
| 7945 | struct ulp_bde64 *bpl = NULL; |
| 7946 | struct ulp_bde64 bde; |
| 7947 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7948 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7949 | IOCB_t *icmd; |
| 7950 | int numBdes = 0; |
| 7951 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7952 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7953 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7954 | |
| 7955 | if (!piocbq || !sglq) |
| 7956 | return xritag; |
| 7957 | |
| 7958 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7959 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7960 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7961 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7962 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7963 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7964 | sizeof(struct ulp_bde64); |
| 7965 | /* The addrHigh and addrLow fields within the IOCB |
| 7966 | * have not been byteswapped yet so there is no |
| 7967 | * need to swap them back. |
| 7968 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7969 | if (piocbq->context3) |
| 7970 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7971 | else |
| 7972 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7973 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7974 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7975 | if (!bpl) |
| 7976 | return xritag; |
| 7977 | |
| 7978 | for (i = 0; i < numBdes; i++) { |
| 7979 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7980 | sgl->addr_hi = bpl->addrHigh; |
| 7981 | sgl->addr_lo = bpl->addrLow; |
| 7982 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7983 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7984 | if ((i+1) == numBdes) |
| 7985 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7986 | else |
| 7987 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7988 | /* swap the size field back to the cpu so we |
| 7989 | * can assign it to the sgl. |
| 7990 | */ |
| 7991 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7992 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7993 | /* The offsets in the sgl need to be accumulated |
| 7994 | * separately for the request and reply lists. |
| 7995 | * The request is always first, the reply follows. |
| 7996 | */ |
| 7997 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7998 | /* add up the reply sg entries */ |
| 7999 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8000 | inbound++; |
| 8001 | /* first inbound? reset the offset */ |
| 8002 | if (inbound == 1) |
| 8003 | offset = 0; |
| 8004 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8005 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8006 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8007 | offset += bde.tus.f.bdeSize; |
| 8008 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8009 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8010 | bpl++; |
| 8011 | sgl++; |
| 8012 | } |
| 8013 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8014 | /* The addrHigh and addrLow fields of the BDE have not |
| 8015 | * been byteswapped yet so they need to be swapped |
| 8016 | * before putting them in the sgl. |
| 8017 | */ |
| 8018 | sgl->addr_hi = |
| 8019 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8020 | sgl->addr_lo = |
| 8021 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8022 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8023 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8024 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8025 | sgl->sge_len = |
| 8026 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8027 | } |
| 8028 | return sglq->sli4_xritag; |
| 8029 | } |
| 8030 | |
| 8031 | /** |
| 8032 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 8033 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8034 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 8035 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8036 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 8037 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8038 | * |
| 8039 | * Return: index into SLI4 fast-path FCP queue index. |
| 8040 | **/ |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8041 | static inline uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8042 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8043 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8044 | struct lpfc_vector_map_info *cpup; |
| 8045 | int chann, cpu; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8046 | |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 8047 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
| 8048 | && phba->cfg_fcp_io_channel > 1) { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8049 | cpu = smp_processor_id(); |
| 8050 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 8051 | cpup = phba->sli4_hba.cpu_map; |
| 8052 | cpup += cpu; |
| 8053 | return cpup->channel_id; |
| 8054 | } |
| 8055 | chann = cpu; |
| 8056 | } |
| 8057 | chann = atomic_add_return(1, &phba->fcp_qidx); |
| 8058 | chann = (chann % phba->cfg_fcp_io_channel); |
| 8059 | return chann; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8064 | * @phba: Pointer to HBA context object. |
| 8065 | * @piocb: Pointer to command iocb. |
| 8066 | * @wqe: Pointer to the work queue entry. |
| 8067 | * |
| 8068 | * This routine converts the iocb command to its Work Queue Entry |
| 8069 | * equivalent. The wqe pointer should not have any fields set when |
| 8070 | * this routine is called because it will memcpy over them. |
| 8071 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8072 | * wqe. |
| 8073 | * |
| 8074 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8075 | **/ |
| 8076 | static int |
| 8077 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8078 | union lpfc_wqe *wqe) |
| 8079 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8080 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8081 | uint8_t ct = 0; |
| 8082 | uint32_t fip; |
| 8083 | uint32_t abort_tag; |
| 8084 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8085 | uint8_t cmnd; |
| 8086 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8087 | uint16_t abrt_iotag; |
| 8088 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8089 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8090 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8091 | int numBdes, i; |
| 8092 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8093 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8094 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8095 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8096 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8097 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8098 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8099 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8100 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8101 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8102 | command_type = ELS_COMMAND_FIP; |
| 8103 | else |
| 8104 | command_type = ELS_COMMAND_NON_FIP; |
| 8105 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8106 | /* Some of the fields are in the right position already */ |
| 8107 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 8108 | abort_tag = (uint32_t) iocbq->iotag; |
| 8109 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8110 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8111 | /* words0-2 bpl convert bde */ |
| 8112 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8113 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8114 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8115 | bpl = (struct ulp_bde64 *) |
| 8116 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8117 | if (!bpl) |
| 8118 | return IOCB_ERROR; |
| 8119 | |
| 8120 | /* Should already be byte swapped. */ |
| 8121 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8122 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8123 | /* swap the size field back to the cpu so we |
| 8124 | * can assign it to the sgl. |
| 8125 | */ |
| 8126 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8127 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8128 | total_len = 0; |
| 8129 | for (i = 0; i < numBdes; i++) { |
| 8130 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8131 | total_len += bde.tus.f.bdeSize; |
| 8132 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8133 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8134 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8135 | |
| 8136 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8137 | cmnd = iocbq->iocb.ulpCommand; |
| 8138 | |
| 8139 | switch (iocbq->iocb.ulpCommand) { |
| 8140 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8141 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8142 | ndlp = iocbq->context_un.ndlp; |
| 8143 | else |
| 8144 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8145 | if (!iocbq->iocb.ulpLe) { |
| 8146 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8147 | "2007 Only Limited Edition cmd Format" |
| 8148 | " supported 0x%x\n", |
| 8149 | iocbq->iocb.ulpCommand); |
| 8150 | return IOCB_ERROR; |
| 8151 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8152 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8153 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8154 | /* Els_reguest64 has a TMO */ |
| 8155 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8156 | iocbq->iocb.ulpTimeout); |
| 8157 | /* Need a VF for word 4 set the vf bit*/ |
| 8158 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8159 | /* And a VFID for word 12 */ |
| 8160 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8161 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8162 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8163 | iocbq->iocb.ulpContext); |
| 8164 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8165 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8166 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8167 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8168 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8169 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8170 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8171 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8172 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8173 | &phba->sli4_hba.sli_intf); |
| 8174 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8175 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8176 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8177 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8178 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8179 | *pcmd == ELS_CMD_PLOGI)) { |
| 8180 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8181 | bf_set(els_req64_sid, &wqe->els_req, |
| 8182 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8183 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8184 | !(phba->fc_topology == |
| 8185 | LPFC_TOPOLOGY_LOOP)) |
| 8186 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8187 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8188 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8189 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8190 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8191 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8192 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8193 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8194 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8195 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8196 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8197 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8198 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8199 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8200 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8201 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8202 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8203 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8204 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8205 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8206 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8207 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8208 | iocbq->iocb.un.ulpWord[3]); |
| 8209 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8210 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8211 | /* The entire sequence is transmitted for this IOCB */ |
| 8212 | xmit_len = total_len; |
| 8213 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8214 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8215 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8216 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8217 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8218 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8219 | /* word4 relative_offset memcpy */ |
| 8220 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8221 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8222 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8223 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8224 | LPFC_WQE_IOD_WRITE); |
| 8225 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8226 | LPFC_WQE_LENLOC_WORD12); |
| 8227 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8228 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8229 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8230 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8231 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8232 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8233 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8234 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8235 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8236 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8237 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8238 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8239 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8240 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8241 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8242 | LPFC_WQE_LENLOC_WORD3); |
| 8243 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8244 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8245 | case CMD_FCP_IWRITE64_CR: |
| 8246 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8247 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8248 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8249 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8250 | xmit_len + sizeof(struct fcp_rsp)); |
| 8251 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8252 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8253 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8254 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8255 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8256 | iocbq->iocb.ulpFCP2Rcvy); |
| 8257 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8258 | /* Always open the exchange */ |
| 8259 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8260 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8261 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8262 | LPFC_WQE_LENLOC_WORD4); |
| 8263 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8264 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8265 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8266 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8267 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
| 8268 | if (phba->cfg_XLanePriority) { |
| 8269 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8270 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8271 | (phba->cfg_XLanePriority << 1)); |
| 8272 | } |
| 8273 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8274 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8275 | case CMD_FCP_IREAD64_CR: |
| 8276 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8277 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8278 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8279 | xmit_len + sizeof(struct fcp_rsp)); |
| 8280 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8281 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8282 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8283 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8284 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8285 | iocbq->iocb.ulpFCP2Rcvy); |
| 8286 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8287 | /* Always open the exchange */ |
| 8288 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8289 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8290 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8291 | LPFC_WQE_LENLOC_WORD4); |
| 8292 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8293 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8294 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8295 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8296 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
| 8297 | if (phba->cfg_XLanePriority) { |
| 8298 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8299 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8300 | (phba->cfg_XLanePriority << 1)); |
| 8301 | } |
| 8302 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8303 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8304 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8305 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8306 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8307 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8308 | xmit_len + sizeof(struct fcp_rsp)); |
| 8309 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8310 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8311 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8312 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8313 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8314 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8315 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8316 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8317 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8318 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8319 | LPFC_WQE_LENLOC_NONE); |
| 8320 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8321 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8322 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8323 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8324 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
| 8325 | if (phba->cfg_XLanePriority) { |
| 8326 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8327 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8328 | (phba->cfg_XLanePriority << 1)); |
| 8329 | } |
| 8330 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8331 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8332 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8333 | /* For this command calculate the xmit length of the |
| 8334 | * request bde. |
| 8335 | */ |
| 8336 | xmit_len = 0; |
| 8337 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8338 | sizeof(struct ulp_bde64); |
| 8339 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8340 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8341 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8342 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8343 | xmit_len += bde.tus.f.bdeSize; |
| 8344 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8345 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8346 | wqe->gen_req.request_payload_len = xmit_len; |
| 8347 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8348 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8349 | /* word6 context tag copied in memcpy */ |
| 8350 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8351 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8352 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8353 | "2015 Invalid CT %x command 0x%x\n", |
| 8354 | ct, iocbq->iocb.ulpCommand); |
| 8355 | return IOCB_ERROR; |
| 8356 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8357 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8358 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8359 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8360 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8361 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8362 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8363 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8364 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8365 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8366 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8367 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8368 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8369 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8370 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8371 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8372 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8373 | /* word4 */ |
| 8374 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8375 | /* word5 iocb=rsvd wge=did */ |
| 8376 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8377 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8378 | |
| 8379 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8380 | &phba->sli4_hba.sli_intf); |
| 8381 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8382 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8383 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8384 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8385 | iocbq->vport->fc_myDID); |
| 8386 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8387 | bf_set(wqe_els_did, |
| 8388 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8389 | } |
| 8390 | } |
| 8391 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8392 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8393 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8394 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8395 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8396 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8397 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8398 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8399 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8400 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8401 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8402 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8403 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8404 | LPFC_WQE_LENLOC_WORD3); |
| 8405 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8406 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8407 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8408 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8409 | iocbq->context2)->virt); |
| 8410 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8411 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8412 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8413 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8414 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8415 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8416 | phba->vpi_ids[phba->pport->vpi]); |
| 8417 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8418 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8419 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8420 | case CMD_CLOSE_XRI_CN: |
| 8421 | case CMD_ABORT_XRI_CN: |
| 8422 | case CMD_ABORT_XRI_CX: |
| 8423 | /* words 0-2 memcpy should be 0 rserved */ |
| 8424 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8425 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8426 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8427 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8428 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8429 | } else |
| 8430 | fip = 0; |
| 8431 | |
| 8432 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8433 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8434 | * The link is down, or the command was ELS_FIP |
| 8435 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8436 | * on the wire. |
| 8437 | */ |
| 8438 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8439 | else |
| 8440 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8441 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8442 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8443 | wqe->abort_cmd.rsrvd5 = 0; |
| 8444 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8445 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8446 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8447 | /* |
| 8448 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8449 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8450 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8451 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8452 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8453 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8454 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8455 | cmnd = CMD_ABORT_XRI_CX; |
| 8456 | command_type = OTHER_COMMAND; |
| 8457 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8458 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8459 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8460 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8461 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8462 | * we re-construct this WQE here based on information in |
| 8463 | * iocbq from scratch. |
| 8464 | */ |
| 8465 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8466 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8467 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8468 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8469 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8470 | LPFC_ABTS_UNSOL_INT) { |
| 8471 | /* ABTS sent by initiator to CT exchange, the |
| 8472 | * RX_ID field will be filled with the newly |
| 8473 | * allocated responder XRI. |
| 8474 | */ |
| 8475 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8476 | iocbq->sli4_xritag); |
| 8477 | } else { |
| 8478 | /* ABTS sent by responder to CT exchange, the |
| 8479 | * RX_ID field will be filled with the responder |
| 8480 | * RX_ID from ABTS. |
| 8481 | */ |
| 8482 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8483 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8484 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8485 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8486 | 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] | 8487 | |
| 8488 | /* Use CT=VPI */ |
| 8489 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8490 | ndlp->nlp_DID); |
| 8491 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8492 | iocbq->iocb.ulpContext); |
| 8493 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8494 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8495 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8496 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8497 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8498 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8499 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8500 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8501 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8502 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8503 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8504 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8505 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8506 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8507 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8508 | } |
| 8509 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8510 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8511 | case CMD_XRI_ABORTED_CX: |
| 8512 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8513 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8514 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8515 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8516 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8517 | default: |
| 8518 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8519 | "2014 Invalid command 0x%x\n", |
| 8520 | iocbq->iocb.ulpCommand); |
| 8521 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8522 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8523 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8524 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8525 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8526 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8527 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8528 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8529 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8530 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8531 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8532 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8533 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8534 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8535 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8536 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8537 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8538 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8539 | 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] | 8540 | return 0; |
| 8541 | } |
| 8542 | |
| 8543 | /** |
| 8544 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8545 | * @phba: Pointer to HBA context object. |
| 8546 | * @ring_number: SLI ring number to issue iocb on. |
| 8547 | * @piocb: Pointer to command iocb. |
| 8548 | * @flag: Flag indicating if this command can be put into txq. |
| 8549 | * |
| 8550 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8551 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8552 | * |
| 8553 | * This function is called with hbalock held. The function will return success |
| 8554 | * after it successfully submit the iocb to firmware or after adding to the |
| 8555 | * txq. |
| 8556 | **/ |
| 8557 | static int |
| 8558 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8559 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8560 | { |
| 8561 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8562 | union lpfc_wqe wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8563 | struct lpfc_queue *wq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8564 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8565 | |
| 8566 | if (piocb->sli4_xritag == NO_XRI) { |
| 8567 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8568 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8569 | sglq = NULL; |
| 8570 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8571 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8572 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8573 | __lpfc_sli_ringtx_put(phba, |
| 8574 | pring, piocb); |
| 8575 | return IOCB_SUCCESS; |
| 8576 | } else { |
| 8577 | return IOCB_BUSY; |
| 8578 | } |
| 8579 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8580 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8581 | if (!sglq) { |
| 8582 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8583 | __lpfc_sli_ringtx_put(phba, |
| 8584 | pring, |
| 8585 | piocb); |
| 8586 | return IOCB_SUCCESS; |
| 8587 | } else |
| 8588 | return IOCB_BUSY; |
| 8589 | } |
| 8590 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8591 | } |
| 8592 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8593 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8594 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8595 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8596 | /* |
| 8597 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8598 | * sglq is on the active list |
| 8599 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8600 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8601 | if (!sglq) |
| 8602 | return IOCB_ERROR; |
| 8603 | } |
| 8604 | |
| 8605 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8606 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8607 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8608 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8609 | return IOCB_ERROR; |
| 8610 | } |
| 8611 | |
| 8612 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8613 | return IOCB_ERROR; |
| 8614 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8615 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8616 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 8617 | if (!phba->cfg_EnableXLane || (!(piocb->iocb_flag & |
| 8618 | LPFC_IO_OAS))) { |
| 8619 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
| 8620 | } else { |
| 8621 | wq = phba->sli4_hba.oas_wq; |
| 8622 | } |
| 8623 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8624 | return IOCB_ERROR; |
| 8625 | } else { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8626 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 8627 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8628 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8629 | return IOCB_ERROR; |
| 8630 | } |
| 8631 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8632 | |
| 8633 | return 0; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8637 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8638 | * |
| 8639 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8640 | * pointer from the lpfc_hba struct. |
| 8641 | * |
| 8642 | * Return codes: |
| 8643 | * IOCB_ERROR - Error |
| 8644 | * IOCB_SUCCESS - Success |
| 8645 | * IOCB_BUSY - Busy |
| 8646 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8647 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8648 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8649 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8650 | { |
| 8651 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8652 | } |
| 8653 | |
| 8654 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8655 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8656 | * @phba: The hba struct for which this call is being executed. |
| 8657 | * @dev_grp: The HBA PCI-Device group number. |
| 8658 | * |
| 8659 | * This routine sets up the SLI interface API function jump table in @phba |
| 8660 | * struct. |
| 8661 | * Returns: 0 - success, -ENODEV - failure. |
| 8662 | **/ |
| 8663 | int |
| 8664 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8665 | { |
| 8666 | |
| 8667 | switch (dev_grp) { |
| 8668 | case LPFC_PCI_DEV_LP: |
| 8669 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8670 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8671 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8672 | case LPFC_PCI_DEV_OC: |
| 8673 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8674 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8675 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8676 | default: |
| 8677 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8678 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8679 | dev_grp); |
| 8680 | return -ENODEV; |
| 8681 | break; |
| 8682 | } |
| 8683 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8684 | return 0; |
| 8685 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8686 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8687 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8688 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8689 | * @phba: Pointer to HBA context object. |
| 8690 | * @pring: Pointer to driver SLI ring object. |
| 8691 | * @piocb: Pointer to command iocb. |
| 8692 | * @flag: Flag indicating if this command can be put into txq. |
| 8693 | * |
| 8694 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8695 | * function. This function gets the hbalock and calls |
| 8696 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8697 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8698 | * functions which do not hold hbalock. |
| 8699 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8700 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8701 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8702 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8703 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8704 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8705 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8706 | struct lpfc_queue *fpeq; |
| 8707 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8708 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8709 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8710 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8711 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8712 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 8713 | if (!phba->cfg_EnableXLane || (!(piocb->iocb_flag & |
| 8714 | LPFC_IO_OAS))) { |
| 8715 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8716 | return IOCB_ERROR; |
| 8717 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
| 8718 | piocb->fcp_wqidx = idx; |
| 8719 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; |
| 8720 | } else { |
| 8721 | if (unlikely(!phba->sli4_hba.oas_wq)) |
| 8722 | return IOCB_ERROR; |
| 8723 | idx = 0; |
| 8724 | piocb->fcp_wqidx = 0; |
| 8725 | ring_number = LPFC_FCP_OAS_RING; |
| 8726 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8727 | pring = &phba->sli.ring[ring_number]; |
| 8728 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8729 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8730 | flag); |
| 8731 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8732 | |
| 8733 | if (lpfc_fcp_look_ahead) { |
| 8734 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
| 8735 | |
| 8736 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 8737 | fcp_eq_in_use)) { |
| 8738 | |
| 8739 | /* Get associated EQ with this index */ |
| 8740 | fpeq = phba->sli4_hba.hba_eq[idx]; |
| 8741 | |
| 8742 | /* Turn off interrupts from this EQ */ |
| 8743 | lpfc_sli4_eq_clr_intr(fpeq); |
| 8744 | |
| 8745 | /* |
| 8746 | * Process all the events on FCP EQ |
| 8747 | */ |
| 8748 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 8749 | lpfc_sli4_hba_handle_eqe(phba, |
| 8750 | eqe, idx); |
| 8751 | fpeq->EQ_processed++; |
| 8752 | } |
| 8753 | |
| 8754 | /* Always clear and re-arm the EQ */ |
| 8755 | lpfc_sli4_eq_release(fpeq, |
| 8756 | LPFC_QUEUE_REARM); |
| 8757 | } |
| 8758 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 8759 | } |
| 8760 | } else { |
| 8761 | pring = &phba->sli.ring[ring_number]; |
| 8762 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8763 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8764 | flag); |
| 8765 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8766 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8767 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8768 | } else { |
| 8769 | /* For now, SLI2/3 will still use hbalock */ |
| 8770 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8771 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8772 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8773 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8774 | return rc; |
| 8775 | } |
| 8776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8778 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8779 | * @phba: Pointer to HBA context object. |
| 8780 | * |
| 8781 | * This function is called while driver attaches with the |
| 8782 | * HBA to setup the extra ring. The extra ring is used |
| 8783 | * only when driver needs to support target mode functionality |
| 8784 | * or IP over FC functionalities. |
| 8785 | * |
| 8786 | * This function is called with no lock held. |
| 8787 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8788 | static int |
| 8789 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8790 | { |
| 8791 | struct lpfc_sli *psli; |
| 8792 | struct lpfc_sli_ring *pring; |
| 8793 | |
| 8794 | psli = &phba->sli; |
| 8795 | |
| 8796 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8797 | |
| 8798 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8799 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8800 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8801 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8802 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8803 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8804 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8805 | /* and give them to the extra ring */ |
| 8806 | pring = &psli->ring[psli->extra_ring]; |
| 8807 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8808 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8809 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8810 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8811 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8812 | |
| 8813 | /* Setup default profile for this ring */ |
| 8814 | pring->iotag_max = 4096; |
| 8815 | pring->num_mask = 1; |
| 8816 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8817 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8818 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8819 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8820 | return 0; |
| 8821 | } |
| 8822 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8823 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8824 | * @phba: Pointer to HBA context object. |
| 8825 | * @iocbq: Pointer to iocb object. |
| 8826 | * |
| 8827 | * The async_event handler calls this routine when it receives |
| 8828 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8829 | * this event when an Abort Sequence request to an rport fails |
| 8830 | * twice in succession. The abort could be originated by the |
| 8831 | * driver or by the port. The ABTS could have been for an ELS |
| 8832 | * or FCP IO. The port only generates this event when an ABTS |
| 8833 | * fails to complete after one retry. |
| 8834 | */ |
| 8835 | static void |
| 8836 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8837 | struct lpfc_iocbq *iocbq) |
| 8838 | { |
| 8839 | struct lpfc_nodelist *ndlp = NULL; |
| 8840 | uint16_t rpi = 0, vpi = 0; |
| 8841 | struct lpfc_vport *vport = NULL; |
| 8842 | |
| 8843 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8844 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8845 | rpi = iocbq->iocb.ulpContext; |
| 8846 | |
| 8847 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8848 | "3092 Port generated ABTS async event " |
| 8849 | "on vpi %d rpi %d status 0x%x\n", |
| 8850 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8851 | |
| 8852 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8853 | if (!vport) |
| 8854 | goto err_exit; |
| 8855 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8856 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8857 | goto err_exit; |
| 8858 | |
| 8859 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8860 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8861 | return; |
| 8862 | |
| 8863 | err_exit: |
| 8864 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8865 | "3095 Event Context not found, no " |
| 8866 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8867 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8868 | vpi, rpi); |
| 8869 | } |
| 8870 | |
| 8871 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8872 | * @phba: pointer to HBA context object. |
| 8873 | * @ndlp: nodelist pointer for the impacted rport. |
| 8874 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8875 | * |
| 8876 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8877 | * port. The port generates this event when an abort exchange request to an |
| 8878 | * rport fails twice in succession with no reply. The abort could be originated |
| 8879 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8880 | */ |
| 8881 | void |
| 8882 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8883 | struct lpfc_nodelist *ndlp, |
| 8884 | struct sli4_wcqe_xri_aborted *axri) |
| 8885 | { |
| 8886 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8887 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8888 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8889 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8890 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8891 | "3115 Node Context not found, driver " |
| 8892 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8893 | return; |
| 8894 | } |
| 8895 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8896 | vport = ndlp->vport; |
| 8897 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8898 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8899 | "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] | 8900 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8901 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8902 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8903 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8904 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8905 | /* |
| 8906 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8907 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8908 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8909 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8910 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8911 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8912 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8913 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8914 | } |
| 8915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8917 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8918 | * @phba: Pointer to HBA context object. |
| 8919 | * @pring: Pointer to driver SLI ring object. |
| 8920 | * @iocbq: Pointer to iocb object. |
| 8921 | * |
| 8922 | * This function is called by the slow ring event handler |
| 8923 | * function when there is an ASYNC event iocb in the ring. |
| 8924 | * This function is called with no lock held. |
| 8925 | * Currently this function handles only temperature related |
| 8926 | * ASYNC events. The function decodes the temperature sensor |
| 8927 | * event message and posts events for the management applications. |
| 8928 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8929 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8930 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8931 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8932 | { |
| 8933 | IOCB_t *icmd; |
| 8934 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8935 | struct temp_event temp_event_data; |
| 8936 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8937 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8938 | |
| 8939 | icmd = &iocbq->iocb; |
| 8940 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8941 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8942 | switch (evt_code) { |
| 8943 | case ASYNC_TEMP_WARN: |
| 8944 | case ASYNC_TEMP_SAFE: |
| 8945 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8946 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8947 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8948 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8949 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8950 | "0347 Adapter is very hot, please take " |
| 8951 | "corrective action. temperature : %d Celsius\n", |
| 8952 | (uint32_t) icmd->ulpContext); |
| 8953 | } else { |
| 8954 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8955 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8956 | "0340 Adapter temperature is OK now. " |
| 8957 | "temperature : %d Celsius\n", |
| 8958 | (uint32_t) icmd->ulpContext); |
| 8959 | } |
| 8960 | |
| 8961 | /* Send temperature change event to applications */ |
| 8962 | shost = lpfc_shost_from_vport(phba->pport); |
| 8963 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8964 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8965 | LPFC_NL_VENDOR_ID); |
| 8966 | break; |
| 8967 | case ASYNC_STATUS_CN: |
| 8968 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8969 | break; |
| 8970 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8971 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8972 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8973 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8974 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8975 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8976 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8977 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8978 | "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] | 8979 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8980 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8981 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8982 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8983 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8984 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8985 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8986 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8987 | } |
| 8988 | |
| 8989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8991 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8992 | * @phba: Pointer to HBA context object. |
| 8993 | * |
| 8994 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8995 | * number of iocbs per ring and iotags. This function is |
| 8996 | * called while driver attach to the HBA and before the |
| 8997 | * interrupts are enabled. So there is no need for locking. |
| 8998 | * |
| 8999 | * This function always returns 0. |
| 9000 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9001 | int |
| 9002 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9003 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9004 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9005 | struct lpfc_sli *psli = &phba->sli; |
| 9006 | struct lpfc_sli_ring *pring; |
| 9007 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9008 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 9009 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9010 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9011 | psli->sli_flag = 0; |
| 9012 | psli->fcp_ring = LPFC_FCP_RING; |
| 9013 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9014 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9015 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9016 | psli->iocbq_lookup = NULL; |
| 9017 | psli->iocbq_lookup_len = 0; |
| 9018 | psli->last_iotag = 0; |
| 9019 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9020 | for (i = 0; i < psli->num_rings; i++) { |
| 9021 | pring = &psli->ring[i]; |
| 9022 | switch (i) { |
| 9023 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9024 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9025 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9026 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9027 | pring->sli.sli3.numCiocb += |
| 9028 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9029 | pring->sli.sli3.numRiocb += |
| 9030 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9031 | pring->sli.sli3.numCiocb += |
| 9032 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9033 | pring->sli.sli3.numRiocb += |
| 9034 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9035 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9036 | SLI3_IOCB_CMD_SIZE : |
| 9037 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9038 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9039 | SLI3_IOCB_RSP_SIZE : |
| 9040 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9041 | pring->iotag_ctr = 0; |
| 9042 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9043 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9044 | pring->fast_iotag = pring->iotag_max; |
| 9045 | pring->num_mask = 0; |
| 9046 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9047 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9048 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9049 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9050 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9051 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9052 | SLI3_IOCB_CMD_SIZE : |
| 9053 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9054 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9055 | SLI3_IOCB_RSP_SIZE : |
| 9056 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9057 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9058 | pring->num_mask = 0; |
| 9059 | break; |
| 9060 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9061 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9062 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9063 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9064 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9065 | SLI3_IOCB_CMD_SIZE : |
| 9066 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9067 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9068 | SLI3_IOCB_RSP_SIZE : |
| 9069 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9070 | pring->fast_iotag = 0; |
| 9071 | pring->iotag_ctr = 0; |
| 9072 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9073 | pring->lpfc_sli_rcv_async_status = |
| 9074 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9075 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9076 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9077 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9078 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9079 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9080 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9081 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9082 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9083 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9084 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9085 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9086 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9087 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9088 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9089 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9090 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9091 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9092 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9093 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9094 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9095 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9096 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9097 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9098 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9099 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9100 | break; |
| 9101 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9102 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9103 | pring->sli.sli3.sizeCiocb) + |
| 9104 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9105 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9106 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9107 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9108 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9109 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9110 | phba->brd_no, totiocbsize, |
| 9111 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9112 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9113 | if (phba->cfg_multi_ring_support == 2) |
| 9114 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9115 | |
| 9116 | return 0; |
| 9117 | } |
| 9118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9120 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9121 | * @phba: Pointer to HBA context object. |
| 9122 | * |
| 9123 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 9124 | * ring. This function also initializes ring indices of each ring. |
| 9125 | * This function is called during the initialization of the SLI |
| 9126 | * interface of an HBA. |
| 9127 | * This function is called with no lock held and always returns |
| 9128 | * 1. |
| 9129 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9130 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9131 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9132 | { |
| 9133 | struct lpfc_sli *psli; |
| 9134 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9135 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9136 | |
| 9137 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9138 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9139 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9140 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9141 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9142 | for (i = 0; i < psli->num_rings; i++) { |
| 9143 | pring = &psli->ring[i]; |
| 9144 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9145 | pring->sli.sli3.next_cmdidx = 0; |
| 9146 | pring->sli.sli3.local_getidx = 0; |
| 9147 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9148 | INIT_LIST_HEAD(&pring->txq); |
| 9149 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9150 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9151 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9152 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9153 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9154 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9155 | spin_unlock_irq(&phba->hbalock); |
| 9156 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9157 | } |
| 9158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9159 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9160 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9161 | * @phba: Pointer to HBA context object. |
| 9162 | * |
| 9163 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9164 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9165 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9166 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9167 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9168 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9169 | * pending mailbox command queue from the various clients must be stopped; |
| 9170 | * either the HBA is in a state that it will never works on the outstanding |
| 9171 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9172 | * mailbox command has been completed. |
| 9173 | **/ |
| 9174 | static void |
| 9175 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 9176 | { |
| 9177 | LIST_HEAD(completions); |
| 9178 | struct lpfc_sli *psli = &phba->sli; |
| 9179 | LPFC_MBOXQ_t *pmb; |
| 9180 | unsigned long iflag; |
| 9181 | |
| 9182 | /* Flush all the mailbox commands in the mbox system */ |
| 9183 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9184 | /* The pending mailbox command queue */ |
| 9185 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9186 | /* The outstanding active mailbox command */ |
| 9187 | if (psli->mbox_active) { |
| 9188 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9189 | psli->mbox_active = NULL; |
| 9190 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9191 | } |
| 9192 | /* The completed mailbox command queue */ |
| 9193 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9194 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9195 | |
| 9196 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9197 | while (!list_empty(&completions)) { |
| 9198 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9199 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9200 | if (pmb->mbox_cmpl) |
| 9201 | pmb->mbox_cmpl(phba, pmb); |
| 9202 | } |
| 9203 | } |
| 9204 | |
| 9205 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9206 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9207 | * @vport: Pointer to virtual port object. |
| 9208 | * |
| 9209 | * lpfc_sli_host_down is called to clean up the resources |
| 9210 | * associated with a vport before destroying virtual |
| 9211 | * port data structures. |
| 9212 | * This function does following operations: |
| 9213 | * - Free discovery resources associated with this virtual |
| 9214 | * port. |
| 9215 | * - Free iocbs associated with this virtual port in |
| 9216 | * the txq. |
| 9217 | * - Send abort for all iocb commands associated with this |
| 9218 | * vport in txcmplq. |
| 9219 | * |
| 9220 | * This function is called with no lock held and always returns 1. |
| 9221 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9222 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9223 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9224 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9225 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9226 | struct lpfc_hba *phba = vport->phba; |
| 9227 | struct lpfc_sli *psli = &phba->sli; |
| 9228 | struct lpfc_sli_ring *pring; |
| 9229 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9230 | int i; |
| 9231 | unsigned long flags = 0; |
| 9232 | uint16_t prev_pring_flag; |
| 9233 | |
| 9234 | lpfc_cleanup_discovery_resources(vport); |
| 9235 | |
| 9236 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9237 | for (i = 0; i < psli->num_rings; i++) { |
| 9238 | pring = &psli->ring[i]; |
| 9239 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9240 | /* Only slow rings */ |
| 9241 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9242 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9243 | /* Set the lpfc data pending flag */ |
| 9244 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9245 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9246 | /* |
| 9247 | * Error everything on the txq since these iocbs have not been |
| 9248 | * given to the FW yet. |
| 9249 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9250 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9251 | if (iocb->vport != vport) |
| 9252 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9253 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9254 | } |
| 9255 | |
| 9256 | /* Next issue ABTS for everything on the txcmplq */ |
| 9257 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9258 | list) { |
| 9259 | if (iocb->vport != vport) |
| 9260 | continue; |
| 9261 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9262 | } |
| 9263 | |
| 9264 | pring->flag = prev_pring_flag; |
| 9265 | } |
| 9266 | |
| 9267 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9268 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9269 | /* Cancel all the IOCBs from the completions list */ |
| 9270 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9271 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9272 | return 1; |
| 9273 | } |
| 9274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9276 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9277 | * @phba: Pointer to HBA context object. |
| 9278 | * |
| 9279 | * This function cleans up all iocb, buffers, mailbox commands |
| 9280 | * while shutting down the HBA. This function is called with no |
| 9281 | * lock held and always returns 1. |
| 9282 | * This function does the following to cleanup driver resources: |
| 9283 | * - Free discovery resources for each virtual port |
| 9284 | * - Cleanup any pending fabric iocbs |
| 9285 | * - Iterate through the iocb txq and free each entry |
| 9286 | * in the list. |
| 9287 | * - Free up any buffer posted to the HBA |
| 9288 | * - Free mailbox commands in the mailbox queue. |
| 9289 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9290 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9291 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9292 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9293 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9294 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9295 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9296 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9297 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9298 | int i; |
| 9299 | |
| 9300 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9301 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9302 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9303 | lpfc_hba_down_prep(phba); |
| 9304 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9305 | lpfc_fabric_abort_hba(phba); |
| 9306 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9307 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9308 | for (i = 0; i < psli->num_rings; i++) { |
| 9309 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9310 | /* Only slow rings */ |
| 9311 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9312 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9313 | /* Set the lpfc data pending flag */ |
| 9314 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9315 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9316 | |
| 9317 | /* |
| 9318 | * Error everything on the txq since these iocbs have not been |
| 9319 | * given to the FW yet. |
| 9320 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9321 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9322 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9323 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9324 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9325 | /* Cancel all the IOCBs from the completions list */ |
| 9326 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9327 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9328 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9329 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9330 | list_splice_init(&phba->elsbuf, &completions); |
| 9331 | phba->elsbuf_cnt = 0; |
| 9332 | phba->elsbuf_prev_cnt = 0; |
| 9333 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9334 | |
| 9335 | while (!list_empty(&completions)) { |
| 9336 | list_remove_head(&completions, buf_ptr, |
| 9337 | struct lpfc_dmabuf, list); |
| 9338 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9339 | kfree(buf_ptr); |
| 9340 | } |
| 9341 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9342 | /* Return any active mbox cmds */ |
| 9343 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9344 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9345 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9346 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9347 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9348 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9349 | return 1; |
| 9350 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9351 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9353 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9354 | * @srcp: Source memory pointer. |
| 9355 | * @destp: Destination memory pointer. |
| 9356 | * @cnt: Number of words required to be copied. |
| 9357 | * |
| 9358 | * This function is used for copying data between driver memory |
| 9359 | * and the SLI memory. This function also changes the endianness |
| 9360 | * of each word if native endianness is different from SLI |
| 9361 | * endianness. This function can be called with or without |
| 9362 | * lock. |
| 9363 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9364 | void |
| 9365 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9366 | { |
| 9367 | uint32_t *src = srcp; |
| 9368 | uint32_t *dest = destp; |
| 9369 | uint32_t ldata; |
| 9370 | int i; |
| 9371 | |
| 9372 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9373 | ldata = *src; |
| 9374 | ldata = le32_to_cpu(ldata); |
| 9375 | *dest = ldata; |
| 9376 | src++; |
| 9377 | dest++; |
| 9378 | } |
| 9379 | } |
| 9380 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9381 | |
| 9382 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9383 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9384 | * @srcp: Source memory pointer. |
| 9385 | * @destp: Destination memory pointer. |
| 9386 | * @cnt: Number of words required to be copied. |
| 9387 | * |
| 9388 | * This function is used for copying data between a data structure |
| 9389 | * with big endian representation to local endianness. |
| 9390 | * This function can be called with or without lock. |
| 9391 | **/ |
| 9392 | void |
| 9393 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9394 | { |
| 9395 | uint32_t *src = srcp; |
| 9396 | uint32_t *dest = destp; |
| 9397 | uint32_t ldata; |
| 9398 | int i; |
| 9399 | |
| 9400 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9401 | ldata = *src; |
| 9402 | ldata = be32_to_cpu(ldata); |
| 9403 | *dest = ldata; |
| 9404 | src++; |
| 9405 | dest++; |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9410 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9411 | * @phba: Pointer to HBA context object. |
| 9412 | * @pring: Pointer to driver SLI ring object. |
| 9413 | * @mp: Pointer to driver buffer object. |
| 9414 | * |
| 9415 | * This function is called with no lock held. |
| 9416 | * It always return zero after adding the buffer to the postbufq |
| 9417 | * buffer list. |
| 9418 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9419 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9420 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9421 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9422 | { |
| 9423 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9424 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9425 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9426 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9427 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9428 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9429 | return 0; |
| 9430 | } |
| 9431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9433 | * 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] | 9434 | * @phba: Pointer to HBA context object. |
| 9435 | * |
| 9436 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9437 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9438 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9439 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9440 | * The function returns the allocated tag. The function is called with |
| 9441 | * no locks held. |
| 9442 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9443 | uint32_t |
| 9444 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9445 | { |
| 9446 | spin_lock_irq(&phba->hbalock); |
| 9447 | phba->buffer_tag_count++; |
| 9448 | /* |
| 9449 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9450 | * a tag assigned by HBQ. |
| 9451 | */ |
| 9452 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9453 | spin_unlock_irq(&phba->hbalock); |
| 9454 | return phba->buffer_tag_count; |
| 9455 | } |
| 9456 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9457 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9458 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9459 | * @phba: Pointer to HBA context object. |
| 9460 | * @pring: Pointer to driver SLI ring object. |
| 9461 | * @tag: Buffer tag. |
| 9462 | * |
| 9463 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9464 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9465 | * iocb is posted to the response ring with the tag of the buffer. |
| 9466 | * This function searches the pring->postbufq list using the tag |
| 9467 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9468 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9469 | * buffer is returned to the caller else NULL is returned. |
| 9470 | * This function is called with no lock held. |
| 9471 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9472 | struct lpfc_dmabuf * |
| 9473 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9474 | uint32_t tag) |
| 9475 | { |
| 9476 | struct lpfc_dmabuf *mp, *next_mp; |
| 9477 | struct list_head *slp = &pring->postbufq; |
| 9478 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9479 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9480 | spin_lock_irq(&phba->hbalock); |
| 9481 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9482 | if (mp->buffer_tag == tag) { |
| 9483 | list_del_init(&mp->list); |
| 9484 | pring->postbufq_cnt--; |
| 9485 | spin_unlock_irq(&phba->hbalock); |
| 9486 | return mp; |
| 9487 | } |
| 9488 | } |
| 9489 | |
| 9490 | spin_unlock_irq(&phba->hbalock); |
| 9491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9492 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9493 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9494 | pring->ringno, (unsigned long) tag, |
| 9495 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9496 | |
| 9497 | return NULL; |
| 9498 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9499 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9500 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9501 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9502 | * @phba: Pointer to HBA context object. |
| 9503 | * @pring: Pointer to driver SLI ring object. |
| 9504 | * @phys: DMA address of the buffer. |
| 9505 | * |
| 9506 | * This function searches the buffer list using the dma_address |
| 9507 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9508 | * corresponding to the dma_address. The function returns the |
| 9509 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9510 | * This function is called by the ct and els unsolicited event |
| 9511 | * handlers to get the buffer associated with the unsolicited |
| 9512 | * event. |
| 9513 | * |
| 9514 | * This function is called with no lock held. |
| 9515 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9516 | struct lpfc_dmabuf * |
| 9517 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9518 | dma_addr_t phys) |
| 9519 | { |
| 9520 | struct lpfc_dmabuf *mp, *next_mp; |
| 9521 | struct list_head *slp = &pring->postbufq; |
| 9522 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9523 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9524 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9525 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9526 | if (mp->phys == phys) { |
| 9527 | list_del_init(&mp->list); |
| 9528 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9529 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9530 | return mp; |
| 9531 | } |
| 9532 | } |
| 9533 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9534 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9536 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9537 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9538 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9539 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9540 | return NULL; |
| 9541 | } |
| 9542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9543 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9544 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9545 | * @phba: Pointer to HBA context object. |
| 9546 | * @cmdiocb: Pointer to driver command iocb object. |
| 9547 | * @rspiocb: Pointer to driver response iocb object. |
| 9548 | * |
| 9549 | * This function is the completion handler for the abort iocbs for |
| 9550 | * ELS commands. This function is called from the ELS ring event |
| 9551 | * handler with no lock held. This function frees memory resources |
| 9552 | * associated with the abort iocb. |
| 9553 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9554 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9555 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9556 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9557 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9558 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9559 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9560 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9561 | |
| 9562 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9563 | |
| 9564 | /* |
| 9565 | * Assume that the port already completed and returned, or |
| 9566 | * will return the iocb. Just Log the message. |
| 9567 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9568 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9569 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9570 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9571 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9572 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9573 | if (abort_iotag != 0 && |
| 9574 | abort_iotag <= phba->sli.last_iotag) |
| 9575 | abort_iocb = |
| 9576 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9577 | } else |
| 9578 | /* For sli4 the abort_tag is the XRI, |
| 9579 | * so the abort routine puts the iotag of the iocb |
| 9580 | * being aborted in the context field of the abort |
| 9581 | * IOCB. |
| 9582 | */ |
| 9583 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9584 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9585 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9586 | "0327 Cannot abort els iocb %p " |
| 9587 | "with tag %x context %x, abort status %x, " |
| 9588 | "abort code %x\n", |
| 9589 | abort_iocb, abort_iotag, abort_context, |
| 9590 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9591 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9592 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9593 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9594 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9595 | return; |
| 9596 | } |
| 9597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9598 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9599 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9600 | * @phba: Pointer to HBA context object. |
| 9601 | * @cmdiocb: Pointer to driver command iocb object. |
| 9602 | * @rspiocb: Pointer to driver response iocb object. |
| 9603 | * |
| 9604 | * The function is called from SLI ring event handler with no |
| 9605 | * lock held. This function is the completion handler for ELS commands |
| 9606 | * which are aborted. The function frees memory resources used for |
| 9607 | * the aborted ELS commands. |
| 9608 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9609 | static void |
| 9610 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9611 | struct lpfc_iocbq *rspiocb) |
| 9612 | { |
| 9613 | IOCB_t *irsp = &rspiocb->iocb; |
| 9614 | |
| 9615 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9616 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9617 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9618 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9619 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9620 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9621 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9622 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9623 | else |
| 9624 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9625 | return; |
| 9626 | } |
| 9627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9628 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9629 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9630 | * @phba: Pointer to HBA context object. |
| 9631 | * @pring: Pointer to driver SLI ring object. |
| 9632 | * @cmdiocb: Pointer to driver command iocb object. |
| 9633 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9634 | * This function issues an abort iocb for the provided command iocb down to |
| 9635 | * the port. Other than the case the outstanding command iocb is an abort |
| 9636 | * request, this function issues abort out unconditionally. This function is |
| 9637 | * called with hbalock held. The function returns 0 when it fails due to |
| 9638 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9639 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9640 | static int |
| 9641 | 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] | 9642 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9643 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9644 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9645 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9646 | IOCB_t *icmd = NULL; |
| 9647 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9648 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9649 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9650 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9651 | /* |
| 9652 | * There are certain command types we don't want to abort. And we |
| 9653 | * don't want to abort commands that are already in the process of |
| 9654 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9655 | */ |
| 9656 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9657 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9658 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9659 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9660 | return 0; |
| 9661 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9662 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9663 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9664 | if (abtsiocbp == NULL) |
| 9665 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9666 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9667 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9668 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9669 | */ |
| 9670 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9672 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9673 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9674 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9675 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9676 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9677 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9678 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9679 | else |
| 9680 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9681 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9682 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9683 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9684 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9685 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9686 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9687 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9688 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9689 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9690 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9691 | else |
| 9692 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9693 | |
| 9694 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9695 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9696 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9697 | "0339 Abort xri x%x, original iotag x%x, " |
| 9698 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9699 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9700 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9701 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9702 | |
| 9703 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9704 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9705 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9706 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9707 | abtsiocbp, 0); |
| 9708 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9709 | } else { |
| 9710 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9711 | abtsiocbp, 0); |
| 9712 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9713 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9714 | if (retval) |
| 9715 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9716 | |
| 9717 | /* |
| 9718 | * Caller to this routine should check for IOCB_ERROR |
| 9719 | * and handle it properly. This routine no longer removes |
| 9720 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9721 | */ |
| 9722 | return retval; |
| 9723 | } |
| 9724 | |
| 9725 | /** |
| 9726 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9727 | * @phba: Pointer to HBA context object. |
| 9728 | * @pring: Pointer to driver SLI ring object. |
| 9729 | * @cmdiocb: Pointer to driver command iocb object. |
| 9730 | * |
| 9731 | * This function issues an abort iocb for the provided command iocb. In case |
| 9732 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9733 | * ring. Instead, the callback function shall be changed to those commands |
| 9734 | * so that nothing happens when them finishes. This function is called with |
| 9735 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9736 | * request. |
| 9737 | **/ |
| 9738 | int |
| 9739 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9740 | struct lpfc_iocbq *cmdiocb) |
| 9741 | { |
| 9742 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9743 | int retval = IOCB_ERROR; |
| 9744 | IOCB_t *icmd = NULL; |
| 9745 | |
| 9746 | /* |
| 9747 | * There are certain command types we don't want to abort. And we |
| 9748 | * don't want to abort commands that are already in the process of |
| 9749 | * being aborted. |
| 9750 | */ |
| 9751 | icmd = &cmdiocb->iocb; |
| 9752 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9753 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9754 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9755 | return 0; |
| 9756 | |
| 9757 | /* |
| 9758 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9759 | * the callback so that nothing happens when it finishes. |
| 9760 | */ |
| 9761 | if ((vport->load_flag & FC_UNLOADING) && |
| 9762 | (pring->ringno == LPFC_ELS_RING)) { |
| 9763 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9764 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9765 | else |
| 9766 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9767 | goto abort_iotag_exit; |
| 9768 | } |
| 9769 | |
| 9770 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9771 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9772 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9773 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9774 | /* |
| 9775 | * Caller to this routine should check for IOCB_ERROR |
| 9776 | * and handle it properly. This routine no longer removes |
| 9777 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9778 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9779 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9780 | } |
| 9781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9782 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9783 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9784 | * @phba: Pointer to HBA context object. |
| 9785 | * @pring: Pointer to driver SLI ring object. |
| 9786 | * |
| 9787 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9788 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9789 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9790 | * to complete before the return of this function. The caller is not required |
| 9791 | * to hold any locks. |
| 9792 | **/ |
| 9793 | static void |
| 9794 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9795 | { |
| 9796 | LIST_HEAD(completions); |
| 9797 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9798 | |
| 9799 | if (pring->ringno == LPFC_ELS_RING) |
| 9800 | lpfc_fabric_abort_hba(phba); |
| 9801 | |
| 9802 | spin_lock_irq(&phba->hbalock); |
| 9803 | |
| 9804 | /* Take off all the iocbs on txq for cancelling */ |
| 9805 | list_splice_init(&pring->txq, &completions); |
| 9806 | pring->txq_cnt = 0; |
| 9807 | |
| 9808 | /* Next issue ABTS for everything on the txcmplq */ |
| 9809 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9810 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9811 | |
| 9812 | spin_unlock_irq(&phba->hbalock); |
| 9813 | |
| 9814 | /* Cancel all the IOCBs from the completions list */ |
| 9815 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9816 | IOERR_SLI_ABORTED); |
| 9817 | } |
| 9818 | |
| 9819 | /** |
| 9820 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9821 | * @phba: pointer to lpfc HBA data structure. |
| 9822 | * |
| 9823 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9824 | **/ |
| 9825 | void |
| 9826 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9827 | { |
| 9828 | struct lpfc_sli *psli = &phba->sli; |
| 9829 | struct lpfc_sli_ring *pring; |
| 9830 | int i; |
| 9831 | |
| 9832 | for (i = 0; i < psli->num_rings; i++) { |
| 9833 | pring = &psli->ring[i]; |
| 9834 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9835 | } |
| 9836 | } |
| 9837 | |
| 9838 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9839 | * 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] | 9840 | * @iocbq: Pointer to driver iocb object. |
| 9841 | * @vport: Pointer to driver virtual port object. |
| 9842 | * @tgt_id: SCSI ID of the target. |
| 9843 | * @lun_id: LUN ID of the scsi device. |
| 9844 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9845 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9846 | * 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] | 9847 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9848 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9849 | * 1 if the filtering criteria is not met. |
| 9850 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9851 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9852 | * lun_id parameter. |
| 9853 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9854 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9855 | * parameters. |
| 9856 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9857 | * given iocb is for the SCSI host associated with the given vport. |
| 9858 | * This function is called with no locks held. |
| 9859 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9860 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9861 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9862 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9863 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9864 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9865 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9866 | int rc = 1; |
| 9867 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9868 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9869 | return rc; |
| 9870 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9871 | if (iocbq->vport != vport) |
| 9872 | return rc; |
| 9873 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9874 | 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] | 9875 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9876 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9877 | return rc; |
| 9878 | |
| 9879 | switch (ctx_cmd) { |
| 9880 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9881 | if ((lpfc_cmd->rdata->pnode) && |
| 9882 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9883 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9884 | rc = 0; |
| 9885 | break; |
| 9886 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9887 | if ((lpfc_cmd->rdata->pnode) && |
| 9888 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9889 | rc = 0; |
| 9890 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9891 | case LPFC_CTX_HOST: |
| 9892 | rc = 0; |
| 9893 | break; |
| 9894 | default: |
| 9895 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9896 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9897 | break; |
| 9898 | } |
| 9899 | |
| 9900 | return rc; |
| 9901 | } |
| 9902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9903 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9904 | * 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] | 9905 | * @vport: Pointer to virtual port. |
| 9906 | * @tgt_id: SCSI ID of the target. |
| 9907 | * @lun_id: LUN ID of the scsi device. |
| 9908 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9909 | * |
| 9910 | * This function returns number of FCP commands pending for the vport. |
| 9911 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9912 | * commands pending on the vport associated with SCSI device specified |
| 9913 | * by tgt_id and lun_id parameters. |
| 9914 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9915 | * commands pending on the vport associated with SCSI target specified |
| 9916 | * by tgt_id parameter. |
| 9917 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9918 | * commands pending on the vport. |
| 9919 | * This function returns the number of iocbs which satisfy the filter. |
| 9920 | * This function is called without any lock held. |
| 9921 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9922 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9923 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9924 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9925 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9926 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9927 | struct lpfc_iocbq *iocbq; |
| 9928 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9929 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9930 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9931 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9932 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9933 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9934 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9935 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9936 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9937 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9938 | return sum; |
| 9939 | } |
| 9940 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9941 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9942 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9943 | * @phba: Pointer to HBA context object |
| 9944 | * @cmdiocb: Pointer to command iocb object. |
| 9945 | * @rspiocb: Pointer to response iocb object. |
| 9946 | * |
| 9947 | * This function is called when an aborted FCP iocb completes. This |
| 9948 | * function is called by the ring event handler with no lock held. |
| 9949 | * This function frees the iocb. |
| 9950 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9951 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9952 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9953 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9954 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9955 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 9956 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9957 | "original iotag x%x, abort cmd iotag x%x " |
| 9958 | "status 0x%x, reason 0x%x\n", |
| 9959 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9960 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9961 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9962 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9963 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9964 | return; |
| 9965 | } |
| 9966 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9967 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9968 | * 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] | 9969 | * @vport: Pointer to virtual port. |
| 9970 | * @pring: Pointer to driver SLI ring object. |
| 9971 | * @tgt_id: SCSI ID of the target. |
| 9972 | * @lun_id: LUN ID of the scsi device. |
| 9973 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9974 | * |
| 9975 | * This function sends an abort command for every SCSI command |
| 9976 | * associated with the given virtual port pending on the ring |
| 9977 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9978 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9979 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9980 | * parameters |
| 9981 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9982 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9983 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9984 | * FCP iocbs associated with virtual port. |
| 9985 | * This function returns number of iocbs it failed to abort. |
| 9986 | * This function is called with no locks held. |
| 9987 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9988 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9989 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9990 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9991 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9992 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9993 | struct lpfc_iocbq *iocbq; |
| 9994 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9995 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9996 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9997 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9998 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9999 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10000 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10001 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10002 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10003 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10004 | continue; |
| 10005 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10006 | /* |
| 10007 | * If the iocbq is already being aborted, don't take a second |
| 10008 | * action, but do count it. |
| 10009 | */ |
| 10010 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10011 | continue; |
| 10012 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10013 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10014 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10015 | if (abtsiocb == NULL) { |
| 10016 | errcnt++; |
| 10017 | continue; |
| 10018 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10019 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10020 | /* indicate the IO is being aborted by the driver. */ |
| 10021 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10022 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10023 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10024 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10025 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10026 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10027 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 10028 | else |
| 10029 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10030 | abtsiocb->iocb.ulpLe = 1; |
| 10031 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10032 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10033 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10034 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10035 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10036 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 10037 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10038 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10039 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10040 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 10041 | else |
| 10042 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10043 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10044 | /* Setup callback routine and issue the command. */ |
| 10045 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10046 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10047 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10048 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10049 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10050 | errcnt++; |
| 10051 | continue; |
| 10052 | } |
| 10053 | } |
| 10054 | |
| 10055 | return errcnt; |
| 10056 | } |
| 10057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10058 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10059 | * 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] | 10060 | * @phba: Pointer to HBA context object. |
| 10061 | * @cmdiocbq: Pointer to command iocb. |
| 10062 | * @rspiocbq: Pointer to response iocb. |
| 10063 | * |
| 10064 | * This function is the completion handler for iocbs issued using |
| 10065 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 10066 | * ring event handler function without any lock held. This function |
| 10067 | * can be called from both worker thread context and interrupt |
| 10068 | * context. This function also can be called from other thread which |
| 10069 | * cleans up the SLI layer objects. |
| 10070 | * This function copy the contents of the response iocb to the |
| 10071 | * response iocb memory object provided by the caller of |
| 10072 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 10073 | * sleeps for the iocb completion. |
| 10074 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10075 | static void |
| 10076 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 10077 | struct lpfc_iocbq *cmdiocbq, |
| 10078 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10079 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10080 | wait_queue_head_t *pdone_q; |
| 10081 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10082 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10083 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10084 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10085 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 10086 | |
| 10087 | /* |
| 10088 | * A time out has occurred for the iocb. If a time out |
| 10089 | * completion handler has been supplied, call it. Otherwise, |
| 10090 | * just free the iocbq. |
| 10091 | */ |
| 10092 | |
| 10093 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10094 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 10095 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 10096 | if (cmdiocbq->iocb_cmpl) |
| 10097 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 10098 | else |
| 10099 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 10100 | return; |
| 10101 | } |
| 10102 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10103 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 10104 | if (cmdiocbq->context2 && rspiocbq) |
| 10105 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 10106 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 10107 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10108 | /* Set the exchange busy flag for task management commands */ |
| 10109 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 10110 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 10111 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 10112 | cur_iocbq); |
| 10113 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 10114 | } |
| 10115 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10116 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10117 | if (pdone_q) |
| 10118 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10119 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10120 | return; |
| 10121 | } |
| 10122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10123 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10124 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 10125 | * @phba: Pointer to HBA context object.. |
| 10126 | * @piocbq: Pointer to command iocb. |
| 10127 | * @flag: Flag to test. |
| 10128 | * |
| 10129 | * This routine grabs the hbalock and then test the iocb_flag to |
| 10130 | * see if the passed in flag is set. |
| 10131 | * Returns: |
| 10132 | * 1 if flag is set. |
| 10133 | * 0 if flag is not set. |
| 10134 | **/ |
| 10135 | static int |
| 10136 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 10137 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 10138 | { |
| 10139 | unsigned long iflags; |
| 10140 | int ret; |
| 10141 | |
| 10142 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10143 | ret = piocbq->iocb_flag & flag; |
| 10144 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10145 | return ret; |
| 10146 | |
| 10147 | } |
| 10148 | |
| 10149 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10150 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10151 | * @phba: Pointer to HBA context object.. |
| 10152 | * @pring: Pointer to sli ring. |
| 10153 | * @piocb: Pointer to command iocb. |
| 10154 | * @prspiocbq: Pointer to response iocb. |
| 10155 | * @timeout: Timeout in number of seconds. |
| 10156 | * |
| 10157 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10158 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 10159 | * to handle iocbs which time out. If the field is NULL, the |
| 10160 | * function shall free the iocbq structure. If more clean up is |
| 10161 | * needed, the caller is expected to provide a completion function |
| 10162 | * that will provide the needed clean up. If the iocb command is |
| 10163 | * not completed within timeout seconds, the function will either |
| 10164 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 10165 | * completion function set in the iocb_cmpl field and then return |
| 10166 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 10167 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10168 | * The function waits for the iocb completion using an |
| 10169 | * non-interruptible wait. |
| 10170 | * This function will sleep while waiting for iocb completion. |
| 10171 | * So, this function should not be called from any context which |
| 10172 | * does not allow sleeping. Due to the same reason, this function |
| 10173 | * cannot be called with interrupt disabled. |
| 10174 | * This function assumes that the iocb completions occur while |
| 10175 | * this function sleep. So, this function cannot be called from |
| 10176 | * the thread which process iocb completion for this ring. |
| 10177 | * This function clears the iocb_flag of the iocb object before |
| 10178 | * issuing the iocb and the iocb completion handler sets this |
| 10179 | * flag and wakes this thread when the iocb completes. |
| 10180 | * The contents of the response iocb will be copied to prspiocbq |
| 10181 | * by the completion handler when the command completes. |
| 10182 | * This function returns IOCB_SUCCESS when success. |
| 10183 | * This function is called with no lock held. |
| 10184 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10185 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10186 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10187 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10188 | struct lpfc_iocbq *piocb, |
| 10189 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10190 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10191 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10192 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10193 | long timeleft, timeout_req = 0; |
| 10194 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10195 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10196 | struct lpfc_iocbq *iocb; |
| 10197 | int txq_cnt = 0; |
| 10198 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10199 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10200 | unsigned long iflags; |
| 10201 | bool iocb_completed = true; |
| 10202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10203 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10204 | * If the caller has provided a response iocbq buffer, then context2 |
| 10205 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10206 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10207 | if (prspiocbq) { |
| 10208 | if (piocb->context2) |
| 10209 | return IOCB_ERROR; |
| 10210 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10211 | } |
| 10212 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10213 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10214 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 10215 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10216 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10217 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10218 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10219 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10220 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10221 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 10222 | writel(creg_val, phba->HCregaddr); |
| 10223 | readl(phba->HCregaddr); /* flush */ |
| 10224 | } |
| 10225 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10226 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10227 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10228 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10229 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10230 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10231 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10232 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10233 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10234 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10235 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10236 | /* |
| 10237 | * IOCB timed out. Inform the wake iocb wait |
| 10238 | * completion function and set local status |
| 10239 | */ |
| 10240 | |
| 10241 | iocb_completed = false; |
| 10242 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 10243 | } |
| 10244 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10245 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10246 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10247 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 10248 | /* Note: we are not indicating if the IOCB has a success |
| 10249 | * status or not - that's for the caller to check. |
| 10250 | * IOCB_SUCCESS means just that the command was sent and |
| 10251 | * completed. Not that it completed successfully. |
| 10252 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10253 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10254 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10255 | "0338 IOCB wait timeout error - no " |
| 10256 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10257 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10258 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10259 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10260 | "0330 IOCB wake NOT set, " |
| 10261 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10262 | timeout, (timeleft / jiffies)); |
| 10263 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10264 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10265 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10266 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10267 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10268 | txq_cnt++; |
| 10269 | } |
| 10270 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10271 | txcmplq_cnt++; |
| 10272 | } |
| 10273 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10274 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10275 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10276 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10277 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10278 | } else { |
| 10279 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10280 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10281 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10282 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10283 | } |
| 10284 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10285 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10286 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10287 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10288 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10289 | writel(creg_val, phba->HCregaddr); |
| 10290 | readl(phba->HCregaddr); /* flush */ |
| 10291 | } |
| 10292 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10293 | if (prspiocbq) |
| 10294 | piocb->context2 = NULL; |
| 10295 | |
| 10296 | piocb->context_un.wait_queue = NULL; |
| 10297 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10298 | return retval; |
| 10299 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10300 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10301 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10302 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10303 | * @phba: Pointer to HBA context object. |
| 10304 | * @pmboxq: Pointer to driver mailbox object. |
| 10305 | * @timeout: Timeout in number of seconds. |
| 10306 | * |
| 10307 | * This function issues the mailbox to firmware and waits for the |
| 10308 | * mailbox command to complete. If the mailbox command is not |
| 10309 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10310 | * The function waits for the mailbox completion using an |
| 10311 | * interruptible wait. If the thread is woken up due to a |
| 10312 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10313 | * should not free the mailbox resources, if this function returns |
| 10314 | * MBX_TIMEOUT. |
| 10315 | * This function will sleep while waiting for mailbox completion. |
| 10316 | * So, this function should not be called from any context which |
| 10317 | * does not allow sleeping. Due to the same reason, this function |
| 10318 | * cannot be called with interrupt disabled. |
| 10319 | * This function assumes that the mailbox completion occurs while |
| 10320 | * this function sleep. So, this function cannot be called from |
| 10321 | * the worker thread which processes mailbox completion. |
| 10322 | * This function is called in the context of HBA management |
| 10323 | * applications. |
| 10324 | * This function returns MBX_SUCCESS when successful. |
| 10325 | * This function is called with no lock held. |
| 10326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10327 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10328 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10329 | uint32_t timeout) |
| 10330 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10331 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10332 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10333 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10334 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10335 | |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10336 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10337 | if (pmboxq->context1) |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10338 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10339 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10340 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10341 | /* setup wake call as IOCB callback */ |
| 10342 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10343 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10344 | pmboxq->context1 = &done_q; |
| 10345 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10346 | /* now issue the command */ |
| 10347 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10348 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10349 | wait_event_interruptible_timeout(done_q, |
| 10350 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10351 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10352 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10353 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10354 | /* restore the possible extended buffer for free resource */ |
| 10355 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10356 | /* |
| 10357 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10358 | * else do not free the resources. |
| 10359 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10360 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10361 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10362 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10363 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10364 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10365 | } |
| 10366 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10367 | } else { |
| 10368 | /* restore the possible extended buffer for free resource */ |
| 10369 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10370 | } |
| 10371 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10372 | return retval; |
| 10373 | } |
| 10374 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10375 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10376 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10377 | * @phba: Pointer to HBA context. |
| 10378 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10379 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10380 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10381 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10382 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10383 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10384 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10385 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10386 | * as with offline or HBA function reset), this routine will wait for the |
| 10387 | * outstanding mailbox command to complete before invoking the mailbox |
| 10388 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10389 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10390 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10391 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10392 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10393 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10394 | unsigned long timeout; |
| 10395 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10396 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10397 | /* delay 100ms for port state */ |
| 10398 | msleep(100); |
| 10399 | lpfc_sli_mbox_sys_flush(phba); |
| 10400 | return; |
| 10401 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10402 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10403 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10404 | spin_lock_irq(&phba->hbalock); |
| 10405 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10406 | |
| 10407 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10408 | /* Determine how long we might wait for the active mailbox |
| 10409 | * command to be gracefully completed by firmware. |
| 10410 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10411 | if (phba->sli.mbox_active) |
| 10412 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10413 | phba->sli.mbox_active) * |
| 10414 | 1000) + jiffies; |
| 10415 | spin_unlock_irq(&phba->hbalock); |
| 10416 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10417 | while (phba->sli.mbox_active) { |
| 10418 | /* Check active mailbox complete status every 2ms */ |
| 10419 | msleep(2); |
| 10420 | if (time_after(jiffies, timeout)) |
| 10421 | /* Timeout, let the mailbox flush routine to |
| 10422 | * forcefully release active mailbox command |
| 10423 | */ |
| 10424 | break; |
| 10425 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10426 | } else |
| 10427 | spin_unlock_irq(&phba->hbalock); |
| 10428 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10429 | lpfc_sli_mbox_sys_flush(phba); |
| 10430 | } |
| 10431 | |
| 10432 | /** |
| 10433 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10434 | * @phba: Pointer to HBA context. |
| 10435 | * |
| 10436 | * This function is called to read the SLI3 device error attention registers |
| 10437 | * for possible error attention events. The caller must hold the hostlock |
| 10438 | * with spin_lock_irq(). |
| 10439 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10440 | * 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] | 10441 | * Register and returns 0 otherwise. |
| 10442 | **/ |
| 10443 | static int |
| 10444 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10445 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10446 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10447 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10448 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10449 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10450 | goto unplug_err; |
| 10451 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10452 | if (ha_copy & HA_ERATT) { |
| 10453 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10454 | if (lpfc_sli_read_hs(phba)) |
| 10455 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10456 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10457 | /* Check if there is a deferred error condition is active */ |
| 10458 | if ((HS_FFER1 & phba->work_hs) && |
| 10459 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10460 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10461 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10462 | /* Clear all interrupt enable conditions */ |
| 10463 | writel(0, phba->HCregaddr); |
| 10464 | readl(phba->HCregaddr); |
| 10465 | } |
| 10466 | |
| 10467 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10468 | phba->work_ha |= HA_ERATT; |
| 10469 | /* Indicate polling handles this ERATT */ |
| 10470 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10471 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10472 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10473 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10474 | |
| 10475 | unplug_err: |
| 10476 | /* Set the driver HS work bitmap */ |
| 10477 | phba->work_hs |= UNPLUG_ERR; |
| 10478 | /* Set the driver HA work bitmap */ |
| 10479 | phba->work_ha |= HA_ERATT; |
| 10480 | /* Indicate polling handles this ERATT */ |
| 10481 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10482 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10483 | } |
| 10484 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10485 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10486 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10487 | * @phba: Pointer to HBA context. |
| 10488 | * |
| 10489 | * This function is called to read the SLI4 device error attention registers |
| 10490 | * for possible error attention events. The caller must hold the hostlock |
| 10491 | * with spin_lock_irq(). |
| 10492 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10493 | * 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] | 10494 | * Register and returns 0 otherwise. |
| 10495 | **/ |
| 10496 | static int |
| 10497 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10498 | { |
| 10499 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10500 | uint32_t if_type, portsmphr; |
| 10501 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10502 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10503 | /* |
| 10504 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10505 | * registers for error attention. This can be changed later. |
| 10506 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10507 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10508 | switch (if_type) { |
| 10509 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10510 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10511 | &uerr_sta_lo) || |
| 10512 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10513 | &uerr_sta_hi)) { |
| 10514 | phba->work_hs |= UNPLUG_ERR; |
| 10515 | phba->work_ha |= HA_ERATT; |
| 10516 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10517 | return 1; |
| 10518 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10519 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10520 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10522 | "1423 HBA Unrecoverable error: " |
| 10523 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10524 | "ue_mask_lo_reg=0x%x, " |
| 10525 | "ue_mask_hi_reg=0x%x\n", |
| 10526 | uerr_sta_lo, uerr_sta_hi, |
| 10527 | phba->sli4_hba.ue_mask_lo, |
| 10528 | phba->sli4_hba.ue_mask_hi); |
| 10529 | phba->work_status[0] = uerr_sta_lo; |
| 10530 | phba->work_status[1] = uerr_sta_hi; |
| 10531 | phba->work_ha |= HA_ERATT; |
| 10532 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10533 | return 1; |
| 10534 | } |
| 10535 | break; |
| 10536 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10537 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10538 | &portstat_reg.word0) || |
| 10539 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10540 | &portsmphr)){ |
| 10541 | phba->work_hs |= UNPLUG_ERR; |
| 10542 | phba->work_ha |= HA_ERATT; |
| 10543 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10544 | return 1; |
| 10545 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10546 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10547 | phba->work_status[0] = |
| 10548 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10549 | phba->work_status[1] = |
| 10550 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10552 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10553 | "port status reg 0x%x, " |
| 10554 | "port smphr reg 0x%x, " |
| 10555 | "error 1=0x%x, error 2=0x%x\n", |
| 10556 | portstat_reg.word0, |
| 10557 | portsmphr, |
| 10558 | phba->work_status[0], |
| 10559 | phba->work_status[1]); |
| 10560 | phba->work_ha |= HA_ERATT; |
| 10561 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10562 | return 1; |
| 10563 | } |
| 10564 | break; |
| 10565 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10566 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10568 | "2886 HBA Error Attention on unsupported " |
| 10569 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10570 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10571 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10572 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10573 | return 0; |
| 10574 | } |
| 10575 | |
| 10576 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10577 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10578 | * @phba: Pointer to HBA context. |
| 10579 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10580 | * 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] | 10581 | * error attention register bit for error attention events. |
| 10582 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10583 | * 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] | 10584 | * Register and returns 0 otherwise. |
| 10585 | **/ |
| 10586 | int |
| 10587 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10588 | { |
| 10589 | uint32_t ha_copy; |
| 10590 | |
| 10591 | /* If somebody is waiting to handle an eratt, don't process it |
| 10592 | * here. The brdkill function will do this. |
| 10593 | */ |
| 10594 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10595 | return 0; |
| 10596 | |
| 10597 | /* Check if interrupt handler handles this ERATT */ |
| 10598 | spin_lock_irq(&phba->hbalock); |
| 10599 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10600 | /* Interrupt handler has handled ERATT */ |
| 10601 | spin_unlock_irq(&phba->hbalock); |
| 10602 | return 0; |
| 10603 | } |
| 10604 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10605 | /* |
| 10606 | * If there is deferred error attention, do not check for error |
| 10607 | * attention |
| 10608 | */ |
| 10609 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10610 | spin_unlock_irq(&phba->hbalock); |
| 10611 | return 0; |
| 10612 | } |
| 10613 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10614 | /* If PCI channel is offline, don't process it */ |
| 10615 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10616 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10617 | return 0; |
| 10618 | } |
| 10619 | |
| 10620 | switch (phba->sli_rev) { |
| 10621 | case LPFC_SLI_REV2: |
| 10622 | case LPFC_SLI_REV3: |
| 10623 | /* Read chip Host Attention (HA) register */ |
| 10624 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10625 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10626 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10627 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10628 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10629 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10630 | default: |
| 10631 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10632 | "0299 Invalid SLI revision (%d)\n", |
| 10633 | phba->sli_rev); |
| 10634 | ha_copy = 0; |
| 10635 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10636 | } |
| 10637 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10638 | |
| 10639 | return ha_copy; |
| 10640 | } |
| 10641 | |
| 10642 | /** |
| 10643 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10644 | * @phba: Pointer to HBA context. |
| 10645 | * |
| 10646 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10647 | * that the interrupt should be handled. |
| 10648 | * |
| 10649 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10650 | * interrupt should be handled, otherwise -EIO. |
| 10651 | */ |
| 10652 | static inline int |
| 10653 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10654 | { |
| 10655 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10656 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10657 | return -EIO; |
| 10658 | |
| 10659 | /* Update device level interrupt statistics */ |
| 10660 | phba->sli.slistat.sli_intr++; |
| 10661 | |
| 10662 | /* Ignore all interrupts during initialization. */ |
| 10663 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10664 | return -EIO; |
| 10665 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10666 | return 0; |
| 10667 | } |
| 10668 | |
| 10669 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10670 | * 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] | 10671 | * @irq: Interrupt number. |
| 10672 | * @dev_id: The device context pointer. |
| 10673 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10674 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10675 | * service routine when device with SLI-3 interface spec is enabled with |
| 10676 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10677 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10678 | * interrupt mode, this function is called as part of the device-level |
| 10679 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10680 | * is undergoing initialization, the interrupt handler will not process |
| 10681 | * the interrupt. The link attention and ELS ring attention events are |
| 10682 | * handled by the worker thread. The interrupt handler signals the worker |
| 10683 | * thread and returns for these events. This function is called without |
| 10684 | * 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] | 10685 | * structures. |
| 10686 | * |
| 10687 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10688 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10689 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10690 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10691 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10692 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10693 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10694 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10695 | uint32_t work_ha_copy; |
| 10696 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10697 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10698 | uint32_t control; |
| 10699 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10700 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10701 | struct lpfc_vport *vport; |
| 10702 | struct lpfc_nodelist *ndlp; |
| 10703 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10704 | LPFC_MBOXQ_t *pmb; |
| 10705 | int rc; |
| 10706 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10707 | /* |
| 10708 | * Get the driver's phba structure from the dev_id and |
| 10709 | * assume the HBA is not interrupting. |
| 10710 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10711 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10712 | |
| 10713 | if (unlikely(!phba)) |
| 10714 | return IRQ_NONE; |
| 10715 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10716 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10717 | * Stuff needs to be attented to when this function is invoked as an |
| 10718 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10719 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10720 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10721 | /* Check device state for handling interrupt */ |
| 10722 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10723 | return IRQ_NONE; |
| 10724 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10725 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10726 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10727 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10728 | /* If somebody is waiting to handle an eratt don't process it |
| 10729 | * here. The brdkill function will do this. |
| 10730 | */ |
| 10731 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10732 | ha_copy &= ~HA_ERATT; |
| 10733 | /* Check the need for handling ERATT in interrupt handler */ |
| 10734 | if (ha_copy & HA_ERATT) { |
| 10735 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10736 | /* ERATT polling has handled ERATT */ |
| 10737 | ha_copy &= ~HA_ERATT; |
| 10738 | else |
| 10739 | /* Indicate interrupt handler handles ERATT */ |
| 10740 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10741 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10742 | |
| 10743 | /* |
| 10744 | * If there is deferred error attention, do not check for any |
| 10745 | * interrupt. |
| 10746 | */ |
| 10747 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10748 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10749 | return IRQ_NONE; |
| 10750 | } |
| 10751 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10752 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10753 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10754 | goto unplug_error; |
| 10755 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10756 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10757 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10758 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10759 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10760 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10761 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10762 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10763 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10764 | } else |
| 10765 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10766 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10767 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10768 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10769 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10770 | if (work_ha_copy & HA_LATT) { |
| 10771 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10772 | /* |
| 10773 | * Turn off Link Attention interrupts |
| 10774 | * until CLEAR_LA done |
| 10775 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10776 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10777 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10778 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10779 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10780 | control &= ~HC_LAINT_ENA; |
| 10781 | writel(control, phba->HCregaddr); |
| 10782 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10783 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10784 | } |
| 10785 | else |
| 10786 | work_ha_copy &= ~HA_LATT; |
| 10787 | } |
| 10788 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10789 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10790 | /* |
| 10791 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10792 | * the only slow ring. |
| 10793 | */ |
| 10794 | status = (work_ha_copy & |
| 10795 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10796 | status >>= (4*LPFC_ELS_RING); |
| 10797 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10798 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10799 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10800 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10801 | |
| 10802 | lpfc_debugfs_slow_ring_trc(phba, |
| 10803 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10804 | control, status, |
| 10805 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10806 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10807 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10808 | lpfc_debugfs_slow_ring_trc(phba, |
| 10809 | "ISR Disable ring:" |
| 10810 | "pwork:x%x hawork:x%x wait:x%x", |
| 10811 | phba->work_ha, work_ha_copy, |
| 10812 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10813 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10814 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10815 | control &= |
| 10816 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10817 | writel(control, phba->HCregaddr); |
| 10818 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10819 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10820 | else { |
| 10821 | lpfc_debugfs_slow_ring_trc(phba, |
| 10822 | "ISR slow ring: pwork:" |
| 10823 | "x%x hawork:x%x wait:x%x", |
| 10824 | phba->work_ha, work_ha_copy, |
| 10825 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10826 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10827 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10828 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10829 | } |
| 10830 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10831 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10832 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10833 | if (lpfc_sli_read_hs(phba)) |
| 10834 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10835 | /* |
| 10836 | * Check if there is a deferred error condition |
| 10837 | * is active |
| 10838 | */ |
| 10839 | if ((HS_FFER1 & phba->work_hs) && |
| 10840 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10841 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10842 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10843 | phba->hba_flag |= DEFER_ERATT; |
| 10844 | /* Clear all interrupt enable conditions */ |
| 10845 | writel(0, phba->HCregaddr); |
| 10846 | readl(phba->HCregaddr); |
| 10847 | } |
| 10848 | } |
| 10849 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10850 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10851 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10852 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10853 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10854 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10855 | |
| 10856 | /* First check out the status word */ |
| 10857 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10858 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10859 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10860 | /* |
| 10861 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10862 | * mbxStatus <status> |
| 10863 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10864 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10865 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10866 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10867 | "Interrupt mbxCommand x%x " |
| 10868 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10869 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10870 | pmbox->mbxCommand, |
| 10871 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10872 | /* clear mailbox attention bit */ |
| 10873 | work_ha_copy &= ~HA_MBATT; |
| 10874 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10875 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10876 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10877 | phba->last_completion_time = jiffies; |
| 10878 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10879 | if (pmb->mbox_cmpl) { |
| 10880 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10881 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10882 | if (pmb->out_ext_byte_len && |
| 10883 | pmb->context2) |
| 10884 | lpfc_sli_pcimem_bcopy( |
| 10885 | phba->mbox_ext, |
| 10886 | pmb->context2, |
| 10887 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10888 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10889 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10890 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10891 | |
| 10892 | lpfc_debugfs_disc_trc(vport, |
| 10893 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10894 | "MBOX dflt rpi: : " |
| 10895 | "status:x%x rpi:x%x", |
| 10896 | (uint32_t)pmbox->mbxStatus, |
| 10897 | pmbox->un.varWords[0], 0); |
| 10898 | |
| 10899 | if (!pmbox->mbxStatus) { |
| 10900 | mp = (struct lpfc_dmabuf *) |
| 10901 | (pmb->context1); |
| 10902 | ndlp = (struct lpfc_nodelist *) |
| 10903 | pmb->context2; |
| 10904 | |
| 10905 | /* Reg_LOGIN of dflt RPI was |
| 10906 | * successful. new lets get |
| 10907 | * rid of the RPI using the |
| 10908 | * same mbox buffer. |
| 10909 | */ |
| 10910 | lpfc_unreg_login(phba, |
| 10911 | vport->vpi, |
| 10912 | pmbox->un.varWords[0], |
| 10913 | pmb); |
| 10914 | pmb->mbox_cmpl = |
| 10915 | lpfc_mbx_cmpl_dflt_rpi; |
| 10916 | pmb->context1 = mp; |
| 10917 | pmb->context2 = ndlp; |
| 10918 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10919 | rc = lpfc_sli_issue_mbox(phba, |
| 10920 | pmb, |
| 10921 | MBX_NOWAIT); |
| 10922 | if (rc != MBX_BUSY) |
| 10923 | lpfc_printf_log(phba, |
| 10924 | KERN_ERR, |
| 10925 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10926 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10927 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10928 | if (rc != MBX_NOT_FINISHED) |
| 10929 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10930 | } |
| 10931 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10932 | spin_lock_irqsave( |
| 10933 | &phba->pport->work_port_lock, |
| 10934 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10935 | phba->pport->work_port_events &= |
| 10936 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10937 | spin_unlock_irqrestore( |
| 10938 | &phba->pport->work_port_lock, |
| 10939 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10940 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10941 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10942 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10943 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10944 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10945 | if ((work_ha_copy & HA_MBATT) && |
| 10946 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10947 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10948 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10949 | do { |
| 10950 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10951 | MBX_NOWAIT); |
| 10952 | } while (rc == MBX_NOT_FINISHED); |
| 10953 | if (rc != MBX_SUCCESS) |
| 10954 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10955 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10956 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10957 | } |
| 10958 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10959 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10960 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10961 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10962 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10963 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10964 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10965 | unplug_error: |
| 10966 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10967 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10968 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10969 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10970 | |
| 10971 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10972 | * 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] | 10973 | * @irq: Interrupt number. |
| 10974 | * @dev_id: The device context pointer. |
| 10975 | * |
| 10976 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10977 | * service routine when device with SLI-3 interface spec is enabled with |
| 10978 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10979 | * ring event in the HBA. However, when the device is enabled with either |
| 10980 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10981 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10982 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10983 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10984 | * the intrrupt context. This function is called without any lock held. |
| 10985 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10986 | * |
| 10987 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10988 | * returns IRQ_NONE. |
| 10989 | **/ |
| 10990 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10991 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10992 | { |
| 10993 | struct lpfc_hba *phba; |
| 10994 | uint32_t ha_copy; |
| 10995 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10996 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10997 | |
| 10998 | /* Get the driver's phba structure from the dev_id and |
| 10999 | * assume the HBA is not interrupting. |
| 11000 | */ |
| 11001 | phba = (struct lpfc_hba *) dev_id; |
| 11002 | |
| 11003 | if (unlikely(!phba)) |
| 11004 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11005 | |
| 11006 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11007 | * Stuff needs to be attented to when this function is invoked as an |
| 11008 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11009 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11010 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11011 | /* Check device state for handling interrupt */ |
| 11012 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11013 | return IRQ_NONE; |
| 11014 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11015 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11016 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11017 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11018 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11019 | /* |
| 11020 | * If there is deferred error attention, do not check for |
| 11021 | * any interrupt. |
| 11022 | */ |
| 11023 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11024 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11025 | return IRQ_NONE; |
| 11026 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11027 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 11028 | phba->HAregaddr); |
| 11029 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11030 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11031 | } else |
| 11032 | ha_copy = phba->ha_copy; |
| 11033 | |
| 11034 | /* |
| 11035 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 11036 | */ |
| 11037 | ha_copy &= ~(phba->work_ha_mask); |
| 11038 | |
| 11039 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11040 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11041 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11042 | lpfc_sli_handle_fast_ring_event(phba, |
| 11043 | &phba->sli.ring[LPFC_FCP_RING], |
| 11044 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11045 | |
| 11046 | if (phba->cfg_multi_ring_support == 2) { |
| 11047 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11048 | * Process all events on extra ring. Take the optimized path |
| 11049 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11050 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11051 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11052 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11053 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11054 | lpfc_sli_handle_fast_ring_event(phba, |
| 11055 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 11056 | status); |
| 11057 | } |
| 11058 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11059 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11060 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11061 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11062 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11063 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11064 | * @irq: Interrupt number. |
| 11065 | * @dev_id: The device context pointer. |
| 11066 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11067 | * This function is the HBA device-level interrupt handler to device with |
| 11068 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 11069 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 11070 | * requires driver attention. This function invokes the slow-path interrupt |
| 11071 | * attention handling function and fast-path interrupt attention handling |
| 11072 | * function in turn to process the relevant HBA attention events. This |
| 11073 | * function is called without any lock held. It gets the hbalock to access |
| 11074 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11075 | * |
| 11076 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11077 | * returns IRQ_NONE. |
| 11078 | **/ |
| 11079 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11080 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11081 | { |
| 11082 | struct lpfc_hba *phba; |
| 11083 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11084 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11085 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11086 | |
| 11087 | /* |
| 11088 | * Get the driver's phba structure from the dev_id and |
| 11089 | * assume the HBA is not interrupting. |
| 11090 | */ |
| 11091 | phba = (struct lpfc_hba *) dev_id; |
| 11092 | |
| 11093 | if (unlikely(!phba)) |
| 11094 | return IRQ_NONE; |
| 11095 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11096 | /* Check device state for handling interrupt */ |
| 11097 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11098 | return IRQ_NONE; |
| 11099 | |
| 11100 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11101 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 11102 | spin_unlock(&phba->hbalock); |
| 11103 | return IRQ_HANDLED; |
| 11104 | } |
| 11105 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11106 | if (unlikely(!phba->ha_copy)) { |
| 11107 | spin_unlock(&phba->hbalock); |
| 11108 | return IRQ_NONE; |
| 11109 | } else if (phba->ha_copy & HA_ERATT) { |
| 11110 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11111 | /* ERATT polling has handled ERATT */ |
| 11112 | phba->ha_copy &= ~HA_ERATT; |
| 11113 | else |
| 11114 | /* Indicate interrupt handler handles ERATT */ |
| 11115 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11116 | } |
| 11117 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11118 | /* |
| 11119 | * If there is deferred error attention, do not check for any interrupt. |
| 11120 | */ |
| 11121 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 11122 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11123 | return IRQ_NONE; |
| 11124 | } |
| 11125 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11126 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11127 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 11128 | spin_unlock(&phba->hbalock); |
| 11129 | return IRQ_HANDLED; |
| 11130 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11131 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 11132 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11133 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11134 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11135 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11136 | readl(phba->HAregaddr); /* flush */ |
| 11137 | spin_unlock(&phba->hbalock); |
| 11138 | |
| 11139 | /* |
| 11140 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11141 | */ |
| 11142 | |
| 11143 | /* status of events with mailbox and link attention */ |
| 11144 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 11145 | |
| 11146 | /* status of events with ELS ring */ |
| 11147 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11148 | status2 >>= (4*LPFC_ELS_RING); |
| 11149 | |
| 11150 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11151 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11152 | else |
| 11153 | sp_irq_rc = IRQ_NONE; |
| 11154 | |
| 11155 | /* |
| 11156 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11157 | */ |
| 11158 | |
| 11159 | /* status of events with FCP ring */ |
| 11160 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 11161 | status1 >>= (4*LPFC_FCP_RING); |
| 11162 | |
| 11163 | /* status of events with extra ring */ |
| 11164 | if (phba->cfg_multi_ring_support == 2) { |
| 11165 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 11166 | status2 >>= (4*LPFC_EXTRA_RING); |
| 11167 | } else |
| 11168 | status2 = 0; |
| 11169 | |
| 11170 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11171 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11172 | else |
| 11173 | fp_irq_rc = IRQ_NONE; |
| 11174 | |
| 11175 | /* Return device-level interrupt handling status */ |
| 11176 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11177 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11178 | |
| 11179 | /** |
| 11180 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 11181 | * @phba: pointer to lpfc hba data structure. |
| 11182 | * |
| 11183 | * This routine is invoked by the worker thread to process all the pending |
| 11184 | * SLI4 FCP abort XRI events. |
| 11185 | **/ |
| 11186 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11187 | { |
| 11188 | struct lpfc_cq_event *cq_event; |
| 11189 | |
| 11190 | /* First, declare the fcp xri abort event has been handled */ |
| 11191 | spin_lock_irq(&phba->hbalock); |
| 11192 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 11193 | spin_unlock_irq(&phba->hbalock); |
| 11194 | /* Now, handle all the fcp xri abort events */ |
| 11195 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 11196 | /* Get the first event from the head of the event queue */ |
| 11197 | spin_lock_irq(&phba->hbalock); |
| 11198 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 11199 | cq_event, struct lpfc_cq_event, list); |
| 11200 | spin_unlock_irq(&phba->hbalock); |
| 11201 | /* Notify aborted XRI for FCP work queue */ |
| 11202 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11203 | /* Free the event processed back to the free pool */ |
| 11204 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11205 | } |
| 11206 | } |
| 11207 | |
| 11208 | /** |
| 11209 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 11210 | * @phba: pointer to lpfc hba data structure. |
| 11211 | * |
| 11212 | * This routine is invoked by the worker thread to process all the pending |
| 11213 | * SLI4 els abort xri events. |
| 11214 | **/ |
| 11215 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11216 | { |
| 11217 | struct lpfc_cq_event *cq_event; |
| 11218 | |
| 11219 | /* First, declare the els xri abort event has been handled */ |
| 11220 | spin_lock_irq(&phba->hbalock); |
| 11221 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 11222 | spin_unlock_irq(&phba->hbalock); |
| 11223 | /* Now, handle all the els xri abort events */ |
| 11224 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 11225 | /* Get the first event from the head of the event queue */ |
| 11226 | spin_lock_irq(&phba->hbalock); |
| 11227 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11228 | cq_event, struct lpfc_cq_event, list); |
| 11229 | spin_unlock_irq(&phba->hbalock); |
| 11230 | /* Notify aborted XRI for ELS work queue */ |
| 11231 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11232 | /* Free the event processed back to the free pool */ |
| 11233 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11234 | } |
| 11235 | } |
| 11236 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11237 | /** |
| 11238 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 11239 | * @phba: pointer to lpfc hba data structure |
| 11240 | * @pIocbIn: pointer to the rspiocbq |
| 11241 | * @pIocbOut: pointer to the cmdiocbq |
| 11242 | * @wcqe: pointer to the complete wcqe |
| 11243 | * |
| 11244 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11245 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11246 | * completion status information from the complete wcqe. |
| 11247 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11248 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11249 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11250 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11251 | struct lpfc_iocbq *pIocbOut, |
| 11252 | struct lpfc_wcqe_complete *wcqe) |
| 11253 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11254 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11255 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11256 | uint32_t status, max_response; |
| 11257 | struct lpfc_dmabuf *dmabuf; |
| 11258 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11259 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11260 | |
| 11261 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11262 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11263 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11264 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11265 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11266 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11267 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11268 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11269 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11270 | wcqe->total_data_placed; |
| 11271 | else |
| 11272 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11273 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11274 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11275 | switch (pIocbOut->iocb.ulpCommand) { |
| 11276 | case CMD_ELS_REQUEST64_CR: |
| 11277 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11278 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11279 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 11280 | max_response = bde.tus.f.bdeSize; |
| 11281 | break; |
| 11282 | case CMD_GEN_REQUEST64_CR: |
| 11283 | max_response = 0; |
| 11284 | if (!pIocbOut->context3) |
| 11285 | break; |
| 11286 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 11287 | sizeof(struct ulp_bde64); |
| 11288 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11289 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11290 | for (i = 0; i < numBdes; i++) { |
| 11291 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 11292 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 11293 | max_response += bde.tus.f.bdeSize; |
| 11294 | } |
| 11295 | break; |
| 11296 | default: |
| 11297 | max_response = wcqe->total_data_placed; |
| 11298 | break; |
| 11299 | } |
| 11300 | if (max_response < wcqe->total_data_placed) |
| 11301 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 11302 | else |
| 11303 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 11304 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11305 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11306 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11307 | /* Convert BG errors for completion status */ |
| 11308 | if (status == CQE_STATUS_DI_ERROR) { |
| 11309 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11310 | |
| 11311 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11312 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11313 | else |
| 11314 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11315 | |
| 11316 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11317 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11318 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11319 | BGS_GUARD_ERR_MASK; |
| 11320 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11321 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11322 | BGS_APPTAG_ERR_MASK; |
| 11323 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11324 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11325 | BGS_REFTAG_ERR_MASK; |
| 11326 | |
| 11327 | /* Check to see if there was any good data before the error */ |
| 11328 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11329 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11330 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11331 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11332 | wcqe->total_data_placed; |
| 11333 | } |
| 11334 | |
| 11335 | /* |
| 11336 | * Set ALL the error bits to indicate we don't know what |
| 11337 | * type of error it is. |
| 11338 | */ |
| 11339 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11340 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11341 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11342 | BGS_GUARD_ERR_MASK); |
| 11343 | } |
| 11344 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11345 | /* Pick up HBA exchange busy condition */ |
| 11346 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11347 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11348 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11349 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11350 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11351 | } |
| 11352 | |
| 11353 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11354 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11355 | * @phba: Pointer to HBA context object. |
| 11356 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11357 | * |
| 11358 | * This routine handles an ELS work-queue completion event and construct |
| 11359 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11360 | * discovery engine to handle. |
| 11361 | * |
| 11362 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11363 | **/ |
| 11364 | static struct lpfc_iocbq * |
| 11365 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11366 | struct lpfc_iocbq *irspiocbq) |
| 11367 | { |
| 11368 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11369 | struct lpfc_iocbq *cmdiocbq; |
| 11370 | struct lpfc_wcqe_complete *wcqe; |
| 11371 | unsigned long iflags; |
| 11372 | |
| 11373 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11374 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11375 | pring->stats.iocb_event++; |
| 11376 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11377 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11378 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11379 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11380 | |
| 11381 | if (unlikely(!cmdiocbq)) { |
| 11382 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11383 | "0386 ELS complete with no corresponding " |
| 11384 | "cmdiocb: iotag (%d)\n", |
| 11385 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11386 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11387 | return NULL; |
| 11388 | } |
| 11389 | |
| 11390 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11391 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11392 | |
| 11393 | return irspiocbq; |
| 11394 | } |
| 11395 | |
| 11396 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11397 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11398 | * @phba: Pointer to HBA context object. |
| 11399 | * @cqe: Pointer to mailbox completion queue entry. |
| 11400 | * |
| 11401 | * This routine process a mailbox completion queue entry with asynchrous |
| 11402 | * event. |
| 11403 | * |
| 11404 | * Return: true if work posted to worker thread, otherwise false. |
| 11405 | **/ |
| 11406 | static bool |
| 11407 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11408 | { |
| 11409 | struct lpfc_cq_event *cq_event; |
| 11410 | unsigned long iflags; |
| 11411 | |
| 11412 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11413 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11414 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11415 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11416 | |
| 11417 | /* Allocate a new internal CQ_EVENT entry */ |
| 11418 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11419 | if (!cq_event) { |
| 11420 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11421 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11422 | return false; |
| 11423 | } |
| 11424 | |
| 11425 | /* Move the CQE into an asynchronous event entry */ |
| 11426 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11427 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11428 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11429 | /* Set the async event flag */ |
| 11430 | phba->hba_flag |= ASYNC_EVENT; |
| 11431 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11432 | |
| 11433 | return true; |
| 11434 | } |
| 11435 | |
| 11436 | /** |
| 11437 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11438 | * @phba: Pointer to HBA context object. |
| 11439 | * @cqe: Pointer to mailbox completion queue entry. |
| 11440 | * |
| 11441 | * This routine process a mailbox completion queue entry with mailbox |
| 11442 | * completion event. |
| 11443 | * |
| 11444 | * Return: true if work posted to worker thread, otherwise false. |
| 11445 | **/ |
| 11446 | static bool |
| 11447 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11448 | { |
| 11449 | uint32_t mcqe_status; |
| 11450 | MAILBOX_t *mbox, *pmbox; |
| 11451 | struct lpfc_mqe *mqe; |
| 11452 | struct lpfc_vport *vport; |
| 11453 | struct lpfc_nodelist *ndlp; |
| 11454 | struct lpfc_dmabuf *mp; |
| 11455 | unsigned long iflags; |
| 11456 | LPFC_MBOXQ_t *pmb; |
| 11457 | bool workposted = false; |
| 11458 | int rc; |
| 11459 | |
| 11460 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11461 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11462 | goto out_no_mqe_complete; |
| 11463 | |
| 11464 | /* Get the reference to the active mbox command */ |
| 11465 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11466 | pmb = phba->sli.mbox_active; |
| 11467 | if (unlikely(!pmb)) { |
| 11468 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11469 | "1832 No pending MBOX command to handle\n"); |
| 11470 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11471 | goto out_no_mqe_complete; |
| 11472 | } |
| 11473 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11474 | mqe = &pmb->u.mqe; |
| 11475 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11476 | mbox = phba->mbox; |
| 11477 | vport = pmb->vport; |
| 11478 | |
| 11479 | /* Reset heartbeat timer */ |
| 11480 | phba->last_completion_time = jiffies; |
| 11481 | del_timer(&phba->sli.mbox_tmo); |
| 11482 | |
| 11483 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11484 | if (pmb->mbox_cmpl && mbox) |
| 11485 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11486 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11487 | /* |
| 11488 | * For mcqe errors, conditionally move a modified error code to |
| 11489 | * the mbox so that the error will not be missed. |
| 11490 | */ |
| 11491 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11492 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11493 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11494 | bf_set(lpfc_mqe_status, mqe, |
| 11495 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11496 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11497 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11498 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11499 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11500 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11501 | mcqe_status, |
| 11502 | pmbox->un.varWords[0], 0); |
| 11503 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11504 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11505 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11506 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11507 | * RID of the PPI using the same mbox buffer. |
| 11508 | */ |
| 11509 | lpfc_unreg_login(phba, vport->vpi, |
| 11510 | pmbox->un.varWords[0], pmb); |
| 11511 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11512 | pmb->context1 = mp; |
| 11513 | pmb->context2 = ndlp; |
| 11514 | pmb->vport = vport; |
| 11515 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11516 | if (rc != MBX_BUSY) |
| 11517 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11518 | LOG_SLI, "0385 rc should " |
| 11519 | "have been MBX_BUSY\n"); |
| 11520 | if (rc != MBX_NOT_FINISHED) |
| 11521 | goto send_current_mbox; |
| 11522 | } |
| 11523 | } |
| 11524 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11525 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11526 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11527 | |
| 11528 | /* There is mailbox completion work to do */ |
| 11529 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11530 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11531 | phba->work_ha |= HA_MBATT; |
| 11532 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11533 | workposted = true; |
| 11534 | |
| 11535 | send_current_mbox: |
| 11536 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11537 | /* Release the mailbox command posting token */ |
| 11538 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11539 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11540 | phba->sli.mbox_active = NULL; |
| 11541 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11542 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11543 | lpfc_worker_wake_up(phba); |
| 11544 | out_no_mqe_complete: |
| 11545 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11546 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11547 | return workposted; |
| 11548 | } |
| 11549 | |
| 11550 | /** |
| 11551 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11552 | * @phba: Pointer to HBA context object. |
| 11553 | * @cqe: Pointer to mailbox completion queue entry. |
| 11554 | * |
| 11555 | * This routine process a mailbox completion queue entry, it invokes the |
| 11556 | * proper mailbox complete handling or asynchrous event handling routine |
| 11557 | * according to the MCQE's async bit. |
| 11558 | * |
| 11559 | * Return: true if work posted to worker thread, otherwise false. |
| 11560 | **/ |
| 11561 | static bool |
| 11562 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11563 | { |
| 11564 | struct lpfc_mcqe mcqe; |
| 11565 | bool workposted; |
| 11566 | |
| 11567 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11568 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11569 | |
| 11570 | /* Invoke the proper event handling routine */ |
| 11571 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11572 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11573 | else |
| 11574 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11575 | return workposted; |
| 11576 | } |
| 11577 | |
| 11578 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11579 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11580 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11581 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11582 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11583 | * |
| 11584 | * This routine handles an ELS work-queue completion event. |
| 11585 | * |
| 11586 | * Return: true if work posted to worker thread, otherwise false. |
| 11587 | **/ |
| 11588 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11589 | 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] | 11590 | struct lpfc_wcqe_complete *wcqe) |
| 11591 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11592 | struct lpfc_iocbq *irspiocbq; |
| 11593 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11594 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11595 | int txq_cnt = 0; |
| 11596 | int txcmplq_cnt = 0; |
| 11597 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11598 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11599 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11600 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11601 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11602 | if (!list_empty(&pring->txq)) |
| 11603 | txq_cnt++; |
| 11604 | if (!list_empty(&pring->txcmplq)) |
| 11605 | txcmplq_cnt++; |
| 11606 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 11607 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11608 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11609 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11610 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11611 | txq_cnt, phba->iocb_cnt, |
| 11612 | fcp_txcmplq_cnt, |
| 11613 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11614 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11615 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11616 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11617 | /* Save off the slow-path queue event for work thread to process */ |
| 11618 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11619 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11620 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11621 | &phba->sli4_hba.sp_queue_event); |
| 11622 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11623 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11624 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11625 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11626 | } |
| 11627 | |
| 11628 | /** |
| 11629 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11630 | * @phba: Pointer to HBA context object. |
| 11631 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11632 | * |
| 11633 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11634 | * proper WQ release routine to the slow-path WQ. |
| 11635 | **/ |
| 11636 | static void |
| 11637 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11638 | struct lpfc_wcqe_release *wcqe) |
| 11639 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11640 | /* sanity check on queue memory */ |
| 11641 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11642 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11643 | /* Check for the slow-path ELS work queue */ |
| 11644 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11645 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11646 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11647 | else |
| 11648 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11649 | "2579 Slow-path wqe consume event carries " |
| 11650 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11651 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11652 | phba->sli4_hba.els_wq->queue_id); |
| 11653 | } |
| 11654 | |
| 11655 | /** |
| 11656 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11657 | * @phba: Pointer to HBA context object. |
| 11658 | * @cq: Pointer to a WQ completion queue. |
| 11659 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11660 | * |
| 11661 | * This routine handles an XRI abort event. |
| 11662 | * |
| 11663 | * Return: true if work posted to worker thread, otherwise false. |
| 11664 | **/ |
| 11665 | static bool |
| 11666 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11667 | struct lpfc_queue *cq, |
| 11668 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11669 | { |
| 11670 | bool workposted = false; |
| 11671 | struct lpfc_cq_event *cq_event; |
| 11672 | unsigned long iflags; |
| 11673 | |
| 11674 | /* Allocate a new internal CQ_EVENT entry */ |
| 11675 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11676 | if (!cq_event) { |
| 11677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11678 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11679 | return false; |
| 11680 | } |
| 11681 | |
| 11682 | /* Move the CQE into the proper xri abort event list */ |
| 11683 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11684 | switch (cq->subtype) { |
| 11685 | case LPFC_FCP: |
| 11686 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11687 | list_add_tail(&cq_event->list, |
| 11688 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11689 | /* Set the fcp xri abort event flag */ |
| 11690 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11691 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11692 | workposted = true; |
| 11693 | break; |
| 11694 | case LPFC_ELS: |
| 11695 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11696 | list_add_tail(&cq_event->list, |
| 11697 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11698 | /* Set the els xri abort event flag */ |
| 11699 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11700 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11701 | workposted = true; |
| 11702 | break; |
| 11703 | default: |
| 11704 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11705 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11706 | cq->subtype); |
| 11707 | workposted = false; |
| 11708 | break; |
| 11709 | } |
| 11710 | return workposted; |
| 11711 | } |
| 11712 | |
| 11713 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11714 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11715 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11716 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11717 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11718 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11719 | * |
| 11720 | * Return: true if work posted to worker thread, otherwise false. |
| 11721 | **/ |
| 11722 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11723 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11724 | { |
| 11725 | bool workposted = false; |
| 11726 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11727 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11728 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11729 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11730 | unsigned long iflags; |
| 11731 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11732 | /* sanity check on queue memory */ |
| 11733 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11734 | return workposted; |
| 11735 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11736 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11737 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11738 | else |
| 11739 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11740 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11741 | goto out; |
| 11742 | |
| 11743 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11744 | switch (status) { |
| 11745 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11746 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11747 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11748 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11749 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11750 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11751 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11752 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11753 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11754 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11755 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11756 | goto out; |
| 11757 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11758 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11759 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11760 | /* save off the frame for the word thread to process */ |
| 11761 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11762 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11763 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11764 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11765 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11766 | workposted = true; |
| 11767 | break; |
| 11768 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11769 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11770 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11771 | /* Post more buffers if possible */ |
| 11772 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11773 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11774 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11775 | workposted = true; |
| 11776 | break; |
| 11777 | } |
| 11778 | out: |
| 11779 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11780 | } |
| 11781 | |
| 11782 | /** |
| 11783 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11784 | * @phba: Pointer to HBA context object. |
| 11785 | * @cq: Pointer to the completion queue. |
| 11786 | * @wcqe: Pointer to a completion queue entry. |
| 11787 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11788 | * 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] | 11789 | * entry. |
| 11790 | * |
| 11791 | * Return: true if work posted to worker thread, otherwise false. |
| 11792 | **/ |
| 11793 | static bool |
| 11794 | 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] | 11795 | struct lpfc_cqe *cqe) |
| 11796 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11797 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11798 | bool workposted = false; |
| 11799 | |
| 11800 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11801 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11802 | |
| 11803 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11804 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11805 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11806 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11807 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11808 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11809 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11810 | break; |
| 11811 | case CQE_CODE_RELEASE_WQE: |
| 11812 | /* Process the WQ release event */ |
| 11813 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11814 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11815 | break; |
| 11816 | case CQE_CODE_XRI_ABORTED: |
| 11817 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11818 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11819 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11820 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11821 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11822 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11823 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11824 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11825 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11826 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11827 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11828 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11829 | default: |
| 11830 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11831 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11832 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11833 | break; |
| 11834 | } |
| 11835 | return workposted; |
| 11836 | } |
| 11837 | |
| 11838 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11839 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11840 | * @phba: Pointer to HBA context object. |
| 11841 | * @eqe: Pointer to fast-path event queue entry. |
| 11842 | * |
| 11843 | * This routine process a event queue entry from the slow-path event queue. |
| 11844 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11845 | * completion event on a completion queue, if not, an error shall be logged |
| 11846 | * and just return. Otherwise, it will get to the corresponding completion |
| 11847 | * queue and process all the entries on that completion queue, rearm the |
| 11848 | * completion queue, and then return. |
| 11849 | * |
| 11850 | **/ |
| 11851 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11852 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11853 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11854 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11855 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11856 | struct lpfc_cqe *cqe; |
| 11857 | bool workposted = false; |
| 11858 | int ecount = 0; |
| 11859 | uint16_t cqid; |
| 11860 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11861 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11862 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11863 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11864 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11865 | if (childq->queue_id == cqid) { |
| 11866 | cq = childq; |
| 11867 | break; |
| 11868 | } |
| 11869 | } |
| 11870 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11871 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11872 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11873 | "0365 Slow-path CQ identifier " |
| 11874 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11875 | return; |
| 11876 | } |
| 11877 | |
| 11878 | /* Process all the entries to the CQ */ |
| 11879 | switch (cq->type) { |
| 11880 | case LPFC_MCQ: |
| 11881 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11882 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11883 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11884 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11885 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11886 | } |
| 11887 | break; |
| 11888 | case LPFC_WCQ: |
| 11889 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11890 | if (cq->subtype == LPFC_FCP) |
| 11891 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11892 | cqe); |
| 11893 | else |
| 11894 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11895 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11896 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11897 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11898 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11899 | |
| 11900 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11901 | if (ecount > cq->CQ_max_cqe) |
| 11902 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11903 | break; |
| 11904 | default: |
| 11905 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11906 | "0370 Invalid completion queue type (%d)\n", |
| 11907 | cq->type); |
| 11908 | return; |
| 11909 | } |
| 11910 | |
| 11911 | /* Catch the no cq entry condition, log an error */ |
| 11912 | if (unlikely(ecount == 0)) |
| 11913 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11914 | "0371 No entry from the CQ: identifier " |
| 11915 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11916 | |
| 11917 | /* In any case, flash and re-arm the RCQ */ |
| 11918 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11919 | |
| 11920 | /* wake up worker thread if there are works to be done */ |
| 11921 | if (workposted) |
| 11922 | lpfc_worker_wake_up(phba); |
| 11923 | } |
| 11924 | |
| 11925 | /** |
| 11926 | * 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] | 11927 | * @phba: Pointer to HBA context object. |
| 11928 | * @cq: Pointer to associated CQ |
| 11929 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11930 | * |
| 11931 | * This routine process a fast-path work queue completion entry from fast-path |
| 11932 | * event queue for FCP command response completion. |
| 11933 | **/ |
| 11934 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11935 | 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] | 11936 | struct lpfc_wcqe_complete *wcqe) |
| 11937 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11938 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11939 | struct lpfc_iocbq *cmdiocbq; |
| 11940 | struct lpfc_iocbq irspiocbq; |
| 11941 | unsigned long iflags; |
| 11942 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11943 | /* Check for response status */ |
| 11944 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11945 | /* If resource errors reported from HBA, reduce queue |
| 11946 | * depth of the SCSI device. |
| 11947 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11948 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11949 | IOSTAT_LOCAL_REJECT)) && |
| 11950 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 11951 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11952 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11953 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11954 | /* Log the error status */ |
| 11955 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11956 | "0373 FCP complete error: status=x%x, " |
| 11957 | "hw_status=x%x, total_data_specified=%d, " |
| 11958 | "parameter=x%x, word3=x%x\n", |
| 11959 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11960 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11961 | wcqe->total_data_placed, wcqe->parameter, |
| 11962 | wcqe->word3); |
| 11963 | } |
| 11964 | |
| 11965 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11966 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11967 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11968 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11969 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11970 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11971 | if (unlikely(!cmdiocbq)) { |
| 11972 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11973 | "0374 FCP complete with no corresponding " |
| 11974 | "cmdiocb: iotag (%d)\n", |
| 11975 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11976 | return; |
| 11977 | } |
| 11978 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11979 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11980 | "0375 FCP cmdiocb not callback function " |
| 11981 | "iotag: (%d)\n", |
| 11982 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11983 | return; |
| 11984 | } |
| 11985 | |
| 11986 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11987 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11988 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11989 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11990 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11991 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11992 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11993 | } |
| 11994 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11995 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11996 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11997 | } |
| 11998 | |
| 11999 | /** |
| 12000 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 12001 | * @phba: Pointer to HBA context object. |
| 12002 | * @cq: Pointer to completion queue. |
| 12003 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12004 | * |
| 12005 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 12006 | * proper WQ release routine to the slow-path WQ. |
| 12007 | **/ |
| 12008 | static void |
| 12009 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12010 | struct lpfc_wcqe_release *wcqe) |
| 12011 | { |
| 12012 | struct lpfc_queue *childwq; |
| 12013 | bool wqid_matched = false; |
| 12014 | uint16_t fcp_wqid; |
| 12015 | |
| 12016 | /* Check for fast-path FCP work queue release */ |
| 12017 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 12018 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 12019 | if (childwq->queue_id == fcp_wqid) { |
| 12020 | lpfc_sli4_wq_release(childwq, |
| 12021 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12022 | wqid_matched = true; |
| 12023 | break; |
| 12024 | } |
| 12025 | } |
| 12026 | /* Report warning log message if no match found */ |
| 12027 | if (wqid_matched != true) |
| 12028 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12029 | "2580 Fast-path wqe consume event carries " |
| 12030 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 12031 | } |
| 12032 | |
| 12033 | /** |
| 12034 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 12035 | * @cq: Pointer to the completion queue. |
| 12036 | * @eqe: Pointer to fast-path completion queue entry. |
| 12037 | * |
| 12038 | * This routine process a fast-path work queue completion entry from fast-path |
| 12039 | * event queue for FCP command response completion. |
| 12040 | **/ |
| 12041 | static int |
| 12042 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12043 | struct lpfc_cqe *cqe) |
| 12044 | { |
| 12045 | struct lpfc_wcqe_release wcqe; |
| 12046 | bool workposted = false; |
| 12047 | |
| 12048 | /* Copy the work queue CQE and convert endian order if needed */ |
| 12049 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 12050 | |
| 12051 | /* Check and process for different type of WCQE and dispatch */ |
| 12052 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 12053 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12054 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12055 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 12056 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12057 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12058 | (struct lpfc_wcqe_complete *)&wcqe); |
| 12059 | break; |
| 12060 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12061 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12062 | /* Process the WQ release event */ |
| 12063 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 12064 | (struct lpfc_wcqe_release *)&wcqe); |
| 12065 | break; |
| 12066 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12067 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12068 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12069 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12070 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 12071 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 12072 | break; |
| 12073 | default: |
| 12074 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12075 | "0144 Not a valid WCQE code: x%x\n", |
| 12076 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 12077 | break; |
| 12078 | } |
| 12079 | return workposted; |
| 12080 | } |
| 12081 | |
| 12082 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12083 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12084 | * @phba: Pointer to HBA context object. |
| 12085 | * @eqe: Pointer to fast-path event queue entry. |
| 12086 | * |
| 12087 | * This routine process a event queue entry from the fast-path event queue. |
| 12088 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12089 | * completion event on a completion queue, if not, an error shall be logged |
| 12090 | * and just return. Otherwise, it will get to the corresponding completion |
| 12091 | * queue and process all the entries on the completion queue, rearm the |
| 12092 | * completion queue, and then return. |
| 12093 | **/ |
| 12094 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12095 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12096 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12097 | { |
| 12098 | struct lpfc_queue *cq; |
| 12099 | struct lpfc_cqe *cqe; |
| 12100 | bool workposted = false; |
| 12101 | uint16_t cqid; |
| 12102 | int ecount = 0; |
| 12103 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12104 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12106 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12107 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12108 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12109 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12110 | return; |
| 12111 | } |
| 12112 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12113 | /* Get the reference to the corresponding CQ */ |
| 12114 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12115 | |
| 12116 | /* Check if this is a Slow path event */ |
| 12117 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 12118 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 12119 | phba->sli4_hba.hba_eq[qidx]); |
| 12120 | return; |
| 12121 | } |
| 12122 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12123 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 12124 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12125 | "3146 Fast-path completion queues " |
| 12126 | "does not exist\n"); |
| 12127 | return; |
| 12128 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12129 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12130 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12131 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12132 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12133 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12134 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12135 | return; |
| 12136 | } |
| 12137 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12138 | if (unlikely(cqid != cq->queue_id)) { |
| 12139 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12140 | "0368 Miss-matched fast-path completion " |
| 12141 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 12142 | cqid, cq->queue_id); |
| 12143 | return; |
| 12144 | } |
| 12145 | |
| 12146 | /* Process all the entries to the CQ */ |
| 12147 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12148 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12149 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12150 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12151 | } |
| 12152 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12153 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12154 | if (ecount > cq->CQ_max_cqe) |
| 12155 | cq->CQ_max_cqe = ecount; |
| 12156 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12157 | /* Catch the no cq entry condition */ |
| 12158 | if (unlikely(ecount == 0)) |
| 12159 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12160 | "0369 No entry from fast-path completion " |
| 12161 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12162 | |
| 12163 | /* In any case, flash and re-arm the CQ */ |
| 12164 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12165 | |
| 12166 | /* wake up worker thread if there are works to be done */ |
| 12167 | if (workposted) |
| 12168 | lpfc_worker_wake_up(phba); |
| 12169 | } |
| 12170 | |
| 12171 | static void |
| 12172 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12173 | { |
| 12174 | struct lpfc_eqe *eqe; |
| 12175 | |
| 12176 | /* walk all the EQ entries and drop on the floor */ |
| 12177 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 12178 | ; |
| 12179 | |
| 12180 | /* Clear and re-arm the EQ */ |
| 12181 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12182 | } |
| 12183 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 12184 | |
| 12185 | /** |
| 12186 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 12187 | * entry |
| 12188 | * @phba: Pointer to HBA context object. |
| 12189 | * @eqe: Pointer to fast-path event queue entry. |
| 12190 | * |
| 12191 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 12192 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 12193 | * is for a completion event on a completion queue, if not, an error shall be |
| 12194 | * logged and just return. Otherwise, it will get to the corresponding |
| 12195 | * completion queue and process all the entries on the completion queue, rearm |
| 12196 | * the completion queue, and then return. |
| 12197 | **/ |
| 12198 | static void |
| 12199 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 12200 | { |
| 12201 | struct lpfc_queue *cq; |
| 12202 | struct lpfc_cqe *cqe; |
| 12203 | bool workposted = false; |
| 12204 | uint16_t cqid; |
| 12205 | int ecount = 0; |
| 12206 | |
| 12207 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 12208 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12209 | "9147 Not a valid completion " |
| 12210 | "event: majorcode=x%x, minorcode=x%x\n", |
| 12211 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12212 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 12213 | return; |
| 12214 | } |
| 12215 | |
| 12216 | /* Get the reference to the corresponding CQ */ |
| 12217 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12218 | |
| 12219 | /* Next check for OAS */ |
| 12220 | cq = phba->sli4_hba.oas_cq; |
| 12221 | if (unlikely(!cq)) { |
| 12222 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12223 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12224 | "9148 OAS completion queue " |
| 12225 | "does not exist\n"); |
| 12226 | return; |
| 12227 | } |
| 12228 | |
| 12229 | if (unlikely(cqid != cq->queue_id)) { |
| 12230 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12231 | "9149 Miss-matched fast-path compl " |
| 12232 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 12233 | cqid, cq->queue_id); |
| 12234 | return; |
| 12235 | } |
| 12236 | |
| 12237 | /* Process all the entries to the OAS CQ */ |
| 12238 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12239 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
| 12240 | if (!(++ecount % cq->entry_repost)) |
| 12241 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12242 | } |
| 12243 | |
| 12244 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12245 | if (ecount > cq->CQ_max_cqe) |
| 12246 | cq->CQ_max_cqe = ecount; |
| 12247 | |
| 12248 | /* Catch the no cq entry condition */ |
| 12249 | if (unlikely(ecount == 0)) |
| 12250 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12251 | "9153 No entry from fast-path completion " |
| 12252 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12253 | |
| 12254 | /* In any case, flash and re-arm the CQ */ |
| 12255 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12256 | |
| 12257 | /* wake up worker thread if there are works to be done */ |
| 12258 | if (workposted) |
| 12259 | lpfc_worker_wake_up(phba); |
| 12260 | } |
| 12261 | |
| 12262 | /** |
| 12263 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 12264 | * @irq: Interrupt number. |
| 12265 | * @dev_id: The device context pointer. |
| 12266 | * |
| 12267 | * This function is directly called from the PCI layer as an interrupt |
| 12268 | * service routine when device with SLI-4 interface spec is enabled with |
| 12269 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 12270 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 12271 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12272 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12273 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12274 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 12275 | * the intrrupt context. This function is called without any lock held. |
| 12276 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12277 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 12278 | * equal to that of CQ index. |
| 12279 | * |
| 12280 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12281 | * returns IRQ_NONE. |
| 12282 | **/ |
| 12283 | irqreturn_t |
| 12284 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 12285 | { |
| 12286 | struct lpfc_hba *phba; |
| 12287 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12288 | struct lpfc_queue *eq; |
| 12289 | struct lpfc_eqe *eqe; |
| 12290 | unsigned long iflag; |
| 12291 | int ecount = 0; |
| 12292 | uint32_t eqidx; |
| 12293 | |
| 12294 | /* Get the driver's phba structure from the dev_id */ |
| 12295 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12296 | phba = fcp_eq_hdl->phba; |
| 12297 | eqidx = fcp_eq_hdl->idx; |
| 12298 | |
| 12299 | if (unlikely(!phba)) |
| 12300 | return IRQ_NONE; |
| 12301 | |
| 12302 | /* Get to the EQ struct associated with this vector */ |
| 12303 | eq = phba->sli4_hba.fof_eq; |
| 12304 | if (unlikely(!eq)) |
| 12305 | return IRQ_NONE; |
| 12306 | |
| 12307 | /* Check device state for handling interrupt */ |
| 12308 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 12309 | eq->EQ_badstate++; |
| 12310 | /* Check again for link_state with lock held */ |
| 12311 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12312 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12313 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12314 | lpfc_sli4_eq_flush(phba, eq); |
| 12315 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12316 | return IRQ_NONE; |
| 12317 | } |
| 12318 | |
| 12319 | /* |
| 12320 | * Process all the event on FCP fast-path EQ |
| 12321 | */ |
| 12322 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 12323 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 12324 | if (!(++ecount % eq->entry_repost)) |
| 12325 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); |
| 12326 | eq->EQ_processed++; |
| 12327 | } |
| 12328 | |
| 12329 | /* Track the max number of EQEs processed in 1 intr */ |
| 12330 | if (ecount > eq->EQ_max_eqe) |
| 12331 | eq->EQ_max_eqe = ecount; |
| 12332 | |
| 12333 | |
| 12334 | if (unlikely(ecount == 0)) { |
| 12335 | eq->EQ_no_entry++; |
| 12336 | |
| 12337 | if (phba->intr_type == MSIX) |
| 12338 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12339 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12340 | "9145 MSI-X interrupt with no EQE\n"); |
| 12341 | else { |
| 12342 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12343 | "9146 ISR interrupt with no EQE\n"); |
| 12344 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12345 | return IRQ_NONE; |
| 12346 | } |
| 12347 | } |
| 12348 | /* Always clear and re-arm the fast-path EQ */ |
| 12349 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12350 | return IRQ_HANDLED; |
| 12351 | } |
| 12352 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12353 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12354 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12355 | * @irq: Interrupt number. |
| 12356 | * @dev_id: The device context pointer. |
| 12357 | * |
| 12358 | * This function is directly called from the PCI layer as an interrupt |
| 12359 | * service routine when device with SLI-4 interface spec is enabled with |
| 12360 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12361 | * ring event in the HBA. However, when the device is enabled with either |
| 12362 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12363 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12364 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12365 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12366 | * the intrrupt context. This function is called without any lock held. |
| 12367 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12368 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 12369 | * equal to that of FCP CQ index. |
| 12370 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12371 | * The link attention and ELS ring attention events are handled |
| 12372 | * by the worker thread. The interrupt handler signals the worker thread |
| 12373 | * and returns for these events. This function is called without any lock |
| 12374 | * held. It gets the hbalock to access and update SLI data structures. |
| 12375 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12376 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12377 | * returns IRQ_NONE. |
| 12378 | **/ |
| 12379 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12380 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12381 | { |
| 12382 | struct lpfc_hba *phba; |
| 12383 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12384 | struct lpfc_queue *fpeq; |
| 12385 | struct lpfc_eqe *eqe; |
| 12386 | unsigned long iflag; |
| 12387 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12388 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12389 | |
| 12390 | /* Get the driver's phba structure from the dev_id */ |
| 12391 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12392 | phba = fcp_eq_hdl->phba; |
| 12393 | fcp_eqidx = fcp_eq_hdl->idx; |
| 12394 | |
| 12395 | if (unlikely(!phba)) |
| 12396 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12397 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12398 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12399 | |
| 12400 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12401 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12402 | if (unlikely(!fpeq)) |
| 12403 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12404 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12405 | if (lpfc_fcp_look_ahead) { |
| 12406 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 12407 | lpfc_sli4_eq_clr_intr(fpeq); |
| 12408 | else { |
| 12409 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12410 | return IRQ_NONE; |
| 12411 | } |
| 12412 | } |
| 12413 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12414 | /* Check device state for handling interrupt */ |
| 12415 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12416 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12417 | /* Check again for link_state with lock held */ |
| 12418 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12419 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12420 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12421 | lpfc_sli4_eq_flush(phba, fpeq); |
| 12422 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12423 | if (lpfc_fcp_look_ahead) |
| 12424 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12425 | return IRQ_NONE; |
| 12426 | } |
| 12427 | |
| 12428 | /* |
| 12429 | * Process all the event on FCP fast-path EQ |
| 12430 | */ |
| 12431 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12432 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12433 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12434 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12435 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12436 | } |
| 12437 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12438 | /* Track the max number of EQEs processed in 1 intr */ |
| 12439 | if (ecount > fpeq->EQ_max_eqe) |
| 12440 | fpeq->EQ_max_eqe = ecount; |
| 12441 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12442 | /* Always clear and re-arm the fast-path EQ */ |
| 12443 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 12444 | |
| 12445 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12446 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12447 | |
| 12448 | if (lpfc_fcp_look_ahead) { |
| 12449 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12450 | return IRQ_NONE; |
| 12451 | } |
| 12452 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12453 | if (phba->intr_type == MSIX) |
| 12454 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12455 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12456 | "0358 MSI-X interrupt with no EQE\n"); |
| 12457 | else |
| 12458 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12459 | return IRQ_NONE; |
| 12460 | } |
| 12461 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12462 | if (lpfc_fcp_look_ahead) |
| 12463 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12464 | return IRQ_HANDLED; |
| 12465 | } /* lpfc_sli4_fp_intr_handler */ |
| 12466 | |
| 12467 | /** |
| 12468 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12469 | * @irq: Interrupt number. |
| 12470 | * @dev_id: The device context pointer. |
| 12471 | * |
| 12472 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12473 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12474 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12475 | * driver attention. This function invokes the slow-path interrupt attention |
| 12476 | * handling function and fast-path interrupt attention handling function in |
| 12477 | * turn to process the relevant HBA attention events. This function is called |
| 12478 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12479 | * structures. |
| 12480 | * |
| 12481 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12482 | * returns IRQ_NONE. |
| 12483 | **/ |
| 12484 | irqreturn_t |
| 12485 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12486 | { |
| 12487 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12488 | irqreturn_t hba_irq_rc; |
| 12489 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12490 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12491 | |
| 12492 | /* Get the driver's phba structure from the dev_id */ |
| 12493 | phba = (struct lpfc_hba *)dev_id; |
| 12494 | |
| 12495 | if (unlikely(!phba)) |
| 12496 | return IRQ_NONE; |
| 12497 | |
| 12498 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12499 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12500 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12501 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12502 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12503 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12504 | if (hba_irq_rc == IRQ_HANDLED) |
| 12505 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12506 | } |
| 12507 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame^] | 12508 | if (phba->cfg_fof) { |
| 12509 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
| 12510 | &phba->sli4_hba.fcp_eq_hdl[0]); |
| 12511 | if (hba_irq_rc == IRQ_HANDLED) |
| 12512 | hba_handled |= true; |
| 12513 | } |
| 12514 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12515 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12516 | } /* lpfc_sli4_intr_handler */ |
| 12517 | |
| 12518 | /** |
| 12519 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12520 | * @queue: The queue structure to free. |
| 12521 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12522 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12523 | * the host resident queue. This function must be called after destroying the |
| 12524 | * queue on the HBA. |
| 12525 | **/ |
| 12526 | void |
| 12527 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12528 | { |
| 12529 | struct lpfc_dmabuf *dmabuf; |
| 12530 | |
| 12531 | if (!queue) |
| 12532 | return; |
| 12533 | |
| 12534 | while (!list_empty(&queue->page_list)) { |
| 12535 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12536 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12537 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12538 | dmabuf->virt, dmabuf->phys); |
| 12539 | kfree(dmabuf); |
| 12540 | } |
| 12541 | kfree(queue); |
| 12542 | return; |
| 12543 | } |
| 12544 | |
| 12545 | /** |
| 12546 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12547 | * @phba: The HBA that this queue is being created on. |
| 12548 | * @entry_size: The size of each queue entry for this queue. |
| 12549 | * @entry count: The number of entries that this queue will handle. |
| 12550 | * |
| 12551 | * This function allocates a queue structure and the DMAable memory used for |
| 12552 | * the host resident queue. This function must be called before creating the |
| 12553 | * queue on the HBA. |
| 12554 | **/ |
| 12555 | struct lpfc_queue * |
| 12556 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12557 | uint32_t entry_count) |
| 12558 | { |
| 12559 | struct lpfc_queue *queue; |
| 12560 | struct lpfc_dmabuf *dmabuf; |
| 12561 | int x, total_qe_count; |
| 12562 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12563 | 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] | 12564 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12565 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12566 | hw_page_size = SLI4_PAGE_SIZE; |
| 12567 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12568 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12569 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12570 | if (!queue) |
| 12571 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12572 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12573 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12574 | INIT_LIST_HEAD(&queue->list); |
| 12575 | INIT_LIST_HEAD(&queue->page_list); |
| 12576 | INIT_LIST_HEAD(&queue->child_list); |
| 12577 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12578 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12579 | if (!dmabuf) |
| 12580 | goto out_fail; |
| 12581 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12582 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12583 | GFP_KERNEL); |
| 12584 | if (!dmabuf->virt) { |
| 12585 | kfree(dmabuf); |
| 12586 | goto out_fail; |
| 12587 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12588 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12589 | dmabuf->buffer_tag = x; |
| 12590 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12591 | /* initialize queue's entry array */ |
| 12592 | dma_pointer = dmabuf->virt; |
| 12593 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12594 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12595 | total_qe_count++, dma_pointer += entry_size) { |
| 12596 | queue->qe[total_qe_count].address = dma_pointer; |
| 12597 | } |
| 12598 | } |
| 12599 | queue->entry_size = entry_size; |
| 12600 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12601 | |
| 12602 | /* |
| 12603 | * entry_repost is calculated based on the number of entries in the |
| 12604 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12605 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12606 | */ |
| 12607 | queue->entry_repost = (entry_count >> 3); |
| 12608 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12609 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12610 | queue->phba = phba; |
| 12611 | |
| 12612 | return queue; |
| 12613 | out_fail: |
| 12614 | lpfc_sli4_queue_free(queue); |
| 12615 | return NULL; |
| 12616 | } |
| 12617 | |
| 12618 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12619 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 12620 | * @phba: HBA structure that indicates port to create a queue on. |
| 12621 | * @pci_barset: PCI BAR set flag. |
| 12622 | * |
| 12623 | * This function shall perform iomap of the specified PCI BAR address to host |
| 12624 | * memory address if not already done so and return it. The returned host |
| 12625 | * memory address can be NULL. |
| 12626 | */ |
| 12627 | static void __iomem * |
| 12628 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 12629 | { |
| 12630 | struct pci_dev *pdev; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12631 | |
| 12632 | if (!phba->pcidev) |
| 12633 | return NULL; |
| 12634 | else |
| 12635 | pdev = phba->pcidev; |
| 12636 | |
| 12637 | switch (pci_barset) { |
| 12638 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12639 | return phba->pci_bar0_memmap_p; |
| 12640 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12641 | return phba->pci_bar2_memmap_p; |
| 12642 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12643 | return phba->pci_bar4_memmap_p; |
| 12644 | default: |
| 12645 | break; |
| 12646 | } |
| 12647 | return NULL; |
| 12648 | } |
| 12649 | |
| 12650 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12651 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12652 | * @phba: HBA structure that indicates port to create a queue on. |
| 12653 | * @startq: The starting FCP EQ to modify |
| 12654 | * |
| 12655 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12656 | * |
| 12657 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12658 | * is used to get the starting FCP EQ to change. |
| 12659 | * This function is asynchronous and will wait for the mailbox |
| 12660 | * command to finish before continuing. |
| 12661 | * |
| 12662 | * On success this function will return a zero. If unable to allocate enough |
| 12663 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12664 | * fails this function will return -ENXIO. |
| 12665 | **/ |
| 12666 | uint32_t |
| 12667 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12668 | { |
| 12669 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12670 | LPFC_MBOXQ_t *mbox; |
| 12671 | struct lpfc_queue *eq; |
| 12672 | int cnt, rc, length, status = 0; |
| 12673 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12674 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12675 | int fcp_eqidx; |
| 12676 | union lpfc_sli4_cfg_shdr *shdr; |
| 12677 | uint16_t dmult; |
| 12678 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12679 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12680 | return 0; |
| 12681 | |
| 12682 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12683 | if (!mbox) |
| 12684 | return -ENOMEM; |
| 12685 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12686 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12687 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12688 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12689 | length, LPFC_SLI4_MBX_EMBED); |
| 12690 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12691 | |
| 12692 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12693 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 12694 | if (result > LPFC_DMULT_CONST) |
| 12695 | dmult = 0; |
| 12696 | else |
| 12697 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12698 | |
| 12699 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12700 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12701 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12702 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12703 | if (!eq) |
| 12704 | continue; |
| 12705 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12706 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12707 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12708 | cnt++; |
| 12709 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12710 | break; |
| 12711 | } |
| 12712 | eq_delay->u.request.num_eq = cnt; |
| 12713 | |
| 12714 | mbox->vport = phba->pport; |
| 12715 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12716 | mbox->context1 = NULL; |
| 12717 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12718 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12719 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12720 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12721 | if (shdr_status || shdr_add_status || rc) { |
| 12722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12723 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12724 | "status x%x add_status x%x, mbx status x%x\n", |
| 12725 | shdr_status, shdr_add_status, rc); |
| 12726 | status = -ENXIO; |
| 12727 | } |
| 12728 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12729 | return status; |
| 12730 | } |
| 12731 | |
| 12732 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12733 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12734 | * @phba: HBA structure that indicates port to create a queue on. |
| 12735 | * @eq: The queue structure to use to create the event queue. |
| 12736 | * @imax: The maximum interrupt per second limit. |
| 12737 | * |
| 12738 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12739 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12740 | * |
| 12741 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12742 | * is used to get the entry count and entry size that are necessary to |
| 12743 | * determine the number of pages to allocate and use for this queue. This |
| 12744 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12745 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12746 | * command to finish before continuing. |
| 12747 | * |
| 12748 | * 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] | 12749 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12750 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12751 | **/ |
| 12752 | uint32_t |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12753 | 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] | 12754 | { |
| 12755 | struct lpfc_mbx_eq_create *eq_create; |
| 12756 | LPFC_MBOXQ_t *mbox; |
| 12757 | int rc, length, status = 0; |
| 12758 | struct lpfc_dmabuf *dmabuf; |
| 12759 | uint32_t shdr_status, shdr_add_status; |
| 12760 | union lpfc_sli4_cfg_shdr *shdr; |
| 12761 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12762 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12763 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12764 | /* sanity check on queue memory */ |
| 12765 | if (!eq) |
| 12766 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12767 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12768 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12769 | |
| 12770 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12771 | if (!mbox) |
| 12772 | return -ENOMEM; |
| 12773 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12774 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12775 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12776 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12777 | length, LPFC_SLI4_MBX_EMBED); |
| 12778 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12779 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12780 | eq->page_count); |
| 12781 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12782 | LPFC_EQE_SIZE); |
| 12783 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12784 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12785 | if (imax > LPFC_DMULT_CONST) |
| 12786 | dmult = 0; |
| 12787 | else |
| 12788 | dmult = LPFC_DMULT_CONST/imax - 1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12789 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12790 | dmult); |
| 12791 | switch (eq->entry_count) { |
| 12792 | default: |
| 12793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12794 | "0360 Unsupported EQ count. (%d)\n", |
| 12795 | eq->entry_count); |
| 12796 | if (eq->entry_count < 256) |
| 12797 | return -EINVAL; |
| 12798 | /* otherwise default to smallest count (drop through) */ |
| 12799 | case 256: |
| 12800 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12801 | LPFC_EQ_CNT_256); |
| 12802 | break; |
| 12803 | case 512: |
| 12804 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12805 | LPFC_EQ_CNT_512); |
| 12806 | break; |
| 12807 | case 1024: |
| 12808 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12809 | LPFC_EQ_CNT_1024); |
| 12810 | break; |
| 12811 | case 2048: |
| 12812 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12813 | LPFC_EQ_CNT_2048); |
| 12814 | break; |
| 12815 | case 4096: |
| 12816 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12817 | LPFC_EQ_CNT_4096); |
| 12818 | break; |
| 12819 | } |
| 12820 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12821 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12822 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12823 | putPaddrLow(dmabuf->phys); |
| 12824 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12825 | putPaddrHigh(dmabuf->phys); |
| 12826 | } |
| 12827 | mbox->vport = phba->pport; |
| 12828 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12829 | mbox->context1 = NULL; |
| 12830 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12831 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12832 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12833 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12834 | if (shdr_status || shdr_add_status || rc) { |
| 12835 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12836 | "2500 EQ_CREATE mailbox failed with " |
| 12837 | "status x%x add_status x%x, mbx status x%x\n", |
| 12838 | shdr_status, shdr_add_status, rc); |
| 12839 | status = -ENXIO; |
| 12840 | } |
| 12841 | eq->type = LPFC_EQ; |
| 12842 | eq->subtype = LPFC_NONE; |
| 12843 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12844 | if (eq->queue_id == 0xFFFF) |
| 12845 | status = -ENXIO; |
| 12846 | eq->host_index = 0; |
| 12847 | eq->hba_index = 0; |
| 12848 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12849 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12850 | return status; |
| 12851 | } |
| 12852 | |
| 12853 | /** |
| 12854 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12855 | * @phba: HBA structure that indicates port to create a queue on. |
| 12856 | * @cq: The queue structure to use to create the completion queue. |
| 12857 | * @eq: The event queue to bind this completion queue to. |
| 12858 | * |
| 12859 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12860 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12861 | * |
| 12862 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12863 | * is used to get the entry count and entry size that are necessary to |
| 12864 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12865 | * is used to indicate which event queue to bind this completion queue to. This |
| 12866 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12867 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12868 | * command to finish before continuing. |
| 12869 | * |
| 12870 | * 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] | 12871 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12872 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12873 | **/ |
| 12874 | uint32_t |
| 12875 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12876 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12877 | { |
| 12878 | struct lpfc_mbx_cq_create *cq_create; |
| 12879 | struct lpfc_dmabuf *dmabuf; |
| 12880 | LPFC_MBOXQ_t *mbox; |
| 12881 | int rc, length, status = 0; |
| 12882 | uint32_t shdr_status, shdr_add_status; |
| 12883 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12884 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12885 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12886 | /* sanity check on queue memory */ |
| 12887 | if (!cq || !eq) |
| 12888 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12889 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12890 | hw_page_size = SLI4_PAGE_SIZE; |
| 12891 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12892 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12893 | if (!mbox) |
| 12894 | return -ENOMEM; |
| 12895 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12896 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12897 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12898 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12899 | length, LPFC_SLI4_MBX_EMBED); |
| 12900 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12901 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12902 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12903 | cq->page_count); |
| 12904 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12905 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12906 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12907 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12908 | 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] | 12909 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12910 | 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] | 12911 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12912 | eq->queue_id); |
| 12913 | } else { |
| 12914 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12915 | eq->queue_id); |
| 12916 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12917 | switch (cq->entry_count) { |
| 12918 | default: |
| 12919 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12920 | "0361 Unsupported CQ count. (%d)\n", |
| 12921 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12922 | if (cq->entry_count < 256) { |
| 12923 | status = -EINVAL; |
| 12924 | goto out; |
| 12925 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12926 | /* otherwise default to smallest count (drop through) */ |
| 12927 | case 256: |
| 12928 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12929 | LPFC_CQ_CNT_256); |
| 12930 | break; |
| 12931 | case 512: |
| 12932 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12933 | LPFC_CQ_CNT_512); |
| 12934 | break; |
| 12935 | case 1024: |
| 12936 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12937 | LPFC_CQ_CNT_1024); |
| 12938 | break; |
| 12939 | } |
| 12940 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12941 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12942 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12943 | putPaddrLow(dmabuf->phys); |
| 12944 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12945 | putPaddrHigh(dmabuf->phys); |
| 12946 | } |
| 12947 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12948 | |
| 12949 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12950 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12951 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12952 | if (shdr_status || shdr_add_status || rc) { |
| 12953 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12954 | "2501 CQ_CREATE mailbox failed with " |
| 12955 | "status x%x add_status x%x, mbx status x%x\n", |
| 12956 | shdr_status, shdr_add_status, rc); |
| 12957 | status = -ENXIO; |
| 12958 | goto out; |
| 12959 | } |
| 12960 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12961 | if (cq->queue_id == 0xFFFF) { |
| 12962 | status = -ENXIO; |
| 12963 | goto out; |
| 12964 | } |
| 12965 | /* link the cq onto the parent eq child list */ |
| 12966 | list_add_tail(&cq->list, &eq->child_list); |
| 12967 | /* Set up completion queue's type and subtype */ |
| 12968 | cq->type = type; |
| 12969 | cq->subtype = subtype; |
| 12970 | 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] | 12971 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12972 | cq->host_index = 0; |
| 12973 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12974 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12975 | out: |
| 12976 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12977 | return status; |
| 12978 | } |
| 12979 | |
| 12980 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12981 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12982 | * @phba: HBA structure that indicates port to create a queue on. |
| 12983 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12984 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12985 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12986 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12987 | * This function provides failback (fb) functionality when the |
| 12988 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12989 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12990 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12991 | * This routine cannot fail as all attributes were previously accessed and |
| 12992 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12993 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12994 | static void |
| 12995 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12996 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12997 | { |
| 12998 | struct lpfc_mbx_mq_create *mq_create; |
| 12999 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13000 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13001 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13002 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 13003 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13004 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13005 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 13006 | length, LPFC_SLI4_MBX_EMBED); |
| 13007 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13008 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13009 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13010 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13011 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13012 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 13013 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13014 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13015 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13016 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13017 | break; |
| 13018 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13019 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13020 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13021 | break; |
| 13022 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13023 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13024 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13025 | break; |
| 13026 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13027 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 13028 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13029 | break; |
| 13030 | } |
| 13031 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 13032 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13033 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13034 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13035 | putPaddrHigh(dmabuf->phys); |
| 13036 | } |
| 13037 | } |
| 13038 | |
| 13039 | /** |
| 13040 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 13041 | * @phba: HBA structure that indicates port to create a queue on. |
| 13042 | * @mq: The queue structure to use to create the mailbox queue. |
| 13043 | * @cq: The completion queue to associate with this cq. |
| 13044 | * @subtype: The queue's subtype. |
| 13045 | * |
| 13046 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 13047 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 13048 | * |
| 13049 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 13050 | * is used to get the entry count and entry size that are necessary to |
| 13051 | * determine the number of pages to allocate and use for this queue. This |
| 13052 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 13053 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 13054 | * command to finish before continuing. |
| 13055 | * |
| 13056 | * 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] | 13057 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13058 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13059 | **/ |
| 13060 | int32_t |
| 13061 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 13062 | struct lpfc_queue *cq, uint32_t subtype) |
| 13063 | { |
| 13064 | struct lpfc_mbx_mq_create *mq_create; |
| 13065 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 13066 | struct lpfc_dmabuf *dmabuf; |
| 13067 | LPFC_MBOXQ_t *mbox; |
| 13068 | int rc, length, status = 0; |
| 13069 | uint32_t shdr_status, shdr_add_status; |
| 13070 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13071 | 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] | 13072 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13073 | /* sanity check on queue memory */ |
| 13074 | if (!mq || !cq) |
| 13075 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13076 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13077 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13078 | |
| 13079 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13080 | if (!mbox) |
| 13081 | return -ENOMEM; |
| 13082 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 13083 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13084 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13085 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 13086 | length, LPFC_SLI4_MBX_EMBED); |
| 13087 | |
| 13088 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13089 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13090 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 13091 | &mq_create_ext->u.request, mq->page_count); |
| 13092 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 13093 | &mq_create_ext->u.request, 1); |
| 13094 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13095 | &mq_create_ext->u.request, 1); |
| 13096 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 13097 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 13098 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 13099 | &mq_create_ext->u.request, 1); |
| 13100 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 13101 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13102 | 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] | 13103 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13104 | phba->sli4_hba.pc_sli4_params.mqv); |
| 13105 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 13106 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 13107 | cq->queue_id); |
| 13108 | else |
| 13109 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 13110 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13111 | switch (mq->entry_count) { |
| 13112 | default: |
| 13113 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13114 | "0362 Unsupported MQ count. (%d)\n", |
| 13115 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13116 | if (mq->entry_count < 16) { |
| 13117 | status = -EINVAL; |
| 13118 | goto out; |
| 13119 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13120 | /* otherwise default to smallest count (drop through) */ |
| 13121 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13122 | bf_set(lpfc_mq_context_ring_size, |
| 13123 | &mq_create_ext->u.request.context, |
| 13124 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13125 | break; |
| 13126 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13127 | bf_set(lpfc_mq_context_ring_size, |
| 13128 | &mq_create_ext->u.request.context, |
| 13129 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13130 | break; |
| 13131 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13132 | bf_set(lpfc_mq_context_ring_size, |
| 13133 | &mq_create_ext->u.request.context, |
| 13134 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13135 | break; |
| 13136 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13137 | bf_set(lpfc_mq_context_ring_size, |
| 13138 | &mq_create_ext->u.request.context, |
| 13139 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13140 | break; |
| 13141 | } |
| 13142 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13143 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13144 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13145 | putPaddrLow(dmabuf->phys); |
| 13146 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13147 | putPaddrHigh(dmabuf->phys); |
| 13148 | } |
| 13149 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 13150 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13151 | &mq_create_ext->u.response); |
| 13152 | if (rc != MBX_SUCCESS) { |
| 13153 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13154 | "2795 MQ_CREATE_EXT failed with " |
| 13155 | "status x%x. Failback to MQ_CREATE.\n", |
| 13156 | rc); |
| 13157 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 13158 | mq_create = &mbox->u.mqe.un.mq_create; |
| 13159 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13160 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 13161 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 13162 | &mq_create->u.response); |
| 13163 | } |
| 13164 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13165 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13166 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13167 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13168 | if (shdr_status || shdr_add_status || rc) { |
| 13169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13170 | "2502 MQ_CREATE mailbox failed with " |
| 13171 | "status x%x add_status x%x, mbx status x%x\n", |
| 13172 | shdr_status, shdr_add_status, rc); |
| 13173 | status = -ENXIO; |
| 13174 | goto out; |
| 13175 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13176 | if (mq->queue_id == 0xFFFF) { |
| 13177 | status = -ENXIO; |
| 13178 | goto out; |
| 13179 | } |
| 13180 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13181 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13182 | mq->subtype = subtype; |
| 13183 | mq->host_index = 0; |
| 13184 | mq->hba_index = 0; |
| 13185 | |
| 13186 | /* link the mq onto the parent cq child list */ |
| 13187 | list_add_tail(&mq->list, &cq->child_list); |
| 13188 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13189 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13190 | return status; |
| 13191 | } |
| 13192 | |
| 13193 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13194 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 13195 | * @phba: HBA structure that indicates port to create a queue on. |
| 13196 | * @wq: The queue structure to use to create the work queue. |
| 13197 | * @cq: The completion queue to bind this work queue to. |
| 13198 | * @subtype: The subtype of the work queue indicating its functionality. |
| 13199 | * |
| 13200 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 13201 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 13202 | * |
| 13203 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 13204 | * is used to get the entry count and entry size that are necessary to |
| 13205 | * determine the number of pages to allocate and use for this queue. The @cq |
| 13206 | * is used to indicate which completion queue to bind this work queue to. This |
| 13207 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 13208 | * work queue. This function is asynchronous and will wait for the mailbox |
| 13209 | * command to finish before continuing. |
| 13210 | * |
| 13211 | * 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] | 13212 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13213 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13214 | **/ |
| 13215 | uint32_t |
| 13216 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 13217 | struct lpfc_queue *cq, uint32_t subtype) |
| 13218 | { |
| 13219 | struct lpfc_mbx_wq_create *wq_create; |
| 13220 | struct lpfc_dmabuf *dmabuf; |
| 13221 | LPFC_MBOXQ_t *mbox; |
| 13222 | int rc, length, status = 0; |
| 13223 | uint32_t shdr_status, shdr_add_status; |
| 13224 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13225 | 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] | 13226 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13227 | void __iomem *bar_memmap_p; |
| 13228 | uint32_t db_offset; |
| 13229 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13230 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13231 | /* sanity check on queue memory */ |
| 13232 | if (!wq || !cq) |
| 13233 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13234 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13235 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13236 | |
| 13237 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13238 | if (!mbox) |
| 13239 | return -ENOMEM; |
| 13240 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 13241 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13242 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13243 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 13244 | length, LPFC_SLI4_MBX_EMBED); |
| 13245 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13246 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13247 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 13248 | wq->page_count); |
| 13249 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 13250 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13251 | |
| 13252 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13253 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13254 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13255 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13256 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 13257 | case LPFC_Q_CREATE_VERSION_0: |
| 13258 | switch (wq->entry_size) { |
| 13259 | default: |
| 13260 | case 64: |
| 13261 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 13262 | page = wq_create->u.request.page; |
| 13263 | break; |
| 13264 | case 128: |
| 13265 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13266 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13267 | status = -ERANGE; |
| 13268 | goto out; |
| 13269 | } |
| 13270 | /* If we get here the HBA MUST also support V1 and |
| 13271 | * we MUST use it |
| 13272 | */ |
| 13273 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13274 | LPFC_Q_CREATE_VERSION_1); |
| 13275 | |
| 13276 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 13277 | &wq_create->u.request_1, wq->entry_count); |
| 13278 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13279 | &wq_create->u.request_1, |
| 13280 | LPFC_WQ_WQE_SIZE_128); |
| 13281 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13282 | &wq_create->u.request_1, |
| 13283 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13284 | page = wq_create->u.request_1.page; |
| 13285 | break; |
| 13286 | } |
| 13287 | break; |
| 13288 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13289 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 13290 | wq->entry_count); |
| 13291 | switch (wq->entry_size) { |
| 13292 | default: |
| 13293 | case 64: |
| 13294 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13295 | &wq_create->u.request_1, |
| 13296 | LPFC_WQ_WQE_SIZE_64); |
| 13297 | break; |
| 13298 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13299 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13300 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13301 | status = -ERANGE; |
| 13302 | goto out; |
| 13303 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13304 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13305 | &wq_create->u.request_1, |
| 13306 | LPFC_WQ_WQE_SIZE_128); |
| 13307 | break; |
| 13308 | } |
| 13309 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 13310 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13311 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13312 | break; |
| 13313 | default: |
| 13314 | status = -ERANGE; |
| 13315 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13316 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13317 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13318 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13319 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13320 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 13321 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13322 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13323 | |
| 13324 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13325 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 13326 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13327 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13328 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13329 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13330 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13331 | if (shdr_status || shdr_add_status || rc) { |
| 13332 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13333 | "2503 WQ_CREATE mailbox failed with " |
| 13334 | "status x%x add_status x%x, mbx status x%x\n", |
| 13335 | shdr_status, shdr_add_status, rc); |
| 13336 | status = -ENXIO; |
| 13337 | goto out; |
| 13338 | } |
| 13339 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 13340 | if (wq->queue_id == 0xFFFF) { |
| 13341 | status = -ENXIO; |
| 13342 | goto out; |
| 13343 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13344 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13345 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 13346 | &wq_create->u.response); |
| 13347 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13348 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13349 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13350 | "3265 WQ[%d] doorbell format not " |
| 13351 | "supported: x%x\n", wq->queue_id, |
| 13352 | wq->db_format); |
| 13353 | status = -EINVAL; |
| 13354 | goto out; |
| 13355 | } |
| 13356 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 13357 | &wq_create->u.response); |
| 13358 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13359 | if (!bar_memmap_p) { |
| 13360 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13361 | "3263 WQ[%d] failed to memmap pci " |
| 13362 | "barset:x%x\n", wq->queue_id, |
| 13363 | pci_barset); |
| 13364 | status = -ENOMEM; |
| 13365 | goto out; |
| 13366 | } |
| 13367 | db_offset = wq_create->u.response.doorbell_offset; |
| 13368 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 13369 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 13370 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13371 | "3252 WQ[%d] doorbell offset not " |
| 13372 | "supported: x%x\n", wq->queue_id, |
| 13373 | db_offset); |
| 13374 | status = -EINVAL; |
| 13375 | goto out; |
| 13376 | } |
| 13377 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 13378 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13379 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 13380 | "format:x%x\n", wq->queue_id, pci_barset, |
| 13381 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13382 | } else { |
| 13383 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 13384 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 13385 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13386 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13387 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13388 | wq->subtype = subtype; |
| 13389 | wq->host_index = 0; |
| 13390 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 13391 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13392 | |
| 13393 | /* link the wq onto the parent cq child list */ |
| 13394 | list_add_tail(&wq->list, &cq->child_list); |
| 13395 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13396 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13397 | return status; |
| 13398 | } |
| 13399 | |
| 13400 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13401 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 13402 | * @phba: HBA structure that indicates port to create a queue on. |
| 13403 | * @rq: The queue structure to use for the receive queue. |
| 13404 | * @qno: The associated HBQ number |
| 13405 | * |
| 13406 | * |
| 13407 | * For SLI4 we need to adjust the RQ repost value based on |
| 13408 | * the number of buffers that are initially posted to the RQ. |
| 13409 | */ |
| 13410 | void |
| 13411 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 13412 | { |
| 13413 | uint32_t cnt; |
| 13414 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13415 | /* sanity check on queue memory */ |
| 13416 | if (!rq) |
| 13417 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13418 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 13419 | |
| 13420 | /* Recalc repost for RQs based on buffers initially posted */ |
| 13421 | cnt = (cnt >> 3); |
| 13422 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 13423 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 13424 | |
| 13425 | rq->entry_repost = cnt; |
| 13426 | } |
| 13427 | |
| 13428 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13429 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 13430 | * @phba: HBA structure that indicates port to create a queue on. |
| 13431 | * @hrq: The queue structure to use to create the header receive queue. |
| 13432 | * @drq: The queue structure to use to create the data receive queue. |
| 13433 | * @cq: The completion queue to bind this work queue to. |
| 13434 | * |
| 13435 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 13436 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 13437 | * to the HBA. |
| 13438 | * |
| 13439 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 13440 | * struct is used to get the entry count that is necessary to determine the |
| 13441 | * number of pages to use for this queue. The @cq is used to indicate which |
| 13442 | * completion queue to bind received buffers that are posted to these queues to. |
| 13443 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 13444 | * receive queue pair. This function is asynchronous and will wait for the |
| 13445 | * mailbox command to finish before continuing. |
| 13446 | * |
| 13447 | * 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] | 13448 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13449 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13450 | **/ |
| 13451 | uint32_t |
| 13452 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13453 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 13454 | { |
| 13455 | struct lpfc_mbx_rq_create *rq_create; |
| 13456 | struct lpfc_dmabuf *dmabuf; |
| 13457 | LPFC_MBOXQ_t *mbox; |
| 13458 | int rc, length, status = 0; |
| 13459 | uint32_t shdr_status, shdr_add_status; |
| 13460 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13461 | 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] | 13462 | void __iomem *bar_memmap_p; |
| 13463 | uint32_t db_offset; |
| 13464 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13465 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13466 | /* sanity check on queue memory */ |
| 13467 | if (!hrq || !drq || !cq) |
| 13468 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13469 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13470 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13471 | |
| 13472 | if (hrq->entry_count != drq->entry_count) |
| 13473 | return -EINVAL; |
| 13474 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13475 | if (!mbox) |
| 13476 | return -ENOMEM; |
| 13477 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 13478 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13479 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13480 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13481 | length, LPFC_SLI4_MBX_EMBED); |
| 13482 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13483 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13484 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13485 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13486 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13487 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13488 | &rq_create->u.request.context, |
| 13489 | hrq->entry_count); |
| 13490 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13491 | bf_set(lpfc_rq_context_rqe_size, |
| 13492 | &rq_create->u.request.context, |
| 13493 | LPFC_RQE_SIZE_8); |
| 13494 | bf_set(lpfc_rq_context_page_size, |
| 13495 | &rq_create->u.request.context, |
| 13496 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13497 | } else { |
| 13498 | switch (hrq->entry_count) { |
| 13499 | default: |
| 13500 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13501 | "2535 Unsupported RQ count. (%d)\n", |
| 13502 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13503 | if (hrq->entry_count < 512) { |
| 13504 | status = -EINVAL; |
| 13505 | goto out; |
| 13506 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13507 | /* otherwise default to smallest count (drop through) */ |
| 13508 | case 512: |
| 13509 | bf_set(lpfc_rq_context_rqe_count, |
| 13510 | &rq_create->u.request.context, |
| 13511 | LPFC_RQ_RING_SIZE_512); |
| 13512 | break; |
| 13513 | case 1024: |
| 13514 | bf_set(lpfc_rq_context_rqe_count, |
| 13515 | &rq_create->u.request.context, |
| 13516 | LPFC_RQ_RING_SIZE_1024); |
| 13517 | break; |
| 13518 | case 2048: |
| 13519 | bf_set(lpfc_rq_context_rqe_count, |
| 13520 | &rq_create->u.request.context, |
| 13521 | LPFC_RQ_RING_SIZE_2048); |
| 13522 | break; |
| 13523 | case 4096: |
| 13524 | bf_set(lpfc_rq_context_rqe_count, |
| 13525 | &rq_create->u.request.context, |
| 13526 | LPFC_RQ_RING_SIZE_4096); |
| 13527 | break; |
| 13528 | } |
| 13529 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13530 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13531 | } |
| 13532 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13533 | cq->queue_id); |
| 13534 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13535 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13536 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13537 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13538 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13539 | putPaddrLow(dmabuf->phys); |
| 13540 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13541 | putPaddrHigh(dmabuf->phys); |
| 13542 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13543 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13544 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 13545 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13546 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13547 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13548 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13549 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13550 | if (shdr_status || shdr_add_status || rc) { |
| 13551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13552 | "2504 RQ_CREATE mailbox failed with " |
| 13553 | "status x%x add_status x%x, mbx status x%x\n", |
| 13554 | shdr_status, shdr_add_status, rc); |
| 13555 | status = -ENXIO; |
| 13556 | goto out; |
| 13557 | } |
| 13558 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13559 | if (hrq->queue_id == 0xFFFF) { |
| 13560 | status = -ENXIO; |
| 13561 | goto out; |
| 13562 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13563 | |
| 13564 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13565 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13566 | &rq_create->u.response); |
| 13567 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13568 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13570 | "3262 RQ [%d] doorbell format not " |
| 13571 | "supported: x%x\n", hrq->queue_id, |
| 13572 | hrq->db_format); |
| 13573 | status = -EINVAL; |
| 13574 | goto out; |
| 13575 | } |
| 13576 | |
| 13577 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 13578 | &rq_create->u.response); |
| 13579 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13580 | if (!bar_memmap_p) { |
| 13581 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13582 | "3269 RQ[%d] failed to memmap pci " |
| 13583 | "barset:x%x\n", hrq->queue_id, |
| 13584 | pci_barset); |
| 13585 | status = -ENOMEM; |
| 13586 | goto out; |
| 13587 | } |
| 13588 | |
| 13589 | db_offset = rq_create->u.response.doorbell_offset; |
| 13590 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 13591 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 13592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13593 | "3270 RQ[%d] doorbell offset not " |
| 13594 | "supported: x%x\n", hrq->queue_id, |
| 13595 | db_offset); |
| 13596 | status = -EINVAL; |
| 13597 | goto out; |
| 13598 | } |
| 13599 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 13600 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13601 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 13602 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 13603 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13604 | } else { |
| 13605 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 13606 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 13607 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13608 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13609 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13610 | hrq->subtype = subtype; |
| 13611 | hrq->host_index = 0; |
| 13612 | hrq->hba_index = 0; |
| 13613 | |
| 13614 | /* now create the data queue */ |
| 13615 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13616 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13617 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13618 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13619 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13620 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13621 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13622 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13623 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13624 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 13625 | LPFC_RQE_SIZE_8); |
| 13626 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 13627 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13628 | } else { |
| 13629 | switch (drq->entry_count) { |
| 13630 | default: |
| 13631 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13632 | "2536 Unsupported RQ count. (%d)\n", |
| 13633 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13634 | if (drq->entry_count < 512) { |
| 13635 | status = -EINVAL; |
| 13636 | goto out; |
| 13637 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13638 | /* otherwise default to smallest count (drop through) */ |
| 13639 | case 512: |
| 13640 | bf_set(lpfc_rq_context_rqe_count, |
| 13641 | &rq_create->u.request.context, |
| 13642 | LPFC_RQ_RING_SIZE_512); |
| 13643 | break; |
| 13644 | case 1024: |
| 13645 | bf_set(lpfc_rq_context_rqe_count, |
| 13646 | &rq_create->u.request.context, |
| 13647 | LPFC_RQ_RING_SIZE_1024); |
| 13648 | break; |
| 13649 | case 2048: |
| 13650 | bf_set(lpfc_rq_context_rqe_count, |
| 13651 | &rq_create->u.request.context, |
| 13652 | LPFC_RQ_RING_SIZE_2048); |
| 13653 | break; |
| 13654 | case 4096: |
| 13655 | bf_set(lpfc_rq_context_rqe_count, |
| 13656 | &rq_create->u.request.context, |
| 13657 | LPFC_RQ_RING_SIZE_4096); |
| 13658 | break; |
| 13659 | } |
| 13660 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13661 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13662 | } |
| 13663 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13664 | cq->queue_id); |
| 13665 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13666 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13667 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 13668 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13669 | putPaddrLow(dmabuf->phys); |
| 13670 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13671 | putPaddrHigh(dmabuf->phys); |
| 13672 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13673 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13674 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13675 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13676 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13677 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13678 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13679 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13680 | if (shdr_status || shdr_add_status || rc) { |
| 13681 | status = -ENXIO; |
| 13682 | goto out; |
| 13683 | } |
| 13684 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13685 | if (drq->queue_id == 0xFFFF) { |
| 13686 | status = -ENXIO; |
| 13687 | goto out; |
| 13688 | } |
| 13689 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13690 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13691 | drq->subtype = subtype; |
| 13692 | drq->host_index = 0; |
| 13693 | drq->hba_index = 0; |
| 13694 | |
| 13695 | /* link the header and data RQs onto the parent cq child list */ |
| 13696 | list_add_tail(&hrq->list, &cq->child_list); |
| 13697 | list_add_tail(&drq->list, &cq->child_list); |
| 13698 | |
| 13699 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13700 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13701 | return status; |
| 13702 | } |
| 13703 | |
| 13704 | /** |
| 13705 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13706 | * @eq: The queue structure associated with the queue to destroy. |
| 13707 | * |
| 13708 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13709 | * command, specific to the type of queue, to the HBA. |
| 13710 | * |
| 13711 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13712 | * |
| 13713 | * 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] | 13714 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13715 | **/ |
| 13716 | uint32_t |
| 13717 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13718 | { |
| 13719 | LPFC_MBOXQ_t *mbox; |
| 13720 | int rc, length, status = 0; |
| 13721 | uint32_t shdr_status, shdr_add_status; |
| 13722 | union lpfc_sli4_cfg_shdr *shdr; |
| 13723 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13724 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13725 | if (!eq) |
| 13726 | return -ENODEV; |
| 13727 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13728 | if (!mbox) |
| 13729 | return -ENOMEM; |
| 13730 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13731 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13732 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13733 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13734 | length, LPFC_SLI4_MBX_EMBED); |
| 13735 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13736 | eq->queue_id); |
| 13737 | mbox->vport = eq->phba->pport; |
| 13738 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13739 | |
| 13740 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13741 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13742 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13743 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13744 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13745 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13746 | if (shdr_status || shdr_add_status || rc) { |
| 13747 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13748 | "2505 EQ_DESTROY mailbox failed with " |
| 13749 | "status x%x add_status x%x, mbx status x%x\n", |
| 13750 | shdr_status, shdr_add_status, rc); |
| 13751 | status = -ENXIO; |
| 13752 | } |
| 13753 | |
| 13754 | /* Remove eq from any list */ |
| 13755 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13756 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13757 | return status; |
| 13758 | } |
| 13759 | |
| 13760 | /** |
| 13761 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13762 | * @cq: The queue structure associated with the queue to destroy. |
| 13763 | * |
| 13764 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13765 | * command, specific to the type of queue, to the HBA. |
| 13766 | * |
| 13767 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13768 | * |
| 13769 | * 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] | 13770 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13771 | **/ |
| 13772 | uint32_t |
| 13773 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13774 | { |
| 13775 | LPFC_MBOXQ_t *mbox; |
| 13776 | int rc, length, status = 0; |
| 13777 | uint32_t shdr_status, shdr_add_status; |
| 13778 | union lpfc_sli4_cfg_shdr *shdr; |
| 13779 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13780 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13781 | if (!cq) |
| 13782 | return -ENODEV; |
| 13783 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13784 | if (!mbox) |
| 13785 | return -ENOMEM; |
| 13786 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13787 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13788 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13789 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13790 | length, LPFC_SLI4_MBX_EMBED); |
| 13791 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13792 | cq->queue_id); |
| 13793 | mbox->vport = cq->phba->pport; |
| 13794 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13795 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13796 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13797 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13798 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13799 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13800 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13801 | if (shdr_status || shdr_add_status || rc) { |
| 13802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13803 | "2506 CQ_DESTROY mailbox failed with " |
| 13804 | "status x%x add_status x%x, mbx status x%x\n", |
| 13805 | shdr_status, shdr_add_status, rc); |
| 13806 | status = -ENXIO; |
| 13807 | } |
| 13808 | /* Remove cq from any list */ |
| 13809 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13810 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13811 | return status; |
| 13812 | } |
| 13813 | |
| 13814 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13815 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13816 | * @qm: The queue structure associated with the queue to destroy. |
| 13817 | * |
| 13818 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13819 | * command, specific to the type of queue, to the HBA. |
| 13820 | * |
| 13821 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13822 | * |
| 13823 | * 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] | 13824 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13825 | **/ |
| 13826 | uint32_t |
| 13827 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13828 | { |
| 13829 | LPFC_MBOXQ_t *mbox; |
| 13830 | int rc, length, status = 0; |
| 13831 | uint32_t shdr_status, shdr_add_status; |
| 13832 | union lpfc_sli4_cfg_shdr *shdr; |
| 13833 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13834 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13835 | if (!mq) |
| 13836 | return -ENODEV; |
| 13837 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13838 | if (!mbox) |
| 13839 | return -ENOMEM; |
| 13840 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13841 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13842 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13843 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13844 | length, LPFC_SLI4_MBX_EMBED); |
| 13845 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13846 | mq->queue_id); |
| 13847 | mbox->vport = mq->phba->pport; |
| 13848 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13849 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13850 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13851 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13852 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13853 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13854 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13855 | if (shdr_status || shdr_add_status || rc) { |
| 13856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13857 | "2507 MQ_DESTROY mailbox failed with " |
| 13858 | "status x%x add_status x%x, mbx status x%x\n", |
| 13859 | shdr_status, shdr_add_status, rc); |
| 13860 | status = -ENXIO; |
| 13861 | } |
| 13862 | /* Remove mq from any list */ |
| 13863 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13864 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13865 | return status; |
| 13866 | } |
| 13867 | |
| 13868 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13869 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13870 | * @wq: The queue structure associated with the queue to destroy. |
| 13871 | * |
| 13872 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13873 | * command, specific to the type of queue, to the HBA. |
| 13874 | * |
| 13875 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13876 | * |
| 13877 | * 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] | 13878 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13879 | **/ |
| 13880 | uint32_t |
| 13881 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13882 | { |
| 13883 | LPFC_MBOXQ_t *mbox; |
| 13884 | int rc, length, status = 0; |
| 13885 | uint32_t shdr_status, shdr_add_status; |
| 13886 | union lpfc_sli4_cfg_shdr *shdr; |
| 13887 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13888 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13889 | if (!wq) |
| 13890 | return -ENODEV; |
| 13891 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13892 | if (!mbox) |
| 13893 | return -ENOMEM; |
| 13894 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13895 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13896 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13897 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13898 | length, LPFC_SLI4_MBX_EMBED); |
| 13899 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13900 | wq->queue_id); |
| 13901 | mbox->vport = wq->phba->pport; |
| 13902 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13903 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13904 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13905 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13906 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13907 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13908 | if (shdr_status || shdr_add_status || rc) { |
| 13909 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13910 | "2508 WQ_DESTROY mailbox failed with " |
| 13911 | "status x%x add_status x%x, mbx status x%x\n", |
| 13912 | shdr_status, shdr_add_status, rc); |
| 13913 | status = -ENXIO; |
| 13914 | } |
| 13915 | /* Remove wq from any list */ |
| 13916 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13917 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13918 | return status; |
| 13919 | } |
| 13920 | |
| 13921 | /** |
| 13922 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13923 | * @rq: The queue structure associated with the queue to destroy. |
| 13924 | * |
| 13925 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13926 | * command, specific to the type of queue, to the HBA. |
| 13927 | * |
| 13928 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13929 | * |
| 13930 | * 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] | 13931 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13932 | **/ |
| 13933 | uint32_t |
| 13934 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13935 | struct lpfc_queue *drq) |
| 13936 | { |
| 13937 | LPFC_MBOXQ_t *mbox; |
| 13938 | int rc, length, status = 0; |
| 13939 | uint32_t shdr_status, shdr_add_status; |
| 13940 | union lpfc_sli4_cfg_shdr *shdr; |
| 13941 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13942 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13943 | if (!hrq || !drq) |
| 13944 | return -ENODEV; |
| 13945 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13946 | if (!mbox) |
| 13947 | return -ENOMEM; |
| 13948 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13949 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13950 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13951 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13952 | length, LPFC_SLI4_MBX_EMBED); |
| 13953 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13954 | hrq->queue_id); |
| 13955 | mbox->vport = hrq->phba->pport; |
| 13956 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13957 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13958 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13959 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13960 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13961 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13962 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13963 | if (shdr_status || shdr_add_status || rc) { |
| 13964 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13965 | "2509 RQ_DESTROY mailbox failed with " |
| 13966 | "status x%x add_status x%x, mbx status x%x\n", |
| 13967 | shdr_status, shdr_add_status, rc); |
| 13968 | if (rc != MBX_TIMEOUT) |
| 13969 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13970 | return -ENXIO; |
| 13971 | } |
| 13972 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13973 | drq->queue_id); |
| 13974 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13975 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13976 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13977 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13978 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13979 | if (shdr_status || shdr_add_status || rc) { |
| 13980 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13981 | "2510 RQ_DESTROY mailbox failed with " |
| 13982 | "status x%x add_status x%x, mbx status x%x\n", |
| 13983 | shdr_status, shdr_add_status, rc); |
| 13984 | status = -ENXIO; |
| 13985 | } |
| 13986 | list_del_init(&hrq->list); |
| 13987 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13988 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13989 | return status; |
| 13990 | } |
| 13991 | |
| 13992 | /** |
| 13993 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13994 | * @phba: The virtual port for which this call being executed. |
| 13995 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13996 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13997 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13998 | * |
| 13999 | * This routine will post the sgl pages for the IO that has the xritag |
| 14000 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 14001 | * creation and persists for as long as the driver is loaded. |
| 14002 | * if the caller has fewer than 256 scatter gather segments to map then |
| 14003 | * pdma_phys_addr1 should be 0. |
| 14004 | * If the caller needs to map more than 256 scatter gather segment then |
| 14005 | * pdma_phys_addr1 should be a valid physical address. |
| 14006 | * physical address for SGLs must be 64 byte aligned. |
| 14007 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 14008 | * the second sgl can have between 1 and 256 entries. |
| 14009 | * |
| 14010 | * Return codes: |
| 14011 | * 0 - Success |
| 14012 | * -ENXIO, -ENOMEM - Failure |
| 14013 | **/ |
| 14014 | int |
| 14015 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 14016 | dma_addr_t pdma_phys_addr0, |
| 14017 | dma_addr_t pdma_phys_addr1, |
| 14018 | uint16_t xritag) |
| 14019 | { |
| 14020 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 14021 | LPFC_MBOXQ_t *mbox; |
| 14022 | int rc; |
| 14023 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14024 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14025 | union lpfc_sli4_cfg_shdr *shdr; |
| 14026 | |
| 14027 | if (xritag == NO_XRI) { |
| 14028 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14029 | "0364 Invalid param:\n"); |
| 14030 | return -EINVAL; |
| 14031 | } |
| 14032 | |
| 14033 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14034 | if (!mbox) |
| 14035 | return -ENOMEM; |
| 14036 | |
| 14037 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14038 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 14039 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 14040 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14041 | |
| 14042 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 14043 | &mbox->u.mqe.un.post_sgl_pages; |
| 14044 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 14045 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 14046 | |
| 14047 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 14048 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 14049 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 14050 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 14051 | |
| 14052 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 14053 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 14054 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 14055 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 14056 | if (!phba->sli4_hba.intr_enable) |
| 14057 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14058 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14059 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14060 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14061 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14062 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14063 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 14064 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14065 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14066 | if (rc != MBX_TIMEOUT) |
| 14067 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14068 | if (shdr_status || shdr_add_status || rc) { |
| 14069 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14070 | "2511 POST_SGL mailbox failed with " |
| 14071 | "status x%x add_status x%x, mbx status x%x\n", |
| 14072 | shdr_status, shdr_add_status, rc); |
| 14073 | rc = -ENXIO; |
| 14074 | } |
| 14075 | return 0; |
| 14076 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14077 | |
| 14078 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14079 | * 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] | 14080 | * @phba: pointer to lpfc hba data structure. |
| 14081 | * |
| 14082 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14083 | * HBA consistent with the SLI-4 interface spec. This routine |
| 14084 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 14085 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14086 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14087 | * Returns |
| 14088 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 14089 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 14090 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14091 | uint16_t |
| 14092 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 14093 | { |
| 14094 | unsigned long xri; |
| 14095 | |
| 14096 | /* |
| 14097 | * Fetch the next logical xri. Because this index is logical, |
| 14098 | * the driver starts at 0 each time. |
| 14099 | */ |
| 14100 | spin_lock_irq(&phba->hbalock); |
| 14101 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 14102 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 14103 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 14104 | spin_unlock_irq(&phba->hbalock); |
| 14105 | return NO_XRI; |
| 14106 | } else { |
| 14107 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 14108 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14109 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14110 | spin_unlock_irq(&phba->hbalock); |
| 14111 | return xri; |
| 14112 | } |
| 14113 | |
| 14114 | /** |
| 14115 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14116 | * @phba: pointer to lpfc hba data structure. |
| 14117 | * |
| 14118 | * This routine is invoked to release an xri to the pool of |
| 14119 | * available rpis maintained by the driver. |
| 14120 | **/ |
| 14121 | void |
| 14122 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14123 | { |
| 14124 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14125 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 14126 | } |
| 14127 | } |
| 14128 | |
| 14129 | /** |
| 14130 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 14131 | * @phba: pointer to lpfc hba data structure. |
| 14132 | * |
| 14133 | * This routine is invoked to release an xri to the pool of |
| 14134 | * available rpis maintained by the driver. |
| 14135 | **/ |
| 14136 | void |
| 14137 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 14138 | { |
| 14139 | spin_lock_irq(&phba->hbalock); |
| 14140 | __lpfc_sli4_free_xri(phba, xri); |
| 14141 | spin_unlock_irq(&phba->hbalock); |
| 14142 | } |
| 14143 | |
| 14144 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14145 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 14146 | * @phba: Pointer to HBA context object. |
| 14147 | * |
| 14148 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 14149 | * it will return 0xffff. |
| 14150 | * The function returns the allocated xritag if successful, else returns zero. |
| 14151 | * Zero is not a valid xritag. |
| 14152 | * The caller is not required to hold any lock. |
| 14153 | **/ |
| 14154 | uint16_t |
| 14155 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 14156 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14157 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14158 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14159 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 14160 | if (xri_index == NO_XRI) |
| 14161 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14162 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 14163 | " Max XRI is %d, Used XRI is %d\n", |
| 14164 | xri_index, |
| 14165 | phba->sli4_hba.max_cfg_param.max_xri, |
| 14166 | phba->sli4_hba.max_cfg_param.xri_used); |
| 14167 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14168 | } |
| 14169 | |
| 14170 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14171 | * 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] | 14172 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14173 | * @post_sgl_list: pointer to els sgl entry list. |
| 14174 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14175 | * |
| 14176 | * This routine is invoked to post a block of driver's sgl pages to the |
| 14177 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 14178 | * is only called when the driver is loading and after all IO has been |
| 14179 | * stopped. |
| 14180 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14181 | static int |
| 14182 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 14183 | struct list_head *post_sgl_list, |
| 14184 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14185 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14186 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14187 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14188 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14189 | void *viraddr; |
| 14190 | LPFC_MBOXQ_t *mbox; |
| 14191 | uint32_t reqlen, alloclen, pg_pairs; |
| 14192 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14193 | uint16_t xritag_start = 0; |
| 14194 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14195 | uint32_t shdr_status, shdr_add_status; |
| 14196 | union lpfc_sli4_cfg_shdr *shdr; |
| 14197 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14198 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14199 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14200 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14201 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14202 | "2559 Block sgl registration required DMA " |
| 14203 | "size (%d) great than a page\n", reqlen); |
| 14204 | return -ENOMEM; |
| 14205 | } |
| 14206 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14207 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14208 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14209 | |
| 14210 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14211 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14212 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14213 | LPFC_SLI4_MBX_NEMBED); |
| 14214 | |
| 14215 | if (alloclen < reqlen) { |
| 14216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14217 | "0285 Allocated DMA memory size (%d) is " |
| 14218 | "less than the requested DMA memory " |
| 14219 | "size (%d)\n", alloclen, reqlen); |
| 14220 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14221 | return -ENOMEM; |
| 14222 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14223 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14224 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14226 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14227 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14228 | pg_pairs = 0; |
| 14229 | 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] | 14230 | /* Set up the sge entry */ |
| 14231 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14232 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 14233 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14234 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 14235 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14236 | cpu_to_le32(putPaddrLow(0)); |
| 14237 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14238 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14239 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14240 | /* Keep the first xritag on the list */ |
| 14241 | if (pg_pairs == 0) |
| 14242 | xritag_start = sglq_entry->sli4_xritag; |
| 14243 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14244 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14245 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14246 | |
| 14247 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14248 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14249 | 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] | 14250 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14251 | if (!phba->sli4_hba.intr_enable) |
| 14252 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14253 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14254 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14255 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14256 | } |
| 14257 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14258 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14259 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14260 | if (rc != MBX_TIMEOUT) |
| 14261 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14262 | if (shdr_status || shdr_add_status || rc) { |
| 14263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14264 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 14265 | "status x%x add_status x%x mbx status x%x\n", |
| 14266 | shdr_status, shdr_add_status, rc); |
| 14267 | rc = -ENXIO; |
| 14268 | } |
| 14269 | return rc; |
| 14270 | } |
| 14271 | |
| 14272 | /** |
| 14273 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 14274 | * @phba: pointer to lpfc hba data structure. |
| 14275 | * @sblist: pointer to scsi buffer list. |
| 14276 | * @count: number of scsi buffers on the list. |
| 14277 | * |
| 14278 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 14279 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 14280 | * No Lock is held. |
| 14281 | * |
| 14282 | **/ |
| 14283 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14284 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 14285 | struct list_head *sblist, |
| 14286 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14287 | { |
| 14288 | struct lpfc_scsi_buf *psb; |
| 14289 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14290 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14291 | void *viraddr; |
| 14292 | LPFC_MBOXQ_t *mbox; |
| 14293 | uint32_t reqlen, alloclen, pg_pairs; |
| 14294 | uint32_t mbox_tmo; |
| 14295 | uint16_t xritag_start = 0; |
| 14296 | int rc = 0; |
| 14297 | uint32_t shdr_status, shdr_add_status; |
| 14298 | dma_addr_t pdma_phys_bpl1; |
| 14299 | union lpfc_sli4_cfg_shdr *shdr; |
| 14300 | |
| 14301 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14302 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14303 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14304 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14305 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14306 | "0217 Block sgl registration required DMA " |
| 14307 | "size (%d) great than a page\n", reqlen); |
| 14308 | return -ENOMEM; |
| 14309 | } |
| 14310 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14311 | if (!mbox) { |
| 14312 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14313 | "0283 Failed to allocate mbox cmd memory\n"); |
| 14314 | return -ENOMEM; |
| 14315 | } |
| 14316 | |
| 14317 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14318 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14319 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14320 | LPFC_SLI4_MBX_NEMBED); |
| 14321 | |
| 14322 | if (alloclen < reqlen) { |
| 14323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14324 | "2561 Allocated DMA memory size (%d) is " |
| 14325 | "less than the requested DMA memory " |
| 14326 | "size (%d)\n", alloclen, reqlen); |
| 14327 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14328 | return -ENOMEM; |
| 14329 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14330 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14331 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14332 | viraddr = mbox->sge_array->addr[0]; |
| 14333 | |
| 14334 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 14335 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14336 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14337 | |
| 14338 | pg_pairs = 0; |
| 14339 | list_for_each_entry(psb, sblist, list) { |
| 14340 | /* Set up the sge entry */ |
| 14341 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14342 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 14343 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14344 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 14345 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 14346 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 14347 | else |
| 14348 | pdma_phys_bpl1 = 0; |
| 14349 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14350 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 14351 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14352 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 14353 | /* Keep the first xritag on the list */ |
| 14354 | if (pg_pairs == 0) |
| 14355 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 14356 | sgl_pg_pairs++; |
| 14357 | pg_pairs++; |
| 14358 | } |
| 14359 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 14360 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 14361 | /* Perform endian conversion if necessary */ |
| 14362 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 14363 | |
| 14364 | if (!phba->sli4_hba.intr_enable) |
| 14365 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14366 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14367 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14368 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14369 | } |
| 14370 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14371 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14372 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14373 | if (rc != MBX_TIMEOUT) |
| 14374 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14375 | if (shdr_status || shdr_add_status || rc) { |
| 14376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14377 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 14378 | "status x%x add_status x%x mbx status x%x\n", |
| 14379 | shdr_status, shdr_add_status, rc); |
| 14380 | rc = -ENXIO; |
| 14381 | } |
| 14382 | return rc; |
| 14383 | } |
| 14384 | |
| 14385 | /** |
| 14386 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 14387 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 14388 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14389 | * |
| 14390 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 14391 | * valid type of frame that the LPFC driver will handle. This function will |
| 14392 | * return a zero if the frame is a valid frame or a non zero value when the |
| 14393 | * frame does not pass the check. |
| 14394 | **/ |
| 14395 | static int |
| 14396 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 14397 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 14398 | /* make rctl_names static to save stack space */ |
| 14399 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14400 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 14401 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14402 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14403 | |
| 14404 | switch (fc_hdr->fh_r_ctl) { |
| 14405 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 14406 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 14407 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 14408 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 14409 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 14410 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 14411 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 14412 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 14413 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 14414 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 14415 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 14416 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 14417 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 14418 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 14419 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 14420 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 14421 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 14422 | case FC_RCTL_BA_PRMT: |
| 14423 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 14424 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 14425 | case FC_RCTL_P_RJT: /* port reject */ |
| 14426 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 14427 | case FC_RCTL_P_BSY: /* port busy */ |
| 14428 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 14429 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 14430 | case FC_RCTL_LCR: /* link credit reset */ |
| 14431 | case FC_RCTL_END: /* end */ |
| 14432 | break; |
| 14433 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 14434 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14435 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 14436 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 14437 | default: |
| 14438 | goto drop; |
| 14439 | } |
| 14440 | switch (fc_hdr->fh_type) { |
| 14441 | case FC_TYPE_BLS: |
| 14442 | case FC_TYPE_ELS: |
| 14443 | case FC_TYPE_FCP: |
| 14444 | case FC_TYPE_CT: |
| 14445 | break; |
| 14446 | case FC_TYPE_IP: |
| 14447 | case FC_TYPE_ILS: |
| 14448 | default: |
| 14449 | goto drop; |
| 14450 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14451 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14452 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14453 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
| 14454 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
| 14455 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, |
| 14456 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14457 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 14458 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14459 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 14460 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14461 | return 0; |
| 14462 | drop: |
| 14463 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14464 | "2539 Dropped frame rctl:%s type:%s\n", |
| 14465 | rctl_names[fc_hdr->fh_r_ctl], |
| 14466 | type_names[fc_hdr->fh_type]); |
| 14467 | return 1; |
| 14468 | } |
| 14469 | |
| 14470 | /** |
| 14471 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 14472 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14473 | * |
| 14474 | * This function processes the FC header to retrieve the VFI from the VF |
| 14475 | * header, if one exists. This function will return the VFI if one exists |
| 14476 | * or 0 if no VSAN Header exists. |
| 14477 | **/ |
| 14478 | static uint32_t |
| 14479 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 14480 | { |
| 14481 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14482 | |
| 14483 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14484 | return 0; |
| 14485 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14486 | } |
| 14487 | |
| 14488 | /** |
| 14489 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14490 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14491 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14492 | * @fcfi: The FC Fabric ID that the frame came from |
| 14493 | * |
| 14494 | * This function searches the @phba for a vport that matches the content of the |
| 14495 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14496 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14497 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14498 | * vport. |
| 14499 | **/ |
| 14500 | static struct lpfc_vport * |
| 14501 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14502 | uint16_t fcfi) |
| 14503 | { |
| 14504 | struct lpfc_vport **vports; |
| 14505 | struct lpfc_vport *vport = NULL; |
| 14506 | int i; |
| 14507 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14508 | fc_hdr->fh_d_id[1] << 8 | |
| 14509 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14510 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14511 | if (did == Fabric_DID) |
| 14512 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14513 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14514 | !(phba->link_state == LPFC_HBA_READY)) |
| 14515 | return phba->pport; |
| 14516 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14517 | vports = lpfc_create_vport_work_array(phba); |
| 14518 | if (vports != NULL) |
| 14519 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14520 | if (phba->fcf.fcfi == fcfi && |
| 14521 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14522 | vports[i]->fc_myDID == did) { |
| 14523 | vport = vports[i]; |
| 14524 | break; |
| 14525 | } |
| 14526 | } |
| 14527 | lpfc_destroy_vport_work_array(phba, vports); |
| 14528 | return vport; |
| 14529 | } |
| 14530 | |
| 14531 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14532 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14533 | * @vport: The vport to work on. |
| 14534 | * |
| 14535 | * This function updates the receive sequence time stamp for this vport. The |
| 14536 | * receive sequence time stamp indicates the time that the last frame of the |
| 14537 | * the sequence that has been idle for the longest amount of time was received. |
| 14538 | * the driver uses this time stamp to indicate if any received sequences have |
| 14539 | * timed out. |
| 14540 | **/ |
| 14541 | void |
| 14542 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14543 | { |
| 14544 | struct lpfc_dmabuf *h_buf; |
| 14545 | struct hbq_dmabuf *dmabuf = NULL; |
| 14546 | |
| 14547 | /* get the oldest sequence on the rcv list */ |
| 14548 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14549 | struct lpfc_dmabuf, list); |
| 14550 | if (!h_buf) |
| 14551 | return; |
| 14552 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14553 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14554 | } |
| 14555 | |
| 14556 | /** |
| 14557 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14558 | * @vport: The vport that the received sequences were sent to. |
| 14559 | * |
| 14560 | * This function cleans up all outstanding received sequences. This is called |
| 14561 | * by the driver when a link event or user action invalidates all the received |
| 14562 | * sequences. |
| 14563 | **/ |
| 14564 | void |
| 14565 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14566 | { |
| 14567 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14568 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14569 | struct hbq_dmabuf *dmabuf = NULL; |
| 14570 | |
| 14571 | /* start with the oldest sequence on the rcv list */ |
| 14572 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14573 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14574 | list_del_init(&dmabuf->hbuf.list); |
| 14575 | list_for_each_entry_safe(d_buf, dnext, |
| 14576 | &dmabuf->dbuf.list, list) { |
| 14577 | list_del_init(&d_buf->list); |
| 14578 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14579 | } |
| 14580 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14581 | } |
| 14582 | } |
| 14583 | |
| 14584 | /** |
| 14585 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 14586 | * @vport: The vport that the received sequences were sent to. |
| 14587 | * |
| 14588 | * This function determines whether any received sequences have timed out by |
| 14589 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 14590 | * indicates that there is at least one timed out sequence this routine will |
| 14591 | * go through the received sequences one at a time from most inactive to most |
| 14592 | * active to determine which ones need to be cleaned up. Once it has determined |
| 14593 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 14594 | * without sending an abort. |
| 14595 | **/ |
| 14596 | void |
| 14597 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 14598 | { |
| 14599 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14600 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14601 | struct hbq_dmabuf *dmabuf = NULL; |
| 14602 | unsigned long timeout; |
| 14603 | int abort_count = 0; |
| 14604 | |
| 14605 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14606 | vport->rcv_buffer_time_stamp); |
| 14607 | if (list_empty(&vport->rcv_buffer_list) || |
| 14608 | time_before(jiffies, timeout)) |
| 14609 | return; |
| 14610 | /* start with the oldest sequence on the rcv list */ |
| 14611 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14612 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14613 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14614 | dmabuf->time_stamp); |
| 14615 | if (time_before(jiffies, timeout)) |
| 14616 | break; |
| 14617 | abort_count++; |
| 14618 | list_del_init(&dmabuf->hbuf.list); |
| 14619 | list_for_each_entry_safe(d_buf, dnext, |
| 14620 | &dmabuf->dbuf.list, list) { |
| 14621 | list_del_init(&d_buf->list); |
| 14622 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14623 | } |
| 14624 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14625 | } |
| 14626 | if (abort_count) |
| 14627 | lpfc_update_rcv_time_stamp(vport); |
| 14628 | } |
| 14629 | |
| 14630 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14631 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 14632 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 14633 | * |
| 14634 | * This function searches through the existing incomplete sequences that have |
| 14635 | * been sent to this @vport. If the frame matches one of the incomplete |
| 14636 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 14637 | * make up that sequence. If no sequence is found that matches this frame then |
| 14638 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 14639 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 14640 | * the frame was linked to. |
| 14641 | **/ |
| 14642 | static struct hbq_dmabuf * |
| 14643 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14644 | { |
| 14645 | struct fc_frame_header *new_hdr; |
| 14646 | struct fc_frame_header *temp_hdr; |
| 14647 | struct lpfc_dmabuf *d_buf; |
| 14648 | struct lpfc_dmabuf *h_buf; |
| 14649 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14650 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 14651 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14652 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14653 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14654 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14655 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 14656 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14657 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14658 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14659 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14660 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14661 | continue; |
| 14662 | /* found a pending sequence that matches this frame */ |
| 14663 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14664 | break; |
| 14665 | } |
| 14666 | if (!seq_dmabuf) { |
| 14667 | /* |
| 14668 | * This indicates first frame received for this sequence. |
| 14669 | * Queue the buffer on the vport's rcv_buffer_list. |
| 14670 | */ |
| 14671 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14672 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14673 | return dmabuf; |
| 14674 | } |
| 14675 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14676 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 14677 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14678 | list_del_init(&seq_dmabuf->hbuf.list); |
| 14679 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14680 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14681 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14682 | return dmabuf; |
| 14683 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14684 | /* move this sequence to the tail to indicate a young sequence */ |
| 14685 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14686 | seq_dmabuf->time_stamp = jiffies; |
| 14687 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14688 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 14689 | temp_hdr = dmabuf->hbuf.virt; |
| 14690 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 14691 | return seq_dmabuf; |
| 14692 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14693 | /* find the correct place in the sequence to insert this frame */ |
| 14694 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14695 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14696 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14697 | /* |
| 14698 | * If the frame's sequence count is greater than the frame on |
| 14699 | * the list then insert the frame right after this frame |
| 14700 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14701 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14702 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14703 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14704 | return seq_dmabuf; |
| 14705 | } |
| 14706 | } |
| 14707 | return NULL; |
| 14708 | } |
| 14709 | |
| 14710 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14711 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14712 | * @vport: pointer to a vitural port |
| 14713 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14714 | * |
| 14715 | * This function tries to abort from the partially assembed sequence, described |
| 14716 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14717 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14718 | * the frames from the partially assembled sequence. |
| 14719 | * |
| 14720 | * Return |
| 14721 | * true -- if there is matching partially assembled sequence present and all |
| 14722 | * the frames freed with the sequence; |
| 14723 | * false -- if there is no matching partially assembled sequence present so |
| 14724 | * nothing got aborted in the lower layer driver |
| 14725 | **/ |
| 14726 | static bool |
| 14727 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14728 | struct hbq_dmabuf *dmabuf) |
| 14729 | { |
| 14730 | struct fc_frame_header *new_hdr; |
| 14731 | struct fc_frame_header *temp_hdr; |
| 14732 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14733 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14734 | |
| 14735 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14736 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14737 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14738 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14739 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14740 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14741 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14742 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14743 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14744 | continue; |
| 14745 | /* found a pending sequence that matches this frame */ |
| 14746 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14747 | break; |
| 14748 | } |
| 14749 | |
| 14750 | /* Free up all the frames from the partially assembled sequence */ |
| 14751 | if (seq_dmabuf) { |
| 14752 | list_for_each_entry_safe(d_buf, n_buf, |
| 14753 | &seq_dmabuf->dbuf.list, list) { |
| 14754 | list_del_init(&d_buf->list); |
| 14755 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14756 | } |
| 14757 | return true; |
| 14758 | } |
| 14759 | return false; |
| 14760 | } |
| 14761 | |
| 14762 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14763 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 14764 | * @vport: pointer to a vitural port |
| 14765 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14766 | * |
| 14767 | * This function tries to abort from the assembed sequence from upper level |
| 14768 | * protocol, described by the information from basic abbort @dmabuf. It |
| 14769 | * checks to see whether such pending context exists at upper level protocol. |
| 14770 | * If so, it shall clean up the pending context. |
| 14771 | * |
| 14772 | * Return |
| 14773 | * true -- if there is matching pending context of the sequence cleaned |
| 14774 | * at ulp; |
| 14775 | * false -- if there is no matching pending context of the sequence present |
| 14776 | * at ulp. |
| 14777 | **/ |
| 14778 | static bool |
| 14779 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14780 | { |
| 14781 | struct lpfc_hba *phba = vport->phba; |
| 14782 | int handled; |
| 14783 | |
| 14784 | /* Accepting abort at ulp with SLI4 only */ |
| 14785 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 14786 | return false; |
| 14787 | |
| 14788 | /* Register all caring upper level protocols to attend abort */ |
| 14789 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 14790 | if (handled) |
| 14791 | return true; |
| 14792 | |
| 14793 | return false; |
| 14794 | } |
| 14795 | |
| 14796 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14797 | * 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] | 14798 | * @phba: Pointer to HBA context object. |
| 14799 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14800 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14801 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14802 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14803 | * event. It properly releases the memory allocated to the sequence abort |
| 14804 | * accept iocb. |
| 14805 | **/ |
| 14806 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14807 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14808 | struct lpfc_iocbq *cmd_iocbq, |
| 14809 | struct lpfc_iocbq *rsp_iocbq) |
| 14810 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14811 | struct lpfc_nodelist *ndlp; |
| 14812 | |
| 14813 | if (cmd_iocbq) { |
| 14814 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 14815 | lpfc_nlp_put(ndlp); |
| 14816 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14817 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14818 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14819 | |
| 14820 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14821 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14822 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14823 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14824 | rsp_iocbq->iocb.ulpStatus, |
| 14825 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14826 | } |
| 14827 | |
| 14828 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14829 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14830 | * @phba: Pointer to HBA context object. |
| 14831 | * @xri: xri id in transaction. |
| 14832 | * |
| 14833 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14834 | * used by the driver. |
| 14835 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14836 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14837 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14838 | uint16_t xri) |
| 14839 | { |
| 14840 | int i; |
| 14841 | |
| 14842 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14843 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14844 | return i; |
| 14845 | } |
| 14846 | return NO_XRI; |
| 14847 | } |
| 14848 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14849 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14850 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14851 | * @phba: Pointer to HBA context object. |
| 14852 | * @fc_hdr: pointer to a FC frame header. |
| 14853 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14854 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14855 | * event after aborting the sequence handling. |
| 14856 | **/ |
| 14857 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14858 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 14859 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14860 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14861 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14862 | struct lpfc_iocbq *ctiocb = NULL; |
| 14863 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14864 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14865 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14866 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14867 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14868 | |
| 14869 | if (!lpfc_is_link_up(phba)) |
| 14870 | return; |
| 14871 | |
| 14872 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14873 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14874 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14875 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14876 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14877 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14878 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 14879 | if (!ndlp) { |
| 14880 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14881 | "1268 Failed to allocate ndlp for " |
| 14882 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 14883 | return; |
| 14884 | } |
| 14885 | lpfc_nlp_init(vport, ndlp, sid); |
| 14886 | /* Put ndlp onto pport node list */ |
| 14887 | lpfc_enqueue_node(vport, ndlp); |
| 14888 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 14889 | /* re-setup ndlp without removing from node list */ |
| 14890 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 14891 | if (!ndlp) { |
| 14892 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14893 | "3275 Failed to active ndlp found " |
| 14894 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 14895 | return; |
| 14896 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14897 | } |
| 14898 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14899 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14900 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14901 | if (!ctiocb) |
| 14902 | return; |
| 14903 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14904 | /* Extract the F_CTL field from FC_HDR */ |
| 14905 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14906 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14907 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14908 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14909 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14910 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14911 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14912 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14913 | |
| 14914 | /* Fill in the rest of iocb fields */ |
| 14915 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14916 | icmd->ulpBdeCount = 0; |
| 14917 | icmd->ulpLe = 1; |
| 14918 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14919 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14920 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14921 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14922 | ctiocb->iocb_cmpl = NULL; |
| 14923 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14924 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14925 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14926 | ctiocb->sli4_xritag = NO_XRI; |
| 14927 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14928 | if (fctl & FC_FC_EX_CTX) |
| 14929 | /* Exchange responder sent the abort so we |
| 14930 | * own the oxid. |
| 14931 | */ |
| 14932 | xri = oxid; |
| 14933 | else |
| 14934 | xri = rxid; |
| 14935 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14936 | if (lxri != NO_XRI) |
| 14937 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14938 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14939 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 14940 | * the oxid maps to the FCP XRI range, the port no longer has |
| 14941 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 14942 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14943 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14944 | if ((fctl & FC_FC_EX_CTX) && |
| 14945 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 14946 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14947 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14948 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14949 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14950 | } |
| 14951 | |
| 14952 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 14953 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 14954 | * the IOCB for a BA_RJT. |
| 14955 | */ |
| 14956 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14957 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14958 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14959 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14960 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14961 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14962 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14963 | if (fctl & FC_FC_EX_CTX) { |
| 14964 | /* ABTS sent by responder to CT exchange, construction |
| 14965 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14966 | * field and RX_ID from ABTS for RX_ID field. |
| 14967 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14968 | 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] | 14969 | } else { |
| 14970 | /* ABTS sent by initiator to CT exchange, construction |
| 14971 | * 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] | 14972 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14973 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14974 | 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] | 14975 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14976 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14977 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14978 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14979 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14980 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 14981 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14982 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14983 | |
| 14984 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14985 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14986 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 14987 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14988 | "xri x%x, Data x%x\n", |
| 14989 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14990 | phba->link_state); |
| 14991 | lpfc_nlp_put(ndlp); |
| 14992 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14993 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14994 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14995 | } |
| 14996 | |
| 14997 | /** |
| 14998 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14999 | * @vport: Pointer to the vport on which this sequence was received |
| 15000 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15001 | * |
| 15002 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 15003 | * receive sequence is only partially assembed by the driver, it shall abort |
| 15004 | * the partially assembled frames for the sequence. Otherwise, if the |
| 15005 | * unsolicited receive sequence has been completely assembled and passed to |
| 15006 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 15007 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 15008 | * accept to accept the abort. |
| 15009 | **/ |
| 15010 | void |
| 15011 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 15012 | struct hbq_dmabuf *dmabuf) |
| 15013 | { |
| 15014 | struct lpfc_hba *phba = vport->phba; |
| 15015 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15016 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15017 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15018 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15019 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 15020 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15021 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15022 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15023 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15024 | /* ABTS by responder to exchange, no cleanup needed */ |
| 15025 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15026 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15027 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 15028 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 15029 | if (aborted == false) |
| 15030 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 15031 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 15032 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15033 | |
| 15034 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 15035 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15036 | } |
| 15037 | |
| 15038 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15039 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 15040 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15041 | * |
| 15042 | * This function checks the sequence, starting with the frame described by |
| 15043 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 15044 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 15045 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 15046 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 15047 | * set. 3) That there are no holes in the sequence count. The function will |
| 15048 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 15049 | **/ |
| 15050 | static int |
| 15051 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 15052 | { |
| 15053 | struct fc_frame_header *hdr; |
| 15054 | struct lpfc_dmabuf *d_buf; |
| 15055 | struct hbq_dmabuf *seq_dmabuf; |
| 15056 | uint32_t fctl; |
| 15057 | int seq_count = 0; |
| 15058 | |
| 15059 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15060 | /* make sure first fame of sequence has a sequence count of zero */ |
| 15061 | if (hdr->fh_seq_cnt != seq_count) |
| 15062 | return 0; |
| 15063 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15064 | hdr->fh_f_ctl[1] << 8 | |
| 15065 | hdr->fh_f_ctl[2]); |
| 15066 | /* If last frame of sequence we can return success. */ |
| 15067 | if (fctl & FC_FC_END_SEQ) |
| 15068 | return 1; |
| 15069 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 15070 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15071 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15072 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15073 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15074 | return 0; |
| 15075 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 15076 | hdr->fh_f_ctl[1] << 8 | |
| 15077 | hdr->fh_f_ctl[2]); |
| 15078 | /* If last frame of sequence we can return success. */ |
| 15079 | if (fctl & FC_FC_END_SEQ) |
| 15080 | return 1; |
| 15081 | } |
| 15082 | return 0; |
| 15083 | } |
| 15084 | |
| 15085 | /** |
| 15086 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 15087 | * @vport: Pointer to the vport on which this sequence was received |
| 15088 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 15089 | * |
| 15090 | * This function takes a sequence, described by a list of frames, and creates |
| 15091 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 15092 | * used to issue to the generic unsolicited sequence handler. This routine |
| 15093 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 15094 | * to allocate an iocbq then it throw out the received frames that were not |
| 15095 | * able to be described and return a pointer to the first iocbq. If unable to |
| 15096 | * allocate any iocbqs (including the first) this function will return NULL. |
| 15097 | **/ |
| 15098 | static struct lpfc_iocbq * |
| 15099 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 15100 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15101 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15102 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 15103 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 15104 | struct fc_frame_header *fc_hdr; |
| 15105 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15106 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 15107 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15108 | |
| 15109 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15110 | /* remove from receive buffer list */ |
| 15111 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 15112 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15113 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15114 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15115 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15116 | /* Get an iocbq struct to fill in. */ |
| 15117 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15118 | if (first_iocbq) { |
| 15119 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15120 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15121 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15122 | |
| 15123 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 15124 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 15125 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 15126 | first_iocbq->iocb.un.rcvels.parmRo = |
| 15127 | sli4_did_from_fc_hdr(fc_hdr); |
| 15128 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 15129 | } else |
| 15130 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15131 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 15132 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 15133 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 15134 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 15135 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 15136 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15137 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15138 | tot_len = bf_get(lpfc_rcqe_length, |
| 15139 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15140 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15141 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 15142 | first_iocbq->context3 = NULL; |
| 15143 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15144 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 15145 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15146 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15147 | else |
| 15148 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 15149 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15150 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15151 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15152 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15153 | } |
| 15154 | iocbq = first_iocbq; |
| 15155 | /* |
| 15156 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 15157 | * of buffers for this sequence and save two buffers in each IOCBq |
| 15158 | */ |
| 15159 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 15160 | if (!iocbq) { |
| 15161 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15162 | continue; |
| 15163 | } |
| 15164 | if (!iocbq->context3) { |
| 15165 | iocbq->context3 = d_buf; |
| 15166 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15167 | /* We need to get the size out of the right CQE */ |
| 15168 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15169 | len = bf_get(lpfc_rcqe_length, |
| 15170 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15171 | pbde = (struct ulp_bde64 *) |
| 15172 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 15173 | if (len > LPFC_DATA_BUF_SIZE) |
| 15174 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 15175 | else |
| 15176 | pbde->tus.f.bdeSize = len; |
| 15177 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15178 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 15179 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15180 | } else { |
| 15181 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 15182 | if (!iocbq) { |
| 15183 | if (first_iocbq) { |
| 15184 | first_iocbq->iocb.ulpStatus = |
| 15185 | IOSTAT_FCP_RSP_ERROR; |
| 15186 | first_iocbq->iocb.un.ulpWord[4] = |
| 15187 | IOERR_NO_RESOURCES; |
| 15188 | } |
| 15189 | lpfc_in_buf_free(vport->phba, d_buf); |
| 15190 | continue; |
| 15191 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15192 | /* We need to get the size out of the right CQE */ |
| 15193 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 15194 | len = bf_get(lpfc_rcqe_length, |
| 15195 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 15196 | iocbq->context2 = d_buf; |
| 15197 | iocbq->context3 = NULL; |
| 15198 | iocbq->iocb.ulpBdeCount = 1; |
| 15199 | if (len > LPFC_DATA_BUF_SIZE) |
| 15200 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 15201 | LPFC_DATA_BUF_SIZE; |
| 15202 | else |
| 15203 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 15204 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15205 | tot_len += len; |
| 15206 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 15207 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15208 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 15209 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 15210 | } |
| 15211 | } |
| 15212 | return first_iocbq; |
| 15213 | } |
| 15214 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15215 | static void |
| 15216 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 15217 | struct hbq_dmabuf *seq_dmabuf) |
| 15218 | { |
| 15219 | struct fc_frame_header *fc_hdr; |
| 15220 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 15221 | struct lpfc_hba *phba = vport->phba; |
| 15222 | |
| 15223 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15224 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 15225 | if (!iocbq) { |
| 15226 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15227 | "2707 Ring %d handler: Failed to allocate " |
| 15228 | "iocb Rctl x%x Type x%x received\n", |
| 15229 | LPFC_ELS_RING, |
| 15230 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15231 | return; |
| 15232 | } |
| 15233 | if (!lpfc_complete_unsol_iocb(phba, |
| 15234 | &phba->sli.ring[LPFC_ELS_RING], |
| 15235 | iocbq, fc_hdr->fh_r_ctl, |
| 15236 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15237 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15238 | "2540 Ring %d handler: unexpected Rctl " |
| 15239 | "x%x Type x%x received\n", |
| 15240 | LPFC_ELS_RING, |
| 15241 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15242 | |
| 15243 | /* Free iocb created in lpfc_prep_seq */ |
| 15244 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 15245 | &iocbq->list, list) { |
| 15246 | list_del_init(&curr_iocb->list); |
| 15247 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 15248 | } |
| 15249 | lpfc_sli_release_iocbq(phba, iocbq); |
| 15250 | } |
| 15251 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15252 | /** |
| 15253 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 15254 | * @phba: Pointer to HBA context object. |
| 15255 | * |
| 15256 | * This function is called with no lock held. This function processes all |
| 15257 | * the received buffers and gives it to upper layers when a received buffer |
| 15258 | * indicates that it is the final frame in the sequence. The interrupt |
| 15259 | * service routine processes received buffers at interrupt contexts and adds |
| 15260 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 15261 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 15262 | * appropriate receive function when the final frame in a sequence is received. |
| 15263 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15264 | void |
| 15265 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 15266 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15267 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15268 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15269 | struct fc_frame_header *fc_hdr; |
| 15270 | struct lpfc_vport *vport; |
| 15271 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15272 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15273 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15274 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15275 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15276 | /* check to see if this a valid type of frame */ |
| 15277 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 15278 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15279 | return; |
| 15280 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15281 | if ((bf_get(lpfc_cqe_code, |
| 15282 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 15283 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 15284 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15285 | else |
| 15286 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 15287 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15288 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15289 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15290 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15291 | /* throw out the frame */ |
| 15292 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15293 | return; |
| 15294 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15295 | |
| 15296 | /* d_id this frame is directed to */ |
| 15297 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 15298 | |
| 15299 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 15300 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 15301 | (did != Fabric_DID)) { |
| 15302 | /* |
| 15303 | * Throw out the frame if we are not pt2pt. |
| 15304 | * The pt2pt protocol allows for discovery frames |
| 15305 | * to be received without a registered VPI. |
| 15306 | */ |
| 15307 | if (!(vport->fc_flag & FC_PT2PT) || |
| 15308 | (phba->link_state == LPFC_HBA_READY)) { |
| 15309 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15310 | return; |
| 15311 | } |
| 15312 | } |
| 15313 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15314 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 15315 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 15316 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 15317 | return; |
| 15318 | } |
| 15319 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15320 | /* Link this frame */ |
| 15321 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 15322 | if (!seq_dmabuf) { |
| 15323 | /* unable to add frame to vport - throw it out */ |
| 15324 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15325 | return; |
| 15326 | } |
| 15327 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15328 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15329 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15330 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15331 | /* Send the complete sequence to the upper layer protocol */ |
| 15332 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15333 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15334 | |
| 15335 | /** |
| 15336 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 15337 | * @phba: pointer to lpfc hba data structure. |
| 15338 | * |
| 15339 | * This routine is invoked to post rpi header templates to the |
| 15340 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15341 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15342 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15343 | * |
| 15344 | * This routine does not require any locks. It's usage is expected |
| 15345 | * to be driver load or reset recovery when the driver is |
| 15346 | * sequential. |
| 15347 | * |
| 15348 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15349 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15350 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15351 | * When this error occurs, the driver is not guaranteed |
| 15352 | * to have any rpi regions posted to the device and |
| 15353 | * must either attempt to repost the regions or take a |
| 15354 | * fatal error. |
| 15355 | **/ |
| 15356 | int |
| 15357 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 15358 | { |
| 15359 | struct lpfc_rpi_hdr *rpi_page; |
| 15360 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15361 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15362 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15363 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15364 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15365 | goto exit; |
| 15366 | if (phba->sli4_hba.extents_in_use) |
| 15367 | return -EIO; |
| 15368 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15369 | 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] | 15370 | /* |
| 15371 | * Assign the rpi headers a physical rpi only if the driver |
| 15372 | * has not initialized those resources. A port reset only |
| 15373 | * needs the headers posted. |
| 15374 | */ |
| 15375 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 15376 | LPFC_RPI_RSRC_RDY) |
| 15377 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 15378 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15379 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 15380 | if (rc != MBX_SUCCESS) { |
| 15381 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15382 | "2008 Error %d posting all rpi " |
| 15383 | "headers\n", rc); |
| 15384 | rc = -EIO; |
| 15385 | break; |
| 15386 | } |
| 15387 | } |
| 15388 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15389 | exit: |
| 15390 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 15391 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15392 | return rc; |
| 15393 | } |
| 15394 | |
| 15395 | /** |
| 15396 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 15397 | * @phba: pointer to lpfc hba data structure. |
| 15398 | * @rpi_page: pointer to the rpi memory region. |
| 15399 | * |
| 15400 | * This routine is invoked to post a single rpi header to the |
| 15401 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 15402 | * maps up to 64 rpi context regions. |
| 15403 | * |
| 15404 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15405 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15406 | * -ENOMEM - No available memory |
| 15407 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15408 | **/ |
| 15409 | int |
| 15410 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 15411 | { |
| 15412 | LPFC_MBOXQ_t *mboxq; |
| 15413 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 15414 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15415 | uint32_t shdr_status, shdr_add_status; |
| 15416 | union lpfc_sli4_cfg_shdr *shdr; |
| 15417 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15418 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15419 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15420 | return rc; |
| 15421 | if (phba->sli4_hba.extents_in_use) |
| 15422 | return -EIO; |
| 15423 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15424 | /* The port is notified of the header region via a mailbox command. */ |
| 15425 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15426 | if (!mboxq) { |
| 15427 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15428 | "2001 Unable to allocate memory for issuing " |
| 15429 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 15430 | return -ENOMEM; |
| 15431 | } |
| 15432 | |
| 15433 | /* Post all rpi memory regions to the port. */ |
| 15434 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15435 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15436 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 15437 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15438 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 15439 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15440 | |
| 15441 | |
| 15442 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15443 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 15444 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15445 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 15446 | hdr_tmpl, rpi_page->page_count); |
| 15447 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15448 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 15449 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 15450 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15451 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 15452 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15453 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15454 | if (rc != MBX_TIMEOUT) |
| 15455 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15456 | if (shdr_status || shdr_add_status || rc) { |
| 15457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15458 | "2514 POST_RPI_HDR mailbox failed with " |
| 15459 | "status x%x add_status x%x, mbx status x%x\n", |
| 15460 | shdr_status, shdr_add_status, rc); |
| 15461 | rc = -ENXIO; |
| 15462 | } |
| 15463 | return rc; |
| 15464 | } |
| 15465 | |
| 15466 | /** |
| 15467 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 15468 | * @phba: pointer to lpfc hba data structure. |
| 15469 | * |
| 15470 | * This routine is invoked to post rpi header templates to the |
| 15471 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15472 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15473 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15474 | * |
| 15475 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15476 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15477 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15478 | **/ |
| 15479 | int |
| 15480 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 15481 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15482 | unsigned long rpi; |
| 15483 | uint16_t max_rpi, rpi_limit; |
| 15484 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15485 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15486 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15487 | |
| 15488 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15489 | rpi_limit = phba->sli4_hba.next_rpi; |
| 15490 | |
| 15491 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15492 | * Fetch the next logical rpi. Because this index is logical, |
| 15493 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15494 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15495 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15496 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15497 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15498 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15499 | else { |
| 15500 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15501 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15502 | phba->sli4_hba.rpi_count++; |
| 15503 | } |
| 15504 | |
| 15505 | /* |
| 15506 | * 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] | 15507 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15508 | */ |
| 15509 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15510 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15511 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15512 | return rpi; |
| 15513 | } |
| 15514 | |
| 15515 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15516 | * RPI header postings are not required for SLI4 ports capable of |
| 15517 | * extents. |
| 15518 | */ |
| 15519 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15520 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15521 | return rpi; |
| 15522 | } |
| 15523 | |
| 15524 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15525 | * If the driver is running low on rpi resources, allocate another |
| 15526 | * page now. Note that the next_rpi value is used because |
| 15527 | * it represents how many are actually in use whereas max_rpi notes |
| 15528 | * how many are supported max by the device. |
| 15529 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15530 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15531 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15532 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15533 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15534 | if (!rpi_hdr) { |
| 15535 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15536 | "2002 Error Could not grow rpi " |
| 15537 | "count\n"); |
| 15538 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15539 | lrpi = rpi_hdr->start_rpi; |
| 15540 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15541 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15542 | } |
| 15543 | } |
| 15544 | |
| 15545 | return rpi; |
| 15546 | } |
| 15547 | |
| 15548 | /** |
| 15549 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15550 | * @phba: pointer to lpfc hba data structure. |
| 15551 | * |
| 15552 | * This routine is invoked to release an rpi to the pool of |
| 15553 | * available rpis maintained by the driver. |
| 15554 | **/ |
| 15555 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15556 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15557 | { |
| 15558 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 15559 | phba->sli4_hba.rpi_count--; |
| 15560 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 15561 | } |
| 15562 | } |
| 15563 | |
| 15564 | /** |
| 15565 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15566 | * @phba: pointer to lpfc hba data structure. |
| 15567 | * |
| 15568 | * This routine is invoked to release an rpi to the pool of |
| 15569 | * available rpis maintained by the driver. |
| 15570 | **/ |
| 15571 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15572 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15573 | { |
| 15574 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15575 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15576 | spin_unlock_irq(&phba->hbalock); |
| 15577 | } |
| 15578 | |
| 15579 | /** |
| 15580 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 15581 | * @phba: pointer to lpfc hba data structure. |
| 15582 | * |
| 15583 | * This routine is invoked to remove the memory region that |
| 15584 | * provided rpi via a bitmask. |
| 15585 | **/ |
| 15586 | void |
| 15587 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 15588 | { |
| 15589 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15590 | kfree(phba->sli4_hba.rpi_ids); |
| 15591 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15592 | } |
| 15593 | |
| 15594 | /** |
| 15595 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 15596 | * @phba: pointer to lpfc hba data structure. |
| 15597 | * |
| 15598 | * This routine is invoked to remove the memory region that |
| 15599 | * provided rpi via a bitmask. |
| 15600 | **/ |
| 15601 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15602 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 15603 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15604 | { |
| 15605 | LPFC_MBOXQ_t *mboxq; |
| 15606 | struct lpfc_hba *phba = ndlp->phba; |
| 15607 | int rc; |
| 15608 | |
| 15609 | /* The port is notified of the header region via a mailbox command. */ |
| 15610 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15611 | if (!mboxq) |
| 15612 | return -ENOMEM; |
| 15613 | |
| 15614 | /* Post all rpi memory regions to the port. */ |
| 15615 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15616 | if (cmpl) { |
| 15617 | mboxq->mbox_cmpl = cmpl; |
| 15618 | mboxq->context1 = arg; |
| 15619 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 15620 | } else |
| 15621 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15622 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15624 | if (rc == MBX_NOT_FINISHED) { |
| 15625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15626 | "2010 Resume RPI Mailbox failed " |
| 15627 | "status %d, mbxStatus x%x\n", rc, |
| 15628 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 15629 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15630 | return -EIO; |
| 15631 | } |
| 15632 | return 0; |
| 15633 | } |
| 15634 | |
| 15635 | /** |
| 15636 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15637 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15638 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15639 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15640 | * |
| 15641 | * Returns: |
| 15642 | * 0 success |
| 15643 | * -Evalue otherwise |
| 15644 | **/ |
| 15645 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15646 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15647 | { |
| 15648 | LPFC_MBOXQ_t *mboxq; |
| 15649 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15650 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15651 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15652 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15653 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15654 | if (!mboxq) |
| 15655 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15656 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15657 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15658 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15659 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15660 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15661 | "2022 INIT VPI Mailbox failed " |
| 15662 | "status %d, mbxStatus x%x\n", rc, |
| 15663 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15664 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15665 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15666 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15667 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15668 | |
| 15669 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15670 | } |
| 15671 | |
| 15672 | /** |
| 15673 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 15674 | * @phba: pointer to lpfc hba data structure. |
| 15675 | * @mboxq: Pointer to mailbox object. |
| 15676 | * |
| 15677 | * This routine is invoked to manually add a single FCF record. The caller |
| 15678 | * must pass a completely initialized FCF_Record. This routine takes |
| 15679 | * care of the nonembedded mailbox operations. |
| 15680 | **/ |
| 15681 | static void |
| 15682 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 15683 | { |
| 15684 | void *virt_addr; |
| 15685 | union lpfc_sli4_cfg_shdr *shdr; |
| 15686 | uint32_t shdr_status, shdr_add_status; |
| 15687 | |
| 15688 | virt_addr = mboxq->sge_array->addr[0]; |
| 15689 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15690 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 15691 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15692 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15693 | |
| 15694 | if ((shdr_status || shdr_add_status) && |
| 15695 | (shdr_status != STATUS_FCF_IN_USE)) |
| 15696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15697 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 15698 | "status x%x add_status x%x\n", |
| 15699 | shdr_status, shdr_add_status); |
| 15700 | |
| 15701 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15702 | } |
| 15703 | |
| 15704 | /** |
| 15705 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 15706 | * @phba: pointer to lpfc hba data structure. |
| 15707 | * @fcf_record: pointer to the initialized fcf record to add. |
| 15708 | * |
| 15709 | * This routine is invoked to manually add a single FCF record. The caller |
| 15710 | * must pass a completely initialized FCF_Record. This routine takes |
| 15711 | * care of the nonembedded mailbox operations. |
| 15712 | **/ |
| 15713 | int |
| 15714 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 15715 | { |
| 15716 | int rc = 0; |
| 15717 | LPFC_MBOXQ_t *mboxq; |
| 15718 | uint8_t *bytep; |
| 15719 | void *virt_addr; |
| 15720 | dma_addr_t phys_addr; |
| 15721 | struct lpfc_mbx_sge sge; |
| 15722 | uint32_t alloc_len, req_len; |
| 15723 | uint32_t fcfindex; |
| 15724 | |
| 15725 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15726 | if (!mboxq) { |
| 15727 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15728 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 15729 | return -ENOMEM; |
| 15730 | } |
| 15731 | |
| 15732 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 15733 | sizeof(uint32_t); |
| 15734 | |
| 15735 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 15736 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15737 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 15738 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 15739 | if (alloc_len < req_len) { |
| 15740 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15741 | "2523 Allocated DMA memory size (x%x) is " |
| 15742 | "less than the requested DMA memory " |
| 15743 | "size (x%x)\n", alloc_len, req_len); |
| 15744 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15745 | return -ENOMEM; |
| 15746 | } |
| 15747 | |
| 15748 | /* |
| 15749 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 15750 | * routine only uses a single SGE. |
| 15751 | */ |
| 15752 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 15753 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15754 | virt_addr = mboxq->sge_array->addr[0]; |
| 15755 | /* |
| 15756 | * Configure the FCF record for FCFI 0. This is the driver's |
| 15757 | * hardcoded default and gets used in nonFIP mode. |
| 15758 | */ |
| 15759 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 15760 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 15761 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 15762 | |
| 15763 | /* |
| 15764 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 15765 | * the FCoE header plus word10. The data copy needs to be endian |
| 15766 | * correct. |
| 15767 | */ |
| 15768 | bytep += sizeof(uint32_t); |
| 15769 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15770 | mboxq->vport = phba->pport; |
| 15771 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15772 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15773 | if (rc == MBX_NOT_FINISHED) { |
| 15774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15775 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15776 | "status 0x%x\n", rc); |
| 15777 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15778 | rc = -EIO; |
| 15779 | } else |
| 15780 | rc = 0; |
| 15781 | |
| 15782 | return rc; |
| 15783 | } |
| 15784 | |
| 15785 | /** |
| 15786 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15787 | * @phba: pointer to lpfc hba data structure. |
| 15788 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15789 | * @fcf_index: FCF table entry index. |
| 15790 | * |
| 15791 | * This routine is invoked to build the driver's default FCF record. The |
| 15792 | * values used are hardcoded. This routine handles memory initialization. |
| 15793 | * |
| 15794 | **/ |
| 15795 | void |
| 15796 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15797 | struct fcf_record *fcf_record, |
| 15798 | uint16_t fcf_index) |
| 15799 | { |
| 15800 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15801 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15802 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15803 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15804 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15805 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15806 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15807 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15808 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15809 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15810 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15811 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15812 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15813 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15814 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15815 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15816 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15817 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15818 | /* Set the VLAN bit map */ |
| 15819 | if (phba->valid_vlan) { |
| 15820 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15821 | = 1 << (phba->vlan_id % 8); |
| 15822 | } |
| 15823 | } |
| 15824 | |
| 15825 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15826 | * 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] | 15827 | * @phba: pointer to lpfc hba data structure. |
| 15828 | * @fcf_index: FCF table entry offset. |
| 15829 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15830 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15831 | * record and processing it one at a time starting from the @fcf_index |
| 15832 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15833 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15834 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15835 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15836 | **/ |
| 15837 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15838 | 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] | 15839 | { |
| 15840 | int rc = 0, error; |
| 15841 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15842 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15843 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15844 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15845 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15846 | if (!mboxq) { |
| 15847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15848 | "2000 Failed to allocate mbox for " |
| 15849 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15850 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15851 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15852 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15853 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15854 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15855 | if (rc) { |
| 15856 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15857 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15858 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15859 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15860 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15861 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15862 | |
| 15863 | spin_lock_irq(&phba->hbalock); |
| 15864 | phba->hba_flag |= FCF_TS_INPROG; |
| 15865 | spin_unlock_irq(&phba->hbalock); |
| 15866 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15867 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15868 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15869 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15870 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15871 | /* Reset eligible FCF count for new scan */ |
| 15872 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15873 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15874 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15875 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15876 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15877 | if (error) { |
| 15878 | if (mboxq) |
| 15879 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15880 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15881 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15882 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15883 | spin_unlock_irq(&phba->hbalock); |
| 15884 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15885 | return error; |
| 15886 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15887 | |
| 15888 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15889 | * 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] | 15890 | * @phba: pointer to lpfc hba data structure. |
| 15891 | * @fcf_index: FCF table entry offset. |
| 15892 | * |
| 15893 | * 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] | 15894 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15895 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15896 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15897 | * otherwise. |
| 15898 | **/ |
| 15899 | int |
| 15900 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15901 | { |
| 15902 | int rc = 0, error; |
| 15903 | LPFC_MBOXQ_t *mboxq; |
| 15904 | |
| 15905 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15906 | if (!mboxq) { |
| 15907 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15908 | "2763 Failed to allocate mbox for " |
| 15909 | "READ_FCF cmd\n"); |
| 15910 | error = -ENOMEM; |
| 15911 | goto fail_fcf_read; |
| 15912 | } |
| 15913 | /* Construct the read FCF record mailbox command */ |
| 15914 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15915 | if (rc) { |
| 15916 | error = -EINVAL; |
| 15917 | goto fail_fcf_read; |
| 15918 | } |
| 15919 | /* Issue the mailbox command asynchronously */ |
| 15920 | mboxq->vport = phba->pport; |
| 15921 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15922 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15923 | if (rc == MBX_NOT_FINISHED) |
| 15924 | error = -EIO; |
| 15925 | else |
| 15926 | error = 0; |
| 15927 | |
| 15928 | fail_fcf_read: |
| 15929 | if (error && mboxq) |
| 15930 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15931 | return error; |
| 15932 | } |
| 15933 | |
| 15934 | /** |
| 15935 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15936 | * @phba: pointer to lpfc hba data structure. |
| 15937 | * @fcf_index: FCF table entry offset. |
| 15938 | * |
| 15939 | * 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] | 15940 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15941 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15942 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15943 | * otherwise. |
| 15944 | **/ |
| 15945 | int |
| 15946 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15947 | { |
| 15948 | int rc = 0, error; |
| 15949 | LPFC_MBOXQ_t *mboxq; |
| 15950 | |
| 15951 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15952 | if (!mboxq) { |
| 15953 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15954 | "2758 Failed to allocate mbox for " |
| 15955 | "READ_FCF cmd\n"); |
| 15956 | error = -ENOMEM; |
| 15957 | goto fail_fcf_read; |
| 15958 | } |
| 15959 | /* Construct the read FCF record mailbox command */ |
| 15960 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15961 | if (rc) { |
| 15962 | error = -EINVAL; |
| 15963 | goto fail_fcf_read; |
| 15964 | } |
| 15965 | /* Issue the mailbox command asynchronously */ |
| 15966 | mboxq->vport = phba->pport; |
| 15967 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15968 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15969 | if (rc == MBX_NOT_FINISHED) |
| 15970 | error = -EIO; |
| 15971 | else |
| 15972 | error = 0; |
| 15973 | |
| 15974 | fail_fcf_read: |
| 15975 | if (error && mboxq) |
| 15976 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15977 | return error; |
| 15978 | } |
| 15979 | |
| 15980 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15981 | * lpfc_check_next_fcf_pri |
| 15982 | * phba pointer to the lpfc_hba struct for this port. |
| 15983 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15984 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15985 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15986 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15987 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15988 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15989 | * fcf_indexes. |
| 15990 | * returns: |
| 15991 | * 1=success 0=failure |
| 15992 | **/ |
| 15993 | int |
| 15994 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15995 | { |
| 15996 | uint16_t next_fcf_pri; |
| 15997 | uint16_t last_index; |
| 15998 | struct lpfc_fcf_pri *fcf_pri; |
| 15999 | int rc; |
| 16000 | int ret = 0; |
| 16001 | |
| 16002 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 16003 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16004 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 16005 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16006 | |
| 16007 | /* Verify the priority list has 2 or more entries */ |
| 16008 | spin_lock_irq(&phba->hbalock); |
| 16009 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 16010 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 16011 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16012 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 16013 | "3061 Last IDX %d\n", last_index); |
| 16014 | return 0; /* Empty rr list */ |
| 16015 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 16016 | spin_unlock_irq(&phba->hbalock); |
| 16017 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16018 | next_fcf_pri = 0; |
| 16019 | /* |
| 16020 | * Clear the rr_bmask and set all of the bits that are at this |
| 16021 | * priority. |
| 16022 | */ |
| 16023 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 16024 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 16025 | spin_lock_irq(&phba->hbalock); |
| 16026 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16027 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 16028 | continue; |
| 16029 | /* |
| 16030 | * the 1st priority that has not FLOGI failed |
| 16031 | * will be the highest. |
| 16032 | */ |
| 16033 | if (!next_fcf_pri) |
| 16034 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16035 | spin_unlock_irq(&phba->hbalock); |
| 16036 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16037 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16038 | fcf_pri->fcf_rec.fcf_index); |
| 16039 | if (rc) |
| 16040 | return 0; |
| 16041 | } |
| 16042 | spin_lock_irq(&phba->hbalock); |
| 16043 | } |
| 16044 | /* |
| 16045 | * if next_fcf_pri was not set above and the list is not empty then |
| 16046 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 16047 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16048 | */ |
| 16049 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 16050 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 16051 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 16052 | /* |
| 16053 | * the 1st priority that has not FLOGI failed |
| 16054 | * will be the highest. |
| 16055 | */ |
| 16056 | if (!next_fcf_pri) |
| 16057 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 16058 | spin_unlock_irq(&phba->hbalock); |
| 16059 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 16060 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 16061 | fcf_pri->fcf_rec.fcf_index); |
| 16062 | if (rc) |
| 16063 | return 0; |
| 16064 | } |
| 16065 | spin_lock_irq(&phba->hbalock); |
| 16066 | } |
| 16067 | } else |
| 16068 | ret = 1; |
| 16069 | spin_unlock_irq(&phba->hbalock); |
| 16070 | |
| 16071 | return ret; |
| 16072 | } |
| 16073 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16074 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 16075 | * @phba: pointer to lpfc hba data structure. |
| 16076 | * |
| 16077 | * This routine is to get the next eligible FCF record index in a round |
| 16078 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16079 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16080 | * shall be returned, otherwise, the next eligible FCF record's index |
| 16081 | * shall be returned. |
| 16082 | **/ |
| 16083 | uint16_t |
| 16084 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 16085 | { |
| 16086 | uint16_t next_fcf_index; |
| 16087 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16088 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16089 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16090 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 16091 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16092 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16093 | /* Determine the next fcf index to check */ |
| 16094 | 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] | 16095 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16096 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16097 | next_fcf_index); |
| 16098 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16099 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16100 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16101 | /* |
| 16102 | * If we have wrapped then we need to clear the bits that |
| 16103 | * have been tested so that we can detect when we should |
| 16104 | * change the priority level. |
| 16105 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16106 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 16107 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16108 | } |
| 16109 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16110 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16111 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16112 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 16113 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 16114 | /* |
| 16115 | * If next fcf index is not found check if there are lower |
| 16116 | * Priority level fcf's in the fcf_priority list. |
| 16117 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 16118 | * at that level and continue the selection process. |
| 16119 | */ |
| 16120 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 16121 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16122 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16123 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16124 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 16125 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 16126 | else { |
| 16127 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 16128 | "3063 Only FCF available idx %d, flag %x\n", |
| 16129 | next_fcf_index, |
| 16130 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 16131 | return next_fcf_index; |
| 16132 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16133 | } |
| 16134 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16135 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 16136 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 16137 | LPFC_FCF_FLOGI_FAILED) |
| 16138 | goto next_priority; |
| 16139 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16140 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16141 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 16142 | next_fcf_index); |
| 16143 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16144 | return next_fcf_index; |
| 16145 | } |
| 16146 | |
| 16147 | /** |
| 16148 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 16149 | * @phba: pointer to lpfc hba data structure. |
| 16150 | * |
| 16151 | * 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] | 16152 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16153 | * does not go beyond the range of the driver allocated bmask dimension |
| 16154 | * before setting the bit. |
| 16155 | * |
| 16156 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 16157 | * -EINVAL. |
| 16158 | **/ |
| 16159 | int |
| 16160 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16161 | { |
| 16162 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16163 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16164 | "2610 FCF (x%x) reached driver's book " |
| 16165 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16166 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16167 | return -EINVAL; |
| 16168 | } |
| 16169 | /* Set the eligible FCF record index bmask */ |
| 16170 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 16171 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16172 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16173 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16174 | "bmask\n", fcf_index); |
| 16175 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16176 | return 0; |
| 16177 | } |
| 16178 | |
| 16179 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16180 | * 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] | 16181 | * @phba: pointer to lpfc hba data structure. |
| 16182 | * |
| 16183 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16184 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16185 | * does not go beyond the range of the driver allocated bmask dimension |
| 16186 | * before clearing the bit. |
| 16187 | **/ |
| 16188 | void |
| 16189 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 16190 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16191 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16192 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 16193 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16194 | "2762 FCF (x%x) reached driver's book " |
| 16195 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16196 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 16197 | return; |
| 16198 | } |
| 16199 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16200 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 16201 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 16202 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 16203 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 16204 | list_del_init(&fcf_pri->list); |
| 16205 | break; |
| 16206 | } |
| 16207 | } |
| 16208 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16209 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16210 | |
| 16211 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16212 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16213 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16214 | } |
| 16215 | |
| 16216 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16217 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 16218 | * @phba: pointer to lpfc hba data structure. |
| 16219 | * |
| 16220 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 16221 | * command. If the mailbox command returned failure, it will try to stop the |
| 16222 | * FCF rediscover wait timer. |
| 16223 | **/ |
| 16224 | void |
| 16225 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 16226 | { |
| 16227 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16228 | uint32_t shdr_status, shdr_add_status; |
| 16229 | |
| 16230 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16231 | |
| 16232 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 16233 | &redisc_fcf->header.cfg_shdr.response); |
| 16234 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 16235 | &redisc_fcf->header.cfg_shdr.response); |
| 16236 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16237 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16238 | "2746 Requesting for FCF rediscovery failed " |
| 16239 | "status x%x add_status x%x\n", |
| 16240 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16241 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16242 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16243 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16244 | spin_unlock_irq(&phba->hbalock); |
| 16245 | /* |
| 16246 | * CVL event triggered FCF rediscover request failed, |
| 16247 | * last resort to re-try current registered FCF entry. |
| 16248 | */ |
| 16249 | lpfc_retry_pport_discovery(phba); |
| 16250 | } else { |
| 16251 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16252 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16253 | spin_unlock_irq(&phba->hbalock); |
| 16254 | /* |
| 16255 | * DEAD FCF event triggered FCF rediscover request |
| 16256 | * failed, last resort to fail over as a link down |
| 16257 | * to FCF registration. |
| 16258 | */ |
| 16259 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 16260 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16261 | } else { |
| 16262 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16263 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16264 | /* |
| 16265 | * Start FCF rediscovery wait timer for pending FCF |
| 16266 | * before rescan FCF record table. |
| 16267 | */ |
| 16268 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16269 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16270 | |
| 16271 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16272 | } |
| 16273 | |
| 16274 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16275 | * 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] | 16276 | * @phba: pointer to lpfc hba data structure. |
| 16277 | * |
| 16278 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 16279 | * by the port. |
| 16280 | **/ |
| 16281 | int |
| 16282 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 16283 | { |
| 16284 | LPFC_MBOXQ_t *mbox; |
| 16285 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16286 | int rc, length; |
| 16287 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16288 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 16289 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 16290 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16291 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16292 | if (!mbox) { |
| 16293 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16294 | "2745 Failed to allocate mbox for " |
| 16295 | "requesting FCF rediscover.\n"); |
| 16296 | return -ENOMEM; |
| 16297 | } |
| 16298 | |
| 16299 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 16300 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16301 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16302 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 16303 | length, LPFC_SLI4_MBX_EMBED); |
| 16304 | |
| 16305 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16306 | /* Set count to 0 for invalidating the entire FCF database */ |
| 16307 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 16308 | |
| 16309 | /* Issue the mailbox command asynchronously */ |
| 16310 | mbox->vport = phba->pport; |
| 16311 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 16312 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 16313 | |
| 16314 | if (rc == MBX_NOT_FINISHED) { |
| 16315 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16316 | return -EIO; |
| 16317 | } |
| 16318 | return 0; |
| 16319 | } |
| 16320 | |
| 16321 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16322 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 16323 | * @phba: pointer to lpfc hba data structure. |
| 16324 | * |
| 16325 | * This function is the failover routine as a last resort to the FCF DEAD |
| 16326 | * event when driver failed to perform fast FCF failover. |
| 16327 | **/ |
| 16328 | void |
| 16329 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 16330 | { |
| 16331 | uint32_t link_state; |
| 16332 | |
| 16333 | /* |
| 16334 | * Last resort as FCF DEAD event failover will treat this as |
| 16335 | * a link down, but save the link state because we don't want |
| 16336 | * it to be changed to Link Down unless it is already down. |
| 16337 | */ |
| 16338 | link_state = phba->link_state; |
| 16339 | lpfc_linkdown(phba); |
| 16340 | phba->link_state = link_state; |
| 16341 | |
| 16342 | /* Unregister FCF if no devices connected to it */ |
| 16343 | lpfc_unregister_unused_fcf(phba); |
| 16344 | } |
| 16345 | |
| 16346 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16347 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16348 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16349 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16350 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16351 | * This function gets SLI3 port configure region 23 data through memory dump |
| 16352 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16353 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16354 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16355 | static uint32_t |
| 16356 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16357 | { |
| 16358 | LPFC_MBOXQ_t *pmb = NULL; |
| 16359 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16360 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16361 | int rc; |
| 16362 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16363 | if (!rgn23_data) |
| 16364 | return 0; |
| 16365 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16366 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16367 | if (!pmb) { |
| 16368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16369 | "2600 failed to allocate mailbox memory\n"); |
| 16370 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16371 | } |
| 16372 | mb = &pmb->u.mb; |
| 16373 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16374 | do { |
| 16375 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 16376 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 16377 | |
| 16378 | if (rc != MBX_SUCCESS) { |
| 16379 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16380 | "2601 failed to read config " |
| 16381 | "region 23, rc 0x%x Status 0x%x\n", |
| 16382 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16383 | mb->un.varDmp.word_cnt = 0; |
| 16384 | } |
| 16385 | /* |
| 16386 | * dump mem may return a zero when finished or we got a |
| 16387 | * mailbox error, either way we are done. |
| 16388 | */ |
| 16389 | if (mb->un.varDmp.word_cnt == 0) |
| 16390 | break; |
| 16391 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 16392 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 16393 | |
| 16394 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16395 | rgn23_data + offset, |
| 16396 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16397 | offset += mb->un.varDmp.word_cnt; |
| 16398 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 16399 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16400 | mempool_free(pmb, phba->mbox_mem_pool); |
| 16401 | return offset; |
| 16402 | } |
| 16403 | |
| 16404 | /** |
| 16405 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 16406 | * @phba: pointer to lpfc hba data structure. |
| 16407 | * @rgn23_data: pointer to configure region 23 data. |
| 16408 | * |
| 16409 | * This function gets SLI4 port configure region 23 data through memory dump |
| 16410 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16411 | * will be returned, otherwise, 0 will be returned. |
| 16412 | **/ |
| 16413 | static uint32_t |
| 16414 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 16415 | { |
| 16416 | LPFC_MBOXQ_t *mboxq = NULL; |
| 16417 | struct lpfc_dmabuf *mp = NULL; |
| 16418 | struct lpfc_mqe *mqe; |
| 16419 | uint32_t data_length = 0; |
| 16420 | int rc; |
| 16421 | |
| 16422 | if (!rgn23_data) |
| 16423 | return 0; |
| 16424 | |
| 16425 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16426 | if (!mboxq) { |
| 16427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16428 | "3105 failed to allocate mailbox memory\n"); |
| 16429 | return 0; |
| 16430 | } |
| 16431 | |
| 16432 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 16433 | goto out; |
| 16434 | mqe = &mboxq->u.mqe; |
| 16435 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 16436 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 16437 | if (rc) |
| 16438 | goto out; |
| 16439 | data_length = mqe->un.mb_words[5]; |
| 16440 | if (data_length == 0) |
| 16441 | goto out; |
| 16442 | if (data_length > DMP_RGN23_SIZE) { |
| 16443 | data_length = 0; |
| 16444 | goto out; |
| 16445 | } |
| 16446 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 16447 | out: |
| 16448 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16449 | if (mp) { |
| 16450 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16451 | kfree(mp); |
| 16452 | } |
| 16453 | return data_length; |
| 16454 | } |
| 16455 | |
| 16456 | /** |
| 16457 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 16458 | * @phba: pointer to lpfc hba data structure. |
| 16459 | * |
| 16460 | * This function read region 23 and parse TLV for port status to |
| 16461 | * decide if the user disaled the port. If the TLV indicates the |
| 16462 | * port is disabled, the hba_flag is set accordingly. |
| 16463 | **/ |
| 16464 | void |
| 16465 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 16466 | { |
| 16467 | uint8_t *rgn23_data = NULL; |
| 16468 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 16469 | uint32_t offset = 0; |
| 16470 | |
| 16471 | /* Get adapter Region 23 data */ |
| 16472 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 16473 | if (!rgn23_data) |
| 16474 | goto out; |
| 16475 | |
| 16476 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16477 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 16478 | else { |
| 16479 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 16480 | &phba->sli4_hba.sli_intf); |
| 16481 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 16482 | goto out; |
| 16483 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 16484 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16485 | |
| 16486 | if (!data_size) |
| 16487 | goto out; |
| 16488 | |
| 16489 | /* Check the region signature first */ |
| 16490 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 16491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16492 | "2619 Config region 23 has bad signature\n"); |
| 16493 | goto out; |
| 16494 | } |
| 16495 | offset += 4; |
| 16496 | |
| 16497 | /* Check the data structure version */ |
| 16498 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16500 | "2620 Config region 23 has bad version\n"); |
| 16501 | goto out; |
| 16502 | } |
| 16503 | offset += 4; |
| 16504 | |
| 16505 | /* Parse TLV entries in the region */ |
| 16506 | while (offset < data_size) { |
| 16507 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16508 | break; |
| 16509 | /* |
| 16510 | * If the TLV is not driver specific TLV or driver id is |
| 16511 | * not linux driver id, skip the record. |
| 16512 | */ |
| 16513 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16514 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16515 | (rgn23_data[offset + 3] != 0)) { |
| 16516 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16517 | continue; |
| 16518 | } |
| 16519 | |
| 16520 | /* Driver found a driver specific TLV in the config region */ |
| 16521 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16522 | offset += 4; |
| 16523 | tlv_offset = 0; |
| 16524 | |
| 16525 | /* |
| 16526 | * Search for configured port state sub-TLV. |
| 16527 | */ |
| 16528 | while ((offset < data_size) && |
| 16529 | (tlv_offset < sub_tlv_len)) { |
| 16530 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16531 | offset += 4; |
| 16532 | tlv_offset += 4; |
| 16533 | break; |
| 16534 | } |
| 16535 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16536 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16537 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16538 | continue; |
| 16539 | } |
| 16540 | |
| 16541 | /* This HBA contains PORT_STE configured */ |
| 16542 | if (!rgn23_data[offset + 2]) |
| 16543 | phba->hba_flag |= LINK_DISABLED; |
| 16544 | |
| 16545 | goto out; |
| 16546 | } |
| 16547 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16548 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16549 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16550 | kfree(rgn23_data); |
| 16551 | return; |
| 16552 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16553 | |
| 16554 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16555 | * lpfc_wr_object - write an object to the firmware |
| 16556 | * @phba: HBA structure that indicates port to create a queue on. |
| 16557 | * @dmabuf_list: list of dmabufs to write to the port. |
| 16558 | * @size: the total byte value of the objects to write to the port. |
| 16559 | * @offset: the current offset to be used to start the transfer. |
| 16560 | * |
| 16561 | * This routine will create a wr_object mailbox command to send to the port. |
| 16562 | * the mailbox command will be constructed using the dma buffers described in |
| 16563 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 16564 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 16565 | * used to indicate the starting offset of the transfer and will also return |
| 16566 | * the offset after the write object mailbox has completed. @size is used to |
| 16567 | * determine the end of the object and whether the eof bit should be set. |
| 16568 | * |
| 16569 | * Return 0 is successful and offset will contain the the new offset to use |
| 16570 | * for the next write. |
| 16571 | * Return negative value for error cases. |
| 16572 | **/ |
| 16573 | int |
| 16574 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 16575 | uint32_t size, uint32_t *offset) |
| 16576 | { |
| 16577 | struct lpfc_mbx_wr_object *wr_object; |
| 16578 | LPFC_MBOXQ_t *mbox; |
| 16579 | int rc = 0, i = 0; |
| 16580 | uint32_t shdr_status, shdr_add_status; |
| 16581 | uint32_t mbox_tmo; |
| 16582 | union lpfc_sli4_cfg_shdr *shdr; |
| 16583 | struct lpfc_dmabuf *dmabuf; |
| 16584 | uint32_t written = 0; |
| 16585 | |
| 16586 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16587 | if (!mbox) |
| 16588 | return -ENOMEM; |
| 16589 | |
| 16590 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16591 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 16592 | sizeof(struct lpfc_mbx_wr_object) - |
| 16593 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 16594 | |
| 16595 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 16596 | wr_object->u.request.write_offset = *offset; |
| 16597 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 16598 | wr_object->u.request.object_name[0] = |
| 16599 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 16600 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 16601 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 16602 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 16603 | break; |
| 16604 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 16605 | wr_object->u.request.bde[i].addrHigh = |
| 16606 | putPaddrHigh(dmabuf->phys); |
| 16607 | if (written + SLI4_PAGE_SIZE >= size) { |
| 16608 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16609 | (size - written); |
| 16610 | written += (size - written); |
| 16611 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 16612 | } else { |
| 16613 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16614 | SLI4_PAGE_SIZE; |
| 16615 | written += SLI4_PAGE_SIZE; |
| 16616 | } |
| 16617 | i++; |
| 16618 | } |
| 16619 | wr_object->u.request.bde_count = i; |
| 16620 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 16621 | if (!phba->sli4_hba.intr_enable) |
| 16622 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16623 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16624 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16625 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16626 | } |
| 16627 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16628 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 16629 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16630 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16631 | if (rc != MBX_TIMEOUT) |
| 16632 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16633 | if (shdr_status || shdr_add_status || rc) { |
| 16634 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16635 | "3025 Write Object mailbox failed with " |
| 16636 | "status x%x add_status x%x, mbx status x%x\n", |
| 16637 | shdr_status, shdr_add_status, rc); |
| 16638 | rc = -ENXIO; |
| 16639 | } else |
| 16640 | *offset += wr_object->u.response.actual_write_length; |
| 16641 | return rc; |
| 16642 | } |
| 16643 | |
| 16644 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16645 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 16646 | * @vport: pointer to vport data structure. |
| 16647 | * |
| 16648 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 16649 | * and REG_VPI mailbox commands associated with the vport. This function |
| 16650 | * is called when driver want to restart discovery of the vport due to |
| 16651 | * a Clear Virtual Link event. |
| 16652 | **/ |
| 16653 | void |
| 16654 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 16655 | { |
| 16656 | struct lpfc_hba *phba = vport->phba; |
| 16657 | LPFC_MBOXQ_t *mb, *nextmb; |
| 16658 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16659 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16660 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16661 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16662 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16663 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16664 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16665 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16666 | spin_lock_irq(&phba->hbalock); |
| 16667 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 16668 | if (mb->vport != vport) |
| 16669 | continue; |
| 16670 | |
| 16671 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16672 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16673 | continue; |
| 16674 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16675 | list_del(&mb->list); |
| 16676 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 16677 | } |
| 16678 | /* Clean up active mailbox command with the vport */ |
| 16679 | mb = phba->sli.mbox_active; |
| 16680 | if (mb && (mb->vport == vport)) { |
| 16681 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 16682 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 16683 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16684 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16685 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16686 | /* Put reference count for delayed processing */ |
| 16687 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 16688 | /* Unregister the RPI when mailbox complete */ |
| 16689 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16690 | } |
| 16691 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16692 | /* Cleanup any mailbox completions which are not yet processed */ |
| 16693 | do { |
| 16694 | restart_loop = 0; |
| 16695 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 16696 | /* |
| 16697 | * If this mailox is already processed or it is |
| 16698 | * for another vport ignore it. |
| 16699 | */ |
| 16700 | if ((mb->vport != vport) || |
| 16701 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 16702 | continue; |
| 16703 | |
| 16704 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16705 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16706 | continue; |
| 16707 | |
| 16708 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16709 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16710 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16711 | /* Unregister the RPI when mailbox complete */ |
| 16712 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16713 | restart_loop = 1; |
| 16714 | spin_unlock_irq(&phba->hbalock); |
| 16715 | spin_lock(shost->host_lock); |
| 16716 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16717 | spin_unlock(shost->host_lock); |
| 16718 | spin_lock_irq(&phba->hbalock); |
| 16719 | break; |
| 16720 | } |
| 16721 | } |
| 16722 | } while (restart_loop); |
| 16723 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16724 | spin_unlock_irq(&phba->hbalock); |
| 16725 | |
| 16726 | /* Release the cleaned-up mailbox commands */ |
| 16727 | while (!list_empty(&mbox_cmd_list)) { |
| 16728 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16729 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16730 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 16731 | if (mp) { |
| 16732 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16733 | kfree(mp); |
| 16734 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16735 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16736 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16737 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16738 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16739 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16740 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16741 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16742 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16743 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16744 | mempool_free(mb, phba->mbox_mem_pool); |
| 16745 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16746 | |
| 16747 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 16748 | if (act_mbx_ndlp) { |
| 16749 | spin_lock(shost->host_lock); |
| 16750 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16751 | spin_unlock(shost->host_lock); |
| 16752 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16753 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16754 | } |
| 16755 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16756 | /** |
| 16757 | * lpfc_drain_txq - Drain the txq |
| 16758 | * @phba: Pointer to HBA context object. |
| 16759 | * |
| 16760 | * This function attempt to submit IOCBs on the txq |
| 16761 | * to the adapter. For SLI4 adapters, the txq contains |
| 16762 | * ELS IOCBs that have been deferred because the there |
| 16763 | * are no SGLs. This congestion can occur with large |
| 16764 | * vport counts during node discovery. |
| 16765 | **/ |
| 16766 | |
| 16767 | uint32_t |
| 16768 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 16769 | { |
| 16770 | LIST_HEAD(completions); |
| 16771 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 16772 | struct lpfc_iocbq *piocbq = 0; |
| 16773 | unsigned long iflags = 0; |
| 16774 | char *fail_msg = NULL; |
| 16775 | struct lpfc_sglq *sglq; |
| 16776 | union lpfc_wqe wqe; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16777 | int txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16778 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16779 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16780 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 16781 | txq_cnt++; |
| 16782 | } |
| 16783 | |
| 16784 | if (txq_cnt > pring->txq_max) |
| 16785 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16786 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16787 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16788 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16789 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16790 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16791 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16792 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16793 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16794 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16795 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16796 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16797 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16798 | break; |
| 16799 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16800 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16801 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16802 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16803 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16804 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16805 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16806 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16807 | |
| 16808 | /* The xri and iocb resources secured, |
| 16809 | * attempt to issue request |
| 16810 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16811 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16812 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16813 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16814 | fail_msg = "to convert bpl to sgl"; |
| 16815 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16816 | fail_msg = "to convert iocb to wqe"; |
| 16817 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16818 | fail_msg = " - Wq is full"; |
| 16819 | else |
| 16820 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16821 | |
| 16822 | if (fail_msg) { |
| 16823 | /* Failed means we can't issue and need to cancel */ |
| 16824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16825 | "2822 IOCB failed %s iotag 0x%x " |
| 16826 | "xri 0x%x\n", |
| 16827 | fail_msg, |
| 16828 | piocbq->iotag, piocbq->sli4_xritag); |
| 16829 | list_add_tail(&piocbq->list, &completions); |
| 16830 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16831 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16832 | } |
| 16833 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16834 | /* Cancel all the IOCBs that cannot be issued */ |
| 16835 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16836 | IOERR_SLI_ABORTED); |
| 16837 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16838 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16839 | } |