| 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 | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4979 | if (phba->sli4_hba.hba_eq) { |
| 4980 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4981 | fcp_eqidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4982 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 4983 | LPFC_QUEUE_REARM); |
| 4984 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4988 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 4989 | * @phba: Pointer to HBA context object. |
| 4990 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4991 | * @extnt_count: buffer to hold port available extent count. |
| 4992 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4993 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4994 | * This function calls the port and retrievs the number of available |
| 4995 | * extents and their size for a particular extent type. |
| 4996 | * |
| 4997 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4998 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4999 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5000 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5001 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5002 | { |
| 5003 | int rc = 0; |
| 5004 | uint32_t length; |
| 5005 | uint32_t mbox_tmo; |
| 5006 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5007 | LPFC_MBOXQ_t *mbox; |
| 5008 | |
| 5009 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5010 | if (!mbox) |
| 5011 | return -ENOMEM; |
| 5012 | |
| 5013 | /* Find out how many extents are available for this resource type */ |
| 5014 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5015 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5016 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5017 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5018 | length, LPFC_SLI4_MBX_EMBED); |
| 5019 | |
| 5020 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5021 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5022 | LPFC_SLI4_MBX_EMBED); |
| 5023 | if (unlikely(rc)) { |
| 5024 | rc = -EIO; |
| 5025 | goto err_exit; |
| 5026 | } |
| 5027 | |
| 5028 | if (!phba->sli4_hba.intr_enable) |
| 5029 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5030 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5031 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5032 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5033 | } |
| 5034 | if (unlikely(rc)) { |
| 5035 | rc = -EIO; |
| 5036 | goto err_exit; |
| 5037 | } |
| 5038 | |
| 5039 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5040 | if (bf_get(lpfc_mbox_hdr_status, |
| 5041 | &rsrc_info->header.cfg_shdr.response)) { |
| 5042 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5043 | "2930 Failed to get resource extents " |
| 5044 | "Status 0x%x Add'l Status 0x%x\n", |
| 5045 | bf_get(lpfc_mbox_hdr_status, |
| 5046 | &rsrc_info->header.cfg_shdr.response), |
| 5047 | bf_get(lpfc_mbox_hdr_add_status, |
| 5048 | &rsrc_info->header.cfg_shdr.response)); |
| 5049 | rc = -EIO; |
| 5050 | goto err_exit; |
| 5051 | } |
| 5052 | |
| 5053 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5054 | &rsrc_info->u.rsp); |
| 5055 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5056 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5057 | |
| 5058 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5059 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5060 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5061 | |
| 5062 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5063 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5064 | return rc; |
| 5065 | } |
| 5066 | |
| 5067 | /** |
| 5068 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5069 | * @phba: Pointer to HBA context object. |
| 5070 | * @type: The extent type to check. |
| 5071 | * |
| 5072 | * This function reads the current available extents from the port and checks |
| 5073 | * if the extent count or extent size has changed since the last access. |
| 5074 | * Callers use this routine post port reset to understand if there is a |
| 5075 | * extent reprovisioning requirement. |
| 5076 | * |
| 5077 | * Returns: |
| 5078 | * -Error: error indicates problem. |
| 5079 | * 1: Extent count or size has changed. |
| 5080 | * 0: No changes. |
| 5081 | **/ |
| 5082 | static int |
| 5083 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5084 | { |
| 5085 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5086 | uint16_t size_diff, rsrc_ext_size; |
| 5087 | int rc = 0; |
| 5088 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5089 | struct list_head *rsrc_blk_list = NULL; |
| 5090 | |
| 5091 | size_diff = 0; |
| 5092 | curr_ext_cnt = 0; |
| 5093 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5094 | &rsrc_ext_cnt, |
| 5095 | &rsrc_ext_size); |
| 5096 | if (unlikely(rc)) |
| 5097 | return -EIO; |
| 5098 | |
| 5099 | switch (type) { |
| 5100 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5101 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5102 | break; |
| 5103 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5104 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5105 | break; |
| 5106 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5107 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5108 | break; |
| 5109 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5110 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5111 | break; |
| 5112 | default: |
| 5113 | break; |
| 5114 | } |
| 5115 | |
| 5116 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5117 | curr_ext_cnt++; |
| 5118 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5119 | size_diff++; |
| 5120 | } |
| 5121 | |
| 5122 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5123 | rc = 1; |
| 5124 | |
| 5125 | return rc; |
| 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * lpfc_sli4_cfg_post_extnts - |
| 5130 | * @phba: Pointer to HBA context object. |
| 5131 | * @extnt_cnt - number of available extents. |
| 5132 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5133 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5134 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5135 | * |
| 5136 | * This function executes the extents allocation request. It also |
| 5137 | * takes care of the amount of memory needed to allocate or get the |
| 5138 | * allocated extents. It is the caller's responsibility to evaluate |
| 5139 | * the response. |
| 5140 | * |
| 5141 | * Returns: |
| 5142 | * -Error: Error value describes the condition found. |
| 5143 | * 0: if successful |
| 5144 | **/ |
| 5145 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5146 | 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] | 5147 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5148 | { |
| 5149 | int rc = 0; |
| 5150 | uint32_t req_len; |
| 5151 | uint32_t emb_len; |
| 5152 | uint32_t alloc_len, mbox_tmo; |
| 5153 | |
| 5154 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5155 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5156 | |
| 5157 | /* |
| 5158 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5159 | * accounts for extents-specific word. |
| 5160 | */ |
| 5161 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5162 | sizeof(uint32_t); |
| 5163 | |
| 5164 | /* |
| 5165 | * Presume the allocation and response will fit into an embedded |
| 5166 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5167 | */ |
| 5168 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5169 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5170 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5171 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5172 | sizeof(uint32_t); |
| 5173 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5174 | } |
| 5175 | |
| 5176 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5177 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5178 | req_len, *emb); |
| 5179 | if (alloc_len < req_len) { |
| 5180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5181 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5182 | "less than the requested DMA memory " |
| 5183 | "size (x%x)\n", alloc_len, req_len); |
| 5184 | return -ENOMEM; |
| 5185 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5186 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5187 | if (unlikely(rc)) |
| 5188 | return -EIO; |
| 5189 | |
| 5190 | if (!phba->sli4_hba.intr_enable) |
| 5191 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5192 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5193 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5194 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5195 | } |
| 5196 | |
| 5197 | if (unlikely(rc)) |
| 5198 | rc = -EIO; |
| 5199 | return rc; |
| 5200 | } |
| 5201 | |
| 5202 | /** |
| 5203 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5204 | * @phba: Pointer to HBA context object. |
| 5205 | * @type: The resource extent type to allocate. |
| 5206 | * |
| 5207 | * This function allocates the number of elements for the specified |
| 5208 | * resource type. |
| 5209 | **/ |
| 5210 | static int |
| 5211 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5212 | { |
| 5213 | bool emb = false; |
| 5214 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5215 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5216 | uint16_t *ids; |
| 5217 | int i, rc; |
| 5218 | unsigned long longs; |
| 5219 | unsigned long *bmask; |
| 5220 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5221 | LPFC_MBOXQ_t *mbox; |
| 5222 | uint32_t length; |
| 5223 | struct lpfc_id_range *id_array = NULL; |
| 5224 | void *virtaddr = NULL; |
| 5225 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5226 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5227 | struct list_head *ext_blk_list; |
| 5228 | |
| 5229 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5230 | &rsrc_cnt, |
| 5231 | &rsrc_size); |
| 5232 | if (unlikely(rc)) |
| 5233 | return -EIO; |
| 5234 | |
| 5235 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5236 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5237 | "3009 No available Resource Extents " |
| 5238 | "for resource type 0x%x: Count: 0x%x, " |
| 5239 | "Size 0x%x\n", type, rsrc_cnt, |
| 5240 | rsrc_size); |
| 5241 | return -ENOMEM; |
| 5242 | } |
| 5243 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5244 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5245 | "2903 Post resource extents type-0x%x: " |
| 5246 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5247 | |
| 5248 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5249 | if (!mbox) |
| 5250 | return -ENOMEM; |
| 5251 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5252 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5253 | if (unlikely(rc)) { |
| 5254 | rc = -EIO; |
| 5255 | goto err_exit; |
| 5256 | } |
| 5257 | |
| 5258 | /* |
| 5259 | * Figure out where the response is located. Then get local pointers |
| 5260 | * to the response data. The port does not guarantee to respond to |
| 5261 | * all extents counts request so update the local variable with the |
| 5262 | * allocated count from the port. |
| 5263 | */ |
| 5264 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5265 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5266 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5267 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5268 | } else { |
| 5269 | virtaddr = mbox->sge_array->addr[0]; |
| 5270 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5271 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5272 | id_array = &n_rsrc->id; |
| 5273 | } |
| 5274 | |
| 5275 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5276 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5277 | |
| 5278 | /* |
| 5279 | * Based on the resource size and count, correct the base and max |
| 5280 | * resource values. |
| 5281 | */ |
| 5282 | length = sizeof(struct lpfc_rsrc_blks); |
| 5283 | switch (type) { |
| 5284 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5285 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5286 | sizeof(unsigned long), |
| 5287 | GFP_KERNEL); |
| 5288 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5289 | rc = -ENOMEM; |
| 5290 | goto err_exit; |
| 5291 | } |
| 5292 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5293 | sizeof(uint16_t), |
| 5294 | GFP_KERNEL); |
| 5295 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5296 | kfree(phba->sli4_hba.rpi_bmask); |
| 5297 | rc = -ENOMEM; |
| 5298 | goto err_exit; |
| 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | * The next_rpi was initialized with the maximum available |
| 5303 | * count but the port may allocate a smaller number. Catch |
| 5304 | * that case and update the next_rpi. |
| 5305 | */ |
| 5306 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5307 | |
| 5308 | /* Initialize local ptrs for common extent processing later. */ |
| 5309 | bmask = phba->sli4_hba.rpi_bmask; |
| 5310 | ids = phba->sli4_hba.rpi_ids; |
| 5311 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5312 | break; |
| 5313 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5314 | phba->vpi_bmask = kzalloc(longs * |
| 5315 | sizeof(unsigned long), |
| 5316 | GFP_KERNEL); |
| 5317 | if (unlikely(!phba->vpi_bmask)) { |
| 5318 | rc = -ENOMEM; |
| 5319 | goto err_exit; |
| 5320 | } |
| 5321 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5322 | sizeof(uint16_t), |
| 5323 | GFP_KERNEL); |
| 5324 | if (unlikely(!phba->vpi_ids)) { |
| 5325 | kfree(phba->vpi_bmask); |
| 5326 | rc = -ENOMEM; |
| 5327 | goto err_exit; |
| 5328 | } |
| 5329 | |
| 5330 | /* Initialize local ptrs for common extent processing later. */ |
| 5331 | bmask = phba->vpi_bmask; |
| 5332 | ids = phba->vpi_ids; |
| 5333 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5334 | break; |
| 5335 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5336 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5337 | sizeof(unsigned long), |
| 5338 | GFP_KERNEL); |
| 5339 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5340 | rc = -ENOMEM; |
| 5341 | goto err_exit; |
| 5342 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5343 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5344 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5345 | sizeof(uint16_t), |
| 5346 | GFP_KERNEL); |
| 5347 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5348 | kfree(phba->sli4_hba.xri_bmask); |
| 5349 | rc = -ENOMEM; |
| 5350 | goto err_exit; |
| 5351 | } |
| 5352 | |
| 5353 | /* Initialize local ptrs for common extent processing later. */ |
| 5354 | bmask = phba->sli4_hba.xri_bmask; |
| 5355 | ids = phba->sli4_hba.xri_ids; |
| 5356 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5357 | break; |
| 5358 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5359 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5360 | sizeof(unsigned long), |
| 5361 | GFP_KERNEL); |
| 5362 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5363 | rc = -ENOMEM; |
| 5364 | goto err_exit; |
| 5365 | } |
| 5366 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5367 | sizeof(uint16_t), |
| 5368 | GFP_KERNEL); |
| 5369 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5370 | kfree(phba->sli4_hba.vfi_bmask); |
| 5371 | rc = -ENOMEM; |
| 5372 | goto err_exit; |
| 5373 | } |
| 5374 | |
| 5375 | /* Initialize local ptrs for common extent processing later. */ |
| 5376 | bmask = phba->sli4_hba.vfi_bmask; |
| 5377 | ids = phba->sli4_hba.vfi_ids; |
| 5378 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5379 | break; |
| 5380 | default: |
| 5381 | /* Unsupported Opcode. Fail call. */ |
| 5382 | id_array = NULL; |
| 5383 | bmask = NULL; |
| 5384 | ids = NULL; |
| 5385 | ext_blk_list = NULL; |
| 5386 | goto err_exit; |
| 5387 | } |
| 5388 | |
| 5389 | /* |
| 5390 | * Complete initializing the extent configuration with the |
| 5391 | * allocated ids assigned to this function. The bitmask serves |
| 5392 | * as an index into the array and manages the available ids. The |
| 5393 | * array just stores the ids communicated to the port via the wqes. |
| 5394 | */ |
| 5395 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5396 | if ((i % 2) == 0) |
| 5397 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5398 | &id_array[k]); |
| 5399 | else |
| 5400 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5401 | &id_array[k]); |
| 5402 | |
| 5403 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5404 | if (unlikely(!rsrc_blks)) { |
| 5405 | rc = -ENOMEM; |
| 5406 | kfree(bmask); |
| 5407 | kfree(ids); |
| 5408 | goto err_exit; |
| 5409 | } |
| 5410 | rsrc_blks->rsrc_start = rsrc_id; |
| 5411 | rsrc_blks->rsrc_size = rsrc_size; |
| 5412 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5413 | rsrc_start = rsrc_id; |
| 5414 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) |
| 5415 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
| 5416 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 5417 | |
| 5418 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5419 | ids[j] = rsrc_id; |
| 5420 | rsrc_id++; |
| 5421 | j++; |
| 5422 | } |
| 5423 | /* Entire word processed. Get next word.*/ |
| 5424 | if ((i % 2) == 1) |
| 5425 | k++; |
| 5426 | } |
| 5427 | err_exit: |
| 5428 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5429 | return rc; |
| 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5434 | * @phba: Pointer to HBA context object. |
| 5435 | * @type: the extent's type. |
| 5436 | * |
| 5437 | * This function deallocates all extents of a particular resource type. |
| 5438 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5439 | * is the caller's responsibility to release all kernel memory resources. |
| 5440 | **/ |
| 5441 | static int |
| 5442 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5443 | { |
| 5444 | int rc; |
| 5445 | uint32_t length, mbox_tmo = 0; |
| 5446 | LPFC_MBOXQ_t *mbox; |
| 5447 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5448 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5449 | |
| 5450 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5451 | if (!mbox) |
| 5452 | return -ENOMEM; |
| 5453 | |
| 5454 | /* |
| 5455 | * This function sends an embedded mailbox because it only sends the |
| 5456 | * the resource type. All extents of this type are released by the |
| 5457 | * port. |
| 5458 | */ |
| 5459 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5460 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5461 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5462 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5463 | length, LPFC_SLI4_MBX_EMBED); |
| 5464 | |
| 5465 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5466 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5467 | LPFC_SLI4_MBX_EMBED); |
| 5468 | if (unlikely(rc)) { |
| 5469 | rc = -EIO; |
| 5470 | goto out_free_mbox; |
| 5471 | } |
| 5472 | if (!phba->sli4_hba.intr_enable) |
| 5473 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5474 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5475 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5476 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5477 | } |
| 5478 | if (unlikely(rc)) { |
| 5479 | rc = -EIO; |
| 5480 | goto out_free_mbox; |
| 5481 | } |
| 5482 | |
| 5483 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5484 | if (bf_get(lpfc_mbox_hdr_status, |
| 5485 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5487 | "2919 Failed to release resource extents " |
| 5488 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5489 | "Resource memory not released.\n", |
| 5490 | type, |
| 5491 | bf_get(lpfc_mbox_hdr_status, |
| 5492 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5493 | bf_get(lpfc_mbox_hdr_add_status, |
| 5494 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5495 | rc = -EIO; |
| 5496 | goto out_free_mbox; |
| 5497 | } |
| 5498 | |
| 5499 | /* Release kernel memory resources for the specific type. */ |
| 5500 | switch (type) { |
| 5501 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5502 | kfree(phba->vpi_bmask); |
| 5503 | kfree(phba->vpi_ids); |
| 5504 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5505 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5506 | &phba->lpfc_vpi_blk_list, list) { |
| 5507 | list_del_init(&rsrc_blk->list); |
| 5508 | kfree(rsrc_blk); |
| 5509 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5510 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5511 | break; |
| 5512 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5513 | kfree(phba->sli4_hba.xri_bmask); |
| 5514 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5515 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5516 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5517 | list_del_init(&rsrc_blk->list); |
| 5518 | kfree(rsrc_blk); |
| 5519 | } |
| 5520 | break; |
| 5521 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5522 | kfree(phba->sli4_hba.vfi_bmask); |
| 5523 | kfree(phba->sli4_hba.vfi_ids); |
| 5524 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5525 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5526 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5527 | list_del_init(&rsrc_blk->list); |
| 5528 | kfree(rsrc_blk); |
| 5529 | } |
| 5530 | break; |
| 5531 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5532 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5533 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5534 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5535 | list_del_init(&rsrc_blk->list); |
| 5536 | kfree(rsrc_blk); |
| 5537 | } |
| 5538 | break; |
| 5539 | default: |
| 5540 | break; |
| 5541 | } |
| 5542 | |
| 5543 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5544 | |
| 5545 | out_free_mbox: |
| 5546 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5547 | return rc; |
| 5548 | } |
| 5549 | |
| 5550 | /** |
| 5551 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5552 | * @phba: Pointer to HBA context object. |
| 5553 | * |
| 5554 | * This function allocates all SLI4 resource identifiers. |
| 5555 | **/ |
| 5556 | int |
| 5557 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5558 | { |
| 5559 | int i, rc, error = 0; |
| 5560 | uint16_t count, base; |
| 5561 | unsigned long longs; |
| 5562 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5563 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5564 | 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] | 5565 | if (phba->sli4_hba.extents_in_use) { |
| 5566 | /* |
| 5567 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5568 | * resource extent count must be read and allocated before |
| 5569 | * provisioning the resource id arrays. |
| 5570 | */ |
| 5571 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5572 | LPFC_IDX_RSRC_RDY) { |
| 5573 | /* |
| 5574 | * Extent-based resources are set - the driver could |
| 5575 | * be in a port reset. Figure out if any corrective |
| 5576 | * actions need to be taken. |
| 5577 | */ |
| 5578 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5579 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5580 | if (rc != 0) |
| 5581 | error++; |
| 5582 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5583 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5584 | if (rc != 0) |
| 5585 | error++; |
| 5586 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5587 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5588 | if (rc != 0) |
| 5589 | error++; |
| 5590 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5591 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5592 | if (rc != 0) |
| 5593 | error++; |
| 5594 | |
| 5595 | /* |
| 5596 | * It's possible that the number of resources |
| 5597 | * provided to this port instance changed between |
| 5598 | * resets. Detect this condition and reallocate |
| 5599 | * resources. Otherwise, there is no action. |
| 5600 | */ |
| 5601 | if (error) { |
| 5602 | lpfc_printf_log(phba, KERN_INFO, |
| 5603 | LOG_MBOX | LOG_INIT, |
| 5604 | "2931 Detected extent resource " |
| 5605 | "change. Reallocating all " |
| 5606 | "extents.\n"); |
| 5607 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5608 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5609 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5610 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5611 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5612 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5613 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5614 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5615 | } else |
| 5616 | return 0; |
| 5617 | } |
| 5618 | |
| 5619 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5620 | if (unlikely(rc)) |
| 5621 | goto err_exit; |
| 5622 | |
| 5623 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5624 | if (unlikely(rc)) |
| 5625 | goto err_exit; |
| 5626 | |
| 5627 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5628 | if (unlikely(rc)) |
| 5629 | goto err_exit; |
| 5630 | |
| 5631 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5632 | if (unlikely(rc)) |
| 5633 | goto err_exit; |
| 5634 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5635 | LPFC_IDX_RSRC_RDY); |
| 5636 | return rc; |
| 5637 | } else { |
| 5638 | /* |
| 5639 | * The port does not support resource extents. The XRI, VPI, |
| 5640 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 5641 | * Just allocate the bitmasks and provision the resource id |
| 5642 | * arrays. If a port reset is active, the resources don't |
| 5643 | * need any action - just exit. |
| 5644 | */ |
| 5645 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5646 | LPFC_IDX_RSRC_RDY) { |
| 5647 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5648 | lpfc_sli4_remove_rpis(phba); |
| 5649 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5650 | /* RPIs. */ |
| 5651 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5652 | if (count <= 0) { |
| 5653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5654 | "3279 Invalid provisioning of " |
| 5655 | "rpi:%d\n", count); |
| 5656 | rc = -EINVAL; |
| 5657 | goto err_exit; |
| 5658 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5659 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 5660 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5661 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5662 | sizeof(unsigned long), |
| 5663 | GFP_KERNEL); |
| 5664 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5665 | rc = -ENOMEM; |
| 5666 | goto err_exit; |
| 5667 | } |
| 5668 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 5669 | sizeof(uint16_t), |
| 5670 | GFP_KERNEL); |
| 5671 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5672 | rc = -ENOMEM; |
| 5673 | goto free_rpi_bmask; |
| 5674 | } |
| 5675 | |
| 5676 | for (i = 0; i < count; i++) |
| 5677 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 5678 | |
| 5679 | /* VPIs. */ |
| 5680 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5681 | if (count <= 0) { |
| 5682 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5683 | "3280 Invalid provisioning of " |
| 5684 | "vpi:%d\n", count); |
| 5685 | rc = -EINVAL; |
| 5686 | goto free_rpi_ids; |
| 5687 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5688 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 5689 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5690 | phba->vpi_bmask = kzalloc(longs * |
| 5691 | sizeof(unsigned long), |
| 5692 | GFP_KERNEL); |
| 5693 | if (unlikely(!phba->vpi_bmask)) { |
| 5694 | rc = -ENOMEM; |
| 5695 | goto free_rpi_ids; |
| 5696 | } |
| 5697 | phba->vpi_ids = kzalloc(count * |
| 5698 | sizeof(uint16_t), |
| 5699 | GFP_KERNEL); |
| 5700 | if (unlikely(!phba->vpi_ids)) { |
| 5701 | rc = -ENOMEM; |
| 5702 | goto free_vpi_bmask; |
| 5703 | } |
| 5704 | |
| 5705 | for (i = 0; i < count; i++) |
| 5706 | phba->vpi_ids[i] = base + i; |
| 5707 | |
| 5708 | /* XRIs. */ |
| 5709 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5710 | if (count <= 0) { |
| 5711 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5712 | "3281 Invalid provisioning of " |
| 5713 | "xri:%d\n", count); |
| 5714 | rc = -EINVAL; |
| 5715 | goto free_vpi_ids; |
| 5716 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5717 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 5718 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5719 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5720 | sizeof(unsigned long), |
| 5721 | GFP_KERNEL); |
| 5722 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5723 | rc = -ENOMEM; |
| 5724 | goto free_vpi_ids; |
| 5725 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 5726 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5727 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 5728 | sizeof(uint16_t), |
| 5729 | GFP_KERNEL); |
| 5730 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5731 | rc = -ENOMEM; |
| 5732 | goto free_xri_bmask; |
| 5733 | } |
| 5734 | |
| 5735 | for (i = 0; i < count; i++) |
| 5736 | phba->sli4_hba.xri_ids[i] = base + i; |
| 5737 | |
| 5738 | /* VFIs. */ |
| 5739 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 5740 | if (count <= 0) { |
| 5741 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5742 | "3282 Invalid provisioning of " |
| 5743 | "vfi:%d\n", count); |
| 5744 | rc = -EINVAL; |
| 5745 | goto free_xri_ids; |
| 5746 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5747 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 5748 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5749 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5750 | sizeof(unsigned long), |
| 5751 | GFP_KERNEL); |
| 5752 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5753 | rc = -ENOMEM; |
| 5754 | goto free_xri_ids; |
| 5755 | } |
| 5756 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 5757 | sizeof(uint16_t), |
| 5758 | GFP_KERNEL); |
| 5759 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5760 | rc = -ENOMEM; |
| 5761 | goto free_vfi_bmask; |
| 5762 | } |
| 5763 | |
| 5764 | for (i = 0; i < count; i++) |
| 5765 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 5766 | |
| 5767 | /* |
| 5768 | * Mark all resources ready. An HBA reset doesn't need |
| 5769 | * to reset the initialization. |
| 5770 | */ |
| 5771 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 5772 | LPFC_IDX_RSRC_RDY); |
| 5773 | return 0; |
| 5774 | } |
| 5775 | |
| 5776 | free_vfi_bmask: |
| 5777 | kfree(phba->sli4_hba.vfi_bmask); |
| 5778 | free_xri_ids: |
| 5779 | kfree(phba->sli4_hba.xri_ids); |
| 5780 | free_xri_bmask: |
| 5781 | kfree(phba->sli4_hba.xri_bmask); |
| 5782 | free_vpi_ids: |
| 5783 | kfree(phba->vpi_ids); |
| 5784 | free_vpi_bmask: |
| 5785 | kfree(phba->vpi_bmask); |
| 5786 | free_rpi_ids: |
| 5787 | kfree(phba->sli4_hba.rpi_ids); |
| 5788 | free_rpi_bmask: |
| 5789 | kfree(phba->sli4_hba.rpi_bmask); |
| 5790 | err_exit: |
| 5791 | return rc; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 5796 | * @phba: Pointer to HBA context object. |
| 5797 | * |
| 5798 | * This function allocates the number of elements for the specified |
| 5799 | * resource type. |
| 5800 | **/ |
| 5801 | int |
| 5802 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 5803 | { |
| 5804 | if (phba->sli4_hba.extents_in_use) { |
| 5805 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5806 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 5807 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 5808 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5809 | } else { |
| 5810 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5811 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5812 | kfree(phba->vpi_ids); |
| 5813 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5814 | kfree(phba->sli4_hba.xri_bmask); |
| 5815 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5816 | kfree(phba->sli4_hba.vfi_bmask); |
| 5817 | kfree(phba->sli4_hba.vfi_ids); |
| 5818 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5819 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5820 | } |
| 5821 | |
| 5822 | return 0; |
| 5823 | } |
| 5824 | |
| 5825 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5826 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 5827 | * @phba: Pointer to HBA context object. |
| 5828 | * @type: The resource extent type. |
| 5829 | * @extnt_count: buffer to hold port extent count response |
| 5830 | * @extnt_size: buffer to hold port extent size response. |
| 5831 | * |
| 5832 | * This function calls the port to read the host allocated extents |
| 5833 | * for a particular type. |
| 5834 | **/ |
| 5835 | int |
| 5836 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 5837 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 5838 | { |
| 5839 | bool emb; |
| 5840 | int rc = 0; |
| 5841 | uint16_t curr_blks = 0; |
| 5842 | uint32_t req_len, emb_len; |
| 5843 | uint32_t alloc_len, mbox_tmo; |
| 5844 | struct list_head *blk_list_head; |
| 5845 | struct lpfc_rsrc_blks *rsrc_blk; |
| 5846 | LPFC_MBOXQ_t *mbox; |
| 5847 | void *virtaddr = NULL; |
| 5848 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5849 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5850 | union lpfc_sli4_cfg_shdr *shdr; |
| 5851 | |
| 5852 | switch (type) { |
| 5853 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5854 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 5855 | break; |
| 5856 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5857 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5858 | break; |
| 5859 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5860 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5861 | break; |
| 5862 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5863 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5864 | break; |
| 5865 | default: |
| 5866 | return -EIO; |
| 5867 | } |
| 5868 | |
| 5869 | /* Count the number of extents currently allocatd for this type. */ |
| 5870 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 5871 | if (curr_blks == 0) { |
| 5872 | /* |
| 5873 | * The GET_ALLOCATED mailbox does not return the size, |
| 5874 | * just the count. The size should be just the size |
| 5875 | * stored in the current allocated block and all sizes |
| 5876 | * for an extent type are the same so set the return |
| 5877 | * value now. |
| 5878 | */ |
| 5879 | *extnt_size = rsrc_blk->rsrc_size; |
| 5880 | } |
| 5881 | curr_blks++; |
| 5882 | } |
| 5883 | |
| 5884 | /* Calculate the total requested length of the dma memory. */ |
| 5885 | req_len = curr_blks * sizeof(uint16_t); |
| 5886 | |
| 5887 | /* |
| 5888 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5889 | * accounts for extents-specific word. |
| 5890 | */ |
| 5891 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5892 | sizeof(uint32_t); |
| 5893 | |
| 5894 | /* |
| 5895 | * Presume the allocation and response will fit into an embedded |
| 5896 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5897 | */ |
| 5898 | emb = LPFC_SLI4_MBX_EMBED; |
| 5899 | req_len = emb_len; |
| 5900 | if (req_len > emb_len) { |
| 5901 | req_len = curr_blks * sizeof(uint16_t) + |
| 5902 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5903 | sizeof(uint32_t); |
| 5904 | emb = LPFC_SLI4_MBX_NEMBED; |
| 5905 | } |
| 5906 | |
| 5907 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5908 | if (!mbox) |
| 5909 | return -ENOMEM; |
| 5910 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 5911 | |
| 5912 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5913 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 5914 | req_len, emb); |
| 5915 | if (alloc_len < req_len) { |
| 5916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5917 | "2983 Allocated DMA memory size (x%x) is " |
| 5918 | "less than the requested DMA memory " |
| 5919 | "size (x%x)\n", alloc_len, req_len); |
| 5920 | rc = -ENOMEM; |
| 5921 | goto err_exit; |
| 5922 | } |
| 5923 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 5924 | if (unlikely(rc)) { |
| 5925 | rc = -EIO; |
| 5926 | goto err_exit; |
| 5927 | } |
| 5928 | |
| 5929 | if (!phba->sli4_hba.intr_enable) |
| 5930 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5931 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5932 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5933 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5934 | } |
| 5935 | |
| 5936 | if (unlikely(rc)) { |
| 5937 | rc = -EIO; |
| 5938 | goto err_exit; |
| 5939 | } |
| 5940 | |
| 5941 | /* |
| 5942 | * Figure out where the response is located. Then get local pointers |
| 5943 | * to the response data. The port does not guarantee to respond to |
| 5944 | * all extents counts request so update the local variable with the |
| 5945 | * allocated count from the port. |
| 5946 | */ |
| 5947 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5948 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5949 | shdr = &rsrc_ext->header.cfg_shdr; |
| 5950 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5951 | } else { |
| 5952 | virtaddr = mbox->sge_array->addr[0]; |
| 5953 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5954 | shdr = &n_rsrc->cfg_shdr; |
| 5955 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5956 | } |
| 5957 | |
| 5958 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 5959 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5960 | "2984 Failed to read allocated resources " |
| 5961 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 5962 | type, |
| 5963 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 5964 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 5965 | rc = -EIO; |
| 5966 | goto err_exit; |
| 5967 | } |
| 5968 | err_exit: |
| 5969 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5970 | return rc; |
| 5971 | } |
| 5972 | |
| 5973 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5974 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block |
| 5975 | * @phba: pointer to lpfc hba data structure. |
| 5976 | * |
| 5977 | * This routine walks the list of els buffers that have been allocated and |
| 5978 | * repost them to the port by using SGL block post. This is needed after a |
| 5979 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
| 5980 | * of els buffer sgls which contains contiguous xris and uses the non-embedded |
| 5981 | * SGL block post mailbox commands to post them to the port. For single els |
| 5982 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 5983 | * mailbox command for posting. |
| 5984 | * |
| 5985 | * Returns: 0 = success, non-zero failure. |
| 5986 | **/ |
| 5987 | static int |
| 5988 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) |
| 5989 | { |
| 5990 | struct lpfc_sglq *sglq_entry = NULL; |
| 5991 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 5992 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 5993 | 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] | 5994 | int last_xritag = NO_XRI; |
| 5995 | LIST_HEAD(prep_sgl_list); |
| 5996 | LIST_HEAD(blck_sgl_list); |
| 5997 | LIST_HEAD(allc_sgl_list); |
| 5998 | LIST_HEAD(post_sgl_list); |
| 5999 | LIST_HEAD(free_sgl_list); |
| 6000 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6001 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6002 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6003 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6004 | |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6005 | total_cnt = phba->sli4_hba.els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6006 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6007 | &allc_sgl_list, list) { |
| 6008 | list_del_init(&sglq_entry->list); |
| 6009 | block_cnt++; |
| 6010 | if ((last_xritag != NO_XRI) && |
| 6011 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6012 | /* a hole in xri block, form a sgl posting block */ |
| 6013 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6014 | post_cnt = block_cnt - 1; |
| 6015 | /* prepare list for next posting block */ |
| 6016 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6017 | block_cnt = 1; |
| 6018 | } else { |
| 6019 | /* prepare list for next posting block */ |
| 6020 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6021 | /* enough sgls for non-embed sgl mbox command */ |
| 6022 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6023 | list_splice_init(&prep_sgl_list, |
| 6024 | &blck_sgl_list); |
| 6025 | post_cnt = block_cnt; |
| 6026 | block_cnt = 0; |
| 6027 | } |
| 6028 | } |
| 6029 | num_posted++; |
| 6030 | |
| 6031 | /* keep track of last sgl's xritag */ |
| 6032 | last_xritag = sglq_entry->sli4_xritag; |
| 6033 | |
| 6034 | /* end of repost sgl list condition for els buffers */ |
| 6035 | if (num_posted == phba->sli4_hba.els_xri_cnt) { |
| 6036 | if (post_cnt == 0) { |
| 6037 | list_splice_init(&prep_sgl_list, |
| 6038 | &blck_sgl_list); |
| 6039 | post_cnt = block_cnt; |
| 6040 | } else if (block_cnt == 1) { |
| 6041 | status = lpfc_sli4_post_sgl(phba, |
| 6042 | sglq_entry->phys, 0, |
| 6043 | sglq_entry->sli4_xritag); |
| 6044 | if (!status) { |
| 6045 | /* successful, put sgl to posted list */ |
| 6046 | list_add_tail(&sglq_entry->list, |
| 6047 | &post_sgl_list); |
| 6048 | } else { |
| 6049 | /* Failure, put sgl to free list */ |
| 6050 | lpfc_printf_log(phba, KERN_WARNING, |
| 6051 | LOG_SLI, |
| 6052 | "3159 Failed to post els " |
| 6053 | "sgl, xritag:x%x\n", |
| 6054 | sglq_entry->sli4_xritag); |
| 6055 | list_add_tail(&sglq_entry->list, |
| 6056 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6057 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6058 | } |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | /* continue until a nembed page worth of sgls */ |
| 6063 | if (post_cnt == 0) |
| 6064 | continue; |
| 6065 | |
| 6066 | /* post the els buffer list sgls as a block */ |
| 6067 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, |
| 6068 | post_cnt); |
| 6069 | |
| 6070 | if (!status) { |
| 6071 | /* success, put sgl list to posted sgl list */ |
| 6072 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6073 | } else { |
| 6074 | /* Failure, put sgl list to free sgl list */ |
| 6075 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6076 | struct lpfc_sglq, |
| 6077 | list); |
| 6078 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6079 | "3160 Failed to post els sgl-list, " |
| 6080 | "xritag:x%x-x%x\n", |
| 6081 | sglq_entry_first->sli4_xritag, |
| 6082 | (sglq_entry_first->sli4_xritag + |
| 6083 | post_cnt - 1)); |
| 6084 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6085 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6086 | } |
| 6087 | |
| 6088 | /* don't reset xirtag due to hole in xri block */ |
| 6089 | if (block_cnt == 0) |
| 6090 | last_xritag = NO_XRI; |
| 6091 | |
| 6092 | /* reset els sgl post count for next round of posting */ |
| 6093 | post_cnt = 0; |
| 6094 | } |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6095 | /* update the number of XRIs posted for ELS */ |
| 6096 | phba->sli4_hba.els_xri_cnt = total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6097 | |
| 6098 | /* free the els sgls failed to post */ |
| 6099 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6100 | |
| 6101 | /* push els sgls posted to the availble list */ |
| 6102 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6103 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6104 | list_splice_init(&post_sgl_list, |
| 6105 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6106 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6107 | } else { |
| 6108 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6109 | "3161 Failure to post els sgl to port.\n"); |
| 6110 | return -EIO; |
| 6111 | } |
| 6112 | return 0; |
| 6113 | } |
| 6114 | |
| 6115 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6116 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function |
| 6117 | * @phba: Pointer to HBA context object. |
| 6118 | * |
| 6119 | * This function is the main SLI4 device intialization PCI function. This |
| 6120 | * function is called by the HBA intialization code, HBA reset code and |
| 6121 | * HBA error attention handler code. Caller is not required to hold any |
| 6122 | * locks. |
| 6123 | **/ |
| 6124 | int |
| 6125 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6126 | { |
| 6127 | int rc; |
| 6128 | LPFC_MBOXQ_t *mboxq; |
| 6129 | struct lpfc_mqe *mqe; |
| 6130 | uint8_t *vpd; |
| 6131 | uint32_t vpd_size; |
| 6132 | uint32_t ftr_rsp = 0; |
| 6133 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6134 | struct lpfc_vport *vport = phba->pport; |
| 6135 | struct lpfc_dmabuf *mp; |
| 6136 | |
| 6137 | /* Perform a PCI function reset to start from clean */ |
| 6138 | rc = lpfc_pci_function_reset(phba); |
| 6139 | if (unlikely(rc)) |
| 6140 | return -ENODEV; |
| 6141 | |
| 6142 | /* Check the HBA Host Status Register for readyness */ |
| 6143 | rc = lpfc_sli4_post_status_check(phba); |
| 6144 | if (unlikely(rc)) |
| 6145 | return -ENODEV; |
| 6146 | else { |
| 6147 | spin_lock_irq(&phba->hbalock); |
| 6148 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6149 | spin_unlock_irq(&phba->hbalock); |
| 6150 | } |
| 6151 | |
| 6152 | /* |
| 6153 | * Allocate a single mailbox container for initializing the |
| 6154 | * port. |
| 6155 | */ |
| 6156 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6157 | if (!mboxq) |
| 6158 | return -ENOMEM; |
| 6159 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6160 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6161 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6162 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6163 | if (!vpd) { |
| 6164 | rc = -ENOMEM; |
| 6165 | goto out_free_mbox; |
| 6166 | } |
| 6167 | |
| 6168 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6169 | if (unlikely(rc)) { |
| 6170 | kfree(vpd); |
| 6171 | goto out_free_mbox; |
| 6172 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6173 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6174 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6175 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
| 6176 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6177 | phba->hba_flag |= HBA_FCOE_MODE; |
| 6178 | else |
| 6179 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6180 | |
| 6181 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6182 | LPFC_DCBX_CEE_MODE) |
| 6183 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6184 | else |
| 6185 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6186 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6187 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6188 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6189 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6190 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6191 | "0376 READ_REV Error. SLI Level %d " |
| 6192 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6193 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6194 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6195 | kfree(vpd); |
| 6196 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6197 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6198 | |
| 6199 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6200 | * Continue initialization with default values even if driver failed |
| 6201 | * to read FCoE param config regions, only read parameters if the |
| 6202 | * board is FCoE |
| 6203 | */ |
| 6204 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6205 | lpfc_sli4_read_fcoe_params(phba)) |
| 6206 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6207 | "2570 Failed to read FCoE parameters\n"); |
| 6208 | |
| 6209 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6210 | * Retrieve sli4 device physical port name, failure of doing it |
| 6211 | * is considered as non-fatal. |
| 6212 | */ |
| 6213 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6214 | if (!rc) |
| 6215 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6216 | "3080 Successful retrieving SLI4 device " |
| 6217 | "physical port name: %s.\n", phba->Port); |
| 6218 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6219 | /* |
| 6220 | * Evaluate the read rev and vpd data. Populate the driver |
| 6221 | * state with the results. If this routine fails, the failure |
| 6222 | * is not fatal as the driver will use generic values. |
| 6223 | */ |
| 6224 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6225 | if (unlikely(!rc)) { |
| 6226 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6227 | "0377 Error %d parsing vpd. " |
| 6228 | "Using defaults.\n", rc); |
| 6229 | rc = 0; |
| 6230 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6231 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6232 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6233 | /* Save information as VPD data */ |
| 6234 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6235 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6236 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6237 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6238 | &mqe->un.read_rev); |
| 6239 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6240 | &mqe->un.read_rev); |
| 6241 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6242 | &mqe->un.read_rev); |
| 6243 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6244 | &mqe->un.read_rev); |
| 6245 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6246 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6247 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6248 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6249 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6250 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6251 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6252 | "(%d):0380 READ_REV Status x%x " |
| 6253 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6254 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6255 | bf_get(lpfc_mqe_status, mqe), |
| 6256 | phba->vpd.rev.opFwName, |
| 6257 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6258 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6259 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6260 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6261 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6262 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6263 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6264 | "3362 LUN queue depth changed from %d to %d\n", |
| 6265 | phba->pport->cfg_lun_queue_depth, rc); |
| 6266 | phba->pport->cfg_lun_queue_depth = rc; |
| 6267 | } |
| 6268 | |
| 6269 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6270 | /* |
| 6271 | * Discover the port's supported feature set and match it against the |
| 6272 | * hosts requests. |
| 6273 | */ |
| 6274 | lpfc_request_features(phba, mboxq); |
| 6275 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6276 | if (unlikely(rc)) { |
| 6277 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6278 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | /* |
| 6282 | * The port must support FCP initiator mode as this is the |
| 6283 | * only mode running in the host. |
| 6284 | */ |
| 6285 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6286 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6287 | "0378 No support for fcpi mode.\n"); |
| 6288 | ftr_rsp++; |
| 6289 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6290 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6291 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6292 | else |
| 6293 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6294 | /* |
| 6295 | * If the port cannot support the host's requested features |
| 6296 | * then turn off the global config parameters to disable the |
| 6297 | * feature in the driver. This is not a fatal error. |
| 6298 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6299 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6300 | if (phba->cfg_enable_bg) { |
| 6301 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6302 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6303 | else |
| 6304 | ftr_rsp++; |
| 6305 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6306 | |
| 6307 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6308 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6309 | ftr_rsp++; |
| 6310 | |
| 6311 | if (ftr_rsp) { |
| 6312 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6313 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6314 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6315 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6316 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6317 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6318 | phba->cfg_enable_bg = 0; |
| 6319 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6320 | phba->cfg_enable_npiv = 0; |
| 6321 | } |
| 6322 | |
| 6323 | /* These SLI3 features are assumed in SLI4 */ |
| 6324 | spin_lock_irq(&phba->hbalock); |
| 6325 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6326 | spin_unlock_irq(&phba->hbalock); |
| 6327 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6328 | /* |
| 6329 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6330 | * calls depends on these resources to complete port setup. |
| 6331 | */ |
| 6332 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6333 | if (rc) { |
| 6334 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6335 | "2920 Failed to alloc Resource IDs " |
| 6336 | "rc = x%x\n", rc); |
| 6337 | goto out_free_mbox; |
| 6338 | } |
| 6339 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6340 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6341 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6342 | if (rc) { |
| 6343 | phba->link_state = LPFC_HBA_ERROR; |
| 6344 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6345 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6346 | } |
| 6347 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6348 | mboxq->vport = vport; |
| 6349 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6350 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6351 | if (rc == MBX_SUCCESS) { |
| 6352 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6353 | rc = 0; |
| 6354 | } |
| 6355 | |
| 6356 | /* |
| 6357 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6358 | * it to the mbuf pool. |
| 6359 | */ |
| 6360 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6361 | kfree(mp); |
| 6362 | mboxq->context1 = NULL; |
| 6363 | if (unlikely(rc)) { |
| 6364 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6365 | "0382 READ_SPARAM command failed " |
| 6366 | "status %d, mbxStatus x%x\n", |
| 6367 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6368 | phba->link_state = LPFC_HBA_ERROR; |
| 6369 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6370 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6371 | } |
| 6372 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6373 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6374 | |
| 6375 | /* Update the fc_host data structures with new wwn. */ |
| 6376 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6377 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6378 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6379 | /* update host els and scsi xri-sgl sizes and mappings */ |
| 6380 | rc = lpfc_sli4_xri_sgl_update(phba); |
| 6381 | if (unlikely(rc)) { |
| 6382 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6383 | "1400 Failed to update xri-sgl size and " |
| 6384 | "mapping: %d\n", rc); |
| 6385 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6386 | } |
| 6387 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6388 | /* register the els sgl pool to the port */ |
| 6389 | rc = lpfc_sli4_repost_els_sgl_list(phba); |
| 6390 | if (unlikely(rc)) { |
| 6391 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6392 | "0582 Error %d during els sgl post " |
| 6393 | "operation\n", rc); |
| 6394 | rc = -ENODEV; |
| 6395 | goto out_free_mbox; |
| 6396 | } |
| 6397 | |
| 6398 | /* register the allocated scsi sgl pool to the port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6399 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6400 | if (unlikely(rc)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6401 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6402 | "0383 Error %d during scsi sgl post " |
| 6403 | "operation\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6404 | /* Some Scsi buffers were moved to the abort scsi list */ |
| 6405 | /* A pci function reset will repost them */ |
| 6406 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6407 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | /* Post the rpi header region to the device. */ |
| 6411 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 6412 | if (unlikely(rc)) { |
| 6413 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6414 | "0393 Error %d during rpi post operation\n", |
| 6415 | rc); |
| 6416 | rc = -ENODEV; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6417 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6418 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6419 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6420 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6421 | /* Create all the SLI4 queues */ |
| 6422 | rc = lpfc_sli4_queue_create(phba); |
| 6423 | if (rc) { |
| 6424 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6425 | "3089 Failed to allocate queues\n"); |
| 6426 | rc = -ENODEV; |
| 6427 | goto out_stop_timers; |
| 6428 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6429 | /* Set up all the queues to the device */ |
| 6430 | rc = lpfc_sli4_queue_setup(phba); |
| 6431 | if (unlikely(rc)) { |
| 6432 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6433 | "0381 Error %d during queue setup.\n ", rc); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6434 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | /* Arm the CQs and then EQs on device */ |
| 6438 | lpfc_sli4_arm_cqeq_intr(phba); |
| 6439 | |
| 6440 | /* Indicate device interrupt mode */ |
| 6441 | phba->sli4_hba.intr_enable = 1; |
| 6442 | |
| 6443 | /* Allow asynchronous mailbox command to go through */ |
| 6444 | spin_lock_irq(&phba->hbalock); |
| 6445 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 6446 | spin_unlock_irq(&phba->hbalock); |
| 6447 | |
| 6448 | /* Post receive buffers to the device */ |
| 6449 | lpfc_sli4_rb_setup(phba); |
| 6450 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6451 | /* Reset HBA FCF states after HBA reset */ |
| 6452 | phba->fcf.fcf_flag = 0; |
| 6453 | phba->fcf.current_rec.flag = 0; |
| 6454 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6455 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 6456 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6457 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6458 | |
| 6459 | /* Start heart beat timer */ |
| 6460 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6461 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6462 | phba->hb_outstanding = 0; |
| 6463 | phba->last_completion_time = jiffies; |
| 6464 | |
| 6465 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6466 | mod_timer(&phba->eratt_poll, |
| 6467 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6468 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6469 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 6470 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 6471 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 6472 | if (!rc) { |
| 6473 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6474 | "2829 This device supports " |
| 6475 | "Advanced Error Reporting (AER)\n"); |
| 6476 | spin_lock_irq(&phba->hbalock); |
| 6477 | phba->hba_flag |= HBA_AER_ENABLED; |
| 6478 | spin_unlock_irq(&phba->hbalock); |
| 6479 | } else { |
| 6480 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6481 | "2830 This device does not support " |
| 6482 | "Advanced Error Reporting (AER)\n"); |
| 6483 | phba->cfg_aer_support = 0; |
| 6484 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6485 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 6486 | } |
| 6487 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6488 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 6489 | /* |
| 6490 | * The FC Port needs to register FCFI (index 0) |
| 6491 | */ |
| 6492 | lpfc_reg_fcfi(phba, mboxq); |
| 6493 | mboxq->vport = phba->pport; |
| 6494 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6495 | if (rc != MBX_SUCCESS) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6496 | goto out_unset_queue; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6497 | rc = 0; |
| 6498 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 6499 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6500 | |
| 6501 | /* Check if the port is configured to be disabled */ |
| 6502 | lpfc_sli_read_link_ste(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6503 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6504 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6505 | /* |
| 6506 | * The port is ready, set the host's link state to LINK_DOWN |
| 6507 | * in preparation for link interrupts. |
| 6508 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6509 | spin_lock_irq(&phba->hbalock); |
| 6510 | phba->link_state = LPFC_LINK_DOWN; |
| 6511 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 6512 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 6513 | (phba->hba_flag & LINK_DISABLED)) { |
| 6514 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6515 | "3103 Adapter Link is disabled.\n"); |
| 6516 | lpfc_down_link(phba, mboxq); |
| 6517 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6518 | if (rc != MBX_SUCCESS) { |
| 6519 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 6520 | "3104 Adapter failed to issue " |
| 6521 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 6522 | goto out_unset_queue; |
| 6523 | } |
| 6524 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6525 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 6526 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 6527 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 6528 | if (rc) |
| 6529 | goto out_unset_queue; |
| 6530 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6531 | } |
| 6532 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6533 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6534 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6535 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6536 | lpfc_sli4_queue_unset(phba); |
| 6537 | out_destroy_queue: |
| 6538 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6539 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6540 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6541 | out_free_mbox: |
| 6542 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6543 | return rc; |
| 6544 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6545 | |
| 6546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6547 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6548 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6549 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6550 | * This is the callback function for mailbox timer. The mailbox |
| 6551 | * timer is armed when a new mailbox command is issued and the timer |
| 6552 | * is deleted when the mailbox complete. The function is called by |
| 6553 | * the kernel timer code when a mailbox does not complete within |
| 6554 | * expected time. This function wakes up the worker thread to |
| 6555 | * process the mailbox timeout and returns. All the processing is |
| 6556 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 6557 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6558 | void |
| 6559 | lpfc_mbox_timeout(unsigned long ptr) |
| 6560 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6561 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6562 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6563 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6564 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6565 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6566 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6567 | if (!tmo_posted) |
| 6568 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 6569 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 6570 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6571 | if (!tmo_posted) |
| 6572 | lpfc_worker_wake_up(phba); |
| 6573 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6574 | } |
| 6575 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6576 | /** |
| 6577 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 6578 | * are pending |
| 6579 | * @phba: Pointer to HBA context object. |
| 6580 | * |
| 6581 | * This function checks if any mailbox completions are present on the mailbox |
| 6582 | * completion queue. |
| 6583 | **/ |
| 6584 | bool |
| 6585 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 6586 | { |
| 6587 | |
| 6588 | uint32_t idx; |
| 6589 | struct lpfc_queue *mcq; |
| 6590 | struct lpfc_mcqe *mcqe; |
| 6591 | bool pending_completions = false; |
| 6592 | |
| 6593 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6594 | return false; |
| 6595 | |
| 6596 | /* Check for completions on mailbox completion queue */ |
| 6597 | |
| 6598 | mcq = phba->sli4_hba.mbx_cq; |
| 6599 | idx = mcq->hba_index; |
| 6600 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 6601 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 6602 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 6603 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 6604 | pending_completions = true; |
| 6605 | break; |
| 6606 | } |
| 6607 | idx = (idx + 1) % mcq->entry_count; |
| 6608 | if (mcq->hba_index == idx) |
| 6609 | break; |
| 6610 | } |
| 6611 | return pending_completions; |
| 6612 | |
| 6613 | } |
| 6614 | |
| 6615 | /** |
| 6616 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 6617 | * that were missed. |
| 6618 | * @phba: Pointer to HBA context object. |
| 6619 | * |
| 6620 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 6621 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 6622 | * checks to see if mbox completions are on the mailbox completion queue |
| 6623 | * and will process all the completions associated with the eq for the |
| 6624 | * mailbox completion queue. |
| 6625 | **/ |
| 6626 | bool |
| 6627 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 6628 | { |
| 6629 | |
| 6630 | uint32_t eqidx; |
| 6631 | struct lpfc_queue *fpeq = NULL; |
| 6632 | struct lpfc_eqe *eqe; |
| 6633 | bool mbox_pending; |
| 6634 | |
| 6635 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 6636 | return false; |
| 6637 | |
| 6638 | /* Find the eq associated with the mcq */ |
| 6639 | |
| 6640 | if (phba->sli4_hba.hba_eq) |
| 6641 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) |
| 6642 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 6643 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 6644 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 6645 | break; |
| 6646 | } |
| 6647 | if (!fpeq) |
| 6648 | return false; |
| 6649 | |
| 6650 | /* Turn off interrupts from this EQ */ |
| 6651 | |
| 6652 | lpfc_sli4_eq_clr_intr(fpeq); |
| 6653 | |
| 6654 | /* Check to see if a mbox completion is pending */ |
| 6655 | |
| 6656 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 6657 | |
| 6658 | /* |
| 6659 | * If a mbox completion is pending, process all the events on EQ |
| 6660 | * associated with the mbox completion queue (this could include |
| 6661 | * mailbox commands, async events, els commands, receive queue data |
| 6662 | * and fcp commands) |
| 6663 | */ |
| 6664 | |
| 6665 | if (mbox_pending) |
| 6666 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 6667 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 6668 | fpeq->EQ_processed++; |
| 6669 | } |
| 6670 | |
| 6671 | /* Always clear and re-arm the EQ */ |
| 6672 | |
| 6673 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 6674 | |
| 6675 | return mbox_pending; |
| 6676 | |
| 6677 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6678 | |
| 6679 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6680 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6681 | * @phba: Pointer to HBA context object. |
| 6682 | * |
| 6683 | * This function is called from worker thread when a mailbox command times out. |
| 6684 | * The caller is not required to hold any locks. This function will reset the |
| 6685 | * HBA and recover all the pending commands. |
| 6686 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6687 | void |
| 6688 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 6689 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6690 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6691 | MAILBOX_t *mb = &pmbox->u.mb; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6692 | struct lpfc_sli *psli = &phba->sli; |
| 6693 | struct lpfc_sli_ring *pring; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6694 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 6695 | /* If the mailbox completed, process the completion and return */ |
| 6696 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 6697 | return; |
| 6698 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6699 | /* Check the pmbox pointer first. There is a race condition |
| 6700 | * between the mbox timeout handler getting executed in the |
| 6701 | * worklist and the mailbox actually completing. When this |
| 6702 | * race condition occurs, the mbox_active will be NULL. |
| 6703 | */ |
| 6704 | spin_lock_irq(&phba->hbalock); |
| 6705 | if (pmbox == NULL) { |
| 6706 | lpfc_printf_log(phba, KERN_WARNING, |
| 6707 | LOG_MBOX | LOG_SLI, |
| 6708 | "0353 Active Mailbox cleared - mailbox timeout " |
| 6709 | "exiting\n"); |
| 6710 | spin_unlock_irq(&phba->hbalock); |
| 6711 | return; |
| 6712 | } |
| 6713 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6714 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6715 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6716 | "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] | 6717 | mb->mbxCommand, |
| 6718 | phba->pport->port_state, |
| 6719 | phba->sli.sli_flag, |
| 6720 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6721 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6722 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6723 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 6724 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6725 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6726 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6727 | spin_lock_irq(&phba->pport->work_port_lock); |
| 6728 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 6729 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 6730 | spin_lock_irq(&phba->hbalock); |
| 6731 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 6732 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6733 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6734 | |
| 6735 | pring = &psli->ring[psli->fcp_ring]; |
| 6736 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 6737 | |
| 6738 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 6739 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6740 | |
| 6741 | /* Reset the HBA device */ |
| 6742 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6743 | } |
| 6744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6745 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6746 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6747 | * @phba: Pointer to HBA context object. |
| 6748 | * @pmbox: Pointer to mailbox object. |
| 6749 | * @flag: Flag indicating how the mailbox need to be processed. |
| 6750 | * |
| 6751 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6752 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 6753 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6754 | * The mailbox command can be submitted in polling mode, in which case |
| 6755 | * this function will wait in a polling loop for the completion of the |
| 6756 | * mailbox. |
| 6757 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 6758 | * function will submit the command and returns immediately without waiting |
| 6759 | * for the mailbox completion. The no_wait is supported only when HBA |
| 6760 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 6761 | * The SLI interface allows only one mailbox pending at a time. If the |
| 6762 | * mailbox is issued in polling mode and there is already a mailbox |
| 6763 | * pending, then the function will return an error. If the mailbox is issued |
| 6764 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 6765 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 6766 | * The sli layer owns the mailbox object until the completion of mailbox |
| 6767 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 6768 | * return codes the caller owns the mailbox command after the return of |
| 6769 | * the function. |
| 6770 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6771 | static int |
| 6772 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 6773 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6774 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6775 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6776 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6777 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6778 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6779 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6780 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6781 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6782 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6783 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6784 | int processing_queue = 0; |
| 6785 | |
| 6786 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 6787 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 6788 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6789 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6790 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 6791 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6792 | return MBX_SUCCESS; |
| 6793 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6794 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6795 | pmbox = lpfc_mbox_get(phba); |
| 6796 | if (!pmbox) { |
| 6797 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6798 | return MBX_SUCCESS; |
| 6799 | } |
| 6800 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6801 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6802 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6803 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6804 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6805 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6806 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6807 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6808 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6809 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6810 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6811 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6812 | } |
| 6813 | } |
| 6814 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6815 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6816 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 6817 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6818 | goto out_not_finished; |
| 6819 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 6820 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6821 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 6822 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 6823 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6824 | goto out_not_finished; |
| 6825 | } |
| 6826 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6827 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6828 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6829 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6830 | status = MBX_SUCCESS; |
| 6831 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6832 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 6833 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6834 | |
| 6835 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6836 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6837 | "(%d):0311 Mailbox command x%x cannot " |
| 6838 | "issue Data: x%x x%x\n", |
| 6839 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6840 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6841 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 6842 | } |
| 6843 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6844 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6845 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 6846 | !(hc_copy & HC_MBINT_ENA)) { |
| 6847 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 6848 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6849 | "(%d):2528 Mailbox command x%x cannot " |
| 6850 | "issue Data: x%x x%x\n", |
| 6851 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6852 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6853 | goto out_not_finished; |
| 6854 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 6855 | } |
| 6856 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6857 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 6858 | /* Polling for a mbox command when another one is already active |
| 6859 | * is not allowed in SLI. Also, the driver must have established |
| 6860 | * SLI2 mode to queue and process multiple mbox commands. |
| 6861 | */ |
| 6862 | |
| 6863 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6864 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6865 | |
| 6866 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6867 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6868 | "(%d):2529 Mailbox command x%x " |
| 6869 | "cannot issue Data: x%x x%x\n", |
| 6870 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6871 | pmbox->u.mb.mbxCommand, |
| 6872 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6873 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6874 | } |
| 6875 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6876 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6877 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6878 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6879 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6880 | "(%d):2530 Mailbox command x%x " |
| 6881 | "cannot issue Data: x%x x%x\n", |
| 6882 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6883 | pmbox->u.mb.mbxCommand, |
| 6884 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6885 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6886 | } |
| 6887 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6888 | /* Another mailbox command is still being processed, queue this |
| 6889 | * command to be processed later. |
| 6890 | */ |
| 6891 | lpfc_mbox_put(phba, pmbox); |
| 6892 | |
| 6893 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6894 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6895 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6896 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6897 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6898 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6899 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6900 | |
| 6901 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6902 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6903 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6904 | if (pmbox->vport) { |
| 6905 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6906 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6907 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6908 | (uint32_t)mbx->mbxCommand, |
| 6909 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6910 | } |
| 6911 | else { |
| 6912 | lpfc_debugfs_disc_trc(phba->pport, |
| 6913 | LPFC_DISC_TRC_MBOX, |
| 6914 | "MBOX Bsy: 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 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6919 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6920 | } |
| 6921 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6922 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 6923 | |
| 6924 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 6925 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6926 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6927 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6928 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6929 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6930 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6931 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6932 | "(%d):2531 Mailbox command x%x " |
| 6933 | "cannot issue Data: x%x x%x\n", |
| 6934 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 6935 | pmbox->u.mb.mbxCommand, |
| 6936 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6937 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6938 | } |
| 6939 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6940 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 6941 | 1000); |
| 6942 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6946 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6947 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6948 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6949 | pmbox->vport ? pmbox->vport->vpi : 0, |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6950 | mbx->mbxCommand, phba->pport->port_state, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6951 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6952 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6953 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6954 | if (pmbox->vport) { |
| 6955 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 6956 | LPFC_DISC_TRC_MBOX_VPORT, |
| 6957 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6958 | (uint32_t)mbx->mbxCommand, |
| 6959 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6960 | } |
| 6961 | else { |
| 6962 | lpfc_debugfs_disc_trc(phba->pport, |
| 6963 | LPFC_DISC_TRC_MBOX, |
| 6964 | "MBOX Send: 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 | } |
| 6969 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6970 | psli->slistat.mbox_cmd++; |
| 6971 | evtctr = psli->slistat.mbox_event; |
| 6972 | |
| 6973 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6974 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6975 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6976 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6977 | /* Populate mbox extension offset word. */ |
| 6978 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6979 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6980 | = (uint8_t *)phba->mbox_ext |
| 6981 | - (uint8_t *)phba->mbox; |
| 6982 | } |
| 6983 | |
| 6984 | /* Copy the mailbox extension data */ |
| 6985 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 6986 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 6987 | (uint8_t *)phba->mbox_ext, |
| 6988 | pmbox->in_ext_byte_len); |
| 6989 | } |
| 6990 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6991 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6992 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6993 | /* Populate mbox extension offset word. */ |
| 6994 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 6995 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6996 | = MAILBOX_HBA_EXT_OFFSET; |
| 6997 | |
| 6998 | /* Copy the mailbox extension data */ |
| 6999 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7000 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7001 | MAILBOX_HBA_EXT_OFFSET, |
| 7002 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7003 | |
| 7004 | } |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7005 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7006 | /* copy command data into host mbox for cmpl */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7007 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7011 | word */ |
| 7012 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7013 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7014 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7015 | |
| 7016 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7017 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7018 | to_slim = phba->MBslimaddr; |
| 7019 | writel(ldata, to_slim); |
| 7020 | readl(to_slim); /* flush */ |
| 7021 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7022 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7023 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7024 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7029 | |
| 7030 | switch (flag) { |
| 7031 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7032 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7033 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7034 | /* Interrupt board to do it */ |
| 7035 | writel(CA_MBATT, phba->CAregaddr); |
| 7036 | readl(phba->CAregaddr); /* flush */ |
| 7037 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7038 | break; |
| 7039 | |
| 7040 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7041 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7042 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7043 | /* Interrupt board to do it */ |
| 7044 | writel(CA_MBATT, phba->CAregaddr); |
| 7045 | readl(phba->CAregaddr); /* flush */ |
| 7046 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7047 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7048 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7049 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7050 | word0 = le32_to_cpu(word0); |
| 7051 | } else { |
| 7052 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7053 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7054 | spin_unlock_irqrestore(&phba->hbalock, |
| 7055 | drvr_flag); |
| 7056 | goto out_not_finished; |
| 7057 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7061 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7062 | spin_unlock_irqrestore(&phba->hbalock, |
| 7063 | drvr_flag); |
| 7064 | goto out_not_finished; |
| 7065 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7066 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7067 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7068 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7069 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7070 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7071 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7072 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7073 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7074 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7075 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7076 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7077 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | /* Check if we took a mbox interrupt while we were |
| 7081 | polling */ |
| 7082 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7083 | && (evtctr != psli->slistat.mbox_event)) |
| 7084 | break; |
| 7085 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7086 | if (i++ > 10) { |
| 7087 | spin_unlock_irqrestore(&phba->hbalock, |
| 7088 | drvr_flag); |
| 7089 | msleep(1); |
| 7090 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7091 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7092 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7093 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7094 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7095 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7096 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7097 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7098 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7099 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7100 | /* Check real SLIM for any errors */ |
| 7101 | slimword0 = readl(phba->MBslimaddr); |
| 7102 | slimmb = (MAILBOX_t *) & slimword0; |
| 7103 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7104 | && slimmb->mbxStatus) { |
| 7105 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7106 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7107 | word0 = slimword0; |
| 7108 | } |
| 7109 | } |
| 7110 | } else { |
| 7111 | /* First copy command data */ |
| 7112 | word0 = readl(phba->MBslimaddr); |
| 7113 | } |
| 7114 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7115 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7116 | spin_unlock_irqrestore(&phba->hbalock, |
| 7117 | drvr_flag); |
| 7118 | goto out_not_finished; |
| 7119 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7120 | } |
| 7121 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7122 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7123 | /* copy results back to user */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7124 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7125 | /* Copy the mailbox extension data */ |
| 7126 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7127 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7128 | pmbox->context2, |
| 7129 | pmbox->out_ext_byte_len); |
| 7130 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7131 | } else { |
| 7132 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7133 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7134 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7135 | /* Copy the mailbox extension data */ |
| 7136 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7137 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7138 | phba->MBslimaddr + |
| 7139 | MAILBOX_HBA_EXT_OFFSET, |
| 7140 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | writel(HA_MBATT, phba->HAregaddr); |
| 7145 | readl(phba->HAregaddr); /* flush */ |
| 7146 | |
| 7147 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7148 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7149 | } |
| 7150 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7151 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7152 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7153 | |
| 7154 | out_not_finished: |
| 7155 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7156 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7157 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7158 | } |
| 7159 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | } |
| 7161 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7162 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7163 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7164 | * @phba: Pointer to HBA context object. |
| 7165 | * |
| 7166 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7167 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7168 | * possible outstanding mailbox command before return. |
| 7169 | * |
| 7170 | * Returns: |
| 7171 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7172 | * the outstanding mailbox command timed out. |
| 7173 | **/ |
| 7174 | static int |
| 7175 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7176 | { |
| 7177 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7178 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7179 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7180 | |
| 7181 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7182 | spin_lock_irq(&phba->hbalock); |
| 7183 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7184 | /* Determine how long we might wait for the active mailbox |
| 7185 | * command to be gracefully completed by firmware. |
| 7186 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7187 | if (phba->sli.mbox_active) |
| 7188 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7189 | phba->sli.mbox_active) * |
| 7190 | 1000) + jiffies; |
| 7191 | spin_unlock_irq(&phba->hbalock); |
| 7192 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7193 | /* Make sure the mailbox is really active */ |
| 7194 | if (timeout) |
| 7195 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7196 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7197 | /* Wait for the outstnading mailbox command to complete */ |
| 7198 | while (phba->sli.mbox_active) { |
| 7199 | /* Check active mailbox complete status every 2ms */ |
| 7200 | msleep(2); |
| 7201 | if (time_after(jiffies, timeout)) { |
| 7202 | /* Timeout, marked the outstanding cmd not complete */ |
| 7203 | rc = 1; |
| 7204 | break; |
| 7205 | } |
| 7206 | } |
| 7207 | |
| 7208 | /* Can not cleanly block async mailbox command, fails it */ |
| 7209 | if (rc) { |
| 7210 | spin_lock_irq(&phba->hbalock); |
| 7211 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7212 | spin_unlock_irq(&phba->hbalock); |
| 7213 | } |
| 7214 | return rc; |
| 7215 | } |
| 7216 | |
| 7217 | /** |
| 7218 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7219 | * @phba: Pointer to HBA context object. |
| 7220 | * |
| 7221 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7222 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7223 | * that there is no outstanding mailbox command before resuming posting |
| 7224 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7225 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7226 | * mailbox command posting. |
| 7227 | **/ |
| 7228 | static void |
| 7229 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7230 | { |
| 7231 | struct lpfc_sli *psli = &phba->sli; |
| 7232 | |
| 7233 | spin_lock_irq(&phba->hbalock); |
| 7234 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7235 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7236 | spin_unlock_irq(&phba->hbalock); |
| 7237 | return; |
| 7238 | } |
| 7239 | |
| 7240 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7241 | * successful or timeout, after timing-out the outstanding mailbox |
| 7242 | * command shall always be removed, so just unblock posting async |
| 7243 | * mailbox command and resume |
| 7244 | */ |
| 7245 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7246 | spin_unlock_irq(&phba->hbalock); |
| 7247 | |
| 7248 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7249 | lpfc_worker_wake_up(phba); |
| 7250 | } |
| 7251 | |
| 7252 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7253 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7254 | * @phba: Pointer to HBA context object. |
| 7255 | * @mboxq: Pointer to mailbox object. |
| 7256 | * |
| 7257 | * The function waits for the bootstrap mailbox register ready bit from |
| 7258 | * port for twice the regular mailbox command timeout value. |
| 7259 | * |
| 7260 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7261 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7262 | **/ |
| 7263 | static int |
| 7264 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7265 | { |
| 7266 | uint32_t db_ready; |
| 7267 | unsigned long timeout; |
| 7268 | struct lpfc_register bmbx_reg; |
| 7269 | |
| 7270 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7271 | * 1000) + jiffies; |
| 7272 | |
| 7273 | do { |
| 7274 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7275 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7276 | if (!db_ready) |
| 7277 | msleep(2); |
| 7278 | |
| 7279 | if (time_after(jiffies, timeout)) |
| 7280 | return MBXERR_ERROR; |
| 7281 | } while (!db_ready); |
| 7282 | |
| 7283 | return 0; |
| 7284 | } |
| 7285 | |
| 7286 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7287 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7288 | * @phba: Pointer to HBA context object. |
| 7289 | * @mboxq: Pointer to mailbox object. |
| 7290 | * |
| 7291 | * The function posts a mailbox to the port. The mailbox is expected |
| 7292 | * to be comletely filled in and ready for the port to operate on it. |
| 7293 | * This routine executes a synchronous completion operation on the |
| 7294 | * mailbox by polling for its completion. |
| 7295 | * |
| 7296 | * The caller must not be holding any locks when calling this routine. |
| 7297 | * |
| 7298 | * Returns: |
| 7299 | * MBX_SUCCESS - mailbox posted successfully |
| 7300 | * Any of the MBX error values. |
| 7301 | **/ |
| 7302 | static int |
| 7303 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7304 | { |
| 7305 | int rc = MBX_SUCCESS; |
| 7306 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7307 | uint32_t mcqe_status; |
| 7308 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7309 | struct lpfc_sli *psli = &phba->sli; |
| 7310 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7311 | struct lpfc_bmbx_create *mbox_rgn; |
| 7312 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7313 | |
| 7314 | /* |
| 7315 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7316 | * at a time and there is no queueing provided. |
| 7317 | */ |
| 7318 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7319 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7320 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7321 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7322 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7323 | "cannot issue Data: x%x x%x\n", |
| 7324 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7325 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7326 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7327 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7328 | psli->sli_flag, MBX_POLL); |
| 7329 | return MBXERR_ERROR; |
| 7330 | } |
| 7331 | /* The server grabs the token and owns it until release */ |
| 7332 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7333 | phba->sli.mbox_active = mboxq; |
| 7334 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7335 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7336 | /* wait for bootstrap mbox register for readyness */ |
| 7337 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7338 | if (rc) |
| 7339 | goto exit; |
| 7340 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7341 | /* |
| 7342 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7343 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7344 | * the bmbx mailbox region. |
| 7345 | */ |
| 7346 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7347 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7348 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7349 | sizeof(struct lpfc_mqe)); |
| 7350 | |
| 7351 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7352 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7353 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7354 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7355 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7356 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7357 | if (rc) |
| 7358 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7359 | |
| 7360 | /* Post the low mailbox dma address to the port. */ |
| 7361 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7362 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7363 | /* wait for bootstrap mbox register for low address write done */ |
| 7364 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7365 | if (rc) |
| 7366 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7367 | |
| 7368 | /* |
| 7369 | * Read the CQ to ensure the mailbox has completed. |
| 7370 | * If so, update the mailbox status so that the upper layers |
| 7371 | * can complete the request normally. |
| 7372 | */ |
| 7373 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7374 | sizeof(struct lpfc_mqe)); |
| 7375 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7376 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7377 | sizeof(struct lpfc_mcqe)); |
| 7378 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7379 | /* |
| 7380 | * When the CQE status indicates a failure and the mailbox status |
| 7381 | * indicates success then copy the CQE status into the mailbox status |
| 7382 | * (and prefix it with x4000). |
| 7383 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7384 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7385 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7386 | bf_set(lpfc_mqe_status, mb, |
| 7387 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7388 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7389 | } else |
| 7390 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7391 | |
| 7392 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7393 | "(%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] | 7394 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 7395 | " 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] | 7396 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 7397 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7398 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7399 | bf_get(lpfc_mqe_status, mb), |
| 7400 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 7401 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 7402 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 7403 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 7404 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 7405 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 7406 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 7407 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 7408 | mboxq->mcqe.trailer); |
| 7409 | exit: |
| 7410 | /* We are holding the token, no needed for lock when release */ |
| 7411 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7412 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7413 | phba->sli.mbox_active = NULL; |
| 7414 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7415 | return rc; |
| 7416 | } |
| 7417 | |
| 7418 | /** |
| 7419 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 7420 | * @phba: Pointer to HBA context object. |
| 7421 | * @pmbox: Pointer to mailbox object. |
| 7422 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7423 | * |
| 7424 | * This function is called by discovery code and HBA management code to submit |
| 7425 | * a mailbox command to firmware with SLI-4 interface spec. |
| 7426 | * |
| 7427 | * Return codes the caller owns the mailbox command after the return of the |
| 7428 | * function. |
| 7429 | **/ |
| 7430 | static int |
| 7431 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 7432 | uint32_t flag) |
| 7433 | { |
| 7434 | struct lpfc_sli *psli = &phba->sli; |
| 7435 | unsigned long iflags; |
| 7436 | int rc; |
| 7437 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 7438 | /* dump from issue mailbox command if setup */ |
| 7439 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 7440 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7441 | rc = lpfc_mbox_dev_check(phba); |
| 7442 | if (unlikely(rc)) { |
| 7443 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7444 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7445 | "cannot issue Data: x%x x%x\n", |
| 7446 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7447 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7448 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7449 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7450 | psli->sli_flag, flag); |
| 7451 | goto out_not_finished; |
| 7452 | } |
| 7453 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7454 | /* Detect polling mode and jump to a handler */ |
| 7455 | if (!phba->sli4_hba.intr_enable) { |
| 7456 | if (flag == MBX_POLL) |
| 7457 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7458 | else |
| 7459 | rc = -EIO; |
| 7460 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7461 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7462 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7463 | "(x%x/x%x) failure: " |
| 7464 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7465 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7466 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7467 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7468 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7469 | mboxq), |
| 7470 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7471 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7472 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7473 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7474 | bf_get(lpfc_mcqe_ext_status, |
| 7475 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7476 | psli->sli_flag, flag); |
| 7477 | return rc; |
| 7478 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7479 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7480 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7481 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7482 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7483 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7484 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7485 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7486 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7487 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7488 | /* Try to block the asynchronous mailbox posting */ |
| 7489 | rc = lpfc_sli4_async_mbox_block(phba); |
| 7490 | if (!rc) { |
| 7491 | /* Successfully blocked, now issue sync mbox cmd */ |
| 7492 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 7493 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7494 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7495 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7496 | "(%d):2597 Sync Mailbox command " |
| 7497 | "x%x (x%x/x%x) failure: " |
| 7498 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 7499 | "Data: x%x x%x\n,", |
| 7500 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7501 | mboxq->u.mb.mbxCommand, |
| 7502 | lpfc_sli_config_mbox_subsys_get(phba, |
| 7503 | mboxq), |
| 7504 | lpfc_sli_config_mbox_opcode_get(phba, |
| 7505 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 7506 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 7507 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 7508 | bf_get(lpfc_mcqe_ext_status, |
| 7509 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7510 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7511 | /* Unblock the async mailbox posting afterward */ |
| 7512 | lpfc_sli4_async_mbox_unblock(phba); |
| 7513 | } |
| 7514 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | /* Now, interrupt mode asynchrous mailbox command */ |
| 7518 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 7519 | if (rc) { |
| 7520 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7521 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7522 | "cannot issue Data: x%x x%x\n", |
| 7523 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7524 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7525 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7526 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7527 | psli->sli_flag, flag); |
| 7528 | goto out_not_finished; |
| 7529 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7530 | |
| 7531 | /* Put the mailbox command to the driver internal FIFO */ |
| 7532 | psli->slistat.mbox_busy++; |
| 7533 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7534 | lpfc_mbox_put(phba, mboxq); |
| 7535 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7536 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7537 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7538 | "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] | 7539 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 7540 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7541 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7542 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7543 | phba->pport->port_state, |
| 7544 | psli->sli_flag, MBX_NOWAIT); |
| 7545 | /* Wake up worker thread to transport mailbox command from head */ |
| 7546 | lpfc_worker_wake_up(phba); |
| 7547 | |
| 7548 | return MBX_BUSY; |
| 7549 | |
| 7550 | out_not_finished: |
| 7551 | return MBX_NOT_FINISHED; |
| 7552 | } |
| 7553 | |
| 7554 | /** |
| 7555 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 7556 | * @phba: Pointer to HBA context object. |
| 7557 | * |
| 7558 | * This function is called by worker thread to send a mailbox command to |
| 7559 | * SLI4 HBA firmware. |
| 7560 | * |
| 7561 | **/ |
| 7562 | int |
| 7563 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 7564 | { |
| 7565 | struct lpfc_sli *psli = &phba->sli; |
| 7566 | LPFC_MBOXQ_t *mboxq; |
| 7567 | int rc = MBX_SUCCESS; |
| 7568 | unsigned long iflags; |
| 7569 | struct lpfc_mqe *mqe; |
| 7570 | uint32_t mbx_cmnd; |
| 7571 | |
| 7572 | /* Check interrupt mode before post async mailbox command */ |
| 7573 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 7574 | return MBX_NOT_FINISHED; |
| 7575 | |
| 7576 | /* Check for mailbox command service token */ |
| 7577 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7578 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7579 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7580 | return MBX_NOT_FINISHED; |
| 7581 | } |
| 7582 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7583 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7584 | return MBX_NOT_FINISHED; |
| 7585 | } |
| 7586 | if (unlikely(phba->sli.mbox_active)) { |
| 7587 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7588 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7589 | "0384 There is pending active mailbox cmd\n"); |
| 7590 | return MBX_NOT_FINISHED; |
| 7591 | } |
| 7592 | /* Take the mailbox command service token */ |
| 7593 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7594 | |
| 7595 | /* Get the next mailbox command from head of queue */ |
| 7596 | mboxq = lpfc_mbox_get(phba); |
| 7597 | |
| 7598 | /* If no more mailbox command waiting for post, we're done */ |
| 7599 | if (!mboxq) { |
| 7600 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7601 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7602 | return MBX_SUCCESS; |
| 7603 | } |
| 7604 | phba->sli.mbox_active = mboxq; |
| 7605 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7606 | |
| 7607 | /* Check device readiness for posting mailbox command */ |
| 7608 | rc = lpfc_mbox_dev_check(phba); |
| 7609 | if (unlikely(rc)) |
| 7610 | /* Driver clean routine will clean up pending mailbox */ |
| 7611 | goto out_not_finished; |
| 7612 | |
| 7613 | /* Prepare the mbox command to be posted */ |
| 7614 | mqe = &mboxq->u.mqe; |
| 7615 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 7616 | |
| 7617 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 7618 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7619 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7620 | |
| 7621 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7622 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7623 | "x%x x%x\n", |
| 7624 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7625 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7626 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7627 | phba->pport->port_state, psli->sli_flag); |
| 7628 | |
| 7629 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 7630 | if (mboxq->vport) { |
| 7631 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 7632 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7633 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 7634 | mbx_cmnd, mqe->un.mb_words[0], |
| 7635 | mqe->un.mb_words[1]); |
| 7636 | } else { |
| 7637 | lpfc_debugfs_disc_trc(phba->pport, |
| 7638 | LPFC_DISC_TRC_MBOX, |
| 7639 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 7640 | mbx_cmnd, mqe->un.mb_words[0], |
| 7641 | mqe->un.mb_words[1]); |
| 7642 | } |
| 7643 | } |
| 7644 | psli->slistat.mbox_cmd++; |
| 7645 | |
| 7646 | /* Post the mailbox command to the port */ |
| 7647 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 7648 | if (rc != MBX_SUCCESS) { |
| 7649 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7650 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7651 | "cannot issue Data: x%x x%x\n", |
| 7652 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7653 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7654 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7655 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7656 | psli->sli_flag, MBX_NOWAIT); |
| 7657 | goto out_not_finished; |
| 7658 | } |
| 7659 | |
| 7660 | return rc; |
| 7661 | |
| 7662 | out_not_finished: |
| 7663 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 7664 | if (phba->sli.mbox_active) { |
| 7665 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 7666 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 7667 | /* Release the token */ |
| 7668 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 7669 | phba->sli.mbox_active = NULL; |
| 7670 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7671 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7672 | |
| 7673 | return MBX_NOT_FINISHED; |
| 7674 | } |
| 7675 | |
| 7676 | /** |
| 7677 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 7678 | * @phba: Pointer to HBA context object. |
| 7679 | * @pmbox: Pointer to mailbox object. |
| 7680 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7681 | * |
| 7682 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 7683 | * the API jump table function pointer from the lpfc_hba struct. |
| 7684 | * |
| 7685 | * Return codes the caller owns the mailbox command after the return of the |
| 7686 | * function. |
| 7687 | **/ |
| 7688 | int |
| 7689 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 7690 | { |
| 7691 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 7692 | } |
| 7693 | |
| 7694 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7695 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7696 | * @phba: The hba struct for which this call is being executed. |
| 7697 | * @dev_grp: The HBA PCI-Device group number. |
| 7698 | * |
| 7699 | * This routine sets up the mbox interface API function jump table in @phba |
| 7700 | * struct. |
| 7701 | * Returns: 0 - success, -ENODEV - failure. |
| 7702 | **/ |
| 7703 | int |
| 7704 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7705 | { |
| 7706 | |
| 7707 | switch (dev_grp) { |
| 7708 | case LPFC_PCI_DEV_LP: |
| 7709 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 7710 | phba->lpfc_sli_handle_slow_ring_event = |
| 7711 | lpfc_sli_handle_slow_ring_event_s3; |
| 7712 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 7713 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 7714 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 7715 | break; |
| 7716 | case LPFC_PCI_DEV_OC: |
| 7717 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 7718 | phba->lpfc_sli_handle_slow_ring_event = |
| 7719 | lpfc_sli_handle_slow_ring_event_s4; |
| 7720 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 7721 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 7722 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 7723 | break; |
| 7724 | default: |
| 7725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7726 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 7727 | dev_grp); |
| 7728 | return -ENODEV; |
| 7729 | break; |
| 7730 | } |
| 7731 | return 0; |
| 7732 | } |
| 7733 | |
| 7734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7735 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7736 | * @phba: Pointer to HBA context object. |
| 7737 | * @pring: Pointer to driver SLI ring object. |
| 7738 | * @piocb: Pointer to address of newly added command iocb. |
| 7739 | * |
| 7740 | * This function is called with hbalock held to add a command |
| 7741 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 7742 | * to the ring. |
| 7743 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 7744 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7745 | __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] | 7746 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7747 | { |
| 7748 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 7749 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7750 | } |
| 7751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7753 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7754 | * @phba: Pointer to HBA context object. |
| 7755 | * @pring: Pointer to driver SLI ring object. |
| 7756 | * @piocb: Pointer to address of newly added command iocb. |
| 7757 | * |
| 7758 | * This function is called with hbalock held before a new |
| 7759 | * iocb is submitted to the firmware. This function checks |
| 7760 | * txq to flush the iocbs in txq to Firmware before |
| 7761 | * submitting new iocbs to the Firmware. |
| 7762 | * If there are iocbs in the txq which need to be submitted |
| 7763 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 7764 | * of the txq after dequeuing it from txq. |
| 7765 | * If there is no iocb in the txq then the function will return |
| 7766 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 7767 | * *piocb to find if there are more commands in the txq. |
| 7768 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7769 | static struct lpfc_iocbq * |
| 7770 | 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] | 7771 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7772 | { |
| 7773 | struct lpfc_iocbq * nextiocb; |
| 7774 | |
| 7775 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 7776 | if (!nextiocb) { |
| 7777 | nextiocb = *piocb; |
| 7778 | *piocb = NULL; |
| 7779 | } |
| 7780 | |
| 7781 | return nextiocb; |
| 7782 | } |
| 7783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7784 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7785 | * __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] | 7786 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7787 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7788 | * @piocb: Pointer to command iocb. |
| 7789 | * @flag: Flag indicating if this command can be put into txq. |
| 7790 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7791 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 7792 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 7793 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 7794 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 7795 | * this function allows only iocbs for posting buffers. This function finds |
| 7796 | * next available slot in the command ring and posts the command to the |
| 7797 | * available slot and writes the port attention register to request HBA start |
| 7798 | * processing new iocb. If there is no slot available in the ring and |
| 7799 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 7800 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7801 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7802 | * This function is called with hbalock held. The function will return success |
| 7803 | * after it successfully submit the iocb to firmware or after adding to the |
| 7804 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7805 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7806 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7807 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7808 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 7809 | { |
| 7810 | struct lpfc_iocbq *nextiocb; |
| 7811 | IOCB_t *iocb; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7812 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7813 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7814 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 7815 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 7816 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 7817 | lpfc_printf_log(phba, KERN_ERR, |
| 7818 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7819 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7820 | piocb->iocb.ulpCommand); |
| 7821 | dump_stack(); |
| 7822 | return IOCB_ERROR; |
| 7823 | } |
| 7824 | |
| 7825 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7826 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 7827 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 7828 | return IOCB_ERROR; |
| 7829 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7830 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7831 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 7832 | return IOCB_ERROR; |
| 7833 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7834 | /* |
| 7835 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 7836 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7837 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7838 | return IOCB_ERROR; |
| 7839 | |
| 7840 | /* |
| 7841 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7842 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7843 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 7844 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7845 | goto iocb_busy; |
| 7846 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7847 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7848 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7849 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7850 | * can be issued if the link is not up. |
| 7851 | */ |
| 7852 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7853 | case CMD_GEN_REQUEST64_CR: |
| 7854 | case CMD_GEN_REQUEST64_CX: |
| 7855 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 7856 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7857 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 7858 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 7859 | MENLO_TRANSPORT_TYPE)) |
| 7860 | |
| 7861 | goto iocb_busy; |
| 7862 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7863 | case CMD_QUE_RING_BUF_CN: |
| 7864 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7865 | /* |
| 7866 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 7867 | * completion, iocb_cmpl MUST be 0. |
| 7868 | */ |
| 7869 | if (piocb->iocb_cmpl) |
| 7870 | piocb->iocb_cmpl = NULL; |
| 7871 | /*FALLTHROUGH*/ |
| 7872 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 7873 | case CMD_CLOSE_XRI_CN: |
| 7874 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7875 | break; |
| 7876 | default: |
| 7877 | goto iocb_busy; |
| 7878 | } |
| 7879 | |
| 7880 | /* |
| 7881 | * For FCP commands, we must be in a state where we can process link |
| 7882 | * attention events. |
| 7883 | */ |
| 7884 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7885 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7886 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7887 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7888 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7889 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 7890 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 7891 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 7892 | |
| 7893 | if (iocb) |
| 7894 | lpfc_sli_update_ring(phba, pring); |
| 7895 | else |
| 7896 | lpfc_sli_update_full_ring(phba, pring); |
| 7897 | |
| 7898 | if (!piocb) |
| 7899 | return IOCB_SUCCESS; |
| 7900 | |
| 7901 | goto out_busy; |
| 7902 | |
| 7903 | iocb_busy: |
| 7904 | pring->stats.iocb_cmd_delay++; |
| 7905 | |
| 7906 | out_busy: |
| 7907 | |
| 7908 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7909 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7910 | return IOCB_SUCCESS; |
| 7911 | } |
| 7912 | |
| 7913 | return IOCB_BUSY; |
| 7914 | } |
| 7915 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7916 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7917 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 7918 | * @phba: Pointer to HBA context object. |
| 7919 | * @piocb: Pointer to command iocb. |
| 7920 | * @sglq: Pointer to the scatter gather queue object. |
| 7921 | * |
| 7922 | * This routine converts the bpl or bde that is in the IOCB |
| 7923 | * to a sgl list for the sli4 hardware. The physical address |
| 7924 | * of the bpl/bde is converted back to a virtual address. |
| 7925 | * If the IOCB contains a BPL then the list of BDE's is |
| 7926 | * converted to sli4_sge's. If the IOCB contains a single |
| 7927 | * BDE then it is converted to a single sli_sge. |
| 7928 | * The IOCB is still in cpu endianess so the contents of |
| 7929 | * the bpl can be used without byte swapping. |
| 7930 | * |
| 7931 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 7932 | **/ |
| 7933 | static uint16_t |
| 7934 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 7935 | struct lpfc_sglq *sglq) |
| 7936 | { |
| 7937 | uint16_t xritag = NO_XRI; |
| 7938 | struct ulp_bde64 *bpl = NULL; |
| 7939 | struct ulp_bde64 bde; |
| 7940 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7941 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7942 | IOCB_t *icmd; |
| 7943 | int numBdes = 0; |
| 7944 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7945 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 7946 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7947 | |
| 7948 | if (!piocbq || !sglq) |
| 7949 | return xritag; |
| 7950 | |
| 7951 | sgl = (struct sli4_sge *)sglq->sgl; |
| 7952 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7953 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 7954 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7955 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 7956 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 7957 | sizeof(struct ulp_bde64); |
| 7958 | /* The addrHigh and addrLow fields within the IOCB |
| 7959 | * have not been byteswapped yet so there is no |
| 7960 | * need to swap them back. |
| 7961 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7962 | if (piocbq->context3) |
| 7963 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 7964 | else |
| 7965 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7966 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7967 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7968 | if (!bpl) |
| 7969 | return xritag; |
| 7970 | |
| 7971 | for (i = 0; i < numBdes; i++) { |
| 7972 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7973 | sgl->addr_hi = bpl->addrHigh; |
| 7974 | sgl->addr_lo = bpl->addrLow; |
| 7975 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7976 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 7977 | if ((i+1) == numBdes) |
| 7978 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 7979 | else |
| 7980 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7981 | /* swap the size field back to the cpu so we |
| 7982 | * can assign it to the sgl. |
| 7983 | */ |
| 7984 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 7985 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 7986 | /* The offsets in the sgl need to be accumulated |
| 7987 | * separately for the request and reply lists. |
| 7988 | * The request is always first, the reply follows. |
| 7989 | */ |
| 7990 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 7991 | /* add up the reply sg entries */ |
| 7992 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 7993 | inbound++; |
| 7994 | /* first inbound? reset the offset */ |
| 7995 | if (inbound == 1) |
| 7996 | offset = 0; |
| 7997 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 7998 | bf_set(lpfc_sli4_sge_type, sgl, |
| 7999 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8000 | offset += bde.tus.f.bdeSize; |
| 8001 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8002 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8003 | bpl++; |
| 8004 | sgl++; |
| 8005 | } |
| 8006 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8007 | /* The addrHigh and addrLow fields of the BDE have not |
| 8008 | * been byteswapped yet so they need to be swapped |
| 8009 | * before putting them in the sgl. |
| 8010 | */ |
| 8011 | sgl->addr_hi = |
| 8012 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8013 | sgl->addr_lo = |
| 8014 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8015 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8016 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8017 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8018 | sgl->sge_len = |
| 8019 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8020 | } |
| 8021 | return sglq->sli4_xritag; |
| 8022 | } |
| 8023 | |
| 8024 | /** |
| 8025 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
| 8026 | * @phba: Pointer to HBA context object. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8027 | * |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 8028 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8029 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
| 8030 | * held. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8031 | * |
| 8032 | * Return: index into SLI4 fast-path FCP queue index. |
| 8033 | **/ |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8034 | static inline uint32_t |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8035 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8036 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8037 | struct lpfc_vector_map_info *cpup; |
| 8038 | int chann, cpu; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8039 | |
James Smart | 76f96b6 | 2013-12-17 20:29:01 -0500 | [diff] [blame] | 8040 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
| 8041 | && phba->cfg_fcp_io_channel > 1) { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8042 | cpu = smp_processor_id(); |
| 8043 | if (cpu < phba->sli4_hba.num_present_cpu) { |
| 8044 | cpup = phba->sli4_hba.cpu_map; |
| 8045 | cpup += cpu; |
| 8046 | return cpup->channel_id; |
| 8047 | } |
| 8048 | chann = cpu; |
| 8049 | } |
| 8050 | chann = atomic_add_return(1, &phba->fcp_qidx); |
| 8051 | chann = (chann % phba->cfg_fcp_io_channel); |
| 8052 | return chann; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8053 | } |
| 8054 | |
| 8055 | /** |
| 8056 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8057 | * @phba: Pointer to HBA context object. |
| 8058 | * @piocb: Pointer to command iocb. |
| 8059 | * @wqe: Pointer to the work queue entry. |
| 8060 | * |
| 8061 | * This routine converts the iocb command to its Work Queue Entry |
| 8062 | * equivalent. The wqe pointer should not have any fields set when |
| 8063 | * this routine is called because it will memcpy over them. |
| 8064 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8065 | * wqe. |
| 8066 | * |
| 8067 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8068 | **/ |
| 8069 | static int |
| 8070 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8071 | union lpfc_wqe *wqe) |
| 8072 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8073 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8074 | uint8_t ct = 0; |
| 8075 | uint32_t fip; |
| 8076 | uint32_t abort_tag; |
| 8077 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8078 | uint8_t cmnd; |
| 8079 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8080 | uint16_t abrt_iotag; |
| 8081 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8082 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8083 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8084 | int numBdes, i; |
| 8085 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8086 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8087 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8088 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8089 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8090 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8091 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8092 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8093 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8094 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8095 | command_type = ELS_COMMAND_FIP; |
| 8096 | else |
| 8097 | command_type = ELS_COMMAND_NON_FIP; |
| 8098 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8099 | /* Some of the fields are in the right position already */ |
| 8100 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
| 8101 | abort_tag = (uint32_t) iocbq->iotag; |
| 8102 | xritag = iocbq->sli4_xritag; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8103 | 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] | 8104 | /* words0-2 bpl convert bde */ |
| 8105 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8106 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8107 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8108 | bpl = (struct ulp_bde64 *) |
| 8109 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8110 | if (!bpl) |
| 8111 | return IOCB_ERROR; |
| 8112 | |
| 8113 | /* Should already be byte swapped. */ |
| 8114 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8115 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8116 | /* swap the size field back to the cpu so we |
| 8117 | * can assign it to the sgl. |
| 8118 | */ |
| 8119 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8120 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8121 | total_len = 0; |
| 8122 | for (i = 0; i < numBdes; i++) { |
| 8123 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8124 | total_len += bde.tus.f.bdeSize; |
| 8125 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8126 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8127 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8128 | |
| 8129 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8130 | cmnd = iocbq->iocb.ulpCommand; |
| 8131 | |
| 8132 | switch (iocbq->iocb.ulpCommand) { |
| 8133 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8134 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8135 | ndlp = iocbq->context_un.ndlp; |
| 8136 | else |
| 8137 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8138 | if (!iocbq->iocb.ulpLe) { |
| 8139 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8140 | "2007 Only Limited Edition cmd Format" |
| 8141 | " supported 0x%x\n", |
| 8142 | iocbq->iocb.ulpCommand); |
| 8143 | return IOCB_ERROR; |
| 8144 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8145 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8146 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8147 | /* Els_reguest64 has a TMO */ |
| 8148 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8149 | iocbq->iocb.ulpTimeout); |
| 8150 | /* Need a VF for word 4 set the vf bit*/ |
| 8151 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8152 | /* And a VFID for word 12 */ |
| 8153 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8154 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8155 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8156 | iocbq->iocb.ulpContext); |
| 8157 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8158 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8159 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8160 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8161 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8162 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8163 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8164 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8165 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8166 | &phba->sli4_hba.sli_intf); |
| 8167 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8168 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8169 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8170 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8171 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8172 | *pcmd == ELS_CMD_PLOGI)) { |
| 8173 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8174 | bf_set(els_req64_sid, &wqe->els_req, |
| 8175 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8176 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8177 | !(phba->fc_topology == |
| 8178 | LPFC_TOPOLOGY_LOOP)) |
| 8179 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8180 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8181 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8182 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8183 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8184 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8185 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8186 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8187 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8188 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8189 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8190 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8191 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8192 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8193 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8194 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8195 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8196 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8197 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8198 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8199 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8200 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8201 | iocbq->iocb.un.ulpWord[3]); |
| 8202 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8203 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8204 | /* The entire sequence is transmitted for this IOCB */ |
| 8205 | xmit_len = total_len; |
| 8206 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8207 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8208 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8209 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8210 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8211 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8212 | /* word4 relative_offset memcpy */ |
| 8213 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8214 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8215 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8216 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8217 | LPFC_WQE_IOD_WRITE); |
| 8218 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8219 | LPFC_WQE_LENLOC_WORD12); |
| 8220 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8221 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8222 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8223 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8224 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8225 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8226 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8227 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8228 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8229 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8230 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8231 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8232 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8233 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8234 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8235 | LPFC_WQE_LENLOC_WORD3); |
| 8236 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8237 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8238 | case CMD_FCP_IWRITE64_CR: |
| 8239 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8240 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8241 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8242 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8243 | xmit_len + sizeof(struct fcp_rsp)); |
| 8244 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8245 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8246 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8247 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8248 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8249 | iocbq->iocb.ulpFCP2Rcvy); |
| 8250 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8251 | /* Always open the exchange */ |
| 8252 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8253 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8254 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8255 | LPFC_WQE_LENLOC_WORD4); |
| 8256 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); |
| 8257 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8258 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8259 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8260 | case CMD_FCP_IREAD64_CR: |
| 8261 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8262 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8263 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8264 | xmit_len + sizeof(struct fcp_rsp)); |
| 8265 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8266 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8267 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8268 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8269 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8270 | iocbq->iocb.ulpFCP2Rcvy); |
| 8271 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8272 | /* Always open the exchange */ |
| 8273 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8274 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8275 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8276 | LPFC_WQE_LENLOC_WORD4); |
| 8277 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); |
| 8278 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8279 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8280 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8281 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8282 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8283 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8284 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8285 | xmit_len + sizeof(struct fcp_rsp)); |
| 8286 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8287 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8288 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8289 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8290 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8291 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
| 8292 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8293 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8294 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8295 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8296 | LPFC_WQE_LENLOC_NONE); |
| 8297 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8298 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8299 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8300 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8301 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8302 | /* For this command calculate the xmit length of the |
| 8303 | * request bde. |
| 8304 | */ |
| 8305 | xmit_len = 0; |
| 8306 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8307 | sizeof(struct ulp_bde64); |
| 8308 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8309 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8310 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 8311 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8312 | xmit_len += bde.tus.f.bdeSize; |
| 8313 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8314 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 8315 | wqe->gen_req.request_payload_len = xmit_len; |
| 8316 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 8317 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8318 | /* word6 context tag copied in memcpy */ |
| 8319 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 8320 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 8321 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8322 | "2015 Invalid CT %x command 0x%x\n", |
| 8323 | ct, iocbq->iocb.ulpCommand); |
| 8324 | return IOCB_ERROR; |
| 8325 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8326 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 8327 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 8328 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 8329 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 8330 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8331 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 8332 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8333 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8334 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8335 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8336 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8337 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8338 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8339 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8340 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 8341 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8342 | /* word4 */ |
| 8343 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8344 | /* word5 iocb=rsvd wge=did */ |
| 8345 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8346 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 8347 | |
| 8348 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8349 | &phba->sli4_hba.sli_intf); |
| 8350 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8351 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 8352 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8353 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 8354 | iocbq->vport->fc_myDID); |
| 8355 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 8356 | bf_set(wqe_els_did, |
| 8357 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 8358 | } |
| 8359 | } |
| 8360 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8361 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 8362 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8363 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 8364 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8365 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8366 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8367 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8368 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8369 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8370 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8371 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8372 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 8373 | LPFC_WQE_LENLOC_WORD3); |
| 8374 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8375 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 8376 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8377 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8378 | iocbq->context2)->virt); |
| 8379 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8380 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 8381 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8382 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8383 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 8384 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8385 | phba->vpi_ids[phba->pport->vpi]); |
| 8386 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8387 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8388 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8389 | case CMD_CLOSE_XRI_CN: |
| 8390 | case CMD_ABORT_XRI_CN: |
| 8391 | case CMD_ABORT_XRI_CX: |
| 8392 | /* words 0-2 memcpy should be 0 rserved */ |
| 8393 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8394 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 8395 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 8396 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 8397 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 8398 | } else |
| 8399 | fip = 0; |
| 8400 | |
| 8401 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8402 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8403 | * The link is down, or the command was ELS_FIP |
| 8404 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8405 | * on the wire. |
| 8406 | */ |
| 8407 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 8408 | else |
| 8409 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 8410 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8411 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 8412 | wqe->abort_cmd.rsrvd5 = 0; |
| 8413 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8414 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 8415 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8416 | /* |
| 8417 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 8418 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 8419 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8420 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 8421 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 8422 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 8423 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8424 | cmnd = CMD_ABORT_XRI_CX; |
| 8425 | command_type = OTHER_COMMAND; |
| 8426 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8427 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8428 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8429 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8430 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8431 | * we re-construct this WQE here based on information in |
| 8432 | * iocbq from scratch. |
| 8433 | */ |
| 8434 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8435 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8436 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8437 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 8438 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8439 | LPFC_ABTS_UNSOL_INT) { |
| 8440 | /* ABTS sent by initiator to CT exchange, the |
| 8441 | * RX_ID field will be filled with the newly |
| 8442 | * allocated responder XRI. |
| 8443 | */ |
| 8444 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 8445 | iocbq->sli4_xritag); |
| 8446 | } else { |
| 8447 | /* ABTS sent by responder to CT exchange, the |
| 8448 | * RX_ID field will be filled with the responder |
| 8449 | * RX_ID from ABTS. |
| 8450 | */ |
| 8451 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8452 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8453 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8454 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 8455 | 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] | 8456 | |
| 8457 | /* Use CT=VPI */ |
| 8458 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 8459 | ndlp->nlp_DID); |
| 8460 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 8461 | iocbq->iocb.ulpContext); |
| 8462 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8463 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8464 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8465 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 8466 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 8467 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8468 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 8469 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8470 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 8471 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 8472 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 8473 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 8474 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 8475 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 8476 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 8477 | } |
| 8478 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8479 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8480 | case CMD_XRI_ABORTED_CX: |
| 8481 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8482 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 8483 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 8484 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 8485 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 8486 | default: |
| 8487 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8488 | "2014 Invalid command 0x%x\n", |
| 8489 | iocbq->iocb.ulpCommand); |
| 8490 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8491 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8492 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8493 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 8494 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 8495 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 8496 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 8497 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 8498 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 8499 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 8500 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 8501 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8502 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 8503 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 8504 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 8505 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 8506 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 8507 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 8508 | 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] | 8509 | return 0; |
| 8510 | } |
| 8511 | |
| 8512 | /** |
| 8513 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 8514 | * @phba: Pointer to HBA context object. |
| 8515 | * @ring_number: SLI ring number to issue iocb on. |
| 8516 | * @piocb: Pointer to command iocb. |
| 8517 | * @flag: Flag indicating if this command can be put into txq. |
| 8518 | * |
| 8519 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 8520 | * an iocb command to an HBA with SLI-4 interface spec. |
| 8521 | * |
| 8522 | * This function is called with hbalock held. The function will return success |
| 8523 | * after it successfully submit the iocb to firmware or after adding to the |
| 8524 | * txq. |
| 8525 | **/ |
| 8526 | static int |
| 8527 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 8528 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8529 | { |
| 8530 | struct lpfc_sglq *sglq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8531 | union lpfc_wqe wqe; |
| 8532 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8533 | |
| 8534 | if (piocb->sli4_xritag == NO_XRI) { |
| 8535 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8536 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8537 | sglq = NULL; |
| 8538 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 8539 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8540 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8541 | __lpfc_sli_ringtx_put(phba, |
| 8542 | pring, piocb); |
| 8543 | return IOCB_SUCCESS; |
| 8544 | } else { |
| 8545 | return IOCB_BUSY; |
| 8546 | } |
| 8547 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8548 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8549 | if (!sglq) { |
| 8550 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 8551 | __lpfc_sli_ringtx_put(phba, |
| 8552 | pring, |
| 8553 | piocb); |
| 8554 | return IOCB_SUCCESS; |
| 8555 | } else |
| 8556 | return IOCB_BUSY; |
| 8557 | } |
| 8558 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8559 | } |
| 8560 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8561 | /* These IO's already have an XRI and a mapped sgl. */ |
| 8562 | sglq = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8563 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8564 | /* |
| 8565 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8566 | * sglq is on the active list |
| 8567 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 8568 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8569 | if (!sglq) |
| 8570 | return IOCB_ERROR; |
| 8571 | } |
| 8572 | |
| 8573 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8574 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8575 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8576 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8577 | return IOCB_ERROR; |
| 8578 | } |
| 8579 | |
| 8580 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
| 8581 | return IOCB_ERROR; |
| 8582 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 8583 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 8584 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8585 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8586 | return IOCB_ERROR; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8587 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
| 8588 | &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8589 | return IOCB_ERROR; |
| 8590 | } else { |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 8591 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 8592 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8593 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 8594 | return IOCB_ERROR; |
| 8595 | } |
| 8596 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 8597 | |
| 8598 | return 0; |
| 8599 | } |
| 8600 | |
| 8601 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8602 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 8603 | * |
| 8604 | * This routine wraps the actual lockless version for issusing IOCB function |
| 8605 | * pointer from the lpfc_hba struct. |
| 8606 | * |
| 8607 | * Return codes: |
| 8608 | * IOCB_ERROR - Error |
| 8609 | * IOCB_SUCCESS - Success |
| 8610 | * IOCB_BUSY - Busy |
| 8611 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8612 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8613 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 8614 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8615 | { |
| 8616 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8617 | } |
| 8618 | |
| 8619 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8620 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8621 | * @phba: The hba struct for which this call is being executed. |
| 8622 | * @dev_grp: The HBA PCI-Device group number. |
| 8623 | * |
| 8624 | * This routine sets up the SLI interface API function jump table in @phba |
| 8625 | * struct. |
| 8626 | * Returns: 0 - success, -ENODEV - failure. |
| 8627 | **/ |
| 8628 | int |
| 8629 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8630 | { |
| 8631 | |
| 8632 | switch (dev_grp) { |
| 8633 | case LPFC_PCI_DEV_LP: |
| 8634 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 8635 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 8636 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8637 | case LPFC_PCI_DEV_OC: |
| 8638 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 8639 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 8640 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8641 | default: |
| 8642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8643 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 8644 | dev_grp); |
| 8645 | return -ENODEV; |
| 8646 | break; |
| 8647 | } |
| 8648 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 8649 | return 0; |
| 8650 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8651 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8653 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8654 | * @phba: Pointer to HBA context object. |
| 8655 | * @pring: Pointer to driver SLI ring object. |
| 8656 | * @piocb: Pointer to command iocb. |
| 8657 | * @flag: Flag indicating if this command can be put into txq. |
| 8658 | * |
| 8659 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 8660 | * function. This function gets the hbalock and calls |
| 8661 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 8662 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 8663 | * functions which do not hold hbalock. |
| 8664 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8665 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8666 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8667 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8668 | { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8669 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8670 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8671 | struct lpfc_queue *fpeq; |
| 8672 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8673 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8674 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8675 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8676 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8677 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
| 8678 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
| 8679 | return IOCB_ERROR; |
| 8680 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
| 8681 | piocb->fcp_wqidx = idx; |
| 8682 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8683 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8684 | pring = &phba->sli.ring[ring_number]; |
| 8685 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8686 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8687 | flag); |
| 8688 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8689 | |
| 8690 | if (lpfc_fcp_look_ahead) { |
| 8691 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; |
| 8692 | |
| 8693 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
| 8694 | fcp_eq_in_use)) { |
| 8695 | |
| 8696 | /* Get associated EQ with this index */ |
| 8697 | fpeq = phba->sli4_hba.hba_eq[idx]; |
| 8698 | |
| 8699 | /* Turn off interrupts from this EQ */ |
| 8700 | lpfc_sli4_eq_clr_intr(fpeq); |
| 8701 | |
| 8702 | /* |
| 8703 | * Process all the events on FCP EQ |
| 8704 | */ |
| 8705 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 8706 | lpfc_sli4_hba_handle_eqe(phba, |
| 8707 | eqe, idx); |
| 8708 | fpeq->EQ_processed++; |
| 8709 | } |
| 8710 | |
| 8711 | /* Always clear and re-arm the EQ */ |
| 8712 | lpfc_sli4_eq_release(fpeq, |
| 8713 | LPFC_QUEUE_REARM); |
| 8714 | } |
| 8715 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 8716 | } |
| 8717 | } else { |
| 8718 | pring = &phba->sli.ring[ring_number]; |
| 8719 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 8720 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 8721 | flag); |
| 8722 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 8723 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8724 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8725 | } else { |
| 8726 | /* For now, SLI2/3 will still use hbalock */ |
| 8727 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8728 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 8729 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8730 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8731 | return rc; |
| 8732 | } |
| 8733 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8735 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8736 | * @phba: Pointer to HBA context object. |
| 8737 | * |
| 8738 | * This function is called while driver attaches with the |
| 8739 | * HBA to setup the extra ring. The extra ring is used |
| 8740 | * only when driver needs to support target mode functionality |
| 8741 | * or IP over FC functionalities. |
| 8742 | * |
| 8743 | * This function is called with no lock held. |
| 8744 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8745 | static int |
| 8746 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 8747 | { |
| 8748 | struct lpfc_sli *psli; |
| 8749 | struct lpfc_sli_ring *pring; |
| 8750 | |
| 8751 | psli = &phba->sli; |
| 8752 | |
| 8753 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8754 | |
| 8755 | /* Take some away from the FCP ring */ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8756 | pring = &psli->ring[psli->fcp_ring]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8757 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8758 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8759 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8760 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8761 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8762 | /* and give them to the extra ring */ |
| 8763 | pring = &psli->ring[psli->extra_ring]; |
| 8764 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8765 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8766 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8767 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8768 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8769 | |
| 8770 | /* Setup default profile for this ring */ |
| 8771 | pring->iotag_max = 4096; |
| 8772 | pring->num_mask = 1; |
| 8773 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8774 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 8775 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 8776 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 8777 | return 0; |
| 8778 | } |
| 8779 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8780 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 8781 | * @phba: Pointer to HBA context object. |
| 8782 | * @iocbq: Pointer to iocb object. |
| 8783 | * |
| 8784 | * The async_event handler calls this routine when it receives |
| 8785 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 8786 | * this event when an Abort Sequence request to an rport fails |
| 8787 | * twice in succession. The abort could be originated by the |
| 8788 | * driver or by the port. The ABTS could have been for an ELS |
| 8789 | * or FCP IO. The port only generates this event when an ABTS |
| 8790 | * fails to complete after one retry. |
| 8791 | */ |
| 8792 | static void |
| 8793 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 8794 | struct lpfc_iocbq *iocbq) |
| 8795 | { |
| 8796 | struct lpfc_nodelist *ndlp = NULL; |
| 8797 | uint16_t rpi = 0, vpi = 0; |
| 8798 | struct lpfc_vport *vport = NULL; |
| 8799 | |
| 8800 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 8801 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 8802 | rpi = iocbq->iocb.ulpContext; |
| 8803 | |
| 8804 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8805 | "3092 Port generated ABTS async event " |
| 8806 | "on vpi %d rpi %d status 0x%x\n", |
| 8807 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 8808 | |
| 8809 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 8810 | if (!vport) |
| 8811 | goto err_exit; |
| 8812 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 8813 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 8814 | goto err_exit; |
| 8815 | |
| 8816 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 8817 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8818 | return; |
| 8819 | |
| 8820 | err_exit: |
| 8821 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8822 | "3095 Event Context not found, no " |
| 8823 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 8824 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 8825 | vpi, rpi); |
| 8826 | } |
| 8827 | |
| 8828 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 8829 | * @phba: pointer to HBA context object. |
| 8830 | * @ndlp: nodelist pointer for the impacted rport. |
| 8831 | * @axri: pointer to the wcqe containing the failed exchange. |
| 8832 | * |
| 8833 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 8834 | * port. The port generates this event when an abort exchange request to an |
| 8835 | * rport fails twice in succession with no reply. The abort could be originated |
| 8836 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 8837 | */ |
| 8838 | void |
| 8839 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 8840 | struct lpfc_nodelist *ndlp, |
| 8841 | struct sli4_wcqe_xri_aborted *axri) |
| 8842 | { |
| 8843 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8844 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8845 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8846 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8847 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8848 | "3115 Node Context not found, driver " |
| 8849 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8850 | return; |
| 8851 | } |
| 8852 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8853 | vport = ndlp->vport; |
| 8854 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8855 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8856 | "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] | 8857 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8858 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8859 | bf_get(lpfc_wcqe_xa_status, axri), |
| 8860 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8861 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8862 | /* |
| 8863 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 8864 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 8865 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 8866 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 8867 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 8868 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 8869 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8870 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 8871 | } |
| 8872 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8873 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8874 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8875 | * @phba: Pointer to HBA context object. |
| 8876 | * @pring: Pointer to driver SLI ring object. |
| 8877 | * @iocbq: Pointer to iocb object. |
| 8878 | * |
| 8879 | * This function is called by the slow ring event handler |
| 8880 | * function when there is an ASYNC event iocb in the ring. |
| 8881 | * This function is called with no lock held. |
| 8882 | * Currently this function handles only temperature related |
| 8883 | * ASYNC events. The function decodes the temperature sensor |
| 8884 | * event message and posts events for the management applications. |
| 8885 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8886 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8887 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 8888 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 8889 | { |
| 8890 | IOCB_t *icmd; |
| 8891 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8892 | struct temp_event temp_event_data; |
| 8893 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8894 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8895 | |
| 8896 | icmd = &iocbq->iocb; |
| 8897 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8898 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8899 | switch (evt_code) { |
| 8900 | case ASYNC_TEMP_WARN: |
| 8901 | case ASYNC_TEMP_SAFE: |
| 8902 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 8903 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 8904 | if (evt_code == ASYNC_TEMP_WARN) { |
| 8905 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 8906 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8907 | "0347 Adapter is very hot, please take " |
| 8908 | "corrective action. temperature : %d Celsius\n", |
| 8909 | (uint32_t) icmd->ulpContext); |
| 8910 | } else { |
| 8911 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 8912 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 8913 | "0340 Adapter temperature is OK now. " |
| 8914 | "temperature : %d Celsius\n", |
| 8915 | (uint32_t) icmd->ulpContext); |
| 8916 | } |
| 8917 | |
| 8918 | /* Send temperature change event to applications */ |
| 8919 | shost = lpfc_shost_from_vport(phba->pport); |
| 8920 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 8921 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 8922 | LPFC_NL_VENDOR_ID); |
| 8923 | break; |
| 8924 | case ASYNC_STATUS_CN: |
| 8925 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 8926 | break; |
| 8927 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8928 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8929 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8930 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 8931 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8932 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 8933 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 8934 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 8935 | "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] | 8936 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8937 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 8938 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 8939 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 8940 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 8941 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8942 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8943 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 8944 | } |
| 8945 | |
| 8946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8947 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8948 | * lpfc_sli_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8949 | * @phba: Pointer to HBA context object. |
| 8950 | * |
| 8951 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 8952 | * number of iocbs per ring and iotags. This function is |
| 8953 | * called while driver attach to the HBA and before the |
| 8954 | * interrupts are enabled. So there is no need for locking. |
| 8955 | * |
| 8956 | * This function always returns 0. |
| 8957 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8958 | int |
| 8959 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 8960 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8961 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8962 | struct lpfc_sli *psli = &phba->sli; |
| 8963 | struct lpfc_sli_ring *pring; |
| 8964 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8965 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| 8966 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8967 | psli->num_rings += phba->cfg_fcp_io_channel; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8968 | psli->sli_flag = 0; |
| 8969 | psli->fcp_ring = LPFC_FCP_RING; |
| 8970 | psli->next_ring = LPFC_FCP_NEXT_RING; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 8971 | psli->extra_ring = LPFC_EXTRA_RING; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8972 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8973 | psli->iocbq_lookup = NULL; |
| 8974 | psli->iocbq_lookup_len = 0; |
| 8975 | psli->last_iotag = 0; |
| 8976 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8977 | for (i = 0; i < psli->num_rings; i++) { |
| 8978 | pring = &psli->ring[i]; |
| 8979 | switch (i) { |
| 8980 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 8981 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8982 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 8983 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 8984 | pring->sli.sli3.numCiocb += |
| 8985 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 8986 | pring->sli.sli3.numRiocb += |
| 8987 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 8988 | pring->sli.sli3.numCiocb += |
| 8989 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 8990 | pring->sli.sli3.numRiocb += |
| 8991 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 8992 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8993 | SLI3_IOCB_CMD_SIZE : |
| 8994 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 8995 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8996 | SLI3_IOCB_RSP_SIZE : |
| 8997 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8998 | pring->iotag_ctr = 0; |
| 8999 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9000 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9001 | pring->fast_iotag = pring->iotag_max; |
| 9002 | pring->num_mask = 0; |
| 9003 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9004 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9005 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9006 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9007 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9008 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9009 | SLI3_IOCB_CMD_SIZE : |
| 9010 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9011 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9012 | SLI3_IOCB_RSP_SIZE : |
| 9013 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9014 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9015 | pring->num_mask = 0; |
| 9016 | break; |
| 9017 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9018 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9019 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9020 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9021 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9022 | SLI3_IOCB_CMD_SIZE : |
| 9023 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9024 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9025 | SLI3_IOCB_RSP_SIZE : |
| 9026 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9027 | pring->fast_iotag = 0; |
| 9028 | pring->iotag_ctr = 0; |
| 9029 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9030 | pring->lpfc_sli_rcv_async_status = |
| 9031 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9032 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9033 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9034 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9035 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9036 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9037 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9038 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9039 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9040 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9041 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9042 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9043 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9044 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9045 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9046 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9047 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9048 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9049 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9050 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9051 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9052 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9053 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9054 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9055 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9056 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9057 | break; |
| 9058 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9059 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9060 | pring->sli.sli3.sizeCiocb) + |
| 9061 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9062 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9063 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9064 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9065 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9066 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9067 | phba->brd_no, totiocbsize, |
| 9068 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9069 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9070 | if (phba->cfg_multi_ring_support == 2) |
| 9071 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9072 | |
| 9073 | return 0; |
| 9074 | } |
| 9075 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9076 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9077 | * lpfc_sli_queue_setup - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9078 | * @phba: Pointer to HBA context object. |
| 9079 | * |
| 9080 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each |
| 9081 | * ring. This function also initializes ring indices of each ring. |
| 9082 | * This function is called during the initialization of the SLI |
| 9083 | * interface of an HBA. |
| 9084 | * This function is called with no lock held and always returns |
| 9085 | * 1. |
| 9086 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9087 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9088 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9089 | { |
| 9090 | struct lpfc_sli *psli; |
| 9091 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9092 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9093 | |
| 9094 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9095 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9096 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9097 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9098 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9099 | for (i = 0; i < psli->num_rings; i++) { |
| 9100 | pring = &psli->ring[i]; |
| 9101 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9102 | pring->sli.sli3.next_cmdidx = 0; |
| 9103 | pring->sli.sli3.local_getidx = 0; |
| 9104 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9105 | INIT_LIST_HEAD(&pring->txq); |
| 9106 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9107 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9108 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9109 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9110 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9111 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9112 | spin_unlock_irq(&phba->hbalock); |
| 9113 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9114 | } |
| 9115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9116 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9117 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9118 | * @phba: Pointer to HBA context object. |
| 9119 | * |
| 9120 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9121 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9122 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9123 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9124 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9125 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9126 | * pending mailbox command queue from the various clients must be stopped; |
| 9127 | * either the HBA is in a state that it will never works on the outstanding |
| 9128 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9129 | * mailbox command has been completed. |
| 9130 | **/ |
| 9131 | static void |
| 9132 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 9133 | { |
| 9134 | LIST_HEAD(completions); |
| 9135 | struct lpfc_sli *psli = &phba->sli; |
| 9136 | LPFC_MBOXQ_t *pmb; |
| 9137 | unsigned long iflag; |
| 9138 | |
| 9139 | /* Flush all the mailbox commands in the mbox system */ |
| 9140 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 9141 | /* The pending mailbox command queue */ |
| 9142 | list_splice_init(&phba->sli.mboxq, &completions); |
| 9143 | /* The outstanding active mailbox command */ |
| 9144 | if (psli->mbox_active) { |
| 9145 | list_add_tail(&psli->mbox_active->list, &completions); |
| 9146 | psli->mbox_active = NULL; |
| 9147 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9148 | } |
| 9149 | /* The completed mailbox command queue */ |
| 9150 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 9151 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 9152 | |
| 9153 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 9154 | while (!list_empty(&completions)) { |
| 9155 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 9156 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9157 | if (pmb->mbox_cmpl) |
| 9158 | pmb->mbox_cmpl(phba, pmb); |
| 9159 | } |
| 9160 | } |
| 9161 | |
| 9162 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9163 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9164 | * @vport: Pointer to virtual port object. |
| 9165 | * |
| 9166 | * lpfc_sli_host_down is called to clean up the resources |
| 9167 | * associated with a vport before destroying virtual |
| 9168 | * port data structures. |
| 9169 | * This function does following operations: |
| 9170 | * - Free discovery resources associated with this virtual |
| 9171 | * port. |
| 9172 | * - Free iocbs associated with this virtual port in |
| 9173 | * the txq. |
| 9174 | * - Send abort for all iocb commands associated with this |
| 9175 | * vport in txcmplq. |
| 9176 | * |
| 9177 | * This function is called with no lock held and always returns 1. |
| 9178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9179 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9180 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 9181 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9182 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9183 | struct lpfc_hba *phba = vport->phba; |
| 9184 | struct lpfc_sli *psli = &phba->sli; |
| 9185 | struct lpfc_sli_ring *pring; |
| 9186 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9187 | int i; |
| 9188 | unsigned long flags = 0; |
| 9189 | uint16_t prev_pring_flag; |
| 9190 | |
| 9191 | lpfc_cleanup_discovery_resources(vport); |
| 9192 | |
| 9193 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9194 | for (i = 0; i < psli->num_rings; i++) { |
| 9195 | pring = &psli->ring[i]; |
| 9196 | prev_pring_flag = pring->flag; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9197 | /* Only slow rings */ |
| 9198 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9199 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9200 | /* Set the lpfc data pending flag */ |
| 9201 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9202 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9203 | /* |
| 9204 | * Error everything on the txq since these iocbs have not been |
| 9205 | * given to the FW yet. |
| 9206 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9207 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
| 9208 | if (iocb->vport != vport) |
| 9209 | continue; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9210 | list_move_tail(&iocb->list, &completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9211 | } |
| 9212 | |
| 9213 | /* Next issue ABTS for everything on the txcmplq */ |
| 9214 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, |
| 9215 | list) { |
| 9216 | if (iocb->vport != vport) |
| 9217 | continue; |
| 9218 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 9219 | } |
| 9220 | |
| 9221 | pring->flag = prev_pring_flag; |
| 9222 | } |
| 9223 | |
| 9224 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9225 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9226 | /* Cancel all the IOCBs from the completions list */ |
| 9227 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9228 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9229 | return 1; |
| 9230 | } |
| 9231 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9232 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9233 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9234 | * @phba: Pointer to HBA context object. |
| 9235 | * |
| 9236 | * This function cleans up all iocb, buffers, mailbox commands |
| 9237 | * while shutting down the HBA. This function is called with no |
| 9238 | * lock held and always returns 1. |
| 9239 | * This function does the following to cleanup driver resources: |
| 9240 | * - Free discovery resources for each virtual port |
| 9241 | * - Cleanup any pending fabric iocbs |
| 9242 | * - Iterate through the iocb txq and free each entry |
| 9243 | * in the list. |
| 9244 | * - Free up any buffer posted to the HBA |
| 9245 | * - Free mailbox commands in the mailbox queue. |
| 9246 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9247 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9248 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9249 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9250 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9251 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9252 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9253 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9254 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9255 | int i; |
| 9256 | |
| 9257 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9258 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9259 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9260 | lpfc_hba_down_prep(phba); |
| 9261 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9262 | lpfc_fabric_abort_hba(phba); |
| 9263 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9264 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9265 | for (i = 0; i < psli->num_rings; i++) { |
| 9266 | pring = &psli->ring[i]; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9267 | /* Only slow rings */ |
| 9268 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9269 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 9270 | /* Set the lpfc data pending flag */ |
| 9271 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 9272 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9273 | |
| 9274 | /* |
| 9275 | * Error everything on the txq since these iocbs have not been |
| 9276 | * given to the FW yet. |
| 9277 | */ |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9278 | list_splice_init(&pring->txq, &completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9279 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9280 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9281 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9282 | /* Cancel all the IOCBs from the completions list */ |
| 9283 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9284 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 9285 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 9286 | spin_lock_irqsave(&phba->hbalock, flags); |
| 9287 | list_splice_init(&phba->elsbuf, &completions); |
| 9288 | phba->elsbuf_cnt = 0; |
| 9289 | phba->elsbuf_prev_cnt = 0; |
| 9290 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 9291 | |
| 9292 | while (!list_empty(&completions)) { |
| 9293 | list_remove_head(&completions, buf_ptr, |
| 9294 | struct lpfc_dmabuf, list); |
| 9295 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 9296 | kfree(buf_ptr); |
| 9297 | } |
| 9298 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9299 | /* Return any active mbox cmds */ |
| 9300 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9301 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9302 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9303 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9304 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9305 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9306 | return 1; |
| 9307 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9308 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9310 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9311 | * @srcp: Source memory pointer. |
| 9312 | * @destp: Destination memory pointer. |
| 9313 | * @cnt: Number of words required to be copied. |
| 9314 | * |
| 9315 | * This function is used for copying data between driver memory |
| 9316 | * and the SLI memory. This function also changes the endianness |
| 9317 | * of each word if native endianness is different from SLI |
| 9318 | * endianness. This function can be called with or without |
| 9319 | * lock. |
| 9320 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9321 | void |
| 9322 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9323 | { |
| 9324 | uint32_t *src = srcp; |
| 9325 | uint32_t *dest = destp; |
| 9326 | uint32_t ldata; |
| 9327 | int i; |
| 9328 | |
| 9329 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 9330 | ldata = *src; |
| 9331 | ldata = le32_to_cpu(ldata); |
| 9332 | *dest = ldata; |
| 9333 | src++; |
| 9334 | dest++; |
| 9335 | } |
| 9336 | } |
| 9337 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9338 | |
| 9339 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 9340 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 9341 | * @srcp: Source memory pointer. |
| 9342 | * @destp: Destination memory pointer. |
| 9343 | * @cnt: Number of words required to be copied. |
| 9344 | * |
| 9345 | * This function is used for copying data between a data structure |
| 9346 | * with big endian representation to local endianness. |
| 9347 | * This function can be called with or without lock. |
| 9348 | **/ |
| 9349 | void |
| 9350 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 9351 | { |
| 9352 | uint32_t *src = srcp; |
| 9353 | uint32_t *dest = destp; |
| 9354 | uint32_t ldata; |
| 9355 | int i; |
| 9356 | |
| 9357 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 9358 | ldata = *src; |
| 9359 | ldata = be32_to_cpu(ldata); |
| 9360 | *dest = ldata; |
| 9361 | src++; |
| 9362 | dest++; |
| 9363 | } |
| 9364 | } |
| 9365 | |
| 9366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9367 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9368 | * @phba: Pointer to HBA context object. |
| 9369 | * @pring: Pointer to driver SLI ring object. |
| 9370 | * @mp: Pointer to driver buffer object. |
| 9371 | * |
| 9372 | * This function is called with no lock held. |
| 9373 | * It always return zero after adding the buffer to the postbufq |
| 9374 | * buffer list. |
| 9375 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9376 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9377 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9378 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9379 | { |
| 9380 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 9381 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9382 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9383 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9384 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9385 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9386 | return 0; |
| 9387 | } |
| 9388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9390 | * 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] | 9391 | * @phba: Pointer to HBA context object. |
| 9392 | * |
| 9393 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 9394 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 9395 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 9396 | * does not conflict with tags of buffer posted for unsolicited events. |
| 9397 | * The function returns the allocated tag. The function is called with |
| 9398 | * no locks held. |
| 9399 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9400 | uint32_t |
| 9401 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 9402 | { |
| 9403 | spin_lock_irq(&phba->hbalock); |
| 9404 | phba->buffer_tag_count++; |
| 9405 | /* |
| 9406 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 9407 | * a tag assigned by HBQ. |
| 9408 | */ |
| 9409 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 9410 | spin_unlock_irq(&phba->hbalock); |
| 9411 | return phba->buffer_tag_count; |
| 9412 | } |
| 9413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9415 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9416 | * @phba: Pointer to HBA context object. |
| 9417 | * @pring: Pointer to driver SLI ring object. |
| 9418 | * @tag: Buffer tag. |
| 9419 | * |
| 9420 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 9421 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 9422 | * iocb is posted to the response ring with the tag of the buffer. |
| 9423 | * This function searches the pring->postbufq list using the tag |
| 9424 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 9425 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 9426 | * buffer is returned to the caller else NULL is returned. |
| 9427 | * This function is called with no lock held. |
| 9428 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9429 | struct lpfc_dmabuf * |
| 9430 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9431 | uint32_t tag) |
| 9432 | { |
| 9433 | struct lpfc_dmabuf *mp, *next_mp; |
| 9434 | struct list_head *slp = &pring->postbufq; |
| 9435 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9436 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9437 | spin_lock_irq(&phba->hbalock); |
| 9438 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9439 | if (mp->buffer_tag == tag) { |
| 9440 | list_del_init(&mp->list); |
| 9441 | pring->postbufq_cnt--; |
| 9442 | spin_unlock_irq(&phba->hbalock); |
| 9443 | return mp; |
| 9444 | } |
| 9445 | } |
| 9446 | |
| 9447 | spin_unlock_irq(&phba->hbalock); |
| 9448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9449 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9450 | "ring %d Data x%lx x%p x%p x%x\n", |
| 9451 | pring->ringno, (unsigned long) tag, |
| 9452 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9453 | |
| 9454 | return NULL; |
| 9455 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
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 | * @phys: DMA address of the buffer. |
| 9462 | * |
| 9463 | * This function searches the buffer list using the dma_address |
| 9464 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 9465 | * corresponding to the dma_address. The function returns the |
| 9466 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 9467 | * This function is called by the ct and els unsolicited event |
| 9468 | * handlers to get the buffer associated with the unsolicited |
| 9469 | * event. |
| 9470 | * |
| 9471 | * This function is called with no lock held. |
| 9472 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9473 | struct lpfc_dmabuf * |
| 9474 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9475 | dma_addr_t phys) |
| 9476 | { |
| 9477 | struct lpfc_dmabuf *mp, *next_mp; |
| 9478 | struct list_head *slp = &pring->postbufq; |
| 9479 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9480 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9481 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9482 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 9483 | if (mp->phys == phys) { |
| 9484 | list_del_init(&mp->list); |
| 9485 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9486 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9487 | return mp; |
| 9488 | } |
| 9489 | } |
| 9490 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9491 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9492 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9493 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9494 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9495 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9496 | slp->next, slp->prev, pring->postbufq_cnt); |
| 9497 | return NULL; |
| 9498 | } |
| 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_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9502 | * @phba: Pointer to HBA context object. |
| 9503 | * @cmdiocb: Pointer to driver command iocb object. |
| 9504 | * @rspiocb: Pointer to driver response iocb object. |
| 9505 | * |
| 9506 | * This function is the completion handler for the abort iocbs for |
| 9507 | * ELS commands. This function is called from the ELS ring event |
| 9508 | * handler with no lock held. This function frees memory resources |
| 9509 | * associated with the abort iocb. |
| 9510 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9511 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9512 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9513 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9514 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9515 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9516 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9517 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9518 | |
| 9519 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9520 | |
| 9521 | /* |
| 9522 | * Assume that the port already completed and returned, or |
| 9523 | * will return the iocb. Just Log the message. |
| 9524 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9525 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 9526 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 9527 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9528 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9529 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 9530 | if (abort_iotag != 0 && |
| 9531 | abort_iotag <= phba->sli.last_iotag) |
| 9532 | abort_iocb = |
| 9533 | phba->sli.iocbq_lookup[abort_iotag]; |
| 9534 | } else |
| 9535 | /* For sli4 the abort_tag is the XRI, |
| 9536 | * so the abort routine puts the iotag of the iocb |
| 9537 | * being aborted in the context field of the abort |
| 9538 | * IOCB. |
| 9539 | */ |
| 9540 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9541 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9542 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 9543 | "0327 Cannot abort els iocb %p " |
| 9544 | "with tag %x context %x, abort status %x, " |
| 9545 | "abort code %x\n", |
| 9546 | abort_iocb, abort_iotag, abort_context, |
| 9547 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9548 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9549 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9550 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9551 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9552 | return; |
| 9553 | } |
| 9554 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9555 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9556 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9557 | * @phba: Pointer to HBA context object. |
| 9558 | * @cmdiocb: Pointer to driver command iocb object. |
| 9559 | * @rspiocb: Pointer to driver response iocb object. |
| 9560 | * |
| 9561 | * The function is called from SLI ring event handler with no |
| 9562 | * lock held. This function is the completion handler for ELS commands |
| 9563 | * which are aborted. The function frees memory resources used for |
| 9564 | * the aborted ELS commands. |
| 9565 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9566 | static void |
| 9567 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9568 | struct lpfc_iocbq *rspiocb) |
| 9569 | { |
| 9570 | IOCB_t *irsp = &rspiocb->iocb; |
| 9571 | |
| 9572 | /* ELS cmd tag <ulpIoTag> completes */ |
| 9573 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9574 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9575 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9576 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9577 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9578 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 9579 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 9580 | else |
| 9581 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9582 | return; |
| 9583 | } |
| 9584 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9585 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9586 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9587 | * @phba: Pointer to HBA context object. |
| 9588 | * @pring: Pointer to driver SLI ring object. |
| 9589 | * @cmdiocb: Pointer to driver command iocb object. |
| 9590 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9591 | * This function issues an abort iocb for the provided command iocb down to |
| 9592 | * the port. Other than the case the outstanding command iocb is an abort |
| 9593 | * request, this function issues abort out unconditionally. This function is |
| 9594 | * called with hbalock held. The function returns 0 when it fails due to |
| 9595 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9596 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9597 | static int |
| 9598 | 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] | 9599 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9600 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9601 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9602 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9603 | IOCB_t *icmd = NULL; |
| 9604 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9605 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9606 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9607 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9608 | /* |
| 9609 | * There are certain command types we don't want to abort. And we |
| 9610 | * don't want to abort commands that are already in the process of |
| 9611 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9612 | */ |
| 9613 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9614 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9615 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9616 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9617 | return 0; |
| 9618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9619 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9620 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9621 | if (abtsiocbp == NULL) |
| 9622 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9623 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9624 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9625 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9626 | */ |
| 9627 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9628 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9629 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9630 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9631 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9632 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9633 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9634 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 9635 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9636 | else |
| 9637 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9638 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9639 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9640 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9641 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9642 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9643 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 9644 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9645 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9646 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9647 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 9648 | else |
| 9649 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 9650 | |
| 9651 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 9652 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9653 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 9654 | "0339 Abort xri x%x, original iotag x%x, " |
| 9655 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9656 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9657 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9658 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9659 | |
| 9660 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9661 | /* Note: both hbalock and ring_lock need to be set here */ |
| 9662 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9663 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9664 | abtsiocbp, 0); |
| 9665 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 9666 | } else { |
| 9667 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 9668 | abtsiocbp, 0); |
| 9669 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9670 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 9671 | if (retval) |
| 9672 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9673 | |
| 9674 | /* |
| 9675 | * Caller to this routine should check for IOCB_ERROR |
| 9676 | * and handle it properly. This routine no longer removes |
| 9677 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 9678 | */ |
| 9679 | return retval; |
| 9680 | } |
| 9681 | |
| 9682 | /** |
| 9683 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 9684 | * @phba: Pointer to HBA context object. |
| 9685 | * @pring: Pointer to driver SLI ring object. |
| 9686 | * @cmdiocb: Pointer to driver command iocb object. |
| 9687 | * |
| 9688 | * This function issues an abort iocb for the provided command iocb. In case |
| 9689 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 9690 | * ring. Instead, the callback function shall be changed to those commands |
| 9691 | * so that nothing happens when them finishes. This function is called with |
| 9692 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 9693 | * request. |
| 9694 | **/ |
| 9695 | int |
| 9696 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 9697 | struct lpfc_iocbq *cmdiocb) |
| 9698 | { |
| 9699 | struct lpfc_vport *vport = cmdiocb->vport; |
| 9700 | int retval = IOCB_ERROR; |
| 9701 | IOCB_t *icmd = NULL; |
| 9702 | |
| 9703 | /* |
| 9704 | * There are certain command types we don't want to abort. And we |
| 9705 | * don't want to abort commands that are already in the process of |
| 9706 | * being aborted. |
| 9707 | */ |
| 9708 | icmd = &cmdiocb->iocb; |
| 9709 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 9710 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 9711 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 9712 | return 0; |
| 9713 | |
| 9714 | /* |
| 9715 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 9716 | * the callback so that nothing happens when it finishes. |
| 9717 | */ |
| 9718 | if ((vport->load_flag & FC_UNLOADING) && |
| 9719 | (pring->ringno == LPFC_ELS_RING)) { |
| 9720 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 9721 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9722 | else |
| 9723 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 9724 | goto abort_iotag_exit; |
| 9725 | } |
| 9726 | |
| 9727 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 9728 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 9729 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9730 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9731 | /* |
| 9732 | * Caller to this routine should check for IOCB_ERROR |
| 9733 | * and handle it properly. This routine no longer removes |
| 9734 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 9735 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9736 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9737 | } |
| 9738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9739 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9740 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring |
| 9741 | * @phba: Pointer to HBA context object. |
| 9742 | * @pring: Pointer to driver SLI ring object. |
| 9743 | * |
| 9744 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 9745 | * objects in txq. This function issues abort iocbs unconditionally for all |
| 9746 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed |
| 9747 | * to complete before the return of this function. The caller is not required |
| 9748 | * to hold any locks. |
| 9749 | **/ |
| 9750 | static void |
| 9751 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 9752 | { |
| 9753 | LIST_HEAD(completions); |
| 9754 | struct lpfc_iocbq *iocb, *next_iocb; |
| 9755 | |
| 9756 | if (pring->ringno == LPFC_ELS_RING) |
| 9757 | lpfc_fabric_abort_hba(phba); |
| 9758 | |
| 9759 | spin_lock_irq(&phba->hbalock); |
| 9760 | |
| 9761 | /* Take off all the iocbs on txq for cancelling */ |
| 9762 | list_splice_init(&pring->txq, &completions); |
| 9763 | pring->txq_cnt = 0; |
| 9764 | |
| 9765 | /* Next issue ABTS for everything on the txcmplq */ |
| 9766 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 9767 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); |
| 9768 | |
| 9769 | spin_unlock_irq(&phba->hbalock); |
| 9770 | |
| 9771 | /* Cancel all the IOCBs from the completions list */ |
| 9772 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 9773 | IOERR_SLI_ABORTED); |
| 9774 | } |
| 9775 | |
| 9776 | /** |
| 9777 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 9778 | * @phba: pointer to lpfc HBA data structure. |
| 9779 | * |
| 9780 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 9781 | **/ |
| 9782 | void |
| 9783 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 9784 | { |
| 9785 | struct lpfc_sli *psli = &phba->sli; |
| 9786 | struct lpfc_sli_ring *pring; |
| 9787 | int i; |
| 9788 | |
| 9789 | for (i = 0; i < psli->num_rings; i++) { |
| 9790 | pring = &psli->ring[i]; |
| 9791 | lpfc_sli_iocb_ring_abort(phba, pring); |
| 9792 | } |
| 9793 | } |
| 9794 | |
| 9795 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9796 | * 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] | 9797 | * @iocbq: Pointer to driver iocb object. |
| 9798 | * @vport: Pointer to driver virtual port object. |
| 9799 | * @tgt_id: SCSI ID of the target. |
| 9800 | * @lun_id: LUN ID of the scsi device. |
| 9801 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 9802 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9803 | * 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] | 9804 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 9805 | * 0 if the filtering criteria is met for the given iocb and will return |
| 9806 | * 1 if the filtering criteria is not met. |
| 9807 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 9808 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 9809 | * lun_id parameter. |
| 9810 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 9811 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 9812 | * parameters. |
| 9813 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 9814 | * given iocb is for the SCSI host associated with the given vport. |
| 9815 | * This function is called with no locks held. |
| 9816 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9817 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9818 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 9819 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9820 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9821 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9822 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9823 | int rc = 1; |
| 9824 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9825 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 9826 | return rc; |
| 9827 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9828 | if (iocbq->vport != vport) |
| 9829 | return rc; |
| 9830 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9831 | 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] | 9832 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9833 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9834 | return rc; |
| 9835 | |
| 9836 | switch (ctx_cmd) { |
| 9837 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9838 | if ((lpfc_cmd->rdata->pnode) && |
| 9839 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 9840 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9841 | rc = 0; |
| 9842 | break; |
| 9843 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 9844 | if ((lpfc_cmd->rdata->pnode) && |
| 9845 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9846 | rc = 0; |
| 9847 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9848 | case LPFC_CTX_HOST: |
| 9849 | rc = 0; |
| 9850 | break; |
| 9851 | default: |
| 9852 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 9853 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9854 | break; |
| 9855 | } |
| 9856 | |
| 9857 | return rc; |
| 9858 | } |
| 9859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9861 | * 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] | 9862 | * @vport: Pointer to virtual port. |
| 9863 | * @tgt_id: SCSI ID of the target. |
| 9864 | * @lun_id: LUN ID of the scsi device. |
| 9865 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9866 | * |
| 9867 | * This function returns number of FCP commands pending for the vport. |
| 9868 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 9869 | * commands pending on the vport associated with SCSI device specified |
| 9870 | * by tgt_id and lun_id parameters. |
| 9871 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 9872 | * commands pending on the vport associated with SCSI target specified |
| 9873 | * by tgt_id parameter. |
| 9874 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 9875 | * commands pending on the vport. |
| 9876 | * This function returns the number of iocbs which satisfy the filter. |
| 9877 | * This function is called without any lock held. |
| 9878 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9879 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9880 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 9881 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9882 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9883 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9884 | struct lpfc_iocbq *iocbq; |
| 9885 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9886 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9887 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 9888 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9889 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9890 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 9891 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9892 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9893 | } |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9894 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9895 | return sum; |
| 9896 | } |
| 9897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9899 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9900 | * @phba: Pointer to HBA context object |
| 9901 | * @cmdiocb: Pointer to command iocb object. |
| 9902 | * @rspiocb: Pointer to response iocb object. |
| 9903 | * |
| 9904 | * This function is called when an aborted FCP iocb completes. This |
| 9905 | * function is called by the ring event handler with no lock held. |
| 9906 | * This function frees the iocb. |
| 9907 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9908 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9909 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 9910 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9911 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9912 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 9913 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9914 | "original iotag x%x, abort cmd iotag x%x " |
| 9915 | "status 0x%x, reason 0x%x\n", |
| 9916 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 9917 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 9918 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 9919 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9920 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 9921 | return; |
| 9922 | } |
| 9923 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9924 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9925 | * 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] | 9926 | * @vport: Pointer to virtual port. |
| 9927 | * @pring: Pointer to driver SLI ring object. |
| 9928 | * @tgt_id: SCSI ID of the target. |
| 9929 | * @lun_id: LUN ID of the scsi device. |
| 9930 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 9931 | * |
| 9932 | * This function sends an abort command for every SCSI command |
| 9933 | * associated with the given virtual port pending on the ring |
| 9934 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 9935 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 9936 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 9937 | * parameters |
| 9938 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 9939 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 9940 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 9941 | * FCP iocbs associated with virtual port. |
| 9942 | * This function returns number of iocbs it failed to abort. |
| 9943 | * This function is called with no locks held. |
| 9944 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9945 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9946 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 9947 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9948 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9949 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9950 | struct lpfc_iocbq *iocbq; |
| 9951 | struct lpfc_iocbq *abtsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9952 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9953 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9954 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9955 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9956 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 9957 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9958 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9959 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9960 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9961 | continue; |
| 9962 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 9963 | /* |
| 9964 | * If the iocbq is already being aborted, don't take a second |
| 9965 | * action, but do count it. |
| 9966 | */ |
| 9967 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 9968 | continue; |
| 9969 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9970 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9971 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9972 | if (abtsiocb == NULL) { |
| 9973 | errcnt++; |
| 9974 | continue; |
| 9975 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9976 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 9977 | /* indicate the IO is being aborted by the driver. */ |
| 9978 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 9979 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 9980 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9981 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 9982 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9983 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9984 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 9985 | else |
| 9986 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9987 | abtsiocb->iocb.ulpLe = 1; |
| 9988 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 9989 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9990 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9991 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 9992 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 9993 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 9994 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9995 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9996 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9997 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 9998 | else |
| 9999 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 10000 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10001 | /* Setup callback routine and issue the command. */ |
| 10002 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10003 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10004 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10005 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10006 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10007 | errcnt++; |
| 10008 | continue; |
| 10009 | } |
| 10010 | } |
| 10011 | |
| 10012 | return errcnt; |
| 10013 | } |
| 10014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10015 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10016 | * 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] | 10017 | * @phba: Pointer to HBA context object. |
| 10018 | * @cmdiocbq: Pointer to command iocb. |
| 10019 | * @rspiocbq: Pointer to response iocb. |
| 10020 | * |
| 10021 | * This function is the completion handler for iocbs issued using |
| 10022 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 10023 | * ring event handler function without any lock held. This function |
| 10024 | * can be called from both worker thread context and interrupt |
| 10025 | * context. This function also can be called from other thread which |
| 10026 | * cleans up the SLI layer objects. |
| 10027 | * This function copy the contents of the response iocb to the |
| 10028 | * response iocb memory object provided by the caller of |
| 10029 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 10030 | * sleeps for the iocb completion. |
| 10031 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10032 | static void |
| 10033 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 10034 | struct lpfc_iocbq *cmdiocbq, |
| 10035 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10036 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10037 | wait_queue_head_t *pdone_q; |
| 10038 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10039 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10041 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10042 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 10043 | |
| 10044 | /* |
| 10045 | * A time out has occurred for the iocb. If a time out |
| 10046 | * completion handler has been supplied, call it. Otherwise, |
| 10047 | * just free the iocbq. |
| 10048 | */ |
| 10049 | |
| 10050 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10051 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 10052 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 10053 | if (cmdiocbq->iocb_cmpl) |
| 10054 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 10055 | else |
| 10056 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 10057 | return; |
| 10058 | } |
| 10059 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10060 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 10061 | if (cmdiocbq->context2 && rspiocbq) |
| 10062 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 10063 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 10064 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 10065 | /* Set the exchange busy flag for task management commands */ |
| 10066 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 10067 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 10068 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 10069 | cur_iocbq); |
| 10070 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 10071 | } |
| 10072 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10073 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10074 | if (pdone_q) |
| 10075 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10076 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10077 | return; |
| 10078 | } |
| 10079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10080 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10081 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 10082 | * @phba: Pointer to HBA context object.. |
| 10083 | * @piocbq: Pointer to command iocb. |
| 10084 | * @flag: Flag to test. |
| 10085 | * |
| 10086 | * This routine grabs the hbalock and then test the iocb_flag to |
| 10087 | * see if the passed in flag is set. |
| 10088 | * Returns: |
| 10089 | * 1 if flag is set. |
| 10090 | * 0 if flag is not set. |
| 10091 | **/ |
| 10092 | static int |
| 10093 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 10094 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 10095 | { |
| 10096 | unsigned long iflags; |
| 10097 | int ret; |
| 10098 | |
| 10099 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10100 | ret = piocbq->iocb_flag & flag; |
| 10101 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10102 | return ret; |
| 10103 | |
| 10104 | } |
| 10105 | |
| 10106 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10107 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10108 | * @phba: Pointer to HBA context object.. |
| 10109 | * @pring: Pointer to sli ring. |
| 10110 | * @piocb: Pointer to command iocb. |
| 10111 | * @prspiocbq: Pointer to response iocb. |
| 10112 | * @timeout: Timeout in number of seconds. |
| 10113 | * |
| 10114 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10115 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 10116 | * to handle iocbs which time out. If the field is NULL, the |
| 10117 | * function shall free the iocbq structure. If more clean up is |
| 10118 | * needed, the caller is expected to provide a completion function |
| 10119 | * that will provide the needed clean up. If the iocb command is |
| 10120 | * not completed within timeout seconds, the function will either |
| 10121 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 10122 | * completion function set in the iocb_cmpl field and then return |
| 10123 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 10124 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10125 | * The function waits for the iocb completion using an |
| 10126 | * non-interruptible wait. |
| 10127 | * This function will sleep while waiting for iocb completion. |
| 10128 | * So, this function should not be called from any context which |
| 10129 | * does not allow sleeping. Due to the same reason, this function |
| 10130 | * cannot be called with interrupt disabled. |
| 10131 | * This function assumes that the iocb completions occur while |
| 10132 | * this function sleep. So, this function cannot be called from |
| 10133 | * the thread which process iocb completion for this ring. |
| 10134 | * This function clears the iocb_flag of the iocb object before |
| 10135 | * issuing the iocb and the iocb completion handler sets this |
| 10136 | * flag and wakes this thread when the iocb completes. |
| 10137 | * The contents of the response iocb will be copied to prspiocbq |
| 10138 | * by the completion handler when the command completes. |
| 10139 | * This function returns IOCB_SUCCESS when success. |
| 10140 | * This function is called with no lock held. |
| 10141 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10142 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10143 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10144 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10145 | struct lpfc_iocbq *piocb, |
| 10146 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10147 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10148 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10149 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10150 | long timeleft, timeout_req = 0; |
| 10151 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10152 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10153 | struct lpfc_iocbq *iocb; |
| 10154 | int txq_cnt = 0; |
| 10155 | int txcmplq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10156 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10157 | unsigned long iflags; |
| 10158 | bool iocb_completed = true; |
| 10159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10160 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10161 | * If the caller has provided a response iocbq buffer, then context2 |
| 10162 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10163 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10164 | if (prspiocbq) { |
| 10165 | if (piocb->context2) |
| 10166 | return IOCB_ERROR; |
| 10167 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10168 | } |
| 10169 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10170 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10171 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 10172 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10173 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10174 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10175 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10176 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10177 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10178 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 10179 | writel(creg_val, phba->HCregaddr); |
| 10180 | readl(phba->HCregaddr); /* flush */ |
| 10181 | } |
| 10182 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10183 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 10184 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10185 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10186 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10187 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 10188 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10189 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10190 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10191 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10192 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 10193 | /* |
| 10194 | * IOCB timed out. Inform the wake iocb wait |
| 10195 | * completion function and set local status |
| 10196 | */ |
| 10197 | |
| 10198 | iocb_completed = false; |
| 10199 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 10200 | } |
| 10201 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10202 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10203 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10204 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 10205 | /* Note: we are not indicating if the IOCB has a success |
| 10206 | * status or not - that's for the caller to check. |
| 10207 | * IOCB_SUCCESS means just that the command was sent and |
| 10208 | * completed. Not that it completed successfully. |
| 10209 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10210 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10211 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10212 | "0338 IOCB wait timeout error - no " |
| 10213 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10214 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10215 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10216 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10217 | "0330 IOCB wake NOT set, " |
| 10218 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10219 | timeout, (timeleft / jiffies)); |
| 10220 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10221 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10222 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 10223 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 10224 | list_for_each_entry(iocb, &pring->txq, list) { |
| 10225 | txq_cnt++; |
| 10226 | } |
| 10227 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 10228 | txcmplq_cnt++; |
| 10229 | } |
| 10230 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10231 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 10232 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 10233 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10234 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10235 | } else { |
| 10236 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10237 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10238 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10239 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10240 | } |
| 10241 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10242 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10243 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 10244 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 10245 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 10246 | writel(creg_val, phba->HCregaddr); |
| 10247 | readl(phba->HCregaddr); /* flush */ |
| 10248 | } |
| 10249 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10250 | if (prspiocbq) |
| 10251 | piocb->context2 = NULL; |
| 10252 | |
| 10253 | piocb->context_un.wait_queue = NULL; |
| 10254 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10255 | return retval; |
| 10256 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 10257 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10258 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10259 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10260 | * @phba: Pointer to HBA context object. |
| 10261 | * @pmboxq: Pointer to driver mailbox object. |
| 10262 | * @timeout: Timeout in number of seconds. |
| 10263 | * |
| 10264 | * This function issues the mailbox to firmware and waits for the |
| 10265 | * mailbox command to complete. If the mailbox command is not |
| 10266 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 10267 | * The function waits for the mailbox completion using an |
| 10268 | * interruptible wait. If the thread is woken up due to a |
| 10269 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 10270 | * should not free the mailbox resources, if this function returns |
| 10271 | * MBX_TIMEOUT. |
| 10272 | * This function will sleep while waiting for mailbox completion. |
| 10273 | * So, this function should not be called from any context which |
| 10274 | * does not allow sleeping. Due to the same reason, this function |
| 10275 | * cannot be called with interrupt disabled. |
| 10276 | * This function assumes that the mailbox completion occurs while |
| 10277 | * this function sleep. So, this function cannot be called from |
| 10278 | * the worker thread which processes mailbox completion. |
| 10279 | * This function is called in the context of HBA management |
| 10280 | * applications. |
| 10281 | * This function returns MBX_SUCCESS when successful. |
| 10282 | * This function is called with no lock held. |
| 10283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10284 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10285 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10286 | uint32_t timeout) |
| 10287 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 10288 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10289 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10290 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10291 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10292 | |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10293 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10294 | if (pmboxq->context1) |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10295 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10296 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10297 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10298 | /* setup wake call as IOCB callback */ |
| 10299 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 10300 | /* setup context field to pass wait_queue pointer to wake function */ |
| 10301 | pmboxq->context1 = &done_q; |
| 10302 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10303 | /* now issue the command */ |
| 10304 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10305 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10306 | wait_event_interruptible_timeout(done_q, |
| 10307 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 10308 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10309 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10310 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10311 | /* restore the possible extended buffer for free resource */ |
| 10312 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10313 | /* |
| 10314 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 10315 | * else do not free the resources. |
| 10316 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10317 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10318 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 10319 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 10320 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10321 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 10322 | } |
| 10323 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 10324 | } else { |
| 10325 | /* restore the possible extended buffer for free resource */ |
| 10326 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10327 | } |
| 10328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10329 | return retval; |
| 10330 | } |
| 10331 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10332 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10333 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10334 | * @phba: Pointer to HBA context. |
| 10335 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10336 | * This function is called to shutdown the driver's mailbox sub-system. |
| 10337 | * It first marks the mailbox sub-system is in a block state to prevent |
| 10338 | * the asynchronous mailbox command from issued off the pending mailbox |
| 10339 | * command queue. If the mailbox command sub-system shutdown is due to |
| 10340 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 10341 | * the mailbox sub-system flush routine to forcefully bring down the |
| 10342 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 10343 | * as with offline or HBA function reset), this routine will wait for the |
| 10344 | * outstanding mailbox command to complete before invoking the mailbox |
| 10345 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10346 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10347 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10348 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10349 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10350 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10351 | unsigned long timeout; |
| 10352 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10353 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 10354 | /* delay 100ms for port state */ |
| 10355 | msleep(100); |
| 10356 | lpfc_sli_mbox_sys_flush(phba); |
| 10357 | return; |
| 10358 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10359 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10360 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10361 | spin_lock_irq(&phba->hbalock); |
| 10362 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10363 | |
| 10364 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10365 | /* Determine how long we might wait for the active mailbox |
| 10366 | * command to be gracefully completed by firmware. |
| 10367 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10368 | if (phba->sli.mbox_active) |
| 10369 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 10370 | phba->sli.mbox_active) * |
| 10371 | 1000) + jiffies; |
| 10372 | spin_unlock_irq(&phba->hbalock); |
| 10373 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10374 | while (phba->sli.mbox_active) { |
| 10375 | /* Check active mailbox complete status every 2ms */ |
| 10376 | msleep(2); |
| 10377 | if (time_after(jiffies, timeout)) |
| 10378 | /* Timeout, let the mailbox flush routine to |
| 10379 | * forcefully release active mailbox command |
| 10380 | */ |
| 10381 | break; |
| 10382 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 10383 | } else |
| 10384 | spin_unlock_irq(&phba->hbalock); |
| 10385 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10386 | lpfc_sli_mbox_sys_flush(phba); |
| 10387 | } |
| 10388 | |
| 10389 | /** |
| 10390 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 10391 | * @phba: Pointer to HBA context. |
| 10392 | * |
| 10393 | * This function is called to read the SLI3 device error attention registers |
| 10394 | * for possible error attention events. The caller must hold the hostlock |
| 10395 | * with spin_lock_irq(). |
| 10396 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10397 | * 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] | 10398 | * Register and returns 0 otherwise. |
| 10399 | **/ |
| 10400 | static int |
| 10401 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 10402 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10403 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10404 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10405 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10406 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10407 | goto unplug_err; |
| 10408 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10409 | if (ha_copy & HA_ERATT) { |
| 10410 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10411 | if (lpfc_sli_read_hs(phba)) |
| 10412 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10413 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10414 | /* Check if there is a deferred error condition is active */ |
| 10415 | if ((HS_FFER1 & phba->work_hs) && |
| 10416 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10417 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10418 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10419 | /* Clear all interrupt enable conditions */ |
| 10420 | writel(0, phba->HCregaddr); |
| 10421 | readl(phba->HCregaddr); |
| 10422 | } |
| 10423 | |
| 10424 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10425 | phba->work_ha |= HA_ERATT; |
| 10426 | /* Indicate polling handles this ERATT */ |
| 10427 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10428 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10429 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10430 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10431 | |
| 10432 | unplug_err: |
| 10433 | /* Set the driver HS work bitmap */ |
| 10434 | phba->work_hs |= UNPLUG_ERR; |
| 10435 | /* Set the driver HA work bitmap */ |
| 10436 | phba->work_ha |= HA_ERATT; |
| 10437 | /* Indicate polling handles this ERATT */ |
| 10438 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10439 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 10440 | } |
| 10441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10442 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10443 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 10444 | * @phba: Pointer to HBA context. |
| 10445 | * |
| 10446 | * This function is called to read the SLI4 device error attention registers |
| 10447 | * for possible error attention events. The caller must hold the hostlock |
| 10448 | * with spin_lock_irq(). |
| 10449 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10450 | * 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] | 10451 | * Register and returns 0 otherwise. |
| 10452 | **/ |
| 10453 | static int |
| 10454 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 10455 | { |
| 10456 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10457 | uint32_t if_type, portsmphr; |
| 10458 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10459 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10460 | /* |
| 10461 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10462 | * registers for error attention. This can be changed later. |
| 10463 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10464 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10465 | switch (if_type) { |
| 10466 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10467 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 10468 | &uerr_sta_lo) || |
| 10469 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 10470 | &uerr_sta_hi)) { |
| 10471 | phba->work_hs |= UNPLUG_ERR; |
| 10472 | phba->work_ha |= HA_ERATT; |
| 10473 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10474 | return 1; |
| 10475 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10476 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 10477 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 10478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10479 | "1423 HBA Unrecoverable error: " |
| 10480 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 10481 | "ue_mask_lo_reg=0x%x, " |
| 10482 | "ue_mask_hi_reg=0x%x\n", |
| 10483 | uerr_sta_lo, uerr_sta_hi, |
| 10484 | phba->sli4_hba.ue_mask_lo, |
| 10485 | phba->sli4_hba.ue_mask_hi); |
| 10486 | phba->work_status[0] = uerr_sta_lo; |
| 10487 | phba->work_status[1] = uerr_sta_hi; |
| 10488 | phba->work_ha |= HA_ERATT; |
| 10489 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10490 | return 1; |
| 10491 | } |
| 10492 | break; |
| 10493 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10494 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 10495 | &portstat_reg.word0) || |
| 10496 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 10497 | &portsmphr)){ |
| 10498 | phba->work_hs |= UNPLUG_ERR; |
| 10499 | phba->work_ha |= HA_ERATT; |
| 10500 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10501 | return 1; |
| 10502 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10503 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 10504 | phba->work_status[0] = |
| 10505 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10506 | phba->work_status[1] = |
| 10507 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10509 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10510 | "port status reg 0x%x, " |
| 10511 | "port smphr reg 0x%x, " |
| 10512 | "error 1=0x%x, error 2=0x%x\n", |
| 10513 | portstat_reg.word0, |
| 10514 | portsmphr, |
| 10515 | phba->work_status[0], |
| 10516 | phba->work_status[1]); |
| 10517 | phba->work_ha |= HA_ERATT; |
| 10518 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10519 | return 1; |
| 10520 | } |
| 10521 | break; |
| 10522 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10523 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10524 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10525 | "2886 HBA Error Attention on unsupported " |
| 10526 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10527 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10528 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10529 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10530 | return 0; |
| 10531 | } |
| 10532 | |
| 10533 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10534 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10535 | * @phba: Pointer to HBA context. |
| 10536 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10537 | * 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] | 10538 | * error attention register bit for error attention events. |
| 10539 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10540 | * 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] | 10541 | * Register and returns 0 otherwise. |
| 10542 | **/ |
| 10543 | int |
| 10544 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 10545 | { |
| 10546 | uint32_t ha_copy; |
| 10547 | |
| 10548 | /* If somebody is waiting to handle an eratt, don't process it |
| 10549 | * here. The brdkill function will do this. |
| 10550 | */ |
| 10551 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10552 | return 0; |
| 10553 | |
| 10554 | /* Check if interrupt handler handles this ERATT */ |
| 10555 | spin_lock_irq(&phba->hbalock); |
| 10556 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 10557 | /* Interrupt handler has handled ERATT */ |
| 10558 | spin_unlock_irq(&phba->hbalock); |
| 10559 | return 0; |
| 10560 | } |
| 10561 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10562 | /* |
| 10563 | * If there is deferred error attention, do not check for error |
| 10564 | * attention |
| 10565 | */ |
| 10566 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 10567 | spin_unlock_irq(&phba->hbalock); |
| 10568 | return 0; |
| 10569 | } |
| 10570 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10571 | /* If PCI channel is offline, don't process it */ |
| 10572 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10573 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10574 | return 0; |
| 10575 | } |
| 10576 | |
| 10577 | switch (phba->sli_rev) { |
| 10578 | case LPFC_SLI_REV2: |
| 10579 | case LPFC_SLI_REV3: |
| 10580 | /* Read chip Host Attention (HA) register */ |
| 10581 | ha_copy = lpfc_sli_eratt_read(phba); |
| 10582 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10583 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10584 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10585 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 10586 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10587 | default: |
| 10588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10589 | "0299 Invalid SLI revision (%d)\n", |
| 10590 | phba->sli_rev); |
| 10591 | ha_copy = 0; |
| 10592 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10593 | } |
| 10594 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10595 | |
| 10596 | return ha_copy; |
| 10597 | } |
| 10598 | |
| 10599 | /** |
| 10600 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 10601 | * @phba: Pointer to HBA context. |
| 10602 | * |
| 10603 | * This inline routine checks whether a device or its PCI slot is in a state |
| 10604 | * that the interrupt should be handled. |
| 10605 | * |
| 10606 | * This function returns 0 if the device or the PCI slot is in a state that |
| 10607 | * interrupt should be handled, otherwise -EIO. |
| 10608 | */ |
| 10609 | static inline int |
| 10610 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 10611 | { |
| 10612 | /* If the pci channel is offline, ignore all the interrupts */ |
| 10613 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 10614 | return -EIO; |
| 10615 | |
| 10616 | /* Update device level interrupt statistics */ |
| 10617 | phba->sli.slistat.sli_intr++; |
| 10618 | |
| 10619 | /* Ignore all interrupts during initialization. */ |
| 10620 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 10621 | return -EIO; |
| 10622 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10623 | return 0; |
| 10624 | } |
| 10625 | |
| 10626 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10627 | * 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] | 10628 | * @irq: Interrupt number. |
| 10629 | * @dev_id: The device context pointer. |
| 10630 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10631 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10632 | * service routine when device with SLI-3 interface spec is enabled with |
| 10633 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 10634 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 10635 | * interrupt mode, this function is called as part of the device-level |
| 10636 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 10637 | * is undergoing initialization, the interrupt handler will not process |
| 10638 | * the interrupt. The link attention and ELS ring attention events are |
| 10639 | * handled by the worker thread. The interrupt handler signals the worker |
| 10640 | * thread and returns for these events. This function is called without |
| 10641 | * 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] | 10642 | * structures. |
| 10643 | * |
| 10644 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10645 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10646 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10647 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10648 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10649 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10650 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10651 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10652 | uint32_t work_ha_copy; |
| 10653 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10654 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10655 | uint32_t control; |
| 10656 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10657 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10658 | struct lpfc_vport *vport; |
| 10659 | struct lpfc_nodelist *ndlp; |
| 10660 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10661 | LPFC_MBOXQ_t *pmb; |
| 10662 | int rc; |
| 10663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10664 | /* |
| 10665 | * Get the driver's phba structure from the dev_id and |
| 10666 | * assume the HBA is not interrupting. |
| 10667 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10668 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10669 | |
| 10670 | if (unlikely(!phba)) |
| 10671 | return IRQ_NONE; |
| 10672 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10673 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10674 | * Stuff needs to be attented to when this function is invoked as an |
| 10675 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10676 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10677 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10678 | /* Check device state for handling interrupt */ |
| 10679 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10680 | return IRQ_NONE; |
| 10681 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10682 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10683 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10684 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10685 | /* If somebody is waiting to handle an eratt don't process it |
| 10686 | * here. The brdkill function will do this. |
| 10687 | */ |
| 10688 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 10689 | ha_copy &= ~HA_ERATT; |
| 10690 | /* Check the need for handling ERATT in interrupt handler */ |
| 10691 | if (ha_copy & HA_ERATT) { |
| 10692 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 10693 | /* ERATT polling has handled ERATT */ |
| 10694 | ha_copy &= ~HA_ERATT; |
| 10695 | else |
| 10696 | /* Indicate interrupt handler handles ERATT */ |
| 10697 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 10698 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10699 | |
| 10700 | /* |
| 10701 | * If there is deferred error attention, do not check for any |
| 10702 | * interrupt. |
| 10703 | */ |
| 10704 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10705 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10706 | return IRQ_NONE; |
| 10707 | } |
| 10708 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10709 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10710 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 10711 | goto unplug_error; |
| 10712 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10713 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 10714 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 10715 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10716 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 10717 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10718 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10719 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10720 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10721 | } else |
| 10722 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10724 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 10725 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10726 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10727 | if (work_ha_copy & HA_LATT) { |
| 10728 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 10729 | /* |
| 10730 | * Turn off Link Attention interrupts |
| 10731 | * until CLEAR_LA done |
| 10732 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10733 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10734 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10735 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10736 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10737 | control &= ~HC_LAINT_ENA; |
| 10738 | writel(control, phba->HCregaddr); |
| 10739 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10740 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10741 | } |
| 10742 | else |
| 10743 | work_ha_copy &= ~HA_LATT; |
| 10744 | } |
| 10745 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10746 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10747 | /* |
| 10748 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 10749 | * the only slow ring. |
| 10750 | */ |
| 10751 | status = (work_ha_copy & |
| 10752 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 10753 | status >>= (4*LPFC_ELS_RING); |
| 10754 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10755 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10756 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 10757 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10758 | |
| 10759 | lpfc_debugfs_slow_ring_trc(phba, |
| 10760 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 10761 | control, status, |
| 10762 | (uint32_t)phba->sli.slistat.sli_intr); |
| 10763 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10764 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10765 | lpfc_debugfs_slow_ring_trc(phba, |
| 10766 | "ISR Disable ring:" |
| 10767 | "pwork:x%x hawork:x%x wait:x%x", |
| 10768 | phba->work_ha, work_ha_copy, |
| 10769 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10770 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10771 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10772 | control &= |
| 10773 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10774 | writel(control, phba->HCregaddr); |
| 10775 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10776 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10777 | else { |
| 10778 | lpfc_debugfs_slow_ring_trc(phba, |
| 10779 | "ISR slow ring: pwork:" |
| 10780 | "x%x hawork:x%x wait:x%x", |
| 10781 | phba->work_ha, work_ha_copy, |
| 10782 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10783 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 10784 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10785 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10786 | } |
| 10787 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10788 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10789 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10790 | if (lpfc_sli_read_hs(phba)) |
| 10791 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10792 | /* |
| 10793 | * Check if there is a deferred error condition |
| 10794 | * is active |
| 10795 | */ |
| 10796 | if ((HS_FFER1 & phba->work_hs) && |
| 10797 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 10798 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 10799 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10800 | phba->hba_flag |= DEFER_ERATT; |
| 10801 | /* Clear all interrupt enable conditions */ |
| 10802 | writel(0, phba->HCregaddr); |
| 10803 | readl(phba->HCregaddr); |
| 10804 | } |
| 10805 | } |
| 10806 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10807 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10808 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10809 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10810 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10811 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10812 | |
| 10813 | /* First check out the status word */ |
| 10814 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 10815 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10816 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10817 | /* |
| 10818 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 10819 | * mbxStatus <status> |
| 10820 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10821 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10822 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10823 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10824 | "Interrupt mbxCommand x%x " |
| 10825 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10826 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10827 | pmbox->mbxCommand, |
| 10828 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10829 | /* clear mailbox attention bit */ |
| 10830 | work_ha_copy &= ~HA_MBATT; |
| 10831 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10832 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10833 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10834 | phba->last_completion_time = jiffies; |
| 10835 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10836 | if (pmb->mbox_cmpl) { |
| 10837 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 10838 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 10839 | if (pmb->out_ext_byte_len && |
| 10840 | pmb->context2) |
| 10841 | lpfc_sli_pcimem_bcopy( |
| 10842 | phba->mbox_ext, |
| 10843 | pmb->context2, |
| 10844 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10845 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10846 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 10847 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 10848 | |
| 10849 | lpfc_debugfs_disc_trc(vport, |
| 10850 | LPFC_DISC_TRC_MBOX_VPORT, |
| 10851 | "MBOX dflt rpi: : " |
| 10852 | "status:x%x rpi:x%x", |
| 10853 | (uint32_t)pmbox->mbxStatus, |
| 10854 | pmbox->un.varWords[0], 0); |
| 10855 | |
| 10856 | if (!pmbox->mbxStatus) { |
| 10857 | mp = (struct lpfc_dmabuf *) |
| 10858 | (pmb->context1); |
| 10859 | ndlp = (struct lpfc_nodelist *) |
| 10860 | pmb->context2; |
| 10861 | |
| 10862 | /* Reg_LOGIN of dflt RPI was |
| 10863 | * successful. new lets get |
| 10864 | * rid of the RPI using the |
| 10865 | * same mbox buffer. |
| 10866 | */ |
| 10867 | lpfc_unreg_login(phba, |
| 10868 | vport->vpi, |
| 10869 | pmbox->un.varWords[0], |
| 10870 | pmb); |
| 10871 | pmb->mbox_cmpl = |
| 10872 | lpfc_mbx_cmpl_dflt_rpi; |
| 10873 | pmb->context1 = mp; |
| 10874 | pmb->context2 = ndlp; |
| 10875 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10876 | rc = lpfc_sli_issue_mbox(phba, |
| 10877 | pmb, |
| 10878 | MBX_NOWAIT); |
| 10879 | if (rc != MBX_BUSY) |
| 10880 | lpfc_printf_log(phba, |
| 10881 | KERN_ERR, |
| 10882 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10883 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10884 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10885 | if (rc != MBX_NOT_FINISHED) |
| 10886 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10887 | } |
| 10888 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10889 | spin_lock_irqsave( |
| 10890 | &phba->pport->work_port_lock, |
| 10891 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10892 | phba->pport->work_port_events &= |
| 10893 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10894 | spin_unlock_irqrestore( |
| 10895 | &phba->pport->work_port_lock, |
| 10896 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 10897 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10898 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 10899 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10900 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10902 | if ((work_ha_copy & HA_MBATT) && |
| 10903 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10904 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10905 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 10906 | do { |
| 10907 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 10908 | MBX_NOWAIT); |
| 10909 | } while (rc == MBX_NOT_FINISHED); |
| 10910 | if (rc != MBX_SUCCESS) |
| 10911 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 10912 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10913 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10914 | } |
| 10915 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10916 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10917 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10918 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 10919 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10920 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10921 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10922 | unplug_error: |
| 10923 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10924 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10925 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10926 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10927 | |
| 10928 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10929 | * 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] | 10930 | * @irq: Interrupt number. |
| 10931 | * @dev_id: The device context pointer. |
| 10932 | * |
| 10933 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10934 | * service routine when device with SLI-3 interface spec is enabled with |
| 10935 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 10936 | * ring event in the HBA. However, when the device is enabled with either |
| 10937 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 10938 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 10939 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 10940 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 10941 | * the intrrupt context. This function is called without any lock held. |
| 10942 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10943 | * |
| 10944 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 10945 | * returns IRQ_NONE. |
| 10946 | **/ |
| 10947 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10948 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10949 | { |
| 10950 | struct lpfc_hba *phba; |
| 10951 | uint32_t ha_copy; |
| 10952 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10953 | unsigned long iflag; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10954 | |
| 10955 | /* Get the driver's phba structure from the dev_id and |
| 10956 | * assume the HBA is not interrupting. |
| 10957 | */ |
| 10958 | phba = (struct lpfc_hba *) dev_id; |
| 10959 | |
| 10960 | if (unlikely(!phba)) |
| 10961 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10962 | |
| 10963 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10964 | * Stuff needs to be attented to when this function is invoked as an |
| 10965 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10966 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10967 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10968 | /* Check device state for handling interrupt */ |
| 10969 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10970 | return IRQ_NONE; |
| 10971 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 10972 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 10973 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10974 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10975 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10976 | /* |
| 10977 | * If there is deferred error attention, do not check for |
| 10978 | * any interrupt. |
| 10979 | */ |
| 10980 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10981 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10982 | return IRQ_NONE; |
| 10983 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10984 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 10985 | phba->HAregaddr); |
| 10986 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10987 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 10988 | } else |
| 10989 | ha_copy = phba->ha_copy; |
| 10990 | |
| 10991 | /* |
| 10992 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 10993 | */ |
| 10994 | ha_copy &= ~(phba->work_ha_mask); |
| 10995 | |
| 10996 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10997 | status >>= (4*LPFC_FCP_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10998 | if (status & HA_RXMASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10999 | lpfc_sli_handle_fast_ring_event(phba, |
| 11000 | &phba->sli.ring[LPFC_FCP_RING], |
| 11001 | status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11002 | |
| 11003 | if (phba->cfg_multi_ring_support == 2) { |
| 11004 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11005 | * Process all events on extra ring. Take the optimized path |
| 11006 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11007 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11008 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11009 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11010 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 11011 | lpfc_sli_handle_fast_ring_event(phba, |
| 11012 | &phba->sli.ring[LPFC_EXTRA_RING], |
| 11013 | status); |
| 11014 | } |
| 11015 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11016 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11017 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11018 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11019 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11020 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11021 | * @irq: Interrupt number. |
| 11022 | * @dev_id: The device context pointer. |
| 11023 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11024 | * This function is the HBA device-level interrupt handler to device with |
| 11025 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 11026 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 11027 | * requires driver attention. This function invokes the slow-path interrupt |
| 11028 | * attention handling function and fast-path interrupt attention handling |
| 11029 | * function in turn to process the relevant HBA attention events. This |
| 11030 | * function is called without any lock held. It gets the hbalock to access |
| 11031 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11032 | * |
| 11033 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 11034 | * returns IRQ_NONE. |
| 11035 | **/ |
| 11036 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11037 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11038 | { |
| 11039 | struct lpfc_hba *phba; |
| 11040 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 11041 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11042 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11043 | |
| 11044 | /* |
| 11045 | * Get the driver's phba structure from the dev_id and |
| 11046 | * assume the HBA is not interrupting. |
| 11047 | */ |
| 11048 | phba = (struct lpfc_hba *) dev_id; |
| 11049 | |
| 11050 | if (unlikely(!phba)) |
| 11051 | return IRQ_NONE; |
| 11052 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11053 | /* Check device state for handling interrupt */ |
| 11054 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11055 | return IRQ_NONE; |
| 11056 | |
| 11057 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11058 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 11059 | spin_unlock(&phba->hbalock); |
| 11060 | return IRQ_HANDLED; |
| 11061 | } |
| 11062 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11063 | if (unlikely(!phba->ha_copy)) { |
| 11064 | spin_unlock(&phba->hbalock); |
| 11065 | return IRQ_NONE; |
| 11066 | } else if (phba->ha_copy & HA_ERATT) { |
| 11067 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11068 | /* ERATT polling has handled ERATT */ |
| 11069 | phba->ha_copy &= ~HA_ERATT; |
| 11070 | else |
| 11071 | /* Indicate interrupt handler handles ERATT */ |
| 11072 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11073 | } |
| 11074 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11075 | /* |
| 11076 | * If there is deferred error attention, do not check for any interrupt. |
| 11077 | */ |
| 11078 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 11079 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11080 | return IRQ_NONE; |
| 11081 | } |
| 11082 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11083 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11084 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 11085 | spin_unlock(&phba->hbalock); |
| 11086 | return IRQ_HANDLED; |
| 11087 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11088 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 11089 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11090 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11091 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11092 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11093 | readl(phba->HAregaddr); /* flush */ |
| 11094 | spin_unlock(&phba->hbalock); |
| 11095 | |
| 11096 | /* |
| 11097 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 11098 | */ |
| 11099 | |
| 11100 | /* status of events with mailbox and link attention */ |
| 11101 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 11102 | |
| 11103 | /* status of events with ELS ring */ |
| 11104 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11105 | status2 >>= (4*LPFC_ELS_RING); |
| 11106 | |
| 11107 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11108 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11109 | else |
| 11110 | sp_irq_rc = IRQ_NONE; |
| 11111 | |
| 11112 | /* |
| 11113 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 11114 | */ |
| 11115 | |
| 11116 | /* status of events with FCP ring */ |
| 11117 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 11118 | status1 >>= (4*LPFC_FCP_RING); |
| 11119 | |
| 11120 | /* status of events with extra ring */ |
| 11121 | if (phba->cfg_multi_ring_support == 2) { |
| 11122 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 11123 | status2 >>= (4*LPFC_EXTRA_RING); |
| 11124 | } else |
| 11125 | status2 = 0; |
| 11126 | |
| 11127 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11128 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11129 | else |
| 11130 | fp_irq_rc = IRQ_NONE; |
| 11131 | |
| 11132 | /* Return device-level interrupt handling status */ |
| 11133 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11134 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11135 | |
| 11136 | /** |
| 11137 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 11138 | * @phba: pointer to lpfc hba data structure. |
| 11139 | * |
| 11140 | * This routine is invoked by the worker thread to process all the pending |
| 11141 | * SLI4 FCP abort XRI events. |
| 11142 | **/ |
| 11143 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11144 | { |
| 11145 | struct lpfc_cq_event *cq_event; |
| 11146 | |
| 11147 | /* First, declare the fcp xri abort event has been handled */ |
| 11148 | spin_lock_irq(&phba->hbalock); |
| 11149 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 11150 | spin_unlock_irq(&phba->hbalock); |
| 11151 | /* Now, handle all the fcp xri abort events */ |
| 11152 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 11153 | /* Get the first event from the head of the event queue */ |
| 11154 | spin_lock_irq(&phba->hbalock); |
| 11155 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 11156 | cq_event, struct lpfc_cq_event, list); |
| 11157 | spin_unlock_irq(&phba->hbalock); |
| 11158 | /* Notify aborted XRI for FCP work queue */ |
| 11159 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11160 | /* Free the event processed back to the free pool */ |
| 11161 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11162 | } |
| 11163 | } |
| 11164 | |
| 11165 | /** |
| 11166 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 11167 | * @phba: pointer to lpfc hba data structure. |
| 11168 | * |
| 11169 | * This routine is invoked by the worker thread to process all the pending |
| 11170 | * SLI4 els abort xri events. |
| 11171 | **/ |
| 11172 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 11173 | { |
| 11174 | struct lpfc_cq_event *cq_event; |
| 11175 | |
| 11176 | /* First, declare the els xri abort event has been handled */ |
| 11177 | spin_lock_irq(&phba->hbalock); |
| 11178 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 11179 | spin_unlock_irq(&phba->hbalock); |
| 11180 | /* Now, handle all the els xri abort events */ |
| 11181 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 11182 | /* Get the first event from the head of the event queue */ |
| 11183 | spin_lock_irq(&phba->hbalock); |
| 11184 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11185 | cq_event, struct lpfc_cq_event, list); |
| 11186 | spin_unlock_irq(&phba->hbalock); |
| 11187 | /* Notify aborted XRI for ELS work queue */ |
| 11188 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 11189 | /* Free the event processed back to the free pool */ |
| 11190 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 11191 | } |
| 11192 | } |
| 11193 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11194 | /** |
| 11195 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 11196 | * @phba: pointer to lpfc hba data structure |
| 11197 | * @pIocbIn: pointer to the rspiocbq |
| 11198 | * @pIocbOut: pointer to the cmdiocbq |
| 11199 | * @wcqe: pointer to the complete wcqe |
| 11200 | * |
| 11201 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 11202 | * by copying all the IOCB fields from command iocbq and transferring the |
| 11203 | * completion status information from the complete wcqe. |
| 11204 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11205 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11206 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 11207 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11208 | struct lpfc_iocbq *pIocbOut, |
| 11209 | struct lpfc_wcqe_complete *wcqe) |
| 11210 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11211 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11212 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11213 | uint32_t status, max_response; |
| 11214 | struct lpfc_dmabuf *dmabuf; |
| 11215 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11216 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 11217 | |
| 11218 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 11219 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11220 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11221 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 11222 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11223 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 11224 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 11225 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 11226 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 11227 | wcqe->total_data_placed; |
| 11228 | else |
| 11229 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11230 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11231 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 11232 | switch (pIocbOut->iocb.ulpCommand) { |
| 11233 | case CMD_ELS_REQUEST64_CR: |
| 11234 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11235 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11236 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 11237 | max_response = bde.tus.f.bdeSize; |
| 11238 | break; |
| 11239 | case CMD_GEN_REQUEST64_CR: |
| 11240 | max_response = 0; |
| 11241 | if (!pIocbOut->context3) |
| 11242 | break; |
| 11243 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 11244 | sizeof(struct ulp_bde64); |
| 11245 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 11246 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 11247 | for (i = 0; i < numBdes; i++) { |
| 11248 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 11249 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 11250 | max_response += bde.tus.f.bdeSize; |
| 11251 | } |
| 11252 | break; |
| 11253 | default: |
| 11254 | max_response = wcqe->total_data_placed; |
| 11255 | break; |
| 11256 | } |
| 11257 | if (max_response < wcqe->total_data_placed) |
| 11258 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 11259 | else |
| 11260 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 11261 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 11262 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11263 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 11264 | /* Convert BG errors for completion status */ |
| 11265 | if (status == CQE_STATUS_DI_ERROR) { |
| 11266 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 11267 | |
| 11268 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 11269 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 11270 | else |
| 11271 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 11272 | |
| 11273 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 11274 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 11275 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11276 | BGS_GUARD_ERR_MASK; |
| 11277 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 11278 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11279 | BGS_APPTAG_ERR_MASK; |
| 11280 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 11281 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11282 | BGS_REFTAG_ERR_MASK; |
| 11283 | |
| 11284 | /* Check to see if there was any good data before the error */ |
| 11285 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 11286 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11287 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 11288 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 11289 | wcqe->total_data_placed; |
| 11290 | } |
| 11291 | |
| 11292 | /* |
| 11293 | * Set ALL the error bits to indicate we don't know what |
| 11294 | * type of error it is. |
| 11295 | */ |
| 11296 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 11297 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 11298 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 11299 | BGS_GUARD_ERR_MASK); |
| 11300 | } |
| 11301 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11302 | /* Pick up HBA exchange busy condition */ |
| 11303 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 11304 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11305 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 11306 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11307 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11308 | } |
| 11309 | |
| 11310 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11311 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 11312 | * @phba: Pointer to HBA context object. |
| 11313 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11314 | * |
| 11315 | * This routine handles an ELS work-queue completion event and construct |
| 11316 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 11317 | * discovery engine to handle. |
| 11318 | * |
| 11319 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 11320 | **/ |
| 11321 | static struct lpfc_iocbq * |
| 11322 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 11323 | struct lpfc_iocbq *irspiocbq) |
| 11324 | { |
| 11325 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 11326 | struct lpfc_iocbq *cmdiocbq; |
| 11327 | struct lpfc_wcqe_complete *wcqe; |
| 11328 | unsigned long iflags; |
| 11329 | |
| 11330 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11331 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11332 | pring->stats.iocb_event++; |
| 11333 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 11334 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11335 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11336 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11337 | |
| 11338 | if (unlikely(!cmdiocbq)) { |
| 11339 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11340 | "0386 ELS complete with no corresponding " |
| 11341 | "cmdiocb: iotag (%d)\n", |
| 11342 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11343 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 11344 | return NULL; |
| 11345 | } |
| 11346 | |
| 11347 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11348 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11349 | |
| 11350 | return irspiocbq; |
| 11351 | } |
| 11352 | |
| 11353 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11354 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 11355 | * @phba: Pointer to HBA context object. |
| 11356 | * @cqe: Pointer to mailbox completion queue entry. |
| 11357 | * |
| 11358 | * This routine process a mailbox completion queue entry with asynchrous |
| 11359 | * event. |
| 11360 | * |
| 11361 | * Return: true if work posted to worker thread, otherwise false. |
| 11362 | **/ |
| 11363 | static bool |
| 11364 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11365 | { |
| 11366 | struct lpfc_cq_event *cq_event; |
| 11367 | unsigned long iflags; |
| 11368 | |
| 11369 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11370 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 11371 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 11372 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 11373 | |
| 11374 | /* Allocate a new internal CQ_EVENT entry */ |
| 11375 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11376 | if (!cq_event) { |
| 11377 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11378 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 11379 | return false; |
| 11380 | } |
| 11381 | |
| 11382 | /* Move the CQE into an asynchronous event entry */ |
| 11383 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 11384 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11385 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 11386 | /* Set the async event flag */ |
| 11387 | phba->hba_flag |= ASYNC_EVENT; |
| 11388 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11389 | |
| 11390 | return true; |
| 11391 | } |
| 11392 | |
| 11393 | /** |
| 11394 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 11395 | * @phba: Pointer to HBA context object. |
| 11396 | * @cqe: Pointer to mailbox completion queue entry. |
| 11397 | * |
| 11398 | * This routine process a mailbox completion queue entry with mailbox |
| 11399 | * completion event. |
| 11400 | * |
| 11401 | * Return: true if work posted to worker thread, otherwise false. |
| 11402 | **/ |
| 11403 | static bool |
| 11404 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 11405 | { |
| 11406 | uint32_t mcqe_status; |
| 11407 | MAILBOX_t *mbox, *pmbox; |
| 11408 | struct lpfc_mqe *mqe; |
| 11409 | struct lpfc_vport *vport; |
| 11410 | struct lpfc_nodelist *ndlp; |
| 11411 | struct lpfc_dmabuf *mp; |
| 11412 | unsigned long iflags; |
| 11413 | LPFC_MBOXQ_t *pmb; |
| 11414 | bool workposted = false; |
| 11415 | int rc; |
| 11416 | |
| 11417 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 11418 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 11419 | goto out_no_mqe_complete; |
| 11420 | |
| 11421 | /* Get the reference to the active mbox command */ |
| 11422 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11423 | pmb = phba->sli.mbox_active; |
| 11424 | if (unlikely(!pmb)) { |
| 11425 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 11426 | "1832 No pending MBOX command to handle\n"); |
| 11427 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11428 | goto out_no_mqe_complete; |
| 11429 | } |
| 11430 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11431 | mqe = &pmb->u.mqe; |
| 11432 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 11433 | mbox = phba->mbox; |
| 11434 | vport = pmb->vport; |
| 11435 | |
| 11436 | /* Reset heartbeat timer */ |
| 11437 | phba->last_completion_time = jiffies; |
| 11438 | del_timer(&phba->sli.mbox_tmo); |
| 11439 | |
| 11440 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 11441 | if (pmb->mbox_cmpl && mbox) |
| 11442 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11443 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11444 | /* |
| 11445 | * For mcqe errors, conditionally move a modified error code to |
| 11446 | * the mbox so that the error will not be missed. |
| 11447 | */ |
| 11448 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 11449 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 11450 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 11451 | bf_set(lpfc_mqe_status, mqe, |
| 11452 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 11453 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11454 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11455 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11456 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 11457 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 11458 | mcqe_status, |
| 11459 | pmbox->un.varWords[0], 0); |
| 11460 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 11461 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 11462 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 11463 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 11464 | * RID of the PPI using the same mbox buffer. |
| 11465 | */ |
| 11466 | lpfc_unreg_login(phba, vport->vpi, |
| 11467 | pmbox->un.varWords[0], pmb); |
| 11468 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 11469 | pmb->context1 = mp; |
| 11470 | pmb->context2 = ndlp; |
| 11471 | pmb->vport = vport; |
| 11472 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 11473 | if (rc != MBX_BUSY) |
| 11474 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 11475 | LOG_SLI, "0385 rc should " |
| 11476 | "have been MBX_BUSY\n"); |
| 11477 | if (rc != MBX_NOT_FINISHED) |
| 11478 | goto send_current_mbox; |
| 11479 | } |
| 11480 | } |
| 11481 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 11482 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 11483 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 11484 | |
| 11485 | /* There is mailbox completion work to do */ |
| 11486 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11487 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 11488 | phba->work_ha |= HA_MBATT; |
| 11489 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11490 | workposted = true; |
| 11491 | |
| 11492 | send_current_mbox: |
| 11493 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11494 | /* Release the mailbox command posting token */ |
| 11495 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11496 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 11497 | phba->sli.mbox_active = NULL; |
| 11498 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11499 | /* Wake up worker thread to post the next pending mailbox command */ |
| 11500 | lpfc_worker_wake_up(phba); |
| 11501 | out_no_mqe_complete: |
| 11502 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 11503 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 11504 | return workposted; |
| 11505 | } |
| 11506 | |
| 11507 | /** |
| 11508 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 11509 | * @phba: Pointer to HBA context object. |
| 11510 | * @cqe: Pointer to mailbox completion queue entry. |
| 11511 | * |
| 11512 | * This routine process a mailbox completion queue entry, it invokes the |
| 11513 | * proper mailbox complete handling or asynchrous event handling routine |
| 11514 | * according to the MCQE's async bit. |
| 11515 | * |
| 11516 | * Return: true if work posted to worker thread, otherwise false. |
| 11517 | **/ |
| 11518 | static bool |
| 11519 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 11520 | { |
| 11521 | struct lpfc_mcqe mcqe; |
| 11522 | bool workposted; |
| 11523 | |
| 11524 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 11525 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 11526 | |
| 11527 | /* Invoke the proper event handling routine */ |
| 11528 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 11529 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 11530 | else |
| 11531 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 11532 | return workposted; |
| 11533 | } |
| 11534 | |
| 11535 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11536 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 11537 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11538 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11539 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11540 | * |
| 11541 | * This routine handles an ELS work-queue completion event. |
| 11542 | * |
| 11543 | * Return: true if work posted to worker thread, otherwise false. |
| 11544 | **/ |
| 11545 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11546 | 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] | 11547 | struct lpfc_wcqe_complete *wcqe) |
| 11548 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11549 | struct lpfc_iocbq *irspiocbq; |
| 11550 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11551 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11552 | int txq_cnt = 0; |
| 11553 | int txcmplq_cnt = 0; |
| 11554 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11555 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11556 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11557 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 11558 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11559 | if (!list_empty(&pring->txq)) |
| 11560 | txq_cnt++; |
| 11561 | if (!list_empty(&pring->txcmplq)) |
| 11562 | txcmplq_cnt++; |
| 11563 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
| 11564 | fcp_txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11565 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11566 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 11567 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11568 | txq_cnt, phba->iocb_cnt, |
| 11569 | fcp_txcmplq_cnt, |
| 11570 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11571 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11572 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11573 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11574 | /* Save off the slow-path queue event for work thread to process */ |
| 11575 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11576 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11577 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11578 | &phba->sli4_hba.sp_queue_event); |
| 11579 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11580 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11581 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11582 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11583 | } |
| 11584 | |
| 11585 | /** |
| 11586 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 11587 | * @phba: Pointer to HBA context object. |
| 11588 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11589 | * |
| 11590 | * This routine handles slow-path WQ entry comsumed event by invoking the |
| 11591 | * proper WQ release routine to the slow-path WQ. |
| 11592 | **/ |
| 11593 | static void |
| 11594 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 11595 | struct lpfc_wcqe_release *wcqe) |
| 11596 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11597 | /* sanity check on queue memory */ |
| 11598 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 11599 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11600 | /* Check for the slow-path ELS work queue */ |
| 11601 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 11602 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 11603 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11604 | else |
| 11605 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11606 | "2579 Slow-path wqe consume event carries " |
| 11607 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 11608 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 11609 | phba->sli4_hba.els_wq->queue_id); |
| 11610 | } |
| 11611 | |
| 11612 | /** |
| 11613 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 11614 | * @phba: Pointer to HBA context object. |
| 11615 | * @cq: Pointer to a WQ completion queue. |
| 11616 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11617 | * |
| 11618 | * This routine handles an XRI abort event. |
| 11619 | * |
| 11620 | * Return: true if work posted to worker thread, otherwise false. |
| 11621 | **/ |
| 11622 | static bool |
| 11623 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 11624 | struct lpfc_queue *cq, |
| 11625 | struct sli4_wcqe_xri_aborted *wcqe) |
| 11626 | { |
| 11627 | bool workposted = false; |
| 11628 | struct lpfc_cq_event *cq_event; |
| 11629 | unsigned long iflags; |
| 11630 | |
| 11631 | /* Allocate a new internal CQ_EVENT entry */ |
| 11632 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 11633 | if (!cq_event) { |
| 11634 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11635 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 11636 | return false; |
| 11637 | } |
| 11638 | |
| 11639 | /* Move the CQE into the proper xri abort event list */ |
| 11640 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 11641 | switch (cq->subtype) { |
| 11642 | case LPFC_FCP: |
| 11643 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11644 | list_add_tail(&cq_event->list, |
| 11645 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 11646 | /* Set the fcp xri abort event flag */ |
| 11647 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 11648 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11649 | workposted = true; |
| 11650 | break; |
| 11651 | case LPFC_ELS: |
| 11652 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11653 | list_add_tail(&cq_event->list, |
| 11654 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 11655 | /* Set the els xri abort event flag */ |
| 11656 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 11657 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11658 | workposted = true; |
| 11659 | break; |
| 11660 | default: |
| 11661 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11662 | "0603 Invalid work queue CQE subtype (x%x)\n", |
| 11663 | cq->subtype); |
| 11664 | workposted = false; |
| 11665 | break; |
| 11666 | } |
| 11667 | return workposted; |
| 11668 | } |
| 11669 | |
| 11670 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11671 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11672 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11673 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11674 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11675 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11676 | * |
| 11677 | * Return: true if work posted to worker thread, otherwise false. |
| 11678 | **/ |
| 11679 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11680 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 11681 | { |
| 11682 | bool workposted = false; |
| 11683 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 11684 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
| 11685 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11686 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11687 | unsigned long iflags; |
| 11688 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11689 | /* sanity check on queue memory */ |
| 11690 | if (unlikely(!hrq) || unlikely(!drq)) |
| 11691 | return workposted; |
| 11692 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11693 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 11694 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 11695 | else |
| 11696 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 11697 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11698 | goto out; |
| 11699 | |
| 11700 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 11701 | switch (status) { |
| 11702 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 11703 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11704 | "2537 Receive Frame Truncated!!\n"); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11705 | hrq->RQ_buf_trunc++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11706 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11707 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11708 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11709 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 11710 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11711 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11712 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11713 | goto out; |
| 11714 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11715 | hrq->RQ_rcv_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11716 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
| 11717 | /* save off the frame for the word thread to process */ |
| 11718 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11719 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11720 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11721 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11722 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11723 | workposted = true; |
| 11724 | break; |
| 11725 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
| 11726 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11727 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11728 | /* Post more buffers if possible */ |
| 11729 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11730 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 11731 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11732 | workposted = true; |
| 11733 | break; |
| 11734 | } |
| 11735 | out: |
| 11736 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11737 | } |
| 11738 | |
| 11739 | /** |
| 11740 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 11741 | * @phba: Pointer to HBA context object. |
| 11742 | * @cq: Pointer to the completion queue. |
| 11743 | * @wcqe: Pointer to a completion queue entry. |
| 11744 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11745 | * 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] | 11746 | * entry. |
| 11747 | * |
| 11748 | * Return: true if work posted to worker thread, otherwise false. |
| 11749 | **/ |
| 11750 | static bool |
| 11751 | 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] | 11752 | struct lpfc_cqe *cqe) |
| 11753 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11754 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11755 | bool workposted = false; |
| 11756 | |
| 11757 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11758 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11759 | |
| 11760 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11761 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11762 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11763 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11764 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11765 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11766 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11767 | break; |
| 11768 | case CQE_CODE_RELEASE_WQE: |
| 11769 | /* Process the WQ release event */ |
| 11770 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11771 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11772 | break; |
| 11773 | case CQE_CODE_XRI_ABORTED: |
| 11774 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11775 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11776 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11777 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11778 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11779 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 11780 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11781 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 11782 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11783 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11784 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11785 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11786 | default: |
| 11787 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11788 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11789 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11790 | break; |
| 11791 | } |
| 11792 | return workposted; |
| 11793 | } |
| 11794 | |
| 11795 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11796 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 11797 | * @phba: Pointer to HBA context object. |
| 11798 | * @eqe: Pointer to fast-path event queue entry. |
| 11799 | * |
| 11800 | * This routine process a event queue entry from the slow-path event queue. |
| 11801 | * It will check the MajorCode and MinorCode to determine this is for a |
| 11802 | * completion event on a completion queue, if not, an error shall be logged |
| 11803 | * and just return. Otherwise, it will get to the corresponding completion |
| 11804 | * queue and process all the entries on that completion queue, rearm the |
| 11805 | * completion queue, and then return. |
| 11806 | * |
| 11807 | **/ |
| 11808 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11809 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 11810 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11811 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11812 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11813 | struct lpfc_cqe *cqe; |
| 11814 | bool workposted = false; |
| 11815 | int ecount = 0; |
| 11816 | uint16_t cqid; |
| 11817 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11818 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 11819 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11820 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11821 | list_for_each_entry(childq, &speq->child_list, list) { |
| 11822 | if (childq->queue_id == cqid) { |
| 11823 | cq = childq; |
| 11824 | break; |
| 11825 | } |
| 11826 | } |
| 11827 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11828 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 11829 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11830 | "0365 Slow-path CQ identifier " |
| 11831 | "(%d) does not exist\n", cqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11832 | return; |
| 11833 | } |
| 11834 | |
| 11835 | /* Process all the entries to the CQ */ |
| 11836 | switch (cq->type) { |
| 11837 | case LPFC_MCQ: |
| 11838 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 11839 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11840 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11841 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11842 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11843 | } |
| 11844 | break; |
| 11845 | case LPFC_WCQ: |
| 11846 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11847 | if (cq->subtype == LPFC_FCP) |
| 11848 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, |
| 11849 | cqe); |
| 11850 | else |
| 11851 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 11852 | cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11853 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11854 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 11855 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 11856 | |
| 11857 | /* Track the max number of CQEs processed in 1 EQ */ |
| 11858 | if (ecount > cq->CQ_max_cqe) |
| 11859 | cq->CQ_max_cqe = ecount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11860 | break; |
| 11861 | default: |
| 11862 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11863 | "0370 Invalid completion queue type (%d)\n", |
| 11864 | cq->type); |
| 11865 | return; |
| 11866 | } |
| 11867 | |
| 11868 | /* Catch the no cq entry condition, log an error */ |
| 11869 | if (unlikely(ecount == 0)) |
| 11870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 11871 | "0371 No entry from the CQ: identifier " |
| 11872 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 11873 | |
| 11874 | /* In any case, flash and re-arm the RCQ */ |
| 11875 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 11876 | |
| 11877 | /* wake up worker thread if there are works to be done */ |
| 11878 | if (workposted) |
| 11879 | lpfc_worker_wake_up(phba); |
| 11880 | } |
| 11881 | |
| 11882 | /** |
| 11883 | * 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] | 11884 | * @phba: Pointer to HBA context object. |
| 11885 | * @cq: Pointer to associated CQ |
| 11886 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11887 | * |
| 11888 | * This routine process a fast-path work queue completion entry from fast-path |
| 11889 | * event queue for FCP command response completion. |
| 11890 | **/ |
| 11891 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11892 | 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] | 11893 | struct lpfc_wcqe_complete *wcqe) |
| 11894 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 11895 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11896 | struct lpfc_iocbq *cmdiocbq; |
| 11897 | struct lpfc_iocbq irspiocbq; |
| 11898 | unsigned long iflags; |
| 11899 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11900 | /* Check for response status */ |
| 11901 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 11902 | /* If resource errors reported from HBA, reduce queue |
| 11903 | * depth of the SCSI device. |
| 11904 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11905 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 11906 | IOSTAT_LOCAL_REJECT)) && |
| 11907 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 11908 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11909 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 11910 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11911 | /* Log the error status */ |
| 11912 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11913 | "0373 FCP complete error: status=x%x, " |
| 11914 | "hw_status=x%x, total_data_specified=%d, " |
| 11915 | "parameter=x%x, word3=x%x\n", |
| 11916 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 11917 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 11918 | wcqe->total_data_placed, wcqe->parameter, |
| 11919 | wcqe->word3); |
| 11920 | } |
| 11921 | |
| 11922 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11923 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11924 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11925 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 11926 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11927 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11928 | if (unlikely(!cmdiocbq)) { |
| 11929 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11930 | "0374 FCP complete with no corresponding " |
| 11931 | "cmdiocb: iotag (%d)\n", |
| 11932 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11933 | return; |
| 11934 | } |
| 11935 | if (unlikely(!cmdiocbq->iocb_cmpl)) { |
| 11936 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11937 | "0375 FCP cmdiocb not callback function " |
| 11938 | "iotag: (%d)\n", |
| 11939 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 11940 | return; |
| 11941 | } |
| 11942 | |
| 11943 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11944 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11945 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11946 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 11947 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11948 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 11949 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11950 | } |
| 11951 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 11952 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 11953 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 11954 | } |
| 11955 | |
| 11956 | /** |
| 11957 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 11958 | * @phba: Pointer to HBA context object. |
| 11959 | * @cq: Pointer to completion queue. |
| 11960 | * @wcqe: Pointer to work-queue completion queue entry. |
| 11961 | * |
| 11962 | * This routine handles an fast-path WQ entry comsumed event by invoking the |
| 11963 | * proper WQ release routine to the slow-path WQ. |
| 11964 | **/ |
| 11965 | static void |
| 11966 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 11967 | struct lpfc_wcqe_release *wcqe) |
| 11968 | { |
| 11969 | struct lpfc_queue *childwq; |
| 11970 | bool wqid_matched = false; |
| 11971 | uint16_t fcp_wqid; |
| 11972 | |
| 11973 | /* Check for fast-path FCP work queue release */ |
| 11974 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
| 11975 | list_for_each_entry(childwq, &cq->child_list, list) { |
| 11976 | if (childwq->queue_id == fcp_wqid) { |
| 11977 | lpfc_sli4_wq_release(childwq, |
| 11978 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 11979 | wqid_matched = true; |
| 11980 | break; |
| 11981 | } |
| 11982 | } |
| 11983 | /* Report warning log message if no match found */ |
| 11984 | if (wqid_matched != true) |
| 11985 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 11986 | "2580 Fast-path wqe consume event carries " |
| 11987 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); |
| 11988 | } |
| 11989 | |
| 11990 | /** |
| 11991 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry |
| 11992 | * @cq: Pointer to the completion queue. |
| 11993 | * @eqe: Pointer to fast-path completion queue entry. |
| 11994 | * |
| 11995 | * This routine process a fast-path work queue completion entry from fast-path |
| 11996 | * event queue for FCP command response completion. |
| 11997 | **/ |
| 11998 | static int |
| 11999 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12000 | struct lpfc_cqe *cqe) |
| 12001 | { |
| 12002 | struct lpfc_wcqe_release wcqe; |
| 12003 | bool workposted = false; |
| 12004 | |
| 12005 | /* Copy the work queue CQE and convert endian order if needed */ |
| 12006 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 12007 | |
| 12008 | /* Check and process for different type of WCQE and dispatch */ |
| 12009 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 12010 | case CQE_CODE_COMPL_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12011 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12012 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 12013 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12014 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12015 | (struct lpfc_wcqe_complete *)&wcqe); |
| 12016 | break; |
| 12017 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12018 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12019 | /* Process the WQ release event */ |
| 12020 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 12021 | (struct lpfc_wcqe_release *)&wcqe); |
| 12022 | break; |
| 12023 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12024 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12025 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12026 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12027 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 12028 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 12029 | break; |
| 12030 | default: |
| 12031 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12032 | "0144 Not a valid WCQE code: x%x\n", |
| 12033 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 12034 | break; |
| 12035 | } |
| 12036 | return workposted; |
| 12037 | } |
| 12038 | |
| 12039 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12040 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12041 | * @phba: Pointer to HBA context object. |
| 12042 | * @eqe: Pointer to fast-path event queue entry. |
| 12043 | * |
| 12044 | * This routine process a event queue entry from the fast-path event queue. |
| 12045 | * It will check the MajorCode and MinorCode to determine this is for a |
| 12046 | * completion event on a completion queue, if not, an error shall be logged |
| 12047 | * and just return. Otherwise, it will get to the corresponding completion |
| 12048 | * queue and process all the entries on the completion queue, rearm the |
| 12049 | * completion queue, and then return. |
| 12050 | **/ |
| 12051 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12052 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 12053 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12054 | { |
| 12055 | struct lpfc_queue *cq; |
| 12056 | struct lpfc_cqe *cqe; |
| 12057 | bool workposted = false; |
| 12058 | uint16_t cqid; |
| 12059 | int ecount = 0; |
| 12060 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12061 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12062 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12063 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12064 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12065 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 12066 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12067 | return; |
| 12068 | } |
| 12069 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12070 | /* Get the reference to the corresponding CQ */ |
| 12071 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 12072 | |
| 12073 | /* Check if this is a Slow path event */ |
| 12074 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { |
| 12075 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 12076 | phba->sli4_hba.hba_eq[qidx]); |
| 12077 | return; |
| 12078 | } |
| 12079 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12080 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
| 12081 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12082 | "3146 Fast-path completion queues " |
| 12083 | "does not exist\n"); |
| 12084 | return; |
| 12085 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12086 | cq = phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12087 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12088 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 12089 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12090 | "0367 Fast-path completion queue " |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12091 | "(%d) does not exist\n", qidx); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12092 | return; |
| 12093 | } |
| 12094 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12095 | if (unlikely(cqid != cq->queue_id)) { |
| 12096 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12097 | "0368 Miss-matched fast-path completion " |
| 12098 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 12099 | cqid, cq->queue_id); |
| 12100 | return; |
| 12101 | } |
| 12102 | |
| 12103 | /* Process all the entries to the CQ */ |
| 12104 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 12105 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12106 | if (!(++ecount % cq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12107 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
| 12108 | } |
| 12109 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12110 | /* Track the max number of CQEs processed in 1 EQ */ |
| 12111 | if (ecount > cq->CQ_max_cqe) |
| 12112 | cq->CQ_max_cqe = ecount; |
| 12113 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12114 | /* Catch the no cq entry condition */ |
| 12115 | if (unlikely(ecount == 0)) |
| 12116 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12117 | "0369 No entry from fast-path completion " |
| 12118 | "queue fcpcqid=%d\n", cq->queue_id); |
| 12119 | |
| 12120 | /* In any case, flash and re-arm the CQ */ |
| 12121 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 12122 | |
| 12123 | /* wake up worker thread if there are works to be done */ |
| 12124 | if (workposted) |
| 12125 | lpfc_worker_wake_up(phba); |
| 12126 | } |
| 12127 | |
| 12128 | static void |
| 12129 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 12130 | { |
| 12131 | struct lpfc_eqe *eqe; |
| 12132 | |
| 12133 | /* walk all the EQ entries and drop on the floor */ |
| 12134 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 12135 | ; |
| 12136 | |
| 12137 | /* Clear and re-arm the EQ */ |
| 12138 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 12139 | } |
| 12140 | |
| 12141 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12142 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12143 | * @irq: Interrupt number. |
| 12144 | * @dev_id: The device context pointer. |
| 12145 | * |
| 12146 | * This function is directly called from the PCI layer as an interrupt |
| 12147 | * service routine when device with SLI-4 interface spec is enabled with |
| 12148 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12149 | * ring event in the HBA. However, when the device is enabled with either |
| 12150 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12151 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12152 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12153 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12154 | * the intrrupt context. This function is called without any lock held. |
| 12155 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 12156 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 12157 | * equal to that of FCP CQ index. |
| 12158 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12159 | * The link attention and ELS ring attention events are handled |
| 12160 | * by the worker thread. The interrupt handler signals the worker thread |
| 12161 | * and returns for these events. This function is called without any lock |
| 12162 | * held. It gets the hbalock to access and update SLI data structures. |
| 12163 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12164 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12165 | * returns IRQ_NONE. |
| 12166 | **/ |
| 12167 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12168 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12169 | { |
| 12170 | struct lpfc_hba *phba; |
| 12171 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
| 12172 | struct lpfc_queue *fpeq; |
| 12173 | struct lpfc_eqe *eqe; |
| 12174 | unsigned long iflag; |
| 12175 | int ecount = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12176 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12177 | |
| 12178 | /* Get the driver's phba structure from the dev_id */ |
| 12179 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; |
| 12180 | phba = fcp_eq_hdl->phba; |
| 12181 | fcp_eqidx = fcp_eq_hdl->idx; |
| 12182 | |
| 12183 | if (unlikely(!phba)) |
| 12184 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12185 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12186 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12187 | |
| 12188 | /* Get to the EQ struct associated with this vector */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12189 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12190 | if (unlikely(!fpeq)) |
| 12191 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12192 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12193 | if (lpfc_fcp_look_ahead) { |
| 12194 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) |
| 12195 | lpfc_sli4_eq_clr_intr(fpeq); |
| 12196 | else { |
| 12197 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12198 | return IRQ_NONE; |
| 12199 | } |
| 12200 | } |
| 12201 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12202 | /* Check device state for handling interrupt */ |
| 12203 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12204 | fpeq->EQ_badstate++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12205 | /* Check again for link_state with lock held */ |
| 12206 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 12207 | if (phba->link_state < LPFC_LINK_DOWN) |
| 12208 | /* Flush, clear interrupt, and rearm the EQ */ |
| 12209 | lpfc_sli4_eq_flush(phba, fpeq); |
| 12210 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12211 | if (lpfc_fcp_look_ahead) |
| 12212 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12213 | return IRQ_NONE; |
| 12214 | } |
| 12215 | |
| 12216 | /* |
| 12217 | * Process all the event on FCP fast-path EQ |
| 12218 | */ |
| 12219 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12220 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12221 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12222 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12223 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12224 | } |
| 12225 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12226 | /* Track the max number of EQEs processed in 1 intr */ |
| 12227 | if (ecount > fpeq->EQ_max_eqe) |
| 12228 | fpeq->EQ_max_eqe = ecount; |
| 12229 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12230 | /* Always clear and re-arm the fast-path EQ */ |
| 12231 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 12232 | |
| 12233 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12234 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12235 | |
| 12236 | if (lpfc_fcp_look_ahead) { |
| 12237 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
| 12238 | return IRQ_NONE; |
| 12239 | } |
| 12240 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12241 | if (phba->intr_type == MSIX) |
| 12242 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 12243 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12244 | "0358 MSI-X interrupt with no EQE\n"); |
| 12245 | else |
| 12246 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 12247 | return IRQ_NONE; |
| 12248 | } |
| 12249 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 12250 | if (lpfc_fcp_look_ahead) |
| 12251 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12252 | return IRQ_HANDLED; |
| 12253 | } /* lpfc_sli4_fp_intr_handler */ |
| 12254 | |
| 12255 | /** |
| 12256 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 12257 | * @irq: Interrupt number. |
| 12258 | * @dev_id: The device context pointer. |
| 12259 | * |
| 12260 | * This function is the device-level interrupt handler to device with SLI-4 |
| 12261 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 12262 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 12263 | * driver attention. This function invokes the slow-path interrupt attention |
| 12264 | * handling function and fast-path interrupt attention handling function in |
| 12265 | * turn to process the relevant HBA attention events. This function is called |
| 12266 | * without any lock held. It gets the hbalock to access and update SLI data |
| 12267 | * structures. |
| 12268 | * |
| 12269 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12270 | * returns IRQ_NONE. |
| 12271 | **/ |
| 12272 | irqreturn_t |
| 12273 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 12274 | { |
| 12275 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12276 | irqreturn_t hba_irq_rc; |
| 12277 | bool hba_handled = false; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12278 | int fcp_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12279 | |
| 12280 | /* Get the driver's phba structure from the dev_id */ |
| 12281 | phba = (struct lpfc_hba *)dev_id; |
| 12282 | |
| 12283 | if (unlikely(!phba)) |
| 12284 | return IRQ_NONE; |
| 12285 | |
| 12286 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12287 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12288 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12289 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 12290 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12291 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12292 | if (hba_irq_rc == IRQ_HANDLED) |
| 12293 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12294 | } |
| 12295 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12296 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12297 | } /* lpfc_sli4_intr_handler */ |
| 12298 | |
| 12299 | /** |
| 12300 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 12301 | * @queue: The queue structure to free. |
| 12302 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 12303 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12304 | * the host resident queue. This function must be called after destroying the |
| 12305 | * queue on the HBA. |
| 12306 | **/ |
| 12307 | void |
| 12308 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 12309 | { |
| 12310 | struct lpfc_dmabuf *dmabuf; |
| 12311 | |
| 12312 | if (!queue) |
| 12313 | return; |
| 12314 | |
| 12315 | while (!list_empty(&queue->page_list)) { |
| 12316 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 12317 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12318 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12319 | dmabuf->virt, dmabuf->phys); |
| 12320 | kfree(dmabuf); |
| 12321 | } |
| 12322 | kfree(queue); |
| 12323 | return; |
| 12324 | } |
| 12325 | |
| 12326 | /** |
| 12327 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 12328 | * @phba: The HBA that this queue is being created on. |
| 12329 | * @entry_size: The size of each queue entry for this queue. |
| 12330 | * @entry count: The number of entries that this queue will handle. |
| 12331 | * |
| 12332 | * This function allocates a queue structure and the DMAable memory used for |
| 12333 | * the host resident queue. This function must be called before creating the |
| 12334 | * queue on the HBA. |
| 12335 | **/ |
| 12336 | struct lpfc_queue * |
| 12337 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 12338 | uint32_t entry_count) |
| 12339 | { |
| 12340 | struct lpfc_queue *queue; |
| 12341 | struct lpfc_dmabuf *dmabuf; |
| 12342 | int x, total_qe_count; |
| 12343 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12344 | 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] | 12345 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12346 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12347 | hw_page_size = SLI4_PAGE_SIZE; |
| 12348 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12349 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 12350 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 12351 | if (!queue) |
| 12352 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12353 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 12354 | hw_page_size))/hw_page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12355 | INIT_LIST_HEAD(&queue->list); |
| 12356 | INIT_LIST_HEAD(&queue->page_list); |
| 12357 | INIT_LIST_HEAD(&queue->child_list); |
| 12358 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 12359 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 12360 | if (!dmabuf) |
| 12361 | goto out_fail; |
| 12362 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12363 | hw_page_size, &dmabuf->phys, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12364 | GFP_KERNEL); |
| 12365 | if (!dmabuf->virt) { |
| 12366 | kfree(dmabuf); |
| 12367 | goto out_fail; |
| 12368 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12369 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12370 | dmabuf->buffer_tag = x; |
| 12371 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 12372 | /* initialize queue's entry array */ |
| 12373 | dma_pointer = dmabuf->virt; |
| 12374 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 12375 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12376 | total_qe_count++, dma_pointer += entry_size) { |
| 12377 | queue->qe[total_qe_count].address = dma_pointer; |
| 12378 | } |
| 12379 | } |
| 12380 | queue->entry_size = entry_size; |
| 12381 | queue->entry_count = entry_count; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12382 | |
| 12383 | /* |
| 12384 | * entry_repost is calculated based on the number of entries in the |
| 12385 | * queue. This works out except for RQs. If buffers are NOT initially |
| 12386 | * posted for every RQE, entry_repost should be adjusted accordingly. |
| 12387 | */ |
| 12388 | queue->entry_repost = (entry_count >> 3); |
| 12389 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) |
| 12390 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12391 | queue->phba = phba; |
| 12392 | |
| 12393 | return queue; |
| 12394 | out_fail: |
| 12395 | lpfc_sli4_queue_free(queue); |
| 12396 | return NULL; |
| 12397 | } |
| 12398 | |
| 12399 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12400 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 12401 | * @phba: HBA structure that indicates port to create a queue on. |
| 12402 | * @pci_barset: PCI BAR set flag. |
| 12403 | * |
| 12404 | * This function shall perform iomap of the specified PCI BAR address to host |
| 12405 | * memory address if not already done so and return it. The returned host |
| 12406 | * memory address can be NULL. |
| 12407 | */ |
| 12408 | static void __iomem * |
| 12409 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 12410 | { |
| 12411 | struct pci_dev *pdev; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12412 | |
| 12413 | if (!phba->pcidev) |
| 12414 | return NULL; |
| 12415 | else |
| 12416 | pdev = phba->pcidev; |
| 12417 | |
| 12418 | switch (pci_barset) { |
| 12419 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12420 | return phba->pci_bar0_memmap_p; |
| 12421 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12422 | return phba->pci_bar2_memmap_p; |
| 12423 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 12424 | return phba->pci_bar4_memmap_p; |
| 12425 | default: |
| 12426 | break; |
| 12427 | } |
| 12428 | return NULL; |
| 12429 | } |
| 12430 | |
| 12431 | /** |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12432 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs |
| 12433 | * @phba: HBA structure that indicates port to create a queue on. |
| 12434 | * @startq: The starting FCP EQ to modify |
| 12435 | * |
| 12436 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
| 12437 | * |
| 12438 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 12439 | * is used to get the starting FCP EQ to change. |
| 12440 | * This function is asynchronous and will wait for the mailbox |
| 12441 | * command to finish before continuing. |
| 12442 | * |
| 12443 | * On success this function will return a zero. If unable to allocate enough |
| 12444 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12445 | * fails this function will return -ENXIO. |
| 12446 | **/ |
| 12447 | uint32_t |
| 12448 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) |
| 12449 | { |
| 12450 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 12451 | LPFC_MBOXQ_t *mbox; |
| 12452 | struct lpfc_queue *eq; |
| 12453 | int cnt, rc, length, status = 0; |
| 12454 | uint32_t shdr_status, shdr_add_status; |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12455 | uint32_t result; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12456 | int fcp_eqidx; |
| 12457 | union lpfc_sli4_cfg_shdr *shdr; |
| 12458 | uint16_t dmult; |
| 12459 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12460 | if (startq >= phba->cfg_fcp_io_channel) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12461 | return 0; |
| 12462 | |
| 12463 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12464 | if (!mbox) |
| 12465 | return -ENOMEM; |
| 12466 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 12467 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12468 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12469 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 12470 | length, LPFC_SLI4_MBX_EMBED); |
| 12471 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 12472 | |
| 12473 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12474 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
| 12475 | if (result > LPFC_DMULT_CONST) |
| 12476 | dmult = 0; |
| 12477 | else |
| 12478 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12479 | |
| 12480 | cnt = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12481 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12482 | fcp_eqidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12483 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 12484 | if (!eq) |
| 12485 | continue; |
| 12486 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 12487 | eq_delay->u.request.eq[cnt].phase = 0; |
| 12488 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 12489 | cnt++; |
| 12490 | if (cnt >= LPFC_MAX_EQ_DELAY) |
| 12491 | break; |
| 12492 | } |
| 12493 | eq_delay->u.request.num_eq = cnt; |
| 12494 | |
| 12495 | mbox->vport = phba->pport; |
| 12496 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12497 | mbox->context1 = NULL; |
| 12498 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12499 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 12500 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12501 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12502 | if (shdr_status || shdr_add_status || rc) { |
| 12503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12504 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 12505 | "status x%x add_status x%x, mbx status x%x\n", |
| 12506 | shdr_status, shdr_add_status, rc); |
| 12507 | status = -ENXIO; |
| 12508 | } |
| 12509 | mempool_free(mbox, phba->mbox_mem_pool); |
| 12510 | return status; |
| 12511 | } |
| 12512 | |
| 12513 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12514 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 12515 | * @phba: HBA structure that indicates port to create a queue on. |
| 12516 | * @eq: The queue structure to use to create the event queue. |
| 12517 | * @imax: The maximum interrupt per second limit. |
| 12518 | * |
| 12519 | * This function creates an event queue, as detailed in @eq, on a port, |
| 12520 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 12521 | * |
| 12522 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 12523 | * is used to get the entry count and entry size that are necessary to |
| 12524 | * determine the number of pages to allocate and use for this queue. This |
| 12525 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 12526 | * event queue. This function is asynchronous and will wait for the mailbox |
| 12527 | * command to finish before continuing. |
| 12528 | * |
| 12529 | * 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] | 12530 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12531 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12532 | **/ |
| 12533 | uint32_t |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12534 | 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] | 12535 | { |
| 12536 | struct lpfc_mbx_eq_create *eq_create; |
| 12537 | LPFC_MBOXQ_t *mbox; |
| 12538 | int rc, length, status = 0; |
| 12539 | struct lpfc_dmabuf *dmabuf; |
| 12540 | uint32_t shdr_status, shdr_add_status; |
| 12541 | union lpfc_sli4_cfg_shdr *shdr; |
| 12542 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12543 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12544 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12545 | /* sanity check on queue memory */ |
| 12546 | if (!eq) |
| 12547 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12548 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12549 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12550 | |
| 12551 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12552 | if (!mbox) |
| 12553 | return -ENOMEM; |
| 12554 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 12555 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12556 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12557 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 12558 | length, LPFC_SLI4_MBX_EMBED); |
| 12559 | eq_create = &mbox->u.mqe.un.eq_create; |
| 12560 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 12561 | eq->page_count); |
| 12562 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 12563 | LPFC_EQE_SIZE); |
| 12564 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
| 12565 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 12566 | if (imax > LPFC_DMULT_CONST) |
| 12567 | dmult = 0; |
| 12568 | else |
| 12569 | dmult = LPFC_DMULT_CONST/imax - 1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12570 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 12571 | dmult); |
| 12572 | switch (eq->entry_count) { |
| 12573 | default: |
| 12574 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12575 | "0360 Unsupported EQ count. (%d)\n", |
| 12576 | eq->entry_count); |
| 12577 | if (eq->entry_count < 256) |
| 12578 | return -EINVAL; |
| 12579 | /* otherwise default to smallest count (drop through) */ |
| 12580 | case 256: |
| 12581 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12582 | LPFC_EQ_CNT_256); |
| 12583 | break; |
| 12584 | case 512: |
| 12585 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12586 | LPFC_EQ_CNT_512); |
| 12587 | break; |
| 12588 | case 1024: |
| 12589 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12590 | LPFC_EQ_CNT_1024); |
| 12591 | break; |
| 12592 | case 2048: |
| 12593 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12594 | LPFC_EQ_CNT_2048); |
| 12595 | break; |
| 12596 | case 4096: |
| 12597 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 12598 | LPFC_EQ_CNT_4096); |
| 12599 | break; |
| 12600 | } |
| 12601 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12602 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12603 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12604 | putPaddrLow(dmabuf->phys); |
| 12605 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12606 | putPaddrHigh(dmabuf->phys); |
| 12607 | } |
| 12608 | mbox->vport = phba->pport; |
| 12609 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12610 | mbox->context1 = NULL; |
| 12611 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12612 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 12613 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12614 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12615 | if (shdr_status || shdr_add_status || rc) { |
| 12616 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12617 | "2500 EQ_CREATE mailbox failed with " |
| 12618 | "status x%x add_status x%x, mbx status x%x\n", |
| 12619 | shdr_status, shdr_add_status, rc); |
| 12620 | status = -ENXIO; |
| 12621 | } |
| 12622 | eq->type = LPFC_EQ; |
| 12623 | eq->subtype = LPFC_NONE; |
| 12624 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 12625 | if (eq->queue_id == 0xFFFF) |
| 12626 | status = -ENXIO; |
| 12627 | eq->host_index = 0; |
| 12628 | eq->hba_index = 0; |
| 12629 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12630 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12631 | return status; |
| 12632 | } |
| 12633 | |
| 12634 | /** |
| 12635 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 12636 | * @phba: HBA structure that indicates port to create a queue on. |
| 12637 | * @cq: The queue structure to use to create the completion queue. |
| 12638 | * @eq: The event queue to bind this completion queue to. |
| 12639 | * |
| 12640 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 12641 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 12642 | * |
| 12643 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12644 | * is used to get the entry count and entry size that are necessary to |
| 12645 | * determine the number of pages to allocate and use for this queue. The @eq |
| 12646 | * is used to indicate which event queue to bind this completion queue to. This |
| 12647 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 12648 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 12649 | * command to finish before continuing. |
| 12650 | * |
| 12651 | * 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] | 12652 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12653 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12654 | **/ |
| 12655 | uint32_t |
| 12656 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 12657 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 12658 | { |
| 12659 | struct lpfc_mbx_cq_create *cq_create; |
| 12660 | struct lpfc_dmabuf *dmabuf; |
| 12661 | LPFC_MBOXQ_t *mbox; |
| 12662 | int rc, length, status = 0; |
| 12663 | uint32_t shdr_status, shdr_add_status; |
| 12664 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12665 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 12666 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12667 | /* sanity check on queue memory */ |
| 12668 | if (!cq || !eq) |
| 12669 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12670 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12671 | hw_page_size = SLI4_PAGE_SIZE; |
| 12672 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12673 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12674 | if (!mbox) |
| 12675 | return -ENOMEM; |
| 12676 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 12677 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12678 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12679 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 12680 | length, LPFC_SLI4_MBX_EMBED); |
| 12681 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12682 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12683 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 12684 | cq->page_count); |
| 12685 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 12686 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12687 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12688 | phba->sli4_hba.pc_sli4_params.cqv); |
| 12689 | 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] | 12690 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 12691 | 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] | 12692 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 12693 | eq->queue_id); |
| 12694 | } else { |
| 12695 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 12696 | eq->queue_id); |
| 12697 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12698 | switch (cq->entry_count) { |
| 12699 | default: |
| 12700 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12701 | "0361 Unsupported CQ count. (%d)\n", |
| 12702 | cq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12703 | if (cq->entry_count < 256) { |
| 12704 | status = -EINVAL; |
| 12705 | goto out; |
| 12706 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12707 | /* otherwise default to smallest count (drop through) */ |
| 12708 | case 256: |
| 12709 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12710 | LPFC_CQ_CNT_256); |
| 12711 | break; |
| 12712 | case 512: |
| 12713 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12714 | LPFC_CQ_CNT_512); |
| 12715 | break; |
| 12716 | case 1024: |
| 12717 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 12718 | LPFC_CQ_CNT_1024); |
| 12719 | break; |
| 12720 | } |
| 12721 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12722 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12723 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12724 | putPaddrLow(dmabuf->phys); |
| 12725 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 12726 | putPaddrHigh(dmabuf->phys); |
| 12727 | } |
| 12728 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12729 | |
| 12730 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12731 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12732 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12733 | if (shdr_status || shdr_add_status || rc) { |
| 12734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12735 | "2501 CQ_CREATE mailbox failed with " |
| 12736 | "status x%x add_status x%x, mbx status x%x\n", |
| 12737 | shdr_status, shdr_add_status, rc); |
| 12738 | status = -ENXIO; |
| 12739 | goto out; |
| 12740 | } |
| 12741 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 12742 | if (cq->queue_id == 0xFFFF) { |
| 12743 | status = -ENXIO; |
| 12744 | goto out; |
| 12745 | } |
| 12746 | /* link the cq onto the parent eq child list */ |
| 12747 | list_add_tail(&cq->list, &eq->child_list); |
| 12748 | /* Set up completion queue's type and subtype */ |
| 12749 | cq->type = type; |
| 12750 | cq->subtype = subtype; |
| 12751 | 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] | 12752 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12753 | cq->host_index = 0; |
| 12754 | cq->hba_index = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12755 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12756 | out: |
| 12757 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12758 | return status; |
| 12759 | } |
| 12760 | |
| 12761 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12762 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12763 | * @phba: HBA structure that indicates port to create a queue on. |
| 12764 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12765 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 12766 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12767 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12768 | * This function provides failback (fb) functionality when the |
| 12769 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 12770 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12771 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12772 | * This routine cannot fail as all attributes were previously accessed and |
| 12773 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12774 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12775 | static void |
| 12776 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12777 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12778 | { |
| 12779 | struct lpfc_mbx_mq_create *mq_create; |
| 12780 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12781 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12782 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12783 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 12784 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12785 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12786 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 12787 | length, LPFC_SLI4_MBX_EMBED); |
| 12788 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12789 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12790 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12791 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12792 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12793 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 12794 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12795 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12796 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12797 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12798 | break; |
| 12799 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12800 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12801 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12802 | break; |
| 12803 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12804 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12805 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12806 | break; |
| 12807 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12808 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 12809 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12810 | break; |
| 12811 | } |
| 12812 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 12813 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12814 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12815 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12816 | putPaddrHigh(dmabuf->phys); |
| 12817 | } |
| 12818 | } |
| 12819 | |
| 12820 | /** |
| 12821 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 12822 | * @phba: HBA structure that indicates port to create a queue on. |
| 12823 | * @mq: The queue structure to use to create the mailbox queue. |
| 12824 | * @cq: The completion queue to associate with this cq. |
| 12825 | * @subtype: The queue's subtype. |
| 12826 | * |
| 12827 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 12828 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 12829 | * |
| 12830 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 12831 | * is used to get the entry count and entry size that are necessary to |
| 12832 | * determine the number of pages to allocate and use for this queue. This |
| 12833 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 12834 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 12835 | * command to finish before continuing. |
| 12836 | * |
| 12837 | * 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] | 12838 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12839 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12840 | **/ |
| 12841 | int32_t |
| 12842 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 12843 | struct lpfc_queue *cq, uint32_t subtype) |
| 12844 | { |
| 12845 | struct lpfc_mbx_mq_create *mq_create; |
| 12846 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 12847 | struct lpfc_dmabuf *dmabuf; |
| 12848 | LPFC_MBOXQ_t *mbox; |
| 12849 | int rc, length, status = 0; |
| 12850 | uint32_t shdr_status, shdr_add_status; |
| 12851 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12852 | 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] | 12853 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12854 | /* sanity check on queue memory */ |
| 12855 | if (!mq || !cq) |
| 12856 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12857 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 12858 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12859 | |
| 12860 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 12861 | if (!mbox) |
| 12862 | return -ENOMEM; |
| 12863 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 12864 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12865 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12866 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 12867 | length, LPFC_SLI4_MBX_EMBED); |
| 12868 | |
| 12869 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12870 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12871 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 12872 | &mq_create_ext->u.request, mq->page_count); |
| 12873 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 12874 | &mq_create_ext->u.request, 1); |
| 12875 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12876 | &mq_create_ext->u.request, 1); |
| 12877 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 12878 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 12879 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 12880 | &mq_create_ext->u.request, 1); |
| 12881 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 12882 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12883 | 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] | 12884 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 12885 | phba->sli4_hba.pc_sli4_params.mqv); |
| 12886 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 12887 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 12888 | cq->queue_id); |
| 12889 | else |
| 12890 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 12891 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12892 | switch (mq->entry_count) { |
| 12893 | default: |
| 12894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12895 | "0362 Unsupported MQ count. (%d)\n", |
| 12896 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 12897 | if (mq->entry_count < 16) { |
| 12898 | status = -EINVAL; |
| 12899 | goto out; |
| 12900 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12901 | /* otherwise default to smallest count (drop through) */ |
| 12902 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12903 | bf_set(lpfc_mq_context_ring_size, |
| 12904 | &mq_create_ext->u.request.context, |
| 12905 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12906 | break; |
| 12907 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12908 | bf_set(lpfc_mq_context_ring_size, |
| 12909 | &mq_create_ext->u.request.context, |
| 12910 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12911 | break; |
| 12912 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12913 | bf_set(lpfc_mq_context_ring_size, |
| 12914 | &mq_create_ext->u.request.context, |
| 12915 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12916 | break; |
| 12917 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 12918 | bf_set(lpfc_mq_context_ring_size, |
| 12919 | &mq_create_ext->u.request.context, |
| 12920 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12921 | break; |
| 12922 | } |
| 12923 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 12924 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12925 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 12926 | putPaddrLow(dmabuf->phys); |
| 12927 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12928 | putPaddrHigh(dmabuf->phys); |
| 12929 | } |
| 12930 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 12931 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12932 | &mq_create_ext->u.response); |
| 12933 | if (rc != MBX_SUCCESS) { |
| 12934 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12935 | "2795 MQ_CREATE_EXT failed with " |
| 12936 | "status x%x. Failback to MQ_CREATE.\n", |
| 12937 | rc); |
| 12938 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 12939 | mq_create = &mbox->u.mqe.un.mq_create; |
| 12940 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 12941 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 12942 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 12943 | &mq_create->u.response); |
| 12944 | } |
| 12945 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12946 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12947 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 12948 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 12949 | if (shdr_status || shdr_add_status || rc) { |
| 12950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12951 | "2502 MQ_CREATE mailbox failed with " |
| 12952 | "status x%x add_status x%x, mbx status x%x\n", |
| 12953 | shdr_status, shdr_add_status, rc); |
| 12954 | status = -ENXIO; |
| 12955 | goto out; |
| 12956 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12957 | if (mq->queue_id == 0xFFFF) { |
| 12958 | status = -ENXIO; |
| 12959 | goto out; |
| 12960 | } |
| 12961 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 12962 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12963 | mq->subtype = subtype; |
| 12964 | mq->host_index = 0; |
| 12965 | mq->hba_index = 0; |
| 12966 | |
| 12967 | /* link the mq onto the parent cq child list */ |
| 12968 | list_add_tail(&mq->list, &cq->child_list); |
| 12969 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12970 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12971 | return status; |
| 12972 | } |
| 12973 | |
| 12974 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12975 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 12976 | * @phba: HBA structure that indicates port to create a queue on. |
| 12977 | * @wq: The queue structure to use to create the work queue. |
| 12978 | * @cq: The completion queue to bind this work queue to. |
| 12979 | * @subtype: The subtype of the work queue indicating its functionality. |
| 12980 | * |
| 12981 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 12982 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 12983 | * |
| 12984 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 12985 | * is used to get the entry count and entry size that are necessary to |
| 12986 | * determine the number of pages to allocate and use for this queue. The @cq |
| 12987 | * is used to indicate which completion queue to bind this work queue to. This |
| 12988 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 12989 | * work queue. This function is asynchronous and will wait for the mailbox |
| 12990 | * command to finish before continuing. |
| 12991 | * |
| 12992 | * 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] | 12993 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 12994 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12995 | **/ |
| 12996 | uint32_t |
| 12997 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 12998 | struct lpfc_queue *cq, uint32_t subtype) |
| 12999 | { |
| 13000 | struct lpfc_mbx_wq_create *wq_create; |
| 13001 | struct lpfc_dmabuf *dmabuf; |
| 13002 | LPFC_MBOXQ_t *mbox; |
| 13003 | int rc, length, status = 0; |
| 13004 | uint32_t shdr_status, shdr_add_status; |
| 13005 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13006 | 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] | 13007 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13008 | void __iomem *bar_memmap_p; |
| 13009 | uint32_t db_offset; |
| 13010 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13011 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13012 | /* sanity check on queue memory */ |
| 13013 | if (!wq || !cq) |
| 13014 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13015 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13016 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13017 | |
| 13018 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13019 | if (!mbox) |
| 13020 | return -ENOMEM; |
| 13021 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 13022 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13023 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13024 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 13025 | length, LPFC_SLI4_MBX_EMBED); |
| 13026 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13027 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13028 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 13029 | wq->page_count); |
| 13030 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 13031 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13032 | |
| 13033 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13034 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13035 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13036 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13037 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 13038 | case LPFC_Q_CREATE_VERSION_0: |
| 13039 | switch (wq->entry_size) { |
| 13040 | default: |
| 13041 | case 64: |
| 13042 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 13043 | page = wq_create->u.request.page; |
| 13044 | break; |
| 13045 | case 128: |
| 13046 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13047 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13048 | status = -ERANGE; |
| 13049 | goto out; |
| 13050 | } |
| 13051 | /* If we get here the HBA MUST also support V1 and |
| 13052 | * we MUST use it |
| 13053 | */ |
| 13054 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13055 | LPFC_Q_CREATE_VERSION_1); |
| 13056 | |
| 13057 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 13058 | &wq_create->u.request_1, wq->entry_count); |
| 13059 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13060 | &wq_create->u.request_1, |
| 13061 | LPFC_WQ_WQE_SIZE_128); |
| 13062 | bf_set(lpfc_mbx_wq_create_page_size, |
| 13063 | &wq_create->u.request_1, |
| 13064 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13065 | page = wq_create->u.request_1.page; |
| 13066 | break; |
| 13067 | } |
| 13068 | break; |
| 13069 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13070 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 13071 | wq->entry_count); |
| 13072 | switch (wq->entry_size) { |
| 13073 | default: |
| 13074 | case 64: |
| 13075 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13076 | &wq_create->u.request_1, |
| 13077 | LPFC_WQ_WQE_SIZE_64); |
| 13078 | break; |
| 13079 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13080 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 13081 | LPFC_WQ_SZ128_SUPPORT)) { |
| 13082 | status = -ERANGE; |
| 13083 | goto out; |
| 13084 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13085 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 13086 | &wq_create->u.request_1, |
| 13087 | LPFC_WQ_WQE_SIZE_128); |
| 13088 | break; |
| 13089 | } |
| 13090 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, |
| 13091 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 13092 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13093 | break; |
| 13094 | default: |
| 13095 | status = -ERANGE; |
| 13096 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13097 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13098 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13099 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13100 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13101 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 13102 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13103 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13104 | |
| 13105 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13106 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 13107 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13108 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13109 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13110 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13111 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13112 | if (shdr_status || shdr_add_status || rc) { |
| 13113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13114 | "2503 WQ_CREATE mailbox failed with " |
| 13115 | "status x%x add_status x%x, mbx status x%x\n", |
| 13116 | shdr_status, shdr_add_status, rc); |
| 13117 | status = -ENXIO; |
| 13118 | goto out; |
| 13119 | } |
| 13120 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 13121 | if (wq->queue_id == 0xFFFF) { |
| 13122 | status = -ENXIO; |
| 13123 | goto out; |
| 13124 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13125 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13126 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 13127 | &wq_create->u.response); |
| 13128 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13129 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13131 | "3265 WQ[%d] doorbell format not " |
| 13132 | "supported: x%x\n", wq->queue_id, |
| 13133 | wq->db_format); |
| 13134 | status = -EINVAL; |
| 13135 | goto out; |
| 13136 | } |
| 13137 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 13138 | &wq_create->u.response); |
| 13139 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13140 | if (!bar_memmap_p) { |
| 13141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13142 | "3263 WQ[%d] failed to memmap pci " |
| 13143 | "barset:x%x\n", wq->queue_id, |
| 13144 | pci_barset); |
| 13145 | status = -ENOMEM; |
| 13146 | goto out; |
| 13147 | } |
| 13148 | db_offset = wq_create->u.response.doorbell_offset; |
| 13149 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 13150 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 13151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13152 | "3252 WQ[%d] doorbell offset not " |
| 13153 | "supported: x%x\n", wq->queue_id, |
| 13154 | db_offset); |
| 13155 | status = -EINVAL; |
| 13156 | goto out; |
| 13157 | } |
| 13158 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 13159 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13160 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 13161 | "format:x%x\n", wq->queue_id, pci_barset, |
| 13162 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13163 | } else { |
| 13164 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 13165 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 13166 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13167 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13168 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13169 | wq->subtype = subtype; |
| 13170 | wq->host_index = 0; |
| 13171 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 13172 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13173 | |
| 13174 | /* link the wq onto the parent cq child list */ |
| 13175 | list_add_tail(&wq->list, &cq->child_list); |
| 13176 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13177 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13178 | return status; |
| 13179 | } |
| 13180 | |
| 13181 | /** |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13182 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ |
| 13183 | * @phba: HBA structure that indicates port to create a queue on. |
| 13184 | * @rq: The queue structure to use for the receive queue. |
| 13185 | * @qno: The associated HBQ number |
| 13186 | * |
| 13187 | * |
| 13188 | * For SLI4 we need to adjust the RQ repost value based on |
| 13189 | * the number of buffers that are initially posted to the RQ. |
| 13190 | */ |
| 13191 | void |
| 13192 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) |
| 13193 | { |
| 13194 | uint32_t cnt; |
| 13195 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13196 | /* sanity check on queue memory */ |
| 13197 | if (!rq) |
| 13198 | return; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13199 | cnt = lpfc_hbq_defs[qno]->entry_count; |
| 13200 | |
| 13201 | /* Recalc repost for RQs based on buffers initially posted */ |
| 13202 | cnt = (cnt >> 3); |
| 13203 | if (cnt < LPFC_QUEUE_MIN_REPOST) |
| 13204 | cnt = LPFC_QUEUE_MIN_REPOST; |
| 13205 | |
| 13206 | rq->entry_repost = cnt; |
| 13207 | } |
| 13208 | |
| 13209 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13210 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 13211 | * @phba: HBA structure that indicates port to create a queue on. |
| 13212 | * @hrq: The queue structure to use to create the header receive queue. |
| 13213 | * @drq: The queue structure to use to create the data receive queue. |
| 13214 | * @cq: The completion queue to bind this work queue to. |
| 13215 | * |
| 13216 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 13217 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 13218 | * to the HBA. |
| 13219 | * |
| 13220 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 13221 | * struct is used to get the entry count that is necessary to determine the |
| 13222 | * number of pages to use for this queue. The @cq is used to indicate which |
| 13223 | * completion queue to bind received buffers that are posted to these queues to. |
| 13224 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 13225 | * receive queue pair. This function is asynchronous and will wait for the |
| 13226 | * mailbox command to finish before continuing. |
| 13227 | * |
| 13228 | * 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] | 13229 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 13230 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13231 | **/ |
| 13232 | uint32_t |
| 13233 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13234 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 13235 | { |
| 13236 | struct lpfc_mbx_rq_create *rq_create; |
| 13237 | struct lpfc_dmabuf *dmabuf; |
| 13238 | LPFC_MBOXQ_t *mbox; |
| 13239 | int rc, length, status = 0; |
| 13240 | uint32_t shdr_status, shdr_add_status; |
| 13241 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13242 | 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] | 13243 | void __iomem *bar_memmap_p; |
| 13244 | uint32_t db_offset; |
| 13245 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13246 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13247 | /* sanity check on queue memory */ |
| 13248 | if (!hrq || !drq || !cq) |
| 13249 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13250 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13251 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13252 | |
| 13253 | if (hrq->entry_count != drq->entry_count) |
| 13254 | return -EINVAL; |
| 13255 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13256 | if (!mbox) |
| 13257 | return -ENOMEM; |
| 13258 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 13259 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13260 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13261 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13262 | length, LPFC_SLI4_MBX_EMBED); |
| 13263 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13264 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13265 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13266 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13267 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13268 | bf_set(lpfc_rq_context_rqe_count_1, |
| 13269 | &rq_create->u.request.context, |
| 13270 | hrq->entry_count); |
| 13271 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13272 | bf_set(lpfc_rq_context_rqe_size, |
| 13273 | &rq_create->u.request.context, |
| 13274 | LPFC_RQE_SIZE_8); |
| 13275 | bf_set(lpfc_rq_context_page_size, |
| 13276 | &rq_create->u.request.context, |
| 13277 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13278 | } else { |
| 13279 | switch (hrq->entry_count) { |
| 13280 | default: |
| 13281 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13282 | "2535 Unsupported RQ count. (%d)\n", |
| 13283 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13284 | if (hrq->entry_count < 512) { |
| 13285 | status = -EINVAL; |
| 13286 | goto out; |
| 13287 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13288 | /* otherwise default to smallest count (drop through) */ |
| 13289 | case 512: |
| 13290 | bf_set(lpfc_rq_context_rqe_count, |
| 13291 | &rq_create->u.request.context, |
| 13292 | LPFC_RQ_RING_SIZE_512); |
| 13293 | break; |
| 13294 | case 1024: |
| 13295 | bf_set(lpfc_rq_context_rqe_count, |
| 13296 | &rq_create->u.request.context, |
| 13297 | LPFC_RQ_RING_SIZE_1024); |
| 13298 | break; |
| 13299 | case 2048: |
| 13300 | bf_set(lpfc_rq_context_rqe_count, |
| 13301 | &rq_create->u.request.context, |
| 13302 | LPFC_RQ_RING_SIZE_2048); |
| 13303 | break; |
| 13304 | case 4096: |
| 13305 | bf_set(lpfc_rq_context_rqe_count, |
| 13306 | &rq_create->u.request.context, |
| 13307 | LPFC_RQ_RING_SIZE_4096); |
| 13308 | break; |
| 13309 | } |
| 13310 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13311 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13312 | } |
| 13313 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13314 | cq->queue_id); |
| 13315 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13316 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13317 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13318 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13319 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13320 | putPaddrLow(dmabuf->phys); |
| 13321 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13322 | putPaddrHigh(dmabuf->phys); |
| 13323 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13324 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13325 | bf_set(lpfc_mbx_rq_create_dua, &rq_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 | "2504 RQ_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 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13340 | if (hrq->queue_id == 0xFFFF) { |
| 13341 | status = -ENXIO; |
| 13342 | goto out; |
| 13343 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13344 | |
| 13345 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 13346 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 13347 | &rq_create->u.response); |
| 13348 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 13349 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 13350 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13351 | "3262 RQ [%d] doorbell format not " |
| 13352 | "supported: x%x\n", hrq->queue_id, |
| 13353 | hrq->db_format); |
| 13354 | status = -EINVAL; |
| 13355 | goto out; |
| 13356 | } |
| 13357 | |
| 13358 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 13359 | &rq_create->u.response); |
| 13360 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 13361 | if (!bar_memmap_p) { |
| 13362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13363 | "3269 RQ[%d] failed to memmap pci " |
| 13364 | "barset:x%x\n", hrq->queue_id, |
| 13365 | pci_barset); |
| 13366 | status = -ENOMEM; |
| 13367 | goto out; |
| 13368 | } |
| 13369 | |
| 13370 | db_offset = rq_create->u.response.doorbell_offset; |
| 13371 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 13372 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 13373 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13374 | "3270 RQ[%d] doorbell offset not " |
| 13375 | "supported: x%x\n", hrq->queue_id, |
| 13376 | db_offset); |
| 13377 | status = -EINVAL; |
| 13378 | goto out; |
| 13379 | } |
| 13380 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 13381 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 13382 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 13383 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 13384 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13385 | } else { |
| 13386 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 13387 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 13388 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13389 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13390 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13391 | hrq->subtype = subtype; |
| 13392 | hrq->host_index = 0; |
| 13393 | hrq->hba_index = 0; |
| 13394 | |
| 13395 | /* now create the data queue */ |
| 13396 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13397 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 13398 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13399 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 13400 | phba->sli4_hba.pc_sli4_params.rqv); |
| 13401 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 13402 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13403 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13404 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 13405 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 13406 | LPFC_RQE_SIZE_8); |
| 13407 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 13408 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13409 | } else { |
| 13410 | switch (drq->entry_count) { |
| 13411 | default: |
| 13412 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13413 | "2536 Unsupported RQ count. (%d)\n", |
| 13414 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 13415 | if (drq->entry_count < 512) { |
| 13416 | status = -EINVAL; |
| 13417 | goto out; |
| 13418 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 13419 | /* otherwise default to smallest count (drop through) */ |
| 13420 | case 512: |
| 13421 | bf_set(lpfc_rq_context_rqe_count, |
| 13422 | &rq_create->u.request.context, |
| 13423 | LPFC_RQ_RING_SIZE_512); |
| 13424 | break; |
| 13425 | case 1024: |
| 13426 | bf_set(lpfc_rq_context_rqe_count, |
| 13427 | &rq_create->u.request.context, |
| 13428 | LPFC_RQ_RING_SIZE_1024); |
| 13429 | break; |
| 13430 | case 2048: |
| 13431 | bf_set(lpfc_rq_context_rqe_count, |
| 13432 | &rq_create->u.request.context, |
| 13433 | LPFC_RQ_RING_SIZE_2048); |
| 13434 | break; |
| 13435 | case 4096: |
| 13436 | bf_set(lpfc_rq_context_rqe_count, |
| 13437 | &rq_create->u.request.context, |
| 13438 | LPFC_RQ_RING_SIZE_4096); |
| 13439 | break; |
| 13440 | } |
| 13441 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 13442 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13443 | } |
| 13444 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 13445 | cq->queue_id); |
| 13446 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 13447 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13448 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 13449 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 13450 | putPaddrLow(dmabuf->phys); |
| 13451 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 13452 | putPaddrHigh(dmabuf->phys); |
| 13453 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 13454 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 13455 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13456 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 13457 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13458 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 13459 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13460 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13461 | if (shdr_status || shdr_add_status || rc) { |
| 13462 | status = -ENXIO; |
| 13463 | goto out; |
| 13464 | } |
| 13465 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 13466 | if (drq->queue_id == 0xFFFF) { |
| 13467 | status = -ENXIO; |
| 13468 | goto out; |
| 13469 | } |
| 13470 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 13471 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13472 | drq->subtype = subtype; |
| 13473 | drq->host_index = 0; |
| 13474 | drq->hba_index = 0; |
| 13475 | |
| 13476 | /* link the header and data RQs onto the parent cq child list */ |
| 13477 | list_add_tail(&hrq->list, &cq->child_list); |
| 13478 | list_add_tail(&drq->list, &cq->child_list); |
| 13479 | |
| 13480 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13481 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13482 | return status; |
| 13483 | } |
| 13484 | |
| 13485 | /** |
| 13486 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 13487 | * @eq: The queue structure associated with the queue to destroy. |
| 13488 | * |
| 13489 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 13490 | * command, specific to the type of queue, to the HBA. |
| 13491 | * |
| 13492 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 13493 | * |
| 13494 | * 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] | 13495 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13496 | **/ |
| 13497 | uint32_t |
| 13498 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13499 | { |
| 13500 | LPFC_MBOXQ_t *mbox; |
| 13501 | int rc, length, status = 0; |
| 13502 | uint32_t shdr_status, shdr_add_status; |
| 13503 | union lpfc_sli4_cfg_shdr *shdr; |
| 13504 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13505 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13506 | if (!eq) |
| 13507 | return -ENODEV; |
| 13508 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13509 | if (!mbox) |
| 13510 | return -ENOMEM; |
| 13511 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 13512 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13513 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13514 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 13515 | length, LPFC_SLI4_MBX_EMBED); |
| 13516 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 13517 | eq->queue_id); |
| 13518 | mbox->vport = eq->phba->pport; |
| 13519 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13520 | |
| 13521 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 13522 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13523 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13524 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 13525 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13526 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13527 | if (shdr_status || shdr_add_status || rc) { |
| 13528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13529 | "2505 EQ_DESTROY mailbox failed with " |
| 13530 | "status x%x add_status x%x, mbx status x%x\n", |
| 13531 | shdr_status, shdr_add_status, rc); |
| 13532 | status = -ENXIO; |
| 13533 | } |
| 13534 | |
| 13535 | /* Remove eq from any list */ |
| 13536 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13537 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13538 | return status; |
| 13539 | } |
| 13540 | |
| 13541 | /** |
| 13542 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 13543 | * @cq: The queue structure associated with the queue to destroy. |
| 13544 | * |
| 13545 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 13546 | * command, specific to the type of queue, to the HBA. |
| 13547 | * |
| 13548 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 13549 | * |
| 13550 | * 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] | 13551 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13552 | **/ |
| 13553 | uint32_t |
| 13554 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 13555 | { |
| 13556 | LPFC_MBOXQ_t *mbox; |
| 13557 | int rc, length, status = 0; |
| 13558 | uint32_t shdr_status, shdr_add_status; |
| 13559 | union lpfc_sli4_cfg_shdr *shdr; |
| 13560 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13561 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13562 | if (!cq) |
| 13563 | return -ENODEV; |
| 13564 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13565 | if (!mbox) |
| 13566 | return -ENOMEM; |
| 13567 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 13568 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13569 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13570 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 13571 | length, LPFC_SLI4_MBX_EMBED); |
| 13572 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 13573 | cq->queue_id); |
| 13574 | mbox->vport = cq->phba->pport; |
| 13575 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13576 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 13577 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13578 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13579 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 13580 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13581 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13582 | if (shdr_status || shdr_add_status || rc) { |
| 13583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13584 | "2506 CQ_DESTROY mailbox failed with " |
| 13585 | "status x%x add_status x%x, mbx status x%x\n", |
| 13586 | shdr_status, shdr_add_status, rc); |
| 13587 | status = -ENXIO; |
| 13588 | } |
| 13589 | /* Remove cq from any list */ |
| 13590 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13591 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13592 | return status; |
| 13593 | } |
| 13594 | |
| 13595 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13596 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 13597 | * @qm: The queue structure associated with the queue to destroy. |
| 13598 | * |
| 13599 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 13600 | * command, specific to the type of queue, to the HBA. |
| 13601 | * |
| 13602 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 13603 | * |
| 13604 | * 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] | 13605 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13606 | **/ |
| 13607 | uint32_t |
| 13608 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 13609 | { |
| 13610 | LPFC_MBOXQ_t *mbox; |
| 13611 | int rc, length, status = 0; |
| 13612 | uint32_t shdr_status, shdr_add_status; |
| 13613 | union lpfc_sli4_cfg_shdr *shdr; |
| 13614 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13615 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13616 | if (!mq) |
| 13617 | return -ENODEV; |
| 13618 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13619 | if (!mbox) |
| 13620 | return -ENOMEM; |
| 13621 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 13622 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13623 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13624 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 13625 | length, LPFC_SLI4_MBX_EMBED); |
| 13626 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 13627 | mq->queue_id); |
| 13628 | mbox->vport = mq->phba->pport; |
| 13629 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13630 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 13631 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13632 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13633 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 13634 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13635 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13636 | if (shdr_status || shdr_add_status || rc) { |
| 13637 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13638 | "2507 MQ_DESTROY mailbox failed with " |
| 13639 | "status x%x add_status x%x, mbx status x%x\n", |
| 13640 | shdr_status, shdr_add_status, rc); |
| 13641 | status = -ENXIO; |
| 13642 | } |
| 13643 | /* Remove mq from any list */ |
| 13644 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13645 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13646 | return status; |
| 13647 | } |
| 13648 | |
| 13649 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13650 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 13651 | * @wq: The queue structure associated with the queue to destroy. |
| 13652 | * |
| 13653 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 13654 | * command, specific to the type of queue, to the HBA. |
| 13655 | * |
| 13656 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 13657 | * |
| 13658 | * 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] | 13659 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13660 | **/ |
| 13661 | uint32_t |
| 13662 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 13663 | { |
| 13664 | LPFC_MBOXQ_t *mbox; |
| 13665 | int rc, length, status = 0; |
| 13666 | uint32_t shdr_status, shdr_add_status; |
| 13667 | union lpfc_sli4_cfg_shdr *shdr; |
| 13668 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13669 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13670 | if (!wq) |
| 13671 | return -ENODEV; |
| 13672 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13673 | if (!mbox) |
| 13674 | return -ENOMEM; |
| 13675 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 13676 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13677 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13678 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 13679 | length, LPFC_SLI4_MBX_EMBED); |
| 13680 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 13681 | wq->queue_id); |
| 13682 | mbox->vport = wq->phba->pport; |
| 13683 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13684 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 13685 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13686 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 13687 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13688 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13689 | if (shdr_status || shdr_add_status || rc) { |
| 13690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13691 | "2508 WQ_DESTROY mailbox failed with " |
| 13692 | "status x%x add_status x%x, mbx status x%x\n", |
| 13693 | shdr_status, shdr_add_status, rc); |
| 13694 | status = -ENXIO; |
| 13695 | } |
| 13696 | /* Remove wq from any list */ |
| 13697 | list_del_init(&wq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13698 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13699 | return status; |
| 13700 | } |
| 13701 | |
| 13702 | /** |
| 13703 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 13704 | * @rq: The queue structure associated with the queue to destroy. |
| 13705 | * |
| 13706 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 13707 | * command, specific to the type of queue, to the HBA. |
| 13708 | * |
| 13709 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 13710 | * |
| 13711 | * 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] | 13712 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13713 | **/ |
| 13714 | uint32_t |
| 13715 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 13716 | struct lpfc_queue *drq) |
| 13717 | { |
| 13718 | LPFC_MBOXQ_t *mbox; |
| 13719 | int rc, length, status = 0; |
| 13720 | uint32_t shdr_status, shdr_add_status; |
| 13721 | union lpfc_sli4_cfg_shdr *shdr; |
| 13722 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13723 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13724 | if (!hrq || !drq) |
| 13725 | return -ENODEV; |
| 13726 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 13727 | if (!mbox) |
| 13728 | return -ENOMEM; |
| 13729 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13730 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13731 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13732 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 13733 | length, LPFC_SLI4_MBX_EMBED); |
| 13734 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13735 | hrq->queue_id); |
| 13736 | mbox->vport = hrq->phba->pport; |
| 13737 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 13738 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 13739 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13740 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13741 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13742 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13743 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13744 | if (shdr_status || shdr_add_status || rc) { |
| 13745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13746 | "2509 RQ_DESTROY mailbox failed with " |
| 13747 | "status x%x add_status x%x, mbx status x%x\n", |
| 13748 | shdr_status, shdr_add_status, rc); |
| 13749 | if (rc != MBX_TIMEOUT) |
| 13750 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 13751 | return -ENXIO; |
| 13752 | } |
| 13753 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 13754 | drq->queue_id); |
| 13755 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 13756 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13757 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 13758 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13759 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13760 | if (shdr_status || shdr_add_status || rc) { |
| 13761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13762 | "2510 RQ_DESTROY mailbox failed with " |
| 13763 | "status x%x add_status x%x, mbx status x%x\n", |
| 13764 | shdr_status, shdr_add_status, rc); |
| 13765 | status = -ENXIO; |
| 13766 | } |
| 13767 | list_del_init(&hrq->list); |
| 13768 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13769 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13770 | return status; |
| 13771 | } |
| 13772 | |
| 13773 | /** |
| 13774 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 13775 | * @phba: The virtual port for which this call being executed. |
| 13776 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 13777 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 13778 | * @xritag: the xritag that ties this io to the SGL pages. |
| 13779 | * |
| 13780 | * This routine will post the sgl pages for the IO that has the xritag |
| 13781 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 13782 | * creation and persists for as long as the driver is loaded. |
| 13783 | * if the caller has fewer than 256 scatter gather segments to map then |
| 13784 | * pdma_phys_addr1 should be 0. |
| 13785 | * If the caller needs to map more than 256 scatter gather segment then |
| 13786 | * pdma_phys_addr1 should be a valid physical address. |
| 13787 | * physical address for SGLs must be 64 byte aligned. |
| 13788 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 13789 | * the second sgl can have between 1 and 256 entries. |
| 13790 | * |
| 13791 | * Return codes: |
| 13792 | * 0 - Success |
| 13793 | * -ENXIO, -ENOMEM - Failure |
| 13794 | **/ |
| 13795 | int |
| 13796 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 13797 | dma_addr_t pdma_phys_addr0, |
| 13798 | dma_addr_t pdma_phys_addr1, |
| 13799 | uint16_t xritag) |
| 13800 | { |
| 13801 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 13802 | LPFC_MBOXQ_t *mbox; |
| 13803 | int rc; |
| 13804 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13805 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13806 | union lpfc_sli4_cfg_shdr *shdr; |
| 13807 | |
| 13808 | if (xritag == NO_XRI) { |
| 13809 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13810 | "0364 Invalid param:\n"); |
| 13811 | return -EINVAL; |
| 13812 | } |
| 13813 | |
| 13814 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13815 | if (!mbox) |
| 13816 | return -ENOMEM; |
| 13817 | |
| 13818 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13819 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 13820 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13821 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13822 | |
| 13823 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 13824 | &mbox->u.mqe.un.post_sgl_pages; |
| 13825 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 13826 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 13827 | |
| 13828 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 13829 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 13830 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 13831 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 13832 | |
| 13833 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 13834 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 13835 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 13836 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 13837 | if (!phba->sli4_hba.intr_enable) |
| 13838 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13839 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13840 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13841 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 13842 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13843 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 13844 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 13845 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13846 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 13847 | if (rc != MBX_TIMEOUT) |
| 13848 | mempool_free(mbox, phba->mbox_mem_pool); |
| 13849 | if (shdr_status || shdr_add_status || rc) { |
| 13850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13851 | "2511 POST_SGL mailbox failed with " |
| 13852 | "status x%x add_status x%x, mbx status x%x\n", |
| 13853 | shdr_status, shdr_add_status, rc); |
| 13854 | rc = -ENXIO; |
| 13855 | } |
| 13856 | return 0; |
| 13857 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13858 | |
| 13859 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13860 | * 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] | 13861 | * @phba: pointer to lpfc hba data structure. |
| 13862 | * |
| 13863 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13864 | * HBA consistent with the SLI-4 interface spec. This routine |
| 13865 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 13866 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13867 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13868 | * Returns |
| 13869 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 13870 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 13871 | **/ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13872 | uint16_t |
| 13873 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 13874 | { |
| 13875 | unsigned long xri; |
| 13876 | |
| 13877 | /* |
| 13878 | * Fetch the next logical xri. Because this index is logical, |
| 13879 | * the driver starts at 0 each time. |
| 13880 | */ |
| 13881 | spin_lock_irq(&phba->hbalock); |
| 13882 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 13883 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 13884 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 13885 | spin_unlock_irq(&phba->hbalock); |
| 13886 | return NO_XRI; |
| 13887 | } else { |
| 13888 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 13889 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13890 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13891 | spin_unlock_irq(&phba->hbalock); |
| 13892 | return xri; |
| 13893 | } |
| 13894 | |
| 13895 | /** |
| 13896 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13897 | * @phba: pointer to lpfc hba data structure. |
| 13898 | * |
| 13899 | * This routine is invoked to release an xri to the pool of |
| 13900 | * available rpis maintained by the driver. |
| 13901 | **/ |
| 13902 | void |
| 13903 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13904 | { |
| 13905 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13906 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 13907 | } |
| 13908 | } |
| 13909 | |
| 13910 | /** |
| 13911 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 13912 | * @phba: pointer to lpfc hba data structure. |
| 13913 | * |
| 13914 | * This routine is invoked to release an xri to the pool of |
| 13915 | * available rpis maintained by the driver. |
| 13916 | **/ |
| 13917 | void |
| 13918 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 13919 | { |
| 13920 | spin_lock_irq(&phba->hbalock); |
| 13921 | __lpfc_sli4_free_xri(phba, xri); |
| 13922 | spin_unlock_irq(&phba->hbalock); |
| 13923 | } |
| 13924 | |
| 13925 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13926 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 13927 | * @phba: Pointer to HBA context object. |
| 13928 | * |
| 13929 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 13930 | * it will return 0xffff. |
| 13931 | * The function returns the allocated xritag if successful, else returns zero. |
| 13932 | * Zero is not a valid xritag. |
| 13933 | * The caller is not required to hold any lock. |
| 13934 | **/ |
| 13935 | uint16_t |
| 13936 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 13937 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13938 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13939 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13940 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 13941 | if (xri_index == NO_XRI) |
| 13942 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13943 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 13944 | " Max XRI is %d, Used XRI is %d\n", |
| 13945 | xri_index, |
| 13946 | phba->sli4_hba.max_cfg_param.max_xri, |
| 13947 | phba->sli4_hba.max_cfg_param.xri_used); |
| 13948 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13949 | } |
| 13950 | |
| 13951 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13952 | * 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] | 13953 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13954 | * @post_sgl_list: pointer to els sgl entry list. |
| 13955 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13956 | * |
| 13957 | * This routine is invoked to post a block of driver's sgl pages to the |
| 13958 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 13959 | * is only called when the driver is loading and after all IO has been |
| 13960 | * stopped. |
| 13961 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13962 | static int |
| 13963 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, |
| 13964 | struct list_head *post_sgl_list, |
| 13965 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13966 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13967 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13968 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 13969 | struct sgl_page_pairs *sgl_pg_pairs; |
| 13970 | void *viraddr; |
| 13971 | LPFC_MBOXQ_t *mbox; |
| 13972 | uint32_t reqlen, alloclen, pg_pairs; |
| 13973 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13974 | uint16_t xritag_start = 0; |
| 13975 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13976 | uint32_t shdr_status, shdr_add_status; |
| 13977 | union lpfc_sli4_cfg_shdr *shdr; |
| 13978 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 13979 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13980 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13981 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13982 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 13983 | "2559 Block sgl registration required DMA " |
| 13984 | "size (%d) great than a page\n", reqlen); |
| 13985 | return -ENOMEM; |
| 13986 | } |
| 13987 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13988 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13989 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13990 | |
| 13991 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 13992 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 13993 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 13994 | LPFC_SLI4_MBX_NEMBED); |
| 13995 | |
| 13996 | if (alloclen < reqlen) { |
| 13997 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13998 | "0285 Allocated DMA memory size (%d) is " |
| 13999 | "less than the requested DMA memory " |
| 14000 | "size (%d)\n", alloclen, reqlen); |
| 14001 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14002 | return -ENOMEM; |
| 14003 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14004 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14005 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14006 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14007 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14008 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14009 | pg_pairs = 0; |
| 14010 | 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] | 14011 | /* Set up the sge entry */ |
| 14012 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14013 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 14014 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14015 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 14016 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14017 | cpu_to_le32(putPaddrLow(0)); |
| 14018 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14019 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14020 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14021 | /* Keep the first xritag on the list */ |
| 14022 | if (pg_pairs == 0) |
| 14023 | xritag_start = sglq_entry->sli4_xritag; |
| 14024 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14025 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14027 | |
| 14028 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14029 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14030 | 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] | 14031 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14032 | if (!phba->sli4_hba.intr_enable) |
| 14033 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14034 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14035 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14036 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14037 | } |
| 14038 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14039 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14040 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14041 | if (rc != MBX_TIMEOUT) |
| 14042 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14043 | if (shdr_status || shdr_add_status || rc) { |
| 14044 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14045 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 14046 | "status x%x add_status x%x mbx status x%x\n", |
| 14047 | shdr_status, shdr_add_status, rc); |
| 14048 | rc = -ENXIO; |
| 14049 | } |
| 14050 | return rc; |
| 14051 | } |
| 14052 | |
| 14053 | /** |
| 14054 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 14055 | * @phba: pointer to lpfc hba data structure. |
| 14056 | * @sblist: pointer to scsi buffer list. |
| 14057 | * @count: number of scsi buffers on the list. |
| 14058 | * |
| 14059 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 14060 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 14061 | * No Lock is held. |
| 14062 | * |
| 14063 | **/ |
| 14064 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14065 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 14066 | struct list_head *sblist, |
| 14067 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14068 | { |
| 14069 | struct lpfc_scsi_buf *psb; |
| 14070 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 14071 | struct sgl_page_pairs *sgl_pg_pairs; |
| 14072 | void *viraddr; |
| 14073 | LPFC_MBOXQ_t *mbox; |
| 14074 | uint32_t reqlen, alloclen, pg_pairs; |
| 14075 | uint32_t mbox_tmo; |
| 14076 | uint16_t xritag_start = 0; |
| 14077 | int rc = 0; |
| 14078 | uint32_t shdr_status, shdr_add_status; |
| 14079 | dma_addr_t pdma_phys_bpl1; |
| 14080 | union lpfc_sli4_cfg_shdr *shdr; |
| 14081 | |
| 14082 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14083 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14084 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14085 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14086 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 14087 | "0217 Block sgl registration required DMA " |
| 14088 | "size (%d) great than a page\n", reqlen); |
| 14089 | return -ENOMEM; |
| 14090 | } |
| 14091 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14092 | if (!mbox) { |
| 14093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14094 | "0283 Failed to allocate mbox cmd memory\n"); |
| 14095 | return -ENOMEM; |
| 14096 | } |
| 14097 | |
| 14098 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 14099 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14100 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 14101 | LPFC_SLI4_MBX_NEMBED); |
| 14102 | |
| 14103 | if (alloclen < reqlen) { |
| 14104 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14105 | "2561 Allocated DMA memory size (%d) is " |
| 14106 | "less than the requested DMA memory " |
| 14107 | "size (%d)\n", alloclen, reqlen); |
| 14108 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14109 | return -ENOMEM; |
| 14110 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14111 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14112 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14113 | viraddr = mbox->sge_array->addr[0]; |
| 14114 | |
| 14115 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 14116 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 14117 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 14118 | |
| 14119 | pg_pairs = 0; |
| 14120 | list_for_each_entry(psb, sblist, list) { |
| 14121 | /* Set up the sge entry */ |
| 14122 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 14123 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 14124 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 14125 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 14126 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 14127 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 14128 | else |
| 14129 | pdma_phys_bpl1 = 0; |
| 14130 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 14131 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 14132 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 14133 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 14134 | /* Keep the first xritag on the list */ |
| 14135 | if (pg_pairs == 0) |
| 14136 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 14137 | sgl_pg_pairs++; |
| 14138 | pg_pairs++; |
| 14139 | } |
| 14140 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 14141 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 14142 | /* Perform endian conversion if necessary */ |
| 14143 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 14144 | |
| 14145 | if (!phba->sli4_hba.intr_enable) |
| 14146 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14147 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 14148 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14149 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 14150 | } |
| 14151 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 14152 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14153 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14154 | if (rc != MBX_TIMEOUT) |
| 14155 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14156 | if (shdr_status || shdr_add_status || rc) { |
| 14157 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14158 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 14159 | "status x%x add_status x%x mbx status x%x\n", |
| 14160 | shdr_status, shdr_add_status, rc); |
| 14161 | rc = -ENXIO; |
| 14162 | } |
| 14163 | return rc; |
| 14164 | } |
| 14165 | |
| 14166 | /** |
| 14167 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 14168 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 14169 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14170 | * |
| 14171 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 14172 | * valid type of frame that the LPFC driver will handle. This function will |
| 14173 | * return a zero if the frame is a valid frame or a non zero value when the |
| 14174 | * frame does not pass the check. |
| 14175 | **/ |
| 14176 | static int |
| 14177 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 14178 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 14179 | /* make rctl_names static to save stack space */ |
| 14180 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14181 | char *type_names[] = FC_TYPE_NAMES_INIT; |
| 14182 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14183 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14184 | |
| 14185 | switch (fc_hdr->fh_r_ctl) { |
| 14186 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 14187 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 14188 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 14189 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 14190 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 14191 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 14192 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 14193 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 14194 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 14195 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 14196 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 14197 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 14198 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 14199 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 14200 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 14201 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 14202 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 14203 | case FC_RCTL_BA_PRMT: |
| 14204 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 14205 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 14206 | case FC_RCTL_P_RJT: /* port reject */ |
| 14207 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 14208 | case FC_RCTL_P_BSY: /* port busy */ |
| 14209 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 14210 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 14211 | case FC_RCTL_LCR: /* link credit reset */ |
| 14212 | case FC_RCTL_END: /* end */ |
| 14213 | break; |
| 14214 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 14215 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14216 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 14217 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 14218 | default: |
| 14219 | goto drop; |
| 14220 | } |
| 14221 | switch (fc_hdr->fh_type) { |
| 14222 | case FC_TYPE_BLS: |
| 14223 | case FC_TYPE_ELS: |
| 14224 | case FC_TYPE_FCP: |
| 14225 | case FC_TYPE_CT: |
| 14226 | break; |
| 14227 | case FC_TYPE_IP: |
| 14228 | case FC_TYPE_ILS: |
| 14229 | default: |
| 14230 | goto drop; |
| 14231 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14232 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14233 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14234 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
| 14235 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
| 14236 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, |
| 14237 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14238 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 14239 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 14240 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 14241 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14242 | return 0; |
| 14243 | drop: |
| 14244 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 14245 | "2539 Dropped frame rctl:%s type:%s\n", |
| 14246 | rctl_names[fc_hdr->fh_r_ctl], |
| 14247 | type_names[fc_hdr->fh_type]); |
| 14248 | return 1; |
| 14249 | } |
| 14250 | |
| 14251 | /** |
| 14252 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 14253 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14254 | * |
| 14255 | * This function processes the FC header to retrieve the VFI from the VF |
| 14256 | * header, if one exists. This function will return the VFI if one exists |
| 14257 | * or 0 if no VSAN Header exists. |
| 14258 | **/ |
| 14259 | static uint32_t |
| 14260 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 14261 | { |
| 14262 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 14263 | |
| 14264 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 14265 | return 0; |
| 14266 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 14267 | } |
| 14268 | |
| 14269 | /** |
| 14270 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 14271 | * @phba: Pointer to the HBA structure to search for the vport on |
| 14272 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 14273 | * @fcfi: The FC Fabric ID that the frame came from |
| 14274 | * |
| 14275 | * This function searches the @phba for a vport that matches the content of the |
| 14276 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 14277 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 14278 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 14279 | * vport. |
| 14280 | **/ |
| 14281 | static struct lpfc_vport * |
| 14282 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
| 14283 | uint16_t fcfi) |
| 14284 | { |
| 14285 | struct lpfc_vport **vports; |
| 14286 | struct lpfc_vport *vport = NULL; |
| 14287 | int i; |
| 14288 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | |
| 14289 | fc_hdr->fh_d_id[1] << 8 | |
| 14290 | fc_hdr->fh_d_id[2]); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14291 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 14292 | if (did == Fabric_DID) |
| 14293 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14294 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 14295 | !(phba->link_state == LPFC_HBA_READY)) |
| 14296 | return phba->pport; |
| 14297 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14298 | vports = lpfc_create_vport_work_array(phba); |
| 14299 | if (vports != NULL) |
| 14300 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14301 | if (phba->fcf.fcfi == fcfi && |
| 14302 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 14303 | vports[i]->fc_myDID == did) { |
| 14304 | vport = vports[i]; |
| 14305 | break; |
| 14306 | } |
| 14307 | } |
| 14308 | lpfc_destroy_vport_work_array(phba, vports); |
| 14309 | return vport; |
| 14310 | } |
| 14311 | |
| 14312 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14313 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 14314 | * @vport: The vport to work on. |
| 14315 | * |
| 14316 | * This function updates the receive sequence time stamp for this vport. The |
| 14317 | * receive sequence time stamp indicates the time that the last frame of the |
| 14318 | * the sequence that has been idle for the longest amount of time was received. |
| 14319 | * the driver uses this time stamp to indicate if any received sequences have |
| 14320 | * timed out. |
| 14321 | **/ |
| 14322 | void |
| 14323 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 14324 | { |
| 14325 | struct lpfc_dmabuf *h_buf; |
| 14326 | struct hbq_dmabuf *dmabuf = NULL; |
| 14327 | |
| 14328 | /* get the oldest sequence on the rcv list */ |
| 14329 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 14330 | struct lpfc_dmabuf, list); |
| 14331 | if (!h_buf) |
| 14332 | return; |
| 14333 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14334 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 14335 | } |
| 14336 | |
| 14337 | /** |
| 14338 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 14339 | * @vport: The vport that the received sequences were sent to. |
| 14340 | * |
| 14341 | * This function cleans up all outstanding received sequences. This is called |
| 14342 | * by the driver when a link event or user action invalidates all the received |
| 14343 | * sequences. |
| 14344 | **/ |
| 14345 | void |
| 14346 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 14347 | { |
| 14348 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14349 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14350 | struct hbq_dmabuf *dmabuf = NULL; |
| 14351 | |
| 14352 | /* start with the oldest sequence on the rcv list */ |
| 14353 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14354 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14355 | list_del_init(&dmabuf->hbuf.list); |
| 14356 | list_for_each_entry_safe(d_buf, dnext, |
| 14357 | &dmabuf->dbuf.list, list) { |
| 14358 | list_del_init(&d_buf->list); |
| 14359 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14360 | } |
| 14361 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14362 | } |
| 14363 | } |
| 14364 | |
| 14365 | /** |
| 14366 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 14367 | * @vport: The vport that the received sequences were sent to. |
| 14368 | * |
| 14369 | * This function determines whether any received sequences have timed out by |
| 14370 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 14371 | * indicates that there is at least one timed out sequence this routine will |
| 14372 | * go through the received sequences one at a time from most inactive to most |
| 14373 | * active to determine which ones need to be cleaned up. Once it has determined |
| 14374 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 14375 | * without sending an abort. |
| 14376 | **/ |
| 14377 | void |
| 14378 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 14379 | { |
| 14380 | struct lpfc_dmabuf *h_buf, *hnext; |
| 14381 | struct lpfc_dmabuf *d_buf, *dnext; |
| 14382 | struct hbq_dmabuf *dmabuf = NULL; |
| 14383 | unsigned long timeout; |
| 14384 | int abort_count = 0; |
| 14385 | |
| 14386 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14387 | vport->rcv_buffer_time_stamp); |
| 14388 | if (list_empty(&vport->rcv_buffer_list) || |
| 14389 | time_before(jiffies, timeout)) |
| 14390 | return; |
| 14391 | /* start with the oldest sequence on the rcv list */ |
| 14392 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 14393 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14394 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 14395 | dmabuf->time_stamp); |
| 14396 | if (time_before(jiffies, timeout)) |
| 14397 | break; |
| 14398 | abort_count++; |
| 14399 | list_del_init(&dmabuf->hbuf.list); |
| 14400 | list_for_each_entry_safe(d_buf, dnext, |
| 14401 | &dmabuf->dbuf.list, list) { |
| 14402 | list_del_init(&d_buf->list); |
| 14403 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14404 | } |
| 14405 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 14406 | } |
| 14407 | if (abort_count) |
| 14408 | lpfc_update_rcv_time_stamp(vport); |
| 14409 | } |
| 14410 | |
| 14411 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14412 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 14413 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 14414 | * |
| 14415 | * This function searches through the existing incomplete sequences that have |
| 14416 | * been sent to this @vport. If the frame matches one of the incomplete |
| 14417 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 14418 | * make up that sequence. If no sequence is found that matches this frame then |
| 14419 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 14420 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 14421 | * the frame was linked to. |
| 14422 | **/ |
| 14423 | static struct hbq_dmabuf * |
| 14424 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14425 | { |
| 14426 | struct fc_frame_header *new_hdr; |
| 14427 | struct fc_frame_header *temp_hdr; |
| 14428 | struct lpfc_dmabuf *d_buf; |
| 14429 | struct lpfc_dmabuf *h_buf; |
| 14430 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14431 | struct hbq_dmabuf *temp_dmabuf = NULL; |
| 14432 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14433 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14434 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14435 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14436 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 14437 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14438 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14439 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14440 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14441 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14442 | continue; |
| 14443 | /* found a pending sequence that matches this frame */ |
| 14444 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14445 | break; |
| 14446 | } |
| 14447 | if (!seq_dmabuf) { |
| 14448 | /* |
| 14449 | * This indicates first frame received for this sequence. |
| 14450 | * Queue the buffer on the vport's rcv_buffer_list. |
| 14451 | */ |
| 14452 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14453 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14454 | return dmabuf; |
| 14455 | } |
| 14456 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14457 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 14458 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 14459 | list_del_init(&seq_dmabuf->hbuf.list); |
| 14460 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14461 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14462 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14463 | return dmabuf; |
| 14464 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14465 | /* move this sequence to the tail to indicate a young sequence */ |
| 14466 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 14467 | seq_dmabuf->time_stamp = jiffies; |
| 14468 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14469 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 14470 | temp_hdr = dmabuf->hbuf.virt; |
| 14471 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 14472 | return seq_dmabuf; |
| 14473 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14474 | /* find the correct place in the sequence to insert this frame */ |
| 14475 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { |
| 14476 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14477 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 14478 | /* |
| 14479 | * If the frame's sequence count is greater than the frame on |
| 14480 | * the list then insert the frame right after this frame |
| 14481 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14482 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 14483 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14484 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
| 14485 | return seq_dmabuf; |
| 14486 | } |
| 14487 | } |
| 14488 | return NULL; |
| 14489 | } |
| 14490 | |
| 14491 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14492 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 14493 | * @vport: pointer to a vitural port |
| 14494 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14495 | * |
| 14496 | * This function tries to abort from the partially assembed sequence, described |
| 14497 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 14498 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 14499 | * the frames from the partially assembled sequence. |
| 14500 | * |
| 14501 | * Return |
| 14502 | * true -- if there is matching partially assembled sequence present and all |
| 14503 | * the frames freed with the sequence; |
| 14504 | * false -- if there is no matching partially assembled sequence present so |
| 14505 | * nothing got aborted in the lower layer driver |
| 14506 | **/ |
| 14507 | static bool |
| 14508 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 14509 | struct hbq_dmabuf *dmabuf) |
| 14510 | { |
| 14511 | struct fc_frame_header *new_hdr; |
| 14512 | struct fc_frame_header *temp_hdr; |
| 14513 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 14514 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 14515 | |
| 14516 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 14517 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 14518 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 14519 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14520 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 14521 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 14522 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 14523 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 14524 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 14525 | continue; |
| 14526 | /* found a pending sequence that matches this frame */ |
| 14527 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 14528 | break; |
| 14529 | } |
| 14530 | |
| 14531 | /* Free up all the frames from the partially assembled sequence */ |
| 14532 | if (seq_dmabuf) { |
| 14533 | list_for_each_entry_safe(d_buf, n_buf, |
| 14534 | &seq_dmabuf->dbuf.list, list) { |
| 14535 | list_del_init(&d_buf->list); |
| 14536 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14537 | } |
| 14538 | return true; |
| 14539 | } |
| 14540 | return false; |
| 14541 | } |
| 14542 | |
| 14543 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14544 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 14545 | * @vport: pointer to a vitural port |
| 14546 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14547 | * |
| 14548 | * This function tries to abort from the assembed sequence from upper level |
| 14549 | * protocol, described by the information from basic abbort @dmabuf. It |
| 14550 | * checks to see whether such pending context exists at upper level protocol. |
| 14551 | * If so, it shall clean up the pending context. |
| 14552 | * |
| 14553 | * Return |
| 14554 | * true -- if there is matching pending context of the sequence cleaned |
| 14555 | * at ulp; |
| 14556 | * false -- if there is no matching pending context of the sequence present |
| 14557 | * at ulp. |
| 14558 | **/ |
| 14559 | static bool |
| 14560 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 14561 | { |
| 14562 | struct lpfc_hba *phba = vport->phba; |
| 14563 | int handled; |
| 14564 | |
| 14565 | /* Accepting abort at ulp with SLI4 only */ |
| 14566 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 14567 | return false; |
| 14568 | |
| 14569 | /* Register all caring upper level protocols to attend abort */ |
| 14570 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 14571 | if (handled) |
| 14572 | return true; |
| 14573 | |
| 14574 | return false; |
| 14575 | } |
| 14576 | |
| 14577 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14578 | * 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] | 14579 | * @phba: Pointer to HBA context object. |
| 14580 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 14581 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 14582 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14583 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14584 | * event. It properly releases the memory allocated to the sequence abort |
| 14585 | * accept iocb. |
| 14586 | **/ |
| 14587 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14588 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14589 | struct lpfc_iocbq *cmd_iocbq, |
| 14590 | struct lpfc_iocbq *rsp_iocbq) |
| 14591 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14592 | struct lpfc_nodelist *ndlp; |
| 14593 | |
| 14594 | if (cmd_iocbq) { |
| 14595 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 14596 | lpfc_nlp_put(ndlp); |
| 14597 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14598 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14599 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14600 | |
| 14601 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 14602 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 14603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14604 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 14605 | rsp_iocbq->iocb.ulpStatus, |
| 14606 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14607 | } |
| 14608 | |
| 14609 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14610 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 14611 | * @phba: Pointer to HBA context object. |
| 14612 | * @xri: xri id in transaction. |
| 14613 | * |
| 14614 | * This function validates the xri maps to the known range of XRIs allocated an |
| 14615 | * used by the driver. |
| 14616 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14617 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14618 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 14619 | uint16_t xri) |
| 14620 | { |
| 14621 | int i; |
| 14622 | |
| 14623 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 14624 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 14625 | return i; |
| 14626 | } |
| 14627 | return NO_XRI; |
| 14628 | } |
| 14629 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14630 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14631 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14632 | * @phba: Pointer to HBA context object. |
| 14633 | * @fc_hdr: pointer to a FC frame header. |
| 14634 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14635 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14636 | * event after aborting the sequence handling. |
| 14637 | **/ |
| 14638 | static void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14639 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 14640 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14641 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14642 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14643 | struct lpfc_iocbq *ctiocb = NULL; |
| 14644 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14645 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14646 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14647 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14648 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14649 | |
| 14650 | if (!lpfc_is_link_up(phba)) |
| 14651 | return; |
| 14652 | |
| 14653 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 14654 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14655 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14656 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14657 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14658 | if (!ndlp) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14659 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 14660 | if (!ndlp) { |
| 14661 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14662 | "1268 Failed to allocate ndlp for " |
| 14663 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 14664 | return; |
| 14665 | } |
| 14666 | lpfc_nlp_init(vport, ndlp, sid); |
| 14667 | /* Put ndlp onto pport node list */ |
| 14668 | lpfc_enqueue_node(vport, ndlp); |
| 14669 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 14670 | /* re-setup ndlp without removing from node list */ |
| 14671 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 14672 | if (!ndlp) { |
| 14673 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 14674 | "3275 Failed to active ndlp found " |
| 14675 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 14676 | return; |
| 14677 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14678 | } |
| 14679 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14680 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14681 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 14682 | if (!ctiocb) |
| 14683 | return; |
| 14684 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14685 | /* Extract the F_CTL field from FC_HDR */ |
| 14686 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 14687 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14688 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14689 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14690 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14691 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 14692 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 14693 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 14694 | |
| 14695 | /* Fill in the rest of iocb fields */ |
| 14696 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 14697 | icmd->ulpBdeCount = 0; |
| 14698 | icmd->ulpLe = 1; |
| 14699 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14700 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14701 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14702 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14703 | ctiocb->iocb_cmpl = NULL; |
| 14704 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14705 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 14706 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14707 | ctiocb->sli4_xritag = NO_XRI; |
| 14708 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 14709 | if (fctl & FC_FC_EX_CTX) |
| 14710 | /* Exchange responder sent the abort so we |
| 14711 | * own the oxid. |
| 14712 | */ |
| 14713 | xri = oxid; |
| 14714 | else |
| 14715 | xri = rxid; |
| 14716 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 14717 | if (lxri != NO_XRI) |
| 14718 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 14719 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14720 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 14721 | * the oxid maps to the FCP XRI range, the port no longer has |
| 14722 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 14723 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14724 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14725 | if ((fctl & FC_FC_EX_CTX) && |
| 14726 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { |
| 14727 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14728 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14729 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14730 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14731 | } |
| 14732 | |
| 14733 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 14734 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 14735 | * the IOCB for a BA_RJT. |
| 14736 | */ |
| 14737 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14738 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 14739 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 14740 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 14741 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 14742 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14743 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14744 | if (fctl & FC_FC_EX_CTX) { |
| 14745 | /* ABTS sent by responder to CT exchange, construction |
| 14746 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 14747 | * field and RX_ID from ABTS for RX_ID field. |
| 14748 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14749 | 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] | 14750 | } else { |
| 14751 | /* ABTS sent by initiator to CT exchange, construction |
| 14752 | * 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] | 14753 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14754 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14755 | 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] | 14756 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 14757 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14758 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14759 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14760 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14761 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 14762 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 14763 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14764 | |
| 14765 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 14766 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14767 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 14768 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 14769 | "xri x%x, Data x%x\n", |
| 14770 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 14771 | phba->link_state); |
| 14772 | lpfc_nlp_put(ndlp); |
| 14773 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 14774 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 14775 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14776 | } |
| 14777 | |
| 14778 | /** |
| 14779 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 14780 | * @vport: Pointer to the vport on which this sequence was received |
| 14781 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14782 | * |
| 14783 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 14784 | * receive sequence is only partially assembed by the driver, it shall abort |
| 14785 | * the partially assembled frames for the sequence. Otherwise, if the |
| 14786 | * unsolicited receive sequence has been completely assembled and passed to |
| 14787 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 14788 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 14789 | * accept to accept the abort. |
| 14790 | **/ |
| 14791 | void |
| 14792 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 14793 | struct hbq_dmabuf *dmabuf) |
| 14794 | { |
| 14795 | struct lpfc_hba *phba = vport->phba; |
| 14796 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14797 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14798 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14799 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14800 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 14801 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14802 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14803 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14804 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14805 | /* ABTS by responder to exchange, no cleanup needed */ |
| 14806 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14807 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14808 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 14809 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 14810 | if (aborted == false) |
| 14811 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 14812 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 14813 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 14814 | |
| 14815 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 14816 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14817 | } |
| 14818 | |
| 14819 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14820 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 14821 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14822 | * |
| 14823 | * This function checks the sequence, starting with the frame described by |
| 14824 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 14825 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 14826 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 14827 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 14828 | * set. 3) That there are no holes in the sequence count. The function will |
| 14829 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 14830 | **/ |
| 14831 | static int |
| 14832 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 14833 | { |
| 14834 | struct fc_frame_header *hdr; |
| 14835 | struct lpfc_dmabuf *d_buf; |
| 14836 | struct hbq_dmabuf *seq_dmabuf; |
| 14837 | uint32_t fctl; |
| 14838 | int seq_count = 0; |
| 14839 | |
| 14840 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 14841 | /* make sure first fame of sequence has a sequence count of zero */ |
| 14842 | if (hdr->fh_seq_cnt != seq_count) |
| 14843 | return 0; |
| 14844 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14845 | hdr->fh_f_ctl[1] << 8 | |
| 14846 | hdr->fh_f_ctl[2]); |
| 14847 | /* If last frame of sequence we can return success. */ |
| 14848 | if (fctl & FC_FC_END_SEQ) |
| 14849 | return 1; |
| 14850 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 14851 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14852 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14853 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14854 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14855 | return 0; |
| 14856 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 14857 | hdr->fh_f_ctl[1] << 8 | |
| 14858 | hdr->fh_f_ctl[2]); |
| 14859 | /* If last frame of sequence we can return success. */ |
| 14860 | if (fctl & FC_FC_END_SEQ) |
| 14861 | return 1; |
| 14862 | } |
| 14863 | return 0; |
| 14864 | } |
| 14865 | |
| 14866 | /** |
| 14867 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 14868 | * @vport: Pointer to the vport on which this sequence was received |
| 14869 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 14870 | * |
| 14871 | * This function takes a sequence, described by a list of frames, and creates |
| 14872 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 14873 | * used to issue to the generic unsolicited sequence handler. This routine |
| 14874 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 14875 | * to allocate an iocbq then it throw out the received frames that were not |
| 14876 | * able to be described and return a pointer to the first iocbq. If unable to |
| 14877 | * allocate any iocbqs (including the first) this function will return NULL. |
| 14878 | **/ |
| 14879 | static struct lpfc_iocbq * |
| 14880 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 14881 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14882 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14883 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 14884 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 14885 | struct fc_frame_header *fc_hdr; |
| 14886 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14887 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 14888 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14889 | |
| 14890 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 14891 | /* remove from receive buffer list */ |
| 14892 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 14893 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14894 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14895 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14896 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14897 | /* Get an iocbq struct to fill in. */ |
| 14898 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14899 | if (first_iocbq) { |
| 14900 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14901 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14902 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 14903 | |
| 14904 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 14905 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 14906 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 14907 | first_iocbq->iocb.un.rcvels.parmRo = |
| 14908 | sli4_did_from_fc_hdr(fc_hdr); |
| 14909 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 14910 | } else |
| 14911 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14912 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 14913 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 14914 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 14915 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 14916 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 14917 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14918 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14919 | tot_len = bf_get(lpfc_rcqe_length, |
| 14920 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 14921 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14922 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 14923 | first_iocbq->context3 = NULL; |
| 14924 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14925 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 14926 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14927 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14928 | else |
| 14929 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 14930 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14931 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14932 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14933 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14934 | } |
| 14935 | iocbq = first_iocbq; |
| 14936 | /* |
| 14937 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 14938 | * of buffers for this sequence and save two buffers in each IOCBq |
| 14939 | */ |
| 14940 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 14941 | if (!iocbq) { |
| 14942 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14943 | continue; |
| 14944 | } |
| 14945 | if (!iocbq->context3) { |
| 14946 | iocbq->context3 = d_buf; |
| 14947 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14948 | /* We need to get the size out of the right CQE */ |
| 14949 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14950 | len = bf_get(lpfc_rcqe_length, |
| 14951 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14952 | pbde = (struct ulp_bde64 *) |
| 14953 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 14954 | if (len > LPFC_DATA_BUF_SIZE) |
| 14955 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 14956 | else |
| 14957 | pbde->tus.f.bdeSize = len; |
| 14958 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14959 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 14960 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14961 | } else { |
| 14962 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 14963 | if (!iocbq) { |
| 14964 | if (first_iocbq) { |
| 14965 | first_iocbq->iocb.ulpStatus = |
| 14966 | IOSTAT_FCP_RSP_ERROR; |
| 14967 | first_iocbq->iocb.un.ulpWord[4] = |
| 14968 | IOERR_NO_RESOURCES; |
| 14969 | } |
| 14970 | lpfc_in_buf_free(vport->phba, d_buf); |
| 14971 | continue; |
| 14972 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14973 | /* We need to get the size out of the right CQE */ |
| 14974 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 14975 | len = bf_get(lpfc_rcqe_length, |
| 14976 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 14977 | iocbq->context2 = d_buf; |
| 14978 | iocbq->context3 = NULL; |
| 14979 | iocbq->iocb.ulpBdeCount = 1; |
| 14980 | if (len > LPFC_DATA_BUF_SIZE) |
| 14981 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 14982 | LPFC_DATA_BUF_SIZE; |
| 14983 | else |
| 14984 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 14985 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 14986 | tot_len += len; |
| 14987 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 14988 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14989 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 14990 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 14991 | } |
| 14992 | } |
| 14993 | return first_iocbq; |
| 14994 | } |
| 14995 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14996 | static void |
| 14997 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 14998 | struct hbq_dmabuf *seq_dmabuf) |
| 14999 | { |
| 15000 | struct fc_frame_header *fc_hdr; |
| 15001 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 15002 | struct lpfc_hba *phba = vport->phba; |
| 15003 | |
| 15004 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 15005 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 15006 | if (!iocbq) { |
| 15007 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15008 | "2707 Ring %d handler: Failed to allocate " |
| 15009 | "iocb Rctl x%x Type x%x received\n", |
| 15010 | LPFC_ELS_RING, |
| 15011 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15012 | return; |
| 15013 | } |
| 15014 | if (!lpfc_complete_unsol_iocb(phba, |
| 15015 | &phba->sli.ring[LPFC_ELS_RING], |
| 15016 | iocbq, fc_hdr->fh_r_ctl, |
| 15017 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15019 | "2540 Ring %d handler: unexpected Rctl " |
| 15020 | "x%x Type x%x received\n", |
| 15021 | LPFC_ELS_RING, |
| 15022 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 15023 | |
| 15024 | /* Free iocb created in lpfc_prep_seq */ |
| 15025 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 15026 | &iocbq->list, list) { |
| 15027 | list_del_init(&curr_iocb->list); |
| 15028 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 15029 | } |
| 15030 | lpfc_sli_release_iocbq(phba, iocbq); |
| 15031 | } |
| 15032 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15033 | /** |
| 15034 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 15035 | * @phba: Pointer to HBA context object. |
| 15036 | * |
| 15037 | * This function is called with no lock held. This function processes all |
| 15038 | * the received buffers and gives it to upper layers when a received buffer |
| 15039 | * indicates that it is the final frame in the sequence. The interrupt |
| 15040 | * service routine processes received buffers at interrupt contexts and adds |
| 15041 | * received dma buffers to the rb_pend_list queue and signals the worker thread. |
| 15042 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 15043 | * appropriate receive function when the final frame in a sequence is received. |
| 15044 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15045 | void |
| 15046 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 15047 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15048 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15049 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15050 | struct fc_frame_header *fc_hdr; |
| 15051 | struct lpfc_vport *vport; |
| 15052 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15053 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15054 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15055 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15056 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 15057 | /* check to see if this a valid type of frame */ |
| 15058 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 15059 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15060 | return; |
| 15061 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 15062 | if ((bf_get(lpfc_cqe_code, |
| 15063 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 15064 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 15065 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 15066 | else |
| 15067 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 15068 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15069 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15070 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15071 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15072 | /* throw out the frame */ |
| 15073 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15074 | return; |
| 15075 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 15076 | |
| 15077 | /* d_id this frame is directed to */ |
| 15078 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 15079 | |
| 15080 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 15081 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 15082 | (did != Fabric_DID)) { |
| 15083 | /* |
| 15084 | * Throw out the frame if we are not pt2pt. |
| 15085 | * The pt2pt protocol allows for discovery frames |
| 15086 | * to be received without a registered VPI. |
| 15087 | */ |
| 15088 | if (!(vport->fc_flag & FC_PT2PT) || |
| 15089 | (phba->link_state == LPFC_HBA_READY)) { |
| 15090 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15091 | return; |
| 15092 | } |
| 15093 | } |
| 15094 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15095 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 15096 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 15097 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 15098 | return; |
| 15099 | } |
| 15100 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15101 | /* Link this frame */ |
| 15102 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 15103 | if (!seq_dmabuf) { |
| 15104 | /* unable to add frame to vport - throw it out */ |
| 15105 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 15106 | return; |
| 15107 | } |
| 15108 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15109 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15110 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 15111 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 15112 | /* Send the complete sequence to the upper layer protocol */ |
| 15113 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15114 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15115 | |
| 15116 | /** |
| 15117 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 15118 | * @phba: pointer to lpfc hba data structure. |
| 15119 | * |
| 15120 | * This routine is invoked to post rpi header templates to the |
| 15121 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15122 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15123 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15124 | * |
| 15125 | * This routine does not require any locks. It's usage is expected |
| 15126 | * to be driver load or reset recovery when the driver is |
| 15127 | * sequential. |
| 15128 | * |
| 15129 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15130 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15131 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15132 | * When this error occurs, the driver is not guaranteed |
| 15133 | * to have any rpi regions posted to the device and |
| 15134 | * must either attempt to repost the regions or take a |
| 15135 | * fatal error. |
| 15136 | **/ |
| 15137 | int |
| 15138 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 15139 | { |
| 15140 | struct lpfc_rpi_hdr *rpi_page; |
| 15141 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15142 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15143 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15144 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15145 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15146 | goto exit; |
| 15147 | if (phba->sli4_hba.extents_in_use) |
| 15148 | return -EIO; |
| 15149 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15150 | 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] | 15151 | /* |
| 15152 | * Assign the rpi headers a physical rpi only if the driver |
| 15153 | * has not initialized those resources. A port reset only |
| 15154 | * needs the headers posted. |
| 15155 | */ |
| 15156 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 15157 | LPFC_RPI_RSRC_RDY) |
| 15158 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 15159 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15160 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 15161 | if (rc != MBX_SUCCESS) { |
| 15162 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15163 | "2008 Error %d posting all rpi " |
| 15164 | "headers\n", rc); |
| 15165 | rc = -EIO; |
| 15166 | break; |
| 15167 | } |
| 15168 | } |
| 15169 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15170 | exit: |
| 15171 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 15172 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15173 | return rc; |
| 15174 | } |
| 15175 | |
| 15176 | /** |
| 15177 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 15178 | * @phba: pointer to lpfc hba data structure. |
| 15179 | * @rpi_page: pointer to the rpi memory region. |
| 15180 | * |
| 15181 | * This routine is invoked to post a single rpi header to the |
| 15182 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 15183 | * maps up to 64 rpi context regions. |
| 15184 | * |
| 15185 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15186 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15187 | * -ENOMEM - No available memory |
| 15188 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15189 | **/ |
| 15190 | int |
| 15191 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 15192 | { |
| 15193 | LPFC_MBOXQ_t *mboxq; |
| 15194 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 15195 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15196 | uint32_t shdr_status, shdr_add_status; |
| 15197 | union lpfc_sli4_cfg_shdr *shdr; |
| 15198 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15199 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 15200 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 15201 | return rc; |
| 15202 | if (phba->sli4_hba.extents_in_use) |
| 15203 | return -EIO; |
| 15204 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15205 | /* The port is notified of the header region via a mailbox command. */ |
| 15206 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15207 | if (!mboxq) { |
| 15208 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15209 | "2001 Unable to allocate memory for issuing " |
| 15210 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 15211 | return -ENOMEM; |
| 15212 | } |
| 15213 | |
| 15214 | /* Post all rpi memory regions to the port. */ |
| 15215 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15216 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15217 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 15218 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15219 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 15220 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15221 | |
| 15222 | |
| 15223 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15224 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 15225 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15226 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 15227 | hdr_tmpl, rpi_page->page_count); |
| 15228 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15229 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 15230 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 15231 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15232 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 15233 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15234 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15235 | if (rc != MBX_TIMEOUT) |
| 15236 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15237 | if (shdr_status || shdr_add_status || rc) { |
| 15238 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15239 | "2514 POST_RPI_HDR mailbox failed with " |
| 15240 | "status x%x add_status x%x, mbx status x%x\n", |
| 15241 | shdr_status, shdr_add_status, rc); |
| 15242 | rc = -ENXIO; |
| 15243 | } |
| 15244 | return rc; |
| 15245 | } |
| 15246 | |
| 15247 | /** |
| 15248 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 15249 | * @phba: pointer to lpfc hba data structure. |
| 15250 | * |
| 15251 | * This routine is invoked to post rpi header templates to the |
| 15252 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15253 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15254 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15255 | * |
| 15256 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 15257 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15258 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15259 | **/ |
| 15260 | int |
| 15261 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 15262 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15263 | unsigned long rpi; |
| 15264 | uint16_t max_rpi, rpi_limit; |
| 15265 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15266 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15267 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15268 | |
| 15269 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15270 | rpi_limit = phba->sli4_hba.next_rpi; |
| 15271 | |
| 15272 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15273 | * Fetch the next logical rpi. Because this index is logical, |
| 15274 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15275 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15276 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15277 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 15278 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15279 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 15280 | else { |
| 15281 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 15282 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 15283 | phba->sli4_hba.rpi_count++; |
| 15284 | } |
| 15285 | |
| 15286 | /* |
| 15287 | * 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] | 15288 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15289 | */ |
| 15290 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 15291 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15292 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15293 | return rpi; |
| 15294 | } |
| 15295 | |
| 15296 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15297 | * RPI header postings are not required for SLI4 ports capable of |
| 15298 | * extents. |
| 15299 | */ |
| 15300 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15301 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15302 | return rpi; |
| 15303 | } |
| 15304 | |
| 15305 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15306 | * If the driver is running low on rpi resources, allocate another |
| 15307 | * page now. Note that the next_rpi value is used because |
| 15308 | * it represents how many are actually in use whereas max_rpi notes |
| 15309 | * how many are supported max by the device. |
| 15310 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15311 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 15312 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15313 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 15314 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 15315 | if (!rpi_hdr) { |
| 15316 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15317 | "2002 Error Could not grow rpi " |
| 15318 | "count\n"); |
| 15319 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15320 | lrpi = rpi_hdr->start_rpi; |
| 15321 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15322 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 15323 | } |
| 15324 | } |
| 15325 | |
| 15326 | return rpi; |
| 15327 | } |
| 15328 | |
| 15329 | /** |
| 15330 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15331 | * @phba: pointer to lpfc hba data structure. |
| 15332 | * |
| 15333 | * This routine is invoked to release an rpi to the pool of |
| 15334 | * available rpis maintained by the driver. |
| 15335 | **/ |
| 15336 | void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15337 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15338 | { |
| 15339 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 15340 | phba->sli4_hba.rpi_count--; |
| 15341 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 15342 | } |
| 15343 | } |
| 15344 | |
| 15345 | /** |
| 15346 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 15347 | * @phba: pointer to lpfc hba data structure. |
| 15348 | * |
| 15349 | * This routine is invoked to release an rpi to the pool of |
| 15350 | * available rpis maintained by the driver. |
| 15351 | **/ |
| 15352 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15353 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 15354 | { |
| 15355 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 15356 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15357 | spin_unlock_irq(&phba->hbalock); |
| 15358 | } |
| 15359 | |
| 15360 | /** |
| 15361 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 15362 | * @phba: pointer to lpfc hba data structure. |
| 15363 | * |
| 15364 | * This routine is invoked to remove the memory region that |
| 15365 | * provided rpi via a bitmask. |
| 15366 | **/ |
| 15367 | void |
| 15368 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 15369 | { |
| 15370 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15371 | kfree(phba->sli4_hba.rpi_ids); |
| 15372 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15373 | } |
| 15374 | |
| 15375 | /** |
| 15376 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 15377 | * @phba: pointer to lpfc hba data structure. |
| 15378 | * |
| 15379 | * This routine is invoked to remove the memory region that |
| 15380 | * provided rpi via a bitmask. |
| 15381 | **/ |
| 15382 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15383 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 15384 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15385 | { |
| 15386 | LPFC_MBOXQ_t *mboxq; |
| 15387 | struct lpfc_hba *phba = ndlp->phba; |
| 15388 | int rc; |
| 15389 | |
| 15390 | /* The port is notified of the header region via a mailbox command. */ |
| 15391 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15392 | if (!mboxq) |
| 15393 | return -ENOMEM; |
| 15394 | |
| 15395 | /* Post all rpi memory regions to the port. */ |
| 15396 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15397 | if (cmpl) { |
| 15398 | mboxq->mbox_cmpl = cmpl; |
| 15399 | mboxq->context1 = arg; |
| 15400 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 15401 | } else |
| 15402 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 15403 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15404 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15405 | if (rc == MBX_NOT_FINISHED) { |
| 15406 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15407 | "2010 Resume RPI Mailbox failed " |
| 15408 | "status %d, mbxStatus x%x\n", rc, |
| 15409 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 15410 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 15411 | return -EIO; |
| 15412 | } |
| 15413 | return 0; |
| 15414 | } |
| 15415 | |
| 15416 | /** |
| 15417 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15418 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15419 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15420 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15421 | * |
| 15422 | * Returns: |
| 15423 | * 0 success |
| 15424 | * -Evalue otherwise |
| 15425 | **/ |
| 15426 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15427 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15428 | { |
| 15429 | LPFC_MBOXQ_t *mboxq; |
| 15430 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15431 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15432 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15433 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15434 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15435 | if (!mboxq) |
| 15436 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15437 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15438 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15439 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15440 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15441 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15442 | "2022 INIT VPI Mailbox failed " |
| 15443 | "status %d, mbxStatus x%x\n", rc, |
| 15444 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15445 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15446 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15447 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 15448 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 15449 | |
| 15450 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15451 | } |
| 15452 | |
| 15453 | /** |
| 15454 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 15455 | * @phba: pointer to lpfc hba data structure. |
| 15456 | * @mboxq: Pointer to mailbox object. |
| 15457 | * |
| 15458 | * This routine is invoked to manually add a single FCF record. The caller |
| 15459 | * must pass a completely initialized FCF_Record. This routine takes |
| 15460 | * care of the nonembedded mailbox operations. |
| 15461 | **/ |
| 15462 | static void |
| 15463 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 15464 | { |
| 15465 | void *virt_addr; |
| 15466 | union lpfc_sli4_cfg_shdr *shdr; |
| 15467 | uint32_t shdr_status, shdr_add_status; |
| 15468 | |
| 15469 | virt_addr = mboxq->sge_array->addr[0]; |
| 15470 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15471 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 15472 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15473 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15474 | |
| 15475 | if ((shdr_status || shdr_add_status) && |
| 15476 | (shdr_status != STATUS_FCF_IN_USE)) |
| 15477 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15478 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 15479 | "status x%x add_status x%x\n", |
| 15480 | shdr_status, shdr_add_status); |
| 15481 | |
| 15482 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15483 | } |
| 15484 | |
| 15485 | /** |
| 15486 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 15487 | * @phba: pointer to lpfc hba data structure. |
| 15488 | * @fcf_record: pointer to the initialized fcf record to add. |
| 15489 | * |
| 15490 | * This routine is invoked to manually add a single FCF record. The caller |
| 15491 | * must pass a completely initialized FCF_Record. This routine takes |
| 15492 | * care of the nonembedded mailbox operations. |
| 15493 | **/ |
| 15494 | int |
| 15495 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 15496 | { |
| 15497 | int rc = 0; |
| 15498 | LPFC_MBOXQ_t *mboxq; |
| 15499 | uint8_t *bytep; |
| 15500 | void *virt_addr; |
| 15501 | dma_addr_t phys_addr; |
| 15502 | struct lpfc_mbx_sge sge; |
| 15503 | uint32_t alloc_len, req_len; |
| 15504 | uint32_t fcfindex; |
| 15505 | |
| 15506 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15507 | if (!mboxq) { |
| 15508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15509 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 15510 | return -ENOMEM; |
| 15511 | } |
| 15512 | |
| 15513 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 15514 | sizeof(uint32_t); |
| 15515 | |
| 15516 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 15517 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15518 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 15519 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 15520 | if (alloc_len < req_len) { |
| 15521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15522 | "2523 Allocated DMA memory size (x%x) is " |
| 15523 | "less than the requested DMA memory " |
| 15524 | "size (x%x)\n", alloc_len, req_len); |
| 15525 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15526 | return -ENOMEM; |
| 15527 | } |
| 15528 | |
| 15529 | /* |
| 15530 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 15531 | * routine only uses a single SGE. |
| 15532 | */ |
| 15533 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 15534 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15535 | virt_addr = mboxq->sge_array->addr[0]; |
| 15536 | /* |
| 15537 | * Configure the FCF record for FCFI 0. This is the driver's |
| 15538 | * hardcoded default and gets used in nonFIP mode. |
| 15539 | */ |
| 15540 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 15541 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 15542 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 15543 | |
| 15544 | /* |
| 15545 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 15546 | * the FCoE header plus word10. The data copy needs to be endian |
| 15547 | * correct. |
| 15548 | */ |
| 15549 | bytep += sizeof(uint32_t); |
| 15550 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 15551 | mboxq->vport = phba->pport; |
| 15552 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 15553 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15554 | if (rc == MBX_NOT_FINISHED) { |
| 15555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15556 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 15557 | "status 0x%x\n", rc); |
| 15558 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15559 | rc = -EIO; |
| 15560 | } else |
| 15561 | rc = 0; |
| 15562 | |
| 15563 | return rc; |
| 15564 | } |
| 15565 | |
| 15566 | /** |
| 15567 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 15568 | * @phba: pointer to lpfc hba data structure. |
| 15569 | * @fcf_record: pointer to the fcf record to write the default data. |
| 15570 | * @fcf_index: FCF table entry index. |
| 15571 | * |
| 15572 | * This routine is invoked to build the driver's default FCF record. The |
| 15573 | * values used are hardcoded. This routine handles memory initialization. |
| 15574 | * |
| 15575 | **/ |
| 15576 | void |
| 15577 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 15578 | struct fcf_record *fcf_record, |
| 15579 | uint16_t fcf_index) |
| 15580 | { |
| 15581 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 15582 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 15583 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 15584 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 15585 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 15586 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 15587 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 15588 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 15589 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 15590 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 15591 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 15592 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 15593 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 15594 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 15595 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15596 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 15597 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 15598 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 15599 | /* Set the VLAN bit map */ |
| 15600 | if (phba->valid_vlan) { |
| 15601 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 15602 | = 1 << (phba->vlan_id % 8); |
| 15603 | } |
| 15604 | } |
| 15605 | |
| 15606 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15607 | * 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] | 15608 | * @phba: pointer to lpfc hba data structure. |
| 15609 | * @fcf_index: FCF table entry offset. |
| 15610 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15611 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 15612 | * record and processing it one at a time starting from the @fcf_index |
| 15613 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 15614 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15615 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15616 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15617 | **/ |
| 15618 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15619 | 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] | 15620 | { |
| 15621 | int rc = 0, error; |
| 15622 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15623 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15624 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 15625 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15626 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15627 | if (!mboxq) { |
| 15628 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15629 | "2000 Failed to allocate mbox for " |
| 15630 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15631 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15632 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15633 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15634 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15635 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15636 | if (rc) { |
| 15637 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15638 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15639 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15640 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15641 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15642 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15643 | |
| 15644 | spin_lock_irq(&phba->hbalock); |
| 15645 | phba->hba_flag |= FCF_TS_INPROG; |
| 15646 | spin_unlock_irq(&phba->hbalock); |
| 15647 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15648 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15649 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15650 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15651 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 15652 | /* Reset eligible FCF count for new scan */ |
| 15653 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 15654 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15655 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 15656 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15657 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15658 | if (error) { |
| 15659 | if (mboxq) |
| 15660 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15661 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15662 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15663 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 15664 | spin_unlock_irq(&phba->hbalock); |
| 15665 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 15666 | return error; |
| 15667 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 15668 | |
| 15669 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15670 | * 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] | 15671 | * @phba: pointer to lpfc hba data structure. |
| 15672 | * @fcf_index: FCF table entry offset. |
| 15673 | * |
| 15674 | * 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] | 15675 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15676 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15677 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15678 | * otherwise. |
| 15679 | **/ |
| 15680 | int |
| 15681 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15682 | { |
| 15683 | int rc = 0, error; |
| 15684 | LPFC_MBOXQ_t *mboxq; |
| 15685 | |
| 15686 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15687 | if (!mboxq) { |
| 15688 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15689 | "2763 Failed to allocate mbox for " |
| 15690 | "READ_FCF cmd\n"); |
| 15691 | error = -ENOMEM; |
| 15692 | goto fail_fcf_read; |
| 15693 | } |
| 15694 | /* Construct the read FCF record mailbox command */ |
| 15695 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15696 | if (rc) { |
| 15697 | error = -EINVAL; |
| 15698 | goto fail_fcf_read; |
| 15699 | } |
| 15700 | /* Issue the mailbox command asynchronously */ |
| 15701 | mboxq->vport = phba->pport; |
| 15702 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 15703 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15704 | if (rc == MBX_NOT_FINISHED) |
| 15705 | error = -EIO; |
| 15706 | else |
| 15707 | error = 0; |
| 15708 | |
| 15709 | fail_fcf_read: |
| 15710 | if (error && mboxq) |
| 15711 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15712 | return error; |
| 15713 | } |
| 15714 | |
| 15715 | /** |
| 15716 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 15717 | * @phba: pointer to lpfc hba data structure. |
| 15718 | * @fcf_index: FCF table entry offset. |
| 15719 | * |
| 15720 | * 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] | 15721 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15722 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 15723 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15724 | * otherwise. |
| 15725 | **/ |
| 15726 | int |
| 15727 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15728 | { |
| 15729 | int rc = 0, error; |
| 15730 | LPFC_MBOXQ_t *mboxq; |
| 15731 | |
| 15732 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15733 | if (!mboxq) { |
| 15734 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 15735 | "2758 Failed to allocate mbox for " |
| 15736 | "READ_FCF cmd\n"); |
| 15737 | error = -ENOMEM; |
| 15738 | goto fail_fcf_read; |
| 15739 | } |
| 15740 | /* Construct the read FCF record mailbox command */ |
| 15741 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 15742 | if (rc) { |
| 15743 | error = -EINVAL; |
| 15744 | goto fail_fcf_read; |
| 15745 | } |
| 15746 | /* Issue the mailbox command asynchronously */ |
| 15747 | mboxq->vport = phba->pport; |
| 15748 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 15749 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 15750 | if (rc == MBX_NOT_FINISHED) |
| 15751 | error = -EIO; |
| 15752 | else |
| 15753 | error = 0; |
| 15754 | |
| 15755 | fail_fcf_read: |
| 15756 | if (error && mboxq) |
| 15757 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 15758 | return error; |
| 15759 | } |
| 15760 | |
| 15761 | /** |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15762 | * lpfc_check_next_fcf_pri |
| 15763 | * phba pointer to the lpfc_hba struct for this port. |
| 15764 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 15765 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 15766 | * rr_bmask based on their priority level. Starting from the highest priority |
| 15767 | * to the lowest. The most likely FCF candidate will be in the highest |
| 15768 | * priority group. When this routine is called it searches the fcf_pri list for |
| 15769 | * next lowest priority group and repopulates the rr_bmask with only those |
| 15770 | * fcf_indexes. |
| 15771 | * returns: |
| 15772 | * 1=success 0=failure |
| 15773 | **/ |
| 15774 | int |
| 15775 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 15776 | { |
| 15777 | uint16_t next_fcf_pri; |
| 15778 | uint16_t last_index; |
| 15779 | struct lpfc_fcf_pri *fcf_pri; |
| 15780 | int rc; |
| 15781 | int ret = 0; |
| 15782 | |
| 15783 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 15784 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15785 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 15786 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 15787 | |
| 15788 | /* Verify the priority list has 2 or more entries */ |
| 15789 | spin_lock_irq(&phba->hbalock); |
| 15790 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 15791 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 15792 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15793 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 15794 | "3061 Last IDX %d\n", last_index); |
| 15795 | return 0; /* Empty rr list */ |
| 15796 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 15797 | spin_unlock_irq(&phba->hbalock); |
| 15798 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15799 | next_fcf_pri = 0; |
| 15800 | /* |
| 15801 | * Clear the rr_bmask and set all of the bits that are at this |
| 15802 | * priority. |
| 15803 | */ |
| 15804 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 15805 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 15806 | spin_lock_irq(&phba->hbalock); |
| 15807 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15808 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 15809 | continue; |
| 15810 | /* |
| 15811 | * the 1st priority that has not FLOGI failed |
| 15812 | * will be the highest. |
| 15813 | */ |
| 15814 | if (!next_fcf_pri) |
| 15815 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15816 | spin_unlock_irq(&phba->hbalock); |
| 15817 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15818 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15819 | fcf_pri->fcf_rec.fcf_index); |
| 15820 | if (rc) |
| 15821 | return 0; |
| 15822 | } |
| 15823 | spin_lock_irq(&phba->hbalock); |
| 15824 | } |
| 15825 | /* |
| 15826 | * if next_fcf_pri was not set above and the list is not empty then |
| 15827 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 15828 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15829 | */ |
| 15830 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 15831 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 15832 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 15833 | /* |
| 15834 | * the 1st priority that has not FLOGI failed |
| 15835 | * will be the highest. |
| 15836 | */ |
| 15837 | if (!next_fcf_pri) |
| 15838 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 15839 | spin_unlock_irq(&phba->hbalock); |
| 15840 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 15841 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 15842 | fcf_pri->fcf_rec.fcf_index); |
| 15843 | if (rc) |
| 15844 | return 0; |
| 15845 | } |
| 15846 | spin_lock_irq(&phba->hbalock); |
| 15847 | } |
| 15848 | } else |
| 15849 | ret = 1; |
| 15850 | spin_unlock_irq(&phba->hbalock); |
| 15851 | |
| 15852 | return ret; |
| 15853 | } |
| 15854 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15855 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 15856 | * @phba: pointer to lpfc hba data structure. |
| 15857 | * |
| 15858 | * This routine is to get the next eligible FCF record index in a round |
| 15859 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15860 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15861 | * shall be returned, otherwise, the next eligible FCF record's index |
| 15862 | * shall be returned. |
| 15863 | **/ |
| 15864 | uint16_t |
| 15865 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 15866 | { |
| 15867 | uint16_t next_fcf_index; |
| 15868 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15869 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15870 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15871 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 15872 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15873 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15874 | /* Determine the next fcf index to check */ |
| 15875 | 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] | 15876 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15877 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15878 | next_fcf_index); |
| 15879 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15880 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15881 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15882 | /* |
| 15883 | * If we have wrapped then we need to clear the bits that |
| 15884 | * have been tested so that we can detect when we should |
| 15885 | * change the priority level. |
| 15886 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15887 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 15888 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15889 | } |
| 15890 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15891 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15892 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15893 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 15894 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 15895 | /* |
| 15896 | * If next fcf index is not found check if there are lower |
| 15897 | * Priority level fcf's in the fcf_priority list. |
| 15898 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 15899 | * at that level and continue the selection process. |
| 15900 | */ |
| 15901 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 15902 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15903 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15904 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15905 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 15906 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 15907 | else { |
| 15908 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 15909 | "3063 Only FCF available idx %d, flag %x\n", |
| 15910 | next_fcf_index, |
| 15911 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 15912 | return next_fcf_index; |
| 15913 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15914 | } |
| 15915 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15916 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 15917 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
| 15918 | LPFC_FCF_FLOGI_FAILED) |
| 15919 | goto next_priority; |
| 15920 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15921 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15922 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 15923 | next_fcf_index); |
| 15924 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15925 | return next_fcf_index; |
| 15926 | } |
| 15927 | |
| 15928 | /** |
| 15929 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 15930 | * @phba: pointer to lpfc hba data structure. |
| 15931 | * |
| 15932 | * 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] | 15933 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15934 | * does not go beyond the range of the driver allocated bmask dimension |
| 15935 | * before setting the bit. |
| 15936 | * |
| 15937 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 15938 | * -EINVAL. |
| 15939 | **/ |
| 15940 | int |
| 15941 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15942 | { |
| 15943 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15944 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15945 | "2610 FCF (x%x) reached driver's book " |
| 15946 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15947 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15948 | return -EINVAL; |
| 15949 | } |
| 15950 | /* Set the eligible FCF record index bmask */ |
| 15951 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 15952 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15953 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15954 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15955 | "bmask\n", fcf_index); |
| 15956 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15957 | return 0; |
| 15958 | } |
| 15959 | |
| 15960 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15961 | * 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] | 15962 | * @phba: pointer to lpfc hba data structure. |
| 15963 | * |
| 15964 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15965 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15966 | * does not go beyond the range of the driver allocated bmask dimension |
| 15967 | * before clearing the bit. |
| 15968 | **/ |
| 15969 | void |
| 15970 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 15971 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 15972 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15973 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 15974 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15975 | "2762 FCF (x%x) reached driver's book " |
| 15976 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15977 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 15978 | return; |
| 15979 | } |
| 15980 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15981 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 15982 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 15983 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 15984 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 15985 | list_del_init(&fcf_pri->list); |
| 15986 | break; |
| 15987 | } |
| 15988 | } |
| 15989 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15990 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15991 | |
| 15992 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 15993 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 15994 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 15995 | } |
| 15996 | |
| 15997 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 15998 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 15999 | * @phba: pointer to lpfc hba data structure. |
| 16000 | * |
| 16001 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 16002 | * command. If the mailbox command returned failure, it will try to stop the |
| 16003 | * FCF rediscover wait timer. |
| 16004 | **/ |
| 16005 | void |
| 16006 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 16007 | { |
| 16008 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16009 | uint32_t shdr_status, shdr_add_status; |
| 16010 | |
| 16011 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16012 | |
| 16013 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 16014 | &redisc_fcf->header.cfg_shdr.response); |
| 16015 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 16016 | &redisc_fcf->header.cfg_shdr.response); |
| 16017 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16018 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16019 | "2746 Requesting for FCF rediscovery failed " |
| 16020 | "status x%x add_status x%x\n", |
| 16021 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16022 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16023 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16024 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16025 | spin_unlock_irq(&phba->hbalock); |
| 16026 | /* |
| 16027 | * CVL event triggered FCF rediscover request failed, |
| 16028 | * last resort to re-try current registered FCF entry. |
| 16029 | */ |
| 16030 | lpfc_retry_pport_discovery(phba); |
| 16031 | } else { |
| 16032 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16033 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16034 | spin_unlock_irq(&phba->hbalock); |
| 16035 | /* |
| 16036 | * DEAD FCF event triggered FCF rediscover request |
| 16037 | * failed, last resort to fail over as a link down |
| 16038 | * to FCF registration. |
| 16039 | */ |
| 16040 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 16041 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16042 | } else { |
| 16043 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 16044 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16045 | /* |
| 16046 | * Start FCF rediscovery wait timer for pending FCF |
| 16047 | * before rescan FCF record table. |
| 16048 | */ |
| 16049 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16050 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16051 | |
| 16052 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16053 | } |
| 16054 | |
| 16055 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 16056 | * 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] | 16057 | * @phba: pointer to lpfc hba data structure. |
| 16058 | * |
| 16059 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 16060 | * by the port. |
| 16061 | **/ |
| 16062 | int |
| 16063 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 16064 | { |
| 16065 | LPFC_MBOXQ_t *mbox; |
| 16066 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 16067 | int rc, length; |
| 16068 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 16069 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 16070 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 16071 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 16072 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16073 | if (!mbox) { |
| 16074 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16075 | "2745 Failed to allocate mbox for " |
| 16076 | "requesting FCF rediscover.\n"); |
| 16077 | return -ENOMEM; |
| 16078 | } |
| 16079 | |
| 16080 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 16081 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16082 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16083 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 16084 | length, LPFC_SLI4_MBX_EMBED); |
| 16085 | |
| 16086 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 16087 | /* Set count to 0 for invalidating the entire FCF database */ |
| 16088 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 16089 | |
| 16090 | /* Issue the mailbox command asynchronously */ |
| 16091 | mbox->vport = phba->pport; |
| 16092 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 16093 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 16094 | |
| 16095 | if (rc == MBX_NOT_FINISHED) { |
| 16096 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16097 | return -EIO; |
| 16098 | } |
| 16099 | return 0; |
| 16100 | } |
| 16101 | |
| 16102 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 16103 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 16104 | * @phba: pointer to lpfc hba data structure. |
| 16105 | * |
| 16106 | * This function is the failover routine as a last resort to the FCF DEAD |
| 16107 | * event when driver failed to perform fast FCF failover. |
| 16108 | **/ |
| 16109 | void |
| 16110 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 16111 | { |
| 16112 | uint32_t link_state; |
| 16113 | |
| 16114 | /* |
| 16115 | * Last resort as FCF DEAD event failover will treat this as |
| 16116 | * a link down, but save the link state because we don't want |
| 16117 | * it to be changed to Link Down unless it is already down. |
| 16118 | */ |
| 16119 | link_state = phba->link_state; |
| 16120 | lpfc_linkdown(phba); |
| 16121 | phba->link_state = link_state; |
| 16122 | |
| 16123 | /* Unregister FCF if no devices connected to it */ |
| 16124 | lpfc_unregister_unused_fcf(phba); |
| 16125 | } |
| 16126 | |
| 16127 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16128 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16129 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16130 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16131 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16132 | * This function gets SLI3 port configure region 23 data through memory dump |
| 16133 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16134 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16135 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16136 | static uint32_t |
| 16137 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16138 | { |
| 16139 | LPFC_MBOXQ_t *pmb = NULL; |
| 16140 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16141 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16142 | int rc; |
| 16143 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16144 | if (!rgn23_data) |
| 16145 | return 0; |
| 16146 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16147 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16148 | if (!pmb) { |
| 16149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16150 | "2600 failed to allocate mailbox memory\n"); |
| 16151 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16152 | } |
| 16153 | mb = &pmb->u.mb; |
| 16154 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16155 | do { |
| 16156 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 16157 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 16158 | |
| 16159 | if (rc != MBX_SUCCESS) { |
| 16160 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16161 | "2601 failed to read config " |
| 16162 | "region 23, rc 0x%x Status 0x%x\n", |
| 16163 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16164 | mb->un.varDmp.word_cnt = 0; |
| 16165 | } |
| 16166 | /* |
| 16167 | * dump mem may return a zero when finished or we got a |
| 16168 | * mailbox error, either way we are done. |
| 16169 | */ |
| 16170 | if (mb->un.varDmp.word_cnt == 0) |
| 16171 | break; |
| 16172 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 16173 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 16174 | |
| 16175 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16176 | rgn23_data + offset, |
| 16177 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16178 | offset += mb->un.varDmp.word_cnt; |
| 16179 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 16180 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16181 | mempool_free(pmb, phba->mbox_mem_pool); |
| 16182 | return offset; |
| 16183 | } |
| 16184 | |
| 16185 | /** |
| 16186 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 16187 | * @phba: pointer to lpfc hba data structure. |
| 16188 | * @rgn23_data: pointer to configure region 23 data. |
| 16189 | * |
| 16190 | * This function gets SLI4 port configure region 23 data through memory dump |
| 16191 | * mailbox command. When it successfully retrieves data, the size of the data |
| 16192 | * will be returned, otherwise, 0 will be returned. |
| 16193 | **/ |
| 16194 | static uint32_t |
| 16195 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 16196 | { |
| 16197 | LPFC_MBOXQ_t *mboxq = NULL; |
| 16198 | struct lpfc_dmabuf *mp = NULL; |
| 16199 | struct lpfc_mqe *mqe; |
| 16200 | uint32_t data_length = 0; |
| 16201 | int rc; |
| 16202 | |
| 16203 | if (!rgn23_data) |
| 16204 | return 0; |
| 16205 | |
| 16206 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16207 | if (!mboxq) { |
| 16208 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16209 | "3105 failed to allocate mailbox memory\n"); |
| 16210 | return 0; |
| 16211 | } |
| 16212 | |
| 16213 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 16214 | goto out; |
| 16215 | mqe = &mboxq->u.mqe; |
| 16216 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 16217 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 16218 | if (rc) |
| 16219 | goto out; |
| 16220 | data_length = mqe->un.mb_words[5]; |
| 16221 | if (data_length == 0) |
| 16222 | goto out; |
| 16223 | if (data_length > DMP_RGN23_SIZE) { |
| 16224 | data_length = 0; |
| 16225 | goto out; |
| 16226 | } |
| 16227 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 16228 | out: |
| 16229 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 16230 | if (mp) { |
| 16231 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16232 | kfree(mp); |
| 16233 | } |
| 16234 | return data_length; |
| 16235 | } |
| 16236 | |
| 16237 | /** |
| 16238 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 16239 | * @phba: pointer to lpfc hba data structure. |
| 16240 | * |
| 16241 | * This function read region 23 and parse TLV for port status to |
| 16242 | * decide if the user disaled the port. If the TLV indicates the |
| 16243 | * port is disabled, the hba_flag is set accordingly. |
| 16244 | **/ |
| 16245 | void |
| 16246 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 16247 | { |
| 16248 | uint8_t *rgn23_data = NULL; |
| 16249 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 16250 | uint32_t offset = 0; |
| 16251 | |
| 16252 | /* Get adapter Region 23 data */ |
| 16253 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 16254 | if (!rgn23_data) |
| 16255 | goto out; |
| 16256 | |
| 16257 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16258 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 16259 | else { |
| 16260 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 16261 | &phba->sli4_hba.sli_intf); |
| 16262 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 16263 | goto out; |
| 16264 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 16265 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16266 | |
| 16267 | if (!data_size) |
| 16268 | goto out; |
| 16269 | |
| 16270 | /* Check the region signature first */ |
| 16271 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 16272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16273 | "2619 Config region 23 has bad signature\n"); |
| 16274 | goto out; |
| 16275 | } |
| 16276 | offset += 4; |
| 16277 | |
| 16278 | /* Check the data structure version */ |
| 16279 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 16280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16281 | "2620 Config region 23 has bad version\n"); |
| 16282 | goto out; |
| 16283 | } |
| 16284 | offset += 4; |
| 16285 | |
| 16286 | /* Parse TLV entries in the region */ |
| 16287 | while (offset < data_size) { |
| 16288 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 16289 | break; |
| 16290 | /* |
| 16291 | * If the TLV is not driver specific TLV or driver id is |
| 16292 | * not linux driver id, skip the record. |
| 16293 | */ |
| 16294 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 16295 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 16296 | (rgn23_data[offset + 3] != 0)) { |
| 16297 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16298 | continue; |
| 16299 | } |
| 16300 | |
| 16301 | /* Driver found a driver specific TLV in the config region */ |
| 16302 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 16303 | offset += 4; |
| 16304 | tlv_offset = 0; |
| 16305 | |
| 16306 | /* |
| 16307 | * Search for configured port state sub-TLV. |
| 16308 | */ |
| 16309 | while ((offset < data_size) && |
| 16310 | (tlv_offset < sub_tlv_len)) { |
| 16311 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 16312 | offset += 4; |
| 16313 | tlv_offset += 4; |
| 16314 | break; |
| 16315 | } |
| 16316 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 16317 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 16318 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 16319 | continue; |
| 16320 | } |
| 16321 | |
| 16322 | /* This HBA contains PORT_STE configured */ |
| 16323 | if (!rgn23_data[offset + 2]) |
| 16324 | phba->hba_flag |= LINK_DISABLED; |
| 16325 | |
| 16326 | goto out; |
| 16327 | } |
| 16328 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 16329 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16330 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 16331 | kfree(rgn23_data); |
| 16332 | return; |
| 16333 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16334 | |
| 16335 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16336 | * lpfc_wr_object - write an object to the firmware |
| 16337 | * @phba: HBA structure that indicates port to create a queue on. |
| 16338 | * @dmabuf_list: list of dmabufs to write to the port. |
| 16339 | * @size: the total byte value of the objects to write to the port. |
| 16340 | * @offset: the current offset to be used to start the transfer. |
| 16341 | * |
| 16342 | * This routine will create a wr_object mailbox command to send to the port. |
| 16343 | * the mailbox command will be constructed using the dma buffers described in |
| 16344 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 16345 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 16346 | * used to indicate the starting offset of the transfer and will also return |
| 16347 | * the offset after the write object mailbox has completed. @size is used to |
| 16348 | * determine the end of the object and whether the eof bit should be set. |
| 16349 | * |
| 16350 | * Return 0 is successful and offset will contain the the new offset to use |
| 16351 | * for the next write. |
| 16352 | * Return negative value for error cases. |
| 16353 | **/ |
| 16354 | int |
| 16355 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 16356 | uint32_t size, uint32_t *offset) |
| 16357 | { |
| 16358 | struct lpfc_mbx_wr_object *wr_object; |
| 16359 | LPFC_MBOXQ_t *mbox; |
| 16360 | int rc = 0, i = 0; |
| 16361 | uint32_t shdr_status, shdr_add_status; |
| 16362 | uint32_t mbox_tmo; |
| 16363 | union lpfc_sli4_cfg_shdr *shdr; |
| 16364 | struct lpfc_dmabuf *dmabuf; |
| 16365 | uint32_t written = 0; |
| 16366 | |
| 16367 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16368 | if (!mbox) |
| 16369 | return -ENOMEM; |
| 16370 | |
| 16371 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16372 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 16373 | sizeof(struct lpfc_mbx_wr_object) - |
| 16374 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 16375 | |
| 16376 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 16377 | wr_object->u.request.write_offset = *offset; |
| 16378 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 16379 | wr_object->u.request.object_name[0] = |
| 16380 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 16381 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 16382 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 16383 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 16384 | break; |
| 16385 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 16386 | wr_object->u.request.bde[i].addrHigh = |
| 16387 | putPaddrHigh(dmabuf->phys); |
| 16388 | if (written + SLI4_PAGE_SIZE >= size) { |
| 16389 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16390 | (size - written); |
| 16391 | written += (size - written); |
| 16392 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 16393 | } else { |
| 16394 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 16395 | SLI4_PAGE_SIZE; |
| 16396 | written += SLI4_PAGE_SIZE; |
| 16397 | } |
| 16398 | i++; |
| 16399 | } |
| 16400 | wr_object->u.request.bde_count = i; |
| 16401 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 16402 | if (!phba->sli4_hba.intr_enable) |
| 16403 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16404 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16405 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 16406 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16407 | } |
| 16408 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16409 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 16410 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16411 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16412 | if (rc != MBX_TIMEOUT) |
| 16413 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16414 | if (shdr_status || shdr_add_status || rc) { |
| 16415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16416 | "3025 Write Object mailbox failed with " |
| 16417 | "status x%x add_status x%x, mbx status x%x\n", |
| 16418 | shdr_status, shdr_add_status, rc); |
| 16419 | rc = -ENXIO; |
| 16420 | } else |
| 16421 | *offset += wr_object->u.response.actual_write_length; |
| 16422 | return rc; |
| 16423 | } |
| 16424 | |
| 16425 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16426 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 16427 | * @vport: pointer to vport data structure. |
| 16428 | * |
| 16429 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 16430 | * and REG_VPI mailbox commands associated with the vport. This function |
| 16431 | * is called when driver want to restart discovery of the vport due to |
| 16432 | * a Clear Virtual Link event. |
| 16433 | **/ |
| 16434 | void |
| 16435 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 16436 | { |
| 16437 | struct lpfc_hba *phba = vport->phba; |
| 16438 | LPFC_MBOXQ_t *mb, *nextmb; |
| 16439 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16440 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16441 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16442 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16443 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16444 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16445 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16446 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16447 | spin_lock_irq(&phba->hbalock); |
| 16448 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 16449 | if (mb->vport != vport) |
| 16450 | continue; |
| 16451 | |
| 16452 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16453 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16454 | continue; |
| 16455 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16456 | list_del(&mb->list); |
| 16457 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 16458 | } |
| 16459 | /* Clean up active mailbox command with the vport */ |
| 16460 | mb = phba->sli.mbox_active; |
| 16461 | if (mb && (mb->vport == vport)) { |
| 16462 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 16463 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 16464 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16465 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16466 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16467 | /* Put reference count for delayed processing */ |
| 16468 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 16469 | /* Unregister the RPI when mailbox complete */ |
| 16470 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16471 | } |
| 16472 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 16473 | /* Cleanup any mailbox completions which are not yet processed */ |
| 16474 | do { |
| 16475 | restart_loop = 0; |
| 16476 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 16477 | /* |
| 16478 | * If this mailox is already processed or it is |
| 16479 | * for another vport ignore it. |
| 16480 | */ |
| 16481 | if ((mb->vport != vport) || |
| 16482 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 16483 | continue; |
| 16484 | |
| 16485 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 16486 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 16487 | continue; |
| 16488 | |
| 16489 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16490 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16491 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 16492 | /* Unregister the RPI when mailbox complete */ |
| 16493 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 16494 | restart_loop = 1; |
| 16495 | spin_unlock_irq(&phba->hbalock); |
| 16496 | spin_lock(shost->host_lock); |
| 16497 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16498 | spin_unlock(shost->host_lock); |
| 16499 | spin_lock_irq(&phba->hbalock); |
| 16500 | break; |
| 16501 | } |
| 16502 | } |
| 16503 | } while (restart_loop); |
| 16504 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16505 | spin_unlock_irq(&phba->hbalock); |
| 16506 | |
| 16507 | /* Release the cleaned-up mailbox commands */ |
| 16508 | while (!list_empty(&mbox_cmd_list)) { |
| 16509 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16510 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 16511 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 16512 | if (mp) { |
| 16513 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 16514 | kfree(mp); |
| 16515 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16516 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16517 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16518 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16519 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 16520 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 16521 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16522 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 16523 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16524 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16525 | mempool_free(mb, phba->mbox_mem_pool); |
| 16526 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16527 | |
| 16528 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 16529 | if (act_mbx_ndlp) { |
| 16530 | spin_lock(shost->host_lock); |
| 16531 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 16532 | spin_unlock(shost->host_lock); |
| 16533 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16534 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 16535 | } |
| 16536 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16537 | /** |
| 16538 | * lpfc_drain_txq - Drain the txq |
| 16539 | * @phba: Pointer to HBA context object. |
| 16540 | * |
| 16541 | * This function attempt to submit IOCBs on the txq |
| 16542 | * to the adapter. For SLI4 adapters, the txq contains |
| 16543 | * ELS IOCBs that have been deferred because the there |
| 16544 | * are no SGLs. This congestion can occur with large |
| 16545 | * vport counts during node discovery. |
| 16546 | **/ |
| 16547 | |
| 16548 | uint32_t |
| 16549 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 16550 | { |
| 16551 | LIST_HEAD(completions); |
| 16552 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 16553 | struct lpfc_iocbq *piocbq = 0; |
| 16554 | unsigned long iflags = 0; |
| 16555 | char *fail_msg = NULL; |
| 16556 | struct lpfc_sglq *sglq; |
| 16557 | union lpfc_wqe wqe; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16558 | int txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16559 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16560 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16561 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 16562 | txq_cnt++; |
| 16563 | } |
| 16564 | |
| 16565 | if (txq_cnt > pring->txq_max) |
| 16566 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16567 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16568 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16569 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16570 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16571 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16572 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16573 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16574 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16575 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16577 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16578 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 16579 | break; |
| 16580 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16581 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16582 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 16583 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16584 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16585 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16586 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16587 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16588 | |
| 16589 | /* The xri and iocb resources secured, |
| 16590 | * attempt to issue request |
| 16591 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16592 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16593 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 16594 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 16595 | fail_msg = "to convert bpl to sgl"; |
| 16596 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
| 16597 | fail_msg = "to convert iocb to wqe"; |
| 16598 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
| 16599 | fail_msg = " - Wq is full"; |
| 16600 | else |
| 16601 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 16602 | |
| 16603 | if (fail_msg) { |
| 16604 | /* Failed means we can't issue and need to cancel */ |
| 16605 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16606 | "2822 IOCB failed %s iotag 0x%x " |
| 16607 | "xri 0x%x\n", |
| 16608 | fail_msg, |
| 16609 | piocbq->iotag, piocbq->sli4_xritag); |
| 16610 | list_add_tail(&piocbq->list, &completions); |
| 16611 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 16612 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16613 | } |
| 16614 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16615 | /* Cancel all the IOCBs that cannot be issued */ |
| 16616 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 16617 | IOERR_SLI_ABORTED); |
| 16618 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 16619 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 16620 | } |